Remove the code for verifying artifacts.
Verifying artifacts using dexoptanalyzer takes long and is not suitable
for running at early boot. It was replaced with a faster approach, but
the code hasn't been cleaned up. As we are making more and more changes
to odrefresh, the code for verifying artifaccts is outdated and becomes
a maintenance burden.
Bug: 203198541
Test: Presubmits
Change-Id: Ie689a38f44c986582901c1589b31af41e769d13e
diff --git a/odrefresh/odr_config.h b/odrefresh/odr_config.h
index 3752107..af0ee64 100644
--- a/odrefresh/odr_config.h
+++ b/odrefresh/odr_config.h
@@ -127,11 +127,6 @@
return art_bin_dir_ + '/' + prefix + suffix;
}
- std::string GetDexOptAnalyzer() const {
- const char* dexoptanalyzer{UseDebugBinaries() ? "dexoptanalyzerd" : "dexoptanalyzer"};
- return art_bin_dir_ + '/' + dexoptanalyzer;
- }
-
bool GetDryRun() const { return dry_run_; }
const std::string& GetSystemServerClasspath() const {
return system_server_classpath_;
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index 822d4f7..a1985ad 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -429,11 +429,6 @@
return true;
}
-std::string GetBootImage() {
- // Typically "/apex/com.android.art/javalib/boot.art".
- return GetArtRoot() + "/javalib/boot.art";
-}
-
Isa InstructionSetToAidlIsa(InstructionSet isa) {
switch (isa) {
case InstructionSet::kArm:
@@ -1071,192 +1066,6 @@
ExitCode::kOkay;
}
-WARN_UNUSED bool OnDeviceRefresh::VerifyBootExtensionArtifactsAreUpToDate(const InstructionSet isa,
- bool on_system) const {
- const std::string dex_file = boot_extension_compilable_jars_.front();
- const std::string image_location = GetBootImageExtensionImage(on_system);
-
- std::vector<std::string> args;
- args.emplace_back(config_.GetDexOptAnalyzer());
- args.emplace_back("--validate-bcp");
- args.emplace_back(Concatenate({"--image=", GetBootImage(), ":", image_location}));
- args.emplace_back(Concatenate({"--isa=", GetInstructionSetString(isa)}));
- args.emplace_back("--runtime-arg");
- args.emplace_back(Concatenate({"-Xbootclasspath:", config_.GetDex2oatBootClasspath()}));
-
- LOG(INFO) << "Checking " << dex_file << ": " << android::base::Join(args, ' ');
-
- std::string error_msg;
- bool timed_out = false;
- const time_t timeout = GetSubprocessTimeout();
- const int dexoptanalyzer_result =
- exec_utils_->ExecAndReturnCode(args, timeout, &timed_out, &error_msg);
- if (dexoptanalyzer_result == -1) {
- LOG(ERROR) << "Unexpected exit from dexoptanalyzer: " << error_msg;
- if (timed_out) {
- // TODO(oth): record metric for timeout.
- }
- return false;
- }
- auto rc = static_cast<dexoptanalyzer::ReturnCode>(dexoptanalyzer_result);
- if (rc == dexoptanalyzer::ReturnCode::kNoDexOptNeeded) {
- return true;
- }
- return false;
-}
-
-WARN_UNUSED bool OnDeviceRefresh::VerifyBootExtensionArtifactsAreUpToDate(
- InstructionSet isa) const {
- bool system_ok = VerifyBootExtensionArtifactsAreUpToDate(isa, /*on_system=*/true);
- LOG(INFO) << "Boot extension artifacts on /system are " << (system_ok ? "ok" : "stale");
- bool data_ok = VerifyBootExtensionArtifactsAreUpToDate(isa, /*on_system=*/false);
- LOG(INFO) << "Boot extension artifacts on /data are " << (data_ok ? "ok" : "stale");
- return system_ok || data_ok;
-}
-
-WARN_UNUSED bool OnDeviceRefresh::VerifySystemServerArtifactsAreUpToDate(bool on_system) const {
- std::vector<std::string> classloader_context;
- for (const std::string& jar_path : systemserver_compilable_jars_) {
- std::vector<std::string> args;
- args.emplace_back(config_.GetDexOptAnalyzer());
- args.emplace_back("--dex-file=" + jar_path);
-
- const std::string image_location = GetSystemServerImagePath(on_system, jar_path);
-
- // odrefresh produces app-image files, but these are not guaranteed for those pre-installed
- // on /system.
- if (!on_system && !OS::FileExists(image_location.c_str(), true)) {
- LOG(INFO) << "Missing image file: " << QuotePath(image_location);
- return false;
- }
-
- // Generate set of artifacts that are output by compilation.
- OdrArtifacts artifacts = OdrArtifacts::ForSystemServer(image_location);
- if (!on_system) {
- CHECK_EQ(artifacts.OatPath(),
- GetApexDataOdexFilename(jar_path, config_.GetSystemServerIsa()));
- CHECK_EQ(artifacts.ImagePath(),
- GetApexDataDalvikCacheFilename(jar_path, config_.GetSystemServerIsa(), "art"));
- CHECK_EQ(artifacts.OatPath(),
- GetApexDataDalvikCacheFilename(jar_path, config_.GetSystemServerIsa(), "odex"));
- CHECK_EQ(artifacts.VdexPath(),
- GetApexDataDalvikCacheFilename(jar_path, config_.GetSystemServerIsa(), "vdex"));
- }
-
- // Associate inputs and outputs with dexoptanalyzer arguments.
- std::pair<const std::string, const char*> location_args[] = {
- std::make_pair(artifacts.OatPath(), "--oat-fd="),
- std::make_pair(artifacts.VdexPath(), "--vdex-fd="),
- std::make_pair(jar_path, "--zip-fd=")};
-
- // Open file descriptors for dexoptanalyzer file inputs and add to the command-line.
- std::vector<std::unique_ptr<File>> files;
- for (const auto& location_arg : location_args) {
- auto& [location, arg] = location_arg;
- std::unique_ptr<File> file(OS::OpenFileForReading(location.c_str()));
- if (file == nullptr) {
- PLOG(ERROR) << "Failed to open \"" << location << "\"";
- return false;
- }
- args.emplace_back(android::base::StringPrintf("%s%d", arg, file->Fd()));
- files.emplace_back(file.release());
- }
-
- const std::string basename(android::base::Basename(jar_path));
- const std::string root = GetAndroidRoot();
- const std::string profile_file = Concatenate({root, "/framework/", basename, ".prof"});
- if (OS::FileExists(profile_file.c_str())) {
- args.emplace_back("--compiler-filter=speed-profile");
- } else {
- args.emplace_back("--compiler-filter=speed");
- }
-
- args.emplace_back(
- Concatenate({"--image=", GetBootImage(), ":", GetBootImageExtensionImage(on_system)}));
- args.emplace_back(
- Concatenate({"--isa=", GetInstructionSetString(config_.GetSystemServerIsa())}));
- args.emplace_back("--runtime-arg");
- args.emplace_back(Concatenate({"-Xbootclasspath:", config_.GetBootClasspath()}));
- args.emplace_back(Concatenate(
- {"--class-loader-context=PCL[", android::base::Join(classloader_context, ':'), "]"}));
-
- classloader_context.emplace_back(jar_path);
-
- LOG(INFO) << "Checking " << jar_path << ": " << android::base::Join(args, ' ');
- std::string error_msg;
- bool timed_out = false;
- const time_t timeout = GetSubprocessTimeout();
- const int dexoptanalyzer_result =
- exec_utils_->ExecAndReturnCode(args, timeout, &timed_out, &error_msg);
- if (dexoptanalyzer_result == -1) {
- LOG(ERROR) << "Unexpected exit from dexoptanalyzer: " << error_msg;
- if (timed_out) {
- // TODO(oth): record metric for timeout.
- }
- return false;
- }
- LOG(INFO) << "dexoptanalyzer returned " << dexoptanalyzer_result;
-
- bool unexpected_result = true;
- switch (static_cast<dexoptanalyzer::ReturnCode>(dexoptanalyzer_result)) {
- case art::dexoptanalyzer::ReturnCode::kNoDexOptNeeded:
- unexpected_result = false;
- break;
-
- // Recompile needed
- case art::dexoptanalyzer::ReturnCode::kDex2OatFromScratch:
- case art::dexoptanalyzer::ReturnCode::kDex2OatForBootImageOat:
- case art::dexoptanalyzer::ReturnCode::kDex2OatForFilterOat:
- case art::dexoptanalyzer::ReturnCode::kDex2OatForBootImageOdex:
- case art::dexoptanalyzer::ReturnCode::kDex2OatForFilterOdex:
- return false;
-
- // Unexpected issues (note no default-case here to catch missing enum values, but the
- // return code from dexoptanalyzer may also be outside expected values, such as a
- // process crash.
- case art::dexoptanalyzer::ReturnCode::kFlattenClassLoaderContextSuccess:
- case art::dexoptanalyzer::ReturnCode::kErrorInvalidArguments:
- case art::dexoptanalyzer::ReturnCode::kErrorCannotCreateRuntime:
- case art::dexoptanalyzer::ReturnCode::kErrorUnknownDexOptNeeded:
- break;
- }
-
- if (unexpected_result) {
- LOG(ERROR) << "Unexpected result from dexoptanalyzer: " << dexoptanalyzer_result;
- return false;
- }
- }
- return true;
-}
-
-WARN_UNUSED bool OnDeviceRefresh::VerifySystemServerArtifactsAreUpToDate() const {
- bool system_ok = VerifySystemServerArtifactsAreUpToDate(/*on_system=*/true);
- LOG(INFO) << "system_server artifacts on /system are " << (system_ok ? "ok" : "stale");
- bool data_ok = VerifySystemServerArtifactsAreUpToDate(/*on_system=*/false);
- LOG(INFO) << "system_server artifacts on /data are " << (data_ok ? "ok" : "stale");
- return system_ok || data_ok;
-}
-
-WARN_UNUSED ExitCode OnDeviceRefresh::VerifyArtifactsAreUpToDate() const {
- ExitCode exit_code = ExitCode::kOkay;
- for (const InstructionSet isa : config_.GetBootExtensionIsas()) {
- if (!VerifyBootExtensionArtifactsAreUpToDate(isa)) {
- // system_server artifacts are invalid without valid boot extension artifacts.
- if (!RemoveSystemServerArtifactsFromData() || !RemoveBootExtensionArtifactsFromData(isa)) {
- return ExitCode::kCleanupFailed;
- }
- exit_code = ExitCode::kCompilationRequired;
- }
- }
- if (!VerifySystemServerArtifactsAreUpToDate()) {
- if (!RemoveSystemServerArtifactsFromData()) {
- return ExitCode::kCleanupFailed;
- }
- exit_code = ExitCode::kCompilationRequired;
- }
- return exit_code;
-}
-
WARN_UNUSED bool OnDeviceRefresh::CompileBootExtensionArtifacts(const InstructionSet isa,
const std::string& staging_dir,
OdrMetrics& metrics,
diff --git a/odrefresh/odrefresh.h b/odrefresh/odrefresh.h
index 0f7a724..6b91bd8 100644
--- a/odrefresh/odrefresh.h
+++ b/odrefresh/odrefresh.h
@@ -56,16 +56,6 @@
const std::vector<InstructionSet>& compile_boot_extensions,
bool compile_system_server) const;
- // Verify all artifacts are up-to-date.
- //
- // This method checks artifacts can be loaded by the runtime.
- //
- // Returns ExitCode::kOkay if artifacts are up-to-date, ExitCode::kCompilationRequired
- // otherwise.
- //
- // NB This is the main function used by the --verify command-line option.
- WARN_UNUSED ExitCode VerifyArtifactsAreUpToDate() const;
-
WARN_UNUSED bool RemoveArtifactsDirectory() const;
private:
@@ -129,26 +119,6 @@
const std::optional<com::android::art::CacheInfo>& cache_info,
/*out*/ bool* cleanup_required) const;
- // Check the validity of boot class path extension artifacts.
- //
- // Returns true if artifacts exist and are valid according to dexoptanalyzer.
- WARN_UNUSED bool VerifyBootExtensionArtifactsAreUpToDate(const InstructionSet isa,
- bool on_system) const;
-
- // Verify whether boot extension artifacts for `isa` are valid on system partition or in
- // apexdata. This method has the side-effect of removing boot classpath extension artifacts on
- // /data, if there are valid artifacts on /system, or if the artifacts on /data are not valid.
- // Returns true if valid boot externsion artifacts are valid.
- WARN_UNUSED bool VerifyBootExtensionArtifactsAreUpToDate(InstructionSet isa) const;
-
- WARN_UNUSED bool VerifySystemServerArtifactsAreUpToDate(bool on_system) const;
-
- // Verify the validity of system server artifacts on both /system and /data.
- // This method has the side-effect of removing system server artifacts on /data, if there are
- // valid artifacts on /system, or if the artifacts on /data are not valid.
- // Returns true if valid artifacts are found.
- WARN_UNUSED bool VerifySystemServerArtifactsAreUpToDate() const;
-
WARN_UNUSED bool CompileBootExtensionArtifacts(const InstructionSet isa,
const std::string& staging_dir,
OdrMetrics& metrics,
diff --git a/odrefresh/odrefresh_main.cc b/odrefresh/odrefresh_main.cc
index 4403d9c..4aca36f 100644
--- a/odrefresh/odrefresh_main.cc
+++ b/odrefresh/odrefresh_main.cc
@@ -250,13 +250,11 @@
UsageError("");
UsageError("Valid ACTION choices are:");
UsageError("");
- UsageError(
- "--check Check compilation artifacts are up-to-date based on metadata (fast).");
+ UsageError("--check Check compilation artifacts are up-to-date based on metadata.");
UsageError("--compile Compile boot class path extensions and system_server jars");
UsageError(" when necessary.");
UsageError("--force-compile Unconditionally compile the boot class path extensions and");
UsageError(" system_server jars.");
- UsageError("--verify Verify artifacts are up-to-date with dexoptanalyzer (slow).");
UsageError("--help Display this help information.");
UsageError("");
UsageError("Available OPTIONs are:");
@@ -328,10 +326,6 @@
return odr.Compile(metrics,
/*compile_boot_extensions=*/config.GetBootExtensionIsas(),
/*compile_system_server=*/true);
- } else if (action == "--verify") {
- // Slow determination of whether artifacts are up to date. These are too slow for checking
- // during boot (b/181689036).
- return odr.VerifyArtifactsAreUpToDate();
} else if (action == "--help") {
UsageHelp(argv[0]);
} else {