oat_file.h revision ba150c37d582eeeb8c11ba5245edc281cf31793c
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:
76ea46f950e7a51585db293cd7f047de190a482414Brian Carlstrom    void LinkMethod(mirror::ArtMethod* method) const;
77ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom
78ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    uint32_t GetCodeOffset() const {
79ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom      return code_offset_;
80ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    }
81ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    size_t GetFrameSizeInBytes() const {
82ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom      return frame_size_in_bytes_;
83ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    }
84ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    uint32_t GetCoreSpillMask() const {
85ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom      return core_spill_mask_;
86ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    }
87ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    uint32_t GetFpSpillMask() const {
88ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom      return fp_spill_mask_;
89ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    }
90ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    uint32_t GetMappingTableOffset() const {
91ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom      return mapping_table_offset_;
92ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    }
93ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    uint32_t GetVmapTableOffset() const {
94ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom      return vmap_table_offset_;
95ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    }
960c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers    uint32_t GetNativeGcMapOffset() const {
970c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers      return native_gc_map_offset_;
98e7d856b911222aa000ca2be0f8f63f5b292141c3Brian Carlstrom    }
99ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom
1000c717dd1c56bd29cf860d0feda8e629dab2cadb3Logan Chien    const void* GetCode() const;
1010c717dd1c56bd29cf860d0feda8e629dab2cadb3Logan Chien    uint32_t GetCodeSize() const;
1020c717dd1c56bd29cf860d0feda8e629dab2cadb3Logan Chien
1031809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers    const uint8_t* GetMappingTable() const {
1041809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers      return GetOatPointer<const uint8_t*>(mapping_table_offset_);
105ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    }
1061809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers    const uint8_t* GetVmapTable() const {
1071809a72a66d245ae598582d658b93a24ac3bf01eIan Rogers      return GetOatPointer<const uint8_t*>(vmap_table_offset_);
108ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    }
1090c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers    const uint8_t* GetNativeGcMap() const {
1100c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers      return GetOatPointer<const uint8_t*>(native_gc_map_offset_);
111e7d856b911222aa000ca2be0f8f63f5b292141c3Brian Carlstrom    }
1120c717dd1c56bd29cf860d0feda8e629dab2cadb3Logan Chien
113ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    ~OatMethod();
114ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom
115ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    // Create an OatMethod with offsets relative to the given base address
116ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    OatMethod(const byte* base,
117ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom              const uint32_t code_offset,
1183320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom              const size_t frame_size_in_bytes,
1193320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom              const uint32_t core_spill_mask,
1203320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom              const uint32_t fp_spill_mask,
121ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom              const uint32_t mapping_table_offset,
122ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom              const uint32_t vmap_table_offset,
1236a47b9dc850b903aabefcfab4adb132cb68bba2eBrian Carlstrom              const uint32_t gc_map_offset);
1243320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom
125ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom   private:
126ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    template<class T>
127ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    T GetOatPointer(uint32_t offset) const {
128ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom      if (offset == 0) {
129ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom        return NULL;
130ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom      }
13130fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers      return reinterpret_cast<T>(begin_ + offset);
132ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    }
1333320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom
13430fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers    const byte* begin_;
1353320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom
136ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    uint32_t code_offset_;
1373320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom    size_t frame_size_in_bytes_;
1383320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom    uint32_t core_spill_mask_;
1393320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom    uint32_t fp_spill_mask_;
140ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    uint32_t mapping_table_offset_;
141ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    uint32_t vmap_table_offset_;
1420c7abda482f53db3d153c073d1c7a145f84e0626Ian Rogers    uint32_t native_gc_map_offset_;
143ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom
144ae826983f7903bc0a6bbbe8426bf393fb2f6d747Brian Carlstrom    friend class OatClass;
1453320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom  };
1463320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom
147e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  class OatClass {
148e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom   public:
149ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom    mirror::Class::Status GetStatus() const {
150ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom      return status_;
151ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom    }
152ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom
153ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom    OatClassType GetType() const {
154ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom      return type_;
155ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom    }
1560755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom
1573320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom    // get the OatMethod entry based on its index into the class
158e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom    // defintion. direct methods come first, followed by virtual
159e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom    // methods. note that runtime created methods such as miranda
160e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom    // methods are not included.
161aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom    const OatMethod GetOatMethod(uint32_t method_index) const;
162e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom    ~OatClass();
163e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
164e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom   private:
1650755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom    OatClass(const OatFile* oat_file,
1662dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers             mirror::Class::Status status,
167ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom             OatClassType type,
168ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom             uint32_t bitmap_size,
169ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom             const uint32_t* bitmap_pointer,
1700755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom             const OatMethodOffsets* methods_pointer);
1713320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom
172e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom    const OatFile* oat_file_;
173ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom
1742dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers    const mirror::Class::Status status_;
175ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom    COMPILE_ASSERT(mirror::Class::Status::kStatusMax < (2 ^ 16), class_status_wont_fit_in_16bits);
176ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom
177ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom    OatClassType type_;
178ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom    COMPILE_ASSERT(OatClassType::kOatClassMax < (2 ^ 16), oat_class_type_wont_fit_in_16bits);
179ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom
180ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom    const BitVector* bitmap_;
181ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom
1823320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom    const OatMethodOffsets* methods_pointer_;
183e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
184e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom    friend class OatDexFile;
185e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  };
186e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
187e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  class OatDexFile {
188e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom   public:
18956d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom    // Opens the DexFile referred to by this OatDexFile from within the containing OatFile.
1908d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers    const DexFile* OpenDexFile(std::string* error_msg) const;
19156d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom
19256d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom    // Returns the size of the DexFile refered to by this OatDexFile.
19305f28c6e00ecdb1da834acc8c29b4a7eba86d692Ian Rogers    size_t FileSize() const;
194aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom
19556d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom    // Returns original path of DexFile that was the source of this OatDexFile.
196aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom    const std::string& GetDexFileLocation() const {
197aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom      return dex_file_location_;
198aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom    }
19958ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom
20056d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom    // Returns checksum of original DexFile that was the source of this OatDexFile;
2015b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom    uint32_t GetDexFileLocationChecksum() const {
2025b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom      return dex_file_location_checksum_;
20358ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom    }
20458ae9416e197ae68ed12ed43d87407d4dfb15093Brian Carlstrom
20556d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom    // Returns the OatClass for the class specified by the given DexFile class_def_index.
206ee39a10e45a6a0880e8b829525c40d6055818560Ian Rogers    const OatClass* GetOatClass(uint16_t class_def_index) const;
20756d947fbc9bc2992e2f93112fafb73e50d2aaa7aBrian Carlstrom
208e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom    ~OatDexFile();
209a21039c3ae2b20e44ceb2735251c04d0aac89afdElliott Hughes
210e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom   private:
211e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom    OatDexFile(const OatFile* oat_file,
212aa6a588eb83288481389aa08b03105346a87e706Elliott Hughes               const std::string& dex_file_location,
213e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom               uint32_t dex_file_checksum,
214700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom               const byte* dex_file_pointer,
2150755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom               const uint32_t* oat_class_offsets_pointer);
216e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
217e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom    const OatFile* oat_file_;
218e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom    std::string dex_file_location_;
2195b332c89fa3fdd7dc184b22c2587d28af304d019Brian Carlstrom    uint32_t dex_file_location_checksum_;
22089521898b56f2ebc3fb68acfb6bc6dde9b6f5c38Brian Carlstrom    const byte* dex_file_pointer_;
2210755ec5ea1dce0b549fc1adefeb52d89f119ebecBrian Carlstrom    const uint32_t* oat_class_offsets_pointer_;
222e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
223e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom    friend class OatFile;
224e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom    DISALLOW_COPY_AND_ASSIGN(OatDexFile);
225e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  };
226e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
2278d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  const OatDexFile* GetOatDexFile(const char* dex_location,
228756ee4e090bc1e1812b41fb7b4661df601a32ef9Brian Carlstrom                                  const uint32_t* const dex_location_checksum,
2298d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers                                  bool exception_if_not_found = true) const;
2308d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers
231aded5f7ab991f3c1132851599d3bc60ff6707eedBrian Carlstrom  std::vector<const OatDexFile*> GetOatDexFiles() const;
232e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
23330fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers  size_t Size() const {
23430fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers    return End() - Begin();
235e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  }
236e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
237e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom private:
238700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  static void CheckLocation(const std::string& location);
239700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom
240700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  static OatFile* OpenDlopen(const std::string& elf_filename,
241700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom                             const std::string& location,
2428d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers                             byte* requested_base,
2438d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers                             std::string* error_msg);
244700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom
245700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  static OatFile* OpenElfFile(File* file,
246700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom                              const std::string& location,
247700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom                              byte* requested_base,
248f1d3455064792ac1c486a4a9c24279a37b4af473Brian Carlstrom                              bool writable,
2498d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers                              bool executable,
2508d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers                              std::string* error_msg);
251700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom
252a51a3dd5603daf3d368b7735067e1d9eb54c4c40Elliott Hughes  explicit OatFile(const std::string& filename);
2538d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  bool Dlopen(const std::string& elf_filename, byte* requested_base, std::string* error_msg);
2548d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  bool ElfFileOpen(File* file, byte* requested_base, bool writable, bool executable,
2558d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers                   std::string* error_msg);
2568d31bbd3d6536de12bc20e3d29cfe03fe848f9daIan Rogers  bool Setup(std::string* error_msg);
257e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
25830fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers  const byte* Begin() const;
25930fab40ee5a07af6b8c3b6b0e9438071695a57f4Ian Rogers  const byte* End() const;
260e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
261e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  // The oat file name.
262e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  //
263e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  // The image will embed this to link its associated oat file.
264e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  const std::string location_;
265e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
266700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  // Pointer to OatHeader.
267700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  const byte* begin_;
268700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom
269700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  // Pointer to end of oat region for bounds checking.
270700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  const byte* end_;
271700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom
272700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  // Backing memory map for oat file during when opened by ElfWriter during initial compilation.
273e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  UniquePtr<MemMap> mem_map_;
274e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
275700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  // Backing memory map for oat file during cross compilation.
276700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  UniquePtr<ElfFile> elf_file_;
277700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom
278700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  // dlopen handle during runtime.
279700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom  void* dlopen_handle_;
280700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom
281a0e180632411f7fe0edf454e571c42209ee7b540Elliott Hughes  typedef SafeMap<std::string, const OatDexFile*> Table;
282e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  Table oat_dex_files_;
283e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
284e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  friend class OatClass;
285e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  friend class OatDexFile;
286e3c845cdb5884e770287a5c0c65c8bb64733c388Elliott Hughes  friend class OatDumper;  // For GetBase and GetLimit
287e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom  DISALLOW_COPY_AND_ASSIGN(OatFile);
288e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom};
289e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
290e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom}  // namespace art
291e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom
292fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif  // ART_RUNTIME_OAT_FILE_H_
293