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 | |
Andreas Gampe | c15a2f4 | 2017-04-21 12:09:39 -0700 | [diff] [blame] | 23 | #include "android-base/stringprintf.h" |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 24 | #include "android-base/strings.h" |
| 25 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 26 | #include "base/logging.h" |
Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 27 | #include "base/stl_util.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 28 | #include "class_linker.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 29 | #include "compiler_filter.h" |
Mathieu Chartier | 79c87da | 2017-10-10 11:54:29 -0700 | [diff] [blame] | 30 | #include "dex_file_loader.h" |
David Sehr | 97c381e | 2017-02-01 15:09:58 -0800 | [diff] [blame] | 31 | #include "exec_utils.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 32 | #include "gc/heap.h" |
| 33 | #include "gc/space/image_space.h" |
| 34 | #include "image.h" |
| 35 | #include "oat.h" |
| 36 | #include "os.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 37 | #include "runtime.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 38 | #include "scoped_thread_state_change-inl.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 39 | #include "utils.h" |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 40 | #include "vdex_file.h" |
Calin Juravle | 27e0d1f | 2017-07-26 00:16:07 -0700 | [diff] [blame] | 41 | #include "class_loader_context.h" |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 42 | |
| 43 | namespace art { |
| 44 | |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 45 | using android::base::StringPrintf; |
| 46 | |
Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 47 | std::ostream& operator << (std::ostream& stream, const OatFileAssistant::OatStatus status) { |
| 48 | switch (status) { |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 49 | case OatFileAssistant::kOatCannotOpen: |
| 50 | stream << "kOatCannotOpen"; |
| 51 | break; |
| 52 | case OatFileAssistant::kOatDexOutOfDate: |
| 53 | stream << "kOatDexOutOfDate"; |
| 54 | break; |
| 55 | case OatFileAssistant::kOatBootImageOutOfDate: |
| 56 | stream << "kOatBootImageOutOfDate"; |
| 57 | break; |
| 58 | case OatFileAssistant::kOatRelocationOutOfDate: |
| 59 | stream << "kOatRelocationOutOfDate"; |
Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 60 | break; |
| 61 | case OatFileAssistant::kOatUpToDate: |
| 62 | stream << "kOatUpToDate"; |
| 63 | break; |
Narayan Kamath | 8943c1d | 2016-05-02 13:14:48 +0100 | [diff] [blame] | 64 | default: |
| 65 | UNREACHABLE(); |
| 66 | } |
| 67 | |
| 68 | return stream; |
| 69 | } |
| 70 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 71 | OatFileAssistant::OatFileAssistant(const char* dex_location, |
| 72 | const InstructionSet isa, |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 73 | bool load_executable, |
| 74 | int vdex_fd, |
| 75 | int oat_fd) |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 76 | : isa_(isa), |
| 77 | load_executable_(load_executable), |
| 78 | odex_(this, /*is_oat_location*/ false), |
| 79 | oat_(this, /*is_oat_location*/ true) { |
Richard Uhler | 740eec9 | 2015-10-15 15:12:23 -0700 | [diff] [blame] | 80 | CHECK(dex_location != nullptr) << "OatFileAssistant: null dex location"; |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 81 | |
| 82 | // Try to get the realpath for the dex location. |
| 83 | // |
| 84 | // This is OK with respect to dalvik cache naming scheme because we never |
| 85 | // generate oat files starting from symlinks which go into dalvik cache. |
| 86 | // (recall that the oat files in dalvik cache are encoded by replacing '/' |
| 87 | // with '@' in the path). |
| 88 | // The boot image oat files (which are symlinked in dalvik-cache) are not |
| 89 | // loaded via the oat file assistant. |
| 90 | // |
| 91 | // The only case when the dex location may resolve to a different path |
| 92 | // is for secondary dex files (e.g. /data/user/0 symlinks to /data/data and |
| 93 | // the app is free to create its own internal layout). Related to this it is |
| 94 | // worthwhile to mention that installd resolves the secondary dex location |
| 95 | // before calling dex2oat. |
| 96 | UniqueCPtr<const char[]> dex_location_real(realpath(dex_location, nullptr)); |
| 97 | if (dex_location_real != nullptr) { |
| 98 | dex_location_.assign(dex_location_real.get()); |
| 99 | } else { |
| 100 | // If we can't get the realpath of the location there's not much point in trying to move on. |
| 101 | PLOG(ERROR) << "Could not get the realpath of dex_location " << dex_location; |
| 102 | return; |
| 103 | } |
Richard Uhler | 740eec9 | 2015-10-15 15:12:23 -0700 | [diff] [blame] | 104 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 105 | if (load_executable_ && isa != kRuntimeISA) { |
| 106 | LOG(WARNING) << "OatFileAssistant: Load executable specified, " |
| 107 | << "but isa is not kRuntimeISA. Will not attempt to load executable."; |
| 108 | load_executable_ = false; |
| 109 | } |
| 110 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 111 | // Get the odex filename. |
Richard Uhler | d684f52 | 2016-04-19 13:24:41 -0700 | [diff] [blame] | 112 | std::string error_msg; |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 113 | std::string odex_file_name; |
| 114 | if (DexLocationToOdexFilename(dex_location_, isa_, &odex_file_name, &error_msg)) { |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 115 | odex_.Reset(odex_file_name, vdex_fd, oat_fd); |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 116 | } else { |
Richard Uhler | d684f52 | 2016-04-19 13:24:41 -0700 | [diff] [blame] | 117 | LOG(WARNING) << "Failed to determine odex file name: " << error_msg; |
| 118 | } |
| 119 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 120 | // Get the oat filename. |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 121 | std::string oat_file_name; |
| 122 | if (DexLocationToOatFilename(dex_location_, isa_, &oat_file_name, &error_msg)) { |
| 123 | oat_.Reset(oat_file_name); |
Richard Uhler | d684f52 | 2016-04-19 13:24:41 -0700 | [diff] [blame] | 124 | } else { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 125 | LOG(WARNING) << "Failed to determine oat file name for dex location " |
Calin Juravle | 9bfc6bb | 2017-05-04 00:13:50 +0000 | [diff] [blame] | 126 | << dex_location_ << ": " << error_msg; |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | // Check if the dex directory is writable. |
| 130 | // This will be needed in most uses of OatFileAssistant and so it's OK to |
| 131 | // compute it eagerly. (the only use which will not make use of it is |
| 132 | // OatFileAssistant::GetStatusDump()) |
| 133 | size_t pos = dex_location_.rfind('/'); |
| 134 | if (pos == std::string::npos) { |
| 135 | LOG(WARNING) << "Failed to determine dex file parent directory: " << dex_location_; |
| 136 | } else { |
| 137 | std::string parent = dex_location_.substr(0, pos); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 138 | if (access(parent.c_str(), W_OK) == 0 || oat_fd > 0) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 139 | dex_parent_writable_ = true; |
| 140 | } else { |
| 141 | VLOG(oat) << "Dex parent of " << dex_location_ << " is not writable: " << strerror(errno); |
Richard Uhler | d684f52 | 2016-04-19 13:24:41 -0700 | [diff] [blame] | 142 | } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 143 | } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | OatFileAssistant::~OatFileAssistant() { |
| 147 | // Clean up the lock file. |
Narayan Kamath | a3d27eb | 2017-05-11 13:50:59 +0100 | [diff] [blame] | 148 | if (flock_.get() != nullptr) { |
| 149 | unlink(flock_->GetPath().c_str()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
| 153 | bool OatFileAssistant::IsInBootClassPath() { |
| 154 | // Note: We check the current boot class path, regardless of the ISA |
| 155 | // specified by the user. This is okay, because the boot class path should |
| 156 | // be the same for all ISAs. |
| 157 | // TODO: Can we verify the boot class path is the same for all ISAs? |
| 158 | Runtime* runtime = Runtime::Current(); |
| 159 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 160 | const auto& boot_class_path = class_linker->GetBootClassPath(); |
| 161 | for (size_t i = 0; i < boot_class_path.size(); i++) { |
Richard Uhler | 740eec9 | 2015-10-15 15:12:23 -0700 | [diff] [blame] | 162 | if (boot_class_path[i]->GetLocation() == dex_location_) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 163 | VLOG(oat) << "Dex location " << dex_location_ << " is in boot class path"; |
| 164 | return true; |
| 165 | } |
| 166 | } |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | bool OatFileAssistant::Lock(std::string* error_msg) { |
| 171 | CHECK(error_msg != nullptr); |
Narayan Kamath | a3d27eb | 2017-05-11 13:50:59 +0100 | [diff] [blame] | 172 | CHECK(flock_.get() == nullptr) << "OatFileAssistant::Lock already acquired"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 173 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 174 | // Note the lock will only succeed for secondary dex files and in test |
| 175 | // environment. |
| 176 | // |
| 177 | // The lock *will fail* for all primary apks in a production environment. |
| 178 | // The app does not have permissions to create locks next to its dex location |
| 179 | // (be it system, data or vendor parition). We also cannot use the odex or |
| 180 | // oat location for the same reasoning. |
| 181 | // |
| 182 | // This is best effort and if it fails it's unlikely that we will be able |
| 183 | // to generate oat files anyway. |
| 184 | std::string lock_file_name = dex_location_ + "." + GetInstructionSetString(isa_) + ".flock"; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 185 | |
Narayan Kamath | a3d27eb | 2017-05-11 13:50:59 +0100 | [diff] [blame] | 186 | flock_ = LockedFile::Open(lock_file_name.c_str(), error_msg); |
| 187 | if (flock_.get() == nullptr) { |
Vladimir Marko | 66fdcbd | 2016-04-05 14:19:08 +0100 | [diff] [blame] | 188 | unlink(lock_file_name.c_str()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 189 | return false; |
| 190 | } |
| 191 | return true; |
| 192 | } |
| 193 | |
Shubham Ajmera | e4e812a | 2017-05-25 20:09:58 -0700 | [diff] [blame] | 194 | int OatFileAssistant::GetDexOptNeeded(CompilerFilter::Filter target, |
| 195 | bool profile_changed, |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 196 | bool downgrade, |
| 197 | ClassLoaderContext* class_loader_context) { |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 198 | OatFileInfo& info = GetBestInfo(); |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 199 | DexOptNeeded dexopt_needed = info.GetDexOptNeeded(target, |
| 200 | profile_changed, |
| 201 | downgrade, |
| 202 | class_loader_context); |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 203 | if (info.IsOatLocation() || dexopt_needed == kDex2OatFromScratch) { |
| 204 | return dexopt_needed; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 205 | } |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 206 | return -dexopt_needed; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 209 | // Figure out the currently specified compile filter option in the runtime. |
| 210 | // Returns true on success, false if the compiler filter is invalid, in which |
| 211 | // case error_msg describes the problem. |
| 212 | static bool GetRuntimeCompilerFilterOption(CompilerFilter::Filter* filter, |
| 213 | std::string* error_msg) { |
| 214 | CHECK(filter != nullptr); |
| 215 | CHECK(error_msg != nullptr); |
| 216 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 217 | *filter = OatFileAssistant::kDefaultCompilerFilterForDexLoading; |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 218 | for (StringPiece option : Runtime::Current()->GetCompilerOptions()) { |
| 219 | if (option.starts_with("--compiler-filter=")) { |
| 220 | const char* compiler_filter_string = option.substr(strlen("--compiler-filter=")).data(); |
| 221 | if (!CompilerFilter::ParseCompilerFilter(compiler_filter_string, filter)) { |
| 222 | *error_msg = std::string("Unknown --compiler-filter value: ") |
| 223 | + std::string(compiler_filter_string); |
| 224 | return false; |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | return true; |
| 229 | } |
| 230 | |
Richard Uhler | 01be681 | 2016-05-17 10:34:52 -0700 | [diff] [blame] | 231 | bool OatFileAssistant::IsUpToDate() { |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 232 | return GetBestInfo().Status() == kOatUpToDate; |
Richard Uhler | 01be681 | 2016-05-17 10:34:52 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 235 | OatFileAssistant::ResultOfAttemptToUpdate |
Calin Juravle | 27e0d1f | 2017-07-26 00:16:07 -0700 | [diff] [blame] | 236 | OatFileAssistant::MakeUpToDate(bool profile_changed, |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 237 | ClassLoaderContext* class_loader_context, |
Calin Juravle | 27e0d1f | 2017-07-26 00:16:07 -0700 | [diff] [blame] | 238 | std::string* error_msg) { |
Richard Uhler | f4b3487 | 2016-04-13 11:03:46 -0700 | [diff] [blame] | 239 | CompilerFilter::Filter target; |
| 240 | if (!GetRuntimeCompilerFilterOption(&target, error_msg)) { |
| 241 | return kUpdateNotAttempted; |
| 242 | } |
| 243 | |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 244 | OatFileInfo& info = GetBestInfo(); |
Calin Juravle | 27e0d1f | 2017-07-26 00:16:07 -0700 | [diff] [blame] | 245 | // TODO(calin, jeffhao): the context should really be passed to GetDexOptNeeded: b/62269291. |
| 246 | // This is actually not trivial in the current logic as it will interact with the collision |
| 247 | // check: |
| 248 | // - currently, if the context does not match but we have no collisions we still accept the |
| 249 | // oat file. |
| 250 | // - if GetDexOptNeeded would return kDex2OatFromScratch for a context mismatch and we make |
| 251 | // the oat code up to date the collision check becomes useless. |
| 252 | // - however, MakeUpToDate will not always succeed (e.g. for primary apks, or for dex files |
| 253 | // loaded in other processes). So it boils down to how far do we want to complicate |
| 254 | // the logic in order to enable the use of oat files. Maybe its time to try simplify it. |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 255 | switch (info.GetDexOptNeeded( |
| 256 | target, profile_changed, /*downgrade*/ false, class_loader_context)) { |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 257 | case kNoDexOptNeeded: |
| 258 | return kUpdateSucceeded; |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 259 | |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 260 | // TODO: For now, don't bother with all the different ways we can call |
| 261 | // dex2oat to generate the oat file. Always generate the oat file as if it |
| 262 | // were kDex2OatFromScratch. |
| 263 | case kDex2OatFromScratch: |
| 264 | case kDex2OatForBootImage: |
| 265 | case kDex2OatForRelocation: |
| 266 | case kDex2OatForFilter: |
Calin Juravle | 27e0d1f | 2017-07-26 00:16:07 -0700 | [diff] [blame] | 267 | return GenerateOatFileNoChecks(info, target, class_loader_context, error_msg); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 268 | } |
| 269 | UNREACHABLE(); |
| 270 | } |
| 271 | |
| 272 | std::unique_ptr<OatFile> OatFileAssistant::GetBestOatFile() { |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 273 | return GetBestInfo().ReleaseFileForUse(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Richard Uhler | 46cc64f | 2016-11-14 14:53:55 +0000 | [diff] [blame] | 276 | std::string OatFileAssistant::GetStatusDump() { |
| 277 | std::ostringstream status; |
| 278 | bool oat_file_exists = false; |
| 279 | bool odex_file_exists = false; |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 280 | if (oat_.Status() != kOatCannotOpen) { |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 281 | // If we can open the file, Filename should not return null. |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 282 | CHECK(oat_.Filename() != nullptr); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 283 | |
Richard Uhler | 46cc64f | 2016-11-14 14:53:55 +0000 | [diff] [blame] | 284 | oat_file_exists = true; |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 285 | status << *oat_.Filename() << "[status=" << oat_.Status() << ", "; |
| 286 | const OatFile* file = oat_.GetFile(); |
| 287 | if (file == nullptr) { |
| 288 | // If the file is null even though the status is not kOatCannotOpen, it |
| 289 | // means we must have a vdex file with no corresponding oat file. In |
| 290 | // this case we cannot determine the compilation filter. Indicate that |
| 291 | // we have only the vdex file instead. |
| 292 | status << "vdex-only"; |
| 293 | } else { |
| 294 | status << "compilation_filter=" << CompilerFilter::NameOfFilter(file->GetCompilerFilter()); |
| 295 | } |
Richard Uhler | 46cc64f | 2016-11-14 14:53:55 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 298 | if (odex_.Status() != kOatCannotOpen) { |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 299 | // If we can open the file, Filename should not return null. |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 300 | CHECK(odex_.Filename() != nullptr); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 301 | |
Richard Uhler | 46cc64f | 2016-11-14 14:53:55 +0000 | [diff] [blame] | 302 | odex_file_exists = true; |
| 303 | if (oat_file_exists) { |
| 304 | status << "] "; |
| 305 | } |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 306 | status << *odex_.Filename() << "[status=" << odex_.Status() << ", "; |
| 307 | const OatFile* file = odex_.GetFile(); |
| 308 | if (file == nullptr) { |
| 309 | status << "vdex-only"; |
| 310 | } else { |
| 311 | status << "compilation_filter=" << CompilerFilter::NameOfFilter(file->GetCompilerFilter()); |
| 312 | } |
Richard Uhler | 46cc64f | 2016-11-14 14:53:55 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | if (!oat_file_exists && !odex_file_exists) { |
| 316 | status << "invalid["; |
| 317 | } |
| 318 | |
| 319 | status << "]"; |
| 320 | return status.str(); |
| 321 | } |
| 322 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 323 | std::vector<std::unique_ptr<const DexFile>> OatFileAssistant::LoadDexFiles( |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 324 | const OatFile &oat_file, const char *dex_location) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 325 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 326 | if (LoadDexFiles(oat_file, dex_location, &dex_files)) { |
| 327 | return dex_files; |
| 328 | } else { |
| 329 | return std::vector<std::unique_ptr<const DexFile>>(); |
| 330 | } |
| 331 | } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 332 | |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 333 | bool OatFileAssistant::LoadDexFiles( |
| 334 | const OatFile &oat_file, |
| 335 | const std::string& dex_location, |
| 336 | std::vector<std::unique_ptr<const DexFile>>* out_dex_files) { |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 337 | // Load the main dex file. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 338 | std::string error_msg; |
| 339 | const OatFile::OatDexFile* oat_dex_file = oat_file.GetOatDexFile( |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 340 | dex_location.c_str(), nullptr, &error_msg); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 341 | if (oat_dex_file == nullptr) { |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 342 | LOG(WARNING) << error_msg; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 343 | return false; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 344 | } |
| 345 | |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 346 | 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] | 347 | if (dex_file.get() == nullptr) { |
| 348 | LOG(WARNING) << "Failed to open dex file from oat dex file: " << error_msg; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 349 | return false; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 350 | } |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 351 | out_dex_files->push_back(std::move(dex_file)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 352 | |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 353 | // Load the rest of the multidex entries |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 354 | for (size_t i = 1;; i++) { |
Mathieu Chartier | 79c87da | 2017-10-10 11:54:29 -0700 | [diff] [blame] | 355 | std::string multidex_dex_location = DexFileLoader::GetMultiDexLocation(i, dex_location.c_str()); |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 356 | oat_dex_file = oat_file.GetOatDexFile(multidex_dex_location.c_str(), nullptr); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 357 | if (oat_dex_file == nullptr) { |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 358 | // There are no more multidex entries to load. |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 359 | break; |
| 360 | } |
| 361 | |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 362 | dex_file = oat_dex_file->OpenDexFile(&error_msg); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 363 | if (dex_file.get() == nullptr) { |
| 364 | LOG(WARNING) << "Failed to open dex file from oat dex file: " << error_msg; |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 365 | return false; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 366 | } |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 367 | out_dex_files->push_back(std::move(dex_file)); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 368 | } |
Calin Juravle | 87e2cb6 | 2017-06-13 21:48:45 -0700 | [diff] [blame] | 369 | return true; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 370 | } |
| 371 | |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 372 | bool OatFileAssistant::HasOriginalDexFiles() { |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 373 | // Ensure GetRequiredDexChecksums has been run so that |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 374 | // has_original_dex_files_ is initialized. We don't care about the result of |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 375 | // GetRequiredDexChecksums. |
| 376 | GetRequiredDexChecksums(); |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 377 | return has_original_dex_files_; |
| 378 | } |
| 379 | |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 380 | OatFileAssistant::OatStatus OatFileAssistant::OdexFileStatus() { |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 381 | return odex_.Status(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Richard Uhler | 95abd04 | 2015-03-24 09:51:28 -0700 | [diff] [blame] | 384 | OatFileAssistant::OatStatus OatFileAssistant::OatFileStatus() { |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 385 | return oat_.Status(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 386 | } |
| 387 | |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 388 | bool OatFileAssistant::DexChecksumUpToDate(const VdexFile& file, std::string* error_msg) { |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 389 | const std::vector<uint32_t>* required_dex_checksums = GetRequiredDexChecksums(); |
| 390 | if (required_dex_checksums == nullptr) { |
| 391 | LOG(WARNING) << "Required dex checksums not found. Assuming dex checksums are up to date."; |
| 392 | return true; |
| 393 | } |
| 394 | |
| 395 | uint32_t number_of_dex_files = file.GetHeader().GetNumberOfDexFiles(); |
| 396 | if (required_dex_checksums->size() != number_of_dex_files) { |
| 397 | *error_msg = StringPrintf("expected %zu dex files but found %u", |
| 398 | required_dex_checksums->size(), |
| 399 | number_of_dex_files); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 400 | return false; |
Andreas Gampe | f8cd890 | 2017-01-18 16:05:01 -0800 | [diff] [blame] | 401 | } |
| 402 | |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 403 | for (uint32_t i = 0; i < number_of_dex_files; i++) { |
| 404 | uint32_t expected_checksum = (*required_dex_checksums)[i]; |
| 405 | uint32_t actual_checksum = file.GetLocationChecksum(i); |
| 406 | if (expected_checksum != actual_checksum) { |
Mathieu Chartier | 79c87da | 2017-10-10 11:54:29 -0700 | [diff] [blame] | 407 | std::string dex = DexFileLoader::GetMultiDexLocation(i, dex_location_.c_str()); |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 408 | *error_msg = StringPrintf("Dex checksum does not match for dex: %s." |
| 409 | "Expected: %u, actual: %u", |
| 410 | dex.c_str(), |
| 411 | expected_checksum, |
| 412 | actual_checksum); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 413 | return false; |
| 414 | } |
| 415 | } |
| 416 | |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 417 | return true; |
| 418 | } |
| 419 | |
| 420 | bool OatFileAssistant::DexChecksumUpToDate(const OatFile& file, std::string* error_msg) { |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 421 | const std::vector<uint32_t>* required_dex_checksums = GetRequiredDexChecksums(); |
| 422 | if (required_dex_checksums == nullptr) { |
| 423 | LOG(WARNING) << "Required dex checksums not found. Assuming dex checksums are up to date."; |
| 424 | return true; |
| 425 | } |
| 426 | |
| 427 | uint32_t number_of_dex_files = file.GetOatHeader().GetDexFileCount(); |
| 428 | if (required_dex_checksums->size() != number_of_dex_files) { |
| 429 | *error_msg = StringPrintf("expected %zu dex files but found %u", |
| 430 | required_dex_checksums->size(), |
| 431 | number_of_dex_files); |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 432 | return false; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 433 | } |
| 434 | |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 435 | for (uint32_t i = 0; i < number_of_dex_files; i++) { |
Mathieu Chartier | 79c87da | 2017-10-10 11:54:29 -0700 | [diff] [blame] | 436 | std::string dex = DexFileLoader::GetMultiDexLocation(i, dex_location_.c_str()); |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 437 | uint32_t expected_checksum = (*required_dex_checksums)[i]; |
| 438 | const OatFile::OatDexFile* oat_dex_file = file.GetOatDexFile(dex.c_str(), nullptr); |
| 439 | if (oat_dex_file == nullptr) { |
| 440 | *error_msg = StringPrintf("failed to find %s in %s", dex.c_str(), file.GetLocation().c_str()); |
| 441 | return false; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 442 | } |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 443 | uint32_t actual_checksum = oat_dex_file->GetDexFileLocationChecksum(); |
| 444 | if (expected_checksum != actual_checksum) { |
| 445 | VLOG(oat) << "Dex checksum does not match for dex: " << dex |
| 446 | << ". Expected: " << expected_checksum |
| 447 | << ", Actual: " << actual_checksum; |
| 448 | return false; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 449 | } |
| 450 | } |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 451 | return true; |
| 452 | } |
| 453 | |
| 454 | OatFileAssistant::OatStatus OatFileAssistant::GivenOatFileStatus(const OatFile& file) { |
| 455 | // Verify the ART_USE_READ_BARRIER state. |
| 456 | // TODO: Don't fully reject files due to read barrier state. If they contain |
| 457 | // compiled code and are otherwise okay, we should return something like |
| 458 | // kOatRelocationOutOfDate. If they don't contain compiled code, the read |
| 459 | // barrier state doesn't matter. |
| 460 | const bool is_cc = file.GetOatHeader().IsConcurrentCopying(); |
| 461 | constexpr bool kRuntimeIsCC = kUseReadBarrier; |
| 462 | if (is_cc != kRuntimeIsCC) { |
| 463 | return kOatCannotOpen; |
| 464 | } |
| 465 | |
| 466 | // Verify the dex checksum. |
| 467 | std::string error_msg; |
| 468 | if (kIsVdexEnabled) { |
| 469 | VdexFile* vdex = file.GetVdexFile(); |
| 470 | if (!DexChecksumUpToDate(*vdex, &error_msg)) { |
| 471 | LOG(ERROR) << error_msg; |
| 472 | return kOatDexOutOfDate; |
| 473 | } |
| 474 | } else { |
| 475 | if (!DexChecksumUpToDate(file, &error_msg)) { |
| 476 | LOG(ERROR) << error_msg; |
| 477 | return kOatDexOutOfDate; |
| 478 | } |
| 479 | } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 480 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 481 | CompilerFilter::Filter current_compiler_filter = file.GetCompilerFilter(); |
David Brazdil | ce4b0ba | 2016-01-28 15:05:49 +0000 | [diff] [blame] | 482 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 483 | // Verify the image checksum |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 484 | if (CompilerFilter::DependsOnImageChecksum(current_compiler_filter)) { |
| 485 | const ImageInfo* image_info = GetImageInfo(); |
| 486 | if (image_info == nullptr) { |
| 487 | VLOG(oat) << "No image for oat image checksum to match against."; |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 488 | |
Richard Uhler | 76f5cb6 | 2016-04-04 13:30:16 -0700 | [diff] [blame] | 489 | if (HasOriginalDexFiles()) { |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 490 | return kOatBootImageOutOfDate; |
Richard Uhler | 76f5cb6 | 2016-04-04 13:30:16 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | // If there is no original dex file to fall back to, grudgingly accept |
| 494 | // the oat file. This could technically lead to crashes, but there's no |
| 495 | // way we could find a better oat file to use for this dex location, |
| 496 | // and it's better than being stuck in a boot loop with no way out. |
| 497 | // The problem will hopefully resolve itself the next time the runtime |
| 498 | // starts up. |
| 499 | LOG(WARNING) << "Dex location " << dex_location_ << " does not seem to include dex file. " |
| 500 | << "Allow oat file use. This is potentially dangerous."; |
Richard Uhler | 95e0967 | 2017-02-22 11:37:41 +0000 | [diff] [blame] | 501 | } else if (file.GetOatHeader().GetImageFileLocationOatChecksum() != image_info->oat_checksum) { |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 502 | VLOG(oat) << "Oat image checksum does not match image checksum."; |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 503 | return kOatBootImageOutOfDate; |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 504 | } |
| 505 | } else { |
| 506 | VLOG(oat) << "Image checksum test skipped for compiler filter " << current_compiler_filter; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 509 | if (CompilerFilter::IsAotCompilationEnabled(current_compiler_filter)) { |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 510 | if (!file.IsPic()) { |
| 511 | const ImageInfo* image_info = GetImageInfo(); |
| 512 | if (image_info == nullptr) { |
| 513 | VLOG(oat) << "No image to check oat relocation against."; |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 514 | return kOatRelocationOutOfDate; |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 515 | } |
Richard Uhler | a62d2f0 | 2016-03-18 15:05:30 -0700 | [diff] [blame] | 516 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 517 | // Verify the oat_data_begin recorded for the image in the oat file matches |
| 518 | // the actual oat_data_begin for boot.oat in the image. |
| 519 | const OatHeader& oat_header = file.GetOatHeader(); |
| 520 | uintptr_t oat_data_begin = oat_header.GetImageFileLocationOatDataBegin(); |
| 521 | if (oat_data_begin != image_info->oat_data_begin) { |
| 522 | VLOG(oat) << file.GetLocation() << |
| 523 | ": Oat file image oat_data_begin (" << oat_data_begin << ")" |
| 524 | << " does not match actual image oat_data_begin (" |
| 525 | << image_info->oat_data_begin << ")"; |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 526 | return kOatRelocationOutOfDate; |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 527 | } |
Richard Uhler | a62d2f0 | 2016-03-18 15:05:30 -0700 | [diff] [blame] | 528 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 529 | // Verify the oat_patch_delta recorded for the image in the oat file matches |
| 530 | // the actual oat_patch_delta for the image. |
| 531 | int32_t oat_patch_delta = oat_header.GetImagePatchDelta(); |
| 532 | if (oat_patch_delta != image_info->patch_delta) { |
| 533 | VLOG(oat) << file.GetLocation() << |
| 534 | ": Oat file image patch delta (" << oat_patch_delta << ")" |
| 535 | << " does not match actual image patch delta (" |
| 536 | << image_info->patch_delta << ")"; |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 537 | return kOatRelocationOutOfDate; |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 538 | } |
| 539 | } else { |
| 540 | // Oat files compiled in PIC mode do not require relocation. |
| 541 | VLOG(oat) << "Oat relocation test skipped for PIC oat file"; |
| 542 | } |
| 543 | } else { |
| 544 | VLOG(oat) << "Oat relocation test skipped for compiler filter " << current_compiler_filter; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 545 | } |
Richard Uhler | e8109f7 | 2016-04-18 10:40:50 -0700 | [diff] [blame] | 546 | return kOatUpToDate; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 549 | static bool DexLocationToOdexNames(const std::string& location, |
| 550 | InstructionSet isa, |
| 551 | std::string* odex_filename, |
| 552 | std::string* oat_dir, |
| 553 | std::string* isa_dir, |
| 554 | std::string* error_msg) { |
| 555 | CHECK(odex_filename != nullptr); |
| 556 | CHECK(error_msg != nullptr); |
| 557 | |
| 558 | // The odex file name is formed by replacing the dex_location extension with |
| 559 | // .odex and inserting an oat/<isa> directory. For example: |
| 560 | // location = /foo/bar/baz.jar |
| 561 | // odex_location = /foo/bar/oat/<isa>/baz.odex |
| 562 | |
| 563 | // Find the directory portion of the dex location and add the oat/<isa> |
| 564 | // directory. |
| 565 | size_t pos = location.rfind('/'); |
| 566 | if (pos == std::string::npos) { |
| 567 | *error_msg = "Dex location " + location + " has no directory."; |
| 568 | return false; |
| 569 | } |
| 570 | std::string dir = location.substr(0, pos+1); |
| 571 | // Add the oat directory. |
| 572 | dir += "oat"; |
| 573 | if (oat_dir != nullptr) { |
| 574 | *oat_dir = dir; |
| 575 | } |
| 576 | // Add the isa directory |
| 577 | dir += "/" + std::string(GetInstructionSetString(isa)); |
| 578 | if (isa_dir != nullptr) { |
| 579 | *isa_dir = dir; |
| 580 | } |
| 581 | |
| 582 | // Get the base part of the file without the extension. |
| 583 | std::string file = location.substr(pos+1); |
| 584 | pos = file.rfind('.'); |
| 585 | if (pos == std::string::npos) { |
| 586 | *error_msg = "Dex location " + location + " has no extension."; |
| 587 | return false; |
| 588 | } |
| 589 | std::string base = file.substr(0, pos); |
| 590 | |
| 591 | *odex_filename = dir + "/" + base + ".odex"; |
| 592 | return true; |
| 593 | } |
| 594 | |
| 595 | // Prepare a subcomponent of the odex directory. |
| 596 | // (i.e. create and set the expected permissions on the path `dir`). |
| 597 | static bool PrepareDirectory(const std::string& dir, std::string* error_msg) { |
| 598 | struct stat dir_stat; |
| 599 | if (TEMP_FAILURE_RETRY(stat(dir.c_str(), &dir_stat)) == 0) { |
| 600 | // The directory exists. Check if it is indeed a directory. |
| 601 | if (!S_ISDIR(dir_stat.st_mode)) { |
| 602 | *error_msg = dir + " is not a dir"; |
| 603 | return false; |
| 604 | } else { |
| 605 | // The dir is already on disk. |
| 606 | return true; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | // Failed to stat. We need to create the directory. |
| 611 | if (errno != ENOENT) { |
| 612 | *error_msg = "Could not stat isa dir " + dir + ":" + strerror(errno); |
| 613 | return false; |
| 614 | } |
| 615 | |
| 616 | mode_t mode = S_IRWXU | S_IXGRP | S_IXOTH; |
| 617 | if (mkdir(dir.c_str(), mode) != 0) { |
| 618 | *error_msg = "Could not create dir " + dir + ":" + strerror(errno); |
| 619 | return false; |
| 620 | } |
| 621 | if (chmod(dir.c_str(), mode) != 0) { |
| 622 | *error_msg = "Could not create the oat dir " + dir + ":" + strerror(errno); |
| 623 | return false; |
| 624 | } |
| 625 | return true; |
| 626 | } |
| 627 | |
| 628 | // Prepares the odex directory for the given dex location. |
| 629 | static bool PrepareOdexDirectories(const std::string& dex_location, |
| 630 | const std::string& expected_odex_location, |
| 631 | InstructionSet isa, |
| 632 | std::string* error_msg) { |
| 633 | std::string actual_odex_location; |
| 634 | std::string oat_dir; |
| 635 | std::string isa_dir; |
| 636 | if (!DexLocationToOdexNames( |
| 637 | dex_location, isa, &actual_odex_location, &oat_dir, &isa_dir, error_msg)) { |
| 638 | return false; |
| 639 | } |
| 640 | DCHECK_EQ(expected_odex_location, actual_odex_location); |
| 641 | |
| 642 | if (!PrepareDirectory(oat_dir, error_msg)) { |
| 643 | return false; |
| 644 | } |
| 645 | if (!PrepareDirectory(isa_dir, error_msg)) { |
| 646 | return false; |
| 647 | } |
| 648 | return true; |
| 649 | } |
| 650 | |
Calin Juravle | d4215bb | 2017-09-20 11:54:21 -0700 | [diff] [blame] | 651 | class Dex2oatFileWrapper { |
| 652 | public: |
| 653 | explicit Dex2oatFileWrapper(File* file) |
| 654 | : file_(file), |
| 655 | unlink_file_at_destruction_(true) { |
| 656 | } |
| 657 | |
| 658 | ~Dex2oatFileWrapper() { |
| 659 | if (unlink_file_at_destruction_ && (file_ != nullptr)) { |
| 660 | file_->Erase(/*unlink*/ true); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | File* GetFile() { return file_.get(); } |
| 665 | |
| 666 | void DisableUnlinkAtDestruction() { |
| 667 | unlink_file_at_destruction_ = false; |
| 668 | }; |
| 669 | |
| 670 | private: |
| 671 | std::unique_ptr<File> file_; |
| 672 | bool unlink_file_at_destruction_; |
| 673 | }; |
| 674 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 675 | OatFileAssistant::ResultOfAttemptToUpdate OatFileAssistant::GenerateOatFileNoChecks( |
Calin Juravle | 27e0d1f | 2017-07-26 00:16:07 -0700 | [diff] [blame] | 676 | OatFileAssistant::OatFileInfo& info, |
| 677 | CompilerFilter::Filter filter, |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 678 | const ClassLoaderContext* class_loader_context, |
Calin Juravle | 27e0d1f | 2017-07-26 00:16:07 -0700 | [diff] [blame] | 679 | std::string* error_msg) { |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 680 | CHECK(error_msg != nullptr); |
| 681 | |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 682 | Runtime* runtime = Runtime::Current(); |
| 683 | if (!runtime->IsDex2OatEnabled()) { |
| 684 | *error_msg = "Generation of oat file for dex location " + dex_location_ |
| 685 | + " not attempted because dex2oat is disabled."; |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 686 | return kUpdateNotAttempted; |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 689 | if (info.Filename() == nullptr) { |
Richard Uhler | 740eec9 | 2015-10-15 15:12:23 -0700 | [diff] [blame] | 690 | *error_msg = "Generation of oat file for dex location " + dex_location_ |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 691 | + " not attempted because the oat file name could not be determined."; |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 692 | return kUpdateNotAttempted; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 693 | } |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 694 | const std::string& oat_file_name = *info.Filename(); |
Calin Juravle | 367b9d8 | 2017-05-15 18:18:39 -0700 | [diff] [blame] | 695 | const std::string& vdex_file_name = GetVdexFilename(oat_file_name); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 696 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 697 | // dex2oat ignores missing dex files and doesn't report an error. |
| 698 | // Check explicitly here so we can detect the error properly. |
| 699 | // TODO: Why does dex2oat behave that way? |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 700 | struct stat dex_path_stat; |
| 701 | if (TEMP_FAILURE_RETRY(stat(dex_location_.c_str(), &dex_path_stat)) != 0) { |
| 702 | *error_msg = "Could not access dex location " + dex_location_ + ":" + strerror(errno); |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 703 | return kUpdateNotAttempted; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 704 | } |
| 705 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 706 | // If this is the odex location, we need to create the odex file layout (../oat/isa/..) |
| 707 | if (!info.IsOatLocation()) { |
| 708 | if (!PrepareOdexDirectories(dex_location_, oat_file_name, isa_, error_msg)) { |
| 709 | return kUpdateNotAttempted; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | // Set the permissions for the oat and the vdex files. |
| 714 | // The user always gets read and write while the group and others propagate |
| 715 | // the reading access of the original dex file. |
| 716 | mode_t file_mode = S_IRUSR | S_IWUSR | |
| 717 | (dex_path_stat.st_mode & S_IRGRP) | |
| 718 | (dex_path_stat.st_mode & S_IROTH); |
| 719 | |
Calin Juravle | d4215bb | 2017-09-20 11:54:21 -0700 | [diff] [blame] | 720 | Dex2oatFileWrapper vdex_file_wrapper(OS::CreateEmptyFile(vdex_file_name.c_str())); |
| 721 | File* vdex_file = vdex_file_wrapper.GetFile(); |
| 722 | if (vdex_file == nullptr) { |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 723 | *error_msg = "Generation of oat file " + oat_file_name |
| 724 | + " not attempted because the vdex file " + vdex_file_name |
| 725 | + " could not be opened."; |
| 726 | return kUpdateNotAttempted; |
| 727 | } |
| 728 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 729 | if (fchmod(vdex_file->Fd(), file_mode) != 0) { |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 730 | *error_msg = "Generation of oat file " + oat_file_name |
| 731 | + " not attempted because the vdex file " + vdex_file_name |
| 732 | + " could not be made world readable."; |
| 733 | return kUpdateNotAttempted; |
| 734 | } |
| 735 | |
Calin Juravle | d4215bb | 2017-09-20 11:54:21 -0700 | [diff] [blame] | 736 | Dex2oatFileWrapper oat_file_wrapper(OS::CreateEmptyFile(oat_file_name.c_str())); |
| 737 | File* oat_file = oat_file_wrapper.GetFile(); |
| 738 | if (oat_file == nullptr) { |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 739 | *error_msg = "Generation of oat file " + oat_file_name |
| 740 | + " not attempted because the oat file could not be created."; |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 741 | return kUpdateNotAttempted; |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 744 | if (fchmod(oat_file->Fd(), file_mode) != 0) { |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 745 | *error_msg = "Generation of oat file " + oat_file_name |
| 746 | + " not attempted because the oat file could not be made world readable."; |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 747 | return kUpdateNotAttempted; |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | std::vector<std::string> args; |
| 751 | args.push_back("--dex-file=" + dex_location_); |
Nicolas Geoffray | a6a448a | 2016-11-10 10:49:40 +0000 | [diff] [blame] | 752 | args.push_back("--output-vdex-fd=" + std::to_string(vdex_file->Fd())); |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 753 | args.push_back("--oat-fd=" + std::to_string(oat_file->Fd())); |
| 754 | args.push_back("--oat-location=" + oat_file_name); |
Calin Juravle | 07c6d72 | 2017-06-07 17:06:12 +0000 | [diff] [blame] | 755 | args.push_back("--compiler-filter=" + CompilerFilter::NameOfFilter(filter)); |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 756 | const std::string dex2oat_context = class_loader_context == nullptr |
| 757 | ? OatFile::kSpecialSharedLibrary |
| 758 | : class_loader_context->EncodeContextForDex2oat(/*base_dir*/ ""); |
| 759 | args.push_back("--class-loader-context=" + dex2oat_context); |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 760 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 761 | if (!Dex2Oat(args, error_msg)) { |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 762 | return kUpdateFailed; |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 763 | } |
| 764 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 765 | if (vdex_file->FlushCloseOrErase() != 0) { |
| 766 | *error_msg = "Unable to close vdex file " + vdex_file_name; |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 767 | return kUpdateFailed; |
| 768 | } |
| 769 | |
Richard Uhler | 8327cf7 | 2015-10-13 16:34:59 -0700 | [diff] [blame] | 770 | if (oat_file->FlushCloseOrErase() != 0) { |
| 771 | *error_msg = "Unable to close oat file " + oat_file_name; |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 772 | return kUpdateFailed; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 773 | } |
| 774 | |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 775 | // Mark that the odex file has changed and we should try to reload. |
| 776 | info.Reset(); |
Calin Juravle | d4215bb | 2017-09-20 11:54:21 -0700 | [diff] [blame] | 777 | // We have compiled successfully. Disable the auto-unlink. |
| 778 | vdex_file_wrapper.DisableUnlinkAtDestruction(); |
| 779 | oat_file_wrapper.DisableUnlinkAtDestruction(); |
| 780 | |
Richard Uhler | 1e86061 | 2016-03-30 12:17:55 -0700 | [diff] [blame] | 781 | return kUpdateSucceeded; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | bool OatFileAssistant::Dex2Oat(const std::vector<std::string>& args, |
| 785 | std::string* error_msg) { |
| 786 | Runtime* runtime = Runtime::Current(); |
| 787 | std::string image_location = ImageLocation(); |
| 788 | if (image_location.empty()) { |
| 789 | *error_msg = "No image location found for Dex2Oat."; |
| 790 | return false; |
| 791 | } |
| 792 | |
| 793 | std::vector<std::string> argv; |
| 794 | argv.push_back(runtime->GetCompilerExecutable()); |
Nicolas Geoffray | 433b79a | 2017-01-30 20:54:45 +0000 | [diff] [blame] | 795 | if (runtime->IsJavaDebuggable()) { |
Sebastien Hertz | 0de1133 | 2015-05-13 12:14:05 +0200 | [diff] [blame] | 796 | argv.push_back("--debuggable"); |
| 797 | } |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 798 | runtime->AddCurrentRuntimeFeaturesAsDex2OatArguments(&argv); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 799 | |
| 800 | if (!runtime->IsVerificationEnabled()) { |
| 801 | argv.push_back("--compiler-filter=verify-none"); |
| 802 | } |
| 803 | |
| 804 | if (runtime->MustRelocateIfPossible()) { |
| 805 | argv.push_back("--runtime-arg"); |
| 806 | argv.push_back("-Xrelocate"); |
| 807 | } else { |
| 808 | argv.push_back("--runtime-arg"); |
| 809 | argv.push_back("-Xnorelocate"); |
| 810 | } |
| 811 | |
| 812 | if (!kIsTargetBuild) { |
| 813 | argv.push_back("--host"); |
| 814 | } |
| 815 | |
| 816 | argv.push_back("--boot-image=" + image_location); |
| 817 | |
| 818 | std::vector<std::string> compiler_options = runtime->GetCompilerOptions(); |
| 819 | argv.insert(argv.end(), compiler_options.begin(), compiler_options.end()); |
| 820 | |
| 821 | argv.insert(argv.end(), args.begin(), args.end()); |
| 822 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 823 | std::string command_line(android::base::Join(argv, ' ')); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 824 | return Exec(argv, error_msg); |
| 825 | } |
| 826 | |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 827 | bool OatFileAssistant::DexLocationToOdexFilename(const std::string& location, |
| 828 | InstructionSet isa, |
| 829 | std::string* odex_filename, |
| 830 | std::string* error_msg) { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 831 | return DexLocationToOdexNames(location, isa, odex_filename, nullptr, nullptr, error_msg); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 832 | } |
| 833 | |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 834 | bool OatFileAssistant::DexLocationToOatFilename(const std::string& location, |
| 835 | InstructionSet isa, |
| 836 | std::string* oat_filename, |
| 837 | std::string* error_msg) { |
| 838 | CHECK(oat_filename != nullptr); |
| 839 | CHECK(error_msg != nullptr); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 840 | |
Richard Uhler | 55b58b6 | 2016-08-12 09:05:13 -0700 | [diff] [blame] | 841 | std::string cache_dir = GetDalvikCache(GetInstructionSetString(isa)); |
| 842 | if (cache_dir.empty()) { |
| 843 | *error_msg = "Dalvik cache directory does not exist"; |
| 844 | return false; |
| 845 | } |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 846 | |
| 847 | // TODO: The oat file assistant should be the definitive place for |
| 848 | // determining the oat file name from the dex location, not |
| 849 | // GetDalvikCacheFilename. |
Richard Uhler | b81881d | 2016-04-19 13:08:04 -0700 | [diff] [blame] | 850 | 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] | 851 | } |
| 852 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 853 | std::string OatFileAssistant::ImageLocation() { |
| 854 | Runtime* runtime = Runtime::Current(); |
Andreas Gampe | 8994a04 | 2015-12-30 19:03:17 +0000 | [diff] [blame] | 855 | const std::vector<gc::space::ImageSpace*>& image_spaces = |
| 856 | runtime->GetHeap()->GetBootImageSpaces(); |
| 857 | if (image_spaces.empty()) { |
| 858 | return ""; |
| 859 | } |
| 860 | return image_spaces[0]->GetImageLocation(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 861 | } |
| 862 | |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 863 | const std::vector<uint32_t>* OatFileAssistant::GetRequiredDexChecksums() { |
| 864 | if (!required_dex_checksums_attempted_) { |
| 865 | required_dex_checksums_attempted_ = true; |
| 866 | required_dex_checksums_found_ = false; |
| 867 | cached_required_dex_checksums_.clear(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 868 | std::string error_msg; |
Mathieu Chartier | 79c87da | 2017-10-10 11:54:29 -0700 | [diff] [blame] | 869 | if (DexFileLoader::GetMultiDexChecksums(dex_location_.c_str(), |
| 870 | &cached_required_dex_checksums_, |
| 871 | &error_msg)) { |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 872 | required_dex_checksums_found_ = true; |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 873 | has_original_dex_files_ = true; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 874 | } else { |
| 875 | // This can happen if the original dex file has been stripped from the |
| 876 | // apk. |
| 877 | VLOG(oat) << "OatFileAssistant: " << error_msg; |
Richard Uhler | 9b994ea | 2015-06-24 08:44:19 -0700 | [diff] [blame] | 878 | has_original_dex_files_ = false; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 879 | |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 880 | // Get the checksums from the odex if we can. |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 881 | const OatFile* odex_file = odex_.GetFile(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 882 | if (odex_file != nullptr) { |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 883 | required_dex_checksums_found_ = true; |
| 884 | for (size_t i = 0; i < odex_file->GetOatHeader().GetDexFileCount(); i++) { |
Mathieu Chartier | 79c87da | 2017-10-10 11:54:29 -0700 | [diff] [blame] | 885 | std::string dex = DexFileLoader::GetMultiDexLocation(i, dex_location_.c_str()); |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 886 | const OatFile::OatDexFile* odex_dex_file = odex_file->GetOatDexFile(dex.c_str(), nullptr); |
| 887 | if (odex_dex_file == nullptr) { |
| 888 | required_dex_checksums_found_ = false; |
| 889 | break; |
| 890 | } |
| 891 | cached_required_dex_checksums_.push_back(odex_dex_file->GetDexFileLocationChecksum()); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | } |
| 895 | } |
Richard Uhler | 69bcf2c | 2017-01-24 10:25:21 +0000 | [diff] [blame] | 896 | return required_dex_checksums_found_ ? &cached_required_dex_checksums_ : nullptr; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 897 | } |
| 898 | |
Richard Uhler | 95e0967 | 2017-02-22 11:37:41 +0000 | [diff] [blame] | 899 | std::unique_ptr<OatFileAssistant::ImageInfo> |
| 900 | OatFileAssistant::ImageInfo::GetRuntimeImageInfo(InstructionSet isa, std::string* error_msg) { |
| 901 | CHECK(error_msg != nullptr); |
| 902 | |
Richard Uhler | 95e0967 | 2017-02-22 11:37:41 +0000 | [diff] [blame] | 903 | Runtime* runtime = Runtime::Current(); |
Richard Uhler | 8f10486 | 2017-02-22 12:34:01 +0000 | [diff] [blame] | 904 | std::unique_ptr<ImageInfo> info(new ImageInfo()); |
| 905 | info->location = runtime->GetImageLocation(); |
| 906 | |
| 907 | std::unique_ptr<ImageHeader> image_header( |
| 908 | gc::space::ImageSpace::ReadImageHeader(info->location.c_str(), isa, error_msg)); |
| 909 | if (image_header == nullptr) { |
Richard Uhler | 95e0967 | 2017-02-22 11:37:41 +0000 | [diff] [blame] | 910 | return nullptr; |
| 911 | } |
| 912 | |
Richard Uhler | 8f10486 | 2017-02-22 12:34:01 +0000 | [diff] [blame] | 913 | info->oat_checksum = image_header->GetOatChecksum(); |
| 914 | info->oat_data_begin = reinterpret_cast<uintptr_t>(image_header->GetOatDataBegin()); |
| 915 | info->patch_delta = image_header->GetPatchDelta(); |
Richard Uhler | 95e0967 | 2017-02-22 11:37:41 +0000 | [diff] [blame] | 916 | return info; |
| 917 | } |
| 918 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 919 | const OatFileAssistant::ImageInfo* OatFileAssistant::GetImageInfo() { |
| 920 | if (!image_info_load_attempted_) { |
| 921 | image_info_load_attempted_ = true; |
Richard Uhler | 95e0967 | 2017-02-22 11:37:41 +0000 | [diff] [blame] | 922 | std::string error_msg; |
| 923 | cached_image_info_ = ImageInfo::GetRuntimeImageInfo(isa_, &error_msg); |
| 924 | if (cached_image_info_ == nullptr) { |
| 925 | LOG(WARNING) << "Unable to get runtime image info: " << error_msg; |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 926 | } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 927 | } |
Richard Uhler | 95e0967 | 2017-02-22 11:37:41 +0000 | [diff] [blame] | 928 | return cached_image_info_.get(); |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 929 | } |
| 930 | |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 931 | OatFileAssistant::OatFileInfo& OatFileAssistant::GetBestInfo() { |
Calin Juravle | 357c66d | 2017-05-04 01:57:17 +0000 | [diff] [blame] | 932 | // TODO(calin): Document the side effects of class loading when |
| 933 | // running dalvikvm command line. |
| 934 | if (dex_parent_writable_) { |
| 935 | // If the parent of the dex file is writable it means that we can |
| 936 | // create the odex file. In this case we unconditionally pick the odex |
| 937 | // as the best oat file. This corresponds to the regular use case when |
| 938 | // apps gets installed or when they load private, secondary dex file. |
| 939 | // For apps on the system partition the odex location will not be |
| 940 | // writable and thus the oat location might be more up to date. |
| 941 | return odex_; |
| 942 | } |
| 943 | |
| 944 | // We cannot write to the odex location. This must be a system app. |
| 945 | |
| 946 | // If the oat location is usable take it. |
| 947 | if (oat_.IsUseable()) { |
| 948 | return oat_; |
| 949 | } |
| 950 | |
| 951 | // The oat file is not usable but the odex file might be up to date. |
| 952 | // This is an indication that we are dealing with an up to date prebuilt |
| 953 | // (that doesn't need relocation). |
| 954 | if (odex_.Status() == kOatUpToDate) { |
| 955 | return odex_; |
| 956 | } |
| 957 | |
| 958 | // The oat file is not usable and the odex file is not up to date. |
| 959 | // However we have access to the original dex file which means we can make |
| 960 | // the oat location up to date. |
| 961 | if (HasOriginalDexFiles()) { |
| 962 | return oat_; |
| 963 | } |
| 964 | |
| 965 | // We got into the worst situation here: |
| 966 | // - the oat location is not usable |
| 967 | // - the prebuild odex location is not up to date |
| 968 | // - and we don't have the original dex file anymore (stripped). |
| 969 | // Pick the odex if it exists, or the oat if not. |
| 970 | return (odex_.Status() == kOatCannotOpen) ? oat_ : odex_; |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 971 | } |
| 972 | |
Andreas Gampe | a463b6a | 2016-08-12 21:53:32 -0700 | [diff] [blame] | 973 | std::unique_ptr<gc::space::ImageSpace> OatFileAssistant::OpenImageSpace(const OatFile* oat_file) { |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 974 | DCHECK(oat_file != nullptr); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 975 | std::string art_file = ReplaceFileExtension(oat_file->GetLocation(), "art"); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 976 | if (art_file.empty()) { |
| 977 | return nullptr; |
| 978 | } |
| 979 | std::string error_msg; |
| 980 | ScopedObjectAccess soa(Thread::Current()); |
Andreas Gampe | a463b6a | 2016-08-12 21:53:32 -0700 | [diff] [blame] | 981 | std::unique_ptr<gc::space::ImageSpace> ret = |
| 982 | gc::space::ImageSpace::CreateFromAppImage(art_file.c_str(), oat_file, &error_msg); |
Mathieu Chartier | e778fc7 | 2016-01-25 20:11:28 -0800 | [diff] [blame] | 983 | 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] | 984 | LOG(INFO) << "Failed to open app image " << art_file.c_str() << " " << error_msg; |
| 985 | } |
| 986 | return ret; |
| 987 | } |
| 988 | |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 989 | OatFileAssistant::OatFileInfo::OatFileInfo(OatFileAssistant* oat_file_assistant, |
| 990 | bool is_oat_location) |
| 991 | : oat_file_assistant_(oat_file_assistant), is_oat_location_(is_oat_location) |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 992 | {} |
| 993 | |
Richard Uhler | 88bc673 | 2016-11-14 14:38:03 +0000 | [diff] [blame] | 994 | bool OatFileAssistant::OatFileInfo::IsOatLocation() { |
| 995 | return is_oat_location_; |
| 996 | } |
| 997 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 998 | const std::string* OatFileAssistant::OatFileInfo::Filename() { |
| 999 | return filename_provided_ ? &filename_ : nullptr; |
| 1000 | } |
| 1001 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 1002 | bool OatFileAssistant::OatFileInfo::IsUseable() { |
| 1003 | switch (Status()) { |
| 1004 | case kOatCannotOpen: |
| 1005 | case kOatDexOutOfDate: |
| 1006 | case kOatBootImageOutOfDate: return false; |
| 1007 | |
| 1008 | case kOatRelocationOutOfDate: |
| 1009 | case kOatUpToDate: return true; |
| 1010 | } |
| 1011 | UNREACHABLE(); |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | OatFileAssistant::OatStatus OatFileAssistant::OatFileInfo::Status() { |
| 1015 | if (!status_attempted_) { |
| 1016 | status_attempted_ = true; |
| 1017 | const OatFile* file = GetFile(); |
| 1018 | if (file == nullptr) { |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 1019 | // Check to see if there is a vdex file we can make use of. |
| 1020 | std::string error_msg; |
Calin Juravle | 367b9d8 | 2017-05-15 18:18:39 -0700 | [diff] [blame] | 1021 | std::string vdex_filename = GetVdexFilename(filename_); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 1022 | std::unique_ptr<VdexFile> vdex; |
| 1023 | if (vdex_fd_ == -1) { |
| 1024 | vdex = VdexFile::Open(vdex_filename, |
| 1025 | false /*writeable*/, |
| 1026 | false /*low_4gb*/, |
| 1027 | false /*unquicken*/, |
| 1028 | &error_msg); |
| 1029 | } else { |
| 1030 | struct stat s; |
| 1031 | int rc = TEMP_FAILURE_RETRY(fstat(vdex_fd_, &s)); |
| 1032 | if (rc == -1) { |
| 1033 | PLOG(WARNING) << "Failed getting length of vdex file"; |
| 1034 | } else { |
| 1035 | vdex = VdexFile::Open(vdex_fd_, |
| 1036 | s.st_size, |
| 1037 | vdex_filename, |
| 1038 | false /*writable*/, |
| 1039 | false /*low_4gb*/, |
| 1040 | false /* unquicken */, |
| 1041 | &error_msg); |
| 1042 | } |
| 1043 | } |
Richard Uhler | 2f27abd | 2017-01-31 14:02:34 +0000 | [diff] [blame] | 1044 | if (vdex == nullptr) { |
| 1045 | status_ = kOatCannotOpen; |
| 1046 | VLOG(oat) << "unable to open vdex file " << vdex_filename << ": " << error_msg; |
| 1047 | } else { |
| 1048 | if (oat_file_assistant_->DexChecksumUpToDate(*vdex, &error_msg)) { |
| 1049 | // The vdex file does not contain enough information to determine |
| 1050 | // whether it is up to date with respect to the boot image, so we |
| 1051 | // assume it is out of date. |
| 1052 | VLOG(oat) << error_msg; |
| 1053 | status_ = kOatBootImageOutOfDate; |
| 1054 | } else { |
| 1055 | status_ = kOatDexOutOfDate; |
| 1056 | } |
| 1057 | } |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 1058 | } else { |
| 1059 | status_ = oat_file_assistant_->GivenOatFileStatus(*file); |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 1060 | VLOG(oat) << file->GetLocation() << " is " << status_ |
| 1061 | << " with filter " << file->GetCompilerFilter(); |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 1062 | } |
| 1063 | } |
| 1064 | return status_; |
| 1065 | } |
| 1066 | |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 1067 | OatFileAssistant::DexOptNeeded OatFileAssistant::OatFileInfo::GetDexOptNeeded( |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1068 | CompilerFilter::Filter target, |
| 1069 | bool profile_changed, |
| 1070 | bool downgrade, |
| 1071 | ClassLoaderContext* context) { |
| 1072 | |
Nicolas Geoffray | 49cda06 | 2017-04-21 13:08:25 +0100 | [diff] [blame] | 1073 | bool compilation_desired = CompilerFilter::IsAotCompilationEnabled(target); |
Shubham Ajmera | e4e812a | 2017-05-25 20:09:58 -0700 | [diff] [blame] | 1074 | bool filter_okay = CompilerFilterIsOkay(target, profile_changed, downgrade); |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1075 | bool class_loader_context_okay = ClassLoaderContextIsOkay(context); |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 1076 | |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1077 | // Only check the filter and relocation if the class loader context is ok. |
| 1078 | // If it is not, we will return kDex2OatFromScratch as the compilation needs to be redone. |
| 1079 | if (class_loader_context_okay) { |
| 1080 | if (filter_okay && Status() == kOatUpToDate) { |
| 1081 | // The oat file is in good shape as is. |
| 1082 | return kNoDexOptNeeded; |
| 1083 | } |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 1084 | |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1085 | if (filter_okay && !compilation_desired && Status() == kOatRelocationOutOfDate) { |
| 1086 | // If no compilation is desired, then it doesn't matter if the oat |
| 1087 | // file needs relocation. It's in good shape as is. |
| 1088 | return kNoDexOptNeeded; |
| 1089 | } |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 1090 | |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1091 | if (filter_okay && Status() == kOatRelocationOutOfDate) { |
| 1092 | return kDex2OatForRelocation; |
| 1093 | } |
Richard Uhler | 7225a8d | 2016-11-22 10:12:03 +0000 | [diff] [blame] | 1094 | |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1095 | if (IsUseable()) { |
| 1096 | return kDex2OatForFilter; |
| 1097 | } |
Nicolas Geoffray | 08e9eed | 2017-04-25 17:36:51 +0100 | [diff] [blame] | 1098 | |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1099 | if (Status() == kOatBootImageOutOfDate) { |
| 1100 | return kDex2OatForBootImage; |
| 1101 | } |
Nicolas Geoffray | 08e9eed | 2017-04-25 17:36:51 +0100 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | if (oat_file_assistant_->HasOriginalDexFiles()) { |
| 1105 | return kDex2OatFromScratch; |
| 1106 | } else { |
| 1107 | // Otherwise there is nothing we can do, even if we want to. |
| 1108 | return kNoDexOptNeeded; |
| 1109 | } |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 1112 | const OatFile* OatFileAssistant::OatFileInfo::GetFile() { |
| 1113 | CHECK(!file_released_) << "GetFile called after oat file released."; |
| 1114 | if (!load_attempted_) { |
| 1115 | load_attempted_ = true; |
| 1116 | if (filename_provided_) { |
| 1117 | std::string error_msg; |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 1118 | if (oat_fd_ != -1 && vdex_fd_ != -1) { |
| 1119 | file_.reset(OatFile::Open(vdex_fd_, |
| 1120 | oat_fd_, |
| 1121 | filename_.c_str(), |
| 1122 | nullptr, |
| 1123 | nullptr, |
| 1124 | oat_file_assistant_->load_executable_, |
| 1125 | false /* low_4gb */, |
| 1126 | oat_file_assistant_->dex_location_.c_str(), |
| 1127 | &error_msg)); |
| 1128 | } else { |
| 1129 | file_.reset(OatFile::Open(filename_.c_str(), |
| 1130 | filename_.c_str(), |
| 1131 | nullptr, |
| 1132 | nullptr, |
| 1133 | oat_file_assistant_->load_executable_, |
| 1134 | false /* low_4gb */, |
| 1135 | oat_file_assistant_->dex_location_.c_str(), |
| 1136 | &error_msg)); |
| 1137 | } |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 1138 | if (file_.get() == nullptr) { |
| 1139 | VLOG(oat) << "OatFileAssistant test for existing oat file " |
| 1140 | << filename_ << ": " << error_msg; |
| 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | return file_.get(); |
| 1145 | } |
| 1146 | |
| 1147 | bool OatFileAssistant::OatFileInfo::CompilerFilterIsOkay( |
Shubham Ajmera | e4e812a | 2017-05-25 20:09:58 -0700 | [diff] [blame] | 1148 | CompilerFilter::Filter target, bool profile_changed, bool downgrade) { |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 1149 | const OatFile* file = GetFile(); |
| 1150 | if (file == nullptr) { |
| 1151 | return false; |
| 1152 | } |
| 1153 | |
| 1154 | CompilerFilter::Filter current = file->GetCompilerFilter(); |
| 1155 | if (profile_changed && CompilerFilter::DependsOnProfile(current)) { |
| 1156 | VLOG(oat) << "Compiler filter not okay because Profile changed"; |
| 1157 | return false; |
| 1158 | } |
Shubham Ajmera | e4e812a | 2017-05-25 20:09:58 -0700 | [diff] [blame] | 1159 | return downgrade ? !CompilerFilter::IsBetter(current, target) : |
| 1160 | CompilerFilter::IsAsGoodAs(current, target); |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1163 | bool OatFileAssistant::OatFileInfo::ClassLoaderContextIsOkay(ClassLoaderContext* context) { |
| 1164 | if (context == nullptr) { |
| 1165 | VLOG(oat) << "ClassLoaderContext check ignored: null context"; |
| 1166 | return true; |
| 1167 | } |
| 1168 | |
| 1169 | const OatFile* file = GetFile(); |
| 1170 | if (file == nullptr) { |
Calin Juravle | 20c4644 | 2017-09-12 00:54:26 -0700 | [diff] [blame^] | 1171 | // No oat file means we have nothing to verify. |
| 1172 | return true; |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
Calin Juravle | 20c4644 | 2017-09-12 00:54:26 -0700 | [diff] [blame^] | 1175 | size_t dir_index = oat_file_assistant_->dex_location_.rfind('/'); |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1176 | std::string classpath_dir = (dir_index != std::string::npos) |
Calin Juravle | 20c4644 | 2017-09-12 00:54:26 -0700 | [diff] [blame^] | 1177 | ? oat_file_assistant_->dex_location_.substr(0, dir_index) |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 1178 | : ""; |
| 1179 | |
| 1180 | if (!context->OpenDexFiles(oat_file_assistant_->isa_, classpath_dir)) { |
| 1181 | VLOG(oat) << "ClassLoaderContext check failed: dex files from the context could not be opened"; |
| 1182 | return false; |
| 1183 | } |
| 1184 | |
| 1185 | bool result = context->VerifyClassLoaderContextMatch(file->GetClassLoaderContext()); |
| 1186 | if (!result) { |
| 1187 | VLOG(oat) << "ClassLoaderContext check failed. Context was " |
| 1188 | << file->GetClassLoaderContext() |
| 1189 | << ". The expected context is " << context->EncodeContextForOatFile(classpath_dir); |
| 1190 | } |
| 1191 | return result; |
| 1192 | } |
| 1193 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 1194 | bool OatFileAssistant::OatFileInfo::IsExecutable() { |
| 1195 | const OatFile* file = GetFile(); |
| 1196 | return (file != nullptr && file->IsExecutable()); |
| 1197 | } |
| 1198 | |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 1199 | void OatFileAssistant::OatFileInfo::Reset() { |
| 1200 | load_attempted_ = false; |
| 1201 | file_.reset(); |
| 1202 | status_attempted_ = false; |
| 1203 | } |
| 1204 | |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 1205 | void OatFileAssistant::OatFileInfo::Reset(const std::string& filename, int vdex_fd, |
| 1206 | int oat_fd) { |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 1207 | filename_provided_ = true; |
| 1208 | filename_ = filename; |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 1209 | vdex_fd_ = vdex_fd; |
| 1210 | oat_fd_ = oat_fd; |
Richard Uhler | 743bf36 | 2016-04-19 15:39:37 -0700 | [diff] [blame] | 1211 | Reset(); |
| 1212 | } |
| 1213 | |
| 1214 | std::unique_ptr<OatFile> OatFileAssistant::OatFileInfo::ReleaseFile() { |
| 1215 | file_released_ = true; |
| 1216 | return std::move(file_); |
| 1217 | } |
| 1218 | |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 1219 | std::unique_ptr<OatFile> OatFileAssistant::OatFileInfo::ReleaseFileForUse() { |
Richard Uhler | 3e580bc | 2016-11-08 16:23:07 +0000 | [diff] [blame] | 1220 | if (Status() == kOatUpToDate) { |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 1221 | return ReleaseFile(); |
| 1222 | } |
| 1223 | |
| 1224 | VLOG(oat) << "Oat File Assistant: No relocated oat file found," |
| 1225 | << " attempting to fall back to interpreting oat file instead."; |
| 1226 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 1227 | if (Status() == kOatRelocationOutOfDate && !IsExecutable()) { |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 1228 | return ReleaseFile(); |
| 1229 | } |
| 1230 | |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 1231 | if (Status() == kOatRelocationOutOfDate) { |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 1232 | // We are loading an oat file for runtime use that needs relocation. |
| 1233 | // Reload the file non-executable to ensure that we interpret out of the |
| 1234 | // dex code in the oat file rather than trying to execute the unrelocated |
| 1235 | // compiled code. |
| 1236 | oat_file_assistant_->load_executable_ = false; |
| 1237 | Reset(); |
Richard Uhler | 03bc659 | 2016-11-22 09:42:04 +0000 | [diff] [blame] | 1238 | if (IsUseable()) { |
Richard Uhler | 70a8426 | 2016-11-08 16:51:51 +0000 | [diff] [blame] | 1239 | CHECK(!IsExecutable()); |
| 1240 | return ReleaseFile(); |
| 1241 | } |
| 1242 | } |
| 1243 | return std::unique_ptr<OatFile>(); |
| 1244 | } |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 1245 | } // namespace art |