summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2023-04-13 16:22:31 +0100
committer Jiakai Zhang <jiakaiz@google.com> 2023-04-13 16:22:31 +0100
commit36fca05d1bd02087a439664419f0b98c74e38e0e (patch)
treec11944f4b133c79c41c247183623e5e04e78353b
parent1cff8449bac0fdab6e84dc9255c3cccd504c1705 (diff)
Improve oat status reporting.
After this change: - If there is no APK/JAR, it reports "io-error-no-apk" - If there is the APK/JAR doesn't contain any DEX file, it reports "no-dex-code" - If the APK/JAR exists and contains DEX files, but it fails to open the OAT file, it reports "io-error-no-oat" Bug: 277809828 Test: m test-art-host-gtest-art_runtime_tests Change-Id: I39bde2ffcc8a2c75493b3b271b21080bf8a8670f
-rw-r--r--runtime/oat_file_assistant.cc34
-rw-r--r--runtime/oat_file_assistant_test.cc11
2 files changed, 35 insertions, 10 deletions
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index 6014409c78..f30c6e257e 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -1259,16 +1259,30 @@ void OatFileAssistant::GetOptimizationStatus(std::string* out_odex_location,
const OatFile* oat_file = GetBestInfo().GetFile();
if (oat_file == nullptr) {
- *out_odex_location = "error";
- *out_compilation_filter = "run-from-apk";
- *out_compilation_reason = "unknown";
- // This mostly happens when we cannot open the oat file.
- // Note that it's different than kOatCannotOpen.
- // TODO: The design of getting the BestInfo is not ideal,
- // as it's not very clear what's the difference between
- // a nullptr and kOatcannotOpen. The logic should be revised
- // and improved.
- *out_odex_status = "io-error-no-oat";
+ std::string error_msg;
+ std::optional<bool> has_dex_files = HasDexFiles(&error_msg);
+ if (!has_dex_files.has_value()) {
+ *out_odex_location = "error";
+ *out_compilation_filter = "unknown";
+ *out_compilation_reason = "unknown";
+ // This happens when we cannot open the APK/JAR.
+ *out_odex_status = "io-error-no-apk";
+ } else if (!has_dex_files.value()) {
+ *out_odex_location = "none";
+ *out_compilation_filter = "unknown";
+ *out_compilation_reason = "unknown";
+ // This happens when the APK/JAR doesn't contain any DEX file.
+ *out_odex_status = "no-dex-code";
+ } else {
+ *out_odex_location = "error";
+ *out_compilation_filter = "run-from-apk";
+ *out_compilation_reason = "unknown";
+ // This mostly happens when we cannot open the oat file.
+ // Note that it's different than kOatCannotOpen.
+ // TODO: The design of getting the BestInfo is not ideal, as it's not very clear what's the
+ // difference between a nullptr and kOatcannotOpen. The logic should be revised and improved.
+ *out_odex_status = "io-error-no-oat";
+ }
return;
}
diff --git a/runtime/oat_file_assistant_test.cc b/runtime/oat_file_assistant_test.cc
index 42350dc9f8..56d4c70920 100644
--- a/runtime/oat_file_assistant_test.cc
+++ b/runtime/oat_file_assistant_test.cc
@@ -428,6 +428,9 @@ TEST_P(OatFileAssistantTest, NoDexNoOat) {
// Trying to get the best oat file should fail, but not crash.
std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
EXPECT_EQ(nullptr, oat_file.get());
+
+ VerifyOptimizationStatusWithInstance(
+ &oat_file_assistant, "unknown", "unknown", "io-error-no-apk");
}
// Case: We have a DEX file and an ODEX file, but no OAT file.
@@ -1238,6 +1241,8 @@ TEST_P(OatFileAssistantTest, ResourceOnlyDex) {
EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OdexFileStatus());
EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
ExpectHasDexFiles(&oat_file_assistant, false);
+
+ VerifyOptimizationStatusWithInstance(&oat_file_assistant, "unknown", "unknown", "no-dex-code");
}
// Case: We have a DEX file, an ODEX file and an OAT file.
@@ -2070,6 +2075,9 @@ TEST_P(OatFileAssistantTest, OdexNoDex) {
/*expected_is_vdex_usable=*/false,
/*expected_location=*/OatFileAssistant::kLocationNoneOrError,
/*expected_legacy_result=*/OatFileAssistant::kNoDexOptNeeded);
+
+ VerifyOptimizationStatusWithInstance(
+ &oat_file_assistant, "unknown", "unknown", "io-error-no-apk");
}
// Case: We have a VDEX file, but the DEX file is gone.
@@ -2093,6 +2101,9 @@ TEST_P(OatFileAssistantTest, VdexNoDex) {
/*expected_is_vdex_usable=*/false,
/*expected_location=*/OatFileAssistant::kLocationNoneOrError,
/*expected_legacy_result=*/OatFileAssistant::kNoDexOptNeeded);
+
+ VerifyOptimizationStatusWithInstance(
+ &oat_file_assistant, "unknown", "unknown", "io-error-no-apk");
}
// Test that GetLocation of a dex file is the same whether the dex