Compute oat and odex filenames eagerly.
Because we almost always need both of them anyway, and they aren't
expensive to compute.
Test: oat file assistant tests.
Change-Id: I328ea51da6eb8700329f829a0458b02e12d1ee9e
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index ac329a3..8700a90 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -81,11 +81,18 @@
load_executable_ = false;
}
- // If the user gave a target oat location, save that as the cached oat
- // location now so we won't try to construct the default location later.
+ std::string error_msg;
+ if (!DexLocationToOdexFilename(dex_location_, isa_, &odex_file_name_, &error_msg)) {
+ LOG(WARNING) << "Failed to determine odex file name: " << error_msg;
+ }
+
if (oat_location != nullptr) {
- cached_oat_file_name_ = std::string(oat_location);
- cached_oat_file_name_attempted_ = true;
+ oat_file_name_ = std::string(oat_location);
+ } else {
+ if (!DexLocationToOatFilename(dex_location_, isa_, &oat_file_name_, &error_msg)) {
+ LOG(WARNING) << "Failed to determine oat file name for dex location "
+ << dex_location_ << ": " << error_msg;
+ }
}
}
@@ -351,17 +358,7 @@
}
const std::string* OatFileAssistant::OdexFileName() {
- if (!cached_odex_file_name_attempted_) {
- cached_odex_file_name_attempted_ = true;
-
- std::string error_msg;
- if (!DexLocationToOdexFilename(dex_location_, isa_, &cached_odex_file_name_, &error_msg)) {
- // If we can't figure out the odex file, we treat it as if the odex
- // file was inaccessible.
- LOG(WARNING) << "Failed to determine odex file name: " << error_msg;
- }
- }
- return cached_odex_file_name_.empty() ? nullptr : &cached_odex_file_name_;
+ return odex_file_name_.empty() ? nullptr : &odex_file_name_;
}
bool OatFileAssistant::OdexFileExists() {
@@ -412,18 +409,7 @@
}
const std::string* OatFileAssistant::OatFileName() {
- if (!cached_oat_file_name_attempted_) {
- cached_oat_file_name_attempted_ = true;
-
- std::string error_msg;
- if (!DexLocationToOatFilename(dex_location_, isa_, &cached_oat_file_name_, &error_msg)) {
- // If we can't determine the oat file name, we treat the oat file as
- // inaccessible.
- LOG(WARNING) << "Failed to determine oat file name for dex location "
- << dex_location_ << ": " << error_msg;
- }
- }
- return cached_oat_file_name_.empty() ? nullptr : &cached_oat_file_name_;
+ return oat_file_name_.empty() ? nullptr : &oat_file_name_;
}
bool OatFileAssistant::OatFileExists() {