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