odrefresh: add flag of system server compiler filter
Similar to --zygote-kind, the flag allows the caller to specify system
server compiler filter, with higher precedence than the corresponding
system property (dalvik.vm.systemservercompilerfilter).
Since the property is used earlier (where the default value is used),
the test is updated to test explicitly with "speed" filter, instead of
checking the default behavior implicitly. Also, since we're not
expecting unknown filter, when an unknown value is given, the actual
code now crashes with UNREACHABLE().
Bug: 208269838
Test: atest art_standalone_odrefresh_tests
Test: atest ComposHostTestCases
Change-Id: I4f5335e872b245dc6156cddd944800120adc60da
diff --git a/odrefresh/Android.bp b/odrefresh/Android.bp
index 316052d..7f79e11 100644
--- a/odrefresh/Android.bp
+++ b/odrefresh/Android.bp
@@ -210,7 +210,7 @@
"libdexfiled",
"libdexoptd",
],
- test_config_template: "//art/test:art-gtests-target-standalone-root-template",
+ test_config_template: "//art/test:art-gtests-target-standalone-template",
}
// Standalone version of ART gtest `art_odrefresh_tests`, not bundled with the ART APEX on target.
@@ -224,7 +224,7 @@
"libdexfile",
"libdexopt",
],
- test_config_template: "//art/test:art-gtests-target-standalone-root-template",
+ test_config_template: "//art/test:art-gtests-target-standalone-template",
}
genrule {
diff --git a/odrefresh/odr_config.h b/odrefresh/odr_config.h
index fcc182c..af7c0a7 100644
--- a/odrefresh/odr_config.h
+++ b/odrefresh/odr_config.h
@@ -64,6 +64,7 @@
InstructionSet isa_;
std::string program_name_;
std::string system_server_classpath_;
+ std::string system_server_compiler_filter_;
ZygoteKind zygote_kind_;
int compilation_os_address_ = 0;
std::string boot_classpath_;
@@ -143,6 +144,9 @@
const std::string& GetSystemServerClasspath() const {
return system_server_classpath_;
}
+ const std::string& GetSystemServerCompilerFilter() const {
+ return system_server_compiler_filter_;
+ }
bool UseCompilationOs() const { return compilation_os_address_ != 0; }
int GetCompilationOsAddress() const { return compilation_os_address_; }
const std::string& GetStagingDir() const {
@@ -178,6 +182,10 @@
system_server_classpath_ = classpath;
}
+ void SetSystemServerCompilerFilter(const std::string& filter) {
+ system_server_compiler_filter_ = filter;
+ }
+
void SetZygoteKind(ZygoteKind zygote_kind) { zygote_kind_ = zygote_kind; }
const std::string& GetBootClasspath() const { return boot_classpath_; }
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index ce80901..9517e54 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -520,6 +520,7 @@
} else if (compiler_filter == "verify") {
return CompilerFilter::VERIFY;
} else {
+ LOG(FATAL) << "Unrecognized compiler filter: " << compiler_filter;
return CompilerFilter::UNSUPPORTED;
}
}
@@ -1380,8 +1381,7 @@
dexopt_args.isa = InstructionSetToAidlIsa(isa);
const std::string jar_name(android::base::Basename(jar));
const std::string profile = Concatenate({GetAndroidRoot(), "/framework/", jar_name, ".prof"});
- std::string compiler_filter =
- android::base::GetProperty("dalvik.vm.systemservercompilerfilter", "speed");
+ std::string compiler_filter = config_.GetSystemServerCompilerFilter();
if (compiler_filter == "speed-profile") {
// Use speed-profile only if profile is provided, otherwise fallback to speed.
if (PrepareDex2OatProfileIfExists(&dexopt_args.profileFd, &readonly_files_raii, profile)) {
diff --git a/odrefresh/odrefresh_main.cc b/odrefresh/odrefresh_main.cc
index 6bfb8a8..e4ef25a 100644
--- a/odrefresh/odrefresh_main.cc
+++ b/odrefresh/odrefresh_main.cc
@@ -152,6 +152,8 @@
config->SetMaxChildProcessSeconds(seconds);
} else if (ArgumentMatches(arg, "--zygote-arch=", &value)) {
zygote = value;
+ } else if (ArgumentMatches(arg, "--system-server-compiler-filter=", &value)) {
+ config->SetSystemServerCompilerFilter(value);
} else if (ArgumentMatches(arg, "--staging-dir=", &value)) {
config->SetStagingDir(value);
} else if (ArgumentEquals(arg, "--dry-run")) {
@@ -175,6 +177,12 @@
}
config->SetZygoteKind(zygote_kind);
+ if (config->GetSystemServerCompilerFilter().empty()) {
+ std::string filter =
+ android::base::GetProperty("dalvik.vm.systemservercompilerfilter", "speed");
+ config->SetSystemServerCompilerFilter(filter);
+ }
+
return n;
}
@@ -192,6 +200,9 @@
UsageError("--staging-dir=<DIR> Write temporary artifacts to <DIR> rather than");
UsageError(" .../staging");
UsageError("--zygote-arch=<STRING> Zygote kind that overrides ro.zygote");
+ UsageError("--system-server-compiler-filter=<STRING>");
+ UsageError(" Compiler filter that overrides");
+ UsageError(" dalvik.vm.systemservercompilerfilter");
}
NO_RETURN void UsageHelp(const char* argv0) {
diff --git a/odrefresh/odrefresh_test.cc b/odrefresh/odrefresh_test.cc
index c392a7d..4d70a66 100644
--- a/odrefresh/odrefresh_test.cc
+++ b/odrefresh/odrefresh_test.cc
@@ -29,7 +29,6 @@
#include "aidl/com/android/art/DexoptSystemServerArgs.h"
#include "aidl/com/android/art/Isa.h"
#include "android-base/parseint.h"
-#include "android-base/properties.h"
#include "android-base/scopeguard.h"
#include "android-base/stringprintf.h"
#include "android-base/strings.h"
@@ -79,13 +78,6 @@
return android::base::ScopeGuard([=]() { unlink(name.c_str()); });
}
-android::base::ScopeGuard<std::function<void()>> ScopedSetProperty(const std::string& key,
- const std::string& value) {
- std::string old_value = android::base::GetProperty(key, /*default_value=*/{});
- android::base::SetProperty(key, value);
- return android::base::ScopeGuard([=]() { android::base::SetProperty(key, old_value); });
-}
-
class MockOdrDexopt : public OdrDexopt {
public:
// A workaround to avoid MOCK_METHOD on a method with an `std::string*` parameter, which will lead
@@ -179,6 +171,7 @@
config_.SetStandaloneSystemServerJars(Concatenate({services_foo_jar_, ":", services_bar_jar_}));
config_.SetIsa(InstructionSet::kX86_64);
config_.SetZygoteKind(ZygoteKind::kZygote64_32);
+ config_.SetSystemServerCompilerFilter("speed"); // specify a default
std::string staging_dir = dalvik_cache_dir_ + "/staging";
ASSERT_TRUE(EnsureDirectoryExists(staging_dir));
@@ -303,21 +296,10 @@
TEST_F(OdRefreshTest, CompileSetsCompilerFilter) {
{
- // Check if the system property can be written.
- auto guard = ScopedSetProperty("dalvik.vm.systemservercompilerfilter", "foo");
- if (android::base::GetProperty("dalvik.vm.systemservercompilerfilter", /*default_value=*/{}) !=
- "foo") {
- // This test depends on a system property that doesn't exist on old platforms. Since the whole
- // odrefresh program is for S and later, we don't need to run the test on old platforms.
- return;
- }
- }
-
- {
auto [odrefresh, mock_odr_dexopt] = CreateOdRefresh();
- // Test setup: default compiler filter should be "speed".
- auto guard = ScopedSetProperty("dalvik.vm.systemservercompilerfilter", "");
+ // Test setup: use "speed" compiler filter.
+ config_.SetSystemServerCompilerFilter("speed");
// Uninteresting calls.
EXPECT_CALL(*mock_odr_dexopt, DoDexoptSystemServer(_))
@@ -350,7 +332,7 @@
// Test setup: with "speed-profile" compiler filter in the request, only apply if there is a
// profile, otherwise fallback to speed.
- auto guard = ScopedSetProperty("dalvik.vm.systemservercompilerfilter", "speed-profile");
+ config_.SetSystemServerCompilerFilter("speed-profile");
// Uninteresting calls.
EXPECT_CALL(*mock_odr_dexopt, DoDexoptSystemServer(_))
@@ -385,7 +367,7 @@
auto [odrefresh, mock_odr_dexopt] = CreateOdRefresh();
// Test setup: "verify" compiler filter should be simply applied.
- auto guard = ScopedSetProperty("dalvik.vm.systemservercompilerfilter", "verify");
+ config_.SetSystemServerCompilerFilter("verify");
// Uninteresting calls.
EXPECT_CALL(*mock_odr_dexopt, DoDexoptSystemServer(_))