Load libart.so with RTLD_NODELETE
am: 6cf8e8d358
* commit '6cf8e8d3587a438c7117cce47330ac37ca9d6884':
Load libart.so with RTLD_NODELETE
Change-Id: I6d031b978cc4b3f7f2bb58f36696beacbd2537a2
diff --git a/JniInvocation.cpp b/JniInvocation.cpp
index a0805ed..b869914 100644
--- a/JniInvocation.cpp
+++ b/JniInvocation.cpp
@@ -103,8 +103,12 @@
char* buffer = NULL;
#endif
library = GetLibrary(library, buffer);
-
- handle_ = dlopen(library, RTLD_NOW);
+ // Load with RTLD_NODELETE in order to ensure that libart.so is not unmapped when it is closed.
+ // This is due to the fact that it is possible that some threads might have yet to finish
+ // exiting even after JNI_DeleteJavaVM returns, which can lead to segfaults if the library is
+ // unloaded.
+ const int kDlopenFlags = RTLD_NOW | RTLD_NODELETE;
+ handle_ = dlopen(library, kDlopenFlags);
if (handle_ == NULL) {
if (strcmp(library, kLibraryFallback) == 0) {
// Nothing else to try.
@@ -119,7 +123,7 @@
ALOGW("Falling back from %s to %s after dlopen error: %s",
library, kLibraryFallback, dlerror());
library = kLibraryFallback;
- handle_ = dlopen(library, RTLD_NOW);
+ handle_ = dlopen(library, kDlopenFlags);
if (handle_ == NULL) {
ALOGE("Failed to dlopen %s: %s", library, dlerror());
return false;