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> |
Vladimir Marko | 59ae4f9 | 2019-02-04 14:06:02 +0000 | [diff] [blame] | 22 | #include <string_view> |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 23 | #include <vector> |
| 24 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 25 | #include "base/array_ref.h" |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 26 | #include "base/mutex.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 27 | #include "base/os.h" |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 28 | #include "base/safe_map.h" |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 29 | #include "base/tracking_safe_map.h" |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 30 | #include "class_status.h" |
Vladimir Marko | 97d7e1c | 2016-10-04 14:44:28 +0100 | [diff] [blame] | 31 | #include "compiler_filter.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 32 | #include "dex/dex_file_layout.h" |
David Sehr | 9c4a015 | 2018-04-05 12:23:54 -0700 | [diff] [blame] | 33 | #include "dex/type_lookup_table.h" |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 34 | #include "dex/utf.h" |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 35 | #include "index_bss_mapping.h" |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 36 | #include "mirror/object.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 37 | #include "oat.h" |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 38 | |
| 39 | namespace art { |
| 40 | |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 41 | class BitVector; |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 42 | class DexFile; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 43 | class ElfFile; |
Mathieu Chartier | 120aa28 | 2017-08-05 16:03:03 -0700 | [diff] [blame] | 44 | class DexLayoutSections; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 45 | template <class MirrorType> class GcRoot; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 46 | class MemMap; |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 47 | class OatDexFile; |
Andreas Gampe | 513061a | 2017-06-01 09:17:34 -0700 | [diff] [blame] | 48 | class OatHeader; |
| 49 | class OatMethodOffsets; |
| 50 | class OatQuickMethodHeader; |
Vladimir Marko | 97d7e1c | 2016-10-04 14:44:28 +0100 | [diff] [blame] | 51 | class VdexFile; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 52 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 53 | namespace dex { |
| 54 | struct ClassDef; |
| 55 | } // namespace dex |
| 56 | |
Mathieu Chartier | 5351da0 | 2016-02-17 16:19:53 -0800 | [diff] [blame] | 57 | namespace gc { |
| 58 | namespace collector { |
| 59 | class DummyOatFile; |
| 60 | } // namespace collector |
| 61 | } // namespace gc |
| 62 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 63 | // Runtime representation of the OAT file format which holds compiler output. |
| 64 | // The class opens an OAT file from storage and maps it to memory, typically with |
| 65 | // dlopen and provides access to its internal data structures (see OatWriter for |
| 66 | // for more details about the OAT format). |
| 67 | // In the process of loading OAT, the class also loads the associated VDEX file |
| 68 | // with the input DEX files (see VdexFile for details about the VDEX format). |
| 69 | // The raw DEX data are accessible transparently through the OatDexFile objects. |
| 70 | |
Andreas Gampe | 049cff0 | 2015-12-01 23:27:12 -0800 | [diff] [blame] | 71 | class OatFile { |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 72 | public: |
Jeff Hao | f0192c8 | 2016-03-28 20:39:50 -0700 | [diff] [blame] | 73 | // Special classpath that skips shared library check. |
| 74 | static constexpr const char* kSpecialSharedLibrary = "&"; |
| 75 | |
Alex Light | 84d7605 | 2014-08-22 17:49:35 -0700 | [diff] [blame] | 76 | // Opens an oat file contained within the given elf file. This is always opened as |
| 77 | // non-executable at the moment. |
Nicolas Geoffray | 3002509 | 2018-04-19 14:43:29 +0100 | [diff] [blame] | 78 | static OatFile* OpenWithElfFile(int zip_fd, |
| 79 | ElfFile* elf_file, |
David Brazdil | c93b3be | 2016-09-12 18:49:58 +0100 | [diff] [blame] | 80 | VdexFile* vdex_file, |
| 81 | const std::string& location, |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 82 | const char* abs_dex_location, |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 83 | std::string* error_msg); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 84 | // Open an oat file. Returns null on failure. Requested base can |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 85 | // optionally be used to request where the file should be loaded. |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 86 | // See the ResolveRelativeEncodedDexLocation for a description of how the |
| 87 | // abs_dex_location argument is used. |
Nicolas Geoffray | 3002509 | 2018-04-19 14:43:29 +0100 | [diff] [blame] | 88 | static OatFile* Open(int zip_fd, |
| 89 | const std::string& filename, |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 90 | const std::string& location, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 91 | bool executable, |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 92 | bool low_4gb, |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 93 | const char* abs_dex_location, |
Vladimir Marko | c09cd05 | 2018-08-23 16:36:36 +0100 | [diff] [blame] | 94 | /*inout*/MemMap* reservation, // Where to load if not null. |
| 95 | /*out*/std::string* error_msg); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 96 | |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 97 | // Similar to OatFile::Open(const std::string...), but accepts input vdex and |
Nicolas Geoffray | 3002509 | 2018-04-19 14:43:29 +0100 | [diff] [blame] | 98 | // odex files as file descriptors. We also take zip_fd in case the vdex does not |
| 99 | // contain the dex code, and we need to read it from the zip file. |
| 100 | static OatFile* Open(int zip_fd, |
| 101 | int vdex_fd, |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 102 | int oat_fd, |
| 103 | const std::string& oat_location, |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 104 | bool executable, |
| 105 | bool low_4gb, |
| 106 | const char* abs_dex_location, |
Vladimir Marko | c09cd05 | 2018-08-23 16:36:36 +0100 | [diff] [blame] | 107 | /*inout*/MemMap* reservation, // Where to load if not null. |
| 108 | /*out*/std::string* error_msg); |
Shubham Ajmera | b22dea0 | 2017-10-04 18:36:41 -0700 | [diff] [blame] | 109 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 110 | // Open an oat file from an already opened File. |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 111 | // Does not use dlopen underneath so cannot be used for runtime use |
| 112 | // where relocations may be required. Currently used from |
| 113 | // ImageWriter which wants to open a writable version from an existing |
| 114 | // file descriptor for patching. |
Nicolas Geoffray | 3002509 | 2018-04-19 14:43:29 +0100 | [diff] [blame] | 115 | static OatFile* OpenWritable(int zip_fd, |
| 116 | File* file, |
| 117 | const std::string& location, |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 118 | const char* abs_dex_location, |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 119 | std::string* error_msg); |
Nicolas Geoffray | 58cc1cb | 2017-11-20 13:27:29 +0000 | [diff] [blame] | 120 | // Open an oat file from an already opened File. Maps it PROT_READ, MAP_PRIVATE. |
Nicolas Geoffray | 3002509 | 2018-04-19 14:43:29 +0100 | [diff] [blame] | 121 | static OatFile* OpenReadable(int zip_fd, |
| 122 | File* file, |
| 123 | const std::string& location, |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 124 | const char* abs_dex_location, |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 125 | std::string* error_msg); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 126 | |
Andreas Gampe | 049cff0 | 2015-12-01 23:27:12 -0800 | [diff] [blame] | 127 | virtual ~OatFile(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 128 | |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 129 | bool IsExecutable() const { |
| 130 | return is_executable_; |
| 131 | } |
| 132 | |
Sebastien Hertz | 0de1133 | 2015-05-13 12:14:05 +0200 | [diff] [blame] | 133 | // Indicates whether the oat file was compiled with full debugging capability. |
| 134 | bool IsDebuggable() const; |
| 135 | |
Andreas Gampe | 29d38e7 | 2016-03-23 15:31:51 +0000 | [diff] [blame] | 136 | CompilerFilter::Filter GetCompilerFilter() const; |
Calin Juravle | b077e15 | 2016-02-18 18:47:37 +0000 | [diff] [blame] | 137 | |
Calin Juravle | 44e5efa | 2017-09-12 00:54:26 -0700 | [diff] [blame] | 138 | std::string GetClassLoaderContext() const; |
| 139 | |
Calin Juravle | 0e09dfc | 2018-02-12 19:01:09 -0800 | [diff] [blame] | 140 | const char* GetCompilationReason() const; |
| 141 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 142 | const std::string& GetLocation() const { |
| 143 | return location_; |
| 144 | } |
| 145 | |
| 146 | const OatHeader& GetOatHeader() const; |
| 147 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 148 | class OatMethod final { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 149 | public: |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 150 | void LinkMethod(ArtMethod* method) const; |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 151 | |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 152 | uint32_t GetCodeOffset() const; |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 153 | |
Nicolas Geoffray | c04c800 | 2015-07-14 11:37:54 +0100 | [diff] [blame] | 154 | const void* GetQuickCode() const; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 155 | |
| 156 | // Returns size of quick code. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 157 | uint32_t GetQuickCodeSize() const; |
Nicolas Geoffray | 5708376 | 2019-03-05 09:24:45 +0000 | [diff] [blame] | 158 | uint32_t GetQuickCodeSizeOffset() const; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 159 | |
| 160 | // Returns OatQuickMethodHeader for debugging. Most callers should |
| 161 | // use more specific methods such as GetQuickCodeSize. |
| 162 | const OatQuickMethodHeader* GetOatQuickMethodHeader() const; |
| 163 | uint32_t GetOatQuickMethodHeaderOffset() const; |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 164 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 165 | size_t GetFrameSizeInBytes() const; |
| 166 | uint32_t GetCoreSpillMask() const; |
| 167 | uint32_t GetFpSpillMask() const; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 168 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 169 | const uint8_t* GetVmapTable() const; |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 170 | uint32_t GetVmapTableOffset() const; |
| 171 | uint32_t GetVmapTableOffsetOffset() const; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 172 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 173 | // Create an OatMethod with offsets relative to the given base address |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 174 | OatMethod(const uint8_t* base, const uint32_t code_offset) |
| 175 | : begin_(base), code_offset_(code_offset) { |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 176 | } |
Andreas Gampe | 758a801 | 2015-04-03 21:28:42 -0700 | [diff] [blame] | 177 | OatMethod(const OatMethod&) = default; |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 178 | ~OatMethod() {} |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 179 | |
Andreas Gampe | 758a801 | 2015-04-03 21:28:42 -0700 | [diff] [blame] | 180 | OatMethod& operator=(const OatMethod&) = default; |
| 181 | |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 182 | // A representation of an invalid OatMethod, used when an OatMethod or OatClass can't be found. |
| 183 | // See ClassLinker::FindOatMethodFor. |
| 184 | static const OatMethod Invalid() { |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 185 | return OatMethod(nullptr, -1); |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 186 | } |
Nicolas Geoffray | 4fcdc94 | 2014-07-22 10:48:00 +0100 | [diff] [blame] | 187 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 188 | private: |
| 189 | template<class T> |
| 190 | T GetOatPointer(uint32_t offset) const { |
| 191 | if (offset == 0) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 192 | return nullptr; |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 193 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 194 | return reinterpret_cast<T>(begin_ + offset); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 197 | const uint8_t* begin_; |
| 198 | uint32_t code_offset_; |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 199 | |
| 200 | friend class OatClass; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 201 | }; |
| 202 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 203 | class OatClass final { |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 204 | public: |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 205 | ClassStatus GetStatus() const { |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 206 | return status_; |
| 207 | } |
| 208 | |
| 209 | OatClassType GetType() const { |
| 210 | return type_; |
| 211 | } |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 212 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 213 | // Get the OatMethod entry based on its index into the class |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 214 | // defintion. Direct methods come first, followed by virtual |
| 215 | // methods. Note that runtime created methods such as miranda |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 216 | // methods are not included. |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 217 | const OatMethod GetOatMethod(uint32_t method_index) const; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 218 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 219 | // Return a pointer to the OatMethodOffsets for the requested |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 220 | // method_index, or null if none is present. Note that most |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 221 | // callers should use GetOatMethod. |
| 222 | const OatMethodOffsets* GetOatMethodOffsets(uint32_t method_index) const; |
| 223 | |
| 224 | // Return the offset from the start of the OatFile to the |
| 225 | // OatMethodOffsets for the requested method_index, or 0 if none |
| 226 | // is present. Note that most callers should use GetOatMethod. |
| 227 | uint32_t GetOatMethodOffsetsOffset(uint32_t method_index) const; |
| 228 | |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 229 | // A representation of an invalid OatClass, used when an OatClass can't be found. |
Vladimir Marko | 97d7e1c | 2016-10-04 14:44:28 +0100 | [diff] [blame] | 230 | // See FindOatClass(). |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 231 | static OatClass Invalid() { |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 232 | return OatClass(/* oat_file= */ nullptr, |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 233 | ClassStatus::kErrorUnresolved, |
Vladimir Marko | 72ab684 | 2017-01-20 19:32:50 +0000 | [diff] [blame] | 234 | kOatClassNoneCompiled, |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 235 | /* bitmap_size= */ 0, |
| 236 | /* bitmap_pointer= */ nullptr, |
| 237 | /* methods_pointer= */ nullptr); |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 238 | } |
Nicolas Geoffray | 4fcdc94 | 2014-07-22 10:48:00 +0100 | [diff] [blame] | 239 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 240 | private: |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 241 | OatClass(const OatFile* oat_file, |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 242 | ClassStatus status, |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 243 | OatClassType type, |
| 244 | uint32_t bitmap_size, |
| 245 | const uint32_t* bitmap_pointer, |
Brian Carlstrom | 0755ec5 | 2012-01-11 15:19:46 -0800 | [diff] [blame] | 246 | const OatMethodOffsets* methods_pointer); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 247 | |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 248 | const OatFile* const oat_file_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 249 | |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 250 | const ClassStatus status_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 251 | |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 252 | const OatClassType type_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 253 | |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 254 | const uint32_t* const bitmap_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 255 | |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 256 | const OatMethodOffsets* const methods_pointer_; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 257 | |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 258 | friend class art::OatDexFile; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 259 | }; |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 260 | |
| 261 | // Get the OatDexFile for the given dex_location within this oat file. |
| 262 | // If dex_location_checksum is non-null, the OatDexFile will only be |
| 263 | // returned if it has a matching checksum. |
| 264 | // If error_msg is non-null and no OatDexFile is returned, error_msg will |
| 265 | // be updated with a description of why no OatDexFile was returned. |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 266 | const OatDexFile* GetOatDexFile(const char* dex_location, |
Brian Carlstrom | 756ee4e | 2013-10-03 15:46:12 -0700 | [diff] [blame] | 267 | const uint32_t* const dex_location_checksum, |
Richard Uhler | 9a37efc | 2016-08-05 16:32:55 -0700 | [diff] [blame] | 268 | /*out*/std::string* error_msg = nullptr) const |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 269 | REQUIRES(!secondary_lookup_lock_); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 270 | |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 271 | const std::vector<const OatDexFile*>& GetOatDexFiles() const { |
| 272 | return oat_dex_files_storage_; |
| 273 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 274 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 275 | size_t Size() const { |
| 276 | return End() - Begin(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Mingyao Yang | 6ea1a0e | 2016-01-29 12:12:49 -0800 | [diff] [blame] | 279 | bool Contains(const void* p) const { |
| 280 | return p >= Begin() && p < End(); |
| 281 | } |
| 282 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 283 | size_t DataBimgRelRoSize() const { |
| 284 | return DataBimgRelRoEnd() - DataBimgRelRoBegin(); |
| 285 | } |
| 286 | |
Vladimir Marko | 5c42c29 | 2015-02-25 12:02:49 +0000 | [diff] [blame] | 287 | size_t BssSize() const { |
| 288 | return BssEnd() - BssBegin(); |
| 289 | } |
| 290 | |
David Srbecky | ec2cdf4 | 2017-12-08 16:21:25 +0000 | [diff] [blame] | 291 | size_t VdexSize() const { |
| 292 | return VdexEnd() - VdexBegin(); |
| 293 | } |
| 294 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 295 | size_t BssMethodsOffset() const { |
| 296 | // Note: This is used only for symbolizer and needs to return a valid .bss offset. |
| 297 | return (bss_methods_ != nullptr) ? bss_methods_ - BssBegin() : BssRootsOffset(); |
| 298 | } |
| 299 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 300 | size_t BssRootsOffset() const { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 301 | // Note: This is used only for symbolizer and needs to return a valid .bss offset. |
| 302 | return (bss_roots_ != nullptr) ? bss_roots_ - BssBegin() : BssSize(); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 303 | } |
| 304 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 305 | size_t DexSize() const { |
| 306 | return DexEnd() - DexBegin(); |
| 307 | } |
| 308 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 309 | const uint8_t* Begin() const; |
| 310 | const uint8_t* End() const; |
Alex Light | 53cb16b | 2014-06-12 11:26:29 -0700 | [diff] [blame] | 311 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 312 | const uint8_t* DataBimgRelRoBegin() const { return data_bimg_rel_ro_begin_; } |
| 313 | const uint8_t* DataBimgRelRoEnd() const { return data_bimg_rel_ro_end_; } |
Vladimir Marko | 5c42c29 | 2015-02-25 12:02:49 +0000 | [diff] [blame] | 314 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 315 | const uint8_t* BssBegin() const { return bss_begin_; } |
| 316 | const uint8_t* BssEnd() const { return bss_end_; } |
| 317 | |
| 318 | const uint8_t* VdexBegin() const { return vdex_begin_; } |
| 319 | const uint8_t* VdexEnd() const { return vdex_end_; } |
David Srbecky | ec2cdf4 | 2017-12-08 16:21:25 +0000 | [diff] [blame] | 320 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 321 | const uint8_t* DexBegin() const; |
| 322 | const uint8_t* DexEnd() const; |
| 323 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 324 | ArrayRef<const uint32_t> GetBootImageRelocations() const; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 325 | ArrayRef<ArtMethod*> GetBssMethods() const; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 326 | ArrayRef<GcRoot<mirror::Object>> GetBssGcRoots() const; |
| 327 | |
Vladimir Marko | 1cedb4a | 2019-02-06 14:13:28 +0000 | [diff] [blame] | 328 | // Initialize relocation sections (.data.bimg.rel.ro and .bss). |
| 329 | void InitializeRelocations() const; |
| 330 | |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 331 | // Returns the absolute dex location for the encoded relative dex location. |
| 332 | // |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 333 | // If not null, abs_dex_location is used to resolve the absolute dex |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 334 | // location of relative dex locations encoded in the oat file. |
| 335 | // For example, given absolute location "/data/app/foo/base.apk", encoded |
Calin Juravle | a308a32 | 2017-07-18 16:51:51 -0700 | [diff] [blame] | 336 | // dex locations "base.apk", "base.apk!classes2.dex", etc. would be resolved |
| 337 | // to "/data/app/foo/base.apk", "/data/app/foo/base.apk!classes2.dex", etc. |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 338 | // Relative encoded dex locations that don't match the given abs_dex_location |
| 339 | // are left unchanged. |
| 340 | static std::string ResolveRelativeEncodedDexLocation( |
| 341 | const char* abs_dex_location, const std::string& rel_dex_location); |
| 342 | |
Vladimir Marko | 97d7e1c | 2016-10-04 14:44:28 +0100 | [diff] [blame] | 343 | // Finds the associated oat class for a dex_file and descriptor. Returns an invalid OatClass on |
| 344 | // error and sets found to false. |
| 345 | static OatClass FindOatClass(const DexFile& dex_file, uint16_t class_def_idx, bool* found); |
| 346 | |
Nicolas Geoffray | 4acefd3 | 2016-10-24 13:14:58 +0100 | [diff] [blame] | 347 | VdexFile* GetVdexFile() const { |
| 348 | return vdex_.get(); |
| 349 | } |
| 350 | |
Nicolas Geoffray | f307527 | 2018-01-08 12:41:19 +0000 | [diff] [blame] | 351 | // Whether the OatFile embeds the Dex code. |
| 352 | bool ContainsDexCode() const { |
| 353 | return uncompressed_dex_files_ == nullptr; |
| 354 | } |
| 355 | |
Andreas Gampe | 049cff0 | 2015-12-01 23:27:12 -0800 | [diff] [blame] | 356 | protected: |
| 357 | OatFile(const std::string& filename, bool executable); |
| 358 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 359 | private: |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 360 | // The oat file name. |
| 361 | // |
| 362 | // The image will embed this to link its associated oat file. |
| 363 | const std::string location_; |
| 364 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 365 | // Pointer to the Vdex file with the Dex files for this Oat file. |
| 366 | std::unique_ptr<VdexFile> vdex_; |
| 367 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 368 | // Pointer to OatHeader. |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 369 | const uint8_t* begin_; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 370 | |
| 371 | // Pointer to end of oat region for bounds checking. |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 372 | const uint8_t* end_; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 373 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 374 | // Pointer to the .data.bimg.rel.ro section, if present, otherwise null. |
| 375 | const uint8_t* data_bimg_rel_ro_begin_; |
| 376 | |
| 377 | // Pointer to the end of the .data.bimg.rel.ro section, if present, otherwise null. |
| 378 | const uint8_t* data_bimg_rel_ro_end_; |
| 379 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 380 | // Pointer to the .bss section, if present, otherwise null. |
Vladimir Marko | 06d7aaa | 2015-10-16 11:23:41 +0100 | [diff] [blame] | 381 | uint8_t* bss_begin_; |
Vladimir Marko | 5c42c29 | 2015-02-25 12:02:49 +0000 | [diff] [blame] | 382 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 383 | // Pointer to the end of the .bss section, if present, otherwise null. |
Vladimir Marko | 06d7aaa | 2015-10-16 11:23:41 +0100 | [diff] [blame] | 384 | uint8_t* bss_end_; |
Vladimir Marko | 5c42c29 | 2015-02-25 12:02:49 +0000 | [diff] [blame] | 385 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 386 | // Pointer to the beginning of the ArtMethod*s in .bss section, if present, otherwise null. |
| 387 | uint8_t* bss_methods_; |
| 388 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 389 | // Pointer to the beginning of the GC roots in .bss section, if present, otherwise null. |
| 390 | uint8_t* bss_roots_; |
| 391 | |
Alex Light | 9dcc457 | 2014-08-14 14:16:26 -0700 | [diff] [blame] | 392 | // Was this oat_file loaded executable? |
| 393 | const bool is_executable_; |
| 394 | |
David Srbecky | ec2cdf4 | 2017-12-08 16:21:25 +0000 | [diff] [blame] | 395 | // Pointer to the .vdex section, if present, otherwise null. |
| 396 | uint8_t* vdex_begin_; |
| 397 | |
| 398 | // Pointer to the end of the .vdex section, if present, otherwise null. |
| 399 | uint8_t* vdex_end_; |
| 400 | |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 401 | // Owning storage for the OatDexFile objects. |
| 402 | std::vector<const OatDexFile*> oat_dex_files_storage_; |
| 403 | |
Vladimir Marko | 59ae4f9 | 2019-02-04 14:06:02 +0000 | [diff] [blame] | 404 | // NOTE: We use a std::string_view as the key type to avoid a memory allocation on every |
| 405 | // lookup with a const char* key. The std::string_view doesn't own its backing storage, |
Nicolas Geoffray | e3e0f70 | 2019-03-12 07:02:02 +0000 | [diff] [blame^] | 406 | // therefore we're using the OatFile's stored dex location as the backing storage |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 407 | // for keys in oat_dex_files_ and the string_cache_ entries for the backing storage |
| 408 | // of keys in secondary_oat_dex_files_ and oat_dex_files_by_canonical_location_. |
Vladimir Marko | 59ae4f9 | 2019-02-04 14:06:02 +0000 | [diff] [blame] | 409 | using Table = |
| 410 | AllocationTrackingSafeMap<std::string_view, const OatDexFile*, kAllocatorTagOatFile>; |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 411 | |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 412 | // Map each location and canonical location (if different) retrieved from the |
| 413 | // oat file to its OatDexFile. This map doesn't change after it's constructed in Setup() |
| 414 | // and therefore doesn't need any locking and provides the cheapest dex file lookup |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 415 | // for GetOatDexFile() for a very frequent use case. Never contains a null value. |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 416 | Table oat_dex_files_; |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 417 | |
| 418 | // Lock guarding all members needed for secondary lookup in GetOatDexFile(). |
| 419 | mutable Mutex secondary_lookup_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 420 | |
| 421 | // If the primary oat_dex_files_ lookup fails, use a secondary map. This map stores |
| 422 | // the results of all previous secondary lookups, whether successful (non-null) or |
| 423 | // failed (null). If it doesn't contain an entry we need to calculate the canonical |
| 424 | // location and use oat_dex_files_by_canonical_location_. |
| 425 | mutable Table secondary_oat_dex_files_ GUARDED_BY(secondary_lookup_lock_); |
| 426 | |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 427 | // Cache of strings. Contains the backing storage for keys in the secondary_oat_dex_files_ |
| 428 | // and the lazily initialized oat_dex_files_by_canonical_location_. |
Vladimir Marko | 59ae4f9 | 2019-02-04 14:06:02 +0000 | [diff] [blame] | 429 | // NOTE: We're keeping references to contained strings in form of std::string_view and adding |
Vladimir Marko | 3f5838d | 2014-08-07 18:07:18 +0100 | [diff] [blame] | 430 | // new strings to the end. The adding of a new element must not touch any previously stored |
| 431 | // elements. std::list<> and std::deque<> satisfy this requirement, std::vector<> doesn't. |
| 432 | mutable std::list<std::string> string_cache_ GUARDED_BY(secondary_lookup_lock_); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 433 | |
Nicolas Geoffray | f307527 | 2018-01-08 12:41:19 +0000 | [diff] [blame] | 434 | // Cache of dex files mapped directly from a location, in case the OatFile does |
| 435 | // not embed the dex code. |
| 436 | std::unique_ptr<std::vector<std::unique_ptr<const DexFile>>> uncompressed_dex_files_; |
| 437 | |
Mathieu Chartier | 5351da0 | 2016-02-17 16:19:53 -0800 | [diff] [blame] | 438 | friend class gc::collector::DummyOatFile; // For modifying begin_ and end_. |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 439 | friend class OatClass; |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 440 | friend class art::OatDexFile; |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 441 | friend class OatDumper; // For GetBase and GetLimit |
Andreas Gampe | 049cff0 | 2015-12-01 23:27:12 -0800 | [diff] [blame] | 442 | friend class OatFileBase; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 443 | DISALLOW_COPY_AND_ASSIGN(OatFile); |
| 444 | }; |
| 445 | |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 446 | // OatDexFile should be an inner class of OatFile. Unfortunately, C++ doesn't |
| 447 | // support forward declarations of inner classes, and we want to |
| 448 | // forward-declare OatDexFile so that we can store an opaque pointer to an |
| 449 | // OatDexFile in DexFile. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 450 | class OatDexFile final { |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 451 | public: |
| 452 | // Opens the DexFile referred to by this OatDexFile from within the containing OatFile. |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 453 | std::unique_ptr<const DexFile> OpenDexFile(std::string* error_msg) const; |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 454 | |
Mathieu Chartier | 1b86849 | 2016-11-16 16:22:37 -0800 | [diff] [blame] | 455 | // May return null if the OatDexFile only contains a type lookup table. This case only happens |
| 456 | // for the compiler to speed up compilation. |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 457 | const OatFile* GetOatFile() const { |
Mathieu Chartier | 1b86849 | 2016-11-16 16:22:37 -0800 | [diff] [blame] | 458 | // Avoid pulling in runtime.h in the header file. |
| 459 | if (kIsDebugBuild && oat_file_ == nullptr) { |
| 460 | AssertAotCompiler(); |
| 461 | } |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 462 | return oat_file_; |
| 463 | } |
| 464 | |
| 465 | // Returns the size of the DexFile refered to by this OatDexFile. |
| 466 | size_t FileSize() const; |
| 467 | |
| 468 | // Returns original path of DexFile that was the source of this OatDexFile. |
| 469 | const std::string& GetDexFileLocation() const { |
| 470 | return dex_file_location_; |
| 471 | } |
| 472 | |
| 473 | // Returns the canonical location of DexFile that was the source of this OatDexFile. |
| 474 | const std::string& GetCanonicalDexFileLocation() const { |
| 475 | return canonical_dex_file_location_; |
| 476 | } |
| 477 | |
| 478 | // Returns checksum of original DexFile that was the source of this OatDexFile; |
| 479 | uint32_t GetDexFileLocationChecksum() const { |
| 480 | return dex_file_location_checksum_; |
| 481 | } |
| 482 | |
| 483 | // Returns the OatClass for the class specified by the given DexFile class_def_index. |
| 484 | OatFile::OatClass GetOatClass(uint16_t class_def_index) const; |
| 485 | |
| 486 | // Returns the offset to the OatClass information. Most callers should use GetOatClass. |
| 487 | uint32_t GetOatClassOffset(uint16_t class_def_index) const; |
| 488 | |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 489 | const uint8_t* GetLookupTableData() const { |
| 490 | return lookup_table_data_; |
| 491 | } |
| 492 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 493 | const IndexBssMapping* GetMethodBssMapping() const { |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 494 | return method_bss_mapping_; |
| 495 | } |
| 496 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 497 | const IndexBssMapping* GetTypeBssMapping() const { |
| 498 | return type_bss_mapping_; |
| 499 | } |
| 500 | |
| 501 | const IndexBssMapping* GetStringBssMapping() const { |
| 502 | return string_bss_mapping_; |
| 503 | } |
| 504 | |
Andreas Gampe | 2ba8895 | 2016-04-29 17:52:07 -0700 | [diff] [blame] | 505 | const uint8_t* GetDexFilePointer() const { |
| 506 | return dex_file_pointer_; |
| 507 | } |
| 508 | |
Hans Boehm | 206348c | 2018-12-05 11:11:33 -0800 | [diff] [blame] | 509 | ArrayRef<const uint8_t> GetQuickenedInfoOf(const DexFile& dex_file, |
| 510 | uint32_t dex_method_idx) const; |
| 511 | |
David Sehr | 9aa352e | 2016-09-15 18:13:52 -0700 | [diff] [blame] | 512 | // Looks up a class definition by its class descriptor. Hash must be |
| 513 | // ComputeModifiedUtf8Hash(descriptor). |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 514 | static const dex::ClassDef* FindClassDef(const DexFile& dex_file, |
| 515 | const char* descriptor, |
| 516 | size_t hash); |
David Sehr | 9aa352e | 2016-09-15 18:13:52 -0700 | [diff] [blame] | 517 | |
Mathieu Chartier | 120aa28 | 2017-08-05 16:03:03 -0700 | [diff] [blame] | 518 | // Madvise the dex file based on the state we are moving to. |
| 519 | static void MadviseDexFile(const DexFile& dex_file, MadviseState state); |
| 520 | |
Vladimir Marko | ea341d2 | 2018-05-11 10:33:37 +0100 | [diff] [blame] | 521 | const TypeLookupTable& GetTypeLookupTable() const { |
| 522 | return lookup_table_; |
David Sehr | 9aa352e | 2016-09-15 18:13:52 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 525 | ~OatDexFile(); |
| 526 | |
Mathieu Chartier | 1b86849 | 2016-11-16 16:22:37 -0800 | [diff] [blame] | 527 | // Create only with a type lookup table, used by the compiler to speed up compilation. |
Vladimir Marko | ea341d2 | 2018-05-11 10:33:37 +0100 | [diff] [blame] | 528 | explicit OatDexFile(TypeLookupTable&& lookup_table); |
Mathieu Chartier | 1b86849 | 2016-11-16 16:22:37 -0800 | [diff] [blame] | 529 | |
Mathieu Chartier | 120aa28 | 2017-08-05 16:03:03 -0700 | [diff] [blame] | 530 | // Return the dex layout sections. |
| 531 | const DexLayoutSections* GetDexLayoutSections() const { |
| 532 | return dex_layout_sections_; |
| 533 | } |
| 534 | |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 535 | private: |
| 536 | OatDexFile(const OatFile* oat_file, |
| 537 | const std::string& dex_file_location, |
| 538 | const std::string& canonical_dex_file_location, |
| 539 | uint32_t dex_file_checksum, |
| 540 | const uint8_t* dex_file_pointer, |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 541 | const uint8_t* lookup_table_data, |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 542 | const IndexBssMapping* method_bss_mapping, |
| 543 | const IndexBssMapping* type_bss_mapping, |
| 544 | const IndexBssMapping* string_bss_mapping, |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 545 | const uint32_t* oat_class_offsets_pointer, |
Mathieu Chartier | 120aa28 | 2017-08-05 16:03:03 -0700 | [diff] [blame] | 546 | const DexLayoutSections* dex_layout_sections); |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 547 | |
Mathieu Chartier | 1b86849 | 2016-11-16 16:22:37 -0800 | [diff] [blame] | 548 | static void AssertAotCompiler(); |
| 549 | |
| 550 | const OatFile* const oat_file_ = nullptr; |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 551 | const std::string dex_file_location_; |
| 552 | const std::string canonical_dex_file_location_; |
Mathieu Chartier | 1b86849 | 2016-11-16 16:22:37 -0800 | [diff] [blame] | 553 | const uint32_t dex_file_location_checksum_ = 0u; |
| 554 | const uint8_t* const dex_file_pointer_ = nullptr; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 555 | const uint8_t* const lookup_table_data_ = nullptr; |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 556 | const IndexBssMapping* const method_bss_mapping_ = nullptr; |
| 557 | const IndexBssMapping* const type_bss_mapping_ = nullptr; |
| 558 | const IndexBssMapping* const string_bss_mapping_ = nullptr; |
Yi Kong | 4b22b34 | 2018-08-02 14:43:21 -0700 | [diff] [blame] | 559 | const uint32_t* const oat_class_offsets_pointer_ = nullptr; |
Vladimir Marko | ea341d2 | 2018-05-11 10:33:37 +0100 | [diff] [blame] | 560 | TypeLookupTable lookup_table_; |
Mathieu Chartier | 120aa28 | 2017-08-05 16:03:03 -0700 | [diff] [blame] | 561 | const DexLayoutSections* const dex_layout_sections_ = nullptr; |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 562 | |
| 563 | friend class OatFile; |
Andreas Gampe | 049cff0 | 2015-12-01 23:27:12 -0800 | [diff] [blame] | 564 | friend class OatFileBase; |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 565 | DISALLOW_COPY_AND_ASSIGN(OatDexFile); |
| 566 | }; |
| 567 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 568 | } // namespace art |
| 569 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 570 | #endif // ART_RUNTIME_OAT_FILE_H_ |