Add PreloadPublicNativeLibraries function
Shift responsibility of preloading native libraries to the user of the library. This lets applications that do not use jni but depend on libnative_loader.so to avoid unnecessary preloads of public libraries which could be expensive. Bug: http://b/27245894 Change-Id: I12a8100de5da639c068769bca21ecebff2b2d538
This commit is contained in:
parent
b236ff7156
commit
426799d770
|
@ -25,6 +25,9 @@
|
|||
|
||||
namespace android {
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
void PreloadPublicNativeLibraries();
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
void* OpenNativeLibrary(JNIEnv* env, int32_t target_sdk_version, const char* path,
|
||||
jobject class_loader, bool is_shared, jstring library_path,
|
||||
|
|
|
@ -59,9 +59,7 @@ static const char* kPublicNativeLibraries = "libandroid.so:"
|
|||
|
||||
class LibraryNamespaces {
|
||||
public:
|
||||
LibraryNamespaces() : initialized_(false) {
|
||||
PreloadPublicLibraries();
|
||||
}
|
||||
LibraryNamespaces() : initialized_(false) { }
|
||||
|
||||
android_namespace_t* GetOrCreate(JNIEnv* env, jobject class_loader,
|
||||
bool is_shared,
|
||||
|
@ -114,7 +112,6 @@ class LibraryNamespaces {
|
|||
return it != namespaces_.end() ? it->second : nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
void PreloadPublicLibraries() {
|
||||
// android_init_namespaces() expects all the public libraries
|
||||
// to be loaded so that they can be found by soname alone.
|
||||
|
@ -124,6 +121,7 @@ class LibraryNamespaces {
|
|||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool InitPublicNamespace(const char* library_path, int32_t target_sdk_version) {
|
||||
// Some apps call dlopen from generated code unknown to linker in which
|
||||
// case linker uses anonymous namespace. See b/25844435 for details.
|
||||
|
@ -151,6 +149,12 @@ class LibraryNamespaces {
|
|||
static LibraryNamespaces* g_namespaces = new LibraryNamespaces;
|
||||
#endif
|
||||
|
||||
void PreloadPublicNativeLibraries() {
|
||||
#if defined(__ANDROID__)
|
||||
g_namespaces->PreloadPublicLibraries();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void* OpenNativeLibrary(JNIEnv* env, int32_t target_sdk_version, const char* path,
|
||||
jobject class_loader, bool is_shared, jstring java_library_path,
|
||||
|
|
Loading…
Reference in New Issue