OSDN Git Service

Do not resolve caller_ns when it is not needed
authorDimitry Ivanov <dimitry@google.com>
Mon, 23 May 2016 17:31:11 +0000 (10:31 -0700)
committerDimitry Ivanov <dimitry@google.com>
Mon, 23 May 2016 17:31:11 +0000 (10:31 -0700)
create_namespace resolves caller namespace only
when caller did not explicitly specify parent namespace.

This saves about 25 microseconds for the case when
parent_namepsace is not null (for example when creating
second classloader for the app).

Bug: http://b/28801010
Change-Id: I50ded272c931db701e5a1d8c88ed5ffb13416539

linker/linker.cpp

index 09286c0..719b00a 100644 (file)
@@ -2417,7 +2417,7 @@ bool init_namespaces(const char* public_ns_sonames, const char* anon_ns_library_
   // is still pointing to the default one.
   android_namespace_t* anon_ns =
       create_namespace(nullptr, "(anonymous)", nullptr, anon_ns_library_path,
-                       ANDROID_NAMESPACE_TYPE_REGULAR, nullptr, nullptr);
+                       ANDROID_NAMESPACE_TYPE_REGULAR, nullptr, &g_default_namespace);
 
   if (anon_ns == nullptr) {
     g_public_namespace_initialized = false;
@@ -2440,15 +2440,13 @@ android_namespace_t* create_namespace(const void* caller_addr,
     return nullptr;
   }
 
-  soinfo* caller_soinfo = find_containing_library(caller_addr);
-
-  android_namespace_t* caller_ns = caller_soinfo != nullptr ?
-                                   caller_soinfo->get_primary_namespace() :
-                                   g_anonymous_namespace;
-
-  // if parent_namespace is nullptr -> set it to the caller namespace
   if (parent_namespace == nullptr) {
-    parent_namespace = caller_ns;
+    // if parent_namespace is nullptr -> set it to the caller namespace
+    soinfo* caller_soinfo = find_containing_library(caller_addr);
+
+    parent_namespace = caller_soinfo != nullptr ?
+                       caller_soinfo->get_primary_namespace() :
+                       g_anonymous_namespace;
   }
 
   ProtectedDataGuard guard;