From 5240863ed559cb4c2b121ddfbf6b3d78ac15e38f Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Mon, 23 May 2016 10:31:11 -0700 Subject: [PATCH] Do not resolve caller_ns when it is not needed 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 | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/linker/linker.cpp b/linker/linker.cpp index 09286c021..719b00a42 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -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;