| 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();
|
| }
|
|
|