oat.h revision 8a630577ed2d9e9571c3434c505e5de223b23c07
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_H_ 18fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#define ART_RUNTIME_OAT_H_ 19e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 20e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom#include <vector> 21e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 22761600567d73b23324ae0251e871c15d6849ffd8Elliott Hughes#include "base/macros.h" 23e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom#include "dex_file.h" 240f3c55331439970e01af67f80ac117c473bc04cfElliott Hughes#include "instruction_set.h" 25e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 26e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstromnamespace art { 27e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 28df1ce91ba97bc79a0637e5504b39318fb1c9f577Ian Rogersclass PACKED(4) OatHeader { 29e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom public: 307c3d13aebdd8611cae58a1048bffb13cbdc465cbBrian Carlstrom static const uint8_t kOatMagic[4]; 317c3d13aebdd8611cae58a1048bffb13cbdc465cbBrian Carlstrom static const uint8_t kOatVersion[4]; 327c3d13aebdd8611cae58a1048bffb13cbdc465cbBrian Carlstrom 33a72ec820f8cb8e04b0ba87a62e36b05a2c92ef36Elliott Hughes OatHeader(); 3481f3ca17e9e8d360cc4a1b6c3155cf01ba3be3bcBrian Carlstrom OatHeader(InstructionSet instruction_set, 357020278bce98a0735dc6abcbd33bdf1ed2634f1dDave Allison const InstructionSetFeatures& instruction_set_features, 3681f3ca17e9e8d360cc4a1b6c3155cf01ba3be3bcBrian Carlstrom const std::vector<const DexFile*>* dex_files, 3728db0129e5d7ef642cf8845c86c0e11832817085Brian Carlstrom uint32_t image_file_location_oat_checksum, 38700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom uint32_t image_file_location_oat_data_begin, 3981f3ca17e9e8d360cc4a1b6c3155cf01ba3be3bcBrian Carlstrom const std::string& image_file_location); 40e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 41e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom bool IsValid() const; 42e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom const char* GetMagic() const; 43e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom uint32_t GetChecksum() const; 44e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom void UpdateChecksum(const void* data, size_t length); 454f6ad8ab428038129b2d0d6c40b7fd625cca15e1Ian Rogers uint32_t GetDexFileCount() const { 464f6ad8ab428038129b2d0d6c40b7fd625cca15e1Ian Rogers DCHECK(IsValid()); 474f6ad8ab428038129b2d0d6c40b7fd625cca15e1Ian Rogers return dex_file_count_; 484f6ad8ab428038129b2d0d6c40b7fd625cca15e1Ian Rogers } 49e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom uint32_t GetExecutableOffset() const; 50e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom void SetExecutableOffset(uint32_t executable_offset); 51468532ea115657709bc32ee498e701a4c71762d4Ian Rogers 52468532ea115657709bc32ee498e701a4c71762d4Ian Rogers const void* GetInterpreterToInterpreterBridge() const; 53468532ea115657709bc32ee498e701a4c71762d4Ian Rogers uint32_t GetInterpreterToInterpreterBridgeOffset() const; 54468532ea115657709bc32ee498e701a4c71762d4Ian Rogers void SetInterpreterToInterpreterBridgeOffset(uint32_t offset); 55468532ea115657709bc32ee498e701a4c71762d4Ian Rogers const void* GetInterpreterToCompiledCodeBridge() const; 56468532ea115657709bc32ee498e701a4c71762d4Ian Rogers uint32_t GetInterpreterToCompiledCodeBridgeOffset() const; 57468532ea115657709bc32ee498e701a4c71762d4Ian Rogers void SetInterpreterToCompiledCodeBridgeOffset(uint32_t offset); 58468532ea115657709bc32ee498e701a4c71762d4Ian Rogers 59468532ea115657709bc32ee498e701a4c71762d4Ian Rogers const void* GetJniDlsymLookup() const; 60468532ea115657709bc32ee498e701a4c71762d4Ian Rogers uint32_t GetJniDlsymLookupOffset() const; 61468532ea115657709bc32ee498e701a4c71762d4Ian Rogers void SetJniDlsymLookupOffset(uint32_t offset); 62468532ea115657709bc32ee498e701a4c71762d4Ian Rogers 630aba0ba155bef7346bde19e53581200b89ae8a7aJeff Hao const void* GetPortableResolutionTrampoline() const; 640aba0ba155bef7346bde19e53581200b89ae8a7aJeff Hao uint32_t GetPortableResolutionTrampolineOffset() const; 650aba0ba155bef7346bde19e53581200b89ae8a7aJeff Hao void SetPortableResolutionTrampolineOffset(uint32_t offset); 6688474b416eb257078e590bf9bc7957cee604a186Jeff Hao const void* GetPortableImtConflictTrampoline() const; 6788474b416eb257078e590bf9bc7957cee604a186Jeff Hao uint32_t GetPortableImtConflictTrampolineOffset() const; 6888474b416eb257078e590bf9bc7957cee604a186Jeff Hao void SetPortableImtConflictTrampolineOffset(uint32_t offset); 69468532ea115657709bc32ee498e701a4c71762d4Ian Rogers const void* GetPortableToInterpreterBridge() const; 70468532ea115657709bc32ee498e701a4c71762d4Ian Rogers uint32_t GetPortableToInterpreterBridgeOffset() const; 71468532ea115657709bc32ee498e701a4c71762d4Ian Rogers void SetPortableToInterpreterBridgeOffset(uint32_t offset); 72468532ea115657709bc32ee498e701a4c71762d4Ian Rogers 732da882315a61072664f7ce3c212307342e907207Andreas Gampe const void* GetQuickGenericJniTrampoline() const; 742da882315a61072664f7ce3c212307342e907207Andreas Gampe uint32_t GetQuickGenericJniTrampolineOffset() const; 752da882315a61072664f7ce3c212307342e907207Andreas Gampe void SetQuickGenericJniTrampolineOffset(uint32_t offset); 760aba0ba155bef7346bde19e53581200b89ae8a7aJeff Hao const void* GetQuickResolutionTrampoline() const; 770aba0ba155bef7346bde19e53581200b89ae8a7aJeff Hao uint32_t GetQuickResolutionTrampolineOffset() const; 780aba0ba155bef7346bde19e53581200b89ae8a7aJeff Hao void SetQuickResolutionTrampolineOffset(uint32_t offset); 7988474b416eb257078e590bf9bc7957cee604a186Jeff Hao const void* GetQuickImtConflictTrampoline() const; 8088474b416eb257078e590bf9bc7957cee604a186Jeff Hao uint32_t GetQuickImtConflictTrampolineOffset() const; 8188474b416eb257078e590bf9bc7957cee604a186Jeff Hao void SetQuickImtConflictTrampolineOffset(uint32_t offset); 82468532ea115657709bc32ee498e701a4c71762d4Ian Rogers const void* GetQuickToInterpreterBridge() const; 83468532ea115657709bc32ee498e701a4c71762d4Ian Rogers uint32_t GetQuickToInterpreterBridgeOffset() const; 84468532ea115657709bc32ee498e701a4c71762d4Ian Rogers void SetQuickToInterpreterBridgeOffset(uint32_t offset); 85468532ea115657709bc32ee498e701a4c71762d4Ian Rogers 860aba0ba155bef7346bde19e53581200b89ae8a7aJeff Hao InstructionSet GetInstructionSet() const; 877020278bce98a0735dc6abcbd33bdf1ed2634f1dDave Allison const InstructionSetFeatures& GetInstructionSetFeatures() const; 8828db0129e5d7ef642cf8845c86c0e11832817085Brian Carlstrom uint32_t GetImageFileLocationOatChecksum() const; 89700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom uint32_t GetImageFileLocationOatDataBegin() const; 9081f3ca17e9e8d360cc4a1b6c3155cf01ba3be3bcBrian Carlstrom uint32_t GetImageFileLocationSize() const; 9181f3ca17e9e8d360cc4a1b6c3155cf01ba3be3bcBrian Carlstrom const uint8_t* GetImageFileLocationData() const; 9281f3ca17e9e8d360cc4a1b6c3155cf01ba3be3bcBrian Carlstrom std::string GetImageFileLocation() const; 93e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 94e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom private: 95e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom uint8_t magic_[4]; 96e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom uint8_t version_[4]; 97e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom uint32_t adler32_checksum_; 98a72ec820f8cb8e04b0ba87a62e36b05a2c92ef36Elliott Hughes 99a72ec820f8cb8e04b0ba87a62e36b05a2c92ef36Elliott Hughes InstructionSet instruction_set_; 1007020278bce98a0735dc6abcbd33bdf1ed2634f1dDave Allison InstructionSetFeatures instruction_set_features_; 101e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom uint32_t dex_file_count_; 102e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom uint32_t executable_offset_; 103468532ea115657709bc32ee498e701a4c71762d4Ian Rogers uint32_t interpreter_to_interpreter_bridge_offset_; 104468532ea115657709bc32ee498e701a4c71762d4Ian Rogers uint32_t interpreter_to_compiled_code_bridge_offset_; 105468532ea115657709bc32ee498e701a4c71762d4Ian Rogers uint32_t jni_dlsym_lookup_offset_; 10688474b416eb257078e590bf9bc7957cee604a186Jeff Hao uint32_t portable_imt_conflict_trampoline_offset_; 1070aba0ba155bef7346bde19e53581200b89ae8a7aJeff Hao uint32_t portable_resolution_trampoline_offset_; 108468532ea115657709bc32ee498e701a4c71762d4Ian Rogers uint32_t portable_to_interpreter_bridge_offset_; 1092da882315a61072664f7ce3c212307342e907207Andreas Gampe uint32_t quick_generic_jni_trampoline_offset_; 11088474b416eb257078e590bf9bc7957cee604a186Jeff Hao uint32_t quick_imt_conflict_trampoline_offset_; 1110aba0ba155bef7346bde19e53581200b89ae8a7aJeff Hao uint32_t quick_resolution_trampoline_offset_; 112468532ea115657709bc32ee498e701a4c71762d4Ian Rogers uint32_t quick_to_interpreter_bridge_offset_; 113e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 11428db0129e5d7ef642cf8845c86c0e11832817085Brian Carlstrom uint32_t image_file_location_oat_checksum_; 115700c8d31733534a3d978b75a03f6f7e177dc7e81Brian Carlstrom uint32_t image_file_location_oat_data_begin_; 11681f3ca17e9e8d360cc4a1b6c3155cf01ba3be3bcBrian Carlstrom uint32_t image_file_location_size_; 11781f3ca17e9e8d360cc4a1b6c3155cf01ba3be3bcBrian Carlstrom uint8_t image_file_location_data_[0]; // note variable width data at end 11881f3ca17e9e8d360cc4a1b6c3155cf01ba3be3bcBrian Carlstrom 119e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom DISALLOW_COPY_AND_ASSIGN(OatHeader); 120e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom}; 121e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 1228a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko// OatMethodOffsets are currently 5x32-bits=160-bits long, so if we can 123ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom// save even one OatMethodOffsets struct, the more complicated encoding 1248a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko// using a bitmap pays for itself since few classes will have 160 125ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom// methods. 126ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstromenum OatClassType { 127ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom kOatClassAllCompiled = 0, // OatClass is followed by an OatMethodOffsets for each method. 128ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom kOatClassSomeCompiled = 1, // A bitmap of which OatMethodOffsets are present follows the OatClass. 129ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom kOatClassNoneCompiled = 2, // All methods are interpretted so no OatMethodOffsets are necessary. 130ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom kOatClassMax = 3, 131ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom}; 132ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 133ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstromstd::ostream& operator<<(std::ostream& os, const OatClassType& rhs); 134ba150c37d582eeeb8c11ba5245edc281cf31793cBrian Carlstrom 135df1ce91ba97bc79a0637e5504b39318fb1c9f577Ian Rogersclass PACKED(4) OatMethodOffsets { 1363320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom public: 1373320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom OatMethodOffsets(); 138971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien 1393320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom OatMethodOffsets(uint32_t code_offset, 1403320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom uint32_t frame_size_in_bytes, 1413320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom uint32_t core_spill_mask, 1423320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom uint32_t fp_spill_mask, 143df62950e7a32031b82360c407d46a37b94188fbbBrian Carlstrom uint32_t gc_map_offset); 144971bf3f9184010d68b9a3ad30b396fa401af91a3Logan Chien 1453320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom ~OatMethodOffsets(); 1463320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 1473320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom uint32_t code_offset_; 1483320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom uint32_t frame_size_in_bytes_; 1493320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom uint32_t core_spill_mask_; 1503320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom uint32_t fp_spill_mask_; 151e7d856b911222aa000ca2be0f8f63f5b292141c3Brian Carlstrom uint32_t gc_map_offset_; 1523320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom}; 1533320cf46afd082398aa401b246e6f301cebdf64dBrian Carlstrom 15496c6ab93336b972a38bd2448bcccf19188b8389bVladimir Marko// OatMethodHeader precedes the raw code chunk generated by the Quick compiler. 15596c6ab93336b972a38bd2448bcccf19188b8389bVladimir Markoclass PACKED(4) OatMethodHeader { 15696c6ab93336b972a38bd2448bcccf19188b8389bVladimir Marko public: 15796c6ab93336b972a38bd2448bcccf19188b8389bVladimir Marko OatMethodHeader(); 15896c6ab93336b972a38bd2448bcccf19188b8389bVladimir Marko 1598a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko explicit OatMethodHeader(uint32_t mapping_table_offset, uint32_t vmap_table_offset, 1608a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko uint32_t code_size); 16196c6ab93336b972a38bd2448bcccf19188b8389bVladimir Marko 16296c6ab93336b972a38bd2448bcccf19188b8389bVladimir Marko ~OatMethodHeader(); 16396c6ab93336b972a38bd2448bcccf19188b8389bVladimir Marko 1648a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko // The offset in bytes from the start of the mapping table to the end of the header. 1658a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko uint32_t mapping_table_offset_; 1668a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko // The offset in bytes from the start of the vmap table to the end of the header. 1678a630577ed2d9e9571c3434c505e5de223b23c07Vladimir Marko uint32_t vmap_table_offset_; 16896c6ab93336b972a38bd2448bcccf19188b8389bVladimir Marko // The code size in bytes. 16996c6ab93336b972a38bd2448bcccf19188b8389bVladimir Marko uint32_t code_size_; 17096c6ab93336b972a38bd2448bcccf19188b8389bVladimir Marko}; 17196c6ab93336b972a38bd2448bcccf19188b8389bVladimir Marko 172e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom} // namespace art 173e24fa61603a60ade3797e4a0c8b3fccb346cb048Brian Carlstrom 174fc0e3219edc9a5bf81b166e82fd5db2796eb6a0dBrian Carlstrom#endif // ART_RUNTIME_OAT_H_ 175