diff options
| -rw-r--r-- | runtime/oat_file_assistant.cc | 134 | ||||
| -rw-r--r-- | runtime/oat_file_assistant.h | 36 |
2 files changed, 49 insertions, 121 deletions
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc index a70d65adee..aae9d97aeb 100644 --- a/runtime/oat_file_assistant.cc +++ b/runtime/oat_file_assistant.cc @@ -87,7 +87,6 @@ OatFileAssistant::OatFileAssistant(const char* dex_location, if (oat_location != nullptr) { cached_oat_file_name_ = std::string(oat_location); cached_oat_file_name_attempted_ = true; - cached_oat_file_name_found_ = true; } } @@ -357,15 +356,13 @@ const std::string* OatFileAssistant::OdexFileName() { cached_odex_file_name_attempted_ = true; std::string error_msg; - cached_odex_file_name_found_ = DexFilenameToOdexFilename( - dex_location_, isa_, &cached_odex_file_name_, &error_msg); - if (!cached_odex_file_name_found_) { + if (!DexFilenameToOdexFilename(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_found_ ? &cached_odex_file_name_ : nullptr; + return cached_odex_file_name_.empty() ? nullptr : &cached_odex_file_name_; } bool OatFileAssistant::OdexFileExists() { @@ -373,26 +370,20 @@ bool OatFileAssistant::OdexFileExists() { } OatFileAssistant::OatStatus OatFileAssistant::OdexFileStatus() { - if (OdexFileIsOutOfDate()) { - return kOatOutOfDate; - } - if (OdexFileIsUpToDate()) { - return kOatUpToDate; - } - return kOatNeedsRelocation; -} - -bool OatFileAssistant::OdexFileIsOutOfDate() { - if (!odex_file_is_out_of_date_attempted_) { - odex_file_is_out_of_date_attempted_ = true; + if (!odex_file_status_attempted_) { + odex_file_status_attempted_ = true; const OatFile* odex_file = GetOdexFile(); if (odex_file == nullptr) { - cached_odex_file_is_out_of_date_ = true; + cached_odex_file_status_ = kOatOutOfDate; } else { - cached_odex_file_is_out_of_date_ = GivenOatFileIsOutOfDate(*odex_file); + cached_odex_file_status_ = GivenOatFileStatus(*odex_file); } } - return cached_odex_file_is_out_of_date_; + return cached_odex_file_status_; +} + +bool OatFileAssistant::OdexFileIsOutOfDate() { + return OdexFileStatus() == kOatOutOfDate; } bool OatFileAssistant::OdexFileNeedsRelocation() { @@ -400,16 +391,7 @@ bool OatFileAssistant::OdexFileNeedsRelocation() { } bool OatFileAssistant::OdexFileIsUpToDate() { - if (!odex_file_is_up_to_date_attempted_) { - odex_file_is_up_to_date_attempted_ = true; - const OatFile* odex_file = GetOdexFile(); - if (odex_file == nullptr) { - cached_odex_file_is_up_to_date_ = false; - } else { - cached_odex_file_is_up_to_date_ = GivenOatFileIsUpToDate(*odex_file); - } - } - return cached_odex_file_is_up_to_date_; + return OdexFileStatus() == kOatUpToDate; } CompilerFilter::Filter OatFileAssistant::OdexFileCompilerFilter() { @@ -441,16 +423,15 @@ const std::string* OatFileAssistant::OatFileName() { std::string cache_dir = StringPrintf("%s%s", DalvikCacheDirectory().c_str(), GetInstructionSetString(isa_)); std::string error_msg; - cached_oat_file_name_found_ = GetDalvikCacheFilename(dex_location_.c_str(), - cache_dir.c_str(), &cached_oat_file_name_, &error_msg); - if (!cached_oat_file_name_found_) { + if (!GetDalvikCacheFilename(dex_location_.c_str(), + cache_dir.c_str(), &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_found_ ? &cached_oat_file_name_ : nullptr; + return cached_oat_file_name_.empty() ? nullptr : &cached_oat_file_name_; } bool OatFileAssistant::OatFileExists() { @@ -458,26 +439,20 @@ bool OatFileAssistant::OatFileExists() { } OatFileAssistant::OatStatus OatFileAssistant::OatFileStatus() { - if (OatFileIsOutOfDate()) { - return kOatOutOfDate; - } - if (OatFileIsUpToDate()) { - return kOatUpToDate; - } - return kOatNeedsRelocation; -} - -bool OatFileAssistant::OatFileIsOutOfDate() { - if (!oat_file_is_out_of_date_attempted_) { - oat_file_is_out_of_date_attempted_ = true; + if (!oat_file_status_attempted_) { + oat_file_status_attempted_ = true; const OatFile* oat_file = GetOatFile(); if (oat_file == nullptr) { - cached_oat_file_is_out_of_date_ = true; + cached_oat_file_status_ = kOatOutOfDate; } else { - cached_oat_file_is_out_of_date_ = GivenOatFileIsOutOfDate(*oat_file); + cached_oat_file_status_ = GivenOatFileStatus(*oat_file); } } - return cached_oat_file_is_out_of_date_; + return cached_oat_file_status_; +} + +bool OatFileAssistant::OatFileIsOutOfDate() { + return OatFileStatus() == kOatOutOfDate; } bool OatFileAssistant::OatFileNeedsRelocation() { @@ -485,16 +460,7 @@ bool OatFileAssistant::OatFileNeedsRelocation() { } bool OatFileAssistant::OatFileIsUpToDate() { - if (!oat_file_is_up_to_date_attempted_) { - oat_file_is_up_to_date_attempted_ = true; - const OatFile* oat_file = GetOatFile(); - if (oat_file == nullptr) { - cached_oat_file_is_up_to_date_ = false; - } else { - cached_oat_file_is_up_to_date_ = GivenOatFileIsUpToDate(*oat_file); - } - } - return cached_oat_file_is_up_to_date_; + return OatFileStatus() == kOatUpToDate; } CompilerFilter::Filter OatFileAssistant::OatFileCompilerFilter() { @@ -505,19 +471,6 @@ CompilerFilter::Filter OatFileAssistant::OatFileCompilerFilter() { } OatFileAssistant::OatStatus OatFileAssistant::GivenOatFileStatus(const OatFile& file) { - // TODO: This could cause GivenOatFileIsOutOfDate to be called twice, which - // is more work than we need to do. If performance becomes a concern, and - // this method is actually called, this should be fixed. - if (GivenOatFileIsOutOfDate(file)) { - return kOatOutOfDate; - } - if (GivenOatFileIsUpToDate(file)) { - return kOatUpToDate; - } - return kOatNeedsRelocation; -} - -bool OatFileAssistant::GivenOatFileIsOutOfDate(const OatFile& file) { // Verify the dex checksum. // Note: GetOatDexFile will return null if the dex checksum doesn't match // what we provide, which verifies the primary dex checksum for us. @@ -525,7 +478,7 @@ bool OatFileAssistant::GivenOatFileIsOutOfDate(const OatFile& file) { const OatFile::OatDexFile* oat_dex_file = file.GetOatDexFile( dex_location_.c_str(), dex_checksum_pointer, false); if (oat_dex_file == nullptr) { - return true; + return kOatOutOfDate; } // Verify the dex checksums for any secondary multidex files @@ -550,7 +503,7 @@ bool OatFileAssistant::GivenOatFileIsOutOfDate(const OatFile& file) { << secondary_dex_location << ". Expected: " << expected_secondary_checksum << ", Actual: " << actual_secondary_checksum; - return true; + return kOatOutOfDate; } } else { // If we can't get the checksum for the secondary location, we assume @@ -570,7 +523,7 @@ bool OatFileAssistant::GivenOatFileIsOutOfDate(const OatFile& file) { VLOG(oat) << "No image for oat image checksum to match against."; if (HasOriginalDexFiles()) { - return true; + return kOatOutOfDate; } // If there is no original dex file to fall back to, grudgingly accept @@ -584,33 +537,18 @@ bool OatFileAssistant::GivenOatFileIsOutOfDate(const OatFile& file) { } else if (file.GetOatHeader().GetImageFileLocationOatChecksum() != GetCombinedImageChecksum()) { VLOG(oat) << "Oat image checksum does not match image checksum."; - return true; + return kOatOutOfDate; } } else { VLOG(oat) << "Image checksum test skipped for compiler filter " << current_compiler_filter; } - // Everything looks good; the dex file is not out of date. - return false; -} - -bool OatFileAssistant::GivenOatFileNeedsRelocation(const OatFile& file) { - return GivenOatFileStatus(file) == kOatNeedsRelocation; -} - -bool OatFileAssistant::GivenOatFileIsUpToDate(const OatFile& file) { - if (GivenOatFileIsOutOfDate(file)) { - return false; - } - - CompilerFilter::Filter current_compiler_filter = file.GetCompilerFilter(); - if (CompilerFilter::IsBytecodeCompilationEnabled(current_compiler_filter)) { if (!file.IsPic()) { const ImageInfo* image_info = GetImageInfo(); if (image_info == nullptr) { VLOG(oat) << "No image to check oat relocation against."; - return false; + return kOatNeedsRelocation; } // Verify the oat_data_begin recorded for the image in the oat file matches @@ -622,7 +560,7 @@ bool OatFileAssistant::GivenOatFileIsUpToDate(const OatFile& file) { ": Oat file image oat_data_begin (" << oat_data_begin << ")" << " does not match actual image oat_data_begin (" << image_info->oat_data_begin << ")"; - return false; + return kOatNeedsRelocation; } // Verify the oat_patch_delta recorded for the image in the oat file matches @@ -633,7 +571,7 @@ bool OatFileAssistant::GivenOatFileIsUpToDate(const OatFile& file) { ": Oat file image patch delta (" << oat_patch_delta << ")" << " does not match actual image patch delta (" << image_info->patch_delta << ")"; - return false; + return kOatNeedsRelocation; } } else { // Oat files compiled in PIC mode do not require relocation. @@ -642,7 +580,7 @@ bool OatFileAssistant::GivenOatFileIsUpToDate(const OatFile& file) { } else { VLOG(oat) << "Oat relocation test skipped for compiler filter " << current_compiler_filter; } - return true; + return kOatUpToDate; } OatFileAssistant::ResultOfAttemptToUpdate @@ -947,8 +885,7 @@ bool OatFileAssistant::OdexFileHasPatchInfo() { void OatFileAssistant::ClearOdexFileCache() { odex_file_load_attempted_ = false; cached_odex_file_.reset(); - odex_file_is_out_of_date_attempted_ = false; - odex_file_is_up_to_date_attempted_ = false; + odex_file_status_attempted_ = false; } const OatFile* OatFileAssistant::GetOatFile() { @@ -988,8 +925,7 @@ bool OatFileAssistant::OatFileHasPatchInfo() { void OatFileAssistant::ClearOatFileCache() { oat_file_load_attempted_ = false; cached_oat_file_.reset(); - oat_file_is_out_of_date_attempted_ = false; - oat_file_is_up_to_date_attempted_ = false; + oat_file_status_attempted_ = false; } const OatFileAssistant::ImageInfo* OatFileAssistant::GetImageInfo() { diff --git a/runtime/oat_file_assistant.h b/runtime/oat_file_assistant.h index b8fea8290c..e4aba3f8ad 100644 --- a/runtime/oat_file_assistant.h +++ b/runtime/oat_file_assistant.h @@ -239,12 +239,9 @@ class OatFileAssistant { // |OatFileExists() == true|. CompilerFilter::Filter OatFileCompilerFilter(); - // These methods return the status for a given opened oat file with respect - // to the dex location. + // Return the status for a given opened oat file with respect to the dex + // location. OatStatus GivenOatFileStatus(const OatFile& file); - bool GivenOatFileIsOutOfDate(const OatFile& file); - bool GivenOatFileNeedsRelocation(const OatFile& file); - bool GivenOatFileIsUpToDate(const OatFile& file); // Generates the oat file by relocation from the named input file. // This does not check the current status before attempting to relocate the @@ -280,7 +277,8 @@ class OatFileAssistant { // Constructs the odex file name for the given dex location. // Returns true on success, in which case odex_filename is set to the odex // file name. - // Returns false on error, in which case error_msg describes the error. + // Returns false on error, in which case error_msg describes the error and + // odex_filename is not changed. // Neither odex_filename nor error_msg may be null. static bool DexFilenameToOdexFilename(const std::string& location, InstructionSet isa, std::string* odex_filename, std::string* error_msg); @@ -387,8 +385,9 @@ class OatFileAssistant { // Cached value of the odex file name. // This should be accessed only by the OdexFileName() method. + // The sentinel value "" is used if the odex file name could not be + // determined. bool cached_odex_file_name_attempted_ = false; - bool cached_odex_file_name_found_; std::string cached_odex_file_name_; // Cached value of the loaded odex file. @@ -397,18 +396,15 @@ class OatFileAssistant { bool odex_file_load_attempted_ = false; std::unique_ptr<OatFile> cached_odex_file_; - // Cached results for OdexFileIsOutOfDate - bool odex_file_is_out_of_date_attempted_ = false; - bool cached_odex_file_is_out_of_date_; - - // Cached results for OdexFileIsUpToDate - bool odex_file_is_up_to_date_attempted_ = false; - bool cached_odex_file_is_up_to_date_; + // Cached results for OdexFileStatus + bool odex_file_status_attempted_ = false; + OatStatus cached_odex_file_status_; // Cached value of the oat file name. // This should be accessed only by the OatFileName() method. + // The sentinel value "" is used if the oat file name could not be + // determined. bool cached_oat_file_name_attempted_ = false; - bool cached_oat_file_name_found_; std::string cached_oat_file_name_; // Cached value of the loaded oat file. @@ -417,13 +413,9 @@ class OatFileAssistant { bool oat_file_load_attempted_ = false; std::unique_ptr<OatFile> cached_oat_file_; - // Cached results for OatFileIsOutOfDate - bool oat_file_is_out_of_date_attempted_ = false; - bool cached_oat_file_is_out_of_date_; - - // Cached results for OatFileIsUpToDate - bool oat_file_is_up_to_date_attempted_ = false; - bool cached_oat_file_is_up_to_date_; + // Cached results for OatFileStatus + bool oat_file_status_attempted_ = false; + OatStatus cached_oat_file_status_; // Cached value of the image info. // Use the GetImageInfo method rather than accessing these directly. |