From d3c72db3bb210939ca9ff814577e00111baf4018 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Wed, 23 Oct 2019 09:53:39 -0700 Subject: [PATCH] Avoid preloading classes for boot image profiling Since the clinits may execute methods, we should avoid preloading classes to avoid executing methods that may not be required. These samples could cause inaccuracy in the boot image profile. Test: manual: adb logcat | grep preloadClasses Bug: 139883463 Change-Id: I5b4568a477724606105196cba010109f80eecec1 --- core/java/com/android/internal/os/ZygoteInit.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index 72d24645a2e7e..ad4c6dd7a92b3 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -248,6 +248,18 @@ public class ZygoteInit { InputStream is; try { + // If we are profiling the boot image, avoid preloading classes. + // 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)) { + return; + } + is = new FileInputStream(PRELOADED_CLASSES); } catch (FileNotFoundException e) { Log.e(TAG, "Couldn't find " + PRELOADED_CLASSES + ".");