OSDN Git Service

Get the native bridge library from the framework.
authorCalin Juravle <calin@google.com>
Thu, 7 Aug 2014 13:53:41 +0000 (14:53 +0100)
committerCalin Juravle <calin@google.com>
Thu, 14 Aug 2014 11:08:15 +0000 (12:08 +0100)
Framework now passes the name of the native bridge to the runtime so
there's no need to do the reading in libart.

Bug: 16843953

(cherry picked from commit 421b6466977d4b1ccd453f23b7b492f219099702)

Change-Id: I9a0a8b8c64949e05c6f90bc846d68f0797640f6d

runtime/native_bridge.cc
runtime/parsed_options.cc

index 18532e2..d0b516b 100644 (file)
 
 namespace art {
 
-// Is native-bridge support enabled?
-static constexpr bool kNativeBridgeEnabled = true;
-
-// Default library name for native-bridge.
-static constexpr const char* kDefaultNativeBridge = "libnativebridge.so";
-
-#ifdef HAVE_ANDROID_OS
-// TODO: This will be removed once we have native-bridge command-line arguments.
-
-// Property that defines the library name of native-bridge.
-static constexpr const char* kPropNativeBridge = "persist.native.bridge";
-
-// Property that enables native-bridge.
-static constexpr const char* kPropEnableNativeBridge = "persist.enable.native.bridge";
-#endif
-
 // The symbol name exposed by native-bridge with the type of NativeBridgeCallbacks.
 static constexpr const char* kNativeBridgeInterfaceSymbol = "NativeBridgeItf";
 
@@ -208,22 +192,25 @@ static uint32_t GetNativeMethods(JNIEnv* env, jclass clazz, JNINativeMethod* met
   return count;
 }
 
-NativeBridgeArtCallbacks NativeBridgeArtItf = {
+static NativeBridgeArtCallbacks NativeBridgeArtItf = {
   GetMethodShorty,
   GetNativeMethodCount,
   GetNativeMethods
 };
 
 void SetNativeBridgeLibraryString(const std::string& nb_library_string) {
+  // This is called when the runtime starts and nothing is working concurrently
+  // so we don't need a lock here.
+
   native_bridge_library_string = nb_library_string;
-  // TODO: when given an empty string, set initialized_ to true and available_ to false. This
-  //       change is dependent on the property removal in Initialize().
-}
 
-bool NativeBridgeInitialize() {
-  if (!kNativeBridgeEnabled) {
-    return false;
+  if (native_bridge_library_string.empty()) {
+    initialized = true;
+    available = false;
   }
+}
+
+static bool NativeBridgeInitialize() {
   // TODO: Missing annotalysis static lock ordering of DEFAULT_MUTEX_ACQUIRED, place lock into
   // global order or remove.
   static Mutex lock("native bridge lock");
@@ -236,30 +223,7 @@ bool NativeBridgeInitialize() {
 
   available = false;
 
-  const char* libnb_path;
-
-  if (!native_bridge_library_string.empty()) {
-    libnb_path = native_bridge_library_string.c_str();
-  } else {
-    // TODO: Remove this once the frameworks side is completely implemented.
-
-    libnb_path = kDefaultNativeBridge;
-#ifdef HAVE_ANDROID_OS
-    char prop_buf[PROP_VALUE_MAX];
-    property_get(kPropEnableNativeBridge, prop_buf, "false");
-    if (strcmp(prop_buf, "true") != 0) {
-      initialized = true;
-      return false;
-    }
-
-    // If prop persist.native.bridge set, overwrite the default name.
-    int name_len = property_get(kPropNativeBridge, prop_buf, kDefaultNativeBridge);
-    if (name_len > 0)
-      libnb_path = prop_buf;
-#endif
-  }
-
-  void* handle = dlopen(libnb_path, RTLD_LAZY);
+  void* handle = dlopen(native_bridge_library_string.c_str(), RTLD_LAZY);
   if (handle != nullptr) {
     callbacks = reinterpret_cast<NativeBridgeCallbacks*>(dlsym(handle,
                                                                kNativeBridgeInterfaceSymbol));
index 49f6585..628add0 100644 (file)
@@ -596,7 +596,7 @@ bool ParsedOptions::Parse(const RuntimeOptions& options, bool ignore_unrecognize
         Usage("Unknown -Xverify option %s\n", verify_mode.c_str());
         return false;
       }
-    } else if (StartsWith(option, "-XX:NativeBridge=")) {
+    } else if (StartsWith(option, "-XX:NativeBridgeLibrary=")) {
       if (!ParseStringAfterChar(option, '=', &native_bridge_library_string_)) {
         return false;
       }