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

Commit 00d3f4f8 authored by Patrick Baumann's avatar Patrick Baumann
Browse files

Adds support for restore dexopt flag

This change adds support for a restore dexopt flag that modifies
installd to start dex2oat with a custom cpu set.

Bug: 135202722
Test: manual;adb install --install-reason 2 <apk>
Change-Id: If9ff54277d02d54c7b2dbb2659b708de6eecd500
parent e22e38d2
Loading
Loading
Loading
Loading
+32 −8
Original line number Original line Diff line number Diff line
@@ -262,6 +262,17 @@ static std::string MapPropertyToArg(const std::string& property,
  return "";
  return "";
}
}


static std::string MapPropertyToArgWithBackup(const std::string& property,
                                              const std::string& backupProperty,
                                              const std::string& format,
                                              const std::string& default_value = "") {
  std::string value = GetProperty(property, default_value);
  if (!value.empty()) {
    return StringPrintf(format.c_str(), value.c_str());
  }
  return MapPropertyToArg(backupProperty, format, default_value);
}

// Determines which binary we should use for execution (the debug or non-debug version).
// Determines which binary we should use for execution (the debug or non-debug version).
// e.g. dex2oatd vs dex2oat
// e.g. dex2oatd vs dex2oat
static const char* select_execution_binary(const char* binary, const char* debug_binary,
static const char* select_execution_binary(const char* binary, const char* debug_binary,
@@ -321,6 +332,7 @@ class RunDex2Oat : public ExecVHelper {
               const char* compiler_filter,
               const char* compiler_filter,
               bool debuggable,
               bool debuggable,
               bool post_bootcomplete,
               bool post_bootcomplete,
               bool for_restore,
               bool background_job_compile,
               bool background_job_compile,
               int profile_fd,
               int profile_fd,
               const char* class_loader_context,
               const char* class_loader_context,
@@ -336,14 +348,24 @@ class RunDex2Oat : public ExecVHelper {
        std::string dex2oat_Xms_arg = MapPropertyToArg("dalvik.vm.dex2oat-Xms", "-Xms%s");
        std::string dex2oat_Xms_arg = MapPropertyToArg("dalvik.vm.dex2oat-Xms", "-Xms%s");
        std::string dex2oat_Xmx_arg = MapPropertyToArg("dalvik.vm.dex2oat-Xmx", "-Xmx%s");
        std::string dex2oat_Xmx_arg = MapPropertyToArg("dalvik.vm.dex2oat-Xmx", "-Xmx%s");


        const char* threads_property = post_bootcomplete
        std::string threads_format = "-j%s";
                ? "dalvik.vm.dex2oat-threads"
        std::string dex2oat_threads_arg = post_bootcomplete
                : "dalvik.vm.boot-dex2oat-threads";
                ? (for_restore
        std::string dex2oat_threads_arg = MapPropertyToArg(threads_property, "-j%s");
                    ? MapPropertyToArgWithBackup(
        const char* cpu_set_property = post_bootcomplete
                            "dalvik.vm.restore-dex2oat-threads",
                ? "dalvik.vm.dex2oat-cpu-set"
                            "dalvik.vm.dex2oat-threads",
                : "dalvik.vm.boot-dex2oat-cpu-set";
                            threads_format)
        std::string dex2oat_cpu_set_arg = MapPropertyToArg(cpu_set_property, "--cpu-set=%s");
                    : MapPropertyToArg("dalvik.vm.dex2oat-threads", threads_format))
                : MapPropertyToArg("dalvik.vm.boot-dex2oat-threads", threads_format);
        std::string cpu_set_format = "--cpu-set=%s";
        std::string dex2oat_cpu_set_arg = post_bootcomplete
                ? (for_restore
                    ? MapPropertyToArgWithBackup(
                            "dalvik.vm.restore-dex2oat-cpu-set",
                            "dalvik.vm.dex2oat-cpu-set",
                            cpu_set_format)
                    : MapPropertyToArg("dalvik.vm.dex2oat-cpu-set", cpu_set_format))
                : MapPropertyToArg("dalvik.vm.boot-dex2oat-cpu-set", cpu_set_format);


        std::string bootclasspath;
        std::string bootclasspath;
        char* dex2oat_bootclasspath = getenv("DEX2OATBOOTCLASSPATH");
        char* dex2oat_bootclasspath = getenv("DEX2OATBOOTCLASSPATH");
@@ -2066,6 +2088,7 @@ int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* ins
    bool enable_hidden_api_checks = (dexopt_flags & DEXOPT_ENABLE_HIDDEN_API_CHECKS) != 0;
    bool enable_hidden_api_checks = (dexopt_flags & DEXOPT_ENABLE_HIDDEN_API_CHECKS) != 0;
    bool generate_compact_dex = (dexopt_flags & DEXOPT_GENERATE_COMPACT_DEX) != 0;
    bool generate_compact_dex = (dexopt_flags & DEXOPT_GENERATE_COMPACT_DEX) != 0;
    bool generate_app_image = (dexopt_flags & DEXOPT_GENERATE_APP_IMAGE) != 0;
    bool generate_app_image = (dexopt_flags & DEXOPT_GENERATE_APP_IMAGE) != 0;
    bool for_restore = (dexopt_flags & DEXOPT_FOR_RESTORE) != 0;


    // Check if we're dealing with a secondary dex file and if we need to compile it.
    // Check if we're dealing with a secondary dex file and if we need to compile it.
    std::string oat_dir_str;
    std::string oat_dir_str;
@@ -2182,6 +2205,7 @@ int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* ins
                      compiler_filter,
                      compiler_filter,
                      debuggable,
                      debuggable,
                      boot_complete,
                      boot_complete,
                      for_restore,
                      background_job_compile,
                      background_job_compile,
                      reference_profile_fd.get(),
                      reference_profile_fd.get(),
                      class_loader_context,
                      class_loader_context,
+3 −1
Original line number Original line Diff line number Diff line
@@ -55,6 +55,7 @@ constexpr int DEXOPT_IDLE_BACKGROUND_JOB = 1 << 9;
constexpr int DEXOPT_ENABLE_HIDDEN_API_CHECKS = 1 << 10;
constexpr int DEXOPT_ENABLE_HIDDEN_API_CHECKS = 1 << 10;
constexpr int DEXOPT_GENERATE_COMPACT_DEX = 1 << 11;
constexpr int DEXOPT_GENERATE_COMPACT_DEX = 1 << 11;
constexpr int DEXOPT_GENERATE_APP_IMAGE = 1 << 12;
constexpr int DEXOPT_GENERATE_APP_IMAGE = 1 << 12;
constexpr int DEXOPT_FOR_RESTORE = 1 << 13; // TODO(b/135202722): remove


/* all known values for dexopt flags */
/* all known values for dexopt flags */
constexpr int DEXOPT_MASK =
constexpr int DEXOPT_MASK =
@@ -69,7 +70,8 @@ constexpr int DEXOPT_MASK =
    | DEXOPT_IDLE_BACKGROUND_JOB
    | DEXOPT_IDLE_BACKGROUND_JOB
    | DEXOPT_ENABLE_HIDDEN_API_CHECKS
    | DEXOPT_ENABLE_HIDDEN_API_CHECKS
    | DEXOPT_GENERATE_COMPACT_DEX
    | DEXOPT_GENERATE_COMPACT_DEX
    | DEXOPT_GENERATE_APP_IMAGE;
    | DEXOPT_GENERATE_APP_IMAGE
    | DEXOPT_FOR_RESTORE;


// NOTE: keep in sync with StorageManager
// NOTE: keep in sync with StorageManager
constexpr int FLAG_STORAGE_DE = 1 << 0;
constexpr int FLAG_STORAGE_DE = 1 << 0;
+1 −1
Original line number Original line Diff line number Diff line
@@ -83,7 +83,7 @@ static_assert(DEXOPT_ENABLE_HIDDEN_API_CHECKS == 1 << 10,
static_assert(DEXOPT_GENERATE_COMPACT_DEX == 1 << 11, "DEXOPT_GENERATE_COMPACT_DEX unexpected");
static_assert(DEXOPT_GENERATE_COMPACT_DEX == 1 << 11, "DEXOPT_GENERATE_COMPACT_DEX unexpected");
static_assert(DEXOPT_GENERATE_APP_IMAGE == 1 << 12, "DEXOPT_GENERATE_APP_IMAGE unexpected");
static_assert(DEXOPT_GENERATE_APP_IMAGE == 1 << 12, "DEXOPT_GENERATE_APP_IMAGE unexpected");


static_assert(DEXOPT_MASK           == (0x1dfe | DEXOPT_IDLE_BACKGROUND_JOB),
static_assert(DEXOPT_MASK           == (0x3dfe | DEXOPT_IDLE_BACKGROUND_JOB),
              "DEXOPT_MASK unexpected.");
              "DEXOPT_MASK unexpected.");




+9 −0
Original line number Original line Diff line number Diff line
@@ -653,6 +653,15 @@ TEST_F(DexoptTest, DexoptPrimaryPublicCreateOatDir) {
                        DEX2OAT_FROM_SCRATCH);
                        DEX2OAT_FROM_SCRATCH);
}
}


TEST_F(DexoptTest, DexoptPrimaryPublicRestore) {
    LOG(INFO) << "DexoptPrimaryPublicRestore";
    CompilePrimaryDexOk("verify",
                        DEXOPT_FOR_RESTORE | DEXOPT_BOOTCOMPLETE | DEXOPT_PUBLIC,
                        app_oat_dir_.c_str(),
                        kTestAppGid,
                        DEX2OAT_FROM_SCRATCH);
}

TEST_F(DexoptTest, DexoptPrimaryFailedInvalidFilter) {
TEST_F(DexoptTest, DexoptPrimaryFailedInvalidFilter) {
    LOG(INFO) << "DexoptPrimaryFailedInvalidFilter";
    LOG(INFO) << "DexoptPrimaryFailedInvalidFilter";
    binder::Status status;
    binder::Status status;