Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Unified Diff: base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java

Issue 1001343002: Prefetch the native library from native code by parsing /proc/pid/maps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-use existing /proc/maps parsing code. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java
diff --git a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java
index 484c6bc56d55596cdf77610e3cbf8e541c4d3d67..96b9c23508b2c8b1da6d7578557cc0e68d1264f7 100644
--- a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java
+++ b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java
@@ -250,15 +250,23 @@ public class LibraryLoader {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
- // Note: AsyncTasks are executed in a low priority background
- // thread, which is the desired behavior here since we don't
- // want to interfere with the rest of the initialization.
- for (String library : NativeLibraries.LIBRARIES) {
- if (Linker.isChromiumLinkerLibrary(library)) {
- continue;
+ TraceEvent.begin("LibraryLoader.asyncPrefetchLibrariesToMemory");
+ // First, try to fork a new process to do the prefetch. If it
+ // fails, fall back to doing it by mapping the library.
+ boolean ok = nativeForkAndPrefetchNativeLibrary();
+ if (!ok) {
+ Log.w(TAG, "Forking a process to prefetch the native library failed.");
+ // AsyncTasks are executed in a low priority background
+ // thread, which is the desired behavior to avoid
+ // interfering with the rest of the initialization.
+ for (String library : NativeLibraries.LIBRARIES) {
+ if (Linker.isChromiumLinkerLibrary(library)) {
+ continue;
+ }
+ prefetchLibraryToMemory(context, library);
}
- prefetchLibraryToMemory(context, library);
}
+ TraceEvent.end("LibraryLoader.asyncPrefetchLibrariesToMemory");
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@@ -573,4 +581,9 @@ public class LibraryLoader {
// Get the version of the native library. This is needed so that we can check we
// have the right version before initializing the (rest of the) JNI.
private native String nativeGetVersionNumber();
+
+ // Finds the ranges corresponding to the native library pages, forks a new
+ // process to prefetch these pages and waits for it. The new process then
+ // terminates. This is blocking.
+ private static native boolean nativeForkAndPrefetchNativeLibrary();
}
« no previous file with comments | « no previous file | base/android/library_loader/library_loader_hooks.cc » ('j') | base/android/library_loader/library_prefetcher.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698