Generating stub code for registering a jni function at runtime.
On ARM and x86. Added a unit test.
Change-Id: I6b1ee09ad18295108f406ce21d73555796ecbba6
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 83a147f..954fafd 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -25,6 +25,25 @@
namespace art {
+void* FindNativeMethod(Thread* thread) {
+ DCHECK(Thread::Current() == thread);
+
+ Method* method = const_cast<Method*>(thread->GetCurrentMethod());
+ DCHECK(method != NULL);
+
+ // Lookup symbol address for method, on failure we'll return NULL with an
+ // exception set, otherwise we return the address of the method we found.
+ void* native_code = thread->GetJniEnv()->vm->FindCodeForNativeMethod(method);
+ if (native_code == NULL) {
+ DCHECK(thread->IsExceptionPending());
+ return NULL;
+ } else {
+ // Register so that future calls don't come here
+ method->RegisterNative(native_code);
+ return native_code;
+ }
+}
+
/*
* Add a local reference for an object to the current stack frame. When
* the native function returns, the reference will be discarded.
@@ -452,6 +471,7 @@
SharedLibrary(const std::string& path, void* handle, Object* class_loader)
: path_(path),
handle_(handle),
+ class_loader_(class_loader),
jni_on_load_lock_("JNI_OnLoad lock"),
jni_on_load_thread_id_(Thread::Current()->GetThinLockId()),
jni_on_load_result_(kPending) {