oat_file.h revision eb8167a4f4d27fce0530f6724ab8032610cd146b
12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/* 22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2011 The Android Open Source Project 32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License. 62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at 72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * 102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software 112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and 142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License. 152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */ 16e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 17fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#ifndef ART_RUNTIME_OAT_FILE_H_ 18fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#define ART_RUNTIME_OAT_FILE_H_ 19e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 20700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom#include <string> 21e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom#include <vector> 22e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 232dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "dex_file.h" 242dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "invoke_type.h" 252dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mem_map.h" 26ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom#include "mirror/art_method.h" 272dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "oat.h" 28700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom#include "os.h" 29e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 30e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstromnamespace art { 31e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 32ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstromclass BitVector; 33700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstromclass ElfFile; 34700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstromclass MemMap; 35700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstromclass OatMethodOffsets; 3633e9566255c426e7a2c8fca5b8a1b6a94a5d352cIan Rogersclass OatHeader; 37700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 38e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstromclass OatFile { 39e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom public: 4030e2ea4a701d53f28431041af68dc0669e60c569Brian Carlstrom // Returns an .odex file name next adjacent to the dex location. 4130e2ea4a701d53f28431041af68dc0669e60c569Brian Carlstrom // For example, for "/foo/bar/baz.jar", return "/foo/bar/baz.odex". 4230e2ea4a701d53f28431041af68dc0669e60c569Brian Carlstrom static std::string DexFilenameToOdexFilename(const std::string& location); 43b7bbba49d88eae58223d9878da4069bf6d7140bfBrian Carlstrom 44e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // Open an oat file. Returns NULL on failure. Requested base can 45e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // optionally be used to request where the file should be loaded. 46e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom static OatFile* Open(const std::string& filename, 47a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom const std::string& location, 48f1d3455064792ac1c486a4a9c24279a37b4af473Brian Carlstrom byte* requested_base, 498d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool executable, 508d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 51e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 52700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Open an oat file from an already opened File. 53265091e581c9f643b37e7966890911f09e223269Brian Carlstrom // Does not use dlopen underneath so cannot be used for runtime use 54265091e581c9f643b37e7966890911f09e223269Brian Carlstrom // where relocations may be required. Currently used from 55265091e581c9f643b37e7966890911f09e223269Brian Carlstrom // ImageWriter which wants to open a writable version from an existing 56265091e581c9f643b37e7966890911f09e223269Brian Carlstrom // file descriptor for patching. 578d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers static OatFile* OpenWritable(File* file, const std::string& location, std::string* error_msg); 58700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 59700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Open an oat file backed by a std::vector with the given location. 60265091e581c9f643b37e7966890911f09e223269Brian Carlstrom static OatFile* OpenMemory(std::vector<uint8_t>& oat_contents, 618d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers const std::string& location, 628d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 635b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom 64e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom ~OatFile(); 65e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 66e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom const std::string& GetLocation() const { 67e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom return location_; 68e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom } 69e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 70e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom const OatHeader& GetOatHeader() const; 71e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 72e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom class OatDexFile; 73e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 743320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom class OatMethod { 753320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom public: 76b0fa5dc7769c1e054032f39de0a3f6d6dd06f8cfIan Rogers void LinkMethod(mirror::ArtMethod* method) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 77ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 78ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom uint32_t GetCodeOffset() const { 79ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom return code_offset_; 80ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom } 810c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers uint32_t GetNativeGcMapOffset() const { 820c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers return native_gc_map_offset_; 83e7d856b911222aa000ca2be0f8f63f5b292141c3Brian Carlstrom } 84ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 85ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const void* GetPortableCode() const { 86ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers // TODO: encode whether code is portable/quick in flags within OatMethod. 87ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers if (kUsePortableCompiler) { 88ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return GetOatPointer<const void*>(code_offset_); 89ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } else { 90ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return nullptr; 91ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 92ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 93ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers 94ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const void* GetQuickCode() const { 95ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers if (kUsePortableCompiler) { 96ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return nullptr; 97ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } else { 98ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return GetOatPointer<const void*>(code_offset_); 99ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 100ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 101ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers 102ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers uint32_t GetPortableCodeSize() const { 103ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers // TODO: With Quick, we store the size before the code. With Portable, the code is in a .o 104ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers // file we don't manage ourselves. ELF symbols do have a concept of size, so we could capture 105ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers // that and store it somewhere, such as the OatMethod. 106ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return 0; 107ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 108ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers uint32_t GetQuickCodeSize() const; 1090c717dd1c56bd29cf860d0feda8e629dab2cadb3Logan Chien 1100c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers const uint8_t* GetNativeGcMap() const { 1110c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers return GetOatPointer<const uint8_t*>(native_gc_map_offset_); 112e7d856b911222aa000ca2be0f8f63f5b292141c3Brian Carlstrom } 1130c717dd1c56bd29cf860d0feda8e629dab2cadb3Logan Chien 1147624d25dad2d1ba25969ae704fccf68649103ae5Vladimir Marko size_t GetFrameSizeInBytes() const; 1157624d25dad2d1ba25969ae704fccf68649103ae5Vladimir Marko uint32_t GetCoreSpillMask() const; 1167624d25dad2d1ba25969ae704fccf68649103ae5Vladimir Marko uint32_t GetFpSpillMask() const; 1178a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko uint32_t GetMappingTableOffset() const; 1188a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko uint32_t GetVmapTableOffset() const; 1198a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko const uint8_t* GetMappingTable() const; 1208a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko const uint8_t* GetVmapTable() const; 1218a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko 122ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom ~OatMethod(); 123ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 124ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom // Create an OatMethod with offsets relative to the given base address 125ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom OatMethod(const byte* base, 126ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom const uint32_t code_offset, 1276a47b9dc850b903aabefcfab4adb132cb68bba2eBrian Carlstrom const uint32_t gc_map_offset); 1283320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 129ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom private: 130ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom template<class T> 131ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom T GetOatPointer(uint32_t offset) const { 132ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom if (offset == 0) { 133ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom return NULL; 134ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom } 13530fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers return reinterpret_cast<T>(begin_ + offset); 136ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom } 1373320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 13830fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers const byte* begin_; 1393320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 140ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom uint32_t code_offset_; 1410c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers uint32_t native_gc_map_offset_; 142ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 143ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom friend class OatClass; 1443320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom }; 1453320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 146e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom class OatClass { 147e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom public: 148ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom mirror::Class::Status GetStatus() const { 149ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom return status_; 150ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom } 151ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 152ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom OatClassType GetType() const { 153ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom return type_; 154ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom } 1550755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom 156eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier // Get the OatMethod entry based on its index into the class 157e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // defintion. direct methods come first, followed by virtual 158e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // methods. note that runtime created methods such as miranda 159e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // methods are not included. 160aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom const OatMethod GetOatMethod(uint32_t method_index) const; 161e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 162e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom private: 1630755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom OatClass(const OatFile* oat_file, 1642dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Class::Status status, 165ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom OatClassType type, 166ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom uint32_t bitmap_size, 167ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom const uint32_t* bitmap_pointer, 1680755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom const OatMethodOffsets* methods_pointer); 1693320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 170d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko const OatFile* const oat_file_; 171ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 1722dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers const mirror::Class::Status status_; 173ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 174d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko const OatClassType type_; 175ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 176d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko const uint32_t* const bitmap_; 177ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 1783320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom const OatMethodOffsets* methods_pointer_; 179e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 180e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom friend class OatDexFile; 181e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom }; 182e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 183e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom class OatDexFile { 184e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom public: 18556d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Opens the DexFile referred to by this OatDexFile from within the containing OatFile. 1868d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers const DexFile* OpenDexFile(std::string* error_msg) const; 18756d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom 18856d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Returns the size of the DexFile refered to by this OatDexFile. 18905f28c6e00ecdb1da834acc8c29b4a7eba86d692Ian Rogers size_t FileSize() const; 190aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 19156d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Returns original path of DexFile that was the source of this OatDexFile. 192aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom const std::string& GetDexFileLocation() const { 193aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom return dex_file_location_; 194aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 19558ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom 19656d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Returns checksum of original DexFile that was the source of this OatDexFile; 1975b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom uint32_t GetDexFileLocationChecksum() const { 1985b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom return dex_file_location_checksum_; 19958ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom } 20058ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom 20156d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Returns the OatClass for the class specified by the given DexFile class_def_index. 202d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko OatClass GetOatClass(uint16_t class_def_index) const; 20356d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom 204e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom ~OatDexFile(); 205a21039c3ae2b20e44ceb2735251c04d0aac89afdElliott Hughes 206e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom private: 207e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom OatDexFile(const OatFile* oat_file, 208aa6a588eb83288481389aa08b03105346a87e706Elliott Hughes const std::string& dex_file_location, 209e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom uint32_t dex_file_checksum, 210700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const byte* dex_file_pointer, 2110755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom const uint32_t* oat_class_offsets_pointer); 212e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 213e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom const OatFile* oat_file_; 214e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom std::string dex_file_location_; 2155b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom uint32_t dex_file_location_checksum_; 21689521898b56f2ebc3fb68acfb6bc6dde9b6f5c38Brian Carlstrom const byte* dex_file_pointer_; 2170755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom const uint32_t* oat_class_offsets_pointer_; 218e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 219e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom friend class OatFile; 220e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom DISALLOW_COPY_AND_ASSIGN(OatDexFile); 221e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom }; 222e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 2238d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers const OatDexFile* GetOatDexFile(const char* dex_location, 224756ee4e090bc1e1812b41fb7b4661df601a32ef9Brian Carlstrom const uint32_t* const dex_location_checksum, 2258d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool exception_if_not_found = true) const; 2268d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers 227aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom std::vector<const OatDexFile*> GetOatDexFiles() const; 228e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 22930fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers size_t Size() const { 23030fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers return End() - Begin(); 231e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom } 232e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 233e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom private: 234700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom static void CheckLocation(const std::string& location); 235700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 236700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom static OatFile* OpenDlopen(const std::string& elf_filename, 237700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const std::string& location, 2388d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers byte* requested_base, 2398d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 240700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 241700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom static OatFile* OpenElfFile(File* file, 242700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const std::string& location, 243700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom byte* requested_base, 244f1d3455064792ac1c486a4a9c24279a37b4af473Brian Carlstrom bool writable, 2458d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool executable, 2468d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 247700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 248a51a3dd5603daf3d368b7735067e1d9eb54c4c40Elliott Hughes explicit OatFile(const std::string& filename); 2498d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool Dlopen(const std::string& elf_filename, byte* requested_base, std::string* error_msg); 2508d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool ElfFileOpen(File* file, byte* requested_base, bool writable, bool executable, 2518d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 2528d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool Setup(std::string* error_msg); 253e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 25430fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers const byte* Begin() const; 25530fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers const byte* End() const; 256e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 257e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // The oat file name. 258e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // 259e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // The image will embed this to link its associated oat file. 260e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom const std::string location_; 261e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 262700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Pointer to OatHeader. 263700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const byte* begin_; 264700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 265700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Pointer to end of oat region for bounds checking. 266700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const byte* end_; 267700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 268700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Backing memory map for oat file during when opened by ElfWriter during initial compilation. 269e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom UniquePtr<MemMap> mem_map_; 270e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 271700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Backing memory map for oat file during cross compilation. 272700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom UniquePtr<ElfFile> elf_file_; 273700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 274700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // dlopen handle during runtime. 275700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom void* dlopen_handle_; 276700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 277a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes typedef SafeMap<std::string, const OatDexFile*> Table; 278e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom Table oat_dex_files_; 279e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 280e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom friend class OatClass; 281e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom friend class OatDexFile; 282e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes friend class OatDumper; // For GetBase and GetLimit 283e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom DISALLOW_COPY_AND_ASSIGN(OatFile); 284e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom}; 285e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 286e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom} // namespace art 287e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 288fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif // ART_RUNTIME_OAT_FILE_H_ 289