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

Commit 91c72e79 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Adds support for restore dexopt flag"

parents 7d1604dc 2271b3e8
Loading
Loading
Loading
Loading
+32 −8
Original line number Diff line number Diff line
@@ -262,6 +262,17 @@ static std::string MapPropertyToArg(const std::string& property,
  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).
// e.g. dex2oatd vs dex2oat
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,
               bool debuggable,
               bool post_bootcomplete,
               bool for_restore,
               bool background_job_compile,
               int profile_fd,
               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_Xmx_arg = MapPropertyToArg("dalvik.vm.dex2oat-Xmx", "-Xmx%s");

        const char* threads_property = post_bootcomplete
                ? "dalvik.vm.dex2oat-threads"
                : "dalvik.vm.boot-dex2oat-threads";
        std::string dex2oat_threads_arg = MapPropertyToArg(threads_property, "-j%s");
        const char* cpu_set_property = post_bootcomplete
                ? "dalvik.vm.dex2oat-cpu-set"
                : "dalvik.vm.boot-dex2oat-cpu-set";
        std::string dex2oat_cpu_set_arg = MapPropertyToArg(cpu_set_property, "--cpu-set=%s");
        std::string threads_format = "-j%s";
        std::string dex2oat_threads_arg = post_bootcomplete
                ? (for_restore
                    ? MapPropertyToArgWithBackup(
                            "dalvik.vm.restore-dex2oat-threads",
                            "dalvik.vm.dex2oat-threads",
                            threads_format)
                    : 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;
        char* dex2oat_bootclasspath = getenv("DEX2OATBOOTCLASSPATH");
@@ -2075,6 +2097,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 generate_compact_dex = (dexopt_flags & DEXOPT_GENERATE_COMPACT_DEX) != 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.
    std::string oat_dir_str;
@@ -2191,6 +2214,7 @@ int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* ins
                      compiler_filter,
                      debuggable,
                      boot_complete,
                      for_restore,
                      background_job_compile,
                      reference_profile_fd.get(),
                      class_loader_context,
+3 −1
Original line number 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_GENERATE_COMPACT_DEX = 1 << 11;
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 */
constexpr int DEXOPT_MASK =
@@ -69,7 +70,8 @@ constexpr int DEXOPT_MASK =
    | DEXOPT_IDLE_BACKGROUND_JOB
    | DEXOPT_ENABLE_HIDDEN_API_CHECKS
    | DEXOPT_GENERATE_COMPACT_DEX
    | DEXOPT_GENERATE_APP_IMAGE;
    | DEXOPT_GENERATE_APP_IMAGE
    | DEXOPT_FOR_RESTORE;

// NOTE: keep in sync with StorageManager
constexpr int FLAG_STORAGE_DE = 1 << 0;
+1 −1
Original line number 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_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.");


+9 −0
Original line number Diff line number Diff line
@@ -643,6 +643,15 @@ TEST_F(DexoptTest, DexoptPrimaryPublicCreateOatDir) {
                        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) {
    LOG(INFO) << "DexoptPrimaryFailedInvalidFilter";
    binder::Status status;