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