oat_file.h revision a59dd80f9f48cb750d329d4d4af2d99d72b484d1
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 23539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko#include "base/stringpiece.h" 242dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "dex_file.h" 252dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "invoke_type.h" 262dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mem_map.h" 2798d1cc8033251c93786e2fa8c59a2e555a9493beMingyao Yang#include "mirror/class.h" 282dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "oat.h" 29700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom#include "os.h" 30e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 31e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstromnamespace art { 32e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 33ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstromclass BitVector; 34700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstromclass ElfFile; 35700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstromclass MemMap; 36700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstromclass OatMethodOffsets; 3733e9566255c426e7a2c8fca5b8a1b6a94a5d352cIan Rogersclass OatHeader; 38700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 39e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstromclass OatFile { 40e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom public: 41e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // Open an oat file. Returns NULL on failure. Requested base can 42e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // optionally be used to request where the file should be loaded. 43e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom static OatFile* Open(const std::string& filename, 44a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom const std::string& location, 45f1d3455064792ac1c486a4a9c24279a37b4af473Brian Carlstrom byte* requested_base, 468d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool executable, 478d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 48e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 49700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Open an oat file from an already opened File. 50265091e581c9f643b37e7966890911f09e223269Brian Carlstrom // Does not use dlopen underneath so cannot be used for runtime use 51265091e581c9f643b37e7966890911f09e223269Brian Carlstrom // where relocations may be required. Currently used from 52265091e581c9f643b37e7966890911f09e223269Brian Carlstrom // ImageWriter which wants to open a writable version from an existing 53265091e581c9f643b37e7966890911f09e223269Brian Carlstrom // file descriptor for patching. 548d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers static OatFile* OpenWritable(File* file, const std::string& location, std::string* error_msg); 55a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light // Opens an oat file from an already opened File. Maps it PROT_READ, MAP_PRIVATE. 56a59dd80f9f48cb750d329d4d4af2d99d72b484d1Alex Light static OatFile* OpenReadable(File* file, const std::string& location, std::string* error_msg); 57700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 58700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Open an oat file backed by a std::vector with the given location. 59265091e581c9f643b37e7966890911f09e223269Brian Carlstrom static OatFile* OpenMemory(std::vector<uint8_t>& oat_contents, 608d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers const std::string& location, 618d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 625b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom 63e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom ~OatFile(); 64e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 6553cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light ElfFile* GetElfFile() const { 6653cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light CHECK_NE(reinterpret_cast<uintptr_t>(elf_file_.get()), reinterpret_cast<uintptr_t>(nullptr)) 6753cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light << "Cannot get an elf file from " << GetLocation(); 6853cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light return elf_file_.get(); 6953cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light } 7053cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light 71e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom const std::string& GetLocation() const { 72e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom return location_; 73e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom } 74e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 75e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom const OatHeader& GetOatHeader() const; 76e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 77e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom class OatDexFile; 78e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 793320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom class OatMethod { 803320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom public: 81b0fa5dc7769c1e054032f39de0a3f6d6dd06f8cfIan Rogers void LinkMethod(mirror::ArtMethod* method) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 82ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 83ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom uint32_t GetCodeOffset() const { 84ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom return code_offset_; 85ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom } 860c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers uint32_t GetNativeGcMapOffset() const { 870c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers return native_gc_map_offset_; 88e7d856b911222aa000ca2be0f8f63f5b292141c3Brian Carlstrom } 89ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 90ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const void* GetPortableCode() const { 91ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers // TODO: encode whether code is portable/quick in flags within OatMethod. 92ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers if (kUsePortableCompiler) { 93ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return GetOatPointer<const void*>(code_offset_); 94ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } else { 95ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return nullptr; 96ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 97ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 98ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers 99ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const void* GetQuickCode() const { 100ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers if (kUsePortableCompiler) { 101ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return nullptr; 102ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } else { 103ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return GetOatPointer<const void*>(code_offset_); 104ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 105ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 106ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers 107ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers uint32_t GetPortableCodeSize() const { 108ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers // TODO: With Quick, we store the size before the code. With Portable, the code is in a .o 109ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers // file we don't manage ourselves. ELF symbols do have a concept of size, so we could capture 110ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers // that and store it somewhere, such as the OatMethod. 111ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return 0; 112ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 113ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers uint32_t GetQuickCodeSize() const; 1140c717dd1c56bd29cf860d0feda8e629dab2cadb3Logan Chien 1150c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers const uint8_t* GetNativeGcMap() const { 1160c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers return GetOatPointer<const uint8_t*>(native_gc_map_offset_); 117e7d856b911222aa000ca2be0f8f63f5b292141c3Brian Carlstrom } 1180c717dd1c56bd29cf860d0feda8e629dab2cadb3Logan Chien 1197624d25dad2d1ba25969ae704fccf68649103ae5Vladimir Marko size_t GetFrameSizeInBytes() const; 1207624d25dad2d1ba25969ae704fccf68649103ae5Vladimir Marko uint32_t GetCoreSpillMask() const; 1217624d25dad2d1ba25969ae704fccf68649103ae5Vladimir Marko uint32_t GetFpSpillMask() const; 1228a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko uint32_t GetMappingTableOffset() const; 1238a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko uint32_t GetVmapTableOffset() const; 1248a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko const uint8_t* GetMappingTable() const; 1258a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko const uint8_t* GetVmapTable() const; 1268a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko 127ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom ~OatMethod(); 128ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 129ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom // Create an OatMethod with offsets relative to the given base address 130ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom OatMethod(const byte* base, 131ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom const uint32_t code_offset, 1326a47b9dc850b903aabefcfab4adb132cb68bba2eBrian Carlstrom const uint32_t gc_map_offset); 1333320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 134ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom private: 135ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom template<class T> 136ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom T GetOatPointer(uint32_t offset) const { 137ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom if (offset == 0) { 138ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom return NULL; 139ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom } 14030fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers return reinterpret_cast<T>(begin_ + offset); 141ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom } 1423320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 14330fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers const byte* begin_; 1443320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 145ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom uint32_t code_offset_; 1460c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers uint32_t native_gc_map_offset_; 147ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 148ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom friend class OatClass; 1493320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom }; 1503320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 151e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom class OatClass { 152e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom public: 153ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom mirror::Class::Status GetStatus() const { 154ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom return status_; 155ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom } 156ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 157ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom OatClassType GetType() const { 158ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom return type_; 159ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom } 1600755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom 161eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier // Get the OatMethod entry based on its index into the class 162e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // defintion. direct methods come first, followed by virtual 163e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // methods. note that runtime created methods such as miranda 164e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // methods are not included. 165aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom const OatMethod GetOatMethod(uint32_t method_index) const; 166e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 167e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom private: 1680755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom OatClass(const OatFile* oat_file, 1692dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Class::Status status, 170ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom OatClassType type, 171ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom uint32_t bitmap_size, 172ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom const uint32_t* bitmap_pointer, 1730755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom const OatMethodOffsets* methods_pointer); 1743320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 175d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko const OatFile* const oat_file_; 176ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 1772dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers const mirror::Class::Status status_; 178ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 179d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko const OatClassType type_; 180ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 181d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko const uint32_t* const bitmap_; 182ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 1833320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom const OatMethodOffsets* methods_pointer_; 184e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 185e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom friend class OatDexFile; 186e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom }; 187e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 188e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom class OatDexFile { 189e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom public: 19056d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Opens the DexFile referred to by this OatDexFile from within the containing OatFile. 1918d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers const DexFile* OpenDexFile(std::string* error_msg) const; 19256d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom 19356d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Returns the size of the DexFile refered to by this OatDexFile. 19405f28c6e00ecdb1da834acc8c29b4a7eba86d692Ian Rogers size_t FileSize() const; 195aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 19656d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Returns original path of DexFile that was the source of this OatDexFile. 197aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom const std::string& GetDexFileLocation() const { 198aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom return dex_file_location_; 199aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 20058ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom 20156d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Returns checksum of original DexFile that was the source of this OatDexFile; 2025b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom uint32_t GetDexFileLocationChecksum() const { 2035b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom return dex_file_location_checksum_; 20458ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom } 20558ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom 20656d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Returns the OatClass for the class specified by the given DexFile class_def_index. 207d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko OatClass GetOatClass(uint16_t class_def_index) const; 20856d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom 209e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom ~OatDexFile(); 210a21039c3ae2b20e44ceb2735251c04d0aac89afdElliott Hughes 211e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom private: 212e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom OatDexFile(const OatFile* oat_file, 213aa6a588eb83288481389aa08b03105346a87e706Elliott Hughes const std::string& dex_file_location, 214e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom uint32_t dex_file_checksum, 215700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const byte* dex_file_pointer, 2160755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom const uint32_t* oat_class_offsets_pointer); 217e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 218539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko const OatFile* const oat_file_; 219539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko const std::string dex_file_location_; 220539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko const uint32_t dex_file_location_checksum_; 221539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko const byte* const dex_file_pointer_; 222539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko const uint32_t* const oat_class_offsets_pointer_; 223e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 224e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom friend class OatFile; 225e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom DISALLOW_COPY_AND_ASSIGN(OatDexFile); 226e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom }; 227e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 2288d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers const OatDexFile* GetOatDexFile(const char* dex_location, 229756ee4e090bc1e1812b41fb7b4661df601a32ef9Brian Carlstrom const uint32_t* const dex_location_checksum, 2308d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool exception_if_not_found = true) const; 2318d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers 232aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom std::vector<const OatDexFile*> GetOatDexFiles() const; 233e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 23430fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers size_t Size() const { 23530fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers return End() - Begin(); 236e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom } 237e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 23853cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light const byte* Begin() const; 23953cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light const byte* End() const; 24053cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light 241e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom private: 242700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom static void CheckLocation(const std::string& location); 243700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 244700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom static OatFile* OpenDlopen(const std::string& elf_filename, 245700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const std::string& location, 2468d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers byte* requested_base, 2478d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 248700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 249700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom static OatFile* OpenElfFile(File* file, 250700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const std::string& location, 251700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom byte* requested_base, 252f1d3455064792ac1c486a4a9c24279a37b4af473Brian Carlstrom bool writable, 2538d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool executable, 2548d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 255700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 256a51a3dd5603daf3d368b7735067e1d9eb54c4c40Elliott Hughes explicit OatFile(const std::string& filename); 2578d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool Dlopen(const std::string& elf_filename, byte* requested_base, std::string* error_msg); 2588d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool ElfFileOpen(File* file, byte* requested_base, bool writable, bool executable, 2598d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 2608d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool Setup(std::string* error_msg); 261e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 262e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // The oat file name. 263e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // 264e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // The image will embed this to link its associated oat file. 265e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom const std::string location_; 266e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 267700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Pointer to OatHeader. 268700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const byte* begin_; 269700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 270700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Pointer to end of oat region for bounds checking. 271700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const byte* end_; 272700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 273700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Backing memory map for oat file during when opened by ElfWriter during initial compilation. 274700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers std::unique_ptr<MemMap> mem_map_; 275e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 276700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Backing memory map for oat file during cross compilation. 277700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers std::unique_ptr<ElfFile> elf_file_; 278700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 279700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // dlopen handle during runtime. 280700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom void* dlopen_handle_; 281700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 282539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko // NOTE: We use a StringPiece as the key type to avoid a memory allocation on every lookup 283539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko // with a const char* key. 284539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko typedef SafeMap<StringPiece, const OatDexFile*> Table; 285e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom Table oat_dex_files_; 286e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 287e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom friend class OatClass; 288e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom friend class OatDexFile; 289e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes friend class OatDumper; // For GetBase and GetLimit 290e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom DISALLOW_COPY_AND_ASSIGN(OatFile); 291e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom}; 292e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 293e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom} // namespace art 294e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 295fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif // ART_RUNTIME_OAT_FILE_H_ 296