blob: cbc0ec6d28ae1cd5454041d6e2fe48c2e551a8f9 [file] [log] [blame]
Richard Uhler66d874d2015-01-15 09:37:19 -08001/*
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
19#include <fcntl.h>
20#ifdef __linux__
21#include <sys/sendfile.h>
22#else
23#include <sys/socket.h>
24#endif
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <unistd.h>
28
29#include <set>
30
31#include "base/logging.h"
32#include "base/stringprintf.h"
33#include "class_linker.h"
34#include "gc/heap.h"
35#include "gc/space/image_space.h"
36#include "image.h"
37#include "oat.h"
38#include "os.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080039#include "runtime.h"
Mathieu Chartierfbc31082016-01-24 11:59:56 -080040#include "scoped_thread_state_change.h"
Richard Uhler66d874d2015-01-15 09:37:19 -080041#include "ScopedFd.h"
42#include "utils.h"
43
44namespace art {
45
46OatFileAssistant::OatFileAssistant(const char* dex_location,
Nicolas Geoffray845e5062016-03-23 06:42:05 +000047 const int target_compilation_type_mask,
Richard Uhler66d874d2015-01-15 09:37:19 -080048 const InstructionSet isa,
49 bool load_executable)
Nicolas Geoffray845e5062016-03-23 06:42:05 +000050 : OatFileAssistant(dex_location, nullptr, target_compilation_type_mask, isa, load_executable)
Calin Juravleb077e152016-02-18 18:47:37 +000051{ }
Richard Uhler66d874d2015-01-15 09:37:19 -080052
53OatFileAssistant::OatFileAssistant(const char* dex_location,
54 const char* oat_location,
Nicolas Geoffray845e5062016-03-23 06:42:05 +000055 const int target_compilation_type_mask,
Richard Uhler66d874d2015-01-15 09:37:19 -080056 const InstructionSet isa,
57 bool load_executable)
Nicolas Geoffray845e5062016-03-23 06:42:05 +000058 : target_compilation_type_mask_(target_compilation_type_mask), isa_(isa),
59 load_executable_(load_executable) {
Richard Uhler740eec92015-10-15 15:12:23 -070060 CHECK(dex_location != nullptr) << "OatFileAssistant: null dex location";
61 dex_location_.assign(dex_location);
62
Richard Uhler66d874d2015-01-15 09:37:19 -080063 if (load_executable_ && isa != kRuntimeISA) {
64 LOG(WARNING) << "OatFileAssistant: Load executable specified, "
65 << "but isa is not kRuntimeISA. Will not attempt to load executable.";
66 load_executable_ = false;
67 }
68
69 // If the user gave a target oat location, save that as the cached oat
70 // location now so we won't try to construct the default location later.
71 if (oat_location != nullptr) {
72 cached_oat_file_name_ = std::string(oat_location);
73 cached_oat_file_name_attempted_ = true;
74 cached_oat_file_name_found_ = true;
75 }
Richard Uhler66d874d2015-01-15 09:37:19 -080076}
77
78OatFileAssistant::~OatFileAssistant() {
79 // Clean up the lock file.
Richard Uhler581f4e92015-05-07 10:19:35 -070080 if (flock_.HasFile()) {
81 TEMP_FAILURE_RETRY(unlink(flock_.GetFile()->GetPath().c_str()));
Richard Uhler66d874d2015-01-15 09:37:19 -080082 }
83}
84
85bool OatFileAssistant::IsInBootClassPath() {
86 // Note: We check the current boot class path, regardless of the ISA
87 // specified by the user. This is okay, because the boot class path should
88 // be the same for all ISAs.
89 // TODO: Can we verify the boot class path is the same for all ISAs?
90 Runtime* runtime = Runtime::Current();
91 ClassLinker* class_linker = runtime->GetClassLinker();
92 const auto& boot_class_path = class_linker->GetBootClassPath();
93 for (size_t i = 0; i < boot_class_path.size(); i++) {
Richard Uhler740eec92015-10-15 15:12:23 -070094 if (boot_class_path[i]->GetLocation() == dex_location_) {
Richard Uhler66d874d2015-01-15 09:37:19 -080095 VLOG(oat) << "Dex location " << dex_location_ << " is in boot class path";
96 return true;
97 }
98 }
99 return false;
100}
101
102bool OatFileAssistant::Lock(std::string* error_msg) {
103 CHECK(error_msg != nullptr);
Richard Uhler581f4e92015-05-07 10:19:35 -0700104 CHECK(!flock_.HasFile()) << "OatFileAssistant::Lock already acquired";
Richard Uhler66d874d2015-01-15 09:37:19 -0800105
106 if (OatFileName() == nullptr) {
107 *error_msg = "Failed to determine lock file";
108 return false;
109 }
110 std::string lock_file_name = *OatFileName() + ".flock";
111
Richard Uhler581f4e92015-05-07 10:19:35 -0700112 if (!flock_.Init(lock_file_name.c_str(), error_msg)) {
Richard Uhler66d874d2015-01-15 09:37:19 -0800113 TEMP_FAILURE_RETRY(unlink(lock_file_name.c_str()));
114 return false;
115 }
116 return true;
117}
118
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000119// Returns the compilation mode of the given oat file.
120static OatFileAssistant::CompilationType GetCompilationType(const OatFile& oat_file) {
121 if (oat_file.IsExtractOnly()) {
122 return OatFileAssistant::kExtractOnly;
123 }
124 if (oat_file.IsProfileGuideCompiled()) {
125 return OatFileAssistant::kProfileGuideCompilation;
126 }
127 // Assume that if the oat files is not extract-only or profile-guide compiled
128 // then it must be fully compiled.
129 // NB: this does not necessary mean that the oat file is actually fully compiled. It
130 // might have been compiled in a different way (e.g. interpret-only) which does
131 // not record a type in the header.
132 return OatFileAssistant::kFullCompilation;
Calin Juravleb077e152016-02-18 18:47:37 +0000133}
Richard Uhler66d874d2015-01-15 09:37:19 -0800134
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000135OatFileAssistant::DexOptNeeded OatFileAssistant::GetDexOptNeeded() {
136 if (OatFileIsUpToDate() || OdexFileIsUpToDate()) {
137 return kNoDexOptNeeded;
Richard Uhler66d874d2015-01-15 09:37:19 -0800138 }
Richard Uhler95abd042015-03-24 09:51:28 -0700139
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000140 if (OdexFileNeedsRelocation()) {
141 return kPatchOatNeeded;
Richard Uhler95abd042015-03-24 09:51:28 -0700142 }
143
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000144 if (OatFileNeedsRelocation()) {
145 return kSelfPatchOatNeeded;
Richard Uhler95abd042015-03-24 09:51:28 -0700146 }
147
Richard Uhler9b994ea2015-06-24 08:44:19 -0700148 return HasOriginalDexFiles() ? kDex2OatNeeded : kNoDexOptNeeded;
Richard Uhler66d874d2015-01-15 09:37:19 -0800149}
150
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000151bool OatFileAssistant::MakeUpToDate(std::string* error_msg) {
152 switch (GetDexOptNeeded()) {
Richard Uhler95abd042015-03-24 09:51:28 -0700153 case kNoDexOptNeeded: return true;
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000154 case kDex2OatNeeded: return GenerateOatFile(error_msg);
Richard Uhler95abd042015-03-24 09:51:28 -0700155 case kPatchOatNeeded: return RelocateOatFile(OdexFileName(), error_msg);
156 case kSelfPatchOatNeeded: return RelocateOatFile(OatFileName(), error_msg);
Richard Uhler66d874d2015-01-15 09:37:19 -0800157 }
158 UNREACHABLE();
159}
160
161std::unique_ptr<OatFile> OatFileAssistant::GetBestOatFile() {
Richard Uhler5f946da2015-07-17 12:28:32 -0700162 // The best oat files are, in descending order of bestness:
163 // 1. Properly relocated files. These may be opened executable.
164 // 2. Not out-of-date files that are already opened non-executable.
165 // 3. Not out-of-date files that we must reopen non-executable.
166
Richard Uhler66d874d2015-01-15 09:37:19 -0800167 if (OatFileIsUpToDate()) {
168 oat_file_released_ = true;
169 return std::move(cached_oat_file_);
170 }
171
172 if (OdexFileIsUpToDate()) {
173 oat_file_released_ = true;
174 return std::move(cached_odex_file_);
175 }
176
Richard Uhler5f946da2015-07-17 12:28:32 -0700177 VLOG(oat) << "Oat File Assistant: No relocated oat file found,"
178 << " attempting to fall back to interpreting oat file instead.";
Richard Uhler66d874d2015-01-15 09:37:19 -0800179
Richard Uhler5f946da2015-07-17 12:28:32 -0700180 if (!OatFileIsOutOfDate() && !OatFileIsExecutable()) {
181 oat_file_released_ = true;
182 return std::move(cached_oat_file_);
183 }
184
185 if (!OdexFileIsOutOfDate() && !OdexFileIsExecutable()) {
186 oat_file_released_ = true;
187 return std::move(cached_odex_file_);
188 }
189
190 if (!OatFileIsOutOfDate()) {
191 load_executable_ = false;
192 ClearOatFileCache();
Richard Uhler66d874d2015-01-15 09:37:19 -0800193 if (!OatFileIsOutOfDate()) {
Richard Uhler5f946da2015-07-17 12:28:32 -0700194 CHECK(!OatFileIsExecutable());
195 oat_file_released_ = true;
196 return std::move(cached_oat_file_);
Richard Uhler66d874d2015-01-15 09:37:19 -0800197 }
Richard Uhler5f946da2015-07-17 12:28:32 -0700198 }
Richard Uhler66d874d2015-01-15 09:37:19 -0800199
Richard Uhler5f946da2015-07-17 12:28:32 -0700200 if (!OdexFileIsOutOfDate()) {
201 load_executable_ = false;
202 ClearOdexFileCache();
Richard Uhler66d874d2015-01-15 09:37:19 -0800203 if (!OdexFileIsOutOfDate()) {
Richard Uhler5f946da2015-07-17 12:28:32 -0700204 CHECK(!OdexFileIsExecutable());
205 oat_file_released_ = true;
206 return std::move(cached_odex_file_);
Richard Uhler66d874d2015-01-15 09:37:19 -0800207 }
208 }
209
210 return std::unique_ptr<OatFile>();
211}
212
213std::vector<std::unique_ptr<const DexFile>> OatFileAssistant::LoadDexFiles(
214 const OatFile& oat_file, const char* dex_location) {
215 std::vector<std::unique_ptr<const DexFile>> dex_files;
216
217 // Load the primary dex file.
218 std::string error_msg;
219 const OatFile::OatDexFile* oat_dex_file = oat_file.GetOatDexFile(
220 dex_location, nullptr, false);
221 if (oat_dex_file == nullptr) {
222 LOG(WARNING) << "Attempt to load out-of-date oat file "
223 << oat_file.GetLocation() << " for dex location " << dex_location;
224 return std::vector<std::unique_ptr<const DexFile>>();
225 }
226
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700227 std::unique_ptr<const DexFile> dex_file = oat_dex_file->OpenDexFile(&error_msg);
Richard Uhler66d874d2015-01-15 09:37:19 -0800228 if (dex_file.get() == nullptr) {
229 LOG(WARNING) << "Failed to open dex file from oat dex file: " << error_msg;
230 return std::vector<std::unique_ptr<const DexFile>>();
231 }
232 dex_files.push_back(std::move(dex_file));
233
234 // Load secondary multidex files
Andreas Gampe90e34042015-04-27 20:01:52 -0700235 for (size_t i = 1; ; i++) {
236 std::string secondary_dex_location = DexFile::GetMultiDexLocation(i, dex_location);
Richard Uhler66d874d2015-01-15 09:37:19 -0800237 oat_dex_file = oat_file.GetOatDexFile(secondary_dex_location.c_str(), nullptr, false);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700238 if (oat_dex_file == nullptr) {
Richard Uhler66d874d2015-01-15 09:37:19 -0800239 // There are no more secondary dex files to load.
240 break;
241 }
242
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700243 dex_file = oat_dex_file->OpenDexFile(&error_msg);
Richard Uhler66d874d2015-01-15 09:37:19 -0800244 if (dex_file.get() == nullptr) {
245 LOG(WARNING) << "Failed to open dex file from oat dex file: " << error_msg;
246 return std::vector<std::unique_ptr<const DexFile>>();
247 }
248 dex_files.push_back(std::move(dex_file));
249 }
250 return dex_files;
251}
252
Richard Uhler9b994ea2015-06-24 08:44:19 -0700253bool OatFileAssistant::HasOriginalDexFiles() {
254 // Ensure GetRequiredDexChecksum has been run so that
255 // has_original_dex_files_ is initialized. We don't care about the result of
256 // GetRequiredDexChecksum.
257 GetRequiredDexChecksum();
258 return has_original_dex_files_;
259}
260
Richard Uhler66d874d2015-01-15 09:37:19 -0800261const std::string* OatFileAssistant::OdexFileName() {
262 if (!cached_odex_file_name_attempted_) {
Richard Uhler66d874d2015-01-15 09:37:19 -0800263 cached_odex_file_name_attempted_ = true;
264
265 std::string error_msg;
266 cached_odex_file_name_found_ = DexFilenameToOdexFilename(
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700267 dex_location_, isa_, &cached_odex_file_name_, &error_msg);
Richard Uhler66d874d2015-01-15 09:37:19 -0800268 if (!cached_odex_file_name_found_) {
269 // If we can't figure out the odex file, we treat it as if the odex
270 // file was inaccessible.
271 LOG(WARNING) << "Failed to determine odex file name: " << error_msg;
272 }
273 }
274 return cached_odex_file_name_found_ ? &cached_odex_file_name_ : nullptr;
275}
276
277bool OatFileAssistant::OdexFileExists() {
278 return GetOdexFile() != nullptr;
279}
280
Richard Uhler95abd042015-03-24 09:51:28 -0700281OatFileAssistant::OatStatus OatFileAssistant::OdexFileStatus() {
Richard Uhler66d874d2015-01-15 09:37:19 -0800282 if (OdexFileIsOutOfDate()) {
Richard Uhler95abd042015-03-24 09:51:28 -0700283 return kOatOutOfDate;
Richard Uhler66d874d2015-01-15 09:37:19 -0800284 }
285 if (OdexFileIsUpToDate()) {
Richard Uhler95abd042015-03-24 09:51:28 -0700286 return kOatUpToDate;
Richard Uhler66d874d2015-01-15 09:37:19 -0800287 }
Richard Uhler95abd042015-03-24 09:51:28 -0700288 return kOatNeedsRelocation;
Richard Uhler66d874d2015-01-15 09:37:19 -0800289}
290
291bool OatFileAssistant::OdexFileIsOutOfDate() {
292 if (!odex_file_is_out_of_date_attempted_) {
293 odex_file_is_out_of_date_attempted_ = true;
294 const OatFile* odex_file = GetOdexFile();
295 if (odex_file == nullptr) {
296 cached_odex_file_is_out_of_date_ = true;
297 } else {
298 cached_odex_file_is_out_of_date_ = GivenOatFileIsOutOfDate(*odex_file);
299 }
300 }
301 return cached_odex_file_is_out_of_date_;
302}
303
304bool OatFileAssistant::OdexFileNeedsRelocation() {
Richard Uhler95abd042015-03-24 09:51:28 -0700305 return OdexFileStatus() == kOatNeedsRelocation;
Richard Uhler66d874d2015-01-15 09:37:19 -0800306}
307
308bool OatFileAssistant::OdexFileIsUpToDate() {
309 if (!odex_file_is_up_to_date_attempted_) {
310 odex_file_is_up_to_date_attempted_ = true;
311 const OatFile* odex_file = GetOdexFile();
312 if (odex_file == nullptr) {
313 cached_odex_file_is_up_to_date_ = false;
314 } else {
315 cached_odex_file_is_up_to_date_ = GivenOatFileIsUpToDate(*odex_file);
316 }
317 }
318 return cached_odex_file_is_up_to_date_;
319}
320
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800321std::string OatFileAssistant::ArtFileName(const OatFile* oat_file) const {
322 const std::string oat_file_location = oat_file->GetLocation();
323 // Replace extension with .art
324 const size_t last_ext = oat_file_location.find_last_of('.');
325 if (last_ext == std::string::npos) {
326 LOG(ERROR) << "No extension in oat file " << oat_file_location;
327 return std::string();
328 }
329 return oat_file_location.substr(0, last_ext) + ".art";
330}
331
Richard Uhler66d874d2015-01-15 09:37:19 -0800332const std::string* OatFileAssistant::OatFileName() {
333 if (!cached_oat_file_name_attempted_) {
334 cached_oat_file_name_attempted_ = true;
335
336 // Compute the oat file name from the dex location.
Richard Uhler66d874d2015-01-15 09:37:19 -0800337 // TODO: The oat file assistant should be the definitive place for
338 // determining the oat file name from the dex location, not
339 // GetDalvikCacheFilename.
340 std::string cache_dir = StringPrintf("%s%s",
341 DalvikCacheDirectory().c_str(), GetInstructionSetString(isa_));
342 std::string error_msg;
Richard Uhler740eec92015-10-15 15:12:23 -0700343 cached_oat_file_name_found_ = GetDalvikCacheFilename(dex_location_.c_str(),
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700344 cache_dir.c_str(), &cached_oat_file_name_, &error_msg);
Richard Uhler66d874d2015-01-15 09:37:19 -0800345 if (!cached_oat_file_name_found_) {
346 // If we can't determine the oat file name, we treat the oat file as
347 // inaccessible.
348 LOG(WARNING) << "Failed to determine oat file name for dex location "
349 << dex_location_ << ": " << error_msg;
350 }
351 }
352 return cached_oat_file_name_found_ ? &cached_oat_file_name_ : nullptr;
353}
354
355bool OatFileAssistant::OatFileExists() {
356 return GetOatFile() != nullptr;
357}
358
Richard Uhler95abd042015-03-24 09:51:28 -0700359OatFileAssistant::OatStatus OatFileAssistant::OatFileStatus() {
Richard Uhler66d874d2015-01-15 09:37:19 -0800360 if (OatFileIsOutOfDate()) {
Richard Uhler95abd042015-03-24 09:51:28 -0700361 return kOatOutOfDate;
Richard Uhler66d874d2015-01-15 09:37:19 -0800362 }
363 if (OatFileIsUpToDate()) {
Richard Uhler95abd042015-03-24 09:51:28 -0700364 return kOatUpToDate;
Richard Uhler66d874d2015-01-15 09:37:19 -0800365 }
Richard Uhler95abd042015-03-24 09:51:28 -0700366 return kOatNeedsRelocation;
Richard Uhler66d874d2015-01-15 09:37:19 -0800367}
368
369bool OatFileAssistant::OatFileIsOutOfDate() {
370 if (!oat_file_is_out_of_date_attempted_) {
371 oat_file_is_out_of_date_attempted_ = true;
372 const OatFile* oat_file = GetOatFile();
373 if (oat_file == nullptr) {
374 cached_oat_file_is_out_of_date_ = true;
375 } else {
376 cached_oat_file_is_out_of_date_ = GivenOatFileIsOutOfDate(*oat_file);
377 }
378 }
379 return cached_oat_file_is_out_of_date_;
380}
381
382bool OatFileAssistant::OatFileNeedsRelocation() {
Richard Uhler95abd042015-03-24 09:51:28 -0700383 return OatFileStatus() == kOatNeedsRelocation;
Richard Uhler66d874d2015-01-15 09:37:19 -0800384}
385
386bool OatFileAssistant::OatFileIsUpToDate() {
387 if (!oat_file_is_up_to_date_attempted_) {
388 oat_file_is_up_to_date_attempted_ = true;
389 const OatFile* oat_file = GetOatFile();
390 if (oat_file == nullptr) {
391 cached_oat_file_is_up_to_date_ = false;
392 } else {
393 cached_oat_file_is_up_to_date_ = GivenOatFileIsUpToDate(*oat_file);
394 }
395 }
396 return cached_oat_file_is_up_to_date_;
397}
398
Richard Uhler95abd042015-03-24 09:51:28 -0700399OatFileAssistant::OatStatus OatFileAssistant::GivenOatFileStatus(const OatFile& file) {
Richard Uhler66d874d2015-01-15 09:37:19 -0800400 // TODO: This could cause GivenOatFileIsOutOfDate to be called twice, which
401 // is more work than we need to do. If performance becomes a concern, and
402 // this method is actually called, this should be fixed.
403 if (GivenOatFileIsOutOfDate(file)) {
Richard Uhler95abd042015-03-24 09:51:28 -0700404 return kOatOutOfDate;
Richard Uhler66d874d2015-01-15 09:37:19 -0800405 }
406 if (GivenOatFileIsUpToDate(file)) {
Richard Uhler95abd042015-03-24 09:51:28 -0700407 return kOatUpToDate;
Richard Uhler66d874d2015-01-15 09:37:19 -0800408 }
Richard Uhler95abd042015-03-24 09:51:28 -0700409 return kOatNeedsRelocation;
Richard Uhler66d874d2015-01-15 09:37:19 -0800410}
411
412bool OatFileAssistant::GivenOatFileIsOutOfDate(const OatFile& file) {
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000413 // Verify the file satisfies the desired compilation type.
414 if ((target_compilation_type_mask_ & GetCompilationType(file)) == 0) {
415 return true;
416 }
417
Richard Uhler66d874d2015-01-15 09:37:19 -0800418 // Verify the dex checksum.
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700419 // Note: GetOatDexFile will return null if the dex checksum doesn't match
Richard Uhler66d874d2015-01-15 09:37:19 -0800420 // what we provide, which verifies the primary dex checksum for us.
421 const uint32_t* dex_checksum_pointer = GetRequiredDexChecksum();
422 const OatFile::OatDexFile* oat_dex_file = file.GetOatDexFile(
Richard Uhler740eec92015-10-15 15:12:23 -0700423 dex_location_.c_str(), dex_checksum_pointer, false);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700424 if (oat_dex_file == nullptr) {
Richard Uhler66d874d2015-01-15 09:37:19 -0800425 return true;
426 }
427
428 // Verify the dex checksums for any secondary multidex files
Andreas Gampe90e34042015-04-27 20:01:52 -0700429 for (size_t i = 1; ; i++) {
Richard Uhler66d874d2015-01-15 09:37:19 -0800430 std::string secondary_dex_location
Richard Uhler740eec92015-10-15 15:12:23 -0700431 = DexFile::GetMultiDexLocation(i, dex_location_.c_str());
Richard Uhler66d874d2015-01-15 09:37:19 -0800432 const OatFile::OatDexFile* secondary_oat_dex_file
433 = file.GetOatDexFile(secondary_dex_location.c_str(), nullptr, false);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700434 if (secondary_oat_dex_file == nullptr) {
Richard Uhler66d874d2015-01-15 09:37:19 -0800435 // There are no more secondary dex files to check.
436 break;
437 }
438
439 std::string error_msg;
440 uint32_t expected_secondary_checksum = 0;
441 if (DexFile::GetChecksum(secondary_dex_location.c_str(),
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700442 &expected_secondary_checksum, &error_msg)) {
Richard Uhler66d874d2015-01-15 09:37:19 -0800443 uint32_t actual_secondary_checksum
444 = secondary_oat_dex_file->GetDexFileLocationChecksum();
445 if (expected_secondary_checksum != actual_secondary_checksum) {
446 VLOG(oat) << "Dex checksum does not match for secondary dex: "
447 << secondary_dex_location
448 << ". Expected: " << expected_secondary_checksum
449 << ", Actual: " << actual_secondary_checksum;
Richard Uhler67ff7d12015-05-14 13:21:13 -0700450 return true;
Richard Uhler66d874d2015-01-15 09:37:19 -0800451 }
452 } else {
453 // If we can't get the checksum for the secondary location, we assume
454 // the dex checksum is up to date for this and all other secondary dex
455 // files.
456 break;
457 }
458 }
459
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000460 if (file.IsExtractOnly()) {
461 VLOG(oat) << "Oat file is extract-only. Image checksum test skipped.";
462 if (kIsDebugBuild) {
463 // Sanity check that no classes have compiled code. Does not test that
464 // the DEX code has not been quickened.
465 std::string error_msg;
466 for (const OatFile::OatDexFile* current : file.GetOatDexFiles()) {
467 std::unique_ptr<const DexFile> dex_file = current->OpenDexFile(&error_msg);
468 DCHECK(dex_file != nullptr);
469 for (size_t i = 0, e = dex_file->NumClassDefs(); i < e; ++i) {
470 DCHECK_EQ(current->GetOatClass(i).GetType(), kOatClassNoneCompiled);
471 }
472 }
473 }
474 return false;
475 }
David Brazdilce4b0ba2016-01-28 15:05:49 +0000476
Richard Uhler66d874d2015-01-15 09:37:19 -0800477 // Verify the image checksum
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000478 const ImageInfo* image_info = GetImageInfo();
479 if (image_info == nullptr) {
480 VLOG(oat) << "No image for oat image checksum to match against.";
481 return true;
Richard Uhler66d874d2015-01-15 09:37:19 -0800482 }
483
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000484 if (file.GetOatHeader().GetImageFileLocationOatChecksum() != image_info->oat_checksum) {
485 VLOG(oat) << "Oat image checksum does not match image checksum.";
486 return true;
Richard Uhler66d874d2015-01-15 09:37:19 -0800487 }
488
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000489 // The checksums are all good; the dex file is not out of date.
Richard Uhler66d874d2015-01-15 09:37:19 -0800490 return false;
491}
492
493bool OatFileAssistant::GivenOatFileNeedsRelocation(const OatFile& file) {
Richard Uhler95abd042015-03-24 09:51:28 -0700494 return GivenOatFileStatus(file) == kOatNeedsRelocation;
Richard Uhler66d874d2015-01-15 09:37:19 -0800495}
496
497bool OatFileAssistant::GivenOatFileIsUpToDate(const OatFile& file) {
498 if (GivenOatFileIsOutOfDate(file)) {
499 return false;
500 }
501
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000502 if (file.IsPic() || file.IsExtractOnly()) {
503 // Oat files compiled in PIC mode do not require relocation and extract-only
504 // oat files do not contain any compiled code. Skip the relocation test.
505 VLOG(oat) << "Oat relocation test skipped.";
506 return true;
507 }
Richard Uhlera62d2f02016-03-18 15:05:30 -0700508
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000509 const ImageInfo* image_info = GetImageInfo();
510 if (image_info == nullptr) {
511 VLOG(oat) << "No image to check oat relocation against.";
Richard Uhlera62d2f02016-03-18 15:05:30 -0700512 return false;
513 }
514
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000515 // Verify the oat_data_begin recorded for the image in the oat file matches
516 // the actual oat_data_begin for boot.oat in the image.
517 const OatHeader& oat_header = file.GetOatHeader();
518 uintptr_t oat_data_begin = oat_header.GetImageFileLocationOatDataBegin();
519 if (oat_data_begin != image_info->oat_data_begin) {
520 VLOG(oat) << file.GetLocation() <<
521 ": Oat file image oat_data_begin (" << oat_data_begin << ")"
522 << " does not match actual image oat_data_begin ("
523 << image_info->oat_data_begin << ")";
524 return false;
525 }
Richard Uhlera62d2f02016-03-18 15:05:30 -0700526
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000527 // Verify the oat_patch_delta recorded for the image in the oat file matches
528 // the actual oat_patch_delta for the image.
529 int32_t oat_patch_delta = oat_header.GetImagePatchDelta();
530 if (oat_patch_delta != image_info->patch_delta) {
531 VLOG(oat) << file.GetLocation() <<
532 ": Oat file image patch delta (" << oat_patch_delta << ")"
533 << " does not match actual image patch delta ("
534 << image_info->patch_delta << ")";
535 return false;
Richard Uhler66d874d2015-01-15 09:37:19 -0800536 }
537 return true;
538}
539
Richard Uhler95abd042015-03-24 09:51:28 -0700540bool OatFileAssistant::RelocateOatFile(const std::string* input_file,
541 std::string* error_msg) {
Richard Uhler66d874d2015-01-15 09:37:19 -0800542 CHECK(error_msg != nullptr);
543
Richard Uhler95abd042015-03-24 09:51:28 -0700544 if (input_file == nullptr) {
Richard Uhler740eec92015-10-15 15:12:23 -0700545 *error_msg = "Patching of oat file for dex location " + dex_location_
Richard Uhler95abd042015-03-24 09:51:28 -0700546 + " not attempted because the input file name could not be determined.";
Richard Uhler66d874d2015-01-15 09:37:19 -0800547 return false;
548 }
Richard Uhler95abd042015-03-24 09:51:28 -0700549 const std::string& input_file_name = *input_file;
Richard Uhler66d874d2015-01-15 09:37:19 -0800550
551 if (OatFileName() == nullptr) {
Richard Uhler740eec92015-10-15 15:12:23 -0700552 *error_msg = "Patching of oat file for dex location " + dex_location_
Richard Uhler66d874d2015-01-15 09:37:19 -0800553 + " not attempted because the oat file name could not be determined.";
554 return false;
555 }
556 const std::string& oat_file_name = *OatFileName();
557
558 const ImageInfo* image_info = GetImageInfo();
559 Runtime* runtime = Runtime::Current();
560 if (image_info == nullptr) {
561 *error_msg = "Patching of oat file " + oat_file_name
562 + " not attempted because no image location was found.";
563 return false;
564 }
565
566 if (!runtime->IsDex2OatEnabled()) {
567 *error_msg = "Patching of oat file " + oat_file_name
568 + " not attempted because dex2oat is disabled";
569 return false;
570 }
571
572 std::vector<std::string> argv;
573 argv.push_back(runtime->GetPatchoatExecutable());
574 argv.push_back("--instruction-set=" + std::string(GetInstructionSetString(isa_)));
Richard Uhler95abd042015-03-24 09:51:28 -0700575 argv.push_back("--input-oat-file=" + input_file_name);
Richard Uhler66d874d2015-01-15 09:37:19 -0800576 argv.push_back("--output-oat-file=" + oat_file_name);
577 argv.push_back("--patched-image-location=" + image_info->location);
578
579 std::string command_line(Join(argv, ' '));
580 if (!Exec(argv, error_msg)) {
581 // Manually delete the file. This ensures there is no garbage left over if
582 // the process unexpectedly died.
583 TEMP_FAILURE_RETRY(unlink(oat_file_name.c_str()));
584 return false;
585 }
586
587 // Mark that the oat file has changed and we should try to reload.
588 ClearOatFileCache();
589 return true;
590}
591
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000592bool OatFileAssistant::GenerateOatFile(std::string* error_msg) {
Richard Uhler66d874d2015-01-15 09:37:19 -0800593 CHECK(error_msg != nullptr);
594
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000595 // TODO: Currently we only know how to make a fully-compiled oat file.
596 // Perhaps we should support generating other kinds of oat files?
597 if ((target_compilation_type_mask_ & kFullCompilation) == 0) {
598 *error_msg = "Generation of oat file for dex location " + dex_location_
599 + " not attempted because full compilation was not specified"
600 + " as an acceptable target compilation type.";
601 return false;
602 }
603
Richard Uhler8327cf72015-10-13 16:34:59 -0700604 Runtime* runtime = Runtime::Current();
605 if (!runtime->IsDex2OatEnabled()) {
606 *error_msg = "Generation of oat file for dex location " + dex_location_
607 + " not attempted because dex2oat is disabled.";
608 return false;
609 }
610
Richard Uhler66d874d2015-01-15 09:37:19 -0800611 if (OatFileName() == nullptr) {
Richard Uhler740eec92015-10-15 15:12:23 -0700612 *error_msg = "Generation of oat file for dex location " + dex_location_
Richard Uhler66d874d2015-01-15 09:37:19 -0800613 + " not attempted because the oat file name could not be determined.";
614 return false;
615 }
616 const std::string& oat_file_name = *OatFileName();
617
Richard Uhler66d874d2015-01-15 09:37:19 -0800618 // dex2oat ignores missing dex files and doesn't report an error.
619 // Check explicitly here so we can detect the error properly.
620 // TODO: Why does dex2oat behave that way?
Richard Uhler740eec92015-10-15 15:12:23 -0700621 if (!OS::FileExists(dex_location_.c_str())) {
622 *error_msg = "Dex location " + dex_location_ + " does not exists.";
Richard Uhler66d874d2015-01-15 09:37:19 -0800623 return false;
624 }
625
Richard Uhler8327cf72015-10-13 16:34:59 -0700626 std::unique_ptr<File> oat_file;
627 oat_file.reset(OS::CreateEmptyFile(oat_file_name.c_str()));
628 if (oat_file.get() == nullptr) {
629 *error_msg = "Generation of oat file " + oat_file_name
630 + " not attempted because the oat file could not be created.";
631 return false;
632 }
633
634 if (fchmod(oat_file->Fd(), 0644) != 0) {
635 *error_msg = "Generation of oat file " + oat_file_name
636 + " not attempted because the oat file could not be made world readable.";
637 oat_file->Erase();
638 return false;
639 }
640
641 std::vector<std::string> args;
642 args.push_back("--dex-file=" + dex_location_);
643 args.push_back("--oat-fd=" + std::to_string(oat_file->Fd()));
644 args.push_back("--oat-location=" + oat_file_name);
645
Richard Uhler66d874d2015-01-15 09:37:19 -0800646 if (!Dex2Oat(args, error_msg)) {
647 // Manually delete the file. This ensures there is no garbage left over if
648 // the process unexpectedly died.
Richard Uhler8327cf72015-10-13 16:34:59 -0700649 oat_file->Erase();
650 TEMP_FAILURE_RETRY(unlink(oat_file_name.c_str()));
651 return false;
652 }
653
654 if (oat_file->FlushCloseOrErase() != 0) {
655 *error_msg = "Unable to close oat file " + oat_file_name;
Richard Uhler66d874d2015-01-15 09:37:19 -0800656 TEMP_FAILURE_RETRY(unlink(oat_file_name.c_str()));
657 return false;
658 }
659
660 // Mark that the oat file has changed and we should try to reload.
661 ClearOatFileCache();
662 return true;
663}
664
665bool OatFileAssistant::Dex2Oat(const std::vector<std::string>& args,
666 std::string* error_msg) {
667 Runtime* runtime = Runtime::Current();
668 std::string image_location = ImageLocation();
669 if (image_location.empty()) {
670 *error_msg = "No image location found for Dex2Oat.";
671 return false;
672 }
673
674 std::vector<std::string> argv;
675 argv.push_back(runtime->GetCompilerExecutable());
676 argv.push_back("--runtime-arg");
677 argv.push_back("-classpath");
678 argv.push_back("--runtime-arg");
679 argv.push_back(runtime->GetClassPathString());
Nicolas Geoffray7a4d0152015-07-10 17:29:39 +0100680 if (runtime->IsDebuggable()) {
Sebastien Hertz0de11332015-05-13 12:14:05 +0200681 argv.push_back("--debuggable");
682 }
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700683 runtime->AddCurrentRuntimeFeaturesAsDex2OatArguments(&argv);
Richard Uhler66d874d2015-01-15 09:37:19 -0800684
685 if (!runtime->IsVerificationEnabled()) {
686 argv.push_back("--compiler-filter=verify-none");
687 }
688
689 if (runtime->MustRelocateIfPossible()) {
690 argv.push_back("--runtime-arg");
691 argv.push_back("-Xrelocate");
692 } else {
693 argv.push_back("--runtime-arg");
694 argv.push_back("-Xnorelocate");
695 }
696
697 if (!kIsTargetBuild) {
698 argv.push_back("--host");
699 }
700
701 argv.push_back("--boot-image=" + image_location);
702
703 std::vector<std::string> compiler_options = runtime->GetCompilerOptions();
704 argv.insert(argv.end(), compiler_options.begin(), compiler_options.end());
705
706 argv.insert(argv.end(), args.begin(), args.end());
707
708 std::string command_line(Join(argv, ' '));
709 return Exec(argv, error_msg);
710}
711
712bool OatFileAssistant::DexFilenameToOdexFilename(const std::string& location,
713 InstructionSet isa, std::string* odex_filename, std::string* error_msg) {
714 CHECK(odex_filename != nullptr);
715 CHECK(error_msg != nullptr);
716
717 // The odex file name is formed by replacing the dex_location extension with
Richard Uhler63434112015-03-16 14:32:16 -0700718 // .odex and inserting an oat/<isa> directory. For example:
Richard Uhler66d874d2015-01-15 09:37:19 -0800719 // location = /foo/bar/baz.jar
Richard Uhler63434112015-03-16 14:32:16 -0700720 // odex_location = /foo/bar/oat/<isa>/baz.odex
Richard Uhler66d874d2015-01-15 09:37:19 -0800721
Richard Uhler63434112015-03-16 14:32:16 -0700722 // Find the directory portion of the dex location and add the oat/<isa>
723 // directory.
Richard Uhler66d874d2015-01-15 09:37:19 -0800724 size_t pos = location.rfind('/');
725 if (pos == std::string::npos) {
726 *error_msg = "Dex location " + location + " has no directory.";
727 return false;
728 }
729 std::string dir = location.substr(0, pos+1);
Richard Uhler63434112015-03-16 14:32:16 -0700730 dir += "oat/" + std::string(GetInstructionSetString(isa));
Richard Uhler66d874d2015-01-15 09:37:19 -0800731
732 // Find the file portion of the dex location.
733 std::string file;
734 if (pos == std::string::npos) {
735 file = location;
736 } else {
737 file = location.substr(pos+1);
738 }
739
740 // Get the base part of the file without the extension.
741 pos = file.rfind('.');
742 if (pos == std::string::npos) {
743 *error_msg = "Dex location " + location + " has no extension.";
744 return false;
745 }
746 std::string base = file.substr(0, pos);
747
748 *odex_filename = dir + "/" + base + ".odex";
749 return true;
750}
751
752std::string OatFileAssistant::DalvikCacheDirectory() {
753 // Note: We don't cache this, because it will only be called once by
Nicolas Geoffray845e5062016-03-23 06:42:05 +0000754 // OatFileName, and we don't care about the performance of the profiling
755 // code, which isn't used in practice.
Richard Uhler66d874d2015-01-15 09:37:19 -0800756
757 // TODO: The work done in GetDalvikCache is overkill for what we need.
758 // Ideally a new API for getting the DalvikCacheDirectory the way we want
759 // (without existence testing, creation, or death) is provided with the rest
760 // of the GetDalvikCache family of functions. Until such an API is in place,
761 // we use GetDalvikCache to avoid duplicating the logic for determining the
762 // dalvik cache directory.
763 std::string result;
764 bool have_android_data;
765 bool dalvik_cache_exists;
766 bool is_global_cache;
767 GetDalvikCache("", false, &result, &have_android_data, &dalvik_cache_exists, &is_global_cache);
768 return result;
769}
770
Richard Uhler66d874d2015-01-15 09:37:19 -0800771std::string OatFileAssistant::ImageLocation() {
772 Runtime* runtime = Runtime::Current();
Andreas Gampe8994a042015-12-30 19:03:17 +0000773 const std::vector<gc::space::ImageSpace*>& image_spaces =
774 runtime->GetHeap()->GetBootImageSpaces();
775 if (image_spaces.empty()) {
776 return "";
777 }
778 return image_spaces[0]->GetImageLocation();
Richard Uhler66d874d2015-01-15 09:37:19 -0800779}
780
781const uint32_t* OatFileAssistant::GetRequiredDexChecksum() {
Richard Uhler9b994ea2015-06-24 08:44:19 -0700782 if (!required_dex_checksum_attempted_) {
783 required_dex_checksum_attempted_ = true;
784 required_dex_checksum_found_ = false;
Richard Uhler66d874d2015-01-15 09:37:19 -0800785 std::string error_msg;
Richard Uhler740eec92015-10-15 15:12:23 -0700786 if (DexFile::GetChecksum(dex_location_.c_str(), &cached_required_dex_checksum_, &error_msg)) {
Richard Uhler9b994ea2015-06-24 08:44:19 -0700787 required_dex_checksum_found_ = true;
788 has_original_dex_files_ = true;
Richard Uhler66d874d2015-01-15 09:37:19 -0800789 } else {
790 // This can happen if the original dex file has been stripped from the
791 // apk.
792 VLOG(oat) << "OatFileAssistant: " << error_msg;
Richard Uhler9b994ea2015-06-24 08:44:19 -0700793 has_original_dex_files_ = false;
Richard Uhler66d874d2015-01-15 09:37:19 -0800794
795 // Get the checksum from the odex if we can.
796 const OatFile* odex_file = GetOdexFile();
797 if (odex_file != nullptr) {
798 const OatFile::OatDexFile* odex_dex_file = odex_file->GetOatDexFile(
Richard Uhler740eec92015-10-15 15:12:23 -0700799 dex_location_.c_str(), nullptr, false);
Richard Uhler66d874d2015-01-15 09:37:19 -0800800 if (odex_dex_file != nullptr) {
Richard Uhler9b994ea2015-06-24 08:44:19 -0700801 cached_required_dex_checksum_ = odex_dex_file->GetDexFileLocationChecksum();
802 required_dex_checksum_found_ = true;
Richard Uhler66d874d2015-01-15 09:37:19 -0800803 }
804 }
805 }
806 }
Richard Uhler9b994ea2015-06-24 08:44:19 -0700807 return required_dex_checksum_found_ ? &cached_required_dex_checksum_ : nullptr;
Richard Uhler66d874d2015-01-15 09:37:19 -0800808}
809
810const OatFile* OatFileAssistant::GetOdexFile() {
811 CHECK(!oat_file_released_) << "OdexFile called after oat file released.";
812 if (!odex_file_load_attempted_) {
813 odex_file_load_attempted_ = true;
814 if (OdexFileName() != nullptr) {
815 const std::string& odex_file_name = *OdexFileName();
816 std::string error_msg;
817 cached_odex_file_.reset(OatFile::Open(odex_file_name.c_str(),
Mathieu Chartier0b4cbd02016-03-08 16:49:58 -0800818 odex_file_name.c_str(),
819 nullptr,
820 nullptr,
821 load_executable_,
822 /*low_4gb*/false,
823 dex_location_.c_str(),
824 &error_msg));
Richard Uhler66d874d2015-01-15 09:37:19 -0800825 if (cached_odex_file_.get() == nullptr) {
826 VLOG(oat) << "OatFileAssistant test for existing pre-compiled oat file "
827 << odex_file_name << ": " << error_msg;
828 }
829 }
830 }
831 return cached_odex_file_.get();
832}
833
Richard Uhler5f946da2015-07-17 12:28:32 -0700834bool OatFileAssistant::OdexFileIsExecutable() {
835 const OatFile* odex_file = GetOdexFile();
836 return (odex_file != nullptr && odex_file->IsExecutable());
837}
838
Richard Uhler66d874d2015-01-15 09:37:19 -0800839void OatFileAssistant::ClearOdexFileCache() {
840 odex_file_load_attempted_ = false;
841 cached_odex_file_.reset();
842 odex_file_is_out_of_date_attempted_ = false;
843 odex_file_is_up_to_date_attempted_ = false;
844}
845
846const OatFile* OatFileAssistant::GetOatFile() {
847 CHECK(!oat_file_released_) << "OatFile called after oat file released.";
848 if (!oat_file_load_attempted_) {
849 oat_file_load_attempted_ = true;
850 if (OatFileName() != nullptr) {
851 const std::string& oat_file_name = *OatFileName();
852 std::string error_msg;
853 cached_oat_file_.reset(OatFile::Open(oat_file_name.c_str(),
Mathieu Chartier0b4cbd02016-03-08 16:49:58 -0800854 oat_file_name.c_str(),
855 nullptr,
856 nullptr,
857 load_executable_,
858 /*low_4gb*/false,
859 dex_location_.c_str(),
860 &error_msg));
Richard Uhler66d874d2015-01-15 09:37:19 -0800861 if (cached_oat_file_.get() == nullptr) {
862 VLOG(oat) << "OatFileAssistant test for existing oat file "
863 << oat_file_name << ": " << error_msg;
864 }
865 }
866 }
867 return cached_oat_file_.get();
868}
869
Richard Uhler5f946da2015-07-17 12:28:32 -0700870bool OatFileAssistant::OatFileIsExecutable() {
871 const OatFile* oat_file = GetOatFile();
872 return (oat_file != nullptr && oat_file->IsExecutable());
873}
874
Richard Uhler66d874d2015-01-15 09:37:19 -0800875void OatFileAssistant::ClearOatFileCache() {
876 oat_file_load_attempted_ = false;
877 cached_oat_file_.reset();
878 oat_file_is_out_of_date_attempted_ = false;
879 oat_file_is_up_to_date_attempted_ = false;
880}
881
882const OatFileAssistant::ImageInfo* OatFileAssistant::GetImageInfo() {
883 if (!image_info_load_attempted_) {
884 image_info_load_attempted_ = true;
885
886 Runtime* runtime = Runtime::Current();
Jeff Haodcdc85b2015-12-04 14:06:18 -0800887 std::vector<gc::space::ImageSpace*> image_spaces = runtime->GetHeap()->GetBootImageSpaces();
888 if (!image_spaces.empty()) {
Jeff Haodcdc85b2015-12-04 14:06:18 -0800889 cached_image_info_.location = image_spaces[0]->GetImageLocation();
Richard Uhler66d874d2015-01-15 09:37:19 -0800890
891 if (isa_ == kRuntimeISA) {
Jeff Haodcdc85b2015-12-04 14:06:18 -0800892 const ImageHeader& image_header = image_spaces[0]->GetImageHeader();
Richard Uhler66d874d2015-01-15 09:37:19 -0800893 cached_image_info_.oat_checksum = image_header.GetOatChecksum();
Mathieu Chartier073b16c2015-11-10 14:13:23 -0800894 cached_image_info_.oat_data_begin = reinterpret_cast<uintptr_t>(
895 image_header.GetOatDataBegin());
Richard Uhler66d874d2015-01-15 09:37:19 -0800896 cached_image_info_.patch_delta = image_header.GetPatchDelta();
897 } else {
898 std::unique_ptr<ImageHeader> image_header(
899 gc::space::ImageSpace::ReadImageHeaderOrDie(
900 cached_image_info_.location.c_str(), isa_));
901 cached_image_info_.oat_checksum = image_header->GetOatChecksum();
Mathieu Chartier073b16c2015-11-10 14:13:23 -0800902 cached_image_info_.oat_data_begin = reinterpret_cast<uintptr_t>(
903 image_header->GetOatDataBegin());
Richard Uhler66d874d2015-01-15 09:37:19 -0800904 cached_image_info_.patch_delta = image_header->GetPatchDelta();
905 }
906 }
Jeff Haodcdc85b2015-12-04 14:06:18 -0800907 image_info_load_succeeded_ = (!image_spaces.empty());
Richard Uhler66d874d2015-01-15 09:37:19 -0800908 }
909 return image_info_load_succeeded_ ? &cached_image_info_ : nullptr;
910}
911
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800912gc::space::ImageSpace* OatFileAssistant::OpenImageSpace(const OatFile* oat_file) {
913 DCHECK(oat_file != nullptr);
914 std::string art_file = ArtFileName(oat_file);
915 if (art_file.empty()) {
916 return nullptr;
917 }
918 std::string error_msg;
919 ScopedObjectAccess soa(Thread::Current());
920 gc::space::ImageSpace* ret = gc::space::ImageSpace::CreateFromAppImage(art_file.c_str(),
921 oat_file,
922 &error_msg);
Mathieu Chartiere778fc72016-01-25 20:11:28 -0800923 if (ret == nullptr && (VLOG_IS_ON(image) || OS::FileExists(art_file.c_str()))) {
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800924 LOG(INFO) << "Failed to open app image " << art_file.c_str() << " " << error_msg;
925 }
926 return ret;
927}
928
Richard Uhler66d874d2015-01-15 09:37:19 -0800929} // namespace art
930