blob: 0912ba06c1466735e621c8d59b0d4e41062f4f51 [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
Mathieu Chartiera6e81ed2016-02-25 13:52:10 -080019#define ATRACE_TAG ATRACE_TAG_DALVIK
20#include <cutils/trace.h>
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070021#include <memory>
22#include <queue>
23#include <vector>
24
25#include "base/logging.h"
26#include "base/stl_util.h"
Mathieu Chartierfbc31082016-01-24 11:59:56 -080027#include "class_linker.h"
Mathieu Chartier80b37b72015-10-12 18:13:39 -070028#include "dex_file-inl.h"
Mathieu Chartier61d2b2d2016-02-04 13:31:46 -080029#include "gc/scoped_gc_critical_section.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070030#include "gc/space/image_space.h"
Mathieu Chartierfbc31082016-01-24 11:59:56 -080031#include "handle_scope-inl.h"
32#include "mirror/class_loader.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070033#include "oat_file_assistant.h"
Mathieu Chartierfbc31082016-01-24 11:59:56 -080034#include "scoped_thread_state_change.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070035#include "thread-inl.h"
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -080036#include "thread_list.h"
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070037
38namespace art {
39
40// For b/21333911.
Mathieu Chartier80b37b72015-10-12 18:13:39 -070041// Only enabled for debug builds to prevent bit rot. There are too many performance regressions for
42// normal builds.
43static constexpr bool kDuplicateClassesCheck = kIsDebugBuild;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070044
Mathieu Chartierfbc31082016-01-24 11:59:56 -080045// If true, then we attempt to load the application image if it exists.
46static constexpr bool kEnableAppImage = true;
47
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070048const OatFile* OatFileManager::RegisterOatFile(std::unique_ptr<const OatFile> oat_file) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -070049 WriterMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070050 DCHECK(oat_file != nullptr);
51 if (kIsDebugBuild) {
Mathieu Chartiere58991b2015-10-13 07:59:34 -070052 CHECK(oat_files_.find(oat_file) == oat_files_.end());
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070053 for (const std::unique_ptr<const OatFile>& existing : oat_files_) {
54 CHECK_NE(oat_file.get(), existing.get()) << oat_file->GetLocation();
55 // Check that we don't have an oat file with the same address. Copies of the same oat file
56 // should be loaded at different addresses.
57 CHECK_NE(oat_file->Begin(), existing->Begin()) << "Oat file already mapped at that location";
58 }
59 }
60 have_non_pic_oat_file_ = have_non_pic_oat_file_ || !oat_file->IsPic();
Mathieu Chartiere58991b2015-10-13 07:59:34 -070061 const OatFile* ret = oat_file.get();
62 oat_files_.insert(std::move(oat_file));
63 return ret;
64}
65
66void OatFileManager::UnRegisterAndDeleteOatFile(const OatFile* oat_file) {
67 WriterMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
68 DCHECK(oat_file != nullptr);
69 std::unique_ptr<const OatFile> compare(oat_file);
70 auto it = oat_files_.find(compare);
71 CHECK(it != oat_files_.end());
72 oat_files_.erase(it);
73 compare.release();
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070074}
75
76const OatFile* OatFileManager::FindOpenedOatFileFromOatLocation(const std::string& oat_location)
77 const {
78 ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
Mathieu Chartiere58991b2015-10-13 07:59:34 -070079 return FindOpenedOatFileFromOatLocationLocked(oat_location);
80}
81
82const OatFile* OatFileManager::FindOpenedOatFileFromOatLocationLocked(
83 const std::string& oat_location) const {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -070084 for (const std::unique_ptr<const OatFile>& oat_file : oat_files_) {
85 if (oat_file->GetLocation() == oat_location) {
86 return oat_file.get();
87 }
88 }
89 return nullptr;
90}
91
Jeff Haodcdc85b2015-12-04 14:06:18 -080092std::vector<const OatFile*> OatFileManager::GetBootOatFiles() const {
93 std::vector<const OatFile*> oat_files;
94 std::vector<gc::space::ImageSpace*> image_spaces =
95 Runtime::Current()->GetHeap()->GetBootImageSpaces();
96 for (gc::space::ImageSpace* image_space : image_spaces) {
97 oat_files.push_back(image_space->GetOatFile());
98 }
99 return oat_files;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700100}
101
102const OatFile* OatFileManager::GetPrimaryOatFile() const {
103 ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
Jeff Haodcdc85b2015-12-04 14:06:18 -0800104 std::vector<const OatFile*> boot_oat_files = GetBootOatFiles();
105 if (!boot_oat_files.empty()) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700106 for (const std::unique_ptr<const OatFile>& oat_file : oat_files_) {
Jeff Haodcdc85b2015-12-04 14:06:18 -0800107 if (std::find(boot_oat_files.begin(), boot_oat_files.end(), oat_file.get()) ==
108 boot_oat_files.end()) {
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700109 return oat_file.get();
110 }
111 }
112 }
113 return nullptr;
114}
115
116OatFileManager::~OatFileManager() {
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700117 // Explicitly clear oat_files_ since the OatFile destructor calls back into OatFileManager for
118 // UnRegisterOatFileLocation.
119 oat_files_.clear();
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700120}
121
Jeff Haodcdc85b2015-12-04 14:06:18 -0800122std::vector<const OatFile*> OatFileManager::RegisterImageOatFiles(
123 std::vector<gc::space::ImageSpace*> spaces) {
124 std::vector<const OatFile*> oat_files;
125 for (gc::space::ImageSpace* space : spaces) {
126 oat_files.push_back(RegisterOatFile(space->ReleaseOatFile()));
127 }
128 return oat_files;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700129}
130
131class DexFileAndClassPair : ValueObject {
132 public:
133 DexFileAndClassPair(const DexFile* dex_file, size_t current_class_index, bool from_loaded_oat)
134 : cached_descriptor_(GetClassDescriptor(dex_file, current_class_index)),
135 dex_file_(dex_file),
136 current_class_index_(current_class_index),
137 from_loaded_oat_(from_loaded_oat) {}
138
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700139 DexFileAndClassPair(const DexFileAndClassPair& rhs) = default;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700140
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700141 DexFileAndClassPair& operator=(const DexFileAndClassPair& rhs) = default;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700142
143 const char* GetCachedDescriptor() const {
144 return cached_descriptor_;
145 }
146
147 bool operator<(const DexFileAndClassPair& rhs) const {
148 const int cmp = strcmp(cached_descriptor_, rhs.cached_descriptor_);
149 if (cmp != 0) {
150 // Note that the order must be reversed. We want to iterate over the classes in dex files.
151 // They are sorted lexicographically. Thus, the priority-queue must be a min-queue.
152 return cmp > 0;
153 }
154 return dex_file_ < rhs.dex_file_;
155 }
156
157 bool DexFileHasMoreClasses() const {
158 return current_class_index_ + 1 < dex_file_->NumClassDefs();
159 }
160
161 void Next() {
162 ++current_class_index_;
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700163 cached_descriptor_ = GetClassDescriptor(dex_file_.get(), current_class_index_);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700164 }
165
166 size_t GetCurrentClassIndex() const {
167 return current_class_index_;
168 }
169
170 bool FromLoadedOat() const {
171 return from_loaded_oat_;
172 }
173
174 const DexFile* GetDexFile() const {
175 return dex_file_.get();
176 }
177
178 private:
179 static const char* GetClassDescriptor(const DexFile* dex_file, size_t index) {
180 DCHECK(IsUint<16>(index));
181 const DexFile::ClassDef& class_def = dex_file->GetClassDef(static_cast<uint16_t>(index));
182 return dex_file->StringByTypeIdx(class_def.class_idx_);
183 }
184
185 const char* cached_descriptor_;
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700186 std::shared_ptr<const DexFile> dex_file_;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700187 size_t current_class_index_;
188 bool from_loaded_oat_; // We only need to compare mismatches between what we load now
189 // and what was loaded before. Any old duplicates must have been
190 // OK, and any new "internal" duplicates are as well (they must
191 // be from multidex, which resolves correctly).
192};
193
194static void AddDexFilesFromOat(const OatFile* oat_file,
195 bool already_loaded,
196 /*out*/std::priority_queue<DexFileAndClassPair>* heap) {
197 for (const OatDexFile* oat_dex_file : oat_file->GetOatDexFiles()) {
198 std::string error;
199 std::unique_ptr<const DexFile> dex_file = oat_dex_file->OpenDexFile(&error);
200 if (dex_file == nullptr) {
201 LOG(WARNING) << "Could not create dex file from oat file: " << error;
202 } else if (dex_file->NumClassDefs() > 0U) {
203 heap->emplace(dex_file.release(), /*current_class_index*/0U, already_loaded);
204 }
205 }
206}
207
208static void AddNext(/*inout*/DexFileAndClassPair* original,
209 /*inout*/std::priority_queue<DexFileAndClassPair>* heap) {
210 if (original->DexFileHasMoreClasses()) {
211 original->Next();
212 heap->push(std::move(*original));
213 }
214}
215
216// Check for class-def collisions in dex files.
217//
218// This works by maintaining a heap with one class from each dex file, sorted by the class
219// descriptor. Then a dex-file/class pair is continually removed from the heap and compared
220// against the following top element. If the descriptor is the same, it is now checked whether
221// the two elements agree on whether their dex file was from an already-loaded oat-file or the
222// new oat file. Any disagreement indicates a collision.
223bool OatFileManager::HasCollisions(const OatFile* oat_file,
224 std::string* error_msg /*out*/) const {
225 DCHECK(oat_file != nullptr);
226 DCHECK(error_msg != nullptr);
227 if (!kDuplicateClassesCheck) {
228 return false;
229 }
230
231 // Dex files are registered late - once a class is actually being loaded. We have to compare
232 // against the open oat files. Take the oat_file_manager_lock_ that protects oat_files_ accesses.
233 ReaderMutexLock mu(Thread::Current(), *Locks::oat_file_manager_lock_);
234
235 std::priority_queue<DexFileAndClassPair> queue;
236
237 // Add dex files from already loaded oat files, but skip boot.
Jeff Haodcdc85b2015-12-04 14:06:18 -0800238 std::vector<const OatFile*> boot_oat_files = GetBootOatFiles();
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700239 // The same OatFile can be loaded multiple times at different addresses. In this case, we don't
240 // need to check both against each other since they would have resolved the same way at compile
241 // time.
242 std::unordered_set<std::string> unique_locations;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700243 for (const std::unique_ptr<const OatFile>& loaded_oat_file : oat_files_) {
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700244 DCHECK_NE(loaded_oat_file.get(), oat_file);
245 const std::string& location = loaded_oat_file->GetLocation();
Jeff Haodcdc85b2015-12-04 14:06:18 -0800246 if (std::find(boot_oat_files.begin(), boot_oat_files.end(), loaded_oat_file.get()) ==
247 boot_oat_files.end() && location != oat_file->GetLocation() &&
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700248 unique_locations.find(location) == unique_locations.end()) {
249 unique_locations.insert(location);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700250 AddDexFilesFromOat(loaded_oat_file.get(), /*already_loaded*/true, &queue);
251 }
252 }
253
254 if (queue.empty()) {
255 // No other oat files, return early.
256 return false;
257 }
258
259 // Add dex files from the oat file to check.
260 AddDexFilesFromOat(oat_file, /*already_loaded*/false, &queue);
261
262 // Now drain the queue.
263 while (!queue.empty()) {
264 // Modifying the top element is only safe if we pop right after.
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700265 DexFileAndClassPair compare_pop(queue.top());
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700266 queue.pop();
267
268 // Compare against the following elements.
269 while (!queue.empty()) {
Mathieu Chartier80b37b72015-10-12 18:13:39 -0700270 DexFileAndClassPair top(queue.top());
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700271
272 if (strcmp(compare_pop.GetCachedDescriptor(), top.GetCachedDescriptor()) == 0) {
273 // Same descriptor. Check whether it's crossing old-oat-files to new-oat-files.
274 if (compare_pop.FromLoadedOat() != top.FromLoadedOat()) {
275 *error_msg =
276 StringPrintf("Found duplicated class when checking oat files: '%s' in %s and %s",
277 compare_pop.GetCachedDescriptor(),
278 compare_pop.GetDexFile()->GetLocation().c_str(),
279 top.GetDexFile()->GetLocation().c_str());
280 return true;
281 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700282 queue.pop();
283 AddNext(&top, &queue);
284 } else {
285 // Something else. Done here.
286 break;
287 }
288 }
289 AddNext(&compare_pop, &queue);
290 }
291
292 return false;
293}
294
295std::vector<std::unique_ptr<const DexFile>> OatFileManager::OpenDexFilesFromOat(
296 const char* dex_location,
297 const char* oat_location,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800298 jobject class_loader,
299 jobjectArray dex_elements,
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700300 const OatFile** out_oat_file,
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700301 std::vector<std::string>* error_msgs) {
302 CHECK(dex_location != nullptr);
303 CHECK(error_msgs != nullptr);
304
305 // Verify we aren't holding the mutator lock, which could starve GC if we
306 // have to generate or relocate an oat file.
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800307 Thread* const self = Thread::Current();
308 Locks::mutator_lock_->AssertNotHeld(self);
309 Runtime* const runtime = Runtime::Current();
Calin Juravleb077e152016-02-18 18:47:37 +0000310
311 int target_compilation_type_mask = OatFileAssistant::kFullCompilation
312 | OatFileAssistant::kProfileGuideCompilation
313 | OatFileAssistant::kExtractOnly;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700314 OatFileAssistant oat_file_assistant(dex_location,
315 oat_location,
Calin Juravleb077e152016-02-18 18:47:37 +0000316 target_compilation_type_mask,
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700317 kRuntimeISA,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800318 !runtime->IsAotCompiler());
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700319
320 // Lock the target oat location to avoid races generating and loading the
321 // oat file.
322 std::string error_msg;
323 if (!oat_file_assistant.Lock(/*out*/&error_msg)) {
324 // Don't worry too much if this fails. If it does fail, it's unlikely we
325 // can generate an oat file anyway.
326 VLOG(class_linker) << "OatFileAssistant::Lock: " << error_msg;
327 }
328
329 const OatFile* source_oat_file = nullptr;
330
Nicolas Geoffraye722d292015-12-15 11:51:37 +0000331 // Update the oat file on disk if we can. This may fail, but that's okay.
332 // Best effort is all that matters here.
333 if (!oat_file_assistant.MakeUpToDate(/*out*/&error_msg)) {
Nicolas Geoffraya28267f2015-12-16 12:34:50 +0000334 LOG(INFO) << error_msg;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700335 }
336
337 // Get the oat file on disk.
338 std::unique_ptr<const OatFile> oat_file(oat_file_assistant.GetBestOatFile().release());
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800339
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700340 if (oat_file != nullptr) {
341 // Take the file only if it has no collisions, or we must take it because of preopting.
342 bool accept_oat_file = !HasCollisions(oat_file.get(), /*out*/ &error_msg);
343 if (!accept_oat_file) {
344 // Failed the collision check. Print warning.
345 if (Runtime::Current()->IsDexFileFallbackEnabled()) {
346 LOG(WARNING) << "Found duplicate classes, falling back to interpreter mode for "
347 << dex_location;
348 } else {
349 LOG(WARNING) << "Found duplicate classes, dex-file-fallback disabled, will be failing to "
350 " load classes for " << dex_location;
351 }
352 LOG(WARNING) << error_msg;
353
354 // However, if the app was part of /system and preopted, there is no original dex file
355 // available. In that case grudgingly accept the oat file.
356 if (!DexFile::MaybeDex(dex_location)) {
357 accept_oat_file = true;
358 LOG(WARNING) << "Dex location " << dex_location << " does not seem to include dex file. "
359 << "Allow oat file use. This is potentially dangerous.";
360 }
361 }
362
363 if (accept_oat_file) {
364 VLOG(class_linker) << "Registering " << oat_file->GetLocation();
365 source_oat_file = RegisterOatFile(std::move(oat_file));
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700366 *out_oat_file = source_oat_file;
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700367 }
368 }
369
370 std::vector<std::unique_ptr<const DexFile>> dex_files;
371
372 // Load the dex files from the oat file.
373 if (source_oat_file != nullptr) {
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800374 bool added_image_space = false;
375 if (source_oat_file->IsExecutable()) {
376 std::unique_ptr<gc::space::ImageSpace> image_space(
377 kEnableAppImage ? oat_file_assistant.OpenImageSpace(source_oat_file) : nullptr);
378 if (image_space != nullptr) {
379 ScopedObjectAccess soa(self);
380 StackHandleScope<1> hs(self);
381 Handle<mirror::ClassLoader> h_loader(
382 hs.NewHandle(soa.Decode<mirror::ClassLoader*>(class_loader)));
383 // Can not load app image without class loader.
384 if (h_loader.Get() != nullptr) {
385 std::string temp_error_msg;
386 // Add image space has a race condition since other threads could be reading from the
387 // spaces array.
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800388 {
389 ScopedThreadSuspension sts(self, kSuspended);
Mathieu Chartier61d2b2d2016-02-04 13:31:46 -0800390 gc::ScopedGCCriticalSection gcs(self,
391 gc::kGcCauseAddRemoveAppImageSpace,
392 gc::kCollectorTypeAddRemoveAppImageSpace);
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800393 ScopedSuspendAll ssa("Add image space");
394 runtime->GetHeap()->AddSpace(image_space.get());
395 }
Mathieu Chartiera6e81ed2016-02-25 13:52:10 -0800396 ATRACE_BEGIN(StringPrintf("Adding image space for location %s", dex_location).c_str());
397 added_image_space = runtime->GetClassLinker()->AddImageSpace(image_space.get(),
398 h_loader,
399 dex_elements,
400 dex_location,
401 /*out*/&dex_files,
402 /*out*/&temp_error_msg);
403 ATRACE_END();
404 if (added_image_space) {
Mathieu Chartierbd064ea2016-02-11 16:27:18 -0800405 // Successfully added image space to heap, release the map so that it does not get
406 // freed.
407 image_space.release();
408 } else {
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800409 LOG(INFO) << "Failed to add image file " << temp_error_msg;
410 dex_files.clear();
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800411 {
412 ScopedThreadSuspension sts(self, kSuspended);
Mathieu Chartier61d2b2d2016-02-04 13:31:46 -0800413 gc::ScopedGCCriticalSection gcs(self,
414 gc::kGcCauseAddRemoveAppImageSpace,
415 gc::kCollectorTypeAddRemoveAppImageSpace);
Mathieu Chartiera9d82fe2016-01-25 20:06:11 -0800416 ScopedSuspendAll ssa("Remove image space");
417 runtime->GetHeap()->RemoveSpace(image_space.get());
418 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800419 // Non-fatal, don't update error_msg.
420 }
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800421 }
422 }
423 }
424 if (!added_image_space) {
425 DCHECK(dex_files.empty());
426 dex_files = oat_file_assistant.LoadDexFiles(*source_oat_file, dex_location);
427 }
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700428 if (dex_files.empty()) {
429 error_msgs->push_back("Failed to open dex files from " + source_oat_file->GetLocation());
430 }
431 }
432
433 // Fall back to running out of the original dex file if we couldn't load any
434 // dex_files from the oat file.
435 if (dex_files.empty()) {
436 if (oat_file_assistant.HasOriginalDexFiles()) {
437 if (Runtime::Current()->IsDexFileFallbackEnabled()) {
438 if (!DexFile::Open(dex_location, dex_location, /*out*/ &error_msg, &dex_files)) {
439 LOG(WARNING) << error_msg;
440 error_msgs->push_back("Failed to open dex files from " + std::string(dex_location));
441 }
442 } else {
443 error_msgs->push_back("Fallback mode disabled, skipping dex files.");
444 }
445 } else {
446 error_msgs->push_back("No original dex files found for dex location "
447 + std::string(dex_location));
448 }
449 }
Calin Juravlec90bc922016-02-24 10:13:09 +0000450
451 // TODO(calin): Consider optimizing this knowing that is useless to record the
452 // use of fully compiled apks.
453 Runtime::Current()->NotifyDexLoaded(dex_location);
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700454 return dex_files;
455}
456
Mathieu Chartiere58991b2015-10-13 07:59:34 -0700457bool OatFileManager::RegisterOatFileLocation(const std::string& oat_location) {
458 WriterMutexLock mu(Thread::Current(), *Locks::oat_file_count_lock_);
459 auto it = oat_file_count_.find(oat_location);
460 if (it != oat_file_count_.end()) {
461 ++it->second;
462 return false;
463 }
464 oat_file_count_.insert(std::pair<std::string, size_t>(oat_location, 1u));
465 return true;
466}
467
468void OatFileManager::UnRegisterOatFileLocation(const std::string& oat_location) {
469 WriterMutexLock mu(Thread::Current(), *Locks::oat_file_count_lock_);
470 auto it = oat_file_count_.find(oat_location);
471 if (it != oat_file_count_.end()) {
472 --it->second;
473 if (it->second == 0) {
474 oat_file_count_.erase(it);
475 }
476 }
477}
478
Mathieu Chartierf9c6fc62015-10-07 11:44:05 -0700479} // namespace art