From 991ff90e73eec80b4c98ab899ee0a69192c5cbed Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Mon, 3 Dec 2018 10:59:29 +0000 Subject: [PATCH] Move DexLoadReporter setup before AppComponentFactory calls BaseDexClassLoader has a callback for reporting all loaded secondary dex files to DexManager. The callback needs to be set up: (a) after the default app class loader is initialized, so as to not report the app's main APK being loaded, and (b) before control is handed over to the app for the first time, so as to not miss any BaseDexClassLoader instantiations. The latter used to mean setting up the callback before Application.onCreate() but AppComponentFactory calls happen even earlier. Hence move the call into LoadedApk where the borderline between (a) and (b) lies. Test: manually check dex loads from instantiateClassLoader are reported Change-Id: I7961913de302bcede6c231304544d21d8db806a8 --- core/java/android/app/ActivityThread.java | 11 ----------- core/java/android/app/LoadedApk.java | 10 ++++++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 91a00766229c3..0a238588787d1 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -152,7 +152,6 @@ import com.android.org.conscrypt.OpenSSLSocketImpl; import com.android.org.conscrypt.TrustedCertificateStore; import com.android.server.am.MemInfoDumpProto; -import dalvik.system.BaseDexClassLoader; import dalvik.system.CloseGuard; import dalvik.system.VMDebug; import dalvik.system.VMRuntime; @@ -5862,16 +5861,6 @@ public final class ActivityThread extends ClientTransactionHandler { ThreadedRenderer.setIsolatedProcess(true); } - // If we use profiles, setup the dex reporter to notify package manager - // of any relevant dex loads. The idle maintenance job will use the information - // reported to optimize the loaded dex files. - // Note that we only need one global reporter per app. - // Make sure we do this before calling onCreate so that we can capture the - // complete application startup. - if (SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) { - BaseDexClassLoader.setReporter(DexLoadReporter.getInstance()); - } - // Install the Network Security Config Provider. This must happen before the application // code is loaded to prevent issues with instances of TLS objects being created before // the provider is installed. diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java index da4f77baac41a..1a2d7fdcbb10e 100644 --- a/core/java/android/app/LoadedApk.java +++ b/core/java/android/app/LoadedApk.java @@ -56,6 +56,7 @@ import android.view.DisplayAdjustments; import com.android.internal.util.ArrayUtils; +import dalvik.system.BaseDexClassLoader; import dalvik.system.VMRuntime; import java.io.File; @@ -860,6 +861,15 @@ public final class LoadedApk { if (!SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) { return; } + + // If we use profiles, setup the dex reporter to notify package manager + // of any relevant dex loads. The idle maintenance job will use the information + // reported to optimize the loaded dex files. + // Note that we only need one global reporter per app. + // Make sure we do this before invoking app code for the first time so that we + // can capture the complete application startup. + BaseDexClassLoader.setReporter(DexLoadReporter.getInstance()); + // Only set up profile support if the loaded apk has the same uid as the // current process. // Currently, we do not support profiling across different apps.