Merge "Add support for ICU data pinning in the Zygote" into nyc-dev
am: 761f70d5a6
* commit '761f70d5a6b926780db3bba95ee1e01b4d8d95be':
Add support for ICU data pinning in the Zygote
Change-Id: If693e8cbb737186fdf0a3169d024bef08c8ceb6a
This commit is contained in:
@@ -22,6 +22,9 @@ import static android.system.OsConstants.S_IRWXO;
|
|||||||
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.icu.impl.CacheValue;
|
||||||
|
import android.icu.text.DecimalFormatSymbols;
|
||||||
|
import android.icu.util.ULocale;
|
||||||
import android.net.LocalServerSocket;
|
import android.net.LocalServerSocket;
|
||||||
import android.opengl.EGL14;
|
import android.opengl.EGL14;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
@@ -187,6 +190,9 @@ public class ZygoteInit {
|
|||||||
|
|
||||||
static void preload() {
|
static void preload() {
|
||||||
Log.d(TAG, "begin preload");
|
Log.d(TAG, "begin preload");
|
||||||
|
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "BeginIcuCachePinning");
|
||||||
|
beginIcuCachePinning();
|
||||||
|
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
|
||||||
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadClasses");
|
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadClasses");
|
||||||
preloadClasses();
|
preloadClasses();
|
||||||
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
|
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
|
||||||
@@ -201,10 +207,34 @@ public class ZygoteInit {
|
|||||||
// Ask the WebViewFactory to do any initialization that must run in the zygote process,
|
// Ask the WebViewFactory to do any initialization that must run in the zygote process,
|
||||||
// for memory sharing purposes.
|
// for memory sharing purposes.
|
||||||
WebViewFactory.prepareWebViewInZygote();
|
WebViewFactory.prepareWebViewInZygote();
|
||||||
|
endIcuCachePinning();
|
||||||
warmUpJcaProviders();
|
warmUpJcaProviders();
|
||||||
Log.d(TAG, "end preload");
|
Log.d(TAG, "end preload");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void beginIcuCachePinning() {
|
||||||
|
// Pin ICU data in memory from this point that would normally be held by soft references.
|
||||||
|
// Without this, any references created immediately below or during class preloading
|
||||||
|
// would be collected when the Zygote GC runs in gcAndFinalize().
|
||||||
|
Log.i(TAG, "Installing ICU cache reference pinning...");
|
||||||
|
|
||||||
|
CacheValue.setStrength(CacheValue.Strength.STRONG);
|
||||||
|
|
||||||
|
Log.i(TAG, "Preloading ICU data...");
|
||||||
|
// Explicitly exercise code to cache data apps are likely to need.
|
||||||
|
ULocale[] localesToPin = { ULocale.ROOT, ULocale.US, ULocale.getDefault() };
|
||||||
|
for (ULocale uLocale : localesToPin) {
|
||||||
|
new DecimalFormatSymbols(uLocale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void endIcuCachePinning() {
|
||||||
|
// All cache references created by ICU from this point will be soft.
|
||||||
|
CacheValue.setStrength(CacheValue.Strength.SOFT);
|
||||||
|
|
||||||
|
Log.i(TAG, "Uninstalled ICU cache reference pinning...");
|
||||||
|
}
|
||||||
|
|
||||||
private static void preloadSharedLibraries() {
|
private static void preloadSharedLibraries() {
|
||||||
Log.i(TAG, "Preloading shared libraries...");
|
Log.i(TAG, "Preloading shared libraries...");
|
||||||
System.loadLibrary("android");
|
System.loadLibrary("android");
|
||||||
|
|||||||
Reference in New Issue
Block a user