summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2023-12-19 18:28:53 +0000
committer Jiakai Zhang <jiakaiz@google.com> 2023-12-20 11:40:15 +0000
commit1d090efadd31ead13d5491d60aaaf09992132f8c (patch)
tree4e211e427aa5ca899fbd81f1a68a104a2d0f34cf
parentad5061117a1fd9b3977c46aa2bc44e746e670d6a (diff)
Change GetOptimizationStatus to return an enum indicating the location.
The enum is suitable to be used programmatically and will be used by ART Service. Bug: 317081212 Bug: 263579377 Test: m test-art-host-gtest-art_runtime_tests Change-Id: Ic5a949d718b76a1d3defcc1efd823ca8cadadfa4
-rw-r--r--artd/artd.cc5
-rw-r--r--runtime/oat_file_assistant.cc38
-rw-r--r--runtime/oat_file_assistant.h6
-rw-r--r--runtime/oat_file_assistant_test.cc106
-rw-r--r--runtime/oat_file_manager.cc3
5 files changed, 115 insertions, 43 deletions
diff --git a/artd/artd.cc b/artd/artd.cc
index 97faeb080b..e56b3c3eef 100644
--- a/artd/artd.cc
+++ b/artd/artd.cc
@@ -562,10 +562,13 @@ ScopedAStatus Artd::getDexoptStatus(const std::string& in_dexFile,
}
std::string ignored_odex_status;
+ // TODO(jiakaiz): Make use of the location.
+ OatFileAssistant::Location ignored_location;
oat_file_assistant->GetOptimizationStatus(&_aidl_return->locationDebugString,
&_aidl_return->compilerFilter,
&_aidl_return->compilationReason,
- &ignored_odex_status);
+ &ignored_odex_status,
+ &ignored_location);
// We ignore odex_status because it is not meaningful. It can only be either "up-to-date",
// "apk-more-recent", or "io-error-no-oat", which means it doesn't give us information in addition
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index e8047af952..c58e47a13a 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -340,17 +340,7 @@ bool OatFileAssistant::GetDexOptNeeded(CompilerFilter::Filter target_compiler_fi
return true;
}
DexOptNeeded dexopt_needed = info.GetDexOptNeeded(target_compiler_filter, dexopt_trigger);
- if (info.IsUseable()) {
- if (&info == &dm_for_oat_ || &info == &dm_for_odex_) {
- dexopt_status->location_ = kLocationDm;
- } else if (info.IsOatLocation()) {
- dexopt_status->location_ = kLocationOat;
- } else {
- dexopt_status->location_ = kLocationOdex;
- }
- } else {
- dexopt_status->location_ = kLocationNoneOrError;
- }
+ dexopt_status->location_ = GetLocation(info);
return dexopt_needed != kNoDexOptNeeded;
}
@@ -1316,16 +1306,22 @@ void OatFileAssistant::GetOptimizationStatus(const std::string& filename,
ofa_context);
std::string out_odex_location; // unused
std::string out_odex_status; // unused
- oat_file_assistant.GetOptimizationStatus(
- &out_odex_location, out_compilation_filter, out_compilation_reason, &out_odex_status);
+ Location out_location; // unused
+ oat_file_assistant.GetOptimizationStatus(&out_odex_location,
+ out_compilation_filter,
+ out_compilation_reason,
+ &out_odex_status,
+ &out_location);
}
void OatFileAssistant::GetOptimizationStatus(std::string* out_odex_location,
std::string* out_compilation_filter,
std::string* out_compilation_reason,
- std::string* out_odex_status) {
+ std::string* out_odex_status,
+ Location* out_location) {
OatFileInfo& oat_file_info = GetBestInfo();
const OatFile* oat_file = oat_file_info.GetFile();
+ *out_location = GetLocation(oat_file_info);
if (oat_file == nullptr) {
std::string error_msg;
@@ -1399,4 +1395,18 @@ bool OatFileAssistant::ZipFileOnlyContainsUncompressedDex() {
return zip_file_only_contains_uncompressed_dex_;
}
+OatFileAssistant::Location OatFileAssistant::GetLocation(OatFileInfo& info) {
+ if (info.IsUseable()) {
+ if (&info == &dm_for_oat_ || &info == &dm_for_odex_) {
+ return kLocationDm;
+ } else if (info.IsOatLocation()) {
+ return kLocationOat;
+ } else {
+ return kLocationOdex;
+ }
+ } else {
+ return kLocationNoneOrError;
+ }
+}
+
} // namespace art
diff --git a/runtime/oat_file_assistant.h b/runtime/oat_file_assistant.h
index 402e9aef1a..2653600f8e 100644
--- a/runtime/oat_file_assistant.h
+++ b/runtime/oat_file_assistant.h
@@ -257,7 +257,8 @@ class OatFileAssistant {
void GetOptimizationStatus(std::string* out_odex_location,
std::string* out_compilation_filter,
std::string* out_compilation_reason,
- std::string* out_odex_status);
+ std::string* out_odex_status,
+ Location* out_location);
static void GetOptimizationStatus(const std::string& filename,
InstructionSet isa,
@@ -526,6 +527,9 @@ class OatFileAssistant {
// Returns whether the zip file only contains uncompressed dex.
bool ZipFileOnlyContainsUncompressedDex();
+ // Returns the location of the given oat file.
+ Location GetLocation(OatFileInfo& info);
+
std::string dex_location_;
// The class loader context to check against, or null representing that the check should be
diff --git a/runtime/oat_file_assistant_test.cc b/runtime/oat_file_assistant_test.cc
index 03306a9fe4..851c75be8f 100644
--- a/runtime/oat_file_assistant_test.cc
+++ b/runtime/oat_file_assistant_test.cc
@@ -68,6 +68,7 @@ class OatFileAssistantTest : public OatFileAssistantBaseTest,
const T& expected_filter,
const std::string& expected_reason,
const std::string& expected_odex_status,
+ OatFileAssistant::Location expected_location,
bool check_context = false) {
std::string expected_filter_name;
if constexpr (std::is_same_v<T, CompilerFilter::Filter>) {
@@ -95,24 +96,27 @@ class OatFileAssistantTest : public OatFileAssistantBaseTest,
// Verify the instance methods (called at runtime and from artd).
OatFileAssistant assistant = CreateOatFileAssistant(file.c_str(), context);
VerifyOptimizationStatusWithInstance(
- &assistant, expected_filter_name, expected_reason, expected_odex_status);
+ &assistant, expected_filter_name, expected_reason, expected_odex_status, expected_location);
}
void VerifyOptimizationStatusWithInstance(OatFileAssistant* assistant,
const std::string& expected_filter,
const std::string& expected_reason,
- const std::string& expected_odex_status) {
+ const std::string& expected_odex_status,
+ OatFileAssistant::Location expected_location) {
std::string odex_location; // ignored
std::string compilation_filter;
std::string compilation_reason;
std::string odex_status;
+ OatFileAssistant::Location location;
assistant->GetOptimizationStatus(
- &odex_location, &compilation_filter, &compilation_reason, &odex_status);
+ &odex_location, &compilation_filter, &compilation_reason, &odex_status, &location);
ASSERT_EQ(expected_filter, compilation_filter);
ASSERT_EQ(expected_reason, compilation_reason);
ASSERT_EQ(expected_odex_status, odex_status);
+ ASSERT_EQ(expected_location, location);
}
bool InsertNewBootClasspathEntry(const std::string& src, std::string* error_msg) {
@@ -403,8 +407,12 @@ TEST_P(OatFileAssistantTest, DexNoOat) {
EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
ExpectHasDexFiles(&oat_file_assistant, true);
- VerifyOptimizationStatus(
- dex_location, default_context_.get(), "run-from-apk", "unknown", "io-error-no-oat");
+ VerifyOptimizationStatus(dex_location,
+ default_context_.get(),
+ "run-from-apk",
+ "unknown",
+ "io-error-no-oat",
+ OatFileAssistant::kLocationNoneOrError);
}
// Case: We have no DEX file and no OAT file.
@@ -429,8 +437,11 @@ TEST_P(OatFileAssistantTest, NoDexNoOat) {
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");
+ VerifyOptimizationStatusWithInstance(&oat_file_assistant,
+ "unknown",
+ "unknown",
+ "io-error-no-apk",
+ OatFileAssistant::kLocationNoneOrError);
}
// Case: We have a DEX file and an ODEX file, but no OAT file.
@@ -470,8 +481,12 @@ TEST_P(OatFileAssistantTest, OdexUpToDate) {
EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
ExpectHasDexFiles(&oat_file_assistant, true);
- VerifyOptimizationStatus(
- dex_location, default_context_.get(), CompilerFilter::kSpeed, "install", "up-to-date");
+ VerifyOptimizationStatus(dex_location,
+ default_context_.get(),
+ CompilerFilter::kSpeed,
+ "install",
+ "up-to-date",
+ OatFileAssistant::kLocationOdex);
}
// Case: We have an ODEX file compiled against partial boot image.
@@ -515,8 +530,12 @@ TEST_P(OatFileAssistantTest, OdexUpToDatePartialBootImage) {
EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
ExpectHasDexFiles(&oat_file_assistant, true);
- VerifyOptimizationStatus(
- dex_location, default_context_.get(), CompilerFilter::kSpeed, "install", "up-to-date");
+ VerifyOptimizationStatus(dex_location,
+ default_context_.get(),
+ CompilerFilter::kSpeed,
+ "install",
+ "up-to-date",
+ OatFileAssistant::kLocationOdex);
}
// Case: We have a DEX file and a PIC ODEX file, but no OAT file. We load the dex
@@ -609,8 +628,12 @@ TEST_P(OatFileAssistantTest, OatUpToDate) {
EXPECT_EQ(OatFileAssistant::kOatUpToDate, oat_file_assistant.OatFileStatus());
ExpectHasDexFiles(&oat_file_assistant, true);
- VerifyOptimizationStatus(
- dex_location, default_context_.get(), CompilerFilter::kSpeed, "unknown", "up-to-date");
+ VerifyOptimizationStatus(dex_location,
+ default_context_.get(),
+ CompilerFilter::kSpeed,
+ "unknown",
+ "up-to-date",
+ OatFileAssistant::kLocationOat);
}
// Case: Passing valid file descriptors of updated odex/vdex files along with the dex file.
@@ -809,7 +832,12 @@ TEST_P(OatFileAssistantTest, VdexUpToDateNoOdex) {
// care what the actual dumped value is.
oat_file_assistant.GetStatusDump();
- VerifyOptimizationStatus(dex_location, default_context_.get(), "verify", "vdex", "up-to-date");
+ VerifyOptimizationStatus(dex_location,
+ default_context_.get(),
+ "verify",
+ "vdex",
+ "up-to-date",
+ OatFileAssistant::kLocationOdex);
}
// Case: We have a DEX file and empty VDEX and ODEX files.
@@ -1047,8 +1075,12 @@ TEST_P(OatFileAssistantTest, OatDexOutOfDate) {
EXPECT_EQ(OatFileAssistant::kOatDexOutOfDate, oat_file_assistant.OatFileStatus());
ExpectHasDexFiles(&oat_file_assistant, true);
- VerifyOptimizationStatus(
- dex_location, default_context_.get(), "run-from-apk-fallback", "unknown", "apk-more-recent");
+ VerifyOptimizationStatus(dex_location,
+ default_context_.get(),
+ "run-from-apk-fallback",
+ "unknown",
+ "apk-more-recent",
+ OatFileAssistant::kLocationNoneOrError);
}
// Case: We have a DEX file and an (ODEX) VDEX file out of date with respect
@@ -1137,7 +1169,12 @@ TEST_P(OatFileAssistantTest, OatImageOutOfDate) {
EXPECT_EQ(OatFileAssistant::kOatBootImageOutOfDate, oat_file_assistant.OatFileStatus());
ExpectHasDexFiles(&oat_file_assistant, true);
- VerifyOptimizationStatus(dex_location, default_context_.get(), "verify", "vdex", "up-to-date");
+ VerifyOptimizationStatus(dex_location,
+ default_context_.get(),
+ "verify",
+ "vdex",
+ "up-to-date",
+ OatFileAssistant::kLocationOat);
}
TEST_P(OatFileAssistantTest, OatContextOutOfDate) {
@@ -1165,8 +1202,13 @@ TEST_P(OatFileAssistantTest, OatContextOutOfDate) {
auto scoped_maybe_without_runtime = ScopedMaybeWithoutRuntime();
- VerifyOptimizationStatus(
- dex_location, context.get(), "verify", "vdex", "up-to-date", /*check_context=*/true);
+ VerifyOptimizationStatus(dex_location,
+ context.get(),
+ "verify",
+ "vdex",
+ "up-to-date",
+ OatFileAssistant::kLocationOdex,
+ /*check_context=*/true);
}
// Case: We have a DEX file and an ODEX file, but no OAT file.
@@ -1242,7 +1284,11 @@ TEST_P(OatFileAssistantTest, ResourceOnlyDex) {
EXPECT_EQ(OatFileAssistant::kOatCannotOpen, oat_file_assistant.OatFileStatus());
ExpectHasDexFiles(&oat_file_assistant, false);
- VerifyOptimizationStatusWithInstance(&oat_file_assistant, "unknown", "unknown", "no-dex-code");
+ VerifyOptimizationStatusWithInstance(&oat_file_assistant,
+ "unknown",
+ "unknown",
+ "no-dex-code",
+ OatFileAssistant::kLocationNoneOrError);
}
// Case: We have a DEX file, an ODEX file and an OAT file.
@@ -2080,8 +2126,11 @@ TEST_P(OatFileAssistantTest, OdexNoDex) {
/*expected_location=*/OatFileAssistant::kLocationNoneOrError,
/*expected_legacy_result=*/OatFileAssistant::kNoDexOptNeeded);
- VerifyOptimizationStatusWithInstance(
- &oat_file_assistant, "unknown", "unknown", "io-error-no-apk");
+ VerifyOptimizationStatusWithInstance(&oat_file_assistant,
+ "unknown",
+ "unknown",
+ "io-error-no-apk",
+ OatFileAssistant::kLocationNoneOrError);
}
// Case: We have a VDEX file, but the DEX file is gone.
@@ -2106,8 +2155,11 @@ TEST_P(OatFileAssistantTest, VdexNoDex) {
/*expected_location=*/OatFileAssistant::kLocationNoneOrError,
/*expected_legacy_result=*/OatFileAssistant::kNoDexOptNeeded);
- VerifyOptimizationStatusWithInstance(
- &oat_file_assistant, "unknown", "unknown", "io-error-no-apk");
+ VerifyOptimizationStatusWithInstance(&oat_file_assistant,
+ "unknown",
+ "unknown",
+ "io-error-no-apk",
+ OatFileAssistant::kLocationNoneOrError);
}
// Case: We have a VDEX file, generated without a boot image, and we now have a boot image.
@@ -2493,7 +2545,8 @@ TEST_P(OatFileAssistantTest, Create) {
ASSERT_NE(oat_file_assistant, nullptr);
// Verify that the created instance is usable.
- VerifyOptimizationStatusWithInstance(oat_file_assistant.get(), "speed", "install", "up-to-date");
+ VerifyOptimizationStatusWithInstance(
+ oat_file_assistant.get(), "speed", "install", "up-to-date", OatFileAssistant::kLocationOdex);
}
TEST_P(OatFileAssistantTest, CreateWithNullContext) {
@@ -2519,7 +2572,8 @@ TEST_P(OatFileAssistantTest, CreateWithNullContext) {
ASSERT_EQ(context, nullptr);
// Verify that the created instance is usable.
- VerifyOptimizationStatusWithInstance(oat_file_assistant.get(), "speed", "install", "up-to-date");
+ VerifyOptimizationStatusWithInstance(
+ oat_file_assistant.get(), "speed", "install", "up-to-date", OatFileAssistant::kLocationOdex);
}
TEST_P(OatFileAssistantTest, ErrorOnInvalidIsaString) {
diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc
index 5c97db20ba..f5f72f3859 100644
--- a/runtime/oat_file_manager.cc
+++ b/runtime/oat_file_manager.cc
@@ -232,8 +232,9 @@ std::vector<std::unique_ptr<const DexFile>> OatFileManager::OpenDexFilesFromOat(
std::string compilation_filter;
std::string compilation_reason;
std::string odex_status;
+ OatFileAssistant::Location ignored_location;
oat_file_assistant->GetOptimizationStatus(
- &odex_location, &compilation_filter, &compilation_reason, &odex_status);
+ &odex_location, &compilation_filter, &compilation_reason, &odex_status, &ignored_location);
ScopedTrace odex_loading(StringPrintf(
"location=%s status=%s filter=%s reason=%s",