OSDN Git Service

Simplify LoadNativeLibrary()
authorDimitry Ivanov <dimitry@google.com>
Wed, 24 Feb 2016 21:33:33 +0000 (13:33 -0800)
committerDimitry Ivanov <dimitry@google.com>
Wed, 24 Feb 2016 23:16:20 +0000 (15:16 -0800)
With ApplicationLoaders.getClassLoader() ensuring
linker-namespace initialization there is no longer
need for LoadNativeLibrary() and callers to pass
along namespace-specific information to art.

This change removes unnecessary parameters of such
calls.

Bug: http://b/27189432
Bug: http://b/22548808
Change-Id: I341d35a2d5195e634678b352f4361f8712984b69

compiler/jni/jni_compiler_test.cc
runtime/java_vm_ext.cc
runtime/java_vm_ext.h
runtime/native/java_lang_Runtime.cc
runtime/openjdkjvm/OpenjdkJvm.cc
runtime/runtime.cc
runtime/well_known_classes.cc

index 8d60be2..cf836a9 100644 (file)
@@ -220,8 +220,7 @@ void JniCompilerTest::CompileAndRunIntMethodThroughStubImpl() {
 
   std::string reason;
   ASSERT_TRUE(Runtime::Current()->GetJavaVM()->
-                  LoadNativeLibrary(env_, "", class_loader_, /* is_shared_namespace */ false,
-                                    nullptr, nullptr, &reason))
+                  LoadNativeLibrary(env_, "", class_loader_, nullptr, &reason))
       << reason;
 
   jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 24);
@@ -236,8 +235,7 @@ void JniCompilerTest::CompileAndRunStaticIntMethodThroughStubImpl() {
 
   std::string reason;
   ASSERT_TRUE(Runtime::Current()->GetJavaVM()->
-                  LoadNativeLibrary(env_, "", class_loader_, /* is_shared_namespace */ false,
-                                    nullptr, nullptr, &reason))
+                  LoadNativeLibrary(env_, "", class_loader_, nullptr, &reason))
       << reason;
 
   jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 42);
index 5c44193..191c0c7 100644 (file)
@@ -716,9 +716,11 @@ void JavaVMExt::UnloadNativeLibraries() {
   libraries_.get()->UnloadNativeLibraries();
 }
 
-bool JavaVMExt::LoadNativeLibrary(JNIEnv* env, const std::string& path, jobject class_loader,
-                                  bool is_shared_namespace, jstring library_path,
-                                  jstring permitted_path, std::string* error_msg) {
+bool JavaVMExt::LoadNativeLibrary(JNIEnv* env,
+                                  const std::string& path,
+                                  jobject class_loader,
+                                  jstring library_path,
+                                  std::string* error_msg) {
   error_msg->clear();
 
   // See if we've already loaded this library.  If we have, and the class loader
@@ -777,9 +779,12 @@ bool JavaVMExt::LoadNativeLibrary(JNIEnv* env, const std::string& path, jobject
 
   Locks::mutator_lock_->AssertNotHeld(self);
   const char* path_str = path.empty() ? nullptr : path.c_str();
-  void* handle = android::OpenNativeLibrary(env, runtime_->GetTargetSdkVersion(), path_str,
-                                            class_loader, is_shared_namespace, library_path,
-                                            permitted_path);
+  void* handle = android::OpenNativeLibrary(env,
+                                            runtime_->GetTargetSdkVersion(),
+                                            path_str,
+                                            class_loader,
+                                            library_path);
+
   bool needs_native_bridge = false;
   if (handle == nullptr) {
     if (android::NativeBridgeIsSupported(path_str)) {
index 8cae1e5..3d055cd 100644 (file)
@@ -85,8 +85,10 @@ class JavaVMExt : public JavaVM {
    * Returns 'true' on success. On failure, sets 'error_msg' to a
    * human-readable description of the error.
    */
-  bool LoadNativeLibrary(JNIEnv* env, const std::string& path, jobject class_loader,
-                         bool is_shared_namespace, jstring library_path, jstring permitted_path,
+  bool LoadNativeLibrary(JNIEnv* env,
+                         const std::string& path,
+                         jobject class_loader,
+                         jstring library_path,
                          std::string* error_msg);
 
   // Unload native libraries with cleared class loaders.
index c177f19..df794e1 100644 (file)
@@ -67,9 +67,11 @@ static void SetLdLibraryPath(JNIEnv* env, jstring javaLdLibraryPath) {
 #endif
 }
 
-static jstring Runtime_nativeLoad(JNIEnv* env, jclass, jstring javaFilename, jobject javaLoader,
-                                  jboolean isSharedNamespace, jstring javaLibrarySearchPath,
-                                  jstring javaLibraryPermittedPath) {
+static jstring Runtime_nativeLoad(JNIEnv* env,
+                                  jclass,
+                                  jstring javaFilename,
+                                  jobject javaLoader,
+                                  jstring javaLibrarySearchPath) {
   ScopedUtfChars filename(env, javaFilename);
   if (filename.c_str() == nullptr) {
     return nullptr;
@@ -79,7 +81,9 @@ static jstring Runtime_nativeLoad(JNIEnv* env, jclass, jstring javaFilename, job
 
   // Starting with N nativeLoad uses classloader local
   // linker namespace instead of global LD_LIBRARY_PATH
-  // (23 is Marshmallow)
+  // (23 is Marshmallow). This call is here to preserve
+  // backwards compatibility for the apps targeting sdk
+  // version <= 23
   if (target_sdk_version == 0) {
     SetLdLibraryPath(env, javaLibrarySearchPath);
   }
@@ -90,9 +94,7 @@ static jstring Runtime_nativeLoad(JNIEnv* env, jclass, jstring javaFilename, job
     bool success = vm->LoadNativeLibrary(env,
                                          filename.c_str(),
                                          javaLoader,
-                                         isSharedNamespace == JNI_TRUE,
                                          javaLibrarySearchPath,
-                                         javaLibraryPermittedPath,
                                          &error_msg);
     if (success) {
       return nullptr;
@@ -121,7 +123,7 @@ static JNINativeMethod gMethods[] = {
   NATIVE_METHOD(Runtime, gc, "()V"),
   NATIVE_METHOD(Runtime, maxMemory, "!()J"),
   NATIVE_METHOD(Runtime, nativeExit, "(I)V"),
-  NATIVE_METHOD(Runtime, nativeLoad, "(Ljava/lang/String;Ljava/lang/ClassLoader;ZLjava/lang/String;Ljava/lang/String;)Ljava/lang/String;"),
+  NATIVE_METHOD(Runtime, nativeLoad, "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/String;"),
   NATIVE_METHOD(Runtime, totalMemory, "!()J"),
 };
 
index 725067a..d377457 100644 (file)
@@ -329,9 +329,10 @@ static void SetLdLibraryPath(JNIEnv* env, jstring javaLdLibraryPath) {
 }
 
 
-JNIEXPORT jstring JVM_NativeLoad(JNIEnv* env, jstring javaFilename, jobject javaLoader,
-                                 jboolean isSharedNamespace, jstring javaLibrarySearchPath,
-                                 jstring javaLibraryPermittedPath) {
+JNIEXPORT jstring JVM_NativeLoad(JNIEnv* env,
+                                 jstring javaFilename,
+                                 jobject javaLoader,
+                                 jstring javaLibrarySearchPath) {
   ScopedUtfChars filename(env, javaFilename);
   if (filename.c_str() == NULL) {
     return NULL;
@@ -354,9 +355,7 @@ JNIEXPORT jstring JVM_NativeLoad(JNIEnv* env, jstring javaFilename, jobject java
     bool success = vm->LoadNativeLibrary(env,
                                          filename.c_str(),
                                          javaLoader,
-                                         isSharedNamespace == JNI_TRUE,
                                          javaLibrarySearchPath,
-                                         javaLibraryPermittedPath,
                                          &error_msg);
     if (success) {
       return nullptr;
index eb5455a..a82974c 100644 (file)
@@ -1276,9 +1276,7 @@ void Runtime::InitNativeMethods() {
   // libcore can't because it's the library that implements System.loadLibrary!
   {
     std::string error_msg;
-    if (!java_vm_->LoadNativeLibrary(env, "libjavacore.so", nullptr,
-                                     /* is_shared_namespace */ false,
-                                     nullptr, nullptr, &error_msg)) {
+    if (!java_vm_->LoadNativeLibrary(env, "libjavacore.so", nullptr, nullptr, &error_msg)) {
       LOG(FATAL) << "LoadNativeLibrary failed for \"libjavacore.so\": " << error_msg;
     }
   }
@@ -1287,9 +1285,7 @@ void Runtime::InitNativeMethods() {
                                                 ? "libopenjdkd.so"
                                                 : "libopenjdk.so";
     std::string error_msg;
-    if (!java_vm_->LoadNativeLibrary(env, kOpenJdkLibrary, nullptr,
-                                     /* is_shared_namespace */ false,
-                                     nullptr, nullptr, &error_msg)) {
+    if (!java_vm_->LoadNativeLibrary(env, kOpenJdkLibrary, nullptr, nullptr, &error_msg)) {
       LOG(FATAL) << "LoadNativeLibrary failed for \"" << kOpenJdkLibrary << "\": " << error_msg;
     }
   }
index cfa8329..d288943 100644 (file)
@@ -385,7 +385,7 @@ void WellKnownClasses::LateInit(JNIEnv* env) {
   ScopedLocalRef<jclass> java_lang_Runtime(env, env->FindClass("java/lang/Runtime"));
   java_lang_Runtime_nativeLoad =
       CacheMethod(env, java_lang_Runtime.get(), true, "nativeLoad",
-                  "(Ljava/lang/String;Ljava/lang/ClassLoader;ZLjava/lang/String;Ljava/lang/String;)"
+                  "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;)"
                       "Ljava/lang/String;");
 }