Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "oat_file_assistant.h" |
| 18 | |
Richard Uhler | 46cc64f | 2016-11-14 14:53:55 +0000 | [diff] [blame] | 19 | #include <sstream> |
| 20 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 21 | #include <sys/stat.h> |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 22 | |
| 23 | #include "android-base/strings.h" |
| 24 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 25 | #include "base/logging.h" |
Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 26 | #include "compiler_filter.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 27 | #include "class_linker.h" |
| 28 | #include "gc/heap.h" |
| 29 | #include "gc/space/image_space.h" |
| 30 | #include "image.h" |
| 31 | #include "oat.h" |
| 32 | #include "os.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 33 | #include "runtime.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 34 | #include "scoped_thread_state_change-inl.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 35 | #include "utils.h" |
| 36 | |
| 37 | namespace art { |
| 38 | |
Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 39 | std::ostream& operator << (std::ostream& stream, const OatFileAssistant::OatStatus status) { |
| 40 | switch (status) { |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 41 | case OatFileAssistant::kOatCannotOpen: |
| 42 | stream << "kOatCannotOpen"; |
| 43 | break; |
| 44 | case OatFileAssistant::kOatDexOutOfDate: |
| 45 | stream << "kOatDexOutOfDate"; |
| 46 | break; |
| 47 | case OatFileAssistant::kOatBootImageOutOfDate: |
| 48 | stream << "kOatBootImageOutOfDate"; |
| 49 | break; |
| 50 | case OatFileAssistant::kOatRelocationOutOfDate: |
| 51 | stream << "kOatRelocationOutOfDate"; |
Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 52 | break; |
| 53 | case OatFileAssistant::kOatUpToDate: |
| 54 | stream << "kOatUpToDate"; |
| 55 | break; |
Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 56 | default: |
| 57 | UNREACHABLE(); |
| 58 | } |
| 59 | |
| 60 | return stream; |
| 61 | } |
| 62 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 63 | OatFileAssistant::OatFileAssistant(const char* dex_location, |
| 64 | const InstructionSet isa, |
| 65 | bool load_executable) |
Richard Uhler | d1472a2 | 2016-04-15 15:18:56 -0700 | [diff] [blame] | 66 | : OatFileAssistant(dex_location, nullptr, isa, load_executable) |
Calin Juravle | b077e15 | 2016-02-18 18:47:37 +0000 | [diff] [blame] | 67 | { } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 68 | |
| 69 | OatFileAssistant::OatFileAssistant(const char* dex_location, |
| 70 | const char* oat_location, |
| 71 | const InstructionSet isa, |
| 72 | bool load_executable) |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 73 | : isa_(isa), |
| 74 | load_executable_(load_executable), |
| 75 | odex_(this, /*is_oat_location*/ false), |
| 76 | oat_(this, /*is_oat_location*/ true) { |
Richard Uhler | 740eec9 | 2015-10-15 15:12:23 -0700 | [diff] [blame] | 77 | CHECK(dex_location != nullptr) << "OatFileAssistant: null dex location"; |
| 78 | dex_location_.assign(dex_location); |
| 79 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 80 | if (load_executable_ && isa != kRuntimeISA) { |
| 81 | LOG(WARNING) << "OatFileAssistant: Load executable specified, " |
| 82 | << "but isa is not kRuntimeISA. Will not attempt to load executable."; |
| 83 | load_executable_ = false; |
| 84 | } |
| 85 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 86 | // Get the odex filename. |
Richard Uhler | d684f52 | 2016-04-19 13:24:41 -0700 | [diff] [blame] | 87 | std::string error_msg; |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 88 | std::string odex_file_name; |
| 89 | if (DexLocationToOdexFilename(dex_location_, isa_, &odex_file_name, &error_msg)) { |
| 90 | odex_.Reset(odex_file_name); |
| 91 | } else { |
Richard Uhler | d684f52 | 2016-04-19 13:24:41 -0700 | [diff] [blame] | 92 | LOG(WARNING) << "Failed to determine odex file name: " << error_msg; |
| 93 | } |
| 94 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 95 | // Get the oat filename. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 96 | if (oat_location != nullptr) { |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 97 | oat_.Reset(oat_location); |
Richard Uhler | d684f52 | 2016-04-19 13:24:41 -0700 | [diff] [blame] | 98 | } else { |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 99 | std::string oat_file_name; |
| 100 | if (DexLocationToOatFilename(dex_location_, isa_, &oat_file_name, &error_msg)) { |
| 101 | oat_.Reset(oat_file_name); |
| 102 | } else { |
Richard Uhler | d684f52 | 2016-04-19 13:24:41 -0700 | [diff] [blame] | 103 | LOG(WARNING) << "Failed to determine oat file name for dex location " |
| 104 | << dex_location_ << ": " << error_msg; |
| 105 | } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 106 | } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | OatFileAssistant::~OatFileAssistant() { |
| 110 | // Clean up the lock file. |
Richard Uhler | 581f4e9 | 2015-05-07 10:19:35 -0700 | [diff] [blame] | 111 | if (flock_.HasFile()) { |
Vladimir Marko | 66fdcbd | 2016-04-05 14:19:08 +0100 | [diff] [blame] | 112 | unlink(flock_.GetFile()->GetPath().c_str()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | bool OatFileAssistant::IsInBootClassPath() { |
| 117 | // Note: We check the current boot class path, regardless of the ISA |
| 118 | // specified by the user. This is okay, because the boot class path should |
| 119 | // be the same for all ISAs. |
| 120 | // TODO: Can we verify the boot class path is the same for all ISAs? |
| 121 | Runtime* runtime = Runtime::Current(); |
| 122 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 123 | const auto& boot_class_path = class_linker->GetBootClassPath(); |
| 124 | for (size_t i = 0; i < boot_class_path.size(); i++) { |
Richard Uhler | 740eec9 | 2015-10-15 15:12:23 -0700 | [diff] [blame] | 125 | if (boot_class_path[i]->GetLocation() == dex_location_) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 126 | VLOG(oat) << "Dex location " << dex_location_ << " is in boot class path"; |
| 127 | return true; |
| 128 | } |
| 129 | } |
| 130 | return false; |
| 131 | } |
| 132 | |
| 133 | bool OatFileAssistant::Lock(std::string* error_msg) { |
| 134 | CHECK(error_msg != nullptr); |
Richard Uhler | 581f4e9 | 2015-05-07 10:19:35 -0700 | [diff] [blame] | 135 | CHECK(!flock_.HasFile()) << "OatFileAssistant::Lock already acquired"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 136 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 137 | const std::string* oat_file_name = oat_.Filename(); |
| 138 | if (oat_file_name == nullptr) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 139 | *error_msg = "Failed to determine lock file"; |
| 140 | return false; |
| 141 | } |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 142 | std::string lock_file_name = *oat_file_name + ".flock"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 143 | |
Richard Uhler | 581f4e9 | 2015-05-07 10:19:35 -0700 | [diff] [blame] | 144 | if (!flock_.Init(lock_file_name.c_str(), error_msg)) { |
Vladimir Marko | 66fdcbd | 2016-04-05 14:19:08 +0100 | [diff] [blame] | 145 | unlink(lock_file_name.c_str()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 146 | return false; |
| 147 | } |
| 148 | return true; |
| 149 | } |
| 150 | |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 151 | int OatFileAssistant::GetDexOptNeeded(CompilerFilter::Filter target, bool profile_changed) { |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 152 | OatFileInfo& info = GetBestInfo(); |
| 153 | DexOptNeeded dexopt_needed = info.GetDexOptNeeded(target, profile_changed); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 154 | if (info.IsOatLocation() || dexopt_needed == kDex2OatFromScratch) { |
| 155 | return dexopt_needed; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 156 | } |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 157 | return -dexopt_needed; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 160 | // Figure out the currently specified compile filter option in the runtime. |
| 161 | // Returns true on success, false if the compiler filter is invalid, in which |
| 162 | // case error_msg describes the problem. |
| 163 | static bool GetRuntimeCompilerFilterOption(CompilerFilter::Filter* filter, |
| 164 | std::string* error_msg) { |
| 165 | CHECK(filter != nullptr); |
| 166 | CHECK(error_msg != nullptr); |
| 167 | |
| 168 | *filter = CompilerFilter::kDefaultCompilerFilter; |
| 169 | for (StringPiece option : Runtime::Current()->GetCompilerOptions()) { |
| 170 | if (option.starts_with("--compiler-filter=")) { |
| 171 | const char* compiler_filter_string = option.substr(strlen("--compiler-filter=")).data(); |
| 172 | if (!CompilerFilter::ParseCompilerFilter(compiler_filter_string, filter)) { |
| 173 | *error_msg = std::string("Unknown --compiler-filter value: ") |
| 174 | + std::string(compiler_filter_string); |
| 175 | return false; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | return true; |
| 180 | } |
| 181 | |
Richard Uhler | 01be681 | 2016-05-17 10:34:52 -0700 | [diff] [blame] | 182 | bool OatFileAssistant::IsUpToDate() { |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 183 | return GetBestInfo().Status() == kOatUpToDate; |
Richard Uhler | 01be681 | 2016-05-17 10:34:52 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 186 | OatFileAssistant::ResultOfAttemptToUpdate |
Richard Uhler | d1472a2 | 2016-04-15 15:18:56 -0700 | [diff] [blame] | 187 | OatFileAssistant::MakeUpToDate(bool profile_changed, std::string* error_msg) { |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 188 | CompilerFilter::Filter target; |
| 189 | if (!GetRuntimeCompilerFilterOption(&target, error_msg)) { |
| 190 | return kUpdateNotAttempted; |
| 191 | } |
| 192 | |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 193 | OatFileInfo& info = GetBestInfo(); |
| 194 | switch (info.GetDexOptNeeded(target, profile_changed)) { |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 195 | case kNoDexOptNeeded: |
| 196 | return kUpdateSucceeded; |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 197 | |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 198 | // TODO: For now, don't bother with all the different ways we can call |
| 199 | // dex2oat to generate the oat file. Always generate the oat file as if it |
| 200 | // were kDex2OatFromScratch. |
| 201 | case kDex2OatFromScratch: |
| 202 | case kDex2OatForBootImage: |
| 203 | case kDex2OatForRelocation: |
| 204 | case kDex2OatForFilter: |
| 205 | return GenerateOatFile(error_msg); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 206 | } |
| 207 | UNREACHABLE(); |
| 208 | } |
| 209 | |
| 210 | std::unique_ptr<OatFile> OatFileAssistant::GetBestOatFile() { |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 211 | return GetBestInfo().ReleaseFileForUse(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 212 | } |
| 213 | |
Richard Uhler | 46cc64f | 2016-11-14 14:53:55 +0000 | [diff] [blame] | 214 | std::string OatFileAssistant::GetStatusDump() { |
| 215 | std::ostringstream status; |
| 216 | bool oat_file_exists = false; |
| 217 | bool odex_file_exists = false; |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 218 | if (oat_.Status() != kOatCannotOpen) { |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 219 | // If we can open the file, neither Filename nor GetFile should return null. |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 220 | CHECK(oat_.Filename() != nullptr); |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 221 | CHECK(oat_.GetFile() != nullptr); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 222 | |
Richard Uhler | 46cc64f | 2016-11-14 14:53:55 +0000 | [diff] [blame] | 223 | oat_file_exists = true; |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 224 | status << *oat_.Filename() << " [compilation_filter="; |
| 225 | status << CompilerFilter::NameOfFilter(oat_.GetFile()->GetCompilerFilter()); |
| 226 | status << ", status=" << oat_.Status(); |
Richard Uhler | 46cc64f | 2016-11-14 14:53:55 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 229 | if (odex_.Status() != kOatCannotOpen) { |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 230 | // If we can open the file, neither Filename nor GetFile should return null. |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 231 | CHECK(odex_.Filename() != nullptr); |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 232 | CHECK(odex_.GetFile() != nullptr); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 233 | |
Richard Uhler | 46cc64f | 2016-11-14 14:53:55 +0000 | [diff] [blame] | 234 | odex_file_exists = true; |
| 235 | if (oat_file_exists) { |
| 236 | status << "] "; |
| 237 | } |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 238 | status << *odex_.Filename() << " [compilation_filter="; |
| 239 | status << CompilerFilter::NameOfFilter(odex_.GetFile()->GetCompilerFilter()); |
| 240 | status << ", status=" << odex_.Status(); |
Richard Uhler | 46cc64f | 2016-11-14 14:53:55 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | if (!oat_file_exists && !odex_file_exists) { |
| 244 | status << "invalid["; |
| 245 | } |
| 246 | |
| 247 | status << "]"; |
| 248 | return status.str(); |
| 249 | } |
| 250 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 251 | std::vector<std::unique_ptr<const DexFile>> OatFileAssistant::LoadDexFiles( |
| 252 | const OatFile& oat_file, const char* dex_location) { |
| 253 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 254 | |
| 255 | // Load the primary dex file. |
| 256 | std::string error_msg; |
| 257 | const OatFile::OatDexFile* oat_dex_file = oat_file.GetOatDexFile( |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 258 | dex_location, nullptr, &error_msg); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 259 | if (oat_dex_file == nullptr) { |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 260 | LOG(WARNING) << error_msg; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 261 | return std::vector<std::unique_ptr<const DexFile>>(); |
| 262 | } |
| 263 | |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 264 | std::unique_ptr<const DexFile> dex_file = oat_dex_file->OpenDexFile(&error_msg); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 265 | if (dex_file.get() == nullptr) { |
| 266 | LOG(WARNING) << "Failed to open dex file from oat dex file: " << error_msg; |
| 267 | return std::vector<std::unique_ptr<const DexFile>>(); |
| 268 | } |
| 269 | dex_files.push_back(std::move(dex_file)); |
| 270 | |
| 271 | // Load secondary multidex files |
Andreas Gampe | 90e3404 | 2015-04-27 20:01:52 -0700 | [diff] [blame] | 272 | for (size_t i = 1; ; i++) { |
| 273 | std::string secondary_dex_location = DexFile::GetMultiDexLocation(i, dex_location); |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 274 | oat_dex_file = oat_file.GetOatDexFile(secondary_dex_location.c_str(), nullptr); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 275 | if (oat_dex_file == nullptr) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 276 | // There are no more secondary dex files to load. |
| 277 | break; |
| 278 | } |
| 279 | |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 280 | dex_file = oat_dex_file->OpenDexFile(&error_msg); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 281 | if (dex_file.get() == nullptr) { |
| 282 | LOG(WARNING) << "Failed to open dex file from oat dex file: " << error_msg; |
| 283 | return std::vector<std::unique_ptr<const DexFile>>(); |
| 284 | } |
| 285 | dex_files.push_back(std::move(dex_file)); |
| 286 | } |
| 287 | return dex_files; |
| 288 | } |
| 289 | |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 290 | bool OatFileAssistant::HasOriginalDexFiles() { |
| 291 | // Ensure GetRequiredDexChecksum has been run so that |
| 292 | // has_original_dex_files_ is initialized. We don't care about the result of |
| 293 | // GetRequiredDexChecksum. |
| 294 | GetRequiredDexChecksum(); |
| 295 | return has_original_dex_files_; |
| 296 | } |
| 297 | |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 298 | OatFileAssistant::OatStatus OatFileAssistant::OdexFileStatus() { |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 299 | return odex_.Status(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 300 | } |
| 301 | |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 302 | OatFileAssistant::OatStatus OatFileAssistant::OatFileStatus() { |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 303 | return oat_.Status(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 304 | } |
| 305 | |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 306 | OatFileAssistant::OatStatus OatFileAssistant::GivenOatFileStatus(const OatFile& file) { |
| 307 | // Verify the ART_USE_READ_BARRIER state. |
| 308 | const bool is_cc = file.GetOatHeader().IsConcurrentCopying(); |
| 309 | constexpr bool kRuntimeIsCC = kUseReadBarrier; |
| 310 | if (is_cc != kRuntimeIsCC) { |
| 311 | return kOatCannotOpen; |
Andreas Gampe | f8cd890 | 2017-01-18 16:05:01 -0800 | [diff] [blame] | 312 | } |
| 313 | |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 314 | // Verify the dex checksum. |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 315 | // Note: GetOatDexFile will return null if the dex checksum doesn't match |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 316 | // what we provide, which verifies the primary dex checksum for us. |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 317 | std::string error_msg; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 318 | const uint32_t* dex_checksum_pointer = GetRequiredDexChecksum(); |
| 319 | const OatFile::OatDexFile* oat_dex_file = file.GetOatDexFile( |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 320 | dex_location_.c_str(), dex_checksum_pointer, &error_msg); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 321 | if (oat_dex_file == nullptr) { |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 322 | LOG(ERROR) << error_msg; |
| 323 | return kOatDexOutOfDate; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | // Verify the dex checksums for any secondary multidex files |
Andreas Gampe | 90e3404 | 2015-04-27 20:01:52 -0700 | [diff] [blame] | 327 | for (size_t i = 1; ; i++) { |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 328 | std::string secondary_dex_location = DexFile::GetMultiDexLocation(i, dex_location_.c_str()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 329 | const OatFile::OatDexFile* secondary_oat_dex_file |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 330 | = file.GetOatDexFile(secondary_dex_location.c_str(), nullptr); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 331 | if (secondary_oat_dex_file == nullptr) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 332 | // There are no more secondary dex files to check. |
| 333 | break; |
| 334 | } |
| 335 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 336 | uint32_t expected_secondary_checksum = 0; |
| 337 | if (DexFile::GetChecksum(secondary_dex_location.c_str(), |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 338 | &expected_secondary_checksum, &error_msg)) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 339 | uint32_t actual_secondary_checksum |
| 340 | = secondary_oat_dex_file->GetDexFileLocationChecksum(); |
| 341 | if (expected_secondary_checksum != actual_secondary_checksum) { |
| 342 | VLOG(oat) << "Dex checksum does not match for secondary dex: " |
| 343 | << secondary_dex_location |
| 344 | << ". Expected: " << expected_secondary_checksum |
| 345 | << ", Actual: " << actual_secondary_checksum; |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 346 | return kOatDexOutOfDate; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 347 | } |
| 348 | } else { |
| 349 | // If we can't get the checksum for the secondary location, we assume |
| 350 | // the dex checksum is up to date for this and all other secondary dex |
| 351 | // files. |
| 352 | break; |
| 353 | } |
| 354 | } |
| 355 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 356 | CompilerFilter::Filter current_compiler_filter = file.GetCompilerFilter(); |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 357 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 358 | // Verify the image checksum |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 359 | if (CompilerFilter::DependsOnImageChecksum(current_compiler_filter)) { |
| 360 | const ImageInfo* image_info = GetImageInfo(); |
| 361 | if (image_info == nullptr) { |
| 362 | VLOG(oat) << "No image for oat image checksum to match against."; |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 363 | |
Richard Uhler | 76f5cb6 | 2016-04-04 13:30:16 -0700 | [diff] [blame] | 364 | if (HasOriginalDexFiles()) { |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 365 | return kOatBootImageOutOfDate; |
Richard Uhler | 76f5cb6 | 2016-04-04 13:30:16 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | // If there is no original dex file to fall back to, grudgingly accept |
| 369 | // the oat file. This could technically lead to crashes, but there's no |
| 370 | // way we could find a better oat file to use for this dex location, |
| 371 | // and it's better than being stuck in a boot loop with no way out. |
| 372 | // The problem will hopefully resolve itself the next time the runtime |
| 373 | // starts up. |
| 374 | LOG(WARNING) << "Dex location " << dex_location_ << " does not seem to include dex file. " |
| 375 | << "Allow oat file use. This is potentially dangerous."; |
| 376 | } else if (file.GetOatHeader().GetImageFileLocationOatChecksum() |
| 377 | != GetCombinedImageChecksum()) { |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 378 | VLOG(oat) << "Oat image checksum does not match image checksum."; |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 379 | return kOatBootImageOutOfDate; |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 380 | } |
| 381 | } else { |
| 382 | VLOG(oat) << "Image checksum test skipped for compiler filter " << current_compiler_filter; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 383 | } |
| 384 | |
Vladimir Marko | f6d1e0f | 2016-05-23 15:32:42 +0100 | [diff] [blame] | 385 | if (CompilerFilter::IsBytecodeCompilationEnabled(current_compiler_filter)) { |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 386 | if (!file.IsPic()) { |
| 387 | const ImageInfo* image_info = GetImageInfo(); |
| 388 | if (image_info == nullptr) { |
| 389 | VLOG(oat) << "No image to check oat relocation against."; |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 390 | return kOatRelocationOutOfDate; |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 391 | } |
Richard Uhler | a62d2f0 | 2016-03-18 15:05:30 -0700 | [diff] [blame] | 392 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 393 | // Verify the oat_data_begin recorded for the image in the oat file matches |
| 394 | // the actual oat_data_begin for boot.oat in the image. |
| 395 | const OatHeader& oat_header = file.GetOatHeader(); |
| 396 | uintptr_t oat_data_begin = oat_header.GetImageFileLocationOatDataBegin(); |
| 397 | if (oat_data_begin != image_info->oat_data_begin) { |
| 398 | VLOG(oat) << file.GetLocation() << |
| 399 | ": Oat file image oat_data_begin (" << oat_data_begin << ")" |
| 400 | << " does not match actual image oat_data_begin (" |
| 401 | << image_info->oat_data_begin << ")"; |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 402 | return kOatRelocationOutOfDate; |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 403 | } |
Richard Uhler | a62d2f0 | 2016-03-18 15:05:30 -0700 | [diff] [blame] | 404 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 405 | // Verify the oat_patch_delta recorded for the image in the oat file matches |
| 406 | // the actual oat_patch_delta for the image. |
| 407 | int32_t oat_patch_delta = oat_header.GetImagePatchDelta(); |
| 408 | if (oat_patch_delta != image_info->patch_delta) { |
| 409 | VLOG(oat) << file.GetLocation() << |
| 410 | ": Oat file image patch delta (" << oat_patch_delta << ")" |
| 411 | << " does not match actual image patch delta (" |
| 412 | << image_info->patch_delta << ")"; |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 413 | return kOatRelocationOutOfDate; |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 414 | } |
| 415 | } else { |
| 416 | // Oat files compiled in PIC mode do not require relocation. |
| 417 | VLOG(oat) << "Oat relocation test skipped for PIC oat file"; |
| 418 | } |
| 419 | } else { |
| 420 | VLOG(oat) << "Oat relocation test skipped for compiler filter " << current_compiler_filter; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 421 | } |
Richard Uhler | e8109f7 | 2016-04-18 10:40:50 -0700 | [diff] [blame] | 422 | return kOatUpToDate; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 423 | } |
| 424 | |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 425 | OatFileAssistant::ResultOfAttemptToUpdate |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 426 | OatFileAssistant::GenerateOatFile(std::string* error_msg) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 427 | CHECK(error_msg != nullptr); |
| 428 | |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 429 | Runtime* runtime = Runtime::Current(); |
| 430 | if (!runtime->IsDex2OatEnabled()) { |
| 431 | *error_msg = "Generation of oat file for dex location " + dex_location_ |
| 432 | + " not attempted because dex2oat is disabled."; |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 433 | return kUpdateNotAttempted; |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 436 | if (oat_.Filename() == nullptr) { |
Richard Uhler | 740eec9 | 2015-10-15 15:12:23 -0700 | [diff] [blame] | 437 | *error_msg = "Generation of oat file for dex location " + dex_location_ |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 438 | + " not attempted because the oat file name could not be determined."; |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 439 | return kUpdateNotAttempted; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 440 | } |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 441 | const std::string& oat_file_name = *oat_.Filename(); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 442 | const std::string& vdex_file_name = ReplaceFileExtension(oat_file_name, "vdex"); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 443 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 444 | // dex2oat ignores missing dex files and doesn't report an error. |
| 445 | // Check explicitly here so we can detect the error properly. |
| 446 | // TODO: Why does dex2oat behave that way? |
Richard Uhler | 740eec9 | 2015-10-15 15:12:23 -0700 | [diff] [blame] | 447 | if (!OS::FileExists(dex_location_.c_str())) { |
| 448 | *error_msg = "Dex location " + dex_location_ + " does not exists."; |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 449 | return kUpdateNotAttempted; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 450 | } |
| 451 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 452 | std::unique_ptr<File> vdex_file(OS::CreateEmptyFile(vdex_file_name.c_str())); |
| 453 | if (vdex_file.get() == nullptr) { |
| 454 | *error_msg = "Generation of oat file " + oat_file_name |
| 455 | + " not attempted because the vdex file " + vdex_file_name |
| 456 | + " could not be opened."; |
| 457 | return kUpdateNotAttempted; |
| 458 | } |
| 459 | |
| 460 | if (fchmod(vdex_file->Fd(), 0644) != 0) { |
| 461 | *error_msg = "Generation of oat file " + oat_file_name |
| 462 | + " not attempted because the vdex file " + vdex_file_name |
| 463 | + " could not be made world readable."; |
| 464 | return kUpdateNotAttempted; |
| 465 | } |
| 466 | |
| 467 | std::unique_ptr<File> oat_file(OS::CreateEmptyFile(oat_file_name.c_str())); |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 468 | if (oat_file.get() == nullptr) { |
| 469 | *error_msg = "Generation of oat file " + oat_file_name |
| 470 | + " not attempted because the oat file could not be created."; |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 471 | return kUpdateNotAttempted; |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | if (fchmod(oat_file->Fd(), 0644) != 0) { |
| 475 | *error_msg = "Generation of oat file " + oat_file_name |
| 476 | + " not attempted because the oat file could not be made world readable."; |
| 477 | oat_file->Erase(); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 478 | return kUpdateNotAttempted; |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | std::vector<std::string> args; |
| 482 | args.push_back("--dex-file=" + dex_location_); |
Nicolas Geoffray | a6a448a | 2016-11-10 10:49:40 +0000 | [diff] [blame] | 483 | args.push_back("--output-vdex-fd=" + std::to_string(vdex_file->Fd())); |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 484 | args.push_back("--oat-fd=" + std::to_string(oat_file->Fd())); |
| 485 | args.push_back("--oat-location=" + oat_file_name); |
| 486 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 487 | if (!Dex2Oat(args, error_msg)) { |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 488 | // Manually delete the oat and vdex files. This ensures there is no garbage |
| 489 | // left over if the process unexpectedly died. |
| 490 | vdex_file->Erase(); |
| 491 | unlink(vdex_file_name.c_str()); |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 492 | oat_file->Erase(); |
Vladimir Marko | 66fdcbd | 2016-04-05 14:19:08 +0100 | [diff] [blame] | 493 | unlink(oat_file_name.c_str()); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 494 | return kUpdateFailed; |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 495 | } |
| 496 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 497 | if (vdex_file->FlushCloseOrErase() != 0) { |
| 498 | *error_msg = "Unable to close vdex file " + vdex_file_name; |
| 499 | unlink(vdex_file_name.c_str()); |
| 500 | return kUpdateFailed; |
| 501 | } |
| 502 | |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 503 | if (oat_file->FlushCloseOrErase() != 0) { |
| 504 | *error_msg = "Unable to close oat file " + oat_file_name; |
Vladimir Marko | 66fdcbd | 2016-04-05 14:19:08 +0100 | [diff] [blame] | 505 | unlink(oat_file_name.c_str()); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 506 | return kUpdateFailed; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | // Mark that the oat file has changed and we should try to reload. |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 510 | oat_.Reset(); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 511 | return kUpdateSucceeded; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | bool OatFileAssistant::Dex2Oat(const std::vector<std::string>& args, |
| 515 | std::string* error_msg) { |
| 516 | Runtime* runtime = Runtime::Current(); |
| 517 | std::string image_location = ImageLocation(); |
| 518 | if (image_location.empty()) { |
| 519 | *error_msg = "No image location found for Dex2Oat."; |
| 520 | return false; |
| 521 | } |
| 522 | |
| 523 | std::vector<std::string> argv; |
| 524 | argv.push_back(runtime->GetCompilerExecutable()); |
| 525 | argv.push_back("--runtime-arg"); |
| 526 | argv.push_back("-classpath"); |
| 527 | argv.push_back("--runtime-arg"); |
Jeff Hao | f0192c8 | 2016-03-28 20:39:50 -0700 | [diff] [blame] | 528 | std::string class_path = runtime->GetClassPathString(); |
| 529 | if (class_path == "") { |
| 530 | class_path = OatFile::kSpecialSharedLibrary; |
| 531 | } |
| 532 | argv.push_back(class_path); |
Nicolas Geoffray | 7a4d015 | 2015-07-10 17:29:39 +0100 | [diff] [blame] | 533 | if (runtime->IsDebuggable()) { |
Sebastien Hertz | 0de1133 | 2015-05-13 12:14:05 +0200 | [diff] [blame] | 534 | argv.push_back("--debuggable"); |
| 535 | } |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 536 | runtime->AddCurrentRuntimeFeaturesAsDex2OatArguments(&argv); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 537 | |
| 538 | if (!runtime->IsVerificationEnabled()) { |
| 539 | argv.push_back("--compiler-filter=verify-none"); |
| 540 | } |
| 541 | |
| 542 | if (runtime->MustRelocateIfPossible()) { |
| 543 | argv.push_back("--runtime-arg"); |
| 544 | argv.push_back("-Xrelocate"); |
| 545 | } else { |
| 546 | argv.push_back("--runtime-arg"); |
| 547 | argv.push_back("-Xnorelocate"); |
| 548 | } |
| 549 | |
| 550 | if (!kIsTargetBuild) { |
| 551 | argv.push_back("--host"); |
| 552 | } |
| 553 | |
| 554 | argv.push_back("--boot-image=" + image_location); |
| 555 | |
| 556 | std::vector<std::string> compiler_options = runtime->GetCompilerOptions(); |
| 557 | argv.insert(argv.end(), compiler_options.begin(), compiler_options.end()); |
| 558 | |
| 559 | argv.insert(argv.end(), args.begin(), args.end()); |
| 560 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 561 | std::string command_line(android::base::Join(argv, ' ')); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 562 | return Exec(argv, error_msg); |
| 563 | } |
| 564 | |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 565 | bool OatFileAssistant::DexLocationToOdexFilename(const std::string& location, |
| 566 | InstructionSet isa, |
| 567 | std::string* odex_filename, |
| 568 | std::string* error_msg) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 569 | CHECK(odex_filename != nullptr); |
| 570 | CHECK(error_msg != nullptr); |
| 571 | |
| 572 | // The odex file name is formed by replacing the dex_location extension with |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 573 | // .odex and inserting an oat/<isa> directory. For example: |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 574 | // location = /foo/bar/baz.jar |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 575 | // odex_location = /foo/bar/oat/<isa>/baz.odex |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 576 | |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 577 | // Find the directory portion of the dex location and add the oat/<isa> |
| 578 | // directory. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 579 | size_t pos = location.rfind('/'); |
| 580 | if (pos == std::string::npos) { |
| 581 | *error_msg = "Dex location " + location + " has no directory."; |
| 582 | return false; |
| 583 | } |
| 584 | std::string dir = location.substr(0, pos+1); |
Richard Uhler | 6343411 | 2015-03-16 14:32:16 -0700 | [diff] [blame] | 585 | dir += "oat/" + std::string(GetInstructionSetString(isa)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 586 | |
| 587 | // Find the file portion of the dex location. |
| 588 | std::string file; |
| 589 | if (pos == std::string::npos) { |
| 590 | file = location; |
| 591 | } else { |
| 592 | file = location.substr(pos+1); |
| 593 | } |
| 594 | |
| 595 | // Get the base part of the file without the extension. |
| 596 | pos = file.rfind('.'); |
| 597 | if (pos == std::string::npos) { |
| 598 | *error_msg = "Dex location " + location + " has no extension."; |
| 599 | return false; |
| 600 | } |
| 601 | std::string base = file.substr(0, pos); |
| 602 | |
| 603 | *odex_filename = dir + "/" + base + ".odex"; |
| 604 | return true; |
| 605 | } |
| 606 | |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 607 | bool OatFileAssistant::DexLocationToOatFilename(const std::string& location, |
| 608 | InstructionSet isa, |
| 609 | std::string* oat_filename, |
| 610 | std::string* error_msg) { |
| 611 | CHECK(oat_filename != nullptr); |
| 612 | CHECK(error_msg != nullptr); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 613 | |
Richard Uhler | 55b58b6 | 2016-08-12 09:05:13 -0700 | [diff] [blame] | 614 | std::string cache_dir = GetDalvikCache(GetInstructionSetString(isa)); |
| 615 | if (cache_dir.empty()) { |
| 616 | *error_msg = "Dalvik cache directory does not exist"; |
| 617 | return false; |
| 618 | } |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 619 | |
| 620 | // TODO: The oat file assistant should be the definitive place for |
| 621 | // determining the oat file name from the dex location, not |
| 622 | // GetDalvikCacheFilename. |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 623 | return GetDalvikCacheFilename(location.c_str(), cache_dir.c_str(), oat_filename, error_msg); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 624 | } |
| 625 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 626 | std::string OatFileAssistant::ImageLocation() { |
| 627 | Runtime* runtime = Runtime::Current(); |
Andreas Gampe | 8994a04 | 2015-12-30 19:03:17 +0000 | [diff] [blame] | 628 | const std::vector<gc::space::ImageSpace*>& image_spaces = |
| 629 | runtime->GetHeap()->GetBootImageSpaces(); |
| 630 | if (image_spaces.empty()) { |
| 631 | return ""; |
| 632 | } |
| 633 | return image_spaces[0]->GetImageLocation(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | const uint32_t* OatFileAssistant::GetRequiredDexChecksum() { |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 637 | if (!required_dex_checksum_attempted_) { |
| 638 | required_dex_checksum_attempted_ = true; |
| 639 | required_dex_checksum_found_ = false; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 640 | std::string error_msg; |
Richard Uhler | 740eec9 | 2015-10-15 15:12:23 -0700 | [diff] [blame] | 641 | if (DexFile::GetChecksum(dex_location_.c_str(), &cached_required_dex_checksum_, &error_msg)) { |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 642 | required_dex_checksum_found_ = true; |
| 643 | has_original_dex_files_ = true; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 644 | } else { |
| 645 | // This can happen if the original dex file has been stripped from the |
| 646 | // apk. |
| 647 | VLOG(oat) << "OatFileAssistant: " << error_msg; |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 648 | has_original_dex_files_ = false; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 649 | |
| 650 | // Get the checksum from the odex if we can. |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 651 | const OatFile* odex_file = odex_.GetFile(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 652 | if (odex_file != nullptr) { |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 653 | const OatFile::OatDexFile* odex_dex_file |
| 654 | = odex_file->GetOatDexFile(dex_location_.c_str(), nullptr); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 655 | if (odex_dex_file != nullptr) { |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 656 | cached_required_dex_checksum_ = odex_dex_file->GetDexFileLocationChecksum(); |
| 657 | required_dex_checksum_found_ = true; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | } |
| 661 | } |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 662 | return required_dex_checksum_found_ ? &cached_required_dex_checksum_ : nullptr; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 665 | const OatFileAssistant::ImageInfo* OatFileAssistant::GetImageInfo() { |
| 666 | if (!image_info_load_attempted_) { |
| 667 | image_info_load_attempted_ = true; |
| 668 | |
| 669 | Runtime* runtime = Runtime::Current(); |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 670 | std::vector<gc::space::ImageSpace*> image_spaces = runtime->GetHeap()->GetBootImageSpaces(); |
| 671 | if (!image_spaces.empty()) { |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 672 | cached_image_info_.location = image_spaces[0]->GetImageLocation(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 673 | |
| 674 | if (isa_ == kRuntimeISA) { |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 675 | const ImageHeader& image_header = image_spaces[0]->GetImageHeader(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 676 | cached_image_info_.oat_checksum = image_header.GetOatChecksum(); |
Mathieu Chartier | 073b16c | 2015-11-10 14:13:23 -0800 | [diff] [blame] | 677 | cached_image_info_.oat_data_begin = reinterpret_cast<uintptr_t>( |
| 678 | image_header.GetOatDataBegin()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 679 | cached_image_info_.patch_delta = image_header.GetPatchDelta(); |
| 680 | } else { |
Andreas Gampe | a463b6a | 2016-08-12 21:53:32 -0700 | [diff] [blame] | 681 | std::string error_msg; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 682 | std::unique_ptr<ImageHeader> image_header( |
Andreas Gampe | a463b6a | 2016-08-12 21:53:32 -0700 | [diff] [blame] | 683 | gc::space::ImageSpace::ReadImageHeader(cached_image_info_.location.c_str(), |
| 684 | isa_, |
| 685 | &error_msg)); |
| 686 | CHECK(image_header != nullptr) << error_msg; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 687 | cached_image_info_.oat_checksum = image_header->GetOatChecksum(); |
Mathieu Chartier | 073b16c | 2015-11-10 14:13:23 -0800 | [diff] [blame] | 688 | cached_image_info_.oat_data_begin = reinterpret_cast<uintptr_t>( |
| 689 | image_header->GetOatDataBegin()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 690 | cached_image_info_.patch_delta = image_header->GetPatchDelta(); |
| 691 | } |
| 692 | } |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 693 | image_info_load_succeeded_ = (!image_spaces.empty()); |
Jeff Hao | b11ffb7 | 2016-04-07 15:40:54 -0700 | [diff] [blame] | 694 | |
Jeff Hao | fd336c3 | 2016-04-07 19:46:31 -0700 | [diff] [blame] | 695 | combined_image_checksum_ = CalculateCombinedImageChecksum(isa_); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 696 | } |
| 697 | return image_info_load_succeeded_ ? &cached_image_info_ : nullptr; |
| 698 | } |
| 699 | |
Jeff Hao | b11ffb7 | 2016-04-07 15:40:54 -0700 | [diff] [blame] | 700 | // TODO: Use something better than xor. |
Jeff Hao | fd336c3 | 2016-04-07 19:46:31 -0700 | [diff] [blame] | 701 | uint32_t OatFileAssistant::CalculateCombinedImageChecksum(InstructionSet isa) { |
Jeff Hao | b11ffb7 | 2016-04-07 15:40:54 -0700 | [diff] [blame] | 702 | uint32_t checksum = 0; |
| 703 | std::vector<gc::space::ImageSpace*> image_spaces = |
| 704 | Runtime::Current()->GetHeap()->GetBootImageSpaces(); |
Jeff Hao | fd336c3 | 2016-04-07 19:46:31 -0700 | [diff] [blame] | 705 | if (isa == kRuntimeISA) { |
| 706 | for (gc::space::ImageSpace* image_space : image_spaces) { |
| 707 | checksum ^= image_space->GetImageHeader().GetOatChecksum(); |
| 708 | } |
| 709 | } else { |
| 710 | for (gc::space::ImageSpace* image_space : image_spaces) { |
| 711 | std::string location = image_space->GetImageLocation(); |
Andreas Gampe | a463b6a | 2016-08-12 21:53:32 -0700 | [diff] [blame] | 712 | std::string error_msg; |
Jeff Hao | fd336c3 | 2016-04-07 19:46:31 -0700 | [diff] [blame] | 713 | std::unique_ptr<ImageHeader> image_header( |
Andreas Gampe | a463b6a | 2016-08-12 21:53:32 -0700 | [diff] [blame] | 714 | gc::space::ImageSpace::ReadImageHeader(location.c_str(), isa, &error_msg)); |
| 715 | CHECK(image_header != nullptr) << error_msg; |
Jeff Hao | fd336c3 | 2016-04-07 19:46:31 -0700 | [diff] [blame] | 716 | checksum ^= image_header->GetOatChecksum(); |
| 717 | } |
Jeff Hao | b11ffb7 | 2016-04-07 15:40:54 -0700 | [diff] [blame] | 718 | } |
| 719 | return checksum; |
| 720 | } |
| 721 | |
| 722 | uint32_t OatFileAssistant::GetCombinedImageChecksum() { |
| 723 | if (!image_info_load_attempted_) { |
| 724 | GetImageInfo(); |
| 725 | } |
| 726 | return combined_image_checksum_; |
| 727 | } |
| 728 | |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 729 | OatFileAssistant::OatFileInfo& OatFileAssistant::GetBestInfo() { |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 730 | bool use_oat = oat_.IsUseable() || odex_.Status() == kOatCannotOpen; |
| 731 | return use_oat ? oat_ : odex_; |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 732 | } |
| 733 | |
Andreas Gampe | a463b6a | 2016-08-12 21:53:32 -0700 | [diff] [blame] | 734 | std::unique_ptr<gc::space::ImageSpace> OatFileAssistant::OpenImageSpace(const OatFile* oat_file) { |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 735 | DCHECK(oat_file != nullptr); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 736 | std::string art_file = ReplaceFileExtension(oat_file->GetLocation(), "art"); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 737 | if (art_file.empty()) { |
| 738 | return nullptr; |
| 739 | } |
| 740 | std::string error_msg; |
| 741 | ScopedObjectAccess soa(Thread::Current()); |
Andreas Gampe | a463b6a | 2016-08-12 21:53:32 -0700 | [diff] [blame] | 742 | std::unique_ptr<gc::space::ImageSpace> ret = |
| 743 | gc::space::ImageSpace::CreateFromAppImage(art_file.c_str(), oat_file, &error_msg); |
Mathieu Chartier | e778fc7 | 2016-01-25 20:11:28 -0800 | [diff] [blame] | 744 | if (ret == nullptr && (VLOG_IS_ON(image) || OS::FileExists(art_file.c_str()))) { |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 745 | LOG(INFO) << "Failed to open app image " << art_file.c_str() << " " << error_msg; |
| 746 | } |
| 747 | return ret; |
| 748 | } |
| 749 | |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 750 | OatFileAssistant::OatFileInfo::OatFileInfo(OatFileAssistant* oat_file_assistant, |
| 751 | bool is_oat_location) |
| 752 | : oat_file_assistant_(oat_file_assistant), is_oat_location_(is_oat_location) |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 753 | {} |
| 754 | |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 755 | bool OatFileAssistant::OatFileInfo::IsOatLocation() { |
| 756 | return is_oat_location_; |
| 757 | } |
| 758 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 759 | const std::string* OatFileAssistant::OatFileInfo::Filename() { |
| 760 | return filename_provided_ ? &filename_ : nullptr; |
| 761 | } |
| 762 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 763 | bool OatFileAssistant::OatFileInfo::IsUseable() { |
| 764 | switch (Status()) { |
| 765 | case kOatCannotOpen: |
| 766 | case kOatDexOutOfDate: |
| 767 | case kOatBootImageOutOfDate: return false; |
| 768 | |
| 769 | case kOatRelocationOutOfDate: |
| 770 | case kOatUpToDate: return true; |
| 771 | } |
| 772 | UNREACHABLE(); |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | OatFileAssistant::OatStatus OatFileAssistant::OatFileInfo::Status() { |
| 776 | if (!status_attempted_) { |
| 777 | status_attempted_ = true; |
| 778 | const OatFile* file = GetFile(); |
| 779 | if (file == nullptr) { |
Andreas Gampe | ba037b1 | 2017-01-25 00:16:27 +0000 | [diff] [blame] | 780 | status_ = kOatCannotOpen; |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 781 | } else { |
| 782 | status_ = oat_file_assistant_->GivenOatFileStatus(*file); |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 783 | VLOG(oat) << file->GetLocation() << " is " << status_ |
| 784 | << " with filter " << file->GetCompilerFilter(); |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | return status_; |
| 788 | } |
| 789 | |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 790 | OatFileAssistant::DexOptNeeded OatFileAssistant::OatFileInfo::GetDexOptNeeded( |
| 791 | CompilerFilter::Filter target, bool profile_changed) { |
| 792 | bool compilation_desired = CompilerFilter::IsBytecodeCompilationEnabled(target); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 793 | bool filter_okay = CompilerFilterIsOkay(target, profile_changed); |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 794 | |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 795 | if (filter_okay && Status() == kOatUpToDate) { |
| 796 | // The oat file is in good shape as is. |
| 797 | return kNoDexOptNeeded; |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 800 | if (filter_okay && !compilation_desired && Status() == kOatRelocationOutOfDate) { |
| 801 | // If no compilation is desired, then it doesn't matter if the oat |
| 802 | // file needs relocation. It's in good shape as is. |
| 803 | return kNoDexOptNeeded; |
| 804 | } |
| 805 | |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 806 | if (oat_file_assistant_->HasOriginalDexFiles()) { |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 807 | if (filter_okay && Status() == kOatRelocationOutOfDate) { |
| 808 | return kDex2OatForRelocation; |
| 809 | } |
| 810 | |
| 811 | if (IsUseable()) { |
| 812 | return kDex2OatForFilter; |
| 813 | } |
| 814 | |
| 815 | if (Status() == kOatBootImageOutOfDate) { |
| 816 | return kDex2OatForBootImage; |
| 817 | } |
| 818 | |
| 819 | return kDex2OatFromScratch; |
| 820 | } |
| 821 | |
| 822 | // Otherwise there is nothing we can do, even if we want to. |
| 823 | return kNoDexOptNeeded; |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 824 | } |
| 825 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 826 | const OatFile* OatFileAssistant::OatFileInfo::GetFile() { |
| 827 | CHECK(!file_released_) << "GetFile called after oat file released."; |
| 828 | if (!load_attempted_) { |
| 829 | load_attempted_ = true; |
| 830 | if (filename_provided_) { |
| 831 | std::string error_msg; |
| 832 | file_.reset(OatFile::Open(filename_.c_str(), |
| 833 | filename_.c_str(), |
| 834 | nullptr, |
| 835 | nullptr, |
| 836 | oat_file_assistant_->load_executable_, |
| 837 | /*low_4gb*/false, |
| 838 | oat_file_assistant_->dex_location_.c_str(), |
| 839 | &error_msg)); |
| 840 | if (file_.get() == nullptr) { |
| 841 | VLOG(oat) << "OatFileAssistant test for existing oat file " |
| 842 | << filename_ << ": " << error_msg; |
| 843 | } |
| 844 | } |
| 845 | } |
| 846 | return file_.get(); |
| 847 | } |
| 848 | |
| 849 | bool OatFileAssistant::OatFileInfo::CompilerFilterIsOkay( |
| 850 | CompilerFilter::Filter target, bool profile_changed) { |
| 851 | const OatFile* file = GetFile(); |
| 852 | if (file == nullptr) { |
| 853 | return false; |
| 854 | } |
| 855 | |
| 856 | CompilerFilter::Filter current = file->GetCompilerFilter(); |
| 857 | if (profile_changed && CompilerFilter::DependsOnProfile(current)) { |
| 858 | VLOG(oat) << "Compiler filter not okay because Profile changed"; |
| 859 | return false; |
| 860 | } |
| 861 | return CompilerFilter::IsAsGoodAs(current, target); |
| 862 | } |
| 863 | |
| 864 | bool OatFileAssistant::OatFileInfo::IsExecutable() { |
| 865 | const OatFile* file = GetFile(); |
| 866 | return (file != nullptr && file->IsExecutable()); |
| 867 | } |
| 868 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 869 | void OatFileAssistant::OatFileInfo::Reset() { |
| 870 | load_attempted_ = false; |
| 871 | file_.reset(); |
| 872 | status_attempted_ = false; |
| 873 | } |
| 874 | |
| 875 | void OatFileAssistant::OatFileInfo::Reset(const std::string& filename) { |
| 876 | filename_provided_ = true; |
| 877 | filename_ = filename; |
| 878 | Reset(); |
| 879 | } |
| 880 | |
| 881 | std::unique_ptr<OatFile> OatFileAssistant::OatFileInfo::ReleaseFile() { |
| 882 | file_released_ = true; |
| 883 | return std::move(file_); |
| 884 | } |
| 885 | |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 886 | std::unique_ptr<OatFile> OatFileAssistant::OatFileInfo::ReleaseFileForUse() { |
Richard Uhler | 3e580bc | 2016-11-08 16:23:07 +0000 | [diff] [blame] | 887 | if (Status() == kOatUpToDate) { |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 888 | return ReleaseFile(); |
| 889 | } |
| 890 | |
| 891 | VLOG(oat) << "Oat File Assistant: No relocated oat file found," |
| 892 | << " attempting to fall back to interpreting oat file instead."; |
| 893 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 894 | if (Status() == kOatRelocationOutOfDate && !IsExecutable()) { |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 895 | return ReleaseFile(); |
| 896 | } |
| 897 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 898 | if (Status() == kOatRelocationOutOfDate) { |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 899 | // We are loading an oat file for runtime use that needs relocation. |
| 900 | // Reload the file non-executable to ensure that we interpret out of the |
| 901 | // dex code in the oat file rather than trying to execute the unrelocated |
| 902 | // compiled code. |
| 903 | oat_file_assistant_->load_executable_ = false; |
| 904 | Reset(); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 905 | if (IsUseable()) { |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 906 | CHECK(!IsExecutable()); |
| 907 | return ReleaseFile(); |
| 908 | } |
| 909 | } |
| 910 | return std::unique_ptr<OatFile>(); |
| 911 | } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 912 | } // namespace art |