oat_file.h revision 98d1cc8033251c93786e2fa8c59a2e555a9493be
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); 55700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 56700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Open an oat file backed by a std::vector with the given location. 57265091e581c9f643b37e7966890911f09e223269Brian Carlstrom static OatFile* OpenMemory(std::vector<uint8_t>& oat_contents, 588d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers const std::string& location, 598d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 605b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom 61e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom ~OatFile(); 62e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 6353cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light ElfFile* GetElfFile() const { 6453cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light CHECK_NE(reinterpret_cast<uintptr_t>(elf_file_.get()), reinterpret_cast<uintptr_t>(nullptr)) 6553cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light << "Cannot get an elf file from " << GetLocation(); 6653cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light return elf_file_.get(); 6753cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light } 6853cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light 69e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom const std::string& GetLocation() const { 70e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom return location_; 71e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom } 72e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 73e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom const OatHeader& GetOatHeader() const; 74e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 75e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom class OatDexFile; 76e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 773320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom class OatMethod { 783320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom public: 79b0fa5dc7769c1e054032f39de0a3f6d6dd06f8cfIan Rogers void LinkMethod(mirror::ArtMethod* method) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 80ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 81ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom uint32_t GetCodeOffset() const { 82ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom return code_offset_; 83ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom } 840c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers uint32_t GetNativeGcMapOffset() const { 850c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers return native_gc_map_offset_; 86e7d856b911222aa000ca2be0f8f63f5b292141c3Brian Carlstrom } 87ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 88ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const void* GetPortableCode() const { 89ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers // TODO: encode whether code is portable/quick in flags within OatMethod. 90ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers if (kUsePortableCompiler) { 91ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return GetOatPointer<const void*>(code_offset_); 92ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } else { 93ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return nullptr; 94ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 95ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 96ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers 97ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers const void* GetQuickCode() const { 98ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers if (kUsePortableCompiler) { 99ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return nullptr; 100ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } else { 101ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return GetOatPointer<const void*>(code_offset_); 102ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 103ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 104ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers 105ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers uint32_t GetPortableCodeSize() const { 106ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers // TODO: With Quick, we store the size before the code. With Portable, the code is in a .o 107ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers // file we don't manage ourselves. ELF symbols do have a concept of size, so we could capture 108ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers // that and store it somewhere, such as the OatMethod. 109ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers return 0; 110ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers } 111ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers uint32_t GetQuickCodeSize() const; 1120c717dd1c56bd29cf860d0feda8e629dab2cadb3Logan Chien 1130c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers const uint8_t* GetNativeGcMap() const { 1140c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers return GetOatPointer<const uint8_t*>(native_gc_map_offset_); 115e7d856b911222aa000ca2be0f8f63f5b292141c3Brian Carlstrom } 1160c717dd1c56bd29cf860d0feda8e629dab2cadb3Logan Chien 1177624d25dad2d1ba25969ae704fccf68649103ae5Vladimir Marko size_t GetFrameSizeInBytes() const; 1187624d25dad2d1ba25969ae704fccf68649103ae5Vladimir Marko uint32_t GetCoreSpillMask() const; 1197624d25dad2d1ba25969ae704fccf68649103ae5Vladimir Marko uint32_t GetFpSpillMask() const; 1208a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko uint32_t GetMappingTableOffset() const; 1218a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko uint32_t GetVmapTableOffset() const; 1228a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko const uint8_t* GetMappingTable() const; 1238a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko const uint8_t* GetVmapTable() const; 1248a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko 125ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom ~OatMethod(); 126ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 127ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom // Create an OatMethod with offsets relative to the given base address 128ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom OatMethod(const byte* base, 129ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom const uint32_t code_offset, 1306a47b9dc850b903aabefcfab4adb132cb68bba2eBrian Carlstrom const uint32_t gc_map_offset); 1313320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 132ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom private: 133ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom template<class T> 134ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom T GetOatPointer(uint32_t offset) const { 135ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom if (offset == 0) { 136ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom return NULL; 137ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom } 13830fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers return reinterpret_cast<T>(begin_ + offset); 139ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom } 1403320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 14130fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers const byte* begin_; 1423320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 143ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom uint32_t code_offset_; 1440c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers uint32_t native_gc_map_offset_; 145ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom 146ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom friend class OatClass; 1473320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom }; 1483320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 149e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom class OatClass { 150e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom public: 151ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom mirror::Class::Status GetStatus() const { 152ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom return status_; 153ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom } 154ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 155ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom OatClassType GetType() const { 156ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom return type_; 157ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom } 1580755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom 159eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier // Get the OatMethod entry based on its index into the class 160e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // defintion. direct methods come first, followed by virtual 161e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // methods. note that runtime created methods such as miranda 162e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // methods are not included. 163aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom const OatMethod GetOatMethod(uint32_t method_index) const; 164e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 165e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom private: 1660755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom OatClass(const OatFile* oat_file, 1672dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers mirror::Class::Status status, 168ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom OatClassType type, 169ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom uint32_t bitmap_size, 170ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom const uint32_t* bitmap_pointer, 1710755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom const OatMethodOffsets* methods_pointer); 1723320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 173d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko const OatFile* const oat_file_; 174ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 1752dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers const mirror::Class::Status status_; 176ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 177d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko const OatClassType type_; 178ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 179d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko const uint32_t* const bitmap_; 180ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 1813320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom const OatMethodOffsets* methods_pointer_; 182e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 183e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom friend class OatDexFile; 184e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom }; 185e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 186e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom class OatDexFile { 187e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom public: 18856d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Opens the DexFile referred to by this OatDexFile from within the containing OatFile. 1898d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers const DexFile* OpenDexFile(std::string* error_msg) const; 19056d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom 19156d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Returns the size of the DexFile refered to by this OatDexFile. 19205f28c6e00ecdb1da834acc8c29b4a7eba86d692Ian Rogers size_t FileSize() const; 193aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom 19456d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Returns original path of DexFile that was the source of this OatDexFile. 195aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom const std::string& GetDexFileLocation() const { 196aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom return dex_file_location_; 197aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom } 19858ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom 19956d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Returns checksum of original DexFile that was the source of this OatDexFile; 2005b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom uint32_t GetDexFileLocationChecksum() const { 2015b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom return dex_file_location_checksum_; 20258ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom } 20358ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom 20456d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom // Returns the OatClass for the class specified by the given DexFile class_def_index. 205d3c5bebcb52a67cb06e7ab303eaf45f230c08b60Vladimir Marko OatClass GetOatClass(uint16_t class_def_index) const; 20656d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom 207e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom ~OatDexFile(); 208a21039c3ae2b20e44ceb2735251c04d0aac89afdElliott Hughes 209e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom private: 210e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom OatDexFile(const OatFile* oat_file, 211aa6a588eb83288481389aa08b03105346a87e706Elliott Hughes const std::string& dex_file_location, 212e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom uint32_t dex_file_checksum, 213700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const byte* dex_file_pointer, 2140755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom const uint32_t* oat_class_offsets_pointer); 215e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 216539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko const OatFile* const oat_file_; 217539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko const std::string dex_file_location_; 218539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko const uint32_t dex_file_location_checksum_; 219539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko const byte* const dex_file_pointer_; 220539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko const uint32_t* const oat_class_offsets_pointer_; 221e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 222e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom friend class OatFile; 223e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom DISALLOW_COPY_AND_ASSIGN(OatDexFile); 224e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom }; 225e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 2268d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers const OatDexFile* GetOatDexFile(const char* dex_location, 227756ee4e090bc1e1812b41fb7b4661df601a32ef9Brian Carlstrom const uint32_t* const dex_location_checksum, 2288d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool exception_if_not_found = true) const; 2298d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers 230aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom std::vector<const OatDexFile*> GetOatDexFiles() const; 231e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 23230fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers size_t Size() const { 23330fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers return End() - Begin(); 234e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom } 235e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 23653cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light const byte* Begin() const; 23753cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light const byte* End() const; 23853cb16b98acf3cf6f3a1e2204ad4958ecf1b5a3cAlex Light 239e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom private: 240700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom static void CheckLocation(const std::string& location); 241700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 242700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom static OatFile* OpenDlopen(const std::string& elf_filename, 243700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const std::string& location, 2448d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers byte* requested_base, 2458d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 246700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 247700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom static OatFile* OpenElfFile(File* file, 248700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const std::string& location, 249700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom byte* requested_base, 250f1d3455064792ac1c486a4a9c24279a37b4af473Brian Carlstrom bool writable, 2518d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool executable, 2528d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 253700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 254a51a3dd5603daf3d368b7735067e1d9eb54c4c40Elliott Hughes explicit OatFile(const std::string& filename); 2558d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool Dlopen(const std::string& elf_filename, byte* requested_base, std::string* error_msg); 2568d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool ElfFileOpen(File* file, byte* requested_base, bool writable, bool executable, 2578d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers std::string* error_msg); 2588d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers bool Setup(std::string* error_msg); 259e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 260e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // The oat file name. 261e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // 262e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom // The image will embed this to link its associated oat file. 263e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom const std::string location_; 264e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 265700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Pointer to OatHeader. 266700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const byte* begin_; 267700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 268700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Pointer to end of oat region for bounds checking. 269700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom const byte* end_; 270700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 271700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Backing memory map for oat file during when opened by ElfWriter during initial compilation. 272700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers std::unique_ptr<MemMap> mem_map_; 273e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 274700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // Backing memory map for oat file during cross compilation. 275700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers std::unique_ptr<ElfFile> elf_file_; 276700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 277700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom // dlopen handle during runtime. 278700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom void* dlopen_handle_; 279700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom 280539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko // NOTE: We use a StringPiece as the key type to avoid a memory allocation on every lookup 281539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko // with a const char* key. 282539690a351d8c325707368729aafa2b4fa134d4cVladimir Marko typedef SafeMap<StringPiece, const OatDexFile*> Table; 283e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom Table oat_dex_files_; 284e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 285e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom friend class OatClass; 286e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom friend class OatDexFile; 287e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes friend class OatDumper; // For GetBase and GetLimit 288e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom DISALLOW_COPY_AND_ASSIGN(OatFile); 289e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom}; 290e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 291e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom} // namespace art 292e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 293fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif // ART_RUNTIME_OAT_FILE_H_ 294