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/macros.h" 24 #include "base/safe_map.h" 25 #include "compiler_filter.h" 26 27 namespace art { 28 29 enum class InstructionSet; 30 class InstructionSetFeatures; 31 32 class PACKED(4) OatHeader { 33 public: 34 static constexpr std::array<uint8_t, 4> kOatMagic { { 'o', 'a', 't', '\n' } }; 35 // Last oat version changed reason: Removal of Thread->tls32_.debug_suspend_count 36 static constexpr std::array<uint8_t, 4> kOatVersion { { '1', '8', '5', '\0' } }; 37 38 static constexpr const char* kDex2OatCmdLineKey = "dex2oat-cmdline"; 39 static constexpr const char* kDebuggableKey = "debuggable"; 40 static constexpr const char* kNativeDebuggableKey = "native-debuggable"; 41 static constexpr const char* kCompilerFilter = "compiler-filter"; 42 static constexpr const char* kClassPathKey = "classpath"; 43 static constexpr const char* kBootClassPathKey = "bootclasspath"; 44 static constexpr const char* kBootClassPathChecksumsKey = "bootclasspath-checksums"; 45 static constexpr const char* kConcurrentCopying = "concurrent-copying"; 46 static constexpr const char* kCompilationReasonKey = "compilation-reason"; 47 static constexpr const char* kRequiresImage = "requires-image"; 48 49 static constexpr const char kTrueValue[] = "true"; 50 static constexpr const char kFalseValue[] = "false"; 51 52 53 static OatHeader* Create(InstructionSet instruction_set, 54 const InstructionSetFeatures* instruction_set_features, 55 uint32_t dex_file_count, 56 const SafeMap<std::string, std::string>* variable_data); 57 58 bool IsValid() const; 59 std::string GetValidationErrorMessage() const; 60 static void CheckOatVersion(std::array<uint8_t, 4> version); 61 const char* GetMagic() const; 62 uint32_t GetChecksum() const; 63 void SetChecksum(uint32_t checksum); GetDexFileCount()64 uint32_t GetDexFileCount() const { 65 DCHECK(IsValid()); 66 return dex_file_count_; 67 } 68 uint32_t GetOatDexFilesOffset() const; 69 void SetOatDexFilesOffset(uint32_t oat_dex_files_offset); 70 uint32_t GetExecutableOffset() const; 71 void SetExecutableOffset(uint32_t executable_offset); 72 73 const void* GetJniDlsymLookupTrampoline() const; 74 uint32_t GetJniDlsymLookupTrampolineOffset() const; 75 void SetJniDlsymLookupTrampolineOffset(uint32_t offset); 76 const void* GetJniDlsymLookupCriticalTrampoline() const; 77 uint32_t GetJniDlsymLookupCriticalTrampolineOffset() const; 78 void SetJniDlsymLookupCriticalTrampolineOffset(uint32_t offset); 79 80 const void* GetQuickGenericJniTrampoline() const; 81 uint32_t GetQuickGenericJniTrampolineOffset() const; 82 void SetQuickGenericJniTrampolineOffset(uint32_t offset); 83 const void* GetQuickResolutionTrampoline() const; 84 uint32_t GetQuickResolutionTrampolineOffset() const; 85 void SetQuickResolutionTrampolineOffset(uint32_t offset); 86 const void* GetQuickImtConflictTrampoline() const; 87 uint32_t GetQuickImtConflictTrampolineOffset() const; 88 void SetQuickImtConflictTrampolineOffset(uint32_t offset); 89 const void* GetQuickToInterpreterBridge() const; 90 uint32_t GetQuickToInterpreterBridgeOffset() const; 91 void SetQuickToInterpreterBridgeOffset(uint32_t offset); 92 93 InstructionSet GetInstructionSet() const; 94 uint32_t GetInstructionSetFeaturesBitmap() const; 95 96 uint32_t GetKeyValueStoreSize() const; 97 const uint8_t* GetKeyValueStore() const; 98 const char* GetStoreValueByKey(const char* key) const; 99 bool GetStoreKeyValuePairByIndex(size_t index, const char** key, const char** value) const; 100 101 size_t GetHeaderSize() const; 102 bool IsDebuggable() const; 103 bool IsNativeDebuggable() const; 104 CompilerFilter::Filter GetCompilerFilter() const; 105 bool IsConcurrentCopying() const; 106 bool RequiresImage() const; 107 108 private: 109 bool KeyHasValue(const char* key, const char* value, size_t value_size) const; 110 111 OatHeader(InstructionSet instruction_set, 112 const InstructionSetFeatures* instruction_set_features, 113 uint32_t dex_file_count, 114 const SafeMap<std::string, std::string>* variable_data); 115 116 // Returns true if the value of the given key is "true", false otherwise. 117 bool IsKeyEnabled(const char* key) const; 118 119 void Flatten(const SafeMap<std::string, std::string>* variable_data); 120 121 std::array<uint8_t, 4> magic_; 122 std::array<uint8_t, 4> version_; 123 uint32_t oat_checksum_; 124 125 InstructionSet instruction_set_; 126 uint32_t instruction_set_features_bitmap_; 127 uint32_t dex_file_count_; 128 uint32_t oat_dex_files_offset_; 129 uint32_t executable_offset_; 130 uint32_t jni_dlsym_lookup_trampoline_offset_; 131 uint32_t jni_dlsym_lookup_critical_trampoline_offset_; 132 uint32_t quick_generic_jni_trampoline_offset_; 133 uint32_t quick_imt_conflict_trampoline_offset_; 134 uint32_t quick_resolution_trampoline_offset_; 135 uint32_t quick_to_interpreter_bridge_offset_; 136 137 uint32_t key_value_store_size_; 138 uint8_t key_value_store_[0]; // note variable width data at end 139 140 DISALLOW_COPY_AND_ASSIGN(OatHeader); 141 }; 142 143 } // namespace art 144 145 #endif // ART_RUNTIME_OAT_H_ 146