blob: a48791ee73a44485d898452d5d0d6ef5dfbe4602 [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"
Nicolas Geoffray6bc43742015-10-12 18:11:10 +010032#include "utils.h"
David Brazdil7b49e6c2016-09-01 11:06:18 +010033#include "vdex_file.h"
Brian Carlstrome24fa612011-09-29 00:53:55 -070034
35namespace art {
36
Brian Carlstromba150c32013-08-27 17:31:03 -070037class BitVector;
Brian Carlstrom700c8d32012-11-05 10:42:02 -080038class ElfFile;
39class MemMap;
40class OatMethodOffsets;
Ian Rogers33e95662013-05-20 20:29:14 -070041class OatHeader;
Richard Uhler07b3c232015-03-31 15:57:54 -070042class OatDexFile;
Brian Carlstrom700c8d32012-11-05 10:42:02 -080043
Mathieu Chartier5351da02016-02-17 16:19:53 -080044namespace gc {
45namespace collector {
46class DummyOatFile;
47} // namespace collector
48} // namespace gc
49
David Brazdil7b49e6c2016-09-01 11:06:18 +010050// Runtime representation of the OAT file format which holds compiler output.
51// The class opens an OAT file from storage and maps it to memory, typically with
52// dlopen and provides access to its internal data structures (see OatWriter for
53// for more details about the OAT format).
54// In the process of loading OAT, the class also loads the associated VDEX file
55// with the input DEX files (see VdexFile for details about the VDEX format).
56// The raw DEX data are accessible transparently through the OatDexFile objects.
57
Andreas Gampe049cff02015-12-01 23:27:12 -080058class OatFile {
Brian Carlstrome24fa612011-09-29 00:53:55 -070059 public:
Jeff Haof0192c82016-03-28 20:39:50 -070060 // Special classpath that skips shared library check.
61 static constexpr const char* kSpecialSharedLibrary = "&";
62
Richard Uhler07b3c232015-03-31 15:57:54 -070063 typedef art::OatDexFile OatDexFile;
64
Alex Light84d76052014-08-22 17:49:35 -070065 // Opens an oat file contained within the given elf file. This is always opened as
66 // non-executable at the moment.
David Brazdilc93b3be2016-09-12 18:49:58 +010067 static OatFile* OpenWithElfFile(ElfFile* elf_file,
68 VdexFile* vdex_file,
69 const std::string& location,
Richard Uhlere5fed032015-03-18 08:21:11 -070070 const char* abs_dex_location,
Igor Murashkinb1d8c312015-08-04 11:18:43 -070071 std::string* error_msg);
Mathieu Chartier2cebb242015-04-21 16:50:40 -070072 // Open an oat file. Returns null on failure. Requested base can
Brian Carlstrome24fa612011-09-29 00:53:55 -070073 // optionally be used to request where the file should be loaded.
Richard Uhlere5fed032015-03-18 08:21:11 -070074 // See the ResolveRelativeEncodedDexLocation for a description of how the
75 // abs_dex_location argument is used.
Brian Carlstrome24fa612011-09-29 00:53:55 -070076 static OatFile* Open(const std::string& filename,
Brian Carlstroma004aa92012-02-08 18:05:09 -080077 const std::string& location,
Ian Rogers13735952014-10-08 12:43:28 -070078 uint8_t* requested_base,
Igor Murashkin46774762014-10-22 11:37:02 -070079 uint8_t* oat_file_begin,
Ian Rogers8d31bbd2013-10-13 10:44:14 -070080 bool executable,
Mathieu Chartier0b4cbd02016-03-08 16:49:58 -080081 bool low_4gb,
Richard Uhlere5fed032015-03-18 08:21:11 -070082 const char* abs_dex_location,
Igor Murashkinb1d8c312015-08-04 11:18:43 -070083 std::string* error_msg);
Brian Carlstrome24fa612011-09-29 00:53:55 -070084
Brian Carlstrom700c8d32012-11-05 10:42:02 -080085 // Open an oat file from an already opened File.
Brian Carlstrom265091e2013-01-30 14:08:26 -080086 // Does not use dlopen underneath so cannot be used for runtime use
87 // where relocations may be required. Currently used from
88 // ImageWriter which wants to open a writable version from an existing
89 // file descriptor for patching.
Igor Murashkinb1d8c312015-08-04 11:18:43 -070090 static OatFile* OpenWritable(File* file, const std::string& location,
Richard Uhlere5fed032015-03-18 08:21:11 -070091 const char* abs_dex_location,
Igor Murashkinb1d8c312015-08-04 11:18:43 -070092 std::string* error_msg);
Alex Lighta59dd802014-07-02 16:28:08 -070093 // Opens an oat file from an already opened File. Maps it PROT_READ, MAP_PRIVATE.
Igor Murashkinb1d8c312015-08-04 11:18:43 -070094 static OatFile* OpenReadable(File* file, const std::string& location,
Richard Uhlere5fed032015-03-18 08:21:11 -070095 const char* abs_dex_location,
Igor Murashkinb1d8c312015-08-04 11:18:43 -070096 std::string* error_msg);
Brian Carlstrom700c8d32012-11-05 10:42:02 -080097
Andreas Gampe049cff02015-12-01 23:27:12 -080098 virtual ~OatFile();
Brian Carlstrome24fa612011-09-29 00:53:55 -070099
Alex Light9dcc4572014-08-14 14:16:26 -0700100 bool IsExecutable() const {
101 return is_executable_;
102 }
103
Richard Uhlerd1537b52016-03-29 13:27:41 -0700104 bool HasPatchInfo() const;
105
Andreas Gampe7ba64962014-10-23 11:37:40 -0700106 bool IsPic() const;
107
Sebastien Hertz0de11332015-05-13 12:14:05 +0200108 // Indicates whether the oat file was compiled with full debugging capability.
109 bool IsDebuggable() const;
110
Andreas Gampe29d38e72016-03-23 15:31:51 +0000111 CompilerFilter::Filter GetCompilerFilter() const;
Calin Juravleb077e152016-02-18 18:47:37 +0000112
Brian Carlstrome24fa612011-09-29 00:53:55 -0700113 const std::string& GetLocation() const {
114 return location_;
115 }
116
117 const OatHeader& GetOatHeader() const;
118
Richard Uhler07b3c232015-03-31 15:57:54 -0700119 class OatMethod FINAL {
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700120 public:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700121 void LinkMethod(ArtMethod* method) const;
Brian Carlstromae826982011-11-09 01:33:42 -0800122
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100123 uint32_t GetCodeOffset() const;
Brian Carlstromae826982011-11-09 01:33:42 -0800124
Nicolas Geoffrayc04c8002015-07-14 11:37:54 +0100125 const void* GetQuickCode() const;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700126
127 // Returns size of quick code.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800128 uint32_t GetQuickCodeSize() const;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700129 uint32_t GetQuickCodeSizeOffset() const;
130
131 // Returns OatQuickMethodHeader for debugging. Most callers should
132 // use more specific methods such as GetQuickCodeSize.
133 const OatQuickMethodHeader* GetOatQuickMethodHeader() const;
134 uint32_t GetOatQuickMethodHeaderOffset() const;
Logan Chien0c717dd2012-03-28 18:31:07 +0800135
Vladimir Marko7624d252014-05-02 14:40:15 +0100136 size_t GetFrameSizeInBytes() const;
137 uint32_t GetCoreSpillMask() const;
138 uint32_t GetFpSpillMask() const;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700139
Vladimir Marko8a630572014-04-09 18:45:35 +0100140 const uint8_t* GetVmapTable() const;
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700141 uint32_t GetVmapTableOffset() const;
142 uint32_t GetVmapTableOffsetOffset() const;
Vladimir Marko8a630572014-04-09 18:45:35 +0100143
Brian Carlstromae826982011-11-09 01:33:42 -0800144 // Create an OatMethod with offsets relative to the given base address
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800145 OatMethod(const uint8_t* base, const uint32_t code_offset)
146 : begin_(base), code_offset_(code_offset) {
Ian Rogers97b52f82014-08-14 11:34:07 -0700147 }
Andreas Gampe758a8012015-04-03 21:28:42 -0700148 OatMethod(const OatMethod&) = default;
Ian Rogers97b52f82014-08-14 11:34:07 -0700149 ~OatMethod() {}
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700150
Andreas Gampe758a8012015-04-03 21:28:42 -0700151 OatMethod& operator=(const OatMethod&) = default;
152
Ian Rogers97b52f82014-08-14 11:34:07 -0700153 // A representation of an invalid OatMethod, used when an OatMethod or OatClass can't be found.
154 // See ClassLinker::FindOatMethodFor.
155 static const OatMethod Invalid() {
Mathieu Chartier957ca1c2014-11-21 16:51:29 -0800156 return OatMethod(nullptr, -1);
Ian Rogers97b52f82014-08-14 11:34:07 -0700157 }
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100158
Brian Carlstromae826982011-11-09 01:33:42 -0800159 private:
160 template<class T>
161 T GetOatPointer(uint32_t offset) const {
162 if (offset == 0) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700163 return nullptr;
Brian Carlstromae826982011-11-09 01:33:42 -0800164 }
Ian Rogers30fab402012-01-23 15:43:46 -0800165 return reinterpret_cast<T>(begin_ + offset);
Brian Carlstromae826982011-11-09 01:33:42 -0800166 }
167
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800168 const uint8_t* begin_;
169 uint32_t code_offset_;
Brian Carlstromae826982011-11-09 01:33:42 -0800170
171 friend class OatClass;
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700172 };
173
Richard Uhler07b3c232015-03-31 15:57:54 -0700174 class OatClass FINAL {
Brian Carlstrome24fa612011-09-29 00:53:55 -0700175 public:
Brian Carlstromba150c32013-08-27 17:31:03 -0700176 mirror::Class::Status GetStatus() const {
177 return status_;
178 }
179
180 OatClassType GetType() const {
181 return type_;
182 }
Brian Carlstrom0755ec52012-01-11 15:19:46 -0800183
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700184 // Get the OatMethod entry based on its index into the class
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700185 // defintion. Direct methods come first, followed by virtual
186 // methods. Note that runtime created methods such as miranda
Brian Carlstrome24fa612011-09-29 00:53:55 -0700187 // methods are not included.
Brian Carlstromaded5f72011-10-07 17:15:04 -0700188 const OatMethod GetOatMethod(uint32_t method_index) const;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700189
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700190 // Return a pointer to the OatMethodOffsets for the requested
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700191 // method_index, or null if none is present. Note that most
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700192 // callers should use GetOatMethod.
193 const OatMethodOffsets* GetOatMethodOffsets(uint32_t method_index) const;
194
195 // Return the offset from the start of the OatFile to the
196 // OatMethodOffsets for the requested method_index, or 0 if none
197 // is present. Note that most callers should use GetOatMethod.
198 uint32_t GetOatMethodOffsetsOffset(uint32_t method_index) const;
199
Ian Rogers97b52f82014-08-14 11:34:07 -0700200 // A representation of an invalid OatClass, used when an OatClass can't be found.
201 // See ClassLinker::FindOatClass.
202 static OatClass Invalid() {
203 return OatClass(nullptr, mirror::Class::kStatusError, kOatClassNoneCompiled, 0, nullptr,
204 nullptr);
205 }
Nicolas Geoffray4fcdc942014-07-22 10:48:00 +0100206
Brian Carlstrome24fa612011-09-29 00:53:55 -0700207 private:
Brian Carlstrom0755ec52012-01-11 15:19:46 -0800208 OatClass(const OatFile* oat_file,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800209 mirror::Class::Status status,
Brian Carlstromba150c32013-08-27 17:31:03 -0700210 OatClassType type,
211 uint32_t bitmap_size,
212 const uint32_t* bitmap_pointer,
Brian Carlstrom0755ec52012-01-11 15:19:46 -0800213 const OatMethodOffsets* methods_pointer);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700214
Ian Rogers97b52f82014-08-14 11:34:07 -0700215 const OatFile* const oat_file_;
Brian Carlstromba150c32013-08-27 17:31:03 -0700216
Ian Rogers97b52f82014-08-14 11:34:07 -0700217 const mirror::Class::Status status_;
Brian Carlstromba150c32013-08-27 17:31:03 -0700218
Ian Rogers97b52f82014-08-14 11:34:07 -0700219 const OatClassType type_;
Brian Carlstromba150c32013-08-27 17:31:03 -0700220
Ian Rogers97b52f82014-08-14 11:34:07 -0700221 const uint32_t* const bitmap_;
Brian Carlstromba150c32013-08-27 17:31:03 -0700222
Ian Rogers97b52f82014-08-14 11:34:07 -0700223 const OatMethodOffsets* const methods_pointer_;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700224
Richard Uhler07b3c232015-03-31 15:57:54 -0700225 friend class art::OatDexFile;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700226 };
Richard Uhler9a37efc2016-08-05 16:32:55 -0700227
228 // Get the OatDexFile for the given dex_location within this oat file.
229 // If dex_location_checksum is non-null, the OatDexFile will only be
230 // returned if it has a matching checksum.
231 // If error_msg is non-null and no OatDexFile is returned, error_msg will
232 // be updated with a description of why no OatDexFile was returned.
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700233 const OatDexFile* GetOatDexFile(const char* dex_location,
Brian Carlstrom756ee4e2013-10-03 15:46:12 -0700234 const uint32_t* const dex_location_checksum,
Richard Uhler9a37efc2016-08-05 16:32:55 -0700235 /*out*/std::string* error_msg = nullptr) const
Mathieu Chartier90443472015-07-16 20:32:27 -0700236 REQUIRES(!secondary_lookup_lock_);
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700237
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100238 const std::vector<const OatDexFile*>& GetOatDexFiles() const {
239 return oat_dex_files_storage_;
240 }
Brian Carlstrome24fa612011-09-29 00:53:55 -0700241
Ian Rogers30fab402012-01-23 15:43:46 -0800242 size_t Size() const {
243 return End() - Begin();
Brian Carlstrome24fa612011-09-29 00:53:55 -0700244 }
245
Mingyao Yang6ea1a0e2016-01-29 12:12:49 -0800246 bool Contains(const void* p) const {
247 return p >= Begin() && p < End();
248 }
249
Vladimir Marko5c42c292015-02-25 12:02:49 +0000250 size_t BssSize() const {
251 return BssEnd() - BssBegin();
252 }
253
David Brazdil7b49e6c2016-09-01 11:06:18 +0100254 size_t DexSize() const {
255 return DexEnd() - DexBegin();
256 }
257
Ian Rogers13735952014-10-08 12:43:28 -0700258 const uint8_t* Begin() const;
259 const uint8_t* End() const;
Alex Light53cb16b2014-06-12 11:26:29 -0700260
Vladimir Marko5c42c292015-02-25 12:02:49 +0000261 const uint8_t* BssBegin() const;
262 const uint8_t* BssEnd() const;
263
David Brazdil7b49e6c2016-09-01 11:06:18 +0100264 const uint8_t* DexBegin() const;
265 const uint8_t* DexEnd() const;
266
Richard Uhlere5fed032015-03-18 08:21:11 -0700267 // Returns the absolute dex location for the encoded relative dex location.
268 //
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700269 // If not null, abs_dex_location is used to resolve the absolute dex
Richard Uhlere5fed032015-03-18 08:21:11 -0700270 // location of relative dex locations encoded in the oat file.
271 // For example, given absolute location "/data/app/foo/base.apk", encoded
272 // dex locations "base.apk", "base.apk:classes2.dex", etc. would be resolved
273 // to "/data/app/foo/base.apk", "/data/app/foo/base.apk:classes2.dex", etc.
274 // Relative encoded dex locations that don't match the given abs_dex_location
275 // are left unchanged.
276 static std::string ResolveRelativeEncodedDexLocation(
277 const char* abs_dex_location, const std::string& rel_dex_location);
278
Andreas Gampe7848da42015-04-09 11:15:04 -0700279 // Create a dependency list (dex locations and checksums) for the given dex files.
280 static std::string EncodeDexFileDependencies(const std::vector<const DexFile*>& dex_files);
281
282 // Check the given dependency list against their dex files - thus the name "Static," this does
283 // not check the class-loader environment, only whether there have been file updates.
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700284 static bool CheckStaticDexFileDependencies(const char* dex_dependencies, std::string* msg);
Andreas Gampe7848da42015-04-09 11:15:04 -0700285
286 // Get the dex locations of a dependency list. Note: this is *not* cleaned for synthetic
287 // locations of multidex files.
288 static bool GetDexLocationsFromDependencies(const char* dex_dependencies,
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700289 std::vector<std::string>* locations);
Andreas Gampe7848da42015-04-09 11:15:04 -0700290
Andreas Gampe049cff02015-12-01 23:27:12 -0800291 protected:
292 OatFile(const std::string& filename, bool executable);
293
Brian Carlstrome24fa612011-09-29 00:53:55 -0700294 private:
Brian Carlstrome24fa612011-09-29 00:53:55 -0700295 // The oat file name.
296 //
297 // The image will embed this to link its associated oat file.
298 const std::string location_;
299
David Brazdil7b49e6c2016-09-01 11:06:18 +0100300 // Pointer to the Vdex file with the Dex files for this Oat file.
301 std::unique_ptr<VdexFile> vdex_;
302
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800303 // Pointer to OatHeader.
Ian Rogers13735952014-10-08 12:43:28 -0700304 const uint8_t* begin_;
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800305
306 // Pointer to end of oat region for bounds checking.
Ian Rogers13735952014-10-08 12:43:28 -0700307 const uint8_t* end_;
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800308
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700309 // Pointer to the .bss section, if present, otherwise null.
Vladimir Marko06d7aaa2015-10-16 11:23:41 +0100310 uint8_t* bss_begin_;
Vladimir Marko5c42c292015-02-25 12:02:49 +0000311
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700312 // Pointer to the end of the .bss section, if present, otherwise null.
Vladimir Marko06d7aaa2015-10-16 11:23:41 +0100313 uint8_t* bss_end_;
Vladimir Marko5c42c292015-02-25 12:02:49 +0000314
Alex Light9dcc4572014-08-14 14:16:26 -0700315 // Was this oat_file loaded executable?
316 const bool is_executable_;
317
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100318 // Owning storage for the OatDexFile objects.
319 std::vector<const OatDexFile*> oat_dex_files_storage_;
320
Vladimir Marko3f5838d2014-08-07 18:07:18 +0100321 // NOTE: We use a StringPiece as the key type to avoid a memory allocation on every
322 // lookup with a const char* key. The StringPiece doesn't own its backing storage,
323 // therefore we're using the OatDexFile::dex_file_location_ as the backing storage
324 // for keys in oat_dex_files_ and the string_cache_ entries for the backing storage
325 // of keys in secondary_oat_dex_files_ and oat_dex_files_by_canonical_location_.
Mathieu Chartierbad02672014-08-25 13:08:22 -0700326 typedef AllocationTrackingSafeMap<StringPiece, const OatDexFile*, kAllocatorTagOatFile> Table;
Vladimir Marko3f5838d2014-08-07 18:07:18 +0100327
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100328 // Map each location and canonical location (if different) retrieved from the
329 // oat file to its OatDexFile. This map doesn't change after it's constructed in Setup()
330 // and therefore doesn't need any locking and provides the cheapest dex file lookup
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700331 // for GetOatDexFile() for a very frequent use case. Never contains a null value.
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100332 Table oat_dex_files_;
Vladimir Marko3f5838d2014-08-07 18:07:18 +0100333
334 // Lock guarding all members needed for secondary lookup in GetOatDexFile().
335 mutable Mutex secondary_lookup_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
336
337 // If the primary oat_dex_files_ lookup fails, use a secondary map. This map stores
338 // the results of all previous secondary lookups, whether successful (non-null) or
339 // failed (null). If it doesn't contain an entry we need to calculate the canonical
340 // location and use oat_dex_files_by_canonical_location_.
341 mutable Table secondary_oat_dex_files_ GUARDED_BY(secondary_lookup_lock_);
342
Vladimir Marko3f5838d2014-08-07 18:07:18 +0100343 // Cache of strings. Contains the backing storage for keys in the secondary_oat_dex_files_
344 // and the lazily initialized oat_dex_files_by_canonical_location_.
345 // NOTE: We're keeping references to contained strings in form of StringPiece and adding
346 // new strings to the end. The adding of a new element must not touch any previously stored
347 // elements. std::list<> and std::deque<> satisfy this requirement, std::vector<> doesn't.
348 mutable std::list<std::string> string_cache_ GUARDED_BY(secondary_lookup_lock_);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700349
Mathieu Chartier5351da02016-02-17 16:19:53 -0800350 friend class gc::collector::DummyOatFile; // For modifying begin_ and end_.
Brian Carlstrome24fa612011-09-29 00:53:55 -0700351 friend class OatClass;
Richard Uhler07b3c232015-03-31 15:57:54 -0700352 friend class art::OatDexFile;
Elliott Hughese3c845c2012-02-28 17:23:01 -0800353 friend class OatDumper; // For GetBase and GetLimit
Andreas Gampe049cff02015-12-01 23:27:12 -0800354 friend class OatFileBase;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700355 DISALLOW_COPY_AND_ASSIGN(OatFile);
356};
357
Richard Uhler07b3c232015-03-31 15:57:54 -0700358// OatDexFile should be an inner class of OatFile. Unfortunately, C++ doesn't
359// support forward declarations of inner classes, and we want to
360// forward-declare OatDexFile so that we can store an opaque pointer to an
361// OatDexFile in DexFile.
362class OatDexFile FINAL {
363 public:
364 // Opens the DexFile referred to by this OatDexFile from within the containing OatFile.
Igor Murashkinb1d8c312015-08-04 11:18:43 -0700365 std::unique_ptr<const DexFile> OpenDexFile(std::string* error_msg) const;
Richard Uhler07b3c232015-03-31 15:57:54 -0700366
367 const OatFile* GetOatFile() const {
368 return oat_file_;
369 }
370
371 // Returns the size of the DexFile refered to by this OatDexFile.
372 size_t FileSize() const;
373
374 // Returns original path of DexFile that was the source of this OatDexFile.
375 const std::string& GetDexFileLocation() const {
376 return dex_file_location_;
377 }
378
379 // Returns the canonical location of DexFile that was the source of this OatDexFile.
380 const std::string& GetCanonicalDexFileLocation() const {
381 return canonical_dex_file_location_;
382 }
383
384 // Returns checksum of original DexFile that was the source of this OatDexFile;
385 uint32_t GetDexFileLocationChecksum() const {
386 return dex_file_location_checksum_;
387 }
388
389 // Returns the OatClass for the class specified by the given DexFile class_def_index.
390 OatFile::OatClass GetOatClass(uint16_t class_def_index) const;
391
392 // Returns the offset to the OatClass information. Most callers should use GetOatClass.
393 uint32_t GetOatClassOffset(uint16_t class_def_index) const;
394
Vladimir Marko06d7aaa2015-10-16 11:23:41 +0100395 uint8_t* GetDexCacheArrays() const {
Vladimir Marko09d09432015-09-08 13:47:48 +0100396 return dex_cache_arrays_;
397 }
398
Artem Udovichenkod9786b02015-10-14 16:36:55 +0300399 const uint8_t* GetLookupTableData() const {
400 return lookup_table_data_;
401 }
402
Andreas Gampe2ba88952016-04-29 17:52:07 -0700403 const uint8_t* GetDexFilePointer() const {
404 return dex_file_pointer_;
405 }
406
Richard Uhler07b3c232015-03-31 15:57:54 -0700407 ~OatDexFile();
408
409 private:
410 OatDexFile(const OatFile* oat_file,
411 const std::string& dex_file_location,
412 const std::string& canonical_dex_file_location,
413 uint32_t dex_file_checksum,
414 const uint8_t* dex_file_pointer,
Artem Udovichenkod9786b02015-10-14 16:36:55 +0300415 const uint8_t* lookup_table_data,
Vladimir Marko09d09432015-09-08 13:47:48 +0100416 const uint32_t* oat_class_offsets_pointer,
Vladimir Marko06d7aaa2015-10-16 11:23:41 +0100417 uint8_t* dex_cache_arrays);
Richard Uhler07b3c232015-03-31 15:57:54 -0700418
419 const OatFile* const oat_file_;
420 const std::string dex_file_location_;
421 const std::string canonical_dex_file_location_;
422 const uint32_t dex_file_location_checksum_;
423 const uint8_t* const dex_file_pointer_;
Artem Udovichenkod9786b02015-10-14 16:36:55 +0300424 const uint8_t* lookup_table_data_;
Richard Uhler07b3c232015-03-31 15:57:54 -0700425 const uint32_t* const oat_class_offsets_pointer_;
Vladimir Marko06d7aaa2015-10-16 11:23:41 +0100426 uint8_t* const dex_cache_arrays_;
Richard Uhler07b3c232015-03-31 15:57:54 -0700427
428 friend class OatFile;
Andreas Gampe049cff02015-12-01 23:27:12 -0800429 friend class OatFileBase;
Richard Uhler07b3c232015-03-31 15:57:54 -0700430 DISALLOW_COPY_AND_ASSIGN(OatDexFile);
431};
432
Brian Carlstrome24fa612011-09-29 00:53:55 -0700433} // namespace art
434
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700435#endif // ART_RUNTIME_OAT_FILE_H_