diff options
-rw-r--r-- | cmds/installd/dexopt.cpp | 2 | ||||
-rw-r--r-- | cmds/installd/run_dex2oat.cpp | 21 | ||||
-rw-r--r-- | cmds/installd/run_dex2oat.h | 5 | ||||
-rw-r--r-- | cmds/installd/run_dex2oat_test.cpp | 50 |
4 files changed, 72 insertions, 6 deletions
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp index ebb78913b1..34ea7597b4 100644 --- a/cmds/installd/dexopt.cpp +++ b/cmds/installd/dexopt.cpp @@ -1956,7 +1956,7 @@ int dexopt(const char* dex_path, uid_t uid, const char* pkgname, const char* ins join_fds(context_input_fds), swap_fd.get(), instruction_set, compiler_filter, debuggable, boot_complete, for_restore, target_sdk_version, enable_hidden_api_checks, generate_compact_dex, use_jitzygote_image, - compilation_reason); + background_job_compile, compilation_reason); bool cancelled = false; pid_t pid = dexopt_status_->check_cancellation_and_fork(&cancelled); diff --git a/cmds/installd/run_dex2oat.cpp b/cmds/installd/run_dex2oat.cpp index 51c4589440..4221a3a593 100644 --- a/cmds/installd/run_dex2oat.cpp +++ b/cmds/installd/run_dex2oat.cpp @@ -81,6 +81,7 @@ void RunDex2Oat::Initialize(const UniqueFile& output_oat, bool enable_hidden_api_checks, bool generate_compact_dex, bool use_jitzygote, + bool background_job_compile, const char* compilation_reason) { PrepareBootImageFlags(use_jitzygote); @@ -92,7 +93,8 @@ void RunDex2Oat::Initialize(const UniqueFile& output_oat, debuggable, target_sdk_version, enable_hidden_api_checks, generate_compact_dex, compilation_reason); - PrepareCompilerRuntimeAndPerfConfigFlags(post_bootcomplete, for_restore); + PrepareCompilerRuntimeAndPerfConfigFlags(post_bootcomplete, for_restore, + background_job_compile); const std::string dex2oat_flags = GetProperty("dalvik.vm.dex2oat-flags", ""); std::vector<std::string> dex2oat_flags_args = SplitBySpaces(dex2oat_flags); @@ -296,7 +298,8 @@ void RunDex2Oat::PrepareCompilerConfigFlags(const UniqueFile& input_vdex, } void RunDex2Oat::PrepareCompilerRuntimeAndPerfConfigFlags(bool post_bootcomplete, - bool for_restore) { + bool for_restore, + bool background_job_compile) { // CPU set { std::string cpu_set_format = "--cpu-set=%s"; @@ -306,7 +309,12 @@ void RunDex2Oat::PrepareCompilerRuntimeAndPerfConfigFlags(bool post_bootcomplete "dalvik.vm.restore-dex2oat-cpu-set", "dalvik.vm.dex2oat-cpu-set", cpu_set_format) - : MapPropertyToArg("dalvik.vm.dex2oat-cpu-set", cpu_set_format)) + : (background_job_compile + ? MapPropertyToArgWithBackup( + "dalvik.vm.background-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); AddArg(dex2oat_cpu_set_arg); } @@ -320,7 +328,12 @@ void RunDex2Oat::PrepareCompilerRuntimeAndPerfConfigFlags(bool post_bootcomplete "dalvik.vm.restore-dex2oat-threads", "dalvik.vm.dex2oat-threads", threads_format) - : MapPropertyToArg("dalvik.vm.dex2oat-threads", threads_format)) + : (background_job_compile + ? MapPropertyToArgWithBackup( + "dalvik.vm.background-dex2oat-threads", + "dalvik.vm.dex2oat-threads", + threads_format) + : MapPropertyToArg("dalvik.vm.dex2oat-threads", threads_format))) : MapPropertyToArg("dalvik.vm.boot-dex2oat-threads", threads_format); AddArg(dex2oat_threads_arg); } diff --git a/cmds/installd/run_dex2oat.h b/cmds/installd/run_dex2oat.h index 559244f2b7..c13e1f1acb 100644 --- a/cmds/installd/run_dex2oat.h +++ b/cmds/installd/run_dex2oat.h @@ -51,6 +51,7 @@ class RunDex2Oat { bool enable_hidden_api_checks, bool generate_compact_dex, bool use_jitzygote, + bool background_job_compile, const char* compilation_reason); void Exec(int exit_code); @@ -76,7 +77,9 @@ class RunDex2Oat { bool enable_hidden_api_checks, bool generate_compact_dex, const char* compilation_reason); - void PrepareCompilerRuntimeAndPerfConfigFlags(bool post_bootcomplete, bool for_restore); + void PrepareCompilerRuntimeAndPerfConfigFlags(bool post_bootcomplete, + bool for_restore, + bool background_job_compile); virtual std::string GetProperty(const std::string& key, const std::string& default_value); virtual bool GetBoolProperty(const std::string& key, bool default_value); diff --git a/cmds/installd/run_dex2oat_test.cpp b/cmds/installd/run_dex2oat_test.cpp index 2a8135a037..304ba7b04f 100644 --- a/cmds/installd/run_dex2oat_test.cpp +++ b/cmds/installd/run_dex2oat_test.cpp @@ -115,6 +115,7 @@ class RunDex2OatTest : public testing::Test { bool enable_hidden_api_checks = false; bool generate_compact_dex = true; bool use_jitzygote = false; + bool background_job_compile = false; const char* compilation_reason = nullptr; }; @@ -259,6 +260,7 @@ class RunDex2OatTest : public testing::Test { args->enable_hidden_api_checks, args->generate_compact_dex, args->use_jitzygote, + args->background_job_compile, args->compilation_reason); runner.Exec(/*exit_code=*/ 0); } @@ -375,6 +377,30 @@ TEST_F(RunDex2OatTest, CpuSetPostBootCompleteNotForRestore) { VerifyExpectedFlags(); } +TEST_F(RunDex2OatTest, CpuSetPostBootCompleteBackground) { + setSystemProperty("dalvik.vm.background-dex2oat-cpu-set", "1,3"); + setSystemProperty("dalvik.vm.dex2oat-cpu-set", "1,2"); + auto args = RunDex2OatArgs::MakeDefaultTestArgs(); + args->post_bootcomplete = true; + args->background_job_compile = true; + CallRunDex2Oat(std::move(args)); + + SetExpectedFlagUsed("--cpu-set", "=1,3"); + VerifyExpectedFlags(); +} + +TEST_F(RunDex2OatTest, CpuSetPostBootCompleteBackground_Backup) { + setSystemProperty("dalvik.vm.background-dex2oat-cpu-set", ""); + setSystemProperty("dalvik.vm.dex2oat-cpu-set", "1,2"); + auto args = RunDex2OatArgs::MakeDefaultTestArgs(); + args->post_bootcomplete = true; + args->background_job_compile = true; + CallRunDex2Oat(std::move(args)); + + SetExpectedFlagUsed("--cpu-set", "=1,2"); + VerifyExpectedFlags(); +} + TEST_F(RunDex2OatTest, CpuSetPostBootCompleteForRestore) { setSystemProperty("dalvik.vm.restore-dex2oat-cpu-set", "1,2"); setSystemProperty("dalvik.vm.dex2oat-cpu-set", "2,3"); @@ -481,6 +507,30 @@ TEST_F(RunDex2OatTest, ThreadsPostBootCompleteNotForRestore) { VerifyExpectedFlags(); } +TEST_F(RunDex2OatTest, ThreadsPostBootCompleteBackground) { + setSystemProperty("dalvik.vm.background-dex2oat-threads", "2"); + setSystemProperty("dalvik.vm.dex2oat-threads", "3"); + auto args = RunDex2OatArgs::MakeDefaultTestArgs(); + args->post_bootcomplete = true; + args->background_job_compile = true; + CallRunDex2Oat(std::move(args)); + + SetExpectedFlagUsed("-j", "2"); + VerifyExpectedFlags(); +} + +TEST_F(RunDex2OatTest, ThreadsPostBootCompleteBackground_Backup) { + setSystemProperty("dalvik.vm.background-dex2oat-threads", ""); + setSystemProperty("dalvik.vm.dex2oat-threads", "3"); + auto args = RunDex2OatArgs::MakeDefaultTestArgs(); + args->post_bootcomplete = true; + args->background_job_compile = true; + CallRunDex2Oat(std::move(args)); + + SetExpectedFlagUsed("-j", "3"); + VerifyExpectedFlags(); +} + TEST_F(RunDex2OatTest, ThreadsPostBootCompleteForRestore) { setSystemProperty("dalvik.vm.restore-dex2oat-threads", "4"); setSystemProperty("dalvik.vm.dex2oat-threads", "5"); |