blob: 1bcddfebc5dbe822d15e4acc908f5e57e8121c20 [file] [log] [blame]
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -07001/*
2 * Copyright (C) 2015 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_manager.h"
18
19#include <memory>
20#include <queue>
21#include <vector>
22
Andreas Gampe46ee31b2016-12-14 10:11:49 -080023#include "android-base/stringprintf.h"
24
Andreas Gampe90b936d2017-01-31 08:58:55 -080025#include "art_field-inl.h"
Jeff Hao8ec0a202017-03-07 21:56:31 -080026#include "base/bit_vector-inl.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070027#include "base/logging.h"
28#include "base/stl_util.h"
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -080029#include "base/systrace.h"
Mathieu Chartierfbc31082016-01-24 11:59:56 -080030#include "class_linker.h"
Mathieu Chartier80b37b72015-10-12 18:13:39 -070031#include "dex_file-inl.h"
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -070032#include "dex_file_tracking_registrar.h"
Mathieu Chartier61d2b2d2016-02-04 13:31:46 -080033#include "gc/scoped_gc_critical_section.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070034#include "gc/space/image_space.h"
Mathieu Chartierfbc31082016-01-24 11:59:56 -080035#include "handle_scope-inl.h"
Andreas Gampe08883de2016-11-08 13:20:52 -080036#include "jni_internal.h"
Mathieu Chartierfbc31082016-01-24 11:59:56 -080037#include "mirror/class_loader.h"
Andreas Gampe90b936d2017-01-31 08:58:55 -080038#include "mirror/object-inl.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070039#include "oat_file_assistant.h"
Mathieu Chartier3398c782016-09-30 10:27:43 -070040#include "obj_ptr-inl.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070041#include "scoped_thread_state_change-inl.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070042#include "thread-inl.h"
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -080043#include "thread_list.h"
Andreas Gampe90b936d2017-01-31 08:58:55 -080044#include "well_known_classes.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070045
46namespace art {
47
Andreas Gampe46ee31b2016-12-14 10:11:49 -080048using android::base::StringPrintf;
49
Mathieu Chartierfbc31082016-01-24 11:59:56 -080050// If true, then we attempt to load the application image if it exists.
51static constexpr bool kEnableAppImage = true;
52
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070053const OatFile* OatFileManager::RegisterOatFile(std::unique_ptr<const OatFile> oat_file) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -070054 WriterMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070055 DCHECK(oat_file != nullptr);
56 if (kIsDebugBuild) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -070057 CHECK(oat_files_.find(oat_file) == oat_files_.end());
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070058 for (const std::unique_ptr<const OatFile>& existing : oat_files_) {
59 CHECK_NE(oat_file.get(), existing.get()) << oat_file->GetLocation();
60 // Check that we don't have an oat file with the same address. Copies of the same oat file
61 // should be loaded at different addresses.
62 CHECK_NE(oat_file->Begin(), existing->Begin()) << "Oat file already mapped at that location";
63 }
64 }
65 have_non_pic_oat_file_ = have_non_pic_oat_file_ || !oat_file->IsPic();
Mathieu Chartiere58991b2015-10-13 07:59:34 -070066 const OatFile* ret = oat_file.get();
67 oat_files_.insert(std::move(oat_file));
68 return ret;
69}
70
71void OatFileManager::UnRegisterAndDeleteOatFile(const OatFile* oat_file) {
72 WriterMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
73 DCHECK(oat_file != nullptr);
74 std::unique_ptr<const OatFile> compare(oat_file);
75 auto it = oat_files_.find(compare);
76 CHECK(it != oat_files_.end());
77 oat_files_.erase(it);
78 compare.release();
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070079}
80
Calin Juravle0b791272016-04-18 16:38:27 +010081const OatFile* OatFileManager::FindOpenedOatFileFromDexLocation(
82 const std::string& dex_base_location) const {
83 ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
84 for (const std::unique_ptr<const OatFile>& oat_file : oat_files_) {
85 const std::vector<const OatDexFile*>& oat_dex_files = oat_file->GetOatDexFiles();
86 for (const OatDexFile* oat_dex_file : oat_dex_files) {
87 if (DexFile::GetBaseLocation(oat_dex_file->GetDexFileLocation()) == dex_base_location) {
88 return oat_file.get();
89 }
90 }
91 }
92 return nullptr;
93}
94
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070095const OatFile* OatFileManager::FindOpenedOatFileFromOatLocation(const std::string& oat_location)
96 const {
97 ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
Mathieu Chartiere58991b2015-10-13 07:59:34 -070098 return FindOpenedOatFileFromOatLocationLocked(oat_location);
99}
100
101const OatFile* OatFileManager::FindOpenedOatFileFromOatLocationLocked(
102 const std::string& oat_location) const {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700103 for (const std::unique_ptr<const OatFile>& oat_file : oat_files_) {
104 if (oat_file->GetLocation() == oat_location) {
105 return oat_file.get();
106 }
107 }
108 return nullptr;
109}
110
Jeff Haodcdc85b2015-12-04 14:06:18 -0800111std::vector<const OatFile*> OatFileManager::GetBootOatFiles() const {
112 std::vector<const OatFile*> oat_files;
113 std::vector<gc::space::ImageSpace*> image_spaces =
114 Runtime::Current()->GetHeap()->GetBootImageSpaces();
115 for (gc::space::ImageSpace* image_space : image_spaces) {
116 oat_files.push_back(image_space->GetOatFile());
117 }
118 return oat_files;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700119}
120
121const OatFile* OatFileManager::GetPrimaryOatFile() const {
122 ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
Jeff Haodcdc85b2015-12-04 14:06:18 -0800123 std::vector<const OatFile*> boot_oat_files = GetBootOatFiles();
124 if (!boot_oat_files.empty()) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700125 for (const std::unique_ptr<const OatFile>& oat_file : oat_files_) {
Jeff Haodcdc85b2015-12-04 14:06:18 -0800126 if (std::find(boot_oat_files.begin(), boot_oat_files.end(), oat_file.get()) ==
127 boot_oat_files.end()) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700128 return oat_file.get();
129 }
130 }
131 }
132 return nullptr;
133}
134
135OatFileManager::~OatFileManager() {
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700136 // Explicitly clear oat_files_ since the OatFile destructor calls back into OatFileManager for
137 // UnRegisterOatFileLocation.
138 oat_files_.clear();
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700139}
140
Jeff Haodcdc85b2015-12-04 14:06:18 -0800141std::vector<const OatFile*> OatFileManager::RegisterImageOatFiles(
142 std::vector<gc::space::ImageSpace*> spaces) {
143 std::vector<const OatFile*> oat_files;
144 for (gc::space::ImageSpace* space : spaces) {
145 oat_files.push_back(RegisterOatFile(space->ReleaseOatFile()));
146 }
147 return oat_files;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700148}
149
Jeff Hao8ec0a202017-03-07 21:56:31 -0800150class TypeIndexInfo {
151 public:
152 explicit TypeIndexInfo(const DexFile* dex_file)
153 : type_indexes_(GenerateTypeIndexes(dex_file)),
154 iter_(type_indexes_.Indexes().begin()),
155 end_(type_indexes_.Indexes().end()) { }
156
157 BitVector& GetTypeIndexes() {
158 return type_indexes_;
159 }
160 BitVector::IndexIterator& GetIterator() {
161 return iter_;
162 }
163 BitVector::IndexIterator& GetIteratorEnd() {
164 return end_;
165 }
166 void AdvanceIterator() {
167 iter_++;
168 }
169
170 private:
171 static BitVector GenerateTypeIndexes(const DexFile* dex_file) {
172 BitVector type_indexes(/*start_bits*/0, /*expandable*/true, Allocator::GetMallocAllocator());
173 for (uint16_t i = 0; i < dex_file->NumClassDefs(); ++i) {
174 const DexFile::ClassDef& class_def = dex_file->GetClassDef(i);
175 uint16_t type_idx = class_def.class_idx_.index_;
176 type_indexes.SetBit(type_idx);
177 }
178 return type_indexes;
179 }
180
181 // BitVector with bits set for the type indexes of all classes in the input dex file.
182 BitVector type_indexes_;
183 BitVector::IndexIterator iter_;
184 BitVector::IndexIterator end_;
185};
186
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700187class DexFileAndClassPair : ValueObject {
188 public:
Jeff Hao8ec0a202017-03-07 21:56:31 -0800189 DexFileAndClassPair(const DexFile* dex_file, TypeIndexInfo* type_info, bool from_loaded_oat)
190 : type_info_(type_info),
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700191 dex_file_(dex_file),
Jeff Hao8ec0a202017-03-07 21:56:31 -0800192 cached_descriptor_(dex_file_->StringByTypeIdx(dex::TypeIndex(*type_info->GetIterator()))),
193 from_loaded_oat_(from_loaded_oat) {
194 type_info_->AdvanceIterator();
195 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700196
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700197 DexFileAndClassPair(const DexFileAndClassPair& rhs) = default;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700198
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700199 DexFileAndClassPair& operator=(const DexFileAndClassPair& rhs) = default;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700200
201 const char* GetCachedDescriptor() const {
202 return cached_descriptor_;
203 }
204
205 bool operator<(const DexFileAndClassPair& rhs) const {
206 const int cmp = strcmp(cached_descriptor_, rhs.cached_descriptor_);
207 if (cmp != 0) {
208 // Note that the order must be reversed. We want to iterate over the classes in dex files.
209 // They are sorted lexicographically. Thus, the priority-queue must be a min-queue.
210 return cmp > 0;
211 }
212 return dex_file_ < rhs.dex_file_;
213 }
214
215 bool DexFileHasMoreClasses() const {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800216 return type_info_->GetIterator() != type_info_->GetIteratorEnd();
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700217 }
218
219 void Next() {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800220 cached_descriptor_ = dex_file_->StringByTypeIdx(dex::TypeIndex(*type_info_->GetIterator()));
221 type_info_->AdvanceIterator();
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700222 }
223
224 bool FromLoadedOat() const {
225 return from_loaded_oat_;
226 }
227
228 const DexFile* GetDexFile() const {
Jeff Haof0192c82016-03-28 20:39:50 -0700229 return dex_file_;
230 }
231
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700232 private:
Jeff Hao8ec0a202017-03-07 21:56:31 -0800233 TypeIndexInfo* type_info_;
Jeff Haof0192c82016-03-28 20:39:50 -0700234 const DexFile* dex_file_;
Jeff Hao8ec0a202017-03-07 21:56:31 -0800235 const char* cached_descriptor_;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700236 bool from_loaded_oat_; // We only need to compare mismatches between what we load now
237 // and what was loaded before. Any old duplicates must have been
238 // OK, and any new "internal" duplicates are as well (they must
239 // be from multidex, which resolves correctly).
240};
241
Jeff Hao8ec0a202017-03-07 21:56:31 -0800242static void AddDexFilesFromOat(
243 const OatFile* oat_file,
244 /*out*/std::vector<const DexFile*>* dex_files,
245 std::vector<std::unique_ptr<const DexFile>>* opened_dex_files) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700246 for (const OatDexFile* oat_dex_file : oat_file->GetOatDexFiles()) {
247 std::string error;
248 std::unique_ptr<const DexFile> dex_file = oat_dex_file->OpenDexFile(&error);
249 if (dex_file == nullptr) {
250 LOG(WARNING) << "Could not create dex file from oat file: " << error;
251 } else if (dex_file->NumClassDefs() > 0U) {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800252 dex_files->push_back(dex_file.get());
Mathieu Chartier14d7b3e2016-06-09 16:18:04 -0700253 opened_dex_files->push_back(std::move(dex_file));
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700254 }
255 }
256}
257
Jeff Hao8ec0a202017-03-07 21:56:31 -0800258static void AddNext(/*inout*/DexFileAndClassPair& original,
259 /*inout*/std::priority_queue<DexFileAndClassPair>& heap) {
260 if (original.DexFileHasMoreClasses()) {
261 original.Next();
262 heap.push(std::move(original));
Jeff Haof0192c82016-03-28 20:39:50 -0700263 }
264}
265
Andreas Gampeca620d72016-11-08 08:09:33 -0800266template <typename T>
Mathieu Chartier3398c782016-09-30 10:27:43 -0700267static void IterateOverJavaDexFile(ObjPtr<mirror::Object> dex_file,
Jeff Haof0192c82016-03-28 20:39:50 -0700268 ArtField* const cookie_field,
Andreas Gampeca620d72016-11-08 08:09:33 -0800269 const T& fn)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700270 REQUIRES_SHARED(Locks::mutator_lock_) {
Jeff Haof0192c82016-03-28 20:39:50 -0700271 if (dex_file != nullptr) {
272 mirror::LongArray* long_array = cookie_field->GetObject(dex_file)->AsLongArray();
273 if (long_array == nullptr) {
274 // This should never happen so log a warning.
275 LOG(WARNING) << "Null DexFile::mCookie";
276 return;
277 }
278 int32_t long_array_size = long_array->GetLength();
279 // Start from 1 to skip the oat file.
280 for (int32_t j = 1; j < long_array_size; ++j) {
281 const DexFile* cp_dex_file = reinterpret_cast<const DexFile*>(static_cast<uintptr_t>(
282 long_array->GetWithoutChecks(j)));
283 if (!fn(cp_dex_file)) {
284 return;
285 }
286 }
287 }
288}
289
Andreas Gampeca620d72016-11-08 08:09:33 -0800290template <typename T>
Jeff Haof0192c82016-03-28 20:39:50 -0700291static void IterateOverPathClassLoader(
Jeff Haof0192c82016-03-28 20:39:50 -0700292 Handle<mirror::ClassLoader> class_loader,
293 MutableHandle<mirror::ObjectArray<mirror::Object>> dex_elements,
Andreas Gampeca620d72016-11-08 08:09:33 -0800294 const T& fn) REQUIRES_SHARED(Locks::mutator_lock_) {
Jeff Haof0192c82016-03-28 20:39:50 -0700295 // Handle this step.
296 // Handle as if this is the child PathClassLoader.
297 // The class loader is a PathClassLoader which inherits from BaseDexClassLoader.
298 // We need to get the DexPathList and loop through it.
Andreas Gampe08883de2016-11-08 13:20:52 -0800299 ArtField* const cookie_field =
300 jni::DecodeArtField(WellKnownClasses::dalvik_system_DexFile_cookie);
Jeff Haof0192c82016-03-28 20:39:50 -0700301 ArtField* const dex_file_field =
Andreas Gampe08883de2016-11-08 13:20:52 -0800302 jni::DecodeArtField(WellKnownClasses::dalvik_system_DexPathList__Element_dexFile);
Mathieu Chartier3398c782016-09-30 10:27:43 -0700303 ObjPtr<mirror::Object> dex_path_list =
Andreas Gampe08883de2016-11-08 13:20:52 -0800304 jni::DecodeArtField(WellKnownClasses::dalvik_system_BaseDexClassLoader_pathList)->
305 GetObject(class_loader.Get());
Jeff Haof0192c82016-03-28 20:39:50 -0700306 if (dex_path_list != nullptr && dex_file_field != nullptr && cookie_field != nullptr) {
307 // DexPathList has an array dexElements of Elements[] which each contain a dex file.
Mathieu Chartier3398c782016-09-30 10:27:43 -0700308 ObjPtr<mirror::Object> dex_elements_obj =
Andreas Gampe08883de2016-11-08 13:20:52 -0800309 jni::DecodeArtField(WellKnownClasses::dalvik_system_DexPathList_dexElements)->
310 GetObject(dex_path_list);
Jeff Haof0192c82016-03-28 20:39:50 -0700311 // Loop through each dalvik.system.DexPathList$Element's dalvik.system.DexFile and look
312 // at the mCookie which is a DexFile vector.
313 if (dex_elements_obj != nullptr) {
314 dex_elements.Assign(dex_elements_obj->AsObjectArray<mirror::Object>());
315 for (int32_t i = 0; i < dex_elements->GetLength(); ++i) {
316 mirror::Object* element = dex_elements->GetWithoutChecks(i);
317 if (element == nullptr) {
318 // Should never happen, fall back to java code to throw a NPE.
319 break;
320 }
Mathieu Chartier3398c782016-09-30 10:27:43 -0700321 ObjPtr<mirror::Object> dex_file = dex_file_field->GetObject(element);
Jeff Haof0192c82016-03-28 20:39:50 -0700322 IterateOverJavaDexFile(dex_file, cookie_field, fn);
323 }
324 }
325 }
326}
327
328static bool GetDexFilesFromClassLoader(
329 ScopedObjectAccessAlreadyRunnable& soa,
330 mirror::ClassLoader* class_loader,
Jeff Hao8ec0a202017-03-07 21:56:31 -0800331 std::vector<const DexFile*>* dex_files)
332 REQUIRES_SHARED(Locks::mutator_lock_) {
Jeff Haof0192c82016-03-28 20:39:50 -0700333 if (ClassLinker::IsBootClassLoader(soa, class_loader)) {
334 // The boot class loader. We don't load any of these files, as we know we compiled against
335 // them correctly.
336 return true;
337 }
338
339 // Unsupported class-loader?
Mathieu Chartier0795f232016-09-27 18:43:30 -0700340 if (soa.Decode<mirror::Class>(WellKnownClasses::dalvik_system_PathClassLoader) !=
341 class_loader->GetClass()) {
David Sehr709b0702016-10-13 09:12:37 -0700342 VLOG(class_linker) << "Unsupported class-loader "
343 << mirror::Class::PrettyClass(class_loader->GetClass());
Jeff Haof0192c82016-03-28 20:39:50 -0700344 return false;
345 }
346
Jeff Hao8ec0a202017-03-07 21:56:31 -0800347 bool recursive_result = GetDexFilesFromClassLoader(soa, class_loader->GetParent(), dex_files);
Jeff Haof0192c82016-03-28 20:39:50 -0700348 if (!recursive_result) {
349 // Something wrong up the chain.
350 return false;
351 }
352
353 // Collect all the dex files.
354 auto GetDexFilesFn = [&] (const DexFile* cp_dex_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700355 REQUIRES_SHARED(Locks::mutator_lock_) {
Jeff Haof0192c82016-03-28 20:39:50 -0700356 if (cp_dex_file->NumClassDefs() > 0) {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800357 dex_files->push_back(cp_dex_file);
Jeff Haof0192c82016-03-28 20:39:50 -0700358 }
359 return true; // Continue looking.
360 };
361
362 // Handle for dex-cache-element.
363 StackHandleScope<3> hs(soa.Self());
364 MutableHandle<mirror::ObjectArray<mirror::Object>> dex_elements(
365 hs.NewHandle<mirror::ObjectArray<mirror::Object>>(nullptr));
366 Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(class_loader));
367
Andreas Gampe08883de2016-11-08 13:20:52 -0800368 IterateOverPathClassLoader(h_class_loader, dex_elements, GetDexFilesFn);
Jeff Haof0192c82016-03-28 20:39:50 -0700369
370 return true;
371}
372
373static void GetDexFilesFromDexElementsArray(
374 ScopedObjectAccessAlreadyRunnable& soa,
375 Handle<mirror::ObjectArray<mirror::Object>> dex_elements,
Jeff Hao8ec0a202017-03-07 21:56:31 -0800376 std::vector<const DexFile*>* dex_files)
377 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampefa4333d2017-02-14 11:10:34 -0800378 if (dex_elements == nullptr) {
Jeff Haof0192c82016-03-28 20:39:50 -0700379 // Nothing to do.
380 return;
381 }
382
Andreas Gampe08883de2016-11-08 13:20:52 -0800383 ArtField* const cookie_field =
384 jni::DecodeArtField(WellKnownClasses::dalvik_system_DexFile_cookie);
Jeff Haof0192c82016-03-28 20:39:50 -0700385 ArtField* const dex_file_field =
Andreas Gampe08883de2016-11-08 13:20:52 -0800386 jni::DecodeArtField(WellKnownClasses::dalvik_system_DexPathList__Element_dexFile);
Mathieu Chartier0795f232016-09-27 18:43:30 -0700387 ObjPtr<mirror::Class> const element_class = soa.Decode<mirror::Class>(
Jeff Haof0192c82016-03-28 20:39:50 -0700388 WellKnownClasses::dalvik_system_DexPathList__Element);
Mathieu Chartier0795f232016-09-27 18:43:30 -0700389 ObjPtr<mirror::Class> const dexfile_class = soa.Decode<mirror::Class>(
390 WellKnownClasses::dalvik_system_DexFile);
Jeff Haof0192c82016-03-28 20:39:50 -0700391
392 // Collect all the dex files.
393 auto GetDexFilesFn = [&] (const DexFile* cp_dex_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700394 REQUIRES_SHARED(Locks::mutator_lock_) {
Jeff Haof0192c82016-03-28 20:39:50 -0700395 if (cp_dex_file != nullptr && cp_dex_file->NumClassDefs() > 0) {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800396 dex_files->push_back(cp_dex_file);
Jeff Haof0192c82016-03-28 20:39:50 -0700397 }
398 return true; // Continue looking.
399 };
400
401 for (int32_t i = 0; i < dex_elements->GetLength(); ++i) {
402 mirror::Object* element = dex_elements->GetWithoutChecks(i);
403 if (element == nullptr) {
404 continue;
405 }
406
407 // We support this being dalvik.system.DexPathList$Element and dalvik.system.DexFile.
408
Mathieu Chartier3398c782016-09-30 10:27:43 -0700409 ObjPtr<mirror::Object> dex_file;
Mathieu Chartier0795f232016-09-27 18:43:30 -0700410 if (element_class == element->GetClass()) {
Jeff Haof0192c82016-03-28 20:39:50 -0700411 dex_file = dex_file_field->GetObject(element);
Mathieu Chartier0795f232016-09-27 18:43:30 -0700412 } else if (dexfile_class == element->GetClass()) {
Jeff Haof0192c82016-03-28 20:39:50 -0700413 dex_file = element;
414 } else {
David Sehr709b0702016-10-13 09:12:37 -0700415 LOG(WARNING) << "Unsupported element in dex_elements: "
416 << mirror::Class::PrettyClass(element->GetClass());
Jeff Haof0192c82016-03-28 20:39:50 -0700417 continue;
418 }
419
420 IterateOverJavaDexFile(dex_file, cookie_field, GetDexFilesFn);
421 }
422}
423
Vladimir Marko5c657fe2016-11-03 15:12:29 +0000424static bool AreSharedLibrariesOk(const std::string& shared_libraries,
Jeff Hao8ec0a202017-03-07 21:56:31 -0800425 std::vector<const DexFile*>& dex_files) {
426 // If no shared libraries, we expect no dex files.
Jeff Haof0192c82016-03-28 20:39:50 -0700427 if (shared_libraries.empty()) {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800428 return dex_files.empty();
Jeff Haof0192c82016-03-28 20:39:50 -0700429 }
Jeff Hao8ec0a202017-03-07 21:56:31 -0800430 // If we find the special shared library, skip the shared libraries check.
431 if (shared_libraries.compare(OatFile::kSpecialSharedLibrary) == 0) {
432 return true;
433 }
434 // Shared libraries is a series of dex file paths and their checksums, each separated by '*'.
435 std::vector<std::string> shared_libraries_split;
436 Split(shared_libraries, '*', &shared_libraries_split);
437
438 // Sanity check size of dex files and split shared libraries. Should be 2x as many entries in
439 // the split shared libraries since it contains pairs of filename/checksum.
440 if (dex_files.size() * 2 != shared_libraries_split.size()) {
441 return false;
442 }
443
Jeff Hao16d48432017-04-05 17:05:46 -0700444 // Check that the loaded dex files have the same order and checksums as the shared libraries.
Jeff Hao8ec0a202017-03-07 21:56:31 -0800445 for (size_t i = 0; i < dex_files.size(); ++i) {
Jeff Hao16d48432017-04-05 17:05:46 -0700446 std::string absolute_library_path =
447 OatFile::ResolveRelativeEncodedDexLocation(dex_files[i]->GetLocation().c_str(),
448 shared_libraries_split[i * 2]);
449 if (dex_files[i]->GetLocation() != absolute_library_path) {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800450 return false;
451 }
452 char* end;
453 size_t shared_lib_checksum = strtoul(shared_libraries_split[i * 2 + 1].c_str(), &end, 10);
454 uint32_t dex_checksum = dex_files[i]->GetLocationChecksum();
455 if (*end != '\0' || dex_checksum != shared_lib_checksum) {
456 return false;
457 }
458 }
459
460 return true;
461}
462
463static bool CollisionCheck(std::vector<const DexFile*>& dex_files_loaded,
464 std::vector<const DexFile*>& dex_files_unloaded,
465 std::string* error_msg /*out*/) {
466 // Generate type index information for each dex file.
467 std::vector<TypeIndexInfo> loaded_types;
468 for (const DexFile* dex_file : dex_files_loaded) {
469 loaded_types.push_back(TypeIndexInfo(dex_file));
470 }
471 std::vector<TypeIndexInfo> unloaded_types;
472 for (const DexFile* dex_file : dex_files_unloaded) {
473 unloaded_types.push_back(TypeIndexInfo(dex_file));
474 }
475
476 // Populate the queue of dex file and class pairs with the loaded and unloaded dex files.
477 std::priority_queue<DexFileAndClassPair> queue;
478 for (size_t i = 0; i < dex_files_loaded.size(); ++i) {
479 if (loaded_types[i].GetIterator() != loaded_types[i].GetIteratorEnd()) {
480 queue.emplace(dex_files_loaded[i], &loaded_types[i], /*from_loaded_oat*/true);
481 }
482 }
483 for (size_t i = 0; i < dex_files_unloaded.size(); ++i) {
484 if (unloaded_types[i].GetIterator() != unloaded_types[i].GetIteratorEnd()) {
485 queue.emplace(dex_files_unloaded[i], &unloaded_types[i], /*from_loaded_oat*/false);
486 }
487 }
488
489 // Now drain the queue.
Jeff Hao0471ece2017-04-07 16:28:12 -0700490 bool has_duplicates = false;
491 error_msg->clear();
Jeff Hao8ec0a202017-03-07 21:56:31 -0800492 while (!queue.empty()) {
493 // Modifying the top element is only safe if we pop right after.
494 DexFileAndClassPair compare_pop(queue.top());
495 queue.pop();
496
497 // Compare against the following elements.
498 while (!queue.empty()) {
499 DexFileAndClassPair top(queue.top());
500 if (strcmp(compare_pop.GetCachedDescriptor(), top.GetCachedDescriptor()) == 0) {
501 // Same descriptor. Check whether it's crossing old-oat-files to new-oat-files.
502 if (compare_pop.FromLoadedOat() != top.FromLoadedOat()) {
Jeff Hao0471ece2017-04-07 16:28:12 -0700503 error_msg->append(
504 StringPrintf("Found duplicated class when checking oat files: '%s' in %s and %s\n",
Jeff Hao8ec0a202017-03-07 21:56:31 -0800505 compare_pop.GetCachedDescriptor(),
506 compare_pop.GetDexFile()->GetLocation().c_str(),
Jeff Hao0471ece2017-04-07 16:28:12 -0700507 top.GetDexFile()->GetLocation().c_str()));
508 if (!VLOG_IS_ON(oat)) {
509 return true;
510 }
511 has_duplicates = true;
Jeff Hao8ec0a202017-03-07 21:56:31 -0800512 }
513 queue.pop();
514 AddNext(top, queue);
515 } else {
516 // Something else. Done here.
517 break;
518 }
519 }
520 AddNext(compare_pop, queue);
521 }
522
Jeff Hao0471ece2017-04-07 16:28:12 -0700523 return has_duplicates;
Jeff Haof0192c82016-03-28 20:39:50 -0700524}
525
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700526// Check for class-def collisions in dex files.
527//
Jeff Haof0192c82016-03-28 20:39:50 -0700528// This first walks the class loader chain, getting all the dex files from the class loader. If
529// the class loader is null or one of the class loaders in the chain is unsupported, we collect
530// dex files from all open non-boot oat files to be safe.
531//
532// This first checks whether the shared libraries are in the expected order and the oat files
533// have the expected checksums. If so, we exit early. Otherwise, we do the collision check.
534//
535// The collision check works by maintaining a heap with one class from each dex file, sorted by the
536// class descriptor. Then a dex-file/class pair is continually removed from the heap and compared
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700537// against the following top element. If the descriptor is the same, it is now checked whether
538// the two elements agree on whether their dex file was from an already-loaded oat-file or the
539// new oat file. Any disagreement indicates a collision.
540bool OatFileManager::HasCollisions(const OatFile* oat_file,
Jeff Haof0192c82016-03-28 20:39:50 -0700541 jobject class_loader,
542 jobjectArray dex_elements,
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700543 std::string* error_msg /*out*/) const {
544 DCHECK(oat_file != nullptr);
545 DCHECK(error_msg != nullptr);
Jeff Haof0192c82016-03-28 20:39:50 -0700546
Jeff Hao8ec0a202017-03-07 21:56:31 -0800547 std::vector<const DexFile*> dex_files_loaded;
Jeff Haof0192c82016-03-28 20:39:50 -0700548
549 // Try to get dex files from the given class loader. If the class loader is null, or we do
Narayan Kamath5c525742017-04-28 10:19:29 +0100550 // not support one of the class loaders in the chain, we do nothing and assume the collision
551 // check has succeeded.
Jeff Haof0192c82016-03-28 20:39:50 -0700552 bool class_loader_ok = false;
553 {
554 ScopedObjectAccess soa(Thread::Current());
555 StackHandleScope<2> hs(Thread::Current());
556 Handle<mirror::ClassLoader> h_class_loader =
Mathieu Chartier0795f232016-09-27 18:43:30 -0700557 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader));
Jeff Haof0192c82016-03-28 20:39:50 -0700558 Handle<mirror::ObjectArray<mirror::Object>> h_dex_elements =
Mathieu Chartier0795f232016-09-27 18:43:30 -0700559 hs.NewHandle(soa.Decode<mirror::ObjectArray<mirror::Object>>(dex_elements));
Andreas Gampefa4333d2017-02-14 11:10:34 -0800560 if (h_class_loader != nullptr &&
Jeff Hao8ec0a202017-03-07 21:56:31 -0800561 GetDexFilesFromClassLoader(soa, h_class_loader.Get(), &dex_files_loaded)) {
Jeff Haof0192c82016-03-28 20:39:50 -0700562 class_loader_ok = true;
563
564 // In this case, also take into account the dex_elements array, if given. We don't need to
565 // read it otherwise, as we'll compare against all open oat files anyways.
Jeff Hao8ec0a202017-03-07 21:56:31 -0800566 GetDexFilesFromDexElementsArray(soa, h_dex_elements, &dex_files_loaded);
Andreas Gampefa4333d2017-02-14 11:10:34 -0800567 } else if (h_class_loader != nullptr) {
Jeff Haof0192c82016-03-28 20:39:50 -0700568 VLOG(class_linker) << "Something unsupported with "
David Sehr709b0702016-10-13 09:12:37 -0700569 << mirror::Class::PrettyClass(h_class_loader->GetClass());
Narayan Kamath5c525742017-04-28 10:19:29 +0100570
571 // This is a class loader we don't recognize. Our earlier strategy would
572 // be to perform a global duplicate class check (with all loaded oat files)
573 // but that seems overly conservative - we have no way of knowing that
574 // those files are present in the same loader hierarchy. Among other
575 // things, it hurt GMS core and its filtering class loader.
Jeff Haof0192c82016-03-28 20:39:50 -0700576 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700577 }
578
Narayan Kamath5c525742017-04-28 10:19:29 +0100579 // Exit if we find a class loader we don't recognize. Proceed to check shared
580 // libraries and do a full class loader check otherwise.
Jeff Haof0192c82016-03-28 20:39:50 -0700581 if (!class_loader_ok) {
Narayan Kamath5c525742017-04-28 10:19:29 +0100582 LOG(WARNING) << "Skipping duplicate class check due to unrecognized classloader";
583 return false;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700584 }
585
Jeff Haof0192c82016-03-28 20:39:50 -0700586 // Exit if shared libraries are ok. Do a full duplicate classes check otherwise.
587 const std::string
588 shared_libraries(oat_file->GetOatHeader().GetStoreValueByKey(OatHeader::kClassPathKey));
Jeff Hao8ec0a202017-03-07 21:56:31 -0800589 if (AreSharedLibrariesOk(shared_libraries, dex_files_loaded)) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700590 return false;
591 }
592
Narayan Kamath5c525742017-04-28 10:19:29 +0100593 // Vector that holds the newly opened dex files live, this is done to prevent leaks.
594 std::vector<std::unique_ptr<const DexFile>> opened_dex_files;
595
Andreas Gampe1fdbe1b2016-06-10 08:36:20 -0700596 ScopedTrace st("Collision check");
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700597 // Add dex files from the oat file to check.
Jeff Hao8ec0a202017-03-07 21:56:31 -0800598 std::vector<const DexFile*> dex_files_unloaded;
599 AddDexFilesFromOat(oat_file, &dex_files_unloaded, &opened_dex_files);
600 return CollisionCheck(dex_files_loaded, dex_files_unloaded, error_msg);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700601}
602
603std::vector<std::unique_ptr<const DexFile>> OatFileManager::OpenDexFilesFromOat(
604 const char* dex_location,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800605 jobject class_loader,
606 jobjectArray dex_elements,
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700607 const OatFile** out_oat_file,
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700608 std::vector<std::string>* error_msgs) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800609 ScopedTrace trace(__FUNCTION__);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700610 CHECK(dex_location != nullptr);
611 CHECK(error_msgs != nullptr);
612
613 // Verify we aren't holding the mutator lock, which could starve GC if we
614 // have to generate or relocate an oat file.
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800615 Thread* const self = Thread::Current();
616 Locks::mutator_lock_->AssertNotHeld(self);
617 Runtime* const runtime = Runtime::Current();
Calin Juravleb077e152016-02-18 18:47:37 +0000618
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700619 OatFileAssistant oat_file_assistant(dex_location,
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700620 kRuntimeISA,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800621 !runtime->IsAotCompiler());
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700622
623 // Lock the target oat location to avoid races generating and loading the
624 // oat file.
625 std::string error_msg;
626 if (!oat_file_assistant.Lock(/*out*/&error_msg)) {
627 // Don't worry too much if this fails. If it does fail, it's unlikely we
628 // can generate an oat file anyway.
629 VLOG(class_linker) << "OatFileAssistant::Lock: " << error_msg;
630 }
631
632 const OatFile* source_oat_file = nullptr;
633
Richard Uhler01be6812016-05-17 10:34:52 -0700634 if (!oat_file_assistant.IsUpToDate()) {
635 // Update the oat file on disk if we can, based on the --compiler-filter
636 // option derived from the current runtime options.
637 // This may fail, but that's okay. Best effort is all that matters here.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700638 switch (oat_file_assistant.MakeUpToDate(/*profile_changed*/false, /*out*/ &error_msg)) {
Richard Uhler01be6812016-05-17 10:34:52 -0700639 case OatFileAssistant::kUpdateFailed:
640 LOG(WARNING) << error_msg;
641 break;
Richard Uhler1e860612016-03-30 12:17:55 -0700642
Richard Uhler01be6812016-05-17 10:34:52 -0700643 case OatFileAssistant::kUpdateNotAttempted:
644 // Avoid spamming the logs if we decided not to attempt making the oat
645 // file up to date.
646 VLOG(oat) << error_msg;
647 break;
Richard Uhler1e860612016-03-30 12:17:55 -0700648
Richard Uhler01be6812016-05-17 10:34:52 -0700649 case OatFileAssistant::kUpdateSucceeded:
650 // Nothing to do.
651 break;
652 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700653 }
654
655 // Get the oat file on disk.
656 std::unique_ptr<const OatFile> oat_file(oat_file_assistant.GetBestOatFile().release());
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800657
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700658 if (oat_file != nullptr) {
659 // Take the file only if it has no collisions, or we must take it because of preopting.
Jeff Haof0192c82016-03-28 20:39:50 -0700660 bool accept_oat_file =
661 !HasCollisions(oat_file.get(), class_loader, dex_elements, /*out*/ &error_msg);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700662 if (!accept_oat_file) {
663 // Failed the collision check. Print warning.
664 if (Runtime::Current()->IsDexFileFallbackEnabled()) {
Narayan Kamath5c525742017-04-28 10:19:29 +0100665 if (!oat_file_assistant.HasOriginalDexFiles()) {
666 // We need to fallback but don't have original dex files. We have to
667 // fallback to opening the existing oat file. This is potentially
668 // unsafe so we warn about it.
669 accept_oat_file = true;
670
671 LOG(WARNING) << "Dex location " << dex_location << " does not seem to include dex file. "
672 << "Allow oat file use. This is potentially dangerous.";
673 } else {
674 // We have to fallback and found original dex files - extract them from an APK.
675 // Also warn about this operation because it's potentially wasteful.
676 LOG(WARNING) << "Found duplicate classes, falling back to extracting from APK : "
677 << dex_location;
678 LOG(WARNING) << "NOTE: This wastes RAM and hurts startup performance.";
679 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700680 } else {
Narayan Kamath5c525742017-04-28 10:19:29 +0100681 // TODO: We should remove this. The fact that we're here implies -Xno-dex-file-fallback
682 // was set, which means that we should never fallback. If we don't have original dex
683 // files, we should just fail resolution as the flag intended.
684 if (!oat_file_assistant.HasOriginalDexFiles()) {
685 accept_oat_file = true;
686 }
687
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700688 LOG(WARNING) << "Found duplicate classes, dex-file-fallback disabled, will be failing to "
689 " load classes for " << dex_location;
690 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700691
Narayan Kamath5c525742017-04-28 10:19:29 +0100692 LOG(WARNING) << error_msg;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700693 }
694
695 if (accept_oat_file) {
696 VLOG(class_linker) << "Registering " << oat_file->GetLocation();
697 source_oat_file = RegisterOatFile(std::move(oat_file));
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700698 *out_oat_file = source_oat_file;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700699 }
700 }
701
702 std::vector<std::unique_ptr<const DexFile>> dex_files;
703
704 // Load the dex files from the oat file.
705 if (source_oat_file != nullptr) {
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800706 bool added_image_space = false;
707 if (source_oat_file->IsExecutable()) {
Andreas Gampea463b6a2016-08-12 21:53:32 -0700708 std::unique_ptr<gc::space::ImageSpace> image_space =
709 kEnableAppImage ? oat_file_assistant.OpenImageSpace(source_oat_file) : nullptr;
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800710 if (image_space != nullptr) {
711 ScopedObjectAccess soa(self);
712 StackHandleScope<1> hs(self);
713 Handle<mirror::ClassLoader> h_loader(
Mathieu Chartier0795f232016-09-27 18:43:30 -0700714 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800715 // Can not load app image without class loader.
Andreas Gampefa4333d2017-02-14 11:10:34 -0800716 if (h_loader != nullptr) {
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800717 std::string temp_error_msg;
718 // Add image space has a race condition since other threads could be reading from the
719 // spaces array.
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800720 {
721 ScopedThreadSuspension sts(self, kSuspended);
Mathieu Chartier61d2b2d2016-02-04 13:31:46 -0800722 gc::ScopedGCCriticalSection gcs(self,
723 gc::kGcCauseAddRemoveAppImageSpace,
724 gc::kCollectorTypeAddRemoveAppImageSpace);
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800725 ScopedSuspendAll ssa("Add image space");
726 runtime->GetHeap()->AddSpace(image_space.get());
727 }
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800728 {
729 ScopedTrace trace2(StringPrintf("Adding image space for location %s", dex_location));
730 added_image_space = runtime->GetClassLinker()->AddImageSpace(image_space.get(),
731 h_loader,
732 dex_elements,
733 dex_location,
734 /*out*/&dex_files,
735 /*out*/&temp_error_msg);
736 }
Mathieu Chartiera6e81ed2016-02-25 13:52:10 -0800737 if (added_image_space) {
Mathieu Chartierbd064ea2016-02-11 16:27:18 -0800738 // Successfully added image space to heap, release the map so that it does not get
739 // freed.
740 image_space.release();
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -0700741
742 // Register for tracking.
743 for (const auto& dex_file : dex_files) {
744 dex::tracking::RegisterDexFile(dex_file.get());
745 }
Mathieu Chartierbd064ea2016-02-11 16:27:18 -0800746 } else {
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800747 LOG(INFO) << "Failed to add image file " << temp_error_msg;
748 dex_files.clear();
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800749 {
750 ScopedThreadSuspension sts(self, kSuspended);
Mathieu Chartier61d2b2d2016-02-04 13:31:46 -0800751 gc::ScopedGCCriticalSection gcs(self,
752 gc::kGcCauseAddRemoveAppImageSpace,
753 gc::kCollectorTypeAddRemoveAppImageSpace);
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800754 ScopedSuspendAll ssa("Remove image space");
755 runtime->GetHeap()->RemoveSpace(image_space.get());
756 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800757 // Non-fatal, don't update error_msg.
758 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800759 }
760 }
761 }
762 if (!added_image_space) {
763 DCHECK(dex_files.empty());
764 dex_files = oat_file_assistant.LoadDexFiles(*source_oat_file, dex_location);
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -0700765
766 // Register for tracking.
767 for (const auto& dex_file : dex_files) {
768 dex::tracking::RegisterDexFile(dex_file.get());
769 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800770 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700771 if (dex_files.empty()) {
772 error_msgs->push_back("Failed to open dex files from " + source_oat_file->GetLocation());
773 }
774 }
775
776 // Fall back to running out of the original dex file if we couldn't load any
777 // dex_files from the oat file.
778 if (dex_files.empty()) {
779 if (oat_file_assistant.HasOriginalDexFiles()) {
780 if (Runtime::Current()->IsDexFileFallbackEnabled()) {
Aart Bik37d6a3b2016-06-21 18:30:10 -0700781 static constexpr bool kVerifyChecksum = true;
782 if (!DexFile::Open(
783 dex_location, dex_location, kVerifyChecksum, /*out*/ &error_msg, &dex_files)) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700784 LOG(WARNING) << error_msg;
Alex Light3045b662016-04-20 14:26:34 -0700785 error_msgs->push_back("Failed to open dex files from " + std::string(dex_location)
786 + " because: " + error_msg);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700787 }
788 } else {
789 error_msgs->push_back("Fallback mode disabled, skipping dex files.");
790 }
791 } else {
792 error_msgs->push_back("No original dex files found for dex location "
793 + std::string(dex_location));
794 }
795 }
Calin Juravlec90bc922016-02-24 10:13:09 +0000796
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700797 return dex_files;
798}
799
Nicolas Geoffray04680f32016-03-17 11:56:54 +0000800void OatFileManager::DumpForSigQuit(std::ostream& os) {
801 ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
802 std::vector<const OatFile*> boot_oat_files = GetBootOatFiles();
803 for (const std::unique_ptr<const OatFile>& oat_file : oat_files_) {
804 if (ContainsElement(boot_oat_files, oat_file.get())) {
805 continue;
806 }
Andreas Gampe29d38e72016-03-23 15:31:51 +0000807 os << oat_file->GetLocation() << ": " << oat_file->GetCompilerFilter() << "\n";
Nicolas Geoffray04680f32016-03-17 11:56:54 +0000808 }
809}
810
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700811} // namespace art