Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 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 Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_OAT_FILE_H_ |
| 18 | #define ART_RUNTIME_OAT_FILE_H_ |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 19 | |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 20 | #include <list> |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 21 | #include <string> |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 24 | #include "base/mutex.h" |
Vladimir Marko | 539690a | 2014-06-05 18:36:42 +0100 | [diff] [blame] | 25 | #include "base/stringpiece.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 26 | #include "dex_file.h" |
| 27 | #include "invoke_type.h" |
| 28 | #include "mem_map.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 29 | #include "mirror/class.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | #include "oat.h" |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 31 | #include "os.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 35 | class BitVector; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 36 | class ElfFile; |
| 37 | class MemMap; |
| 38 | class OatMethodOffsets; |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 39 | class OatHeader; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 40 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 41 | class OatFile { |
| 42 | public: |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 43 | // Open an oat file. Returns NULL on failure. Requested base can |
| 44 | // optionally be used to request where the file should be loaded. |
| 45 | static OatFile* Open(const std::string& filename, |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 46 | const std::string& location, |
Brian Carlstrom | f1d3455 | 2013-07-12 20:22:23 -0700 | [diff] [blame] | 47 | byte* requested_base, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 48 | bool executable, |
| 49 | std::string* error_msg); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 50 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 51 | // Open an oat file from an already opened File. |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 52 | // Does not use dlopen underneath so cannot be used for runtime use |
| 53 | // where relocations may be required. Currently used from |
| 54 | // ImageWriter which wants to open a writable version from an existing |
| 55 | // file descriptor for patching. |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 56 | static OatFile* OpenWritable(File* file, const std::string& location, std::string* error_msg); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 57 | // Opens an oat file from an already opened File. Maps it PROT_READ, MAP_PRIVATE. |
| 58 | static OatFile* OpenReadable(File* file, const std::string& location, std::string* error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 59 | |
| 60 | // Open an oat file backed by a std::vector with the given location. |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 61 | static OatFile* OpenMemory(std::vector<uint8_t>& oat_contents, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 62 | const std::string& location, |
| 63 | std::string* error_msg); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 64 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 65 | ~OatFile(); |
| 66 | |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 67 | ElfFile* GetElfFile() const { |
| 68 | CHECK_NE(reinterpret_cast<uintptr_t>(elf_file_.get()), reinterpret_cast<uintptr_t>(nullptr)) |
| 69 | << "Cannot get an elf file from " << GetLocation(); |
| 70 | return elf_file_.get(); |
| 71 | } |
| 72 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 73 | const std::string& GetLocation() const { |
| 74 | return location_; |
| 75 | } |
| 76 | |
| 77 | const OatHeader& GetOatHeader() const; |
| 78 | |
| 79 | class OatDexFile; |
| 80 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 81 | class OatMethod { |
| 82 | public: |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 83 | void LinkMethod(mirror::ArtMethod* method) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 84 | |
| 85 | uint32_t GetCodeOffset() const { |
| 86 | return code_offset_; |
| 87 | } |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 88 | uint32_t GetNativeGcMapOffset() const { |
| 89 | return native_gc_map_offset_; |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 90 | } |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 91 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 92 | const void* GetPortableCode() const { |
| 93 | // TODO: encode whether code is portable/quick in flags within OatMethod. |
| 94 | if (kUsePortableCompiler) { |
| 95 | return GetOatPointer<const void*>(code_offset_); |
| 96 | } else { |
| 97 | return nullptr; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | const void* GetQuickCode() const { |
| 102 | if (kUsePortableCompiler) { |
| 103 | return nullptr; |
| 104 | } else { |
| 105 | return GetOatPointer<const void*>(code_offset_); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | uint32_t GetPortableCodeSize() const { |
| 110 | // TODO: With Quick, we store the size before the code. With Portable, the code is in a .o |
| 111 | // file we don't manage ourselves. ELF symbols do have a concept of size, so we could capture |
| 112 | // that and store it somewhere, such as the OatMethod. |
| 113 | return 0; |
| 114 | } |
| 115 | uint32_t GetQuickCodeSize() const; |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 116 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 117 | const uint8_t* GetNativeGcMap() const { |
| 118 | return GetOatPointer<const uint8_t*>(native_gc_map_offset_); |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 119 | } |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 120 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 121 | size_t GetFrameSizeInBytes() const; |
| 122 | uint32_t GetCoreSpillMask() const; |
| 123 | uint32_t GetFpSpillMask() const; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 124 | uint32_t GetMappingTableOffset() const; |
| 125 | uint32_t GetVmapTableOffset() const; |
| 126 | const uint8_t* GetMappingTable() const; |
| 127 | const uint8_t* GetVmapTable() const; |
| 128 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 129 | ~OatMethod(); |
| 130 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 131 | // Create an OatMethod with offsets relative to the given base address |
| 132 | OatMethod(const byte* base, |
| 133 | const uint32_t code_offset, |
Brian Carlstrom | 6a47b9d | 2013-05-17 10:58:25 -0700 | [diff] [blame] | 134 | const uint32_t gc_map_offset); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 135 | |
Nicolas Geoffray | 4fcdc94 | 2014-07-22 10:48:00 +0100 | [diff] [blame^] | 136 | OatMethod() {} |
| 137 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 138 | private: |
| 139 | template<class T> |
| 140 | T GetOatPointer(uint32_t offset) const { |
| 141 | if (offset == 0) { |
| 142 | return NULL; |
| 143 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 144 | return reinterpret_cast<T>(begin_ + offset); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 147 | const byte* begin_; |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 148 | |
| 149 | uint32_t code_offset_; |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 150 | uint32_t native_gc_map_offset_; |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 151 | |
| 152 | friend class OatClass; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 153 | }; |
| 154 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 155 | class OatClass { |
| 156 | public: |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 157 | mirror::Class::Status GetStatus() const { |
| 158 | return status_; |
| 159 | } |
| 160 | |
| 161 | OatClassType GetType() const { |
| 162 | return type_; |
| 163 | } |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 164 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 165 | // Get the OatMethod entry based on its index into the class |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 166 | // defintion. direct methods come first, followed by virtual |
| 167 | // methods. note that runtime created methods such as miranda |
| 168 | // methods are not included. |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 169 | const OatMethod GetOatMethod(uint32_t method_index) const; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 170 | |
Nicolas Geoffray | 4fcdc94 | 2014-07-22 10:48:00 +0100 | [diff] [blame^] | 171 | OatClass() {} |
| 172 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 173 | private: |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 174 | OatClass(const OatFile* oat_file, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 175 | mirror::Class::Status status, |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 176 | OatClassType type, |
| 177 | uint32_t bitmap_size, |
| 178 | const uint32_t* bitmap_pointer, |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 179 | const OatMethodOffsets* methods_pointer); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 180 | |
Nicolas Geoffray | 4fcdc94 | 2014-07-22 10:48:00 +0100 | [diff] [blame^] | 181 | const OatFile* oat_file_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 182 | |
Nicolas Geoffray | 4fcdc94 | 2014-07-22 10:48:00 +0100 | [diff] [blame^] | 183 | mirror::Class::Status status_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 184 | |
Nicolas Geoffray | 4fcdc94 | 2014-07-22 10:48:00 +0100 | [diff] [blame^] | 185 | OatClassType type_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 186 | |
Nicolas Geoffray | 4fcdc94 | 2014-07-22 10:48:00 +0100 | [diff] [blame^] | 187 | const uint32_t* bitmap_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 188 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 189 | const OatMethodOffsets* methods_pointer_; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 190 | |
| 191 | friend class OatDexFile; |
| 192 | }; |
| 193 | |
| 194 | class OatDexFile { |
| 195 | public: |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 196 | // Opens the DexFile referred to by this OatDexFile from within the containing OatFile. |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 197 | const DexFile* OpenDexFile(std::string* error_msg) const; |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 198 | |
| 199 | // Returns the size of the DexFile refered to by this OatDexFile. |
Ian Rogers | 05f28c6 | 2012-10-23 18:12:13 -0700 | [diff] [blame] | 200 | size_t FileSize() const; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 201 | |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 202 | // Returns original path of DexFile that was the source of this OatDexFile. |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 203 | const std::string& GetDexFileLocation() const { |
| 204 | return dex_file_location_; |
| 205 | } |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 206 | |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 207 | // Returns checksum of original DexFile that was the source of this OatDexFile; |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 208 | uint32_t GetDexFileLocationChecksum() const { |
| 209 | return dex_file_location_checksum_; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 212 | // Returns the OatClass for the class specified by the given DexFile class_def_index. |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 213 | OatClass GetOatClass(uint16_t class_def_index) const; |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 214 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 215 | ~OatDexFile(); |
Elliott Hughes | a21039c | 2012-06-21 12:09:25 -0700 | [diff] [blame] | 216 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 217 | private: |
| 218 | OatDexFile(const OatFile* oat_file, |
Elliott Hughes | aa6a588 | 2012-01-13 19:39:16 -0800 | [diff] [blame] | 219 | const std::string& dex_file_location, |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 220 | uint32_t dex_file_checksum, |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 221 | const byte* dex_file_pointer, |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 222 | const uint32_t* oat_class_offsets_pointer); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 223 | |
Vladimir Marko | 539690a | 2014-06-05 18:36:42 +0100 | [diff] [blame] | 224 | const OatFile* const oat_file_; |
| 225 | const std::string dex_file_location_; |
| 226 | const uint32_t dex_file_location_checksum_; |
| 227 | const byte* const dex_file_pointer_; |
| 228 | const uint32_t* const oat_class_offsets_pointer_; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 229 | |
| 230 | friend class OatFile; |
| 231 | DISALLOW_COPY_AND_ASSIGN(OatDexFile); |
| 232 | }; |
| 233 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 234 | const OatDexFile* GetOatDexFile(const char* dex_location, |
Brian Carlstrom | 756ee4e | 2013-10-03 15:46:12 -0700 | [diff] [blame] | 235 | const uint32_t* const dex_location_checksum, |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 236 | bool exception_if_not_found = true) const |
| 237 | LOCKS_EXCLUDED(secondary_lookup_lock_); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 238 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 239 | std::vector<const OatDexFile*> GetOatDexFiles() const; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 240 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 241 | size_t Size() const { |
| 242 | return End() - Begin(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 245 | const byte* Begin() const; |
| 246 | const byte* End() const; |
| 247 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 248 | private: |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 249 | static void CheckLocation(const std::string& location); |
| 250 | |
| 251 | static OatFile* OpenDlopen(const std::string& elf_filename, |
| 252 | const std::string& location, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 253 | byte* requested_base, |
| 254 | std::string* error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 255 | |
| 256 | static OatFile* OpenElfFile(File* file, |
| 257 | const std::string& location, |
| 258 | byte* requested_base, |
Brian Carlstrom | f1d3455 | 2013-07-12 20:22:23 -0700 | [diff] [blame] | 259 | bool writable, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 260 | bool executable, |
| 261 | std::string* error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 262 | |
Elliott Hughes | a51a3dd | 2011-10-17 15:19:26 -0700 | [diff] [blame] | 263 | explicit OatFile(const std::string& filename); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 264 | bool Dlopen(const std::string& elf_filename, byte* requested_base, std::string* error_msg); |
| 265 | bool ElfFileOpen(File* file, byte* requested_base, bool writable, bool executable, |
| 266 | std::string* error_msg); |
| 267 | bool Setup(std::string* error_msg); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 268 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 269 | // The oat file name. |
| 270 | // |
| 271 | // The image will embed this to link its associated oat file. |
| 272 | const std::string location_; |
| 273 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 274 | // Pointer to OatHeader. |
| 275 | const byte* begin_; |
| 276 | |
| 277 | // Pointer to end of oat region for bounds checking. |
| 278 | const byte* end_; |
| 279 | |
| 280 | // Backing memory map for oat file during when opened by ElfWriter during initial compilation. |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 281 | std::unique_ptr<MemMap> mem_map_; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 282 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 283 | // Backing memory map for oat file during cross compilation. |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 284 | std::unique_ptr<ElfFile> elf_file_; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 285 | |
| 286 | // dlopen handle during runtime. |
| 287 | void* dlopen_handle_; |
| 288 | |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 289 | // NOTE: We use a StringPiece as the key type to avoid a memory allocation on every |
| 290 | // lookup with a const char* key. The StringPiece doesn't own its backing storage, |
| 291 | // therefore we're using the OatDexFile::dex_file_location_ as the backing storage |
| 292 | // for keys in oat_dex_files_ and the string_cache_ entries for the backing storage |
| 293 | // of keys in secondary_oat_dex_files_ and oat_dex_files_by_canonical_location_. |
Vladimir Marko | 539690a | 2014-06-05 18:36:42 +0100 | [diff] [blame] | 294 | typedef SafeMap<StringPiece, const OatDexFile*> Table; |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 295 | |
| 296 | // Map each plain dex file location retrieved from the oat file to its OatDexFile. |
| 297 | // This map doesn't change after it's constructed in Setup() and therefore doesn't |
| 298 | // need any locking and provides the cheapest dex file lookup for GetOatDexFile() |
| 299 | // for a very frequent use case. Never contains a nullptr value. |
| 300 | Table oat_dex_files_; // Owns the OatDexFile* values. |
| 301 | |
| 302 | // Lock guarding all members needed for secondary lookup in GetOatDexFile(). |
| 303 | mutable Mutex secondary_lookup_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 304 | |
| 305 | // If the primary oat_dex_files_ lookup fails, use a secondary map. This map stores |
| 306 | // the results of all previous secondary lookups, whether successful (non-null) or |
| 307 | // failed (null). If it doesn't contain an entry we need to calculate the canonical |
| 308 | // location and use oat_dex_files_by_canonical_location_. |
| 309 | mutable Table secondary_oat_dex_files_ GUARDED_BY(secondary_lookup_lock_); |
| 310 | |
| 311 | // Map the canonical location to an OatDexFile. This lazily constructed map is used |
| 312 | // when we're doing the secondary lookup for a given location for the first time. |
| 313 | mutable Table oat_dex_files_by_canonical_location_ GUARDED_BY(secondary_lookup_lock_); |
| 314 | |
| 315 | // Cache of strings. Contains the backing storage for keys in the secondary_oat_dex_files_ |
| 316 | // and the lazily initialized oat_dex_files_by_canonical_location_. |
| 317 | // NOTE: We're keeping references to contained strings in form of StringPiece and adding |
| 318 | // new strings to the end. The adding of a new element must not touch any previously stored |
| 319 | // elements. std::list<> and std::deque<> satisfy this requirement, std::vector<> doesn't. |
| 320 | mutable std::list<std::string> string_cache_ GUARDED_BY(secondary_lookup_lock_); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 321 | |
| 322 | friend class OatClass; |
| 323 | friend class OatDexFile; |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 324 | friend class OatDumper; // For GetBase and GetLimit |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 325 | DISALLOW_COPY_AND_ASSIGN(OatFile); |
| 326 | }; |
| 327 | |
| 328 | } // namespace art |
| 329 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 330 | #endif // ART_RUNTIME_OAT_FILE_H_ |