Loading cmds/installd/dexopt.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -314,9 +314,15 @@ class RunDex2Oat : public ExecVHelper { bool skip_compilation = vold_decrypt == "trigger_restart_min_framework" || vold_decrypt == "1"; const std::string resolve_startup_string_arg = std::string resolve_startup_string_arg = MapPropertyToArg("persist.device_config.runtime.dex2oat_resolve_startup_strings", "--resolve-startup-const-strings=%s"); if (resolve_startup_string_arg.empty()) { // If empty, fall back to system property. resolve_startup_string_arg = MapPropertyToArg("dalvik.vm.dex2oat-resolve-startup-strings", "--resolve-startup-const-strings=%s"); } const std::string image_block_size_arg = MapPropertyToArg("dalvik.vm.dex2oat-max-image-block-size", Loading cmds/installd/tests/installd_dexopt_test.cpp +65 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ #include <android-base/file.h> #include <android-base/logging.h> #include <android-base/properties.h> #include <android-base/scopeguard.h> #include <android-base/stringprintf.h> #include <android-base/unique_fd.h> #include <binder/Status.h> Loading Loading @@ -85,6 +87,23 @@ static void run_cmd(const std::string& cmd) { system(cmd.c_str()); } template <typename Visitor> static void run_cmd_and_process_output(const std::string& cmd, const Visitor& visitor) { FILE* file = popen(cmd.c_str(), "r"); CHECK(file != nullptr) << "Failed to ptrace " << cmd; char* line = nullptr; while (true) { size_t n = 0u; ssize_t value = getline(&line, &n, file); if (value == -1) { break; } visitor(line); } free(line); fclose(file); } static int mkdir(const std::string& path, uid_t owner, gid_t group, mode_t mode) { int ret = ::mkdir(path.c_str(), mode); if (ret != 0) { Loading Loading @@ -222,7 +241,8 @@ protected: ::testing::AssertionResult create_mock_app() { // Create the oat dir. app_oat_dir_ = app_apk_dir_ + "/oat"; if (mkdir(app_apk_dir_, kSystemUid, kSystemGid, 0755) != 0) { // For debug mode, the directory might already exist. Avoid erroring out. if (mkdir(app_apk_dir_, kSystemUid, kSystemGid, 0755) != 0 && !kDebug) { return ::testing::AssertionFailure() << "Could not create app dir " << app_apk_dir_ << " : " << strerror(errno); } Loading Loading @@ -628,6 +648,50 @@ TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) { DEX2OAT_FROM_SCRATCH); } TEST_F(DexoptTest, ResolveStartupConstStrings) { LOG(INFO) << "DexoptDex2oatResolveStartupStrings"; const std::string property = "persist.device_config.runtime.dex2oat_resolve_startup_strings"; const std::string previous_value = android::base::GetProperty(property, ""); auto restore_property = android::base::make_scope_guard([=]() { android::base::SetProperty(property, previous_value); }); std::string odex = GetPrimaryDexArtifact(app_oat_dir_.c_str(), apk_path_, "odex"); // Disable the property to start. bool found_disable = false; ASSERT_TRUE(android::base::SetProperty(property, "false")) << property; CompilePrimaryDexOk("speed-profile", DEXOPT_IDLE_BACKGROUND_JOB | DEXOPT_PROFILE_GUIDED | DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), kTestAppGid, DEX2OAT_FROM_SCRATCH); run_cmd_and_process_output( "oatdump --header-only --oat-file=" + odex, [&](const std::string& line) { if (line.find("--resolve-startup-const-strings=false") != std::string::npos) { found_disable = true; } }); EXPECT_TRUE(found_disable); // Enable the property and inspect that .art artifact is larger. bool found_enable = false; ASSERT_TRUE(android::base::SetProperty(property, "true")) << property; CompilePrimaryDexOk("speed-profile", DEXOPT_IDLE_BACKGROUND_JOB | DEXOPT_PROFILE_GUIDED | DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), kTestAppGid, DEX2OAT_FROM_SCRATCH); run_cmd_and_process_output( "oatdump --header-only --oat-file=" + odex, [&](const std::string& line) { if (line.find("--resolve-startup-const-strings=true") != std::string::npos) { found_enable = true; } }); EXPECT_TRUE(found_enable); } class PrimaryDexReCompilationTest : public DexoptTest { public: virtual void SetUp() { Loading Loading
cmds/installd/dexopt.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -314,9 +314,15 @@ class RunDex2Oat : public ExecVHelper { bool skip_compilation = vold_decrypt == "trigger_restart_min_framework" || vold_decrypt == "1"; const std::string resolve_startup_string_arg = std::string resolve_startup_string_arg = MapPropertyToArg("persist.device_config.runtime.dex2oat_resolve_startup_strings", "--resolve-startup-const-strings=%s"); if (resolve_startup_string_arg.empty()) { // If empty, fall back to system property. resolve_startup_string_arg = MapPropertyToArg("dalvik.vm.dex2oat-resolve-startup-strings", "--resolve-startup-const-strings=%s"); } const std::string image_block_size_arg = MapPropertyToArg("dalvik.vm.dex2oat-max-image-block-size", Loading
cmds/installd/tests/installd_dexopt_test.cpp +65 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ #include <android-base/file.h> #include <android-base/logging.h> #include <android-base/properties.h> #include <android-base/scopeguard.h> #include <android-base/stringprintf.h> #include <android-base/unique_fd.h> #include <binder/Status.h> Loading Loading @@ -85,6 +87,23 @@ static void run_cmd(const std::string& cmd) { system(cmd.c_str()); } template <typename Visitor> static void run_cmd_and_process_output(const std::string& cmd, const Visitor& visitor) { FILE* file = popen(cmd.c_str(), "r"); CHECK(file != nullptr) << "Failed to ptrace " << cmd; char* line = nullptr; while (true) { size_t n = 0u; ssize_t value = getline(&line, &n, file); if (value == -1) { break; } visitor(line); } free(line); fclose(file); } static int mkdir(const std::string& path, uid_t owner, gid_t group, mode_t mode) { int ret = ::mkdir(path.c_str(), mode); if (ret != 0) { Loading Loading @@ -222,7 +241,8 @@ protected: ::testing::AssertionResult create_mock_app() { // Create the oat dir. app_oat_dir_ = app_apk_dir_ + "/oat"; if (mkdir(app_apk_dir_, kSystemUid, kSystemGid, 0755) != 0) { // For debug mode, the directory might already exist. Avoid erroring out. if (mkdir(app_apk_dir_, kSystemUid, kSystemGid, 0755) != 0 && !kDebug) { return ::testing::AssertionFailure() << "Could not create app dir " << app_apk_dir_ << " : " << strerror(errno); } Loading Loading @@ -628,6 +648,50 @@ TEST_F(DexoptTest, DexoptPrimaryBackgroundOk) { DEX2OAT_FROM_SCRATCH); } TEST_F(DexoptTest, ResolveStartupConstStrings) { LOG(INFO) << "DexoptDex2oatResolveStartupStrings"; const std::string property = "persist.device_config.runtime.dex2oat_resolve_startup_strings"; const std::string previous_value = android::base::GetProperty(property, ""); auto restore_property = android::base::make_scope_guard([=]() { android::base::SetProperty(property, previous_value); }); std::string odex = GetPrimaryDexArtifact(app_oat_dir_.c_str(), apk_path_, "odex"); // Disable the property to start. bool found_disable = false; ASSERT_TRUE(android::base::SetProperty(property, "false")) << property; CompilePrimaryDexOk("speed-profile", DEXOPT_IDLE_BACKGROUND_JOB | DEXOPT_PROFILE_GUIDED | DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), kTestAppGid, DEX2OAT_FROM_SCRATCH); run_cmd_and_process_output( "oatdump --header-only --oat-file=" + odex, [&](const std::string& line) { if (line.find("--resolve-startup-const-strings=false") != std::string::npos) { found_disable = true; } }); EXPECT_TRUE(found_disable); // Enable the property and inspect that .art artifact is larger. bool found_enable = false; ASSERT_TRUE(android::base::SetProperty(property, "true")) << property; CompilePrimaryDexOk("speed-profile", DEXOPT_IDLE_BACKGROUND_JOB | DEXOPT_PROFILE_GUIDED | DEXOPT_GENERATE_APP_IMAGE, app_oat_dir_.c_str(), kTestAppGid, DEX2OAT_FROM_SCRATCH); run_cmd_and_process_output( "oatdump --header-only --oat-file=" + odex, [&](const std::string& line) { if (line.find("--resolve-startup-const-strings=true") != std::string::npos) { found_enable = true; } }); EXPECT_TRUE(found_enable); } class PrimaryDexReCompilationTest : public DexoptTest { public: virtual void SetUp() { Loading