1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ART_RUNTIME_OAT_H_ 18 #define ART_RUNTIME_OAT_H_ 19 20 #include <array> 21 #include <vector> 22 23 #include "base/compiler_filter.h" 24 #include "base/macros.h" 25 #include "base/safe_map.h" 26 27 namespace art { 28 29 enum class InstructionSet; 30 class InstructionSetFeatures; 31 32 enum class StubType { 33 kJNIDlsymLookupTrampoline, 34 kJNIDlsymLookupCriticalTrampoline, 35 kQuickGenericJNITrampoline, 36 kQuickIMTConflictTrampoline, 37 kQuickResolutionTrampoline, 38 kQuickToInterpreterBridge, 39 kNterpTrampoline, 40 kLast = kNterpTrampoline, 41 }; 42 std::ostream& operator<<(std::ostream& stream, StubType stub_type); 43 44 class PACKED(4) OatHeader { 45 public: 46 static constexpr std::array<uint8_t, 4> kOatMagic { { 'o', 'a', 't', '\n' } }; 47 // Last oat version changed reason: ARM64: Enable implicit suspend checks; compiled code check. 48 static constexpr std::array<uint8_t, 4> kOatVersion { { '2', '3', '0', '\0' } }; 49 50 static constexpr const char* kDex2OatCmdLineKey = "dex2oat-cmdline"; 51 static constexpr const char* kDebuggableKey = "debuggable"; 52 static constexpr const char* kNativeDebuggableKey = "native-debuggable"; 53 static constexpr const char* kCompilerFilter = "compiler-filter"; 54 static constexpr const char* kClassPathKey = "classpath"; 55 static constexpr const char* kBootClassPathKey = "bootclasspath"; 56 static constexpr const char* kBootClassPathChecksumsKey = "bootclasspath-checksums"; 57 static constexpr const char* kApexVersionsKey = "apex-versions"; 58 static constexpr const char* kConcurrentCopying = "concurrent-copying"; 59 static constexpr const char* kCompilationReasonKey = "compilation-reason"; 60 static constexpr const char* kRequiresImage = "requires-image"; 61 62 static constexpr const char kTrueValue[] = "true"; 63 static constexpr const char kFalseValue[] = "false"; 64 65 66 static OatHeader* Create(InstructionSet instruction_set, 67 const InstructionSetFeatures* instruction_set_features, 68 uint32_t dex_file_count, 69 const SafeMap<std::string, std::string>* variable_data); 70 71 bool IsValid() const; 72 std::string GetValidationErrorMessage() const; 73 static void CheckOatVersion(std::array<uint8_t, 4> version); 74 const char* GetMagic() const; 75 uint32_t GetChecksum() const; 76 void SetChecksum(uint32_t checksum); GetDexFileCount()77 uint32_t GetDexFileCount() const { 78 DCHECK(IsValid()); 79 return dex_file_count_; 80 } 81 uint32_t GetOatDexFilesOffset() const; 82 void SetOatDexFilesOffset(uint32_t oat_dex_files_offset); 83 uint32_t GetBcpBssInfoOffset() const; 84 void SetBcpBssInfoOffset(uint32_t bcp_info_offset); 85 uint32_t GetExecutableOffset() const; 86 void SetExecutableOffset(uint32_t executable_offset); 87 88 const void* GetJniDlsymLookupTrampoline() const; 89 uint32_t GetJniDlsymLookupTrampolineOffset() const; 90 void SetJniDlsymLookupTrampolineOffset(uint32_t offset); 91 const void* GetJniDlsymLookupCriticalTrampoline() const; 92 uint32_t GetJniDlsymLookupCriticalTrampolineOffset() const; 93 void SetJniDlsymLookupCriticalTrampolineOffset(uint32_t offset); 94 95 const void* GetQuickGenericJniTrampoline() const; 96 uint32_t GetQuickGenericJniTrampolineOffset() const; 97 void SetQuickGenericJniTrampolineOffset(uint32_t offset); 98 const void* GetQuickResolutionTrampoline() const; 99 uint32_t GetQuickResolutionTrampolineOffset() const; 100 void SetQuickResolutionTrampolineOffset(uint32_t offset); 101 const void* GetQuickImtConflictTrampoline() const; 102 uint32_t GetQuickImtConflictTrampolineOffset() const; 103 void SetQuickImtConflictTrampolineOffset(uint32_t offset); 104 const void* GetQuickToInterpreterBridge() const; 105 uint32_t GetQuickToInterpreterBridgeOffset() const; 106 void SetQuickToInterpreterBridgeOffset(uint32_t offset); 107 const void* GetNterpTrampoline() const; 108 uint32_t GetNterpTrampolineOffset() const; 109 void SetNterpTrampolineOffset(uint32_t offset); 110 111 InstructionSet GetInstructionSet() const; 112 uint32_t GetInstructionSetFeaturesBitmap() const; 113 114 uint32_t GetKeyValueStoreSize() const; 115 const uint8_t* GetKeyValueStore() const; 116 const char* GetStoreValueByKey(const char* key) const; 117 bool GetStoreKeyValuePairByIndex(size_t index, const char** key, const char** value) const; 118 119 size_t GetHeaderSize() const; 120 bool IsDebuggable() const; 121 bool IsNativeDebuggable() const; 122 CompilerFilter::Filter GetCompilerFilter() const; 123 bool IsConcurrentCopying() const; 124 bool RequiresImage() const; 125 126 const uint8_t* GetOatAddress(StubType type) const; 127 128 private: 129 bool KeyHasValue(const char* key, const char* value, size_t value_size) const; 130 131 OatHeader(InstructionSet instruction_set, 132 const InstructionSetFeatures* instruction_set_features, 133 uint32_t dex_file_count, 134 const SafeMap<std::string, std::string>* variable_data); 135 136 // Returns true if the value of the given key is "true", false otherwise. 137 bool IsKeyEnabled(const char* key) const; 138 139 void Flatten(const SafeMap<std::string, std::string>* variable_data); 140 141 std::array<uint8_t, 4> magic_; 142 std::array<uint8_t, 4> version_; 143 uint32_t oat_checksum_; 144 145 InstructionSet instruction_set_; 146 uint32_t instruction_set_features_bitmap_; 147 uint32_t dex_file_count_; 148 uint32_t oat_dex_files_offset_; 149 uint32_t bcp_bss_info_offset_; 150 uint32_t executable_offset_; 151 uint32_t jni_dlsym_lookup_trampoline_offset_; 152 uint32_t jni_dlsym_lookup_critical_trampoline_offset_; 153 uint32_t quick_generic_jni_trampoline_offset_; 154 uint32_t quick_imt_conflict_trampoline_offset_; 155 uint32_t quick_resolution_trampoline_offset_; 156 uint32_t quick_to_interpreter_bridge_offset_; 157 uint32_t nterp_trampoline_offset_; 158 159 uint32_t key_value_store_size_; 160 uint8_t key_value_store_[0]; // note variable width data at end 161 162 DISALLOW_COPY_AND_ASSIGN(OatHeader); 163 }; 164 165 } // namespace art 166 167 #endif // ART_RUNTIME_OAT_H_ 168