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..67e95144b1bda11dba8dd1ce92985c8b2a00b096 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."); |
+ // Note: AsyncTasks are executed in a low priority background |
pasko
2015/03/27 11:03:37
s/Note: //
Benoit L
2015/03/27 15:44:51
Done.
|
+ // thread, which is the desired behavior here since we don't |
pasko
2015/03/27 11:03:37
Please avoid using 'we' in comments, writing in th
Benoit L
2015/03/27 15:44:51
Done.
|
+ // want to interfere 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(); |
} |