blob: 2b942499586ff0ed22b9512bb138504054a03a80 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 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 */
Brian Carlstrome24fa612011-09-29 00:53:55 -070016
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_OAT_FILE_H_
18#define ART_RUNTIME_OAT_FILE_H_
Brian Carlstrome24fa612011-09-29 00:53:55 -070019
Vladimir Marko3f5838d2014-08-07 18:07:18 +010020#include <list>
Brian Carlstrom700c8d32012-11-05 10:42:02 -080021#include <string>
Brian Carlstrome24fa612011-09-29 00:53:55 -070022#include <vector>
23
Vladimir Marko3f5838d2014-08-07 18:07:18 +010024#include "base/mutex.h"
Vladimir Marko539690a2014-06-05 18:36:42 +010025#include "base/stringpiece.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "dex_file.h"
27#include "invoke_type.h"
28#include "mem_map.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070029#include "mirror/class.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030#include "oat.h"
Brian Carlstrom700c8d32012-11-05 10:42:02 -080031#include "os.h"
Brian Carlstrome24fa612011-09-29 00:53:55 -070032
33namespace art {
34
Brian Carlstromba150c32013-08-27 17:31:03 -070035class BitVector;
Brian Carlstrom700c8d32012-11-05 10:42:02 -080036class ElfFile;
37class MemMap;
38class OatMethodOffsets;
Ian Rogers33e95662013-05-20 20:29:14 -070039class OatHeader;
Brian Carlstrom700c8d32012-11-05 10:42:02 -080040
Brian Carlstrome24fa612011-09-29 00:53:55 -070041class OatFile {
42 public:
Alex Light84d76052014-08-22 17:49:35 -070043 // Opens an oat file contained within the given elf file. This is always opened as
44 // non-executable at the moment.
45 static OatFile* OpenWithElfFile(ElfFile* elf_file, const std::string& location,
46 std::string* error_msg);
Brian Carlstrome24fa612011-09-29 00:53:55 -070047 // Open an oat file. Returns NULL on failure. Requested base can
48 // optionally be used to request where the file should be loaded.
49 static OatFile* Open(const std::string& filename,
Brian Carlstroma004aa92012-02-08 18:05:09 -080050 const std::string& location,
Ian Rogers13735952014-10-08 12:43:28 -070051 uint8_t* requested_base,
Igor Murashkin46774762014-10-22 11:37:02 -070052 uint8_t* oat_file_begin,
Ian Rogers8d31bbd2013-10-13 10:44:14 -070053 bool executable,
54 std::string* error_msg);
Brian Carlstrome24fa612011-09-29 00:53:55 -070055
Brian Carlstrom700c8d32012-11-05 10:42:02 -080056 // Open an oat file from an already opened File.
Brian Carlstrom265091e2013-01-30 14:08:26 -080057 // Does not use dlopen underneath so cannot be used for runtime use
58 // where relocations may be required. Currently used from
59 // ImageWriter which wants to open a writable version from an existing
60 // file descriptor for patching.
Ian Rogers8d31bbd2013-10-13 10:44:14 -070061 static OatFile* OpenWritable(File* file, const std::string& location, std::string* error_msg);
Alex Lighta59dd802014-07-02 16:28:08 -070062 // Opens an oat file from an already opened File. Maps it PROT_READ, MAP_PRIVATE.
63 static OatFile* OpenReadable(File* file, const std::string& location, std::string* error_msg);
Brian Carlstrom700c8d32012-11-05 10:42:02 -080064
65 // Open an oat file backed by a std::vector with the given location.
Brian Carlstrom265091e2013-01-30 14:08:26 -080066 static OatFile* OpenMemory(std::vector<uint8_t>& oat_contents,
Ian Rogers8d31bbd2013-10-13 10:44:14 -070067 const std::string& location,
68 std::string* error_msg);
Brian Carlstrom5b332c82012-02-01 15:02:31 -080069
Brian Carlstrome24fa612011-09-29 00:53:55 -070070 ~OatFile();
71
Alex Light9dcc4572014-08-14 14:16:26 -070072 bool IsExecutable() const {
73 return is_executable_;
74 }
75
Andreas Gampe7ba64962014-10-23 11:37:40 -070076 bool IsPic() const;
77
Alex Light53cb16b2014-06-12 11:26:29 -070078 ElfFile* GetElfFile() const {
79 CHECK_NE(reinterpret_cast<uintptr_t>(elf_file_.get()), reinterpret_cast<uintptr_t>(nullptr))
80 << "Cannot get an elf file from " << GetLocation();
81 return elf_file_.get();
82 }
83
Brian Carlstrome24fa612011-09-29 00:53:55 -070084 const std::string& GetLocation() const {
85 return location_;
86 }
87
88 const OatHeader& GetOatHeader() const;
89
90 class OatDexFile;
91
Brian Carlstrom3320cf42011-10-04 14:58:28 -070092 class OatMethod {
93 public:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070094 void LinkMethod(mirror::ArtMethod* method) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromae826982011-11-09 01:33:42 -080095
96 uint32_t GetCodeOffset() const {
97 return code_offset_;
98 }
Ian Rogers0c7abda2012-09-19 13:33:42 -070099 uint32_t GetNativeGcMapOffset() const {
100 return native_gc_map_offset_;
Brian Carlstrome7d856b2012-01-11 18:10:55 -0800101 }
Brian Carlstromae826982011-11-09 01:33:42 -0800102
Ian Rogersef7d42f2014-01-06 12:55:46 -0800103 const void* GetPortableCode() const {
104 // TODO: encode whether code is portable/quick in flags within OatMethod.
105 if (kUsePortableCompiler) {
106 return GetOatPointer<const void*>(code_offset_);
107 } else {
108 return nullptr;
109 }
110 }
111
112 const void* GetQuickCode() const {
113 if (kUsePortableCompiler) {
114 return nullptr;
115 } else {
116 return GetOatPointer<const void*>(code_offset_);
117 }
118 }
119
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700120 // Returns 0.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800121 uint32_t GetPortableCodeSize() const {
122 // TODO: With Quick, we store the size before the code. With Portable, the code is in a .o
123 // file we don't manage ourselves. ELF symbols do have a concept of size, so we could capture
124 // that and store it somewhere, such as the OatMethod.
125 return 0;
126 }
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700127
128 // Returns size of quick code.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800129 uint32_t GetQuickCodeSize() const;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700130 uint32_t GetQuickCodeSizeOffset() const;
131
132 // Returns OatQuickMethodHeader for debugging. Most callers should
133 // use more specific methods such as GetQuickCodeSize.
134 const OatQuickMethodHeader* GetOatQuickMethodHeader() const;
135 uint32_t GetOatQuickMethodHeaderOffset() const;
Logan Chien0c717dd2012-03-28 18:31:07 +0800136
Ian Rogers0c7abda2012-09-19 13:33:42 -0700137 const uint8_t* GetNativeGcMap() const {
138 return GetOatPointer<const uint8_t*>(native_gc_map_offset_);
Brian Carlstrome7d856b2012-01-11 18:10:55 -0800139 }
Logan Chien0c717dd2012-03-28 18:31:07 +0800140
Vladimir Marko7624d252014-05-02 14:40:15 +0100141 size_t GetFrameSizeInBytes() const;
142 uint32_t GetCoreSpillMask() const;
143 uint32_t GetFpSpillMask() const;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700144
Vladimir Marko8a630572014-04-09 18:45:35 +0100145 const uint8_t* GetMappingTable() const;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700146 uint32_t GetMappingTableOffset() const;
147 uint32_t GetMappingTableOffsetOffset() const;
148
Vladimir Marko8a630572014-04-09 18:45:35 +0100149 const uint8_t* GetVmapTable() const;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700150 uint32_t GetVmapTableOffset() const;
151 uint32_t GetVmapTableOffsetOffset() const;
Vladimir Marko8a630572014-04-09 18:45:35 +0100152
Brian Carlstromae826982011-11-09 01:33:42 -0800153 // Create an OatMethod with offsets relative to the given base address
Ian Rogers13735952014-10-08 12:43:28 -0700154 OatMethod(const uint8_t* base, const uint32_t code_offset, const uint32_t gc_map_offset)
Ian Rogers97b52f82014-08-14 11:34:07 -0700155 : begin_(base),
156 code_offset_(code_offset),
157 native_gc_map_offset_(gc_map_offset) {
158 }
159 ~OatMethod() {}
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700160
Ian Rogers97b52f82014-08-14 11:34:07 -0700161 // A representation of an invalid OatMethod, used when an OatMethod or OatClass can't be found.
162 // See ClassLinker::FindOatMethodFor.
163 static const OatMethod Invalid() {
164 return OatMethod(nullptr, -1, -1);
165 }
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100166
Brian Carlstromae826982011-11-09 01:33:42 -0800167 private:
168 template<class T>
169 T GetOatPointer(uint32_t offset) const {
170 if (offset == 0) {
171 return NULL;
172 }
Ian Rogers30fab402012-01-23 15:43:46 -0800173 return reinterpret_cast<T>(begin_ + offset);
Brian Carlstromae826982011-11-09 01:33:42 -0800174 }
175
Ian Rogers13735952014-10-08 12:43:28 -0700176 const uint8_t* const begin_;
Brian Carlstromae826982011-11-09 01:33:42 -0800177
Ian Rogers97b52f82014-08-14 11:34:07 -0700178 const uint32_t code_offset_;
179 const uint32_t native_gc_map_offset_;
Brian Carlstromae826982011-11-09 01:33:42 -0800180
181 friend class OatClass;
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700182 };
183
Brian Carlstrome24fa612011-09-29 00:53:55 -0700184 class OatClass {
185 public:
Brian Carlstromba150c32013-08-27 17:31:03 -0700186 mirror::Class::Status GetStatus() const {
187 return status_;
188 }
189
190 OatClassType GetType() const {
191 return type_;
192 }
Brian Carlstrom0755ec52012-01-11 15:19:46 -0800193
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700194 // Get the OatMethod entry based on its index into the class
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700195 // defintion. Direct methods come first, followed by virtual
196 // methods. Note that runtime created methods such as miranda
Brian Carlstrome24fa612011-09-29 00:53:55 -0700197 // methods are not included.
Brian Carlstromaded5f72011-10-07 17:15:04 -0700198 const OatMethod GetOatMethod(uint32_t method_index) const;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700199
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700200 // Return a pointer to the OatMethodOffsets for the requested
201 // method_index, or nullptr if none is present. Note that most
202 // callers should use GetOatMethod.
203 const OatMethodOffsets* GetOatMethodOffsets(uint32_t method_index) const;
204
205 // Return the offset from the start of the OatFile to the
206 // OatMethodOffsets for the requested method_index, or 0 if none
207 // is present. Note that most callers should use GetOatMethod.
208 uint32_t GetOatMethodOffsetsOffset(uint32_t method_index) const;
209
Ian Rogers97b52f82014-08-14 11:34:07 -0700210 // A representation of an invalid OatClass, used when an OatClass can't be found.
211 // See ClassLinker::FindOatClass.
212 static OatClass Invalid() {
213 return OatClass(nullptr, mirror::Class::kStatusError, kOatClassNoneCompiled, 0, nullptr,
214 nullptr);
215 }
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100216
Brian Carlstrome24fa612011-09-29 00:53:55 -0700217 private:
Brian Carlstrom0755ec52012-01-11 15:19:46 -0800218 OatClass(const OatFile* oat_file,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800219 mirror::Class::Status status,
Brian Carlstromba150c32013-08-27 17:31:03 -0700220 OatClassType type,
221 uint32_t bitmap_size,
222 const uint32_t* bitmap_pointer,
Brian Carlstrom0755ec52012-01-11 15:19:46 -0800223 const OatMethodOffsets* methods_pointer);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700224
Ian Rogers97b52f82014-08-14 11:34:07 -0700225 const OatFile* const oat_file_;
Brian Carlstromba150c32013-08-27 17:31:03 -0700226
Ian Rogers97b52f82014-08-14 11:34:07 -0700227 const mirror::Class::Status status_;
Brian Carlstromba150c32013-08-27 17:31:03 -0700228
Ian Rogers97b52f82014-08-14 11:34:07 -0700229 const OatClassType type_;
Brian Carlstromba150c32013-08-27 17:31:03 -0700230
Ian Rogers97b52f82014-08-14 11:34:07 -0700231 const uint32_t* const bitmap_;
Brian Carlstromba150c32013-08-27 17:31:03 -0700232
Ian Rogers97b52f82014-08-14 11:34:07 -0700233 const OatMethodOffsets* const methods_pointer_;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700234
235 friend class OatDexFile;
236 };
237
238 class OatDexFile {
239 public:
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700240 // Opens the DexFile referred to by this OatDexFile from within the containing OatFile.
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700241 const DexFile* OpenDexFile(std::string* error_msg) const;
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700242
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100243 const OatFile* GetOatFile() const {
244 return oat_file_;
245 }
246
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700247 // Returns the size of the DexFile refered to by this OatDexFile.
Ian Rogers05f28c62012-10-23 18:12:13 -0700248 size_t FileSize() const;
Brian Carlstromaded5f72011-10-07 17:15:04 -0700249
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700250 // Returns original path of DexFile that was the source of this OatDexFile.
Brian Carlstromaded5f72011-10-07 17:15:04 -0700251 const std::string& GetDexFileLocation() const {
252 return dex_file_location_;
253 }
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700254
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100255 // Returns the canonical location of DexFile that was the source of this OatDexFile.
256 const std::string& GetCanonicalDexFileLocation() const {
257 return canonical_dex_file_location_;
258 }
259
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700260 // Returns checksum of original DexFile that was the source of this OatDexFile;
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800261 uint32_t GetDexFileLocationChecksum() const {
262 return dex_file_location_checksum_;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700263 }
264
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700265 // Returns the OatClass for the class specified by the given DexFile class_def_index.
Vladimir Markod3c5beb2014-04-11 16:32:51 +0100266 OatClass GetOatClass(uint16_t class_def_index) const;
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700267
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700268 // Returns the offset to the OatClass information. Most callers should use GetOatClass.
269 uint32_t GetOatClassOffset(uint16_t class_def_index) const;
270
Brian Carlstrome24fa612011-09-29 00:53:55 -0700271 ~OatDexFile();
Elliott Hughesa21039c2012-06-21 12:09:25 -0700272
Brian Carlstrome24fa612011-09-29 00:53:55 -0700273 private:
274 OatDexFile(const OatFile* oat_file,
Elliott Hughesaa6a5882012-01-13 19:39:16 -0800275 const std::string& dex_file_location,
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100276 const std::string& canonical_dex_file_location,
Brian Carlstrome24fa612011-09-29 00:53:55 -0700277 uint32_t dex_file_checksum,
Ian Rogers13735952014-10-08 12:43:28 -0700278 const uint8_t* dex_file_pointer,
Brian Carlstrom0755ec52012-01-11 15:19:46 -0800279 const uint32_t* oat_class_offsets_pointer);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700280
Vladimir Marko539690a2014-06-05 18:36:42 +0100281 const OatFile* const oat_file_;
282 const std::string dex_file_location_;
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100283 const std::string canonical_dex_file_location_;
Vladimir Marko539690a2014-06-05 18:36:42 +0100284 const uint32_t dex_file_location_checksum_;
Ian Rogers13735952014-10-08 12:43:28 -0700285 const uint8_t* const dex_file_pointer_;
Vladimir Marko539690a2014-06-05 18:36:42 +0100286 const uint32_t* const oat_class_offsets_pointer_;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700287
288 friend class OatFile;
289 DISALLOW_COPY_AND_ASSIGN(OatDexFile);
290 };
291
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700292 const OatDexFile* GetOatDexFile(const char* dex_location,
Brian Carlstrom756ee4e2013-10-03 15:46:12 -0700293 const uint32_t* const dex_location_checksum,
Vladimir Marko3f5838d2014-08-07 18:07:18 +0100294 bool exception_if_not_found = true) const
295 LOCKS_EXCLUDED(secondary_lookup_lock_);
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700296
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100297 const std::vector<const OatDexFile*>& GetOatDexFiles() const {
298 return oat_dex_files_storage_;
299 }
Brian Carlstrome24fa612011-09-29 00:53:55 -0700300
Ian Rogers30fab402012-01-23 15:43:46 -0800301 size_t Size() const {
302 return End() - Begin();
Brian Carlstrome24fa612011-09-29 00:53:55 -0700303 }
304
Ian Rogers13735952014-10-08 12:43:28 -0700305 const uint8_t* Begin() const;
306 const uint8_t* End() const;
Alex Light53cb16b2014-06-12 11:26:29 -0700307
Brian Carlstrome24fa612011-09-29 00:53:55 -0700308 private:
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800309 static void CheckLocation(const std::string& location);
310
311 static OatFile* OpenDlopen(const std::string& elf_filename,
312 const std::string& location,
Ian Rogers13735952014-10-08 12:43:28 -0700313 uint8_t* requested_base,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700314 std::string* error_msg);
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800315
316 static OatFile* OpenElfFile(File* file,
317 const std::string& location,
Ian Rogers13735952014-10-08 12:43:28 -0700318 uint8_t* requested_base,
Igor Murashkin46774762014-10-22 11:37:02 -0700319 uint8_t* oat_file_begin, // Override base if not null
Brian Carlstromf1d34552013-07-12 20:22:23 -0700320 bool writable,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700321 bool executable,
322 std::string* error_msg);
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800323
Alex Light9dcc4572014-08-14 14:16:26 -0700324 explicit OatFile(const std::string& filename, bool executable);
Ian Rogers13735952014-10-08 12:43:28 -0700325 bool Dlopen(const std::string& elf_filename, uint8_t* requested_base, std::string* error_msg);
Igor Murashkin46774762014-10-22 11:37:02 -0700326 bool ElfFileOpen(File* file, uint8_t* requested_base,
327 uint8_t* oat_file_begin, // Override where the file is loaded to if not null
328 bool writable, bool executable,
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700329 std::string* error_msg);
330 bool Setup(std::string* error_msg);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700331
Brian Carlstrome24fa612011-09-29 00:53:55 -0700332 // The oat file name.
333 //
334 // The image will embed this to link its associated oat file.
335 const std::string location_;
336
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800337 // Pointer to OatHeader.
Ian Rogers13735952014-10-08 12:43:28 -0700338 const uint8_t* begin_;
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800339
340 // Pointer to end of oat region for bounds checking.
Ian Rogers13735952014-10-08 12:43:28 -0700341 const uint8_t* end_;
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800342
Alex Light9dcc4572014-08-14 14:16:26 -0700343 // Was this oat_file loaded executable?
344 const bool is_executable_;
345
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800346 // Backing memory map for oat file during when opened by ElfWriter during initial compilation.
Ian Rogers700a4022014-05-19 16:49:03 -0700347 std::unique_ptr<MemMap> mem_map_;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700348
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800349 // Backing memory map for oat file during cross compilation.
Ian Rogers700a4022014-05-19 16:49:03 -0700350 std::unique_ptr<ElfFile> elf_file_;
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800351
352 // dlopen handle during runtime.
353 void* dlopen_handle_;
354
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100355 // Owning storage for the OatDexFile objects.
356 std::vector<const OatDexFile*> oat_dex_files_storage_;
357
Vladimir Marko3f5838d2014-08-07 18:07:18 +0100358 // NOTE: We use a StringPiece as the key type to avoid a memory allocation on every
359 // lookup with a const char* key. The StringPiece doesn't own its backing storage,
360 // therefore we're using the OatDexFile::dex_file_location_ as the backing storage
361 // for keys in oat_dex_files_ and the string_cache_ entries for the backing storage
362 // of keys in secondary_oat_dex_files_ and oat_dex_files_by_canonical_location_.
Mathieu Chartierbad02672014-08-25 13:08:22 -0700363 typedef AllocationTrackingSafeMap<StringPiece, const OatDexFile*, kAllocatorTagOatFile> Table;
Vladimir Marko3f5838d2014-08-07 18:07:18 +0100364
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100365 // Map each location and canonical location (if different) retrieved from the
366 // oat file to its OatDexFile. This map doesn't change after it's constructed in Setup()
367 // and therefore doesn't need any locking and provides the cheapest dex file lookup
368 // for GetOatDexFile() for a very frequent use case. Never contains a nullptr value.
369 Table oat_dex_files_;
Vladimir Marko3f5838d2014-08-07 18:07:18 +0100370
371 // Lock guarding all members needed for secondary lookup in GetOatDexFile().
372 mutable Mutex secondary_lookup_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
373
374 // If the primary oat_dex_files_ lookup fails, use a secondary map. This map stores
375 // the results of all previous secondary lookups, whether successful (non-null) or
376 // failed (null). If it doesn't contain an entry we need to calculate the canonical
377 // location and use oat_dex_files_by_canonical_location_.
378 mutable Table secondary_oat_dex_files_ GUARDED_BY(secondary_lookup_lock_);
379
Vladimir Marko3f5838d2014-08-07 18:07:18 +0100380 // Cache of strings. Contains the backing storage for keys in the secondary_oat_dex_files_
381 // and the lazily initialized oat_dex_files_by_canonical_location_.
382 // NOTE: We're keeping references to contained strings in form of StringPiece and adding
383 // new strings to the end. The adding of a new element must not touch any previously stored
384 // elements. std::list<> and std::deque<> satisfy this requirement, std::vector<> doesn't.
385 mutable std::list<std::string> string_cache_ GUARDED_BY(secondary_lookup_lock_);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700386
387 friend class OatClass;
388 friend class OatDexFile;
Elliott Hughese3c845c2012-02-28 17:23:01 -0800389 friend class OatDumper; // For GetBase and GetLimit
Brian Carlstrome24fa612011-09-29 00:53:55 -0700390 DISALLOW_COPY_AND_ASSIGN(OatFile);
391};
392
393} // namespace art
394
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700395#endif // ART_RUNTIME_OAT_FILE_H_