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

Commit 5260ad78 authored by Nicolas Geoffray's avatar Nicolas Geoffray Committed by Automerger Merge Worker
Browse files

Merge "Cleanup and consistency around system server profiling." am: 6cbc807a...

Merge "Cleanup and consistency around system server profiling." am: 6cbc807a am: e60487c7 am: 40b18ebd

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2251513



Change-Id: I1c7e329acf9d7e3d0443150e937fa9c58e001343
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents f970f6f7 40b18ebd
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -87,6 +87,10 @@ public final class SystemServerClassLoaderFactory {
        if (isTestOnly) {
            return true;
        }
        // If system server is being profiled, it's OK to create class loaders anytime.
        if (ZygoteInit.shouldProfileSystemServer()) {
            return true;
        }
        return false;
    }

+23 −18
Original line number Diff line number Diff line
@@ -238,6 +238,21 @@ public class ZygoteInit {
        Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
    }

    private static boolean isExperimentEnabled(String experiment) {
        boolean defaultValue = SystemProperties.getBoolean(
                "dalvik.vm." + experiment,
                /*def=*/false);
        // Can't use device_config since we are the zygote, and it's not initialized at this point.
        return SystemProperties.getBoolean(
                "persist.device_config." + DeviceConfig.NAMESPACE_RUNTIME_NATIVE_BOOT
                        + "." + experiment,
                defaultValue);
    }

    /* package-private */ static boolean shouldProfileSystemServer() {
        return isExperimentEnabled("profilesystemserver");
    }

    /**
     * Performs Zygote process initialization. Loads and initializes commonly used classes.
     *
@@ -341,14 +356,7 @@ public class ZygoteInit {
            // If we are profiling the boot image, reset the Jit counters after preloading the
            // classes. We want to preload for performance, and we can use method counters to
            // infer what clases are used after calling resetJitCounters, for profile purposes.
            // Can't use device_config since we are the zygote.
            String prop = SystemProperties.get(
                    "persist.device_config.runtime_native_boot.profilebootclasspath", "");
            // Might be empty if the property is unset since the default is "".
            if (prop.length() == 0) {
                prop = SystemProperties.get("dalvik.vm.profilebootclasspath", "");
            }
            if ("true".equals(prop)) {
            if (isExperimentEnabled("profilebootclasspath")) {
                Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "ResetJitCounters");
                VMRuntime.resetJitCounters();
                Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
@@ -489,16 +497,6 @@ public class ZygoteInit {
        ZygoteHooks.gcAndFinalize();
    }

    private static boolean shouldProfileSystemServer() {
        boolean defaultValue = SystemProperties.getBoolean("dalvik.vm.profilesystemserver",
                /*default=*/ false);
        // Can't use DeviceConfig since it's not initialized at this point.
        return SystemProperties.getBoolean(
                "persist.device_config." + DeviceConfig.NAMESPACE_RUNTIME_NATIVE_BOOT
                        + ".profilesystemserver",
                defaultValue);
    }

    /**
     * Finish remaining work for the newly forked system server process.
     */
@@ -585,6 +583,13 @@ public class ZygoteInit {
     * in the forked system server process in the zygote SELinux domain.
     */
    private static void prefetchStandaloneSystemServerJars() {
        if (shouldProfileSystemServer()) {
            // We don't prefetch AOT artifacts if we are profiling system server, as we are going to
            // JIT it.
            // This method only gets called from native and should already be skipped if we profile
            // system server. Still, be robust and check it again.
            return;
        }
        String envStr = Os.getenv("STANDALONE_SYSTEMSERVER_JARS");
        if (TextUtils.isEmpty(envStr)) {
            return;
+4 −1
Original line number Diff line number Diff line
@@ -343,6 +343,7 @@ enum MountExternalKind {
// Must match values in com.android.internal.os.Zygote.
enum RuntimeFlags : uint32_t {
    DEBUG_ENABLE_JDWP = 1,
    PROFILE_SYSTEM_SERVER = 1 << 14,
    PROFILE_FROM_SHELL = 1 << 15,
    MEMORY_TAG_LEVEL_MASK = (1 << 19) | (1 << 20),
    MEMORY_TAG_LEVEL_TBI = 1 << 19,
@@ -1821,9 +1822,11 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids,
                                           instruction_set.value().c_str());
    }

    if (is_system_server) {
    if (is_system_server && !(runtime_flags & RuntimeFlags::PROFILE_SYSTEM_SERVER)) {
        // Prefetch the classloader for the system server. This is done early to
        // allow a tie-down of the proper system server selinux domain.
        // We don't prefetch when the system server is being profiled to avoid
        // loading AOT code.
        env->CallStaticObjectMethod(gZygoteInitClass, gGetOrCreateSystemServerClassLoader);
        if (env->ExceptionCheck()) {
            // Be robust here. The Java code will attempt to create the classloader