From c8a0442cad47728fcf433aed729a691268776f48 Mon Sep 17 00:00:00 2001 From: Calin Juravle Date: Fri, 1 May 2020 14:05:40 -0700 Subject: [PATCH] Handle the boot profile format when analyzing profiles When analyzing profiles for dexopt, use the boot image profile format if the system is configured to profile the boot image. Test: atest installd_dexopt_test Bug: 155423653 Change-Id: I83ff959389bafcfce291485f78e1b05d6ca42625 --- cmds/installd/dexopt.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp index ebca892139..ffa87249e2 100644 --- a/cmds/installd/dexopt.cpp +++ b/cmds/installd/dexopt.cpp @@ -318,6 +318,16 @@ static const char* kJitZygoteImage = // Phenotype property name for enabling profiling the boot class path. static const char* PROFILE_BOOT_CLASS_PATH = "profilebootclasspath"; +static bool IsBootClassPathProfilingEnable() { + std::string profile_boot_class_path = GetProperty("dalvik.vm.profilebootclasspath", ""); + profile_boot_class_path = + server_configurable_flags::GetServerConfigurableFlag( + RUNTIME_NATIVE_BOOT_NAMESPACE, + PROFILE_BOOT_CLASS_PATH, + /*default_value=*/ profile_boot_class_path); + return profile_boot_class_path == "true"; +} + class RunDex2Oat : public ExecVHelper { public: RunDex2Oat(int zip_fd, @@ -450,14 +460,7 @@ class RunDex2Oat : public ExecVHelper { ENABLE_JITZYGOTE_IMAGE, /*default_value=*/ ""); - std::string profile_boot_class_path = GetProperty("dalvik.vm.profilebootclasspath", ""); - profile_boot_class_path = - server_configurable_flags::GetServerConfigurableFlag( - RUNTIME_NATIVE_BOOT_NAMESPACE, - PROFILE_BOOT_CLASS_PATH, - /*default_value=*/ profile_boot_class_path); - - if (use_jitzygote_image == "true" || profile_boot_class_path == "true") { + if (use_jitzygote_image == "true" || IsBootClassPathProfilingEnable()) { boot_image = StringPrintf("--boot-image=%s", kJitZygoteImage); } else { boot_image = MapPropertyToArg("dalvik.vm.boot-image", "--boot-image=%s"); @@ -896,7 +899,15 @@ static bool analyze_profiles(uid_t uid, const std::string& package_name, } RunProfman profman_merge; - profman_merge.SetupMerge(profiles_fd, reference_profile_fd); + const std::vector& apk_fds = std::vector(); + const std::vector& dex_locations = std::vector(); + profman_merge.SetupMerge( + profiles_fd, + reference_profile_fd, + apk_fds, + dex_locations, + /* for_snapshot= */ false, + IsBootClassPathProfilingEnable()); pid_t pid = fork(); if (pid == 0) { /* child -- drop privileges before continuing */ @@ -2810,7 +2821,13 @@ static bool create_app_profile_snapshot(int32_t app_id, } RunProfman args; - args.SetupMerge(profiles_fd, snapshot_fd, apk_fds, dex_locations, /*for_snapshot=*/true); + // This is specifically a snapshot for an app, so don't use boot image profiles. + args.SetupMerge(profiles_fd, + snapshot_fd, + apk_fds, + dex_locations, + /* for_snapshot= */ true, + /* for_boot_image= */ false); pid_t pid = fork(); if (pid == 0) { /* child -- drop privileges before continuing */