summaryrefslogtreecommitdiffstats
path: root/runtime/jni_internal.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/jni_internal.cc')
-rw-r--r--runtime/jni_internal.cc58
1 files changed, 53 insertions, 5 deletions
diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc
index f9c7ec6..64cca3d 100644
--- a/runtime/jni_internal.cc
+++ b/runtime/jni_internal.cc
@@ -41,6 +41,7 @@
#include "mirror/object_array-inl.h"
#include "mirror/string-inl.h"
#include "mirror/throwable.h"
+#include "native_bridge.h"
#include "parsed_options.h"
#include "reflection.h"
#include "runtime.h"
@@ -362,6 +363,7 @@ class SharedLibrary {
SharedLibrary(const std::string& path, void* handle, mirror::Object* class_loader)
: path_(path),
handle_(handle),
+ needs_native_bridge_(false),
class_loader_(class_loader),
jni_on_load_lock_("JNI_OnLoad lock"),
jni_on_load_cond_("JNI_OnLoad condition variable", jni_on_load_lock_),
@@ -422,10 +424,30 @@ class SharedLibrary {
jni_on_load_cond_.Broadcast(self);
}
+ void SetNeedsNativeBridge() {
+ needs_native_bridge_ = true;
+ }
+
+ bool NeedsNativeBridge() const {
+ return needs_native_bridge_;
+ }
+
void* FindSymbol(const std::string& symbol_name) {
return dlsym(handle_, symbol_name.c_str());
}
+ void* FindSymbolWithNativeBridge(const std::string& symbol_name, mirror::ArtMethod* m)
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+ CHECK(NeedsNativeBridge());
+
+ uint32_t len = 0;
+ const char* shorty = nullptr;
+ if (m != nullptr) {
+ shorty = m->GetShorty(&len);
+ }
+ return NativeBridge::GetTrampoline(handle_, symbol_name.c_str(), shorty, len);
+ }
+
void VisitRoots(RootCallback* visitor, void* arg) {
if (class_loader_ != nullptr) {
visitor(&class_loader_, arg, 0, kRootVMInternal);
@@ -445,6 +467,9 @@ class SharedLibrary {
// The void* returned by dlopen(3).
void* handle_;
+ // True if a native bridge is required.
+ bool needs_native_bridge_;
+
// The ClassLoader this library is associated with.
mirror::Object* class_loader_;
@@ -505,9 +530,17 @@ class Libraries {
continue;
}
// Try the short name then the long name...
- void* fn = library->FindSymbol(jni_short_name);
- if (fn == nullptr) {
- fn = library->FindSymbol(jni_long_name);
+ void* fn = nullptr;
+ if (UNLIKELY(library->NeedsNativeBridge())) {
+ fn = library->FindSymbolWithNativeBridge(jni_short_name, m);
+ if (fn == nullptr) {
+ fn = library->FindSymbolWithNativeBridge(jni_long_name, m);
+ }
+ } else {
+ fn = library->FindSymbol(jni_short_name);
+ if (fn == nullptr) {
+ fn = library->FindSymbol(jni_long_name);
+ }
}
if (fn != nullptr) {
VLOG(jni) << "[Found native code for " << PrettyMethod(m)
@@ -3267,7 +3300,15 @@ bool JavaVMExt::LoadNativeLibrary(const std::string& path,
// This can execute slowly for a large library on a busy system, so we
// want to switch from kRunnable while it executes. This allows the GC to ignore us.
self->TransitionFromRunnableToSuspended(kWaitingForJniOnLoad);
- void* handle = dlopen(path.empty() ? nullptr : path.c_str(), RTLD_LAZY);
+ const char* path_str = path.empty() ? nullptr : path.c_str();
+ void* handle = dlopen(path_str, RTLD_LAZY);
+ bool needs_native_bridge = false;
+ if (handle == nullptr) {
+ if (NativeBridge::IsSupported(path_str)) {
+ handle = NativeBridge::LoadLibrary(path_str, RTLD_LAZY);
+ needs_native_bridge = true;
+ }
+ }
self->TransitionFromSuspendedToRunnable();
VLOG(jni) << "[Call to dlopen(\"" << path << "\", RTLD_LAZY) returned " << handle << "]";
@@ -3300,7 +3341,14 @@ bool JavaVMExt::LoadNativeLibrary(const std::string& path,
<< "]";
bool was_successful = false;
- void* sym = dlsym(handle, "JNI_OnLoad");
+ void* sym = nullptr;
+ if (UNLIKELY(needs_native_bridge)) {
+ library->SetNeedsNativeBridge();
+ sym = library->FindSymbolWithNativeBridge("JNI_OnLoad", nullptr);
+ } else {
+ sym = dlsym(handle, "JNI_OnLoad");
+ }
+
if (sym == nullptr) {
VLOG(jni) << "[No JNI_OnLoad found in \"" << path << "\"]";
was_successful = true;