1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2011 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #ifndef ART_RUNTIME_OAT_OAT_FILE_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_RUNTIME_OAT_OAT_FILE_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include <list> 21*795d594fSAndroid Build Coastguard Worker #include <memory> 22*795d594fSAndroid Build Coastguard Worker #include <string> 23*795d594fSAndroid Build Coastguard Worker #include <string_view> 24*795d594fSAndroid Build Coastguard Worker #include <vector> 25*795d594fSAndroid Build Coastguard Worker 26*795d594fSAndroid Build Coastguard Worker #include "base/array_ref.h" 27*795d594fSAndroid Build Coastguard Worker #include "base/compiler_filter.h" 28*795d594fSAndroid Build Coastguard Worker #include "base/macros.h" 29*795d594fSAndroid Build Coastguard Worker #include "base/mutex.h" 30*795d594fSAndroid Build Coastguard Worker #include "base/os.h" 31*795d594fSAndroid Build Coastguard Worker #include "base/safe_map.h" 32*795d594fSAndroid Build Coastguard Worker #include "base/tracking_safe_map.h" 33*795d594fSAndroid Build Coastguard Worker #include "class_status.h" 34*795d594fSAndroid Build Coastguard Worker #include "dex/dex_file.h" 35*795d594fSAndroid Build Coastguard Worker #include "dex/dex_file_layout.h" 36*795d594fSAndroid Build Coastguard Worker #include "dex/type_lookup_table.h" 37*795d594fSAndroid Build Coastguard Worker #include "dex/utf.h" 38*795d594fSAndroid Build Coastguard Worker #include "index_bss_mapping.h" 39*795d594fSAndroid Build Coastguard Worker #include "mirror/object.h" 40*795d594fSAndroid Build Coastguard Worker 41*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN { 42*795d594fSAndroid Build Coastguard Worker 43*795d594fSAndroid Build Coastguard Worker class BitVector; 44*795d594fSAndroid Build Coastguard Worker class ClassLinker; 45*795d594fSAndroid Build Coastguard Worker class ClassLoaderContext; 46*795d594fSAndroid Build Coastguard Worker class ElfFile; 47*795d594fSAndroid Build Coastguard Worker class DexLayoutSections; 48*795d594fSAndroid Build Coastguard Worker template <class MirrorType> class GcRoot; 49*795d594fSAndroid Build Coastguard Worker class MemMap; 50*795d594fSAndroid Build Coastguard Worker class OatDexFile; 51*795d594fSAndroid Build Coastguard Worker class OatHeader; 52*795d594fSAndroid Build Coastguard Worker class OatMethodOffsets; 53*795d594fSAndroid Build Coastguard Worker class OatQuickMethodHeader; 54*795d594fSAndroid Build Coastguard Worker class VdexFile; 55*795d594fSAndroid Build Coastguard Worker 56*795d594fSAndroid Build Coastguard Worker namespace dex { 57*795d594fSAndroid Build Coastguard Worker struct ClassDef; 58*795d594fSAndroid Build Coastguard Worker } // namespace dex 59*795d594fSAndroid Build Coastguard Worker 60*795d594fSAndroid Build Coastguard Worker namespace gc { 61*795d594fSAndroid Build Coastguard Worker namespace collector { 62*795d594fSAndroid Build Coastguard Worker class FakeOatFile; 63*795d594fSAndroid Build Coastguard Worker } // namespace collector 64*795d594fSAndroid Build Coastguard Worker } // namespace gc 65*795d594fSAndroid Build Coastguard Worker 66*795d594fSAndroid Build Coastguard Worker // A special compilation reason to indicate that only the VDEX file is usable. Keep in sync with 67*795d594fSAndroid Build Coastguard Worker // `ArtConstants::REASON_VDEX` in artd/binder/com/android/server/art/ArtConstants.aidl. 68*795d594fSAndroid Build Coastguard Worker static constexpr const char* kReasonVdex = "vdex"; 69*795d594fSAndroid Build Coastguard Worker 70*795d594fSAndroid Build Coastguard Worker // OatMethodOffsets are currently 5x32-bits=160-bits long, so if we can 71*795d594fSAndroid Build Coastguard Worker // save even one OatMethodOffsets struct, the more complicated encoding 72*795d594fSAndroid Build Coastguard Worker // using a bitmap pays for itself since few classes will have 160 73*795d594fSAndroid Build Coastguard Worker // methods. 74*795d594fSAndroid Build Coastguard Worker enum class OatClassType : uint8_t { 75*795d594fSAndroid Build Coastguard Worker kAllCompiled = 0, // OatClass is followed by an OatMethodOffsets for each method. 76*795d594fSAndroid Build Coastguard Worker kSomeCompiled = 1, // A bitmap of OatMethodOffsets that are present follows the OatClass. 77*795d594fSAndroid Build Coastguard Worker kNoneCompiled = 2, // All methods are interpreted so no OatMethodOffsets are necessary. 78*795d594fSAndroid Build Coastguard Worker kLast = kNoneCompiled 79*795d594fSAndroid Build Coastguard Worker }; 80*795d594fSAndroid Build Coastguard Worker 81*795d594fSAndroid Build Coastguard Worker EXPORT std::ostream& operator<<(std::ostream& os, OatClassType rhs); 82*795d594fSAndroid Build Coastguard Worker 83*795d594fSAndroid Build Coastguard Worker class PACKED(4) OatMethodOffsets { 84*795d594fSAndroid Build Coastguard Worker public: code_offset_(code_offset)85*795d594fSAndroid Build Coastguard Worker explicit OatMethodOffsets(uint32_t code_offset = 0) : code_offset_(code_offset) {} 86*795d594fSAndroid Build Coastguard Worker ~OatMethodOffsets()87*795d594fSAndroid Build Coastguard Worker ~OatMethodOffsets() {} 88*795d594fSAndroid Build Coastguard Worker 89*795d594fSAndroid Build Coastguard Worker OatMethodOffsets(const OatMethodOffsets&) = default; 90*795d594fSAndroid Build Coastguard Worker OatMethodOffsets& operator=(const OatMethodOffsets&) = default; 91*795d594fSAndroid Build Coastguard Worker 92*795d594fSAndroid Build Coastguard Worker uint32_t code_offset_; 93*795d594fSAndroid Build Coastguard Worker }; 94*795d594fSAndroid Build Coastguard Worker 95*795d594fSAndroid Build Coastguard Worker // Runtime representation of the OAT file format which holds compiler output. 96*795d594fSAndroid Build Coastguard Worker // The class opens an OAT file from storage and maps it to memory, typically with 97*795d594fSAndroid Build Coastguard Worker // dlopen and provides access to its internal data structures (see OatWriter for 98*795d594fSAndroid Build Coastguard Worker // for more details about the OAT format). 99*795d594fSAndroid Build Coastguard Worker // In the process of loading OAT, the class also loads the associated VDEX file 100*795d594fSAndroid Build Coastguard Worker // with the input DEX files (see VdexFile for details about the VDEX format). 101*795d594fSAndroid Build Coastguard Worker // The raw DEX data are accessible transparently through the OatDexFile objects. 102*795d594fSAndroid Build Coastguard Worker 103*795d594fSAndroid Build Coastguard Worker class OatFile { 104*795d594fSAndroid Build Coastguard Worker public: 105*795d594fSAndroid Build Coastguard Worker // Open an oat file. Returns null on failure. 106*795d594fSAndroid Build Coastguard Worker // The `dex_filenames` argument, if provided, overrides the dex locations 107*795d594fSAndroid Build Coastguard Worker // from oat file when opening the dex files if they are not embedded in the 108*795d594fSAndroid Build Coastguard Worker // vdex file. These may differ for cross-compilation (the dex file name is 109*795d594fSAndroid Build Coastguard Worker // the host path and dex location is the future path on target) and testing. 110*795d594fSAndroid Build Coastguard Worker EXPORT static OatFile* Open(int zip_fd, 111*795d594fSAndroid Build Coastguard Worker const std::string& filename, 112*795d594fSAndroid Build Coastguard Worker const std::string& location, 113*795d594fSAndroid Build Coastguard Worker bool executable, 114*795d594fSAndroid Build Coastguard Worker bool low_4gb, 115*795d594fSAndroid Build Coastguard Worker ArrayRef<const std::string> dex_filenames, 116*795d594fSAndroid Build Coastguard Worker ArrayRef<File> dex_files, 117*795d594fSAndroid Build Coastguard Worker /*inout*/ MemMap* reservation, // Where to load if not null. 118*795d594fSAndroid Build Coastguard Worker /*out*/ std::string* error_msg); 119*795d594fSAndroid Build Coastguard Worker // Helper overload that takes a single dex filename and no reservation. Open(int zip_fd,const std::string & filename,const std::string & location,bool executable,bool low_4gb,const std::string & dex_filename,std::string * error_msg)120*795d594fSAndroid Build Coastguard Worker EXPORT static OatFile* Open(int zip_fd, 121*795d594fSAndroid Build Coastguard Worker const std::string& filename, 122*795d594fSAndroid Build Coastguard Worker const std::string& location, 123*795d594fSAndroid Build Coastguard Worker bool executable, 124*795d594fSAndroid Build Coastguard Worker bool low_4gb, 125*795d594fSAndroid Build Coastguard Worker const std::string& dex_filename, 126*795d594fSAndroid Build Coastguard Worker /*out*/ std::string* error_msg) { 127*795d594fSAndroid Build Coastguard Worker return Open(zip_fd, 128*795d594fSAndroid Build Coastguard Worker filename, 129*795d594fSAndroid Build Coastguard Worker location, 130*795d594fSAndroid Build Coastguard Worker executable, 131*795d594fSAndroid Build Coastguard Worker low_4gb, 132*795d594fSAndroid Build Coastguard Worker ArrayRef<const std::string>(&dex_filename, /*size=*/1u), 133*795d594fSAndroid Build Coastguard Worker /*dex_files=*/{}, // not currently supported 134*795d594fSAndroid Build Coastguard Worker /*reservation=*/nullptr, 135*795d594fSAndroid Build Coastguard Worker error_msg); 136*795d594fSAndroid Build Coastguard Worker } 137*795d594fSAndroid Build Coastguard Worker // Helper overload that takes no dex filename and no reservation. Open(int zip_fd,const std::string & filename,const std::string & location,bool executable,bool low_4gb,std::string * error_msg)138*795d594fSAndroid Build Coastguard Worker static OatFile* Open(int zip_fd, 139*795d594fSAndroid Build Coastguard Worker const std::string& filename, 140*795d594fSAndroid Build Coastguard Worker const std::string& location, 141*795d594fSAndroid Build Coastguard Worker bool executable, 142*795d594fSAndroid Build Coastguard Worker bool low_4gb, 143*795d594fSAndroid Build Coastguard Worker /*out*/std::string* error_msg) { 144*795d594fSAndroid Build Coastguard Worker return Open(zip_fd, 145*795d594fSAndroid Build Coastguard Worker filename, 146*795d594fSAndroid Build Coastguard Worker location, 147*795d594fSAndroid Build Coastguard Worker executable, 148*795d594fSAndroid Build Coastguard Worker low_4gb, 149*795d594fSAndroid Build Coastguard Worker /*dex_filenames=*/{}, 150*795d594fSAndroid Build Coastguard Worker /*dex_files=*/{}, // not currently supported 151*795d594fSAndroid Build Coastguard Worker /*reservation=*/nullptr, 152*795d594fSAndroid Build Coastguard Worker error_msg); 153*795d594fSAndroid Build Coastguard Worker } 154*795d594fSAndroid Build Coastguard Worker 155*795d594fSAndroid Build Coastguard Worker // Similar to OatFile::Open(const std::string...), but accepts input vdex and 156*795d594fSAndroid Build Coastguard Worker // odex files as file descriptors. We also take zip_fd in case the vdex does not 157*795d594fSAndroid Build Coastguard Worker // contain the dex code, and we need to read it from the zip file. 158*795d594fSAndroid Build Coastguard Worker static OatFile* Open(int zip_fd, 159*795d594fSAndroid Build Coastguard Worker int vdex_fd, 160*795d594fSAndroid Build Coastguard Worker int oat_fd, 161*795d594fSAndroid Build Coastguard Worker const std::string& oat_location, 162*795d594fSAndroid Build Coastguard Worker bool executable, 163*795d594fSAndroid Build Coastguard Worker bool low_4gb, 164*795d594fSAndroid Build Coastguard Worker ArrayRef<const std::string> dex_filenames, 165*795d594fSAndroid Build Coastguard Worker ArrayRef<File> dex_files, 166*795d594fSAndroid Build Coastguard Worker /*inout*/ MemMap* reservation, // Where to load if not null. 167*795d594fSAndroid Build Coastguard Worker /*out*/ std::string* error_msg); 168*795d594fSAndroid Build Coastguard Worker 169*795d594fSAndroid Build Coastguard Worker // Initialize OatFile instance from an already loaded VdexFile. This assumes 170*795d594fSAndroid Build Coastguard Worker // the vdex does not have a dex section and accepts a vector of DexFiles separately. 171*795d594fSAndroid Build Coastguard Worker static OatFile* OpenFromVdex(const std::vector<const DexFile*>& dex_files, 172*795d594fSAndroid Build Coastguard Worker std::unique_ptr<VdexFile>&& vdex_file, 173*795d594fSAndroid Build Coastguard Worker const std::string& location, 174*795d594fSAndroid Build Coastguard Worker ClassLoaderContext* context); 175*795d594fSAndroid Build Coastguard Worker 176*795d594fSAndroid Build Coastguard Worker // Initialize OatFile instance from an already loaded VdexFile. The dex files 177*795d594fSAndroid Build Coastguard Worker // will be opened through `zip_fd` or `dex_location` if `zip_fd` is -1. 178*795d594fSAndroid Build Coastguard Worker static OatFile* OpenFromVdex(int zip_fd, 179*795d594fSAndroid Build Coastguard Worker std::unique_ptr<VdexFile>&& vdex_file, 180*795d594fSAndroid Build Coastguard Worker const std::string& location, 181*795d594fSAndroid Build Coastguard Worker ClassLoaderContext* context, 182*795d594fSAndroid Build Coastguard Worker std::string* error_msg); 183*795d594fSAndroid Build Coastguard Worker 184*795d594fSAndroid Build Coastguard Worker // Set the start of the app image. 185*795d594fSAndroid Build Coastguard Worker // Needed for initializing app image relocations in the .data.img.rel.ro section. SetAppImageBegin(uint8_t * app_image_begin)186*795d594fSAndroid Build Coastguard Worker void SetAppImageBegin(uint8_t* app_image_begin) const { 187*795d594fSAndroid Build Coastguard Worker app_image_begin_ = app_image_begin; 188*795d594fSAndroid Build Coastguard Worker } 189*795d594fSAndroid Build Coastguard Worker 190*795d594fSAndroid Build Coastguard Worker // Return whether the `OatFile` uses a vdex-only file. 191*795d594fSAndroid Build Coastguard Worker bool IsBackedByVdexOnly() const; 192*795d594fSAndroid Build Coastguard Worker 193*795d594fSAndroid Build Coastguard Worker virtual ~OatFile(); 194*795d594fSAndroid Build Coastguard Worker IsExecutable()195*795d594fSAndroid Build Coastguard Worker bool IsExecutable() const { 196*795d594fSAndroid Build Coastguard Worker return is_executable_; 197*795d594fSAndroid Build Coastguard Worker } 198*795d594fSAndroid Build Coastguard Worker 199*795d594fSAndroid Build Coastguard Worker // Indicates whether the oat file was compiled with full debugging capability. 200*795d594fSAndroid Build Coastguard Worker bool IsDebuggable() const; 201*795d594fSAndroid Build Coastguard Worker 202*795d594fSAndroid Build Coastguard Worker EXPORT CompilerFilter::Filter GetCompilerFilter() const; 203*795d594fSAndroid Build Coastguard Worker 204*795d594fSAndroid Build Coastguard Worker std::string GetClassLoaderContext() const; 205*795d594fSAndroid Build Coastguard Worker 206*795d594fSAndroid Build Coastguard Worker const char* GetCompilationReason() const; 207*795d594fSAndroid Build Coastguard Worker GetLocation()208*795d594fSAndroid Build Coastguard Worker const std::string& GetLocation() const { 209*795d594fSAndroid Build Coastguard Worker return location_; 210*795d594fSAndroid Build Coastguard Worker } 211*795d594fSAndroid Build Coastguard Worker 212*795d594fSAndroid Build Coastguard Worker EXPORT const OatHeader& GetOatHeader() const; 213*795d594fSAndroid Build Coastguard Worker 214*795d594fSAndroid Build Coastguard Worker class OatMethod final { 215*795d594fSAndroid Build Coastguard Worker public: GetCodeOffset()216*795d594fSAndroid Build Coastguard Worker uint32_t GetCodeOffset() const { return code_offset_; } 217*795d594fSAndroid Build Coastguard Worker 218*795d594fSAndroid Build Coastguard Worker const void* GetQuickCode() const; 219*795d594fSAndroid Build Coastguard Worker 220*795d594fSAndroid Build Coastguard Worker // Returns size of quick code. 221*795d594fSAndroid Build Coastguard Worker uint32_t GetQuickCodeSize() const; 222*795d594fSAndroid Build Coastguard Worker 223*795d594fSAndroid Build Coastguard Worker // Returns OatQuickMethodHeader for debugging. Most callers should 224*795d594fSAndroid Build Coastguard Worker // use more specific methods such as GetQuickCodeSize. 225*795d594fSAndroid Build Coastguard Worker const OatQuickMethodHeader* GetOatQuickMethodHeader() const; 226*795d594fSAndroid Build Coastguard Worker uint32_t GetOatQuickMethodHeaderOffset() const; 227*795d594fSAndroid Build Coastguard Worker 228*795d594fSAndroid Build Coastguard Worker size_t GetFrameSizeInBytes() const; 229*795d594fSAndroid Build Coastguard Worker uint32_t GetCoreSpillMask() const; 230*795d594fSAndroid Build Coastguard Worker uint32_t GetFpSpillMask() const; 231*795d594fSAndroid Build Coastguard Worker 232*795d594fSAndroid Build Coastguard Worker const uint8_t* GetVmapTable() const; 233*795d594fSAndroid Build Coastguard Worker uint32_t GetVmapTableOffset() const; 234*795d594fSAndroid Build Coastguard Worker 235*795d594fSAndroid Build Coastguard Worker // Create an OatMethod with offsets relative to the given base address OatMethod(const uint8_t * base,const uint32_t code_offset)236*795d594fSAndroid Build Coastguard Worker OatMethod(const uint8_t* base, const uint32_t code_offset) 237*795d594fSAndroid Build Coastguard Worker : begin_(base), code_offset_(code_offset) { 238*795d594fSAndroid Build Coastguard Worker } 239*795d594fSAndroid Build Coastguard Worker OatMethod(const OatMethod&) = default; ~OatMethod()240*795d594fSAndroid Build Coastguard Worker ~OatMethod() {} 241*795d594fSAndroid Build Coastguard Worker 242*795d594fSAndroid Build Coastguard Worker OatMethod& operator=(const OatMethod&) = default; 243*795d594fSAndroid Build Coastguard Worker 244*795d594fSAndroid Build Coastguard Worker // A representation of an invalid OatMethod, used when an OatMethod or OatClass can't be found. 245*795d594fSAndroid Build Coastguard Worker // See ClassLinker::FindOatMethodFor. Invalid()246*795d594fSAndroid Build Coastguard Worker static const OatMethod Invalid() { 247*795d594fSAndroid Build Coastguard Worker return OatMethod(nullptr, -1); 248*795d594fSAndroid Build Coastguard Worker } 249*795d594fSAndroid Build Coastguard Worker 250*795d594fSAndroid Build Coastguard Worker private: 251*795d594fSAndroid Build Coastguard Worker const uint8_t* begin_; 252*795d594fSAndroid Build Coastguard Worker uint32_t code_offset_; 253*795d594fSAndroid Build Coastguard Worker 254*795d594fSAndroid Build Coastguard Worker friend class OatClass; 255*795d594fSAndroid Build Coastguard Worker }; 256*795d594fSAndroid Build Coastguard Worker 257*795d594fSAndroid Build Coastguard Worker class OatClass final { 258*795d594fSAndroid Build Coastguard Worker public: GetStatus()259*795d594fSAndroid Build Coastguard Worker ClassStatus GetStatus() const { 260*795d594fSAndroid Build Coastguard Worker return status_; 261*795d594fSAndroid Build Coastguard Worker } 262*795d594fSAndroid Build Coastguard Worker GetType()263*795d594fSAndroid Build Coastguard Worker OatClassType GetType() const { 264*795d594fSAndroid Build Coastguard Worker return type_; 265*795d594fSAndroid Build Coastguard Worker } 266*795d594fSAndroid Build Coastguard Worker 267*795d594fSAndroid Build Coastguard Worker // Get the OatMethod entry based on its index into the class 268*795d594fSAndroid Build Coastguard Worker // defintion. Direct methods come first, followed by virtual 269*795d594fSAndroid Build Coastguard Worker // methods. Note that runtime created methods such as miranda 270*795d594fSAndroid Build Coastguard Worker // methods are not included. 271*795d594fSAndroid Build Coastguard Worker EXPORT const OatMethod GetOatMethod(uint32_t method_index) const; 272*795d594fSAndroid Build Coastguard Worker 273*795d594fSAndroid Build Coastguard Worker // Return a pointer to the OatMethodOffsets for the requested 274*795d594fSAndroid Build Coastguard Worker // method_index, or null if none is present. Note that most 275*795d594fSAndroid Build Coastguard Worker // callers should use GetOatMethod. 276*795d594fSAndroid Build Coastguard Worker EXPORT const OatMethodOffsets* GetOatMethodOffsets(uint32_t method_index) const; 277*795d594fSAndroid Build Coastguard Worker 278*795d594fSAndroid Build Coastguard Worker // Return the offset from the start of the OatFile to the 279*795d594fSAndroid Build Coastguard Worker // OatMethodOffsets for the requested method_index, or 0 if none 280*795d594fSAndroid Build Coastguard Worker // is present. Note that most callers should use GetOatMethod. 281*795d594fSAndroid Build Coastguard Worker EXPORT uint32_t GetOatMethodOffsetsOffset(uint32_t method_index) const; 282*795d594fSAndroid Build Coastguard Worker 283*795d594fSAndroid Build Coastguard Worker // A representation of an invalid OatClass, used when an OatClass can't be found. 284*795d594fSAndroid Build Coastguard Worker // See FindOatClass(). Invalid()285*795d594fSAndroid Build Coastguard Worker static OatClass Invalid() { 286*795d594fSAndroid Build Coastguard Worker return OatClass(/* oat_file= */ nullptr, 287*795d594fSAndroid Build Coastguard Worker ClassStatus::kErrorUnresolved, 288*795d594fSAndroid Build Coastguard Worker OatClassType::kNoneCompiled, 289*795d594fSAndroid Build Coastguard Worker /* num_methods= */ 0, 290*795d594fSAndroid Build Coastguard Worker /* bitmap_pointer= */ nullptr, 291*795d594fSAndroid Build Coastguard Worker /* methods_pointer= */ nullptr); 292*795d594fSAndroid Build Coastguard Worker } 293*795d594fSAndroid Build Coastguard Worker 294*795d594fSAndroid Build Coastguard Worker private: 295*795d594fSAndroid Build Coastguard Worker OatClass(const OatFile* oat_file, 296*795d594fSAndroid Build Coastguard Worker ClassStatus status, 297*795d594fSAndroid Build Coastguard Worker OatClassType type, 298*795d594fSAndroid Build Coastguard Worker uint32_t num_methods, 299*795d594fSAndroid Build Coastguard Worker const uint32_t* bitmap_pointer, 300*795d594fSAndroid Build Coastguard Worker const OatMethodOffsets* methods_pointer); 301*795d594fSAndroid Build Coastguard Worker 302*795d594fSAndroid Build Coastguard Worker const OatFile* const oat_file_; 303*795d594fSAndroid Build Coastguard Worker const ClassStatus status_; 304*795d594fSAndroid Build Coastguard Worker const OatClassType type_; 305*795d594fSAndroid Build Coastguard Worker const uint32_t num_methods_; 306*795d594fSAndroid Build Coastguard Worker const uint32_t* const bitmap_; 307*795d594fSAndroid Build Coastguard Worker const OatMethodOffsets* const methods_pointer_; 308*795d594fSAndroid Build Coastguard Worker 309*795d594fSAndroid Build Coastguard Worker friend class ClassLinker; 310*795d594fSAndroid Build Coastguard Worker friend class OatDexFile; 311*795d594fSAndroid Build Coastguard Worker }; 312*795d594fSAndroid Build Coastguard Worker 313*795d594fSAndroid Build Coastguard Worker // Get the OatDexFile for the given dex_location within this oat file. 314*795d594fSAndroid Build Coastguard Worker // If dex_location_checksum is non-null, the OatDexFile will only be 315*795d594fSAndroid Build Coastguard Worker // returned if it has a matching checksum. 316*795d594fSAndroid Build Coastguard Worker // If error_msg is non-null and no OatDexFile is returned, error_msg will 317*795d594fSAndroid Build Coastguard Worker // be updated with a description of why no OatDexFile was returned. 318*795d594fSAndroid Build Coastguard Worker const OatDexFile* GetOatDexFile(const char* dex_location, 319*795d594fSAndroid Build Coastguard Worker /*out*/ std::string* error_msg = nullptr) const 320*795d594fSAndroid Build Coastguard Worker REQUIRES(!secondary_lookup_lock_); 321*795d594fSAndroid Build Coastguard Worker GetOatDexFiles()322*795d594fSAndroid Build Coastguard Worker const std::vector<const OatDexFile*>& GetOatDexFiles() const { 323*795d594fSAndroid Build Coastguard Worker return oat_dex_files_storage_; 324*795d594fSAndroid Build Coastguard Worker } 325*795d594fSAndroid Build Coastguard Worker Size()326*795d594fSAndroid Build Coastguard Worker size_t Size() const { 327*795d594fSAndroid Build Coastguard Worker return End() - Begin(); 328*795d594fSAndroid Build Coastguard Worker } 329*795d594fSAndroid Build Coastguard Worker Contains(const void * p)330*795d594fSAndroid Build Coastguard Worker bool Contains(const void* p) const { 331*795d594fSAndroid Build Coastguard Worker return p >= Begin() && p < End(); 332*795d594fSAndroid Build Coastguard Worker } 333*795d594fSAndroid Build Coastguard Worker DataImgRelRoSize()334*795d594fSAndroid Build Coastguard Worker size_t DataImgRelRoSize() const { 335*795d594fSAndroid Build Coastguard Worker return DataImgRelRoEnd() - DataImgRelRoBegin(); 336*795d594fSAndroid Build Coastguard Worker } 337*795d594fSAndroid Build Coastguard Worker DataImgRelRoAppImageOffset()338*795d594fSAndroid Build Coastguard Worker size_t DataImgRelRoAppImageOffset() const { 339*795d594fSAndroid Build Coastguard Worker return DataImgRelRoAppImage() - DataImgRelRoBegin(); 340*795d594fSAndroid Build Coastguard Worker } 341*795d594fSAndroid Build Coastguard Worker BssSize()342*795d594fSAndroid Build Coastguard Worker size_t BssSize() const { 343*795d594fSAndroid Build Coastguard Worker return BssEnd() - BssBegin(); 344*795d594fSAndroid Build Coastguard Worker } 345*795d594fSAndroid Build Coastguard Worker VdexSize()346*795d594fSAndroid Build Coastguard Worker size_t VdexSize() const { 347*795d594fSAndroid Build Coastguard Worker return VdexEnd() - VdexBegin(); 348*795d594fSAndroid Build Coastguard Worker } 349*795d594fSAndroid Build Coastguard Worker BssMethodsOffset()350*795d594fSAndroid Build Coastguard Worker size_t BssMethodsOffset() const { 351*795d594fSAndroid Build Coastguard Worker // Note: This is used only for symbolizer and needs to return a valid .bss offset. 352*795d594fSAndroid Build Coastguard Worker return (bss_methods_ != nullptr) ? bss_methods_ - BssBegin() : BssRootsOffset(); 353*795d594fSAndroid Build Coastguard Worker } 354*795d594fSAndroid Build Coastguard Worker BssRootsOffset()355*795d594fSAndroid Build Coastguard Worker size_t BssRootsOffset() const { 356*795d594fSAndroid Build Coastguard Worker // Note: This is used only for symbolizer and needs to return a valid .bss offset. 357*795d594fSAndroid Build Coastguard Worker return (bss_roots_ != nullptr) ? bss_roots_ - BssBegin() : BssSize(); 358*795d594fSAndroid Build Coastguard Worker } 359*795d594fSAndroid Build Coastguard Worker DexSize()360*795d594fSAndroid Build Coastguard Worker size_t DexSize() const { 361*795d594fSAndroid Build Coastguard Worker return DexEnd() - DexBegin(); 362*795d594fSAndroid Build Coastguard Worker } 363*795d594fSAndroid Build Coastguard Worker 364*795d594fSAndroid Build Coastguard Worker // Returns the base address of the ELF file, or nullptr if the oat file is not backed by an ELF 365*795d594fSAndroid Build Coastguard Worker // file or an error occurred. 366*795d594fSAndroid Build Coastguard Worker virtual const uint8_t* ComputeElfBegin(std::string* error_msg) const = 0; 367*795d594fSAndroid Build Coastguard Worker 368*795d594fSAndroid Build Coastguard Worker EXPORT const uint8_t* Begin() const; 369*795d594fSAndroid Build Coastguard Worker EXPORT const uint8_t* End() const; 370*795d594fSAndroid Build Coastguard Worker DataImgRelRoBegin()371*795d594fSAndroid Build Coastguard Worker const uint8_t* DataImgRelRoBegin() const { return data_img_rel_ro_begin_; } DataImgRelRoEnd()372*795d594fSAndroid Build Coastguard Worker const uint8_t* DataImgRelRoEnd() const { return data_img_rel_ro_end_; } DataImgRelRoAppImage()373*795d594fSAndroid Build Coastguard Worker const uint8_t* DataImgRelRoAppImage() const { return data_img_rel_ro_app_image_; } 374*795d594fSAndroid Build Coastguard Worker BssBegin()375*795d594fSAndroid Build Coastguard Worker const uint8_t* BssBegin() const { return bss_begin_; } BssEnd()376*795d594fSAndroid Build Coastguard Worker const uint8_t* BssEnd() const { return bss_end_; } 377*795d594fSAndroid Build Coastguard Worker VdexBegin()378*795d594fSAndroid Build Coastguard Worker const uint8_t* VdexBegin() const { return vdex_begin_; } VdexEnd()379*795d594fSAndroid Build Coastguard Worker const uint8_t* VdexEnd() const { return vdex_end_; } 380*795d594fSAndroid Build Coastguard Worker 381*795d594fSAndroid Build Coastguard Worker EXPORT const uint8_t* DexBegin() const; 382*795d594fSAndroid Build Coastguard Worker EXPORT const uint8_t* DexEnd() const; 383*795d594fSAndroid Build Coastguard Worker 384*795d594fSAndroid Build Coastguard Worker EXPORT ArrayRef<const uint32_t> GetBootImageRelocations() const; 385*795d594fSAndroid Build Coastguard Worker EXPORT ArrayRef<const uint32_t> GetAppImageRelocations() const; 386*795d594fSAndroid Build Coastguard Worker EXPORT ArrayRef<ArtMethod*> GetBssMethods() const; 387*795d594fSAndroid Build Coastguard Worker EXPORT ArrayRef<GcRoot<mirror::Object>> GetBssGcRoots() const; 388*795d594fSAndroid Build Coastguard Worker 389*795d594fSAndroid Build Coastguard Worker // Initialize relocation sections (.data.img.rel.ro and .bss). 390*795d594fSAndroid Build Coastguard Worker void InitializeRelocations() const; 391*795d594fSAndroid Build Coastguard Worker 392*795d594fSAndroid Build Coastguard Worker // Finds the associated oat class for a dex_file and descriptor. Returns an invalid OatClass on 393*795d594fSAndroid Build Coastguard Worker // error and sets found to false. 394*795d594fSAndroid Build Coastguard Worker EXPORT static OatClass FindOatClass(const DexFile& dex_file, uint16_t class_def_idx, bool* found); 395*795d594fSAndroid Build Coastguard Worker GetVdexFile()396*795d594fSAndroid Build Coastguard Worker VdexFile* GetVdexFile() const { 397*795d594fSAndroid Build Coastguard Worker return vdex_.get(); 398*795d594fSAndroid Build Coastguard Worker } 399*795d594fSAndroid Build Coastguard Worker 400*795d594fSAndroid Build Coastguard Worker // Whether the OatFile embeds the Dex code. ContainsDexCode()401*795d594fSAndroid Build Coastguard Worker bool ContainsDexCode() const { 402*795d594fSAndroid Build Coastguard Worker return external_dex_files_.empty(); 403*795d594fSAndroid Build Coastguard Worker } 404*795d594fSAndroid Build Coastguard Worker 405*795d594fSAndroid Build Coastguard Worker // Returns whether an image (e.g. app image) is required to safely execute this OAT file. 406*795d594fSAndroid Build Coastguard Worker bool RequiresImage() const; 407*795d594fSAndroid Build Coastguard Worker 408*795d594fSAndroid Build Coastguard Worker struct BssMappingInfo { 409*795d594fSAndroid Build Coastguard Worker const IndexBssMapping* method_bss_mapping = nullptr; 410*795d594fSAndroid Build Coastguard Worker const IndexBssMapping* type_bss_mapping = nullptr; 411*795d594fSAndroid Build Coastguard Worker const IndexBssMapping* public_type_bss_mapping = nullptr; 412*795d594fSAndroid Build Coastguard Worker const IndexBssMapping* package_type_bss_mapping = nullptr; 413*795d594fSAndroid Build Coastguard Worker const IndexBssMapping* string_bss_mapping = nullptr; 414*795d594fSAndroid Build Coastguard Worker const IndexBssMapping* method_type_bss_mapping = nullptr; 415*795d594fSAndroid Build Coastguard Worker }; 416*795d594fSAndroid Build Coastguard Worker GetBcpBssInfo()417*795d594fSAndroid Build Coastguard Worker ArrayRef<const BssMappingInfo> GetBcpBssInfo() const { 418*795d594fSAndroid Build Coastguard Worker return ArrayRef<const BssMappingInfo>(bcp_bss_info_); 419*795d594fSAndroid Build Coastguard Worker } 420*795d594fSAndroid Build Coastguard Worker 421*795d594fSAndroid Build Coastguard Worker // Returns the mapping info of `dex_file` if found in the BcpBssInfo, or nullptr otherwise. 422*795d594fSAndroid Build Coastguard Worker const BssMappingInfo* FindBcpMappingInfo(const DexFile* dex_file) const; 423*795d594fSAndroid Build Coastguard Worker 424*795d594fSAndroid Build Coastguard Worker protected: 425*795d594fSAndroid Build Coastguard Worker OatFile(const std::string& filename, bool executable); 426*795d594fSAndroid Build Coastguard Worker 427*795d594fSAndroid Build Coastguard Worker private: 428*795d594fSAndroid Build Coastguard Worker // The oat file name. 429*795d594fSAndroid Build Coastguard Worker // 430*795d594fSAndroid Build Coastguard Worker // The image will embed this to link its associated oat file. 431*795d594fSAndroid Build Coastguard Worker const std::string location_; 432*795d594fSAndroid Build Coastguard Worker 433*795d594fSAndroid Build Coastguard Worker // Pointer to the Vdex file with the Dex files for this Oat file. 434*795d594fSAndroid Build Coastguard Worker std::unique_ptr<VdexFile> vdex_; 435*795d594fSAndroid Build Coastguard Worker 436*795d594fSAndroid Build Coastguard Worker // Pointer to OatHeader. 437*795d594fSAndroid Build Coastguard Worker const uint8_t* begin_; 438*795d594fSAndroid Build Coastguard Worker 439*795d594fSAndroid Build Coastguard Worker // Pointer to end of oat region for bounds checking. 440*795d594fSAndroid Build Coastguard Worker const uint8_t* end_; 441*795d594fSAndroid Build Coastguard Worker 442*795d594fSAndroid Build Coastguard Worker // Pointer to the .data.img.rel.ro section, if present, otherwise null. 443*795d594fSAndroid Build Coastguard Worker const uint8_t* data_img_rel_ro_begin_; 444*795d594fSAndroid Build Coastguard Worker 445*795d594fSAndroid Build Coastguard Worker // Pointer to the end of the .data.img.rel.ro section, if present, otherwise null. 446*795d594fSAndroid Build Coastguard Worker const uint8_t* data_img_rel_ro_end_; 447*795d594fSAndroid Build Coastguard Worker 448*795d594fSAndroid Build Coastguard Worker // Pointer to the beginning of the app image relocations in the .data.img.rel.ro section, 449*795d594fSAndroid Build Coastguard Worker // if present, otherwise null. 450*795d594fSAndroid Build Coastguard Worker const uint8_t* data_img_rel_ro_app_image_; 451*795d594fSAndroid Build Coastguard Worker 452*795d594fSAndroid Build Coastguard Worker // Pointer to the .bss section, if present, otherwise null. 453*795d594fSAndroid Build Coastguard Worker uint8_t* bss_begin_; 454*795d594fSAndroid Build Coastguard Worker 455*795d594fSAndroid Build Coastguard Worker // Pointer to the end of the .bss section, if present, otherwise null. 456*795d594fSAndroid Build Coastguard Worker uint8_t* bss_end_; 457*795d594fSAndroid Build Coastguard Worker 458*795d594fSAndroid Build Coastguard Worker // Pointer to the beginning of the ArtMethod*s in the .bss section, if present, otherwise null. 459*795d594fSAndroid Build Coastguard Worker uint8_t* bss_methods_; 460*795d594fSAndroid Build Coastguard Worker 461*795d594fSAndroid Build Coastguard Worker // Pointer to the beginning of the GC roots in the .bss section, if present, otherwise null. 462*795d594fSAndroid Build Coastguard Worker uint8_t* bss_roots_; 463*795d594fSAndroid Build Coastguard Worker 464*795d594fSAndroid Build Coastguard Worker // Was this oat_file loaded executable? 465*795d594fSAndroid Build Coastguard Worker const bool is_executable_; 466*795d594fSAndroid Build Coastguard Worker 467*795d594fSAndroid Build Coastguard Worker // Pointer to the .vdex section, if present, otherwise null. 468*795d594fSAndroid Build Coastguard Worker uint8_t* vdex_begin_; 469*795d594fSAndroid Build Coastguard Worker 470*795d594fSAndroid Build Coastguard Worker // Pointer to the end of the .vdex section, if present, otherwise null. 471*795d594fSAndroid Build Coastguard Worker uint8_t* vdex_end_; 472*795d594fSAndroid Build Coastguard Worker 473*795d594fSAndroid Build Coastguard Worker // Pointer to the beginning of the app image, if any. 474*795d594fSAndroid Build Coastguard Worker mutable uint8_t* app_image_begin_; 475*795d594fSAndroid Build Coastguard Worker 476*795d594fSAndroid Build Coastguard Worker // Owning storage for the OatDexFile objects. 477*795d594fSAndroid Build Coastguard Worker std::vector<const OatDexFile*> oat_dex_files_storage_; 478*795d594fSAndroid Build Coastguard Worker 479*795d594fSAndroid Build Coastguard Worker // Mapping info for DexFiles in the BCP. 480*795d594fSAndroid Build Coastguard Worker std::vector<BssMappingInfo> bcp_bss_info_; 481*795d594fSAndroid Build Coastguard Worker 482*795d594fSAndroid Build Coastguard Worker // NOTE: We use a std::string_view as the key type to avoid a memory allocation on every 483*795d594fSAndroid Build Coastguard Worker // lookup with a const char* key. The std::string_view doesn't own its backing storage, 484*795d594fSAndroid Build Coastguard Worker // therefore we're using the OatFile's stored dex location as the backing storage 485*795d594fSAndroid Build Coastguard Worker // for keys in oat_dex_files_ and the string_cache_ entries for the backing storage 486*795d594fSAndroid Build Coastguard Worker // of keys in secondary_oat_dex_files_ and oat_dex_files_by_canonical_location_. 487*795d594fSAndroid Build Coastguard Worker using Table = 488*795d594fSAndroid Build Coastguard Worker AllocationTrackingSafeMap<std::string_view, const OatDexFile*, kAllocatorTagOatFile>; 489*795d594fSAndroid Build Coastguard Worker 490*795d594fSAndroid Build Coastguard Worker // Map each location and canonical location (if different) retrieved from the 491*795d594fSAndroid Build Coastguard Worker // oat file to its OatDexFile. This map doesn't change after it's constructed in Setup() 492*795d594fSAndroid Build Coastguard Worker // and therefore doesn't need any locking and provides the cheapest dex file lookup 493*795d594fSAndroid Build Coastguard Worker // for GetOatDexFile() for a very frequent use case. Never contains a null value. 494*795d594fSAndroid Build Coastguard Worker Table oat_dex_files_; 495*795d594fSAndroid Build Coastguard Worker 496*795d594fSAndroid Build Coastguard Worker // Lock guarding all members needed for secondary lookup in GetOatDexFile(). 497*795d594fSAndroid Build Coastguard Worker mutable Mutex secondary_lookup_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; 498*795d594fSAndroid Build Coastguard Worker 499*795d594fSAndroid Build Coastguard Worker // If the primary oat_dex_files_ lookup fails, use a secondary map. This map stores 500*795d594fSAndroid Build Coastguard Worker // the results of all previous secondary lookups, whether successful (non-null) or 501*795d594fSAndroid Build Coastguard Worker // failed (null). If it doesn't contain an entry we need to calculate the canonical 502*795d594fSAndroid Build Coastguard Worker // location and use oat_dex_files_by_canonical_location_. 503*795d594fSAndroid Build Coastguard Worker mutable Table secondary_oat_dex_files_ GUARDED_BY(secondary_lookup_lock_); 504*795d594fSAndroid Build Coastguard Worker 505*795d594fSAndroid Build Coastguard Worker // Cache of strings. Contains the backing storage for keys in the secondary_oat_dex_files_ 506*795d594fSAndroid Build Coastguard Worker // and the lazily initialized oat_dex_files_by_canonical_location_. 507*795d594fSAndroid Build Coastguard Worker // NOTE: We're keeping references to contained strings in form of std::string_view and adding 508*795d594fSAndroid Build Coastguard Worker // new strings to the end. The adding of a new element must not touch any previously stored 509*795d594fSAndroid Build Coastguard Worker // elements. std::list<> and std::deque<> satisfy this requirement, std::vector<> doesn't. 510*795d594fSAndroid Build Coastguard Worker mutable std::list<std::string> string_cache_ GUARDED_BY(secondary_lookup_lock_); 511*795d594fSAndroid Build Coastguard Worker 512*795d594fSAndroid Build Coastguard Worker // Dex files opened directly from a file referenced from the oat file or specifed 513*795d594fSAndroid Build Coastguard Worker // by the `dex_filenames` parameter, in case the OatFile does not embed the dex code. 514*795d594fSAndroid Build Coastguard Worker std::vector<std::unique_ptr<const DexFile>> external_dex_files_; 515*795d594fSAndroid Build Coastguard Worker 516*795d594fSAndroid Build Coastguard Worker friend class gc::collector::FakeOatFile; // For modifying begin_ and end_. 517*795d594fSAndroid Build Coastguard Worker friend class OatClass; 518*795d594fSAndroid Build Coastguard Worker friend class art::OatDexFile; 519*795d594fSAndroid Build Coastguard Worker friend class OatDumper; // For GetBase and GetLimit 520*795d594fSAndroid Build Coastguard Worker friend class OatFileBackedByVdex; 521*795d594fSAndroid Build Coastguard Worker friend class OatFileBase; 522*795d594fSAndroid Build Coastguard Worker DISALLOW_COPY_AND_ASSIGN(OatFile); 523*795d594fSAndroid Build Coastguard Worker }; 524*795d594fSAndroid Build Coastguard Worker 525*795d594fSAndroid Build Coastguard Worker // OatDexFile should be an inner class of OatFile. Unfortunately, C++ doesn't 526*795d594fSAndroid Build Coastguard Worker // support forward declarations of inner classes, and we want to 527*795d594fSAndroid Build Coastguard Worker // forward-declare OatDexFile so that we can store an opaque pointer to an 528*795d594fSAndroid Build Coastguard Worker // OatDexFile in DexFile. 529*795d594fSAndroid Build Coastguard Worker class OatDexFile final { 530*795d594fSAndroid Build Coastguard Worker public: 531*795d594fSAndroid Build Coastguard Worker // Opens the DexFile referred to by this OatDexFile from within the containing OatFile. 532*795d594fSAndroid Build Coastguard Worker EXPORT std::unique_ptr<const DexFile> OpenDexFile(std::string* error_msg) const; 533*795d594fSAndroid Build Coastguard Worker 534*795d594fSAndroid Build Coastguard Worker // May return null if the OatDexFile only contains a type lookup table. This case only happens 535*795d594fSAndroid Build Coastguard Worker // for the compiler to speed up compilation, or in jitzygote. GetOatFile()536*795d594fSAndroid Build Coastguard Worker const OatFile* GetOatFile() const { 537*795d594fSAndroid Build Coastguard Worker return oat_file_; 538*795d594fSAndroid Build Coastguard Worker } 539*795d594fSAndroid Build Coastguard Worker 540*795d594fSAndroid Build Coastguard Worker // Returns the size of the DexFile refered to by this OatDexFile. 541*795d594fSAndroid Build Coastguard Worker EXPORT size_t FileSize() const; 542*795d594fSAndroid Build Coastguard Worker 543*795d594fSAndroid Build Coastguard Worker // Returns original path of DexFile that was the source of this OatDexFile. GetDexFileLocation()544*795d594fSAndroid Build Coastguard Worker const std::string& GetDexFileLocation() const { 545*795d594fSAndroid Build Coastguard Worker return dex_file_location_; 546*795d594fSAndroid Build Coastguard Worker } 547*795d594fSAndroid Build Coastguard Worker 548*795d594fSAndroid Build Coastguard Worker // Returns original path of DexFile that was the source of this OatDexFile. GetLocation()549*795d594fSAndroid Build Coastguard Worker const std::string& GetLocation() const { return dex_file_location_; } 550*795d594fSAndroid Build Coastguard Worker 551*795d594fSAndroid Build Coastguard Worker // Returns the canonical location of DexFile that was the source of this OatDexFile. GetCanonicalDexFileLocation()552*795d594fSAndroid Build Coastguard Worker const std::string& GetCanonicalDexFileLocation() const { 553*795d594fSAndroid Build Coastguard Worker return canonical_dex_file_location_; 554*795d594fSAndroid Build Coastguard Worker } 555*795d594fSAndroid Build Coastguard Worker GetMagic()556*795d594fSAndroid Build Coastguard Worker DexFile::Magic GetMagic() const { return dex_file_magic_; } 557*795d594fSAndroid Build Coastguard Worker 558*795d594fSAndroid Build Coastguard Worker uint32_t GetDexVersion() const; 559*795d594fSAndroid Build Coastguard Worker 560*795d594fSAndroid Build Coastguard Worker // Returns checksum of original DexFile that was the source of this OatDexFile; GetDexFileLocationChecksum()561*795d594fSAndroid Build Coastguard Worker uint32_t GetDexFileLocationChecksum() const { 562*795d594fSAndroid Build Coastguard Worker return dex_file_location_checksum_; 563*795d594fSAndroid Build Coastguard Worker } 564*795d594fSAndroid Build Coastguard Worker 565*795d594fSAndroid Build Coastguard Worker // Returns checksum of original DexFile that was the source of this OatDexFile; GetLocationChecksum()566*795d594fSAndroid Build Coastguard Worker uint32_t GetLocationChecksum() const { return dex_file_location_checksum_; } 567*795d594fSAndroid Build Coastguard Worker GetSha1()568*795d594fSAndroid Build Coastguard Worker DexFile::Sha1 GetSha1() const { return dex_file_sha1_; } 569*795d594fSAndroid Build Coastguard Worker 570*795d594fSAndroid Build Coastguard Worker // Returns the OatClass for the class specified by the given DexFile class_def_index. 571*795d594fSAndroid Build Coastguard Worker EXPORT OatFile::OatClass GetOatClass(uint16_t class_def_index) const; 572*795d594fSAndroid Build Coastguard Worker 573*795d594fSAndroid Build Coastguard Worker // Returns the offset to the OatClass information. Most callers should use GetOatClass. 574*795d594fSAndroid Build Coastguard Worker EXPORT uint32_t GetOatClassOffset(uint16_t class_def_index) const; 575*795d594fSAndroid Build Coastguard Worker GetLookupTableData()576*795d594fSAndroid Build Coastguard Worker const uint8_t* GetLookupTableData() const { 577*795d594fSAndroid Build Coastguard Worker return lookup_table_data_; 578*795d594fSAndroid Build Coastguard Worker } 579*795d594fSAndroid Build Coastguard Worker GetMethodBssMapping()580*795d594fSAndroid Build Coastguard Worker const IndexBssMapping* GetMethodBssMapping() const { 581*795d594fSAndroid Build Coastguard Worker return bss_mapping_info_.method_bss_mapping; 582*795d594fSAndroid Build Coastguard Worker } 583*795d594fSAndroid Build Coastguard Worker GetTypeBssMapping()584*795d594fSAndroid Build Coastguard Worker const IndexBssMapping* GetTypeBssMapping() const { 585*795d594fSAndroid Build Coastguard Worker return bss_mapping_info_.type_bss_mapping; 586*795d594fSAndroid Build Coastguard Worker } 587*795d594fSAndroid Build Coastguard Worker GetPublicTypeBssMapping()588*795d594fSAndroid Build Coastguard Worker const IndexBssMapping* GetPublicTypeBssMapping() const { 589*795d594fSAndroid Build Coastguard Worker return bss_mapping_info_.public_type_bss_mapping; 590*795d594fSAndroid Build Coastguard Worker } 591*795d594fSAndroid Build Coastguard Worker GetPackageTypeBssMapping()592*795d594fSAndroid Build Coastguard Worker const IndexBssMapping* GetPackageTypeBssMapping() const { 593*795d594fSAndroid Build Coastguard Worker return bss_mapping_info_.package_type_bss_mapping; 594*795d594fSAndroid Build Coastguard Worker } 595*795d594fSAndroid Build Coastguard Worker GetStringBssMapping()596*795d594fSAndroid Build Coastguard Worker const IndexBssMapping* GetStringBssMapping() const { 597*795d594fSAndroid Build Coastguard Worker return bss_mapping_info_.string_bss_mapping; 598*795d594fSAndroid Build Coastguard Worker } 599*795d594fSAndroid Build Coastguard Worker GetMethodTypeBssMapping()600*795d594fSAndroid Build Coastguard Worker const IndexBssMapping* GetMethodTypeBssMapping() const { 601*795d594fSAndroid Build Coastguard Worker return bss_mapping_info_.method_type_bss_mapping; 602*795d594fSAndroid Build Coastguard Worker } 603*795d594fSAndroid Build Coastguard Worker GetDexFilePointer()604*795d594fSAndroid Build Coastguard Worker const uint8_t* GetDexFilePointer() const { 605*795d594fSAndroid Build Coastguard Worker return dex_file_pointer_; 606*795d594fSAndroid Build Coastguard Worker } 607*795d594fSAndroid Build Coastguard Worker 608*795d594fSAndroid Build Coastguard Worker // Looks up a class definition by its class descriptor. Hash must be 609*795d594fSAndroid Build Coastguard Worker // ComputeModifiedUtf8Hash(descriptor). 610*795d594fSAndroid Build Coastguard Worker EXPORT static const dex::ClassDef* FindClassDef(const DexFile& dex_file, 611*795d594fSAndroid Build Coastguard Worker std::string_view descriptor, 612*795d594fSAndroid Build Coastguard Worker size_t hash); 613*795d594fSAndroid Build Coastguard Worker GetTypeLookupTable()614*795d594fSAndroid Build Coastguard Worker const TypeLookupTable& GetTypeLookupTable() const { 615*795d594fSAndroid Build Coastguard Worker return lookup_table_; 616*795d594fSAndroid Build Coastguard Worker } 617*795d594fSAndroid Build Coastguard Worker 618*795d594fSAndroid Build Coastguard Worker EXPORT ~OatDexFile(); 619*795d594fSAndroid Build Coastguard Worker 620*795d594fSAndroid Build Coastguard Worker // Create only with a type lookup table, used by the compiler to speed up compilation. 621*795d594fSAndroid Build Coastguard Worker EXPORT explicit OatDexFile(TypeLookupTable&& lookup_table); 622*795d594fSAndroid Build Coastguard Worker 623*795d594fSAndroid Build Coastguard Worker // Return the dex layout sections. GetDexLayoutSections()624*795d594fSAndroid Build Coastguard Worker const DexLayoutSections* GetDexLayoutSections() const { 625*795d594fSAndroid Build Coastguard Worker return dex_layout_sections_; 626*795d594fSAndroid Build Coastguard Worker } 627*795d594fSAndroid Build Coastguard Worker 628*795d594fSAndroid Build Coastguard Worker private: 629*795d594fSAndroid Build Coastguard Worker OatDexFile(const OatFile* oat_file, 630*795d594fSAndroid Build Coastguard Worker const std::string& dex_file_location, 631*795d594fSAndroid Build Coastguard Worker const std::string& canonical_dex_file_location, 632*795d594fSAndroid Build Coastguard Worker DexFile::Magic dex_file_magic, 633*795d594fSAndroid Build Coastguard Worker uint32_t dex_file_checksum, 634*795d594fSAndroid Build Coastguard Worker DexFile::Sha1 dex_file_sha1, 635*795d594fSAndroid Build Coastguard Worker const std::shared_ptr<DexFileContainer>& dex_file_container_, 636*795d594fSAndroid Build Coastguard Worker const uint8_t* dex_file_pointer, 637*795d594fSAndroid Build Coastguard Worker const uint8_t* lookup_table_data, 638*795d594fSAndroid Build Coastguard Worker const OatFile::BssMappingInfo& bss_mapping_info, 639*795d594fSAndroid Build Coastguard Worker const uint32_t* oat_class_offsets_pointer, 640*795d594fSAndroid Build Coastguard Worker const DexLayoutSections* dex_layout_sections); 641*795d594fSAndroid Build Coastguard Worker 642*795d594fSAndroid Build Coastguard Worker // Create an OatDexFile wrapping an existing DexFile. Will set the OatDexFile 643*795d594fSAndroid Build Coastguard Worker // pointer in the DexFile. 644*795d594fSAndroid Build Coastguard Worker OatDexFile(const OatFile* oat_file, 645*795d594fSAndroid Build Coastguard Worker const std::shared_ptr<DexFileContainer>& dex_file_container_, 646*795d594fSAndroid Build Coastguard Worker const uint8_t* dex_file_pointer, 647*795d594fSAndroid Build Coastguard Worker DexFile::Magic dex_file_magic, 648*795d594fSAndroid Build Coastguard Worker uint32_t dex_file_checksum, 649*795d594fSAndroid Build Coastguard Worker DexFile::Sha1 dex_file_sha1, 650*795d594fSAndroid Build Coastguard Worker const std::string& dex_file_location, 651*795d594fSAndroid Build Coastguard Worker const std::string& canonical_dex_file_location, 652*795d594fSAndroid Build Coastguard Worker const uint8_t* lookup_table_data); 653*795d594fSAndroid Build Coastguard Worker 654*795d594fSAndroid Build Coastguard Worker bool IsBackedByVdexOnly() const; 655*795d594fSAndroid Build Coastguard Worker void InitializeTypeLookupTable(); 656*795d594fSAndroid Build Coastguard Worker 657*795d594fSAndroid Build Coastguard Worker static void AssertAotCompiler(); 658*795d594fSAndroid Build Coastguard Worker 659*795d594fSAndroid Build Coastguard Worker const OatFile* const oat_file_ = nullptr; 660*795d594fSAndroid Build Coastguard Worker const std::string dex_file_location_; 661*795d594fSAndroid Build Coastguard Worker const std::string canonical_dex_file_location_; 662*795d594fSAndroid Build Coastguard Worker const DexFile::Magic dex_file_magic_ = {}; 663*795d594fSAndroid Build Coastguard Worker const uint32_t dex_file_location_checksum_ = 0u; 664*795d594fSAndroid Build Coastguard Worker const DexFile::Sha1 dex_file_sha1_ = {}; 665*795d594fSAndroid Build Coastguard Worker const std::shared_ptr<DexFileContainer> dex_file_container_; 666*795d594fSAndroid Build Coastguard Worker const uint8_t* const dex_file_pointer_ = nullptr; 667*795d594fSAndroid Build Coastguard Worker const uint8_t* const lookup_table_data_ = nullptr; 668*795d594fSAndroid Build Coastguard Worker const OatFile::BssMappingInfo bss_mapping_info_; 669*795d594fSAndroid Build Coastguard Worker const uint32_t* const oat_class_offsets_pointer_ = nullptr; 670*795d594fSAndroid Build Coastguard Worker TypeLookupTable lookup_table_; 671*795d594fSAndroid Build Coastguard Worker const DexLayoutSections* const dex_layout_sections_ = nullptr; 672*795d594fSAndroid Build Coastguard Worker 673*795d594fSAndroid Build Coastguard Worker friend class OatFile; 674*795d594fSAndroid Build Coastguard Worker friend class OatFileBase; 675*795d594fSAndroid Build Coastguard Worker friend class OatFileBackedByVdex; 676*795d594fSAndroid Build Coastguard Worker DISALLOW_COPY_AND_ASSIGN(OatDexFile); 677*795d594fSAndroid Build Coastguard Worker }; 678*795d594fSAndroid Build Coastguard Worker 679*795d594fSAndroid Build Coastguard Worker } // namespace art 680*795d594fSAndroid Build Coastguard Worker 681*795d594fSAndroid Build Coastguard Worker #endif // ART_RUNTIME_OAT_OAT_FILE_H_ 682