blob: 6799918534c47aeef748b11dbbcd5aa2c56c81df [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"
Mathieu Chartier61d2b2d2016-02-04 13:31:46 -080032#include "gc/scoped_gc_critical_section.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070033#include "gc/space/image_space.h"
Mathieu Chartierfbc31082016-01-24 11:59:56 -080034#include "handle_scope-inl.h"
Andreas Gampe08883de2016-11-08 13:20:52 -080035#include "jni_internal.h"
Mathieu Chartierfbc31082016-01-24 11:59:56 -080036#include "mirror/class_loader.h"
Andreas Gampe90b936d2017-01-31 08:58:55 -080037#include "mirror/object-inl.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070038#include "oat_file_assistant.h"
Mathieu Chartier3398c782016-09-30 10:27:43 -070039#include "obj_ptr-inl.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070040#include "scoped_thread_state_change-inl.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070041#include "thread-inl.h"
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -080042#include "thread_list.h"
Andreas Gampe90b936d2017-01-31 08:58:55 -080043#include "well_known_classes.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070044
45namespace art {
46
Andreas Gampe46ee31b2016-12-14 10:11:49 -080047using android::base::StringPrintf;
48
Mathieu Chartierfbc31082016-01-24 11:59:56 -080049// If true, then we attempt to load the application image if it exists.
50static constexpr bool kEnableAppImage = true;
51
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070052const OatFile* OatFileManager::RegisterOatFile(std::unique_ptr<const OatFile> oat_file) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -070053 WriterMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070054 DCHECK(oat_file != nullptr);
55 if (kIsDebugBuild) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -070056 CHECK(oat_files_.find(oat_file) == oat_files_.end());
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070057 for (const std::unique_ptr<const OatFile>& existing : oat_files_) {
58 CHECK_NE(oat_file.get(), existing.get()) << oat_file->GetLocation();
59 // Check that we don't have an oat file with the same address. Copies of the same oat file
60 // should be loaded at different addresses.
61 CHECK_NE(oat_file->Begin(), existing->Begin()) << "Oat file already mapped at that location";
62 }
63 }
64 have_non_pic_oat_file_ = have_non_pic_oat_file_ || !oat_file->IsPic();
Mathieu Chartiere58991b2015-10-13 07:59:34 -070065 const OatFile* ret = oat_file.get();
66 oat_files_.insert(std::move(oat_file));
67 return ret;
68}
69
70void OatFileManager::UnRegisterAndDeleteOatFile(const OatFile* oat_file) {
71 WriterMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
72 DCHECK(oat_file != nullptr);
73 std::unique_ptr<const OatFile> compare(oat_file);
74 auto it = oat_files_.find(compare);
75 CHECK(it != oat_files_.end());
76 oat_files_.erase(it);
77 compare.release();
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070078}
79
Calin Juravle0b791272016-04-18 16:38:27 +010080const OatFile* OatFileManager::FindOpenedOatFileFromDexLocation(
81 const std::string& dex_base_location) const {
82 ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
83 for (const std::unique_ptr<const OatFile>& oat_file : oat_files_) {
84 const std::vector<const OatDexFile*>& oat_dex_files = oat_file->GetOatDexFiles();
85 for (const OatDexFile* oat_dex_file : oat_dex_files) {
86 if (DexFile::GetBaseLocation(oat_dex_file->GetDexFileLocation()) == dex_base_location) {
87 return oat_file.get();
88 }
89 }
90 }
91 return nullptr;
92}
93
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070094const OatFile* OatFileManager::FindOpenedOatFileFromOatLocation(const std::string& oat_location)
95 const {
96 ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
Mathieu Chartiere58991b2015-10-13 07:59:34 -070097 return FindOpenedOatFileFromOatLocationLocked(oat_location);
98}
99
100const OatFile* OatFileManager::FindOpenedOatFileFromOatLocationLocked(
101 const std::string& oat_location) const {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700102 for (const std::unique_ptr<const OatFile>& oat_file : oat_files_) {
103 if (oat_file->GetLocation() == oat_location) {
104 return oat_file.get();
105 }
106 }
107 return nullptr;
108}
109
Jeff Haodcdc85b2015-12-04 14:06:18 -0800110std::vector<const OatFile*> OatFileManager::GetBootOatFiles() const {
111 std::vector<const OatFile*> oat_files;
112 std::vector<gc::space::ImageSpace*> image_spaces =
113 Runtime::Current()->GetHeap()->GetBootImageSpaces();
114 for (gc::space::ImageSpace* image_space : image_spaces) {
115 oat_files.push_back(image_space->GetOatFile());
116 }
117 return oat_files;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700118}
119
120const OatFile* OatFileManager::GetPrimaryOatFile() const {
121 ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
Jeff Haodcdc85b2015-12-04 14:06:18 -0800122 std::vector<const OatFile*> boot_oat_files = GetBootOatFiles();
123 if (!boot_oat_files.empty()) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700124 for (const std::unique_ptr<const OatFile>& oat_file : oat_files_) {
Jeff Haodcdc85b2015-12-04 14:06:18 -0800125 if (std::find(boot_oat_files.begin(), boot_oat_files.end(), oat_file.get()) ==
126 boot_oat_files.end()) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700127 return oat_file.get();
128 }
129 }
130 }
131 return nullptr;
132}
133
134OatFileManager::~OatFileManager() {
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700135 // Explicitly clear oat_files_ since the OatFile destructor calls back into OatFileManager for
136 // UnRegisterOatFileLocation.
137 oat_files_.clear();
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700138}
139
Jeff Haodcdc85b2015-12-04 14:06:18 -0800140std::vector<const OatFile*> OatFileManager::RegisterImageOatFiles(
141 std::vector<gc::space::ImageSpace*> spaces) {
142 std::vector<const OatFile*> oat_files;
143 for (gc::space::ImageSpace* space : spaces) {
144 oat_files.push_back(RegisterOatFile(space->ReleaseOatFile()));
145 }
146 return oat_files;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700147}
148
Jeff Hao8ec0a202017-03-07 21:56:31 -0800149class TypeIndexInfo {
150 public:
151 explicit TypeIndexInfo(const DexFile* dex_file)
152 : type_indexes_(GenerateTypeIndexes(dex_file)),
153 iter_(type_indexes_.Indexes().begin()),
154 end_(type_indexes_.Indexes().end()) { }
155
156 BitVector& GetTypeIndexes() {
157 return type_indexes_;
158 }
159 BitVector::IndexIterator& GetIterator() {
160 return iter_;
161 }
162 BitVector::IndexIterator& GetIteratorEnd() {
163 return end_;
164 }
165 void AdvanceIterator() {
166 iter_++;
167 }
168
169 private:
170 static BitVector GenerateTypeIndexes(const DexFile* dex_file) {
171 BitVector type_indexes(/*start_bits*/0, /*expandable*/true, Allocator::GetMallocAllocator());
172 for (uint16_t i = 0; i < dex_file->NumClassDefs(); ++i) {
173 const DexFile::ClassDef& class_def = dex_file->GetClassDef(i);
174 uint16_t type_idx = class_def.class_idx_.index_;
175 type_indexes.SetBit(type_idx);
176 }
177 return type_indexes;
178 }
179
180 // BitVector with bits set for the type indexes of all classes in the input dex file.
181 BitVector type_indexes_;
182 BitVector::IndexIterator iter_;
183 BitVector::IndexIterator end_;
184};
185
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700186class DexFileAndClassPair : ValueObject {
187 public:
Jeff Hao8ec0a202017-03-07 21:56:31 -0800188 DexFileAndClassPair(const DexFile* dex_file, TypeIndexInfo* type_info, bool from_loaded_oat)
189 : type_info_(type_info),
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700190 dex_file_(dex_file),
Jeff Hao8ec0a202017-03-07 21:56:31 -0800191 cached_descriptor_(dex_file_->StringByTypeIdx(dex::TypeIndex(*type_info->GetIterator()))),
192 from_loaded_oat_(from_loaded_oat) {
193 type_info_->AdvanceIterator();
194 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700195
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700196 DexFileAndClassPair(const DexFileAndClassPair& rhs) = default;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700197
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700198 DexFileAndClassPair& operator=(const DexFileAndClassPair& rhs) = default;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700199
200 const char* GetCachedDescriptor() const {
201 return cached_descriptor_;
202 }
203
204 bool operator<(const DexFileAndClassPair& rhs) const {
205 const int cmp = strcmp(cached_descriptor_, rhs.cached_descriptor_);
206 if (cmp != 0) {
207 // Note that the order must be reversed. We want to iterate over the classes in dex files.
208 // They are sorted lexicographically. Thus, the priority-queue must be a min-queue.
209 return cmp > 0;
210 }
211 return dex_file_ < rhs.dex_file_;
212 }
213
214 bool DexFileHasMoreClasses() const {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800215 return type_info_->GetIterator() != type_info_->GetIteratorEnd();
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700216 }
217
218 void Next() {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800219 cached_descriptor_ = dex_file_->StringByTypeIdx(dex::TypeIndex(*type_info_->GetIterator()));
220 type_info_->AdvanceIterator();
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700221 }
222
223 bool FromLoadedOat() const {
224 return from_loaded_oat_;
225 }
226
227 const DexFile* GetDexFile() const {
Jeff Haof0192c82016-03-28 20:39:50 -0700228 return dex_file_;
229 }
230
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700231 private:
Jeff Hao8ec0a202017-03-07 21:56:31 -0800232 TypeIndexInfo* type_info_;
Jeff Haof0192c82016-03-28 20:39:50 -0700233 const DexFile* dex_file_;
Jeff Hao8ec0a202017-03-07 21:56:31 -0800234 const char* cached_descriptor_;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700235 bool from_loaded_oat_; // We only need to compare mismatches between what we load now
236 // and what was loaded before. Any old duplicates must have been
237 // OK, and any new "internal" duplicates are as well (they must
238 // be from multidex, which resolves correctly).
239};
240
Jeff Hao8ec0a202017-03-07 21:56:31 -0800241static void AddDexFilesFromOat(
242 const OatFile* oat_file,
243 /*out*/std::vector<const DexFile*>* dex_files,
244 std::vector<std::unique_ptr<const DexFile>>* opened_dex_files) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700245 for (const OatDexFile* oat_dex_file : oat_file->GetOatDexFiles()) {
246 std::string error;
247 std::unique_ptr<const DexFile> dex_file = oat_dex_file->OpenDexFile(&error);
248 if (dex_file == nullptr) {
249 LOG(WARNING) << "Could not create dex file from oat file: " << error;
250 } else if (dex_file->NumClassDefs() > 0U) {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800251 dex_files->push_back(dex_file.get());
Mathieu Chartier14d7b3e2016-06-09 16:18:04 -0700252 opened_dex_files->push_back(std::move(dex_file));
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700253 }
254 }
255}
256
Jeff Hao8ec0a202017-03-07 21:56:31 -0800257static void AddNext(/*inout*/DexFileAndClassPair& original,
258 /*inout*/std::priority_queue<DexFileAndClassPair>& heap) {
259 if (original.DexFileHasMoreClasses()) {
260 original.Next();
261 heap.push(std::move(original));
Jeff Haof0192c82016-03-28 20:39:50 -0700262 }
263}
264
Andreas Gampeca620d72016-11-08 08:09:33 -0800265template <typename T>
Mathieu Chartier3398c782016-09-30 10:27:43 -0700266static void IterateOverJavaDexFile(ObjPtr<mirror::Object> dex_file,
Jeff Haof0192c82016-03-28 20:39:50 -0700267 ArtField* const cookie_field,
Andreas Gampeca620d72016-11-08 08:09:33 -0800268 const T& fn)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700269 REQUIRES_SHARED(Locks::mutator_lock_) {
Jeff Haof0192c82016-03-28 20:39:50 -0700270 if (dex_file != nullptr) {
271 mirror::LongArray* long_array = cookie_field->GetObject(dex_file)->AsLongArray();
272 if (long_array == nullptr) {
273 // This should never happen so log a warning.
274 LOG(WARNING) << "Null DexFile::mCookie";
275 return;
276 }
277 int32_t long_array_size = long_array->GetLength();
278 // Start from 1 to skip the oat file.
279 for (int32_t j = 1; j < long_array_size; ++j) {
280 const DexFile* cp_dex_file = reinterpret_cast<const DexFile*>(static_cast<uintptr_t>(
281 long_array->GetWithoutChecks(j)));
282 if (!fn(cp_dex_file)) {
283 return;
284 }
285 }
286 }
287}
288
Andreas Gampeca620d72016-11-08 08:09:33 -0800289template <typename T>
Jeff Haof0192c82016-03-28 20:39:50 -0700290static void IterateOverPathClassLoader(
Jeff Haof0192c82016-03-28 20:39:50 -0700291 Handle<mirror::ClassLoader> class_loader,
292 MutableHandle<mirror::ObjectArray<mirror::Object>> dex_elements,
Andreas Gampeca620d72016-11-08 08:09:33 -0800293 const T& fn) REQUIRES_SHARED(Locks::mutator_lock_) {
Jeff Haof0192c82016-03-28 20:39:50 -0700294 // Handle this step.
295 // Handle as if this is the child PathClassLoader.
296 // The class loader is a PathClassLoader which inherits from BaseDexClassLoader.
297 // We need to get the DexPathList and loop through it.
Andreas Gampe08883de2016-11-08 13:20:52 -0800298 ArtField* const cookie_field =
299 jni::DecodeArtField(WellKnownClasses::dalvik_system_DexFile_cookie);
Jeff Haof0192c82016-03-28 20:39:50 -0700300 ArtField* const dex_file_field =
Andreas Gampe08883de2016-11-08 13:20:52 -0800301 jni::DecodeArtField(WellKnownClasses::dalvik_system_DexPathList__Element_dexFile);
Mathieu Chartier3398c782016-09-30 10:27:43 -0700302 ObjPtr<mirror::Object> dex_path_list =
Andreas Gampe08883de2016-11-08 13:20:52 -0800303 jni::DecodeArtField(WellKnownClasses::dalvik_system_BaseDexClassLoader_pathList)->
304 GetObject(class_loader.Get());
Jeff Haof0192c82016-03-28 20:39:50 -0700305 if (dex_path_list != nullptr && dex_file_field != nullptr && cookie_field != nullptr) {
306 // DexPathList has an array dexElements of Elements[] which each contain a dex file.
Mathieu Chartier3398c782016-09-30 10:27:43 -0700307 ObjPtr<mirror::Object> dex_elements_obj =
Andreas Gampe08883de2016-11-08 13:20:52 -0800308 jni::DecodeArtField(WellKnownClasses::dalvik_system_DexPathList_dexElements)->
309 GetObject(dex_path_list);
Jeff Haof0192c82016-03-28 20:39:50 -0700310 // Loop through each dalvik.system.DexPathList$Element's dalvik.system.DexFile and look
311 // at the mCookie which is a DexFile vector.
312 if (dex_elements_obj != nullptr) {
313 dex_elements.Assign(dex_elements_obj->AsObjectArray<mirror::Object>());
314 for (int32_t i = 0; i < dex_elements->GetLength(); ++i) {
315 mirror::Object* element = dex_elements->GetWithoutChecks(i);
316 if (element == nullptr) {
317 // Should never happen, fall back to java code to throw a NPE.
318 break;
319 }
Mathieu Chartier3398c782016-09-30 10:27:43 -0700320 ObjPtr<mirror::Object> dex_file = dex_file_field->GetObject(element);
Jeff Haof0192c82016-03-28 20:39:50 -0700321 IterateOverJavaDexFile(dex_file, cookie_field, fn);
322 }
323 }
324 }
325}
326
327static bool GetDexFilesFromClassLoader(
328 ScopedObjectAccessAlreadyRunnable& soa,
329 mirror::ClassLoader* class_loader,
Jeff Hao8ec0a202017-03-07 21:56:31 -0800330 std::vector<const DexFile*>* dex_files)
331 REQUIRES_SHARED(Locks::mutator_lock_) {
Jeff Haof0192c82016-03-28 20:39:50 -0700332 if (ClassLinker::IsBootClassLoader(soa, class_loader)) {
333 // The boot class loader. We don't load any of these files, as we know we compiled against
334 // them correctly.
335 return true;
336 }
337
338 // Unsupported class-loader?
Mathieu Chartier0795f232016-09-27 18:43:30 -0700339 if (soa.Decode<mirror::Class>(WellKnownClasses::dalvik_system_PathClassLoader) !=
340 class_loader->GetClass()) {
David Sehr709b0702016-10-13 09:12:37 -0700341 VLOG(class_linker) << "Unsupported class-loader "
342 << mirror::Class::PrettyClass(class_loader->GetClass());
Jeff Haof0192c82016-03-28 20:39:50 -0700343 return false;
344 }
345
Jeff Hao8ec0a202017-03-07 21:56:31 -0800346 bool recursive_result = GetDexFilesFromClassLoader(soa, class_loader->GetParent(), dex_files);
Jeff Haof0192c82016-03-28 20:39:50 -0700347 if (!recursive_result) {
348 // Something wrong up the chain.
349 return false;
350 }
351
352 // Collect all the dex files.
353 auto GetDexFilesFn = [&] (const DexFile* cp_dex_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700354 REQUIRES_SHARED(Locks::mutator_lock_) {
Jeff Haof0192c82016-03-28 20:39:50 -0700355 if (cp_dex_file->NumClassDefs() > 0) {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800356 dex_files->push_back(cp_dex_file);
Jeff Haof0192c82016-03-28 20:39:50 -0700357 }
358 return true; // Continue looking.
359 };
360
361 // Handle for dex-cache-element.
362 StackHandleScope<3> hs(soa.Self());
363 MutableHandle<mirror::ObjectArray<mirror::Object>> dex_elements(
364 hs.NewHandle<mirror::ObjectArray<mirror::Object>>(nullptr));
365 Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(class_loader));
366
Andreas Gampe08883de2016-11-08 13:20:52 -0800367 IterateOverPathClassLoader(h_class_loader, dex_elements, GetDexFilesFn);
Jeff Haof0192c82016-03-28 20:39:50 -0700368
369 return true;
370}
371
372static void GetDexFilesFromDexElementsArray(
373 ScopedObjectAccessAlreadyRunnable& soa,
374 Handle<mirror::ObjectArray<mirror::Object>> dex_elements,
Jeff Hao8ec0a202017-03-07 21:56:31 -0800375 std::vector<const DexFile*>* dex_files)
376 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampefa4333d2017-02-14 11:10:34 -0800377 if (dex_elements == nullptr) {
Jeff Haof0192c82016-03-28 20:39:50 -0700378 // Nothing to do.
379 return;
380 }
381
Andreas Gampe08883de2016-11-08 13:20:52 -0800382 ArtField* const cookie_field =
383 jni::DecodeArtField(WellKnownClasses::dalvik_system_DexFile_cookie);
Jeff Haof0192c82016-03-28 20:39:50 -0700384 ArtField* const dex_file_field =
Andreas Gampe08883de2016-11-08 13:20:52 -0800385 jni::DecodeArtField(WellKnownClasses::dalvik_system_DexPathList__Element_dexFile);
Mathieu Chartier0795f232016-09-27 18:43:30 -0700386 ObjPtr<mirror::Class> const element_class = soa.Decode<mirror::Class>(
Jeff Haof0192c82016-03-28 20:39:50 -0700387 WellKnownClasses::dalvik_system_DexPathList__Element);
Mathieu Chartier0795f232016-09-27 18:43:30 -0700388 ObjPtr<mirror::Class> const dexfile_class = soa.Decode<mirror::Class>(
389 WellKnownClasses::dalvik_system_DexFile);
Jeff Haof0192c82016-03-28 20:39:50 -0700390
391 // Collect all the dex files.
392 auto GetDexFilesFn = [&] (const DexFile* cp_dex_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700393 REQUIRES_SHARED(Locks::mutator_lock_) {
Jeff Haof0192c82016-03-28 20:39:50 -0700394 if (cp_dex_file != nullptr && cp_dex_file->NumClassDefs() > 0) {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800395 dex_files->push_back(cp_dex_file);
Jeff Haof0192c82016-03-28 20:39:50 -0700396 }
397 return true; // Continue looking.
398 };
399
400 for (int32_t i = 0; i < dex_elements->GetLength(); ++i) {
401 mirror::Object* element = dex_elements->GetWithoutChecks(i);
402 if (element == nullptr) {
403 continue;
404 }
405
406 // We support this being dalvik.system.DexPathList$Element and dalvik.system.DexFile.
407
Mathieu Chartier3398c782016-09-30 10:27:43 -0700408 ObjPtr<mirror::Object> dex_file;
Mathieu Chartier0795f232016-09-27 18:43:30 -0700409 if (element_class == element->GetClass()) {
Jeff Haof0192c82016-03-28 20:39:50 -0700410 dex_file = dex_file_field->GetObject(element);
Mathieu Chartier0795f232016-09-27 18:43:30 -0700411 } else if (dexfile_class == element->GetClass()) {
Jeff Haof0192c82016-03-28 20:39:50 -0700412 dex_file = element;
413 } else {
David Sehr709b0702016-10-13 09:12:37 -0700414 LOG(WARNING) << "Unsupported element in dex_elements: "
415 << mirror::Class::PrettyClass(element->GetClass());
Jeff Haof0192c82016-03-28 20:39:50 -0700416 continue;
417 }
418
419 IterateOverJavaDexFile(dex_file, cookie_field, GetDexFilesFn);
420 }
421}
422
Vladimir Marko5c657fe2016-11-03 15:12:29 +0000423static bool AreSharedLibrariesOk(const std::string& shared_libraries,
Jeff Hao8ec0a202017-03-07 21:56:31 -0800424 std::vector<const DexFile*>& dex_files) {
425 // If no shared libraries, we expect no dex files.
Jeff Haof0192c82016-03-28 20:39:50 -0700426 if (shared_libraries.empty()) {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800427 return dex_files.empty();
Jeff Haof0192c82016-03-28 20:39:50 -0700428 }
Jeff Hao8ec0a202017-03-07 21:56:31 -0800429 // If we find the special shared library, skip the shared libraries check.
430 if (shared_libraries.compare(OatFile::kSpecialSharedLibrary) == 0) {
431 return true;
432 }
433 // Shared libraries is a series of dex file paths and their checksums, each separated by '*'.
434 std::vector<std::string> shared_libraries_split;
435 Split(shared_libraries, '*', &shared_libraries_split);
436
437 // Sanity check size of dex files and split shared libraries. Should be 2x as many entries in
438 // the split shared libraries since it contains pairs of filename/checksum.
439 if (dex_files.size() * 2 != shared_libraries_split.size()) {
440 return false;
441 }
442
Jeff Hao16d48432017-04-05 17:05:46 -0700443 // Check that the loaded dex files have the same order and checksums as the shared libraries.
Jeff Hao8ec0a202017-03-07 21:56:31 -0800444 for (size_t i = 0; i < dex_files.size(); ++i) {
Jeff Hao16d48432017-04-05 17:05:46 -0700445 std::string absolute_library_path =
446 OatFile::ResolveRelativeEncodedDexLocation(dex_files[i]->GetLocation().c_str(),
447 shared_libraries_split[i * 2]);
448 if (dex_files[i]->GetLocation() != absolute_library_path) {
Jeff Hao8ec0a202017-03-07 21:56:31 -0800449 return false;
450 }
451 char* end;
452 size_t shared_lib_checksum = strtoul(shared_libraries_split[i * 2 + 1].c_str(), &end, 10);
453 uint32_t dex_checksum = dex_files[i]->GetLocationChecksum();
454 if (*end != '\0' || dex_checksum != shared_lib_checksum) {
455 return false;
456 }
457 }
458
459 return true;
460}
461
462static bool CollisionCheck(std::vector<const DexFile*>& dex_files_loaded,
463 std::vector<const DexFile*>& dex_files_unloaded,
464 std::string* error_msg /*out*/) {
465 // Generate type index information for each dex file.
466 std::vector<TypeIndexInfo> loaded_types;
467 for (const DexFile* dex_file : dex_files_loaded) {
468 loaded_types.push_back(TypeIndexInfo(dex_file));
469 }
470 std::vector<TypeIndexInfo> unloaded_types;
471 for (const DexFile* dex_file : dex_files_unloaded) {
472 unloaded_types.push_back(TypeIndexInfo(dex_file));
473 }
474
475 // Populate the queue of dex file and class pairs with the loaded and unloaded dex files.
476 std::priority_queue<DexFileAndClassPair> queue;
477 for (size_t i = 0; i < dex_files_loaded.size(); ++i) {
478 if (loaded_types[i].GetIterator() != loaded_types[i].GetIteratorEnd()) {
479 queue.emplace(dex_files_loaded[i], &loaded_types[i], /*from_loaded_oat*/true);
480 }
481 }
482 for (size_t i = 0; i < dex_files_unloaded.size(); ++i) {
483 if (unloaded_types[i].GetIterator() != unloaded_types[i].GetIteratorEnd()) {
484 queue.emplace(dex_files_unloaded[i], &unloaded_types[i], /*from_loaded_oat*/false);
485 }
486 }
487
488 // Now drain the queue.
Jeff Hao0471ece2017-04-07 16:28:12 -0700489 bool has_duplicates = false;
490 error_msg->clear();
Jeff Hao8ec0a202017-03-07 21:56:31 -0800491 while (!queue.empty()) {
492 // Modifying the top element is only safe if we pop right after.
493 DexFileAndClassPair compare_pop(queue.top());
494 queue.pop();
495
496 // Compare against the following elements.
497 while (!queue.empty()) {
498 DexFileAndClassPair top(queue.top());
499 if (strcmp(compare_pop.GetCachedDescriptor(), top.GetCachedDescriptor()) == 0) {
500 // Same descriptor. Check whether it's crossing old-oat-files to new-oat-files.
501 if (compare_pop.FromLoadedOat() != top.FromLoadedOat()) {
Jeff Hao0471ece2017-04-07 16:28:12 -0700502 error_msg->append(
503 StringPrintf("Found duplicated class when checking oat files: '%s' in %s and %s\n",
Jeff Hao8ec0a202017-03-07 21:56:31 -0800504 compare_pop.GetCachedDescriptor(),
505 compare_pop.GetDexFile()->GetLocation().c_str(),
Jeff Hao0471ece2017-04-07 16:28:12 -0700506 top.GetDexFile()->GetLocation().c_str()));
507 if (!VLOG_IS_ON(oat)) {
508 return true;
509 }
510 has_duplicates = true;
Jeff Hao8ec0a202017-03-07 21:56:31 -0800511 }
512 queue.pop();
513 AddNext(top, queue);
514 } else {
515 // Something else. Done here.
516 break;
517 }
518 }
519 AddNext(compare_pop, queue);
520 }
521
Jeff Hao0471ece2017-04-07 16:28:12 -0700522 return has_duplicates;
Jeff Haof0192c82016-03-28 20:39:50 -0700523}
524
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700525// Check for class-def collisions in dex files.
526//
Jeff Haof0192c82016-03-28 20:39:50 -0700527// This first walks the class loader chain, getting all the dex files from the class loader. If
528// the class loader is null or one of the class loaders in the chain is unsupported, we collect
529// dex files from all open non-boot oat files to be safe.
530//
531// This first checks whether the shared libraries are in the expected order and the oat files
532// have the expected checksums. If so, we exit early. Otherwise, we do the collision check.
533//
534// The collision check works by maintaining a heap with one class from each dex file, sorted by the
535// class descriptor. Then a dex-file/class pair is continually removed from the heap and compared
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700536// against the following top element. If the descriptor is the same, it is now checked whether
537// the two elements agree on whether their dex file was from an already-loaded oat-file or the
538// new oat file. Any disagreement indicates a collision.
539bool OatFileManager::HasCollisions(const OatFile* oat_file,
Jeff Haof0192c82016-03-28 20:39:50 -0700540 jobject class_loader,
541 jobjectArray dex_elements,
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700542 std::string* error_msg /*out*/) const {
543 DCHECK(oat_file != nullptr);
544 DCHECK(error_msg != nullptr);
Jeff Haof0192c82016-03-28 20:39:50 -0700545
Jeff Hao8ec0a202017-03-07 21:56:31 -0800546 std::vector<const DexFile*> dex_files_loaded;
Jeff Haof0192c82016-03-28 20:39:50 -0700547
548 // Try to get dex files from the given class loader. If the class loader is null, or we do
549 // not support one of the class loaders in the chain, conservatively compare against all
550 // (non-boot) oat files.
551 bool class_loader_ok = false;
552 {
553 ScopedObjectAccess soa(Thread::Current());
554 StackHandleScope<2> hs(Thread::Current());
555 Handle<mirror::ClassLoader> h_class_loader =
Mathieu Chartier0795f232016-09-27 18:43:30 -0700556 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader));
Jeff Haof0192c82016-03-28 20:39:50 -0700557 Handle<mirror::ObjectArray<mirror::Object>> h_dex_elements =
Mathieu Chartier0795f232016-09-27 18:43:30 -0700558 hs.NewHandle(soa.Decode<mirror::ObjectArray<mirror::Object>>(dex_elements));
Andreas Gampefa4333d2017-02-14 11:10:34 -0800559 if (h_class_loader != nullptr &&
Jeff Hao8ec0a202017-03-07 21:56:31 -0800560 GetDexFilesFromClassLoader(soa, h_class_loader.Get(), &dex_files_loaded)) {
Jeff Haof0192c82016-03-28 20:39:50 -0700561 class_loader_ok = true;
562
563 // In this case, also take into account the dex_elements array, if given. We don't need to
564 // read it otherwise, as we'll compare against all open oat files anyways.
Jeff Hao8ec0a202017-03-07 21:56:31 -0800565 GetDexFilesFromDexElementsArray(soa, h_dex_elements, &dex_files_loaded);
Andreas Gampefa4333d2017-02-14 11:10:34 -0800566 } else if (h_class_loader != nullptr) {
Jeff Haof0192c82016-03-28 20:39:50 -0700567 VLOG(class_linker) << "Something unsupported with "
David Sehr709b0702016-10-13 09:12:37 -0700568 << mirror::Class::PrettyClass(h_class_loader->GetClass());
Jeff Haof0192c82016-03-28 20:39:50 -0700569 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700570 }
571
572 // Dex files are registered late - once a class is actually being loaded. We have to compare
573 // against the open oat files. Take the oat_file_manager_lock_ that protects oat_files_ accesses.
574 ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
575
Mathieu Chartier14d7b3e2016-06-09 16:18:04 -0700576 // Vector that holds the newly opened dex files live, this is done to prevent leaks.
577 std::vector<std::unique_ptr<const DexFile>> opened_dex_files;
578
Jeff Haof0192c82016-03-28 20:39:50 -0700579 if (!class_loader_ok) {
580 // Add dex files from already loaded oat files, but skip boot.
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700581
Jeff Hao8ec0a202017-03-07 21:56:31 -0800582 // Clean up the dex files.
583 dex_files_loaded.clear();
Jeff Haof0192c82016-03-28 20:39:50 -0700584
Jeff Haof0192c82016-03-28 20:39:50 -0700585 std::vector<const OatFile*> boot_oat_files = GetBootOatFiles();
586 // The same OatFile can be loaded multiple times at different addresses. In this case, we don't
587 // need to check both against each other since they would have resolved the same way at compile
588 // time.
589 std::unordered_set<std::string> unique_locations;
590 for (const std::unique_ptr<const OatFile>& loaded_oat_file : oat_files_) {
591 DCHECK_NE(loaded_oat_file.get(), oat_file);
592 const std::string& location = loaded_oat_file->GetLocation();
593 if (std::find(boot_oat_files.begin(), boot_oat_files.end(), loaded_oat_file.get()) ==
594 boot_oat_files.end() && location != oat_file->GetLocation() &&
595 unique_locations.find(location) == unique_locations.end()) {
596 unique_locations.insert(location);
Jeff Hao8ec0a202017-03-07 21:56:31 -0800597 AddDexFilesFromOat(loaded_oat_file.get(), &dex_files_loaded, &opened_dex_files);
Jeff Haof0192c82016-03-28 20:39:50 -0700598 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700599 }
600 }
601
Jeff Haof0192c82016-03-28 20:39:50 -0700602 // Exit if shared libraries are ok. Do a full duplicate classes check otherwise.
603 const std::string
604 shared_libraries(oat_file->GetOatHeader().GetStoreValueByKey(OatHeader::kClassPathKey));
Jeff Hao8ec0a202017-03-07 21:56:31 -0800605 if (AreSharedLibrariesOk(shared_libraries, dex_files_loaded)) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700606 return false;
607 }
608
Andreas Gampe1fdbe1b2016-06-10 08:36:20 -0700609 ScopedTrace st("Collision check");
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700610 // Add dex files from the oat file to check.
Jeff Hao8ec0a202017-03-07 21:56:31 -0800611 std::vector<const DexFile*> dex_files_unloaded;
612 AddDexFilesFromOat(oat_file, &dex_files_unloaded, &opened_dex_files);
613 return CollisionCheck(dex_files_loaded, dex_files_unloaded, error_msg);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700614}
615
616std::vector<std::unique_ptr<const DexFile>> OatFileManager::OpenDexFilesFromOat(
617 const char* dex_location,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800618 jobject class_loader,
619 jobjectArray dex_elements,
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700620 const OatFile** out_oat_file,
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700621 std::vector<std::string>* error_msgs) {
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800622 ScopedTrace trace(__FUNCTION__);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700623 CHECK(dex_location != nullptr);
624 CHECK(error_msgs != nullptr);
625
626 // Verify we aren't holding the mutator lock, which could starve GC if we
627 // have to generate or relocate an oat file.
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800628 Thread* const self = Thread::Current();
629 Locks::mutator_lock_->AssertNotHeld(self);
630 Runtime* const runtime = Runtime::Current();
Calin Juravleb077e152016-02-18 18:47:37 +0000631
Calin Juravle1f7079b2017-04-18 21:25:37 -0700632 // TODO(calin): remove the explicit oat_location for OatFileAssistant
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700633 OatFileAssistant oat_file_assistant(dex_location,
Calin Juravle1f7079b2017-04-18 21:25:37 -0700634 /*oat_location*/ nullptr,
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700635 kRuntimeISA,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800636 !runtime->IsAotCompiler());
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700637
638 // Lock the target oat location to avoid races generating and loading the
639 // oat file.
640 std::string error_msg;
641 if (!oat_file_assistant.Lock(/*out*/&error_msg)) {
642 // Don't worry too much if this fails. If it does fail, it's unlikely we
643 // can generate an oat file anyway.
644 VLOG(class_linker) << "OatFileAssistant::Lock: " << error_msg;
645 }
646
647 const OatFile* source_oat_file = nullptr;
648
Richard Uhler01be6812016-05-17 10:34:52 -0700649 if (!oat_file_assistant.IsUpToDate()) {
650 // Update the oat file on disk if we can, based on the --compiler-filter
651 // option derived from the current runtime options.
652 // This may fail, but that's okay. Best effort is all that matters here.
Richard Uhlerd1472a22016-04-15 15:18:56 -0700653 switch (oat_file_assistant.MakeUpToDate(/*profile_changed*/false, /*out*/ &error_msg)) {
Richard Uhler01be6812016-05-17 10:34:52 -0700654 case OatFileAssistant::kUpdateFailed:
655 LOG(WARNING) << error_msg;
656 break;
Richard Uhler1e860612016-03-30 12:17:55 -0700657
Richard Uhler01be6812016-05-17 10:34:52 -0700658 case OatFileAssistant::kUpdateNotAttempted:
659 // Avoid spamming the logs if we decided not to attempt making the oat
660 // file up to date.
661 VLOG(oat) << error_msg;
662 break;
Richard Uhler1e860612016-03-30 12:17:55 -0700663
Richard Uhler01be6812016-05-17 10:34:52 -0700664 case OatFileAssistant::kUpdateSucceeded:
665 // Nothing to do.
666 break;
667 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700668 }
669
670 // Get the oat file on disk.
671 std::unique_ptr<const OatFile> oat_file(oat_file_assistant.GetBestOatFile().release());
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800672
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700673 if (oat_file != nullptr) {
674 // Take the file only if it has no collisions, or we must take it because of preopting.
Jeff Haof0192c82016-03-28 20:39:50 -0700675 bool accept_oat_file =
676 !HasCollisions(oat_file.get(), class_loader, dex_elements, /*out*/ &error_msg);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700677 if (!accept_oat_file) {
678 // Failed the collision check. Print warning.
679 if (Runtime::Current()->IsDexFileFallbackEnabled()) {
680 LOG(WARNING) << "Found duplicate classes, falling back to interpreter mode for "
681 << dex_location;
682 } else {
683 LOG(WARNING) << "Found duplicate classes, dex-file-fallback disabled, will be failing to "
684 " load classes for " << dex_location;
685 }
686 LOG(WARNING) << error_msg;
687
688 // However, if the app was part of /system and preopted, there is no original dex file
689 // available. In that case grudgingly accept the oat file.
Richard Uhler76f5cb62016-04-04 13:30:16 -0700690 if (!oat_file_assistant.HasOriginalDexFiles()) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700691 accept_oat_file = true;
692 LOG(WARNING) << "Dex location " << dex_location << " does not seem to include dex file. "
693 << "Allow oat file use. This is potentially dangerous.";
694 }
695 }
696
697 if (accept_oat_file) {
698 VLOG(class_linker) << "Registering " << oat_file->GetLocation();
699 source_oat_file = RegisterOatFile(std::move(oat_file));
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700700 *out_oat_file = source_oat_file;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700701 }
702 }
703
704 std::vector<std::unique_ptr<const DexFile>> dex_files;
705
706 // Load the dex files from the oat file.
707 if (source_oat_file != nullptr) {
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800708 bool added_image_space = false;
709 if (source_oat_file->IsExecutable()) {
Andreas Gampea463b6a2016-08-12 21:53:32 -0700710 std::unique_ptr<gc::space::ImageSpace> image_space =
711 kEnableAppImage ? oat_file_assistant.OpenImageSpace(source_oat_file) : nullptr;
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800712 if (image_space != nullptr) {
713 ScopedObjectAccess soa(self);
714 StackHandleScope<1> hs(self);
715 Handle<mirror::ClassLoader> h_loader(
Mathieu Chartier0795f232016-09-27 18:43:30 -0700716 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800717 // Can not load app image without class loader.
Andreas Gampefa4333d2017-02-14 11:10:34 -0800718 if (h_loader != nullptr) {
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800719 std::string temp_error_msg;
720 // Add image space has a race condition since other threads could be reading from the
721 // spaces array.
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800722 {
723 ScopedThreadSuspension sts(self, kSuspended);
Mathieu Chartier61d2b2d2016-02-04 13:31:46 -0800724 gc::ScopedGCCriticalSection gcs(self,
725 gc::kGcCauseAddRemoveAppImageSpace,
726 gc::kCollectorTypeAddRemoveAppImageSpace);
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800727 ScopedSuspendAll ssa("Add image space");
728 runtime->GetHeap()->AddSpace(image_space.get());
729 }
Mathieu Chartier32ce2ad2016-03-04 14:58:03 -0800730 {
731 ScopedTrace trace2(StringPrintf("Adding image space for location %s", dex_location));
732 added_image_space = runtime->GetClassLinker()->AddImageSpace(image_space.get(),
733 h_loader,
734 dex_elements,
735 dex_location,
736 /*out*/&dex_files,
737 /*out*/&temp_error_msg);
738 }
Mathieu Chartiera6e81ed2016-02-25 13:52:10 -0800739 if (added_image_space) {
Mathieu Chartierbd064ea2016-02-11 16:27:18 -0800740 // Successfully added image space to heap, release the map so that it does not get
741 // freed.
742 image_space.release();
743 } else {
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800744 LOG(INFO) << "Failed to add image file " << temp_error_msg;
745 dex_files.clear();
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800746 {
747 ScopedThreadSuspension sts(self, kSuspended);
Mathieu Chartier61d2b2d2016-02-04 13:31:46 -0800748 gc::ScopedGCCriticalSection gcs(self,
749 gc::kGcCauseAddRemoveAppImageSpace,
750 gc::kCollectorTypeAddRemoveAppImageSpace);
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800751 ScopedSuspendAll ssa("Remove image space");
752 runtime->GetHeap()->RemoveSpace(image_space.get());
753 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800754 // Non-fatal, don't update error_msg.
755 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800756 }
757 }
758 }
759 if (!added_image_space) {
760 DCHECK(dex_files.empty());
761 dex_files = oat_file_assistant.LoadDexFiles(*source_oat_file, dex_location);
762 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700763 if (dex_files.empty()) {
764 error_msgs->push_back("Failed to open dex files from " + source_oat_file->GetLocation());
765 }
766 }
767
768 // Fall back to running out of the original dex file if we couldn't load any
769 // dex_files from the oat file.
770 if (dex_files.empty()) {
771 if (oat_file_assistant.HasOriginalDexFiles()) {
772 if (Runtime::Current()->IsDexFileFallbackEnabled()) {
Aart Bik37d6a3b2016-06-21 18:30:10 -0700773 static constexpr bool kVerifyChecksum = true;
774 if (!DexFile::Open(
775 dex_location, dex_location, kVerifyChecksum, /*out*/ &error_msg, &dex_files)) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700776 LOG(WARNING) << error_msg;
Alex Light3045b662016-04-20 14:26:34 -0700777 error_msgs->push_back("Failed to open dex files from " + std::string(dex_location)
778 + " because: " + error_msg);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700779 }
780 } else {
781 error_msgs->push_back("Fallback mode disabled, skipping dex files.");
782 }
783 } else {
784 error_msgs->push_back("No original dex files found for dex location "
785 + std::string(dex_location));
786 }
787 }
Calin Juravlec90bc922016-02-24 10:13:09 +0000788
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700789 return dex_files;
790}
791
Nicolas Geoffray04680f32016-03-17 11:56:54 +0000792void OatFileManager::DumpForSigQuit(std::ostream& os) {
793 ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
794 std::vector<const OatFile*> boot_oat_files = GetBootOatFiles();
795 for (const std::unique_ptr<const OatFile>& oat_file : oat_files_) {
796 if (ContainsElement(boot_oat_files, oat_file.get())) {
797 continue;
798 }
Andreas Gampe29d38e72016-03-23 15:31:51 +0000799 os << oat_file->GetLocation() << ": " << oat_file->GetCompilerFilter() << "\n";
Nicolas Geoffray04680f32016-03-17 11:56:54 +0000800 }
801}
802
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700803} // namespace art