summaryrefslogtreecommitdiff
path: root/runtime/native/dalvik_system_VMDebug.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/native/dalvik_system_VMDebug.cc')
-rw-r--r--runtime/native/dalvik_system_VMDebug.cc78
1 files changed, 76 insertions, 2 deletions
diff --git a/runtime/native/dalvik_system_VMDebug.cc b/runtime/native/dalvik_system_VMDebug.cc
index 9c007f8b90..74b9199917 100644
--- a/runtime/native/dalvik_system_VMDebug.cc
+++ b/runtime/native/dalvik_system_VMDebug.cc
@@ -21,8 +21,6 @@
#include <sstream>
-#include "nativehelper/jni_macros.h"
-
#include "base/file_utils.h"
#include "base/histogram-inl.h"
#include "base/time_utils.h"
@@ -30,6 +28,8 @@
#include "class_root-inl.h"
#include "common_throws.h"
#include "debugger.h"
+#include "dex/class_accessor-inl.h"
+#include "dex/descriptors_names.h"
#include "gc/space/bump_pointer_space.h"
#include "gc/space/dlmalloc_space.h"
#include "gc/space/large_object_space.h"
@@ -42,10 +42,14 @@
#include "mirror/array-alloc-inl.h"
#include "mirror/array-inl.h"
#include "mirror/class.h"
+#include "mirror/executable-inl.h"
#include "mirror/object_array-alloc-inl.h"
#include "native_util.h"
+#include "nativehelper/jni_macros.h"
#include "nativehelper/scoped_local_ref.h"
#include "nativehelper/scoped_utf_chars.h"
+#include "nativehelper/utils.h"
+#include "oat/oat_quick_method_header.h"
#include "scoped_fast_native_object_access-inl.h"
#include "string_array_utils.h"
#include "thread-inl.h"
@@ -312,6 +316,72 @@ static jlong VMDebug_countInstancesOfClass(JNIEnv* env,
return count;
}
+static jobject VMDebug_getExecutableMethodFileOffsetsNative(JNIEnv* env,
+ jclass,
+ jobject javaMethod) {
+ ScopedObjectAccess soa(env);
+ ObjPtr<mirror::Executable> m = soa.Decode<mirror::Executable>(javaMethod);
+ if (m == nullptr) {
+ soa.Self()->ThrowNewExceptionF("Ljava/lang/RuntimeException;",
+ "Could not find mirror::Executable for supplied jobject");
+ return nullptr;
+ }
+
+ ObjPtr<mirror::Class> c = m->GetDeclaringClass();
+ if (c == nullptr) {
+ soa.Self()->ThrowNewExceptionF("Ljava/lang/RuntimeException;",
+ "Could not find mirror::Class for supplied jobject");
+ return nullptr;
+ }
+
+ ArtMethod* art_method = m->GetArtMethod();
+ auto oat_method_quick_code =
+ reinterpret_cast<const uint8_t*>(art_method->GetOatMethodQuickCode(kRuntimePointerSize));
+
+ if (oat_method_quick_code == nullptr) {
+ LOG(ERROR) << "No OatMethodQuickCode for method " << art_method->PrettyMethod();
+ return nullptr;
+ }
+
+ const OatDexFile* oat_dex_file = c->GetDexFile().GetOatDexFile();
+ if (oat_dex_file == nullptr) {
+ soa.Self()->ThrowNewExceptionF("Ljava/lang/RuntimeException;", "Could not find oat_dex_file");
+ return nullptr;
+ }
+
+ const OatFile* oat_file = oat_dex_file->GetOatFile();
+ if (oat_file == nullptr) {
+ soa.Self()->ThrowNewExceptionF("Ljava/lang/RuntimeException;", "Could not find oat_file");
+ return nullptr;
+ }
+
+ std::string error_msg;
+ const uint8_t* elf_begin = oat_file->ComputeElfBegin(&error_msg);
+ if (elf_begin == nullptr) {
+ soa.Self()->ThrowNewExceptionF(
+ "Ljava/lang/RuntimeException;", "Could not find elf_begin: %s", error_msg.c_str());
+ return nullptr;
+ }
+
+ size_t adjusted_offset = oat_method_quick_code - elf_begin;
+
+ ScopedLocalRef<jstring> odex_path = CREATE_UTF_OR_RETURN(env, oat_file->GetLocation());
+ auto odex_offset = reinterpret_cast64<jlong>(elf_begin);
+ auto method_offset = static_cast<jlong>(adjusted_offset);
+
+ ScopedLocalRef<jclass> clazz(env,
+ env->FindClass("dalvik/system/VMDebug$ExecutableMethodFileOffsets"));
+ if (clazz == nullptr) {
+ soa.Self()->ThrowNewExceptionF(
+ "Ljava/lang/RuntimeException;",
+ "Could not find dalvik/system/VMDebug$ExecutableMethodFileOffsets");
+ return nullptr;
+ }
+
+ jmethodID constructor_id = env->GetMethodID(clazz.get(), "<init>", "(Ljava/lang/String;JJ)V");
+ return env->NewObject(clazz.get(), constructor_id, odex_path.get(), odex_offset, method_offset);
+}
+
static jlongArray VMDebug_countInstancesOfClasses(JNIEnv* env,
jclass,
jobjectArray javaClasses,
@@ -638,6 +708,10 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(VMDebug, stopLowOverheadTraceImpl, "()V"),
NATIVE_METHOD(VMDebug, dumpLowOverheadTraceImpl, "(Ljava/lang/String;)V"),
NATIVE_METHOD(VMDebug, dumpLowOverheadTraceFdImpl, "(I)V"),
+ NATIVE_METHOD(
+ VMDebug,
+ getExecutableMethodFileOffsetsNative,
+ "(Ljava/lang/reflect/Method;)Ldalvik/system/VMDebug$ExecutableMethodFileOffsets;"),
};
void register_dalvik_system_VMDebug(JNIEnv* env) {