Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d593993 authored by Neil Fuller's avatar Neil Fuller Committed by android-build-merger
Browse files

Merge "Break some dependencies on libcore internals"

am: f672c2bc

Change-Id: I234d938606b07a5116c39dfcc378d55bcd521c2d
parents 6565aae0 f672c2bc
Loading
Loading
Loading
Loading
+4 −11
Original line number Original line Diff line number Diff line
@@ -30,14 +30,13 @@ import android.util.Log;
import android.util.Slog;
import android.util.Slog;
import com.android.internal.logging.AndroidConfig;
import com.android.internal.logging.AndroidConfig;
import com.android.server.NetworkManagementSocketTagger;
import com.android.server.NetworkManagementSocketTagger;
import dalvik.system.RuntimeHooks;
import dalvik.system.VMRuntime;
import dalvik.system.VMRuntime;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Modifier;
import java.util.Objects;
import java.util.Objects;
import java.util.TimeZone;
import java.util.logging.LogManager;
import java.util.logging.LogManager;
import org.apache.harmony.luni.internal.util.TimezoneGetter;


/**
/**
 * Main entry point for runtime initialization.  Not for
 * Main entry point for runtime initialization.  Not for
@@ -195,19 +194,13 @@ public class RuntimeInit {
         * the default handler, but not the pre handler.
         * the default handler, but not the pre handler.
         */
         */
        LoggingHandler loggingHandler = new LoggingHandler();
        LoggingHandler loggingHandler = new LoggingHandler();
        Thread.setUncaughtExceptionPreHandler(loggingHandler);
        RuntimeHooks.setUncaughtExceptionPreHandler(loggingHandler);
        Thread.setDefaultUncaughtExceptionHandler(new KillApplicationHandler(loggingHandler));
        Thread.setDefaultUncaughtExceptionHandler(new KillApplicationHandler(loggingHandler));


        /*
        /*
         * Install a TimezoneGetter subclass for ZoneInfo.db
         * Install a time zone supplier that uses the Android persistent time zone system property.
         */
         */
        TimezoneGetter.setInstance(new TimezoneGetter() {
        RuntimeHooks.setTimeZoneIdSupplier(() -> SystemProperties.get("persist.sys.timezone"));
            @Override
            public String getId() {
                return SystemProperties.get("persist.sys.timezone");
            }
        });
        TimeZone.setDefault(null);


        /*
        /*
         * Sets handler for java.util.logging to use Android log facilities.
         * Sets handler for java.util.logging to use Android log facilities.
+12 −33
Original line number Original line Diff line number Diff line
@@ -21,9 +21,6 @@ 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.opengl.EGL14;
import android.opengl.EGL14;
import android.os.Build;
import android.os.Build;
import android.os.Environment;
import android.os.Environment;
@@ -122,9 +119,9 @@ public class ZygoteInit {


    static void preload(TimingsTraceLog bootTimingsTraceLog) {
    static void preload(TimingsTraceLog bootTimingsTraceLog) {
        Log.d(TAG, "begin preload");
        Log.d(TAG, "begin preload");
        bootTimingsTraceLog.traceBegin("BeginIcuCachePinning");
        bootTimingsTraceLog.traceBegin("BeginPreload");
        beginIcuCachePinning();
        beginPreload();
        bootTimingsTraceLog.traceEnd(); // BeginIcuCachePinning
        bootTimingsTraceLog.traceEnd(); // BeginPreload
        bootTimingsTraceLog.traceBegin("PreloadClasses");
        bootTimingsTraceLog.traceBegin("PreloadClasses");
        preloadClasses();
        preloadClasses();
        bootTimingsTraceLog.traceEnd(); // PreloadClasses
        bootTimingsTraceLog.traceEnd(); // PreloadClasses
@@ -142,7 +139,7 @@ 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();
        endPreload();
        warmUpJcaProviders();
        warmUpJcaProviders();
        Log.d(TAG, "end preload");
        Log.d(TAG, "end preload");


@@ -156,27 +153,16 @@ public class ZygoteInit {
        preload(new TimingsTraceLog("ZygoteInitTiming_lazy", Trace.TRACE_TAG_DALVIK));
        preload(new TimingsTraceLog("ZygoteInitTiming_lazy", Trace.TRACE_TAG_DALVIK));
    }
    }


    private static void beginIcuCachePinning() {
    private static void beginPreload() {
        // Pin ICU data in memory from this point that would normally be held by soft references.
        Log.i(TAG, "Calling ZygoteHooks.beginPreload()");
        // 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);
        ZygoteHooks.onBeginPreload();

        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() {
    private static void endPreload() {
        // All cache references created by ICU from this point will be soft.
        ZygoteHooks.onEndPreload();
        CacheValue.setStrength(CacheValue.Strength.SOFT);


        Log.i(TAG, "Uninstalled ICU cache reference pinning...");
        Log.i(TAG, "Called ZygoteHooks.endPreload()");
    }
    }


    private static void preloadSharedLibraries() {
    private static void preloadSharedLibraries() {
@@ -436,15 +422,8 @@ public class ZygoteInit {
     * softly- and final-reachable objects, along with any other garbage.
     * softly- and final-reachable objects, along with any other garbage.
     * This is only useful just before a fork().
     * This is only useful just before a fork().
     */
     */
    /*package*/ static void gcAndFinalize() {
    private static void gcAndFinalize() {
        final VMRuntime runtime = VMRuntime.getRuntime();
        ZygoteHooks.gcAndFinalize();

        /* runFinalizationSync() lets finalizers be called in Zygote,
         * which doesn't have a HeapWorker thread.
         */
        System.gc();
        runtime.runFinalizationSync();
        System.gc();
    }
    }


    /**
    /**