diff options
author | 2017-12-28 16:55:31 -0800 | |
---|---|---|
committer | 2018-01-03 23:27:37 -0800 | |
commit | 473191c4093aac1ec50bc275c588287fa37a981e (patch) | |
tree | df5b6493b21498097c29b5c9772cd1606f1bd29c /runtime/java_vm_ext.cc | |
parent | a3e50959997f5c3e3b2d7e200b3b022757845f20 (diff) |
ART: Clean up library loading
Retrieve the library path from the classloader before attempting to
load, instead of getting it passed down. This allows unifying said
loading behavior for follow-up changes.
Fix up test code to support the new required data in classloader
objects.
Bug: 70901841
Test: m test-art-host
Test: device boots
Change-Id: Iaccaeb56422877abac9f7fe6f5a17364c8adf4ca
Diffstat (limited to 'runtime/java_vm_ext.cc')
-rw-r--r-- | runtime/java_vm_ext.cc | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/runtime/java_vm_ext.cc b/runtime/java_vm_ext.cc index e15943646d..579552d6ab 100644 --- a/runtime/java_vm_ext.cc +++ b/runtime/java_vm_ext.cc @@ -48,6 +48,7 @@ #include "thread-inl.h" #include "thread_list.h" #include "ti/agent.h" +#include "well_known_classes.h" namespace art { @@ -853,7 +854,6 @@ void JavaVMExt::UnloadNativeLibraries() { bool JavaVMExt::LoadNativeLibrary(JNIEnv* env, const std::string& path, jobject class_loader, - jstring library_path, std::string* error_msg) { error_msg->clear(); @@ -950,6 +950,9 @@ bool JavaVMExt::LoadNativeLibrary(JNIEnv* env, // class unloading. Libraries will only be unloaded when the reference count (incremented by // dlopen) becomes zero from dlclose. + // Retrieve the library path from the classloader, if necessary. + ScopedLocalRef<jstring> library_path(env, GetLibrarySearchPath(env, class_loader)); + Locks::mutator_lock_->AssertNotHeld(self); const char* path_str = path.empty() ? nullptr : path.c_str(); bool needs_native_bridge = false; @@ -957,7 +960,7 @@ bool JavaVMExt::LoadNativeLibrary(JNIEnv* env, runtime_->GetTargetSdkVersion(), path_str, class_loader, - library_path, + library_path.get(), &needs_native_bridge, error_msg); @@ -1119,6 +1122,18 @@ void JavaVMExt::VisitRoots(RootVisitor* visitor) { // The weak_globals table is visited by the GC itself (because it mutates the table). } +jstring JavaVMExt::GetLibrarySearchPath(JNIEnv* env, jobject class_loader) { + if (class_loader == nullptr) { + return nullptr; + } + if (!env->IsInstanceOf(class_loader, WellKnownClasses::dalvik_system_BaseDexClassLoader)) { + return nullptr; + } + return reinterpret_cast<jstring>(env->CallObjectMethod( + class_loader, + WellKnownClasses::dalvik_system_BaseDexClassLoader_getLdLibraryPath)); +} + // JNI Invocation interface. extern "C" jint JNI_CreateJavaVM(JavaVM** p_vm, JNIEnv** p_env, void* vm_args) { |