diff options
| author | 2016-06-06 10:45:28 -0700 | |
|---|---|---|
| committer | 2016-06-06 10:48:05 -0700 | |
| commit | 9e726e874580f1e8b2e0bfa63d2e9a3ac911cd1c (patch) | |
| tree | 96a8bfe6aaafb8af2c63c1741ec2c541d518558d | |
| parent | 681c58c6eab2bc8dab561cb6ac5bcabe89676730 (diff) | |
Revert "Revert some flaky unloading"
This reverts commit 73ad16e0193866d36dbd4088ac77fa5d4ceec334.
With this code it is possible that during testing we will race the
final shutdown of some threads (i.e. returning to thread_start after
signaling thread has been finished) with the unloading of libart.so by
libnativehelper. This could cause crashes. By ensuring that libart.so
code is not unloaded in libnativehelper we fix the issue with this
patch.
Bug: 28406866
Change-Id: Ic67118c2a4e743941402b17b6bbfe4cce441f68f
| -rw-r--r-- | runtime/common_runtime_test.cc | 20 | ||||
| -rw-r--r-- | runtime/java_vm_ext.cc | 31 |
2 files changed, 17 insertions, 34 deletions
diff --git a/runtime/common_runtime_test.cc b/runtime/common_runtime_test.cc index f58af5a8da..5bdb36cafc 100644 --- a/runtime/common_runtime_test.cc +++ b/runtime/common_runtime_test.cc @@ -418,26 +418,6 @@ void CommonRuntimeTestImpl::TearDown() { (*icu_cleanup_fn)(); Runtime::Current()->GetHeap()->VerifyHeap(); // Check for heap corruption after the test - - // Manually closing the JNI libraries. - // Runtime does not support repeatedly doing JNI->CreateVM, thus we need to manually clean up the - // dynamic linking loader so that gtests would not fail. - // Bug: 25785594 - if (runtime_->IsStarted()) { - { - // We retrieve the handle by calling dlopen on the library. To close it, we need to call - // dlclose twice, the first time to undo our dlopen and the second time to actually unload it. - // See man dlopen. - void* handle = dlopen("libjavacore.so", RTLD_LAZY); - dlclose(handle); - CHECK_EQ(0, dlclose(handle)); - } - { - void* handle = dlopen("libopenjdkd.so", RTLD_LAZY); - dlclose(handle); - CHECK_EQ(0, dlclose(handle)); - } - } } static std::string GetDexFileName(const std::string& jar_prefix, bool host) { diff --git a/runtime/java_vm_ext.cc b/runtime/java_vm_ext.cc index d983a9fa19..c2164126e1 100644 --- a/runtime/java_vm_ext.cc +++ b/runtime/java_vm_ext.cc @@ -74,6 +74,10 @@ class SharedLibrary { if (self != nullptr) { self->GetJniEnv()->DeleteWeakGlobalRef(class_loader_); } + + if (!needs_native_bridge_) { + android::CloseNativeLibrary(handle_); + } } jweak GetClassLoader() const { @@ -271,8 +275,7 @@ class Libraries { REQUIRES(!Locks::jni_libraries_lock_) SHARED_REQUIRES(Locks::mutator_lock_) { ScopedObjectAccessUnchecked soa(Thread::Current()); - typedef void (*JNI_OnUnloadFn)(JavaVM*, void*); - std::vector<JNI_OnUnloadFn> unload_functions; + std::vector<SharedLibrary*> unload_libraries; { MutexLock mu(soa.Self(), *Locks::jni_libraries_lock_); for (auto it = libraries_.begin(); it != libraries_.end(); ) { @@ -283,15 +286,7 @@ class Libraries { // the native libraries of the boot class loader. if (class_loader != nullptr && soa.Self()->IsJWeakCleared(class_loader)) { - void* const sym = library->FindSymbol("JNI_OnUnload", nullptr); - if (sym == nullptr) { - VLOG(jni) << "[No JNI_OnUnload found in \"" << library->GetPath() << "\"]"; - } else { - VLOG(jni) << "[JNI_OnUnload found for \"" << library->GetPath() << "\"]"; - JNI_OnUnloadFn jni_on_unload = reinterpret_cast<JNI_OnUnloadFn>(sym); - unload_functions.push_back(jni_on_unload); - } - delete library; + unload_libraries.push_back(library); it = libraries_.erase(it); } else { ++it; @@ -299,9 +294,17 @@ class Libraries { } } // Do this without holding the jni libraries lock to prevent possible deadlocks. - for (JNI_OnUnloadFn fn : unload_functions) { - VLOG(jni) << "Calling JNI_OnUnload"; - (*fn)(soa.Vm(), nullptr); + typedef void (*JNI_OnUnloadFn)(JavaVM*, void*); + for (auto library : unload_libraries) { + void* const sym = library->FindSymbol("JNI_OnUnload", nullptr); + if (sym == nullptr) { + VLOG(jni) << "[No JNI_OnUnload found in \"" << library->GetPath() << "\"]"; + } else { + VLOG(jni) << "[JNI_OnUnload found for \"" << library->GetPath() << "\"]: Calling..."; + JNI_OnUnloadFn jni_on_unload = reinterpret_cast<JNI_OnUnloadFn>(sym); + jni_on_unload(soa.Vm(), nullptr); + } + delete library; } } |