Clean up JNI dlsym lookup trampoline.
Make sure the GenericJniTrampoline recognizes the trampoline
in primary boot image oat file. Rename that trampoline, add
a test and flag some issues in the code.
Test: New test 178-app-image-native-method.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Test: testrunner.py --host -t 178-app-image-native-method
Bug: 112189621
Change-Id: I8f8cd11998af536fd3842dd4183a25f0367655a6
diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
index 6a52d24..1cc4d24 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -2389,7 +2389,7 @@
// Ensure static method's class is initialized.
StackHandleScope<1> hs(self);
Handle<mirror::Class> h_class(hs.NewHandle(declaring_class));
- if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true, true)) {
+ if (!runtime->GetClassLinker()->EnsureInitialized(self, h_class, true, true)) {
DCHECK(Thread::Current()->IsExceptionPending()) << called->PrettyMethod();
self->PopHandleScope();
// A negative value denotes an error.
@@ -2432,7 +2432,11 @@
// In the second case, we need to execute the binding and continue with the actual native function
// pointer.
DCHECK(nativeCode != nullptr);
- if (nativeCode == GetJniDlsymLookupStub()) {
+ if (runtime->GetClassLinker()->IsJniDlsymLookupStub(nativeCode)) {
+ // FIXME: This is broken for @FastNative and @CriticalNative as we're still runnable.
+ // Calls from compiled stubs are also broken.
+ // TODO: We could just let the GenericJNI stub call the ArtFindNativeMethod()
+ // rather than calling it explicitly here.
nativeCode = artFindNativeMethod(self);
if (nativeCode == nullptr) {