diff options
author | Dimitry Ivanov <dimitry@google.com> | 2016-02-10 14:09:22 -0800 |
---|---|---|
committer | Dimitry Ivanov <dimitry@google.com> | 2016-02-11 10:33:35 -0800 |
commit | 55bbb0d88ada4d7394411dba004d2af6086da6a4 (patch) | |
tree | 9ce61e69f089834f852383c5bf02c29010020248 /libnativeloader/native_loader.cpp | |
parent | 718625010d839481cdef5f0305f2622a0aa87cd8 (diff) |
Preload public native libraries
Preload libraries needed by the public namespace
at the earlier stage. This saves time on
InitPublicNamespace and saves memory because
the libraries are linked before zygote fork.
Bug: http://b/26409579
Change-Id: I59153a4180b930f31b542d8d2cb17b5d63c36774
(cherry picked from commit d68c8e9f84557484ef3e8a3ee03398d22f109fa8)
Diffstat (limited to 'libnativeloader/native_loader.cpp')
-rw-r--r-- | libnativeloader/native_loader.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp index 209ff1cc3..a7a071387 100644 --- a/libnativeloader/native_loader.cpp +++ b/libnativeloader/native_loader.cpp @@ -57,7 +57,9 @@ static const char* kPublicNativeLibraries = "libandroid.so:" class LibraryNamespaces { public: - LibraryNamespaces() : initialized_(false) { } + LibraryNamespaces() : initialized_(false) { + PreloadPublicLibraries(); + } android_namespace_t* GetOrCreate(JNIEnv* env, jobject class_loader, bool is_shared, @@ -103,15 +105,16 @@ class LibraryNamespaces { } private: - bool InitPublicNamespace(const char* library_path) { - // Make sure all the public libraries are loaded + void PreloadPublicLibraries() { + // android_init_namespaces() expects all the public libraries + // to be loaded so that they can be found by soname alone. std::vector<std::string> sonames = android::base::Split(kPublicNativeLibraries, ":"); for (const auto& soname : sonames) { - if (dlopen(soname.c_str(), RTLD_NOW | RTLD_NODELETE) == nullptr) { - return false; - } + dlopen(soname.c_str(), RTLD_NOW | RTLD_NODELETE); } + } + bool InitPublicNamespace(const char* library_path) { // Some apps call dlopen from generated code unknown to linker in which // case linker uses anonymous namespace. See b/25844435 for details. initialized_ = android_init_namespaces(kPublicNativeLibraries, library_path); |