diff options
Diffstat (limited to 'runtime/oat_file_assistant.cc')
-rw-r--r-- | runtime/oat_file_assistant.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc index d6b08684b9..2bd5c76c00 100644 --- a/runtime/oat_file_assistant.cc +++ b/runtime/oat_file_assistant.cc @@ -38,6 +38,7 @@ #include "os.h" #include "profiler.h" #include "runtime.h" +#include "scoped_thread_state_change.h" #include "ScopedFd.h" #include "utils.h" @@ -326,6 +327,17 @@ bool OatFileAssistant::OdexFileIsUpToDate() { return cached_odex_file_is_up_to_date_; } +std::string OatFileAssistant::ArtFileName(const OatFile* oat_file) const { + const std::string oat_file_location = oat_file->GetLocation(); + // Replace extension with .art + const size_t last_ext = oat_file_location.find_last_of('.'); + if (last_ext == std::string::npos) { + LOG(ERROR) << "No extension in oat file " << oat_file_location; + return std::string(); + } + return oat_file_location.substr(0, last_ext) + ".art"; +} + const std::string* OatFileAssistant::OatFileName() { if (!cached_oat_file_name_attempted_) { cached_oat_file_name_attempted_ = true; @@ -1003,5 +1015,22 @@ ProfileFile* OatFileAssistant::GetOldProfile() { return old_profile_load_succeeded_ ? &cached_old_profile_ : nullptr; } +gc::space::ImageSpace* OatFileAssistant::OpenImageSpace(const OatFile* oat_file) { + DCHECK(oat_file != nullptr); + std::string art_file = ArtFileName(oat_file); + if (art_file.empty()) { + return nullptr; + } + std::string error_msg; + ScopedObjectAccess soa(Thread::Current()); + gc::space::ImageSpace* ret = gc::space::ImageSpace::CreateFromAppImage(art_file.c_str(), + oat_file, + &error_msg); + if (ret == nullptr) { + LOG(INFO) << "Failed to open app image " << art_file.c_str() << " " << error_msg; + } + return ret; +} + } // namespace art |