OSDN Git Service

Precreate the classloader for the WebView.
authorTorne (Richard Coles) <torne@google.com>
Mon, 10 Oct 2016 14:11:36 +0000 (15:11 +0100)
committerTorne (Richard Coles) <torne@google.com>
Mon, 21 Nov 2016 15:04:13 +0000 (15:04 +0000)
commit3b6ca99b1069e8f303727a00c1da7acabe017fd8
tree1f99e1e944f4c4f3d5ecb08b78a88ad63ad8d608
parent82c9ba9c55c20b6e26a49c15c5f08f0c66e27d9b
Precreate the classloader for the WebView.

We want to create the classloader for the WebView in advance in the
zygote so that it can preload Java and native code for its children, but
the zygote can't talk to the package manager (so doesn't have a
PackageInfo for the APK) and also doesn't have an ActivityThread, so
constructing a LoadedApk is difficult.

Instead, we use the fact that ApplicationLoaders contains a
process-global cache of classloaders for APKs, and prepopulate a cache
entry without constructing a LoadedApk. This requires making
ApplicationLoaders public. To calculate the correct library paths from
the information the zygote has, we reuse the logic in LoadedApk (which
is already public, and just needs a small change to allow a null
ActivityThread when checking for instrumentation).

The other parameters for classloader creation (target SDK, bundled app,
etc) are hardcoded to usable values for the WebView's case. WebView
never needs to use any system libraries that aren't public so claiming
it's not bundled is fine even when that isn't actually true, and WebView
will always target the current platform API level.

Once the classloader is created, look up the factory class and call
preloadInZygote on it to give it a chance to preload the native library
and do other shared initialisation.

Bug: 21643067
Test: enable multiprocess WebView, examine librank output to see sharing
Change-Id: I696ead637e3f7382bcc58cfaf61eac5921862015
core/java/android/app/ApplicationLoaders.java
core/java/android/app/LoadedApk.java
core/java/android/webkit/WebViewFactory.java
core/java/android/webkit/WebViewZygote.java
core/java/com/android/internal/os/WebViewZygoteInit.java