2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ART_RUNTIME_OAT_H_
18 #define ART_RUNTIME_OAT_H_
22 #include "arch/instruction_set.h"
23 #include "base/macros.h"
24 #include "compiler_filter.h"
30 class InstructionSetFeatures;
32 class PACKED(4) OatHeader {
34 static constexpr uint8_t kOatMagic[] = { 'o', 'a', 't', '\n' };
35 static constexpr uint8_t kOatVersion[] = { '1', '1', '8', '\0' }; // ARM64 Read barriers thunks.
37 static constexpr const char* kImageLocationKey = "image-location";
38 static constexpr const char* kDex2OatCmdLineKey = "dex2oat-cmdline";
39 static constexpr const char* kDex2OatHostKey = "dex2oat-host";
40 static constexpr const char* kPicKey = "pic";
41 static constexpr const char* kDebuggableKey = "debuggable";
42 static constexpr const char* kNativeDebuggableKey = "native-debuggable";
43 static constexpr const char* kCompilerFilter = "compiler-filter";
44 static constexpr const char* kClassPathKey = "classpath";
45 static constexpr const char* kBootClassPathKey = "bootclasspath";
46 static constexpr const char* kConcurrentCopying = "concurrent-copying";
48 static constexpr const char kTrueValue[] = "true";
49 static constexpr const char kFalseValue[] = "false";
52 static OatHeader* Create(InstructionSet instruction_set,
53 const InstructionSetFeatures* instruction_set_features,
54 uint32_t dex_file_count,
55 const SafeMap<std::string, std::string>* variable_data);
58 std::string GetValidationErrorMessage() const;
59 const char* GetMagic() const;
60 uint32_t GetChecksum() const;
61 void UpdateChecksumWithHeaderData();
62 void UpdateChecksum(const void* data, size_t length);
63 uint32_t GetDexFileCount() const {
65 return dex_file_count_;
67 uint32_t GetExecutableOffset() const;
68 void SetExecutableOffset(uint32_t executable_offset);
70 const void* GetInterpreterToInterpreterBridge() const;
71 uint32_t GetInterpreterToInterpreterBridgeOffset() const;
72 void SetInterpreterToInterpreterBridgeOffset(uint32_t offset);
73 const void* GetInterpreterToCompiledCodeBridge() const;
74 uint32_t GetInterpreterToCompiledCodeBridgeOffset() const;
75 void SetInterpreterToCompiledCodeBridgeOffset(uint32_t offset);
77 const void* GetJniDlsymLookup() const;
78 uint32_t GetJniDlsymLookupOffset() const;
79 void SetJniDlsymLookupOffset(uint32_t offset);
81 const void* GetQuickGenericJniTrampoline() const;
82 uint32_t GetQuickGenericJniTrampolineOffset() const;
83 void SetQuickGenericJniTrampolineOffset(uint32_t offset);
84 const void* GetQuickResolutionTrampoline() const;
85 uint32_t GetQuickResolutionTrampolineOffset() const;
86 void SetQuickResolutionTrampolineOffset(uint32_t offset);
87 const void* GetQuickImtConflictTrampoline() const;
88 uint32_t GetQuickImtConflictTrampolineOffset() const;
89 void SetQuickImtConflictTrampolineOffset(uint32_t offset);
90 const void* GetQuickToInterpreterBridge() const;
91 uint32_t GetQuickToInterpreterBridgeOffset() const;
92 void SetQuickToInterpreterBridgeOffset(uint32_t offset);
94 int32_t GetImagePatchDelta() const;
95 void RelocateOat(off_t delta);
96 void SetImagePatchDelta(int32_t off);
98 InstructionSet GetInstructionSet() const;
99 uint32_t GetInstructionSetFeaturesBitmap() const;
101 uint32_t GetImageFileLocationOatChecksum() const;
102 void SetImageFileLocationOatChecksum(uint32_t image_file_location_oat_checksum);
103 uint32_t GetImageFileLocationOatDataBegin() const;
104 void SetImageFileLocationOatDataBegin(uint32_t image_file_location_oat_data_begin);
106 uint32_t GetKeyValueStoreSize() const;
107 const uint8_t* GetKeyValueStore() const;
108 const char* GetStoreValueByKey(const char* key) const;
109 bool GetStoreKeyValuePairByIndex(size_t index, const char** key, const char** value) const;
111 size_t GetHeaderSize() const;
113 bool IsDebuggable() const;
114 bool IsNativeDebuggable() const;
115 CompilerFilter::Filter GetCompilerFilter() const;
116 bool IsConcurrentCopying() const;
119 bool KeyHasValue(const char* key, const char* value, size_t value_size) const;
121 OatHeader(InstructionSet instruction_set,
122 const InstructionSetFeatures* instruction_set_features,
123 uint32_t dex_file_count,
124 const SafeMap<std::string, std::string>* variable_data);
126 // Returns true if the value of the given key is "true", false otherwise.
127 bool IsKeyEnabled(const char* key) const;
129 void Flatten(const SafeMap<std::string, std::string>* variable_data);
133 uint32_t adler32_checksum_;
135 InstructionSet instruction_set_;
136 uint32_t instruction_set_features_bitmap_;
137 uint32_t dex_file_count_;
138 uint32_t executable_offset_;
139 uint32_t interpreter_to_interpreter_bridge_offset_;
140 uint32_t interpreter_to_compiled_code_bridge_offset_;
141 uint32_t jni_dlsym_lookup_offset_;
142 uint32_t quick_generic_jni_trampoline_offset_;
143 uint32_t quick_imt_conflict_trampoline_offset_;
144 uint32_t quick_resolution_trampoline_offset_;
145 uint32_t quick_to_interpreter_bridge_offset_;
147 // The amount that the image this oat is associated with has been patched.
148 int32_t image_patch_delta_;
150 uint32_t image_file_location_oat_checksum_;
151 uint32_t image_file_location_oat_data_begin_;
153 uint32_t key_value_store_size_;
154 uint8_t key_value_store_[0]; // note variable width data at end
156 DISALLOW_COPY_AND_ASSIGN(OatHeader);
159 // OatMethodOffsets are currently 5x32-bits=160-bits long, so if we can
160 // save even one OatMethodOffsets struct, the more complicated encoding
161 // using a bitmap pays for itself since few classes will have 160
164 kOatClassAllCompiled = 0, // OatClass is followed by an OatMethodOffsets for each method.
165 kOatClassSomeCompiled = 1, // A bitmap of which OatMethodOffsets are present follows the OatClass.
166 kOatClassNoneCompiled = 2, // All methods are interpreted so no OatMethodOffsets are necessary.
170 std::ostream& operator<<(std::ostream& os, const OatClassType& rhs);
172 class PACKED(4) OatMethodOffsets {
174 explicit OatMethodOffsets(uint32_t code_offset = 0);
178 OatMethodOffsets& operator=(const OatMethodOffsets&) = default;
180 uint32_t code_offset_;
185 #endif // ART_RUNTIME_OAT_H_