blob: 5ef6cbff788e1d040c6c853729943c33089db7d4 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 */
Brian Carlstrom3320cf42011-10-04 14:58:28 -070016
Mathieu Chartier193bad92013-08-29 18:46:00 -070017#ifndef ART_COMPILER_COMPILED_METHOD_H_
18#define ART_COMPILER_COMPILED_METHOD_H_
Brian Carlstrom3320cf42011-10-04 14:58:28 -070019
Vladimir Markocac5a7e2016-02-22 10:39:50 +000020#include <iosfwd>
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070021#include <memory>
Brian Carlstrom265091e2013-01-30 14:08:26 -080022#include <string>
Brian Carlstrom3320cf42011-10-04 14:58:28 -070023#include <vector>
24
Ian Rogersd582fa42014-11-05 23:46:43 -080025#include "arch/instruction_set.h"
David Brazdild9c90372016-09-14 16:53:55 +010026#include "base/array_ref.h"
Vladimir Marko80afd022015-05-19 18:08:00 +010027#include "base/bit_utils.h"
Alex Lighte64300b2015-12-15 15:02:47 -080028#include "base/length_prefixed_array.h"
Andreas Gampea5b09a62016-11-17 15:21:22 -080029#include "dex_file_types.h"
Vladimir Markof4da6752014-08-01 19:04:18 +010030#include "method_reference.h"
Brian Carlstrom3320cf42011-10-04 14:58:28 -070031
32namespace art {
33
Mathieu Chartier193bad92013-08-29 18:46:00 -070034class CompilerDriver;
Vladimir Marko35831e82015-09-11 11:59:18 +010035class CompiledMethodStorage;
Mathieu Chartier193bad92013-08-29 18:46:00 -070036
Logan Chien598c5132012-04-28 22:00:44 +080037class CompiledCode {
38 public:
Brian Carlstrom265091e2013-01-30 14:08:26 -080039 // For Quick to supply an code blob
Mathieu Chartier193bad92013-08-29 18:46:00 -070040 CompiledCode(CompilerDriver* compiler_driver, InstructionSet instruction_set,
Vladimir Marko35831e82015-09-11 11:59:18 +010041 const ArrayRef<const uint8_t>& quick_code);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080042
43 virtual ~CompiledCode();
Logan Chien598c5132012-04-28 22:00:44 +080044
Logan Chien598c5132012-04-28 22:00:44 +080045 InstructionSet GetInstructionSet() const {
46 return instruction_set_;
47 }
48
Vladimir Marko35831e82015-09-11 11:59:18 +010049 ArrayRef<const uint8_t> GetQuickCode() const {
50 return GetArray(quick_code_);
Logan Chien598c5132012-04-28 22:00:44 +080051 }
52
Ian Rogersef7d42f2014-01-06 12:55:46 -080053 bool operator==(const CompiledCode& rhs) const;
54
Logan Chien598c5132012-04-28 22:00:44 +080055 // To align an offset from a page-aligned value to make it suitable
56 // for code storage. For example on ARM, to ensure that PC relative
57 // valu computations work out as expected.
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080058 size_t AlignCode(size_t offset) const;
59 static size_t AlignCode(size_t offset, InstructionSet instruction_set);
Logan Chien598c5132012-04-28 22:00:44 +080060
61 // returns the difference between the code address and a usable PC.
62 // mainly to cope with kThumb2 where the lower bit must be set.
63 size_t CodeDelta() const;
Dave Allison50abf0a2014-06-23 13:19:59 -070064 static size_t CodeDelta(InstructionSet instruction_set);
Logan Chien598c5132012-04-28 22:00:44 +080065
66 // Returns a pointer suitable for invoking the code at the argument
67 // code_pointer address. Mainly to cope with kThumb2 where the
68 // lower bit must be set to indicate Thumb mode.
69 static const void* CodePointer(const void* code_pointer,
70 InstructionSet instruction_set);
71
Vladimir Marko35831e82015-09-11 11:59:18 +010072 protected:
73 template <typename T>
74 static ArrayRef<const T> GetArray(const LengthPrefixedArray<T>* array) {
75 if (array == nullptr) {
76 return ArrayRef<const T>();
77 }
78 DCHECK_NE(array->size(), 0u);
79 return ArrayRef<const T>(&array->At(0), array->size());
80 }
81
82 CompilerDriver* GetCompilerDriver() {
83 return compiler_driver_;
84 }
Brian Carlstrom265091e2013-01-30 14:08:26 -080085
Logan Chien598c5132012-04-28 22:00:44 +080086 private:
Ian Rogersef7d42f2014-01-06 12:55:46 -080087 CompilerDriver* const compiler_driver_;
Mathieu Chartier193bad92013-08-29 18:46:00 -070088
Logan Chien598c5132012-04-28 22:00:44 +080089 const InstructionSet instruction_set_;
Brian Carlstrom8227cc12013-03-06 14:26:48 -080090
Ian Rogersef7d42f2014-01-06 12:55:46 -080091 // Used to store the PIC code for Quick.
Vladimir Marko35831e82015-09-11 11:59:18 +010092 const LengthPrefixedArray<uint8_t>* const quick_code_;
Logan Chien598c5132012-04-28 22:00:44 +080093};
94
Yevgeny Roubane3ea8382014-08-08 16:29:38 +070095class SrcMapElem {
96 public:
97 uint32_t from_;
98 int32_t to_;
Yevgeny Roubane3ea8382014-08-08 16:29:38 +070099};
100
Vladimir Marko35831e82015-09-11 11:59:18 +0100101inline bool operator<(const SrcMapElem& lhs, const SrcMapElem& rhs) {
102 if (lhs.from_ != rhs.from_) {
103 return lhs.from_ < rhs.from_;
104 }
105 return lhs.to_ < rhs.to_;
106}
107
108inline bool operator==(const SrcMapElem& lhs, const SrcMapElem& rhs) {
109 return lhs.from_ == rhs.from_ && lhs.to_ == rhs.to_;
110}
111
Vladimir Markof4da6752014-08-01 19:04:18 +0100112class LinkerPatch {
113 public:
Vladimir Markoef88a112016-03-31 12:34:48 +0100114 // Note: We explicitly specify the underlying type of the enum because GCC
115 // would otherwise select a bigger underlying type and then complain that
116 // 'art::LinkerPatch::patch_type_' is too small to hold all
117 // values of 'enum class art::LinkerPatch::Type'
118 // which is ridiculous given we have only a handful of values here. If we
119 // choose to squeeze the Type into fewer than 8 bits, we'll have to declare
120 // patch_type_ as an uintN_t and do explicit static_cast<>s.
121 enum class Type : uint8_t {
Vladimir Marko65979462017-05-19 17:25:12 +0100122 kMethodRelative, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100123 kMethodBssEntry, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100124 kCall,
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000125 kCallRelative, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000126 kTypeRelative, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Marko94ec2db2017-09-06 17:21:03 +0100127 kTypeClassTable, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000128 kTypeBssEntry, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000129 kStringRelative, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100130 kStringInternTable, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000131 kStringBssEntry, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000132 kBakerReadBarrierBranch, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100133 };
134
Vladimir Marko65979462017-05-19 17:25:12 +0100135 static LinkerPatch RelativeMethodPatch(size_t literal_offset,
136 const DexFile* target_dex_file,
137 uint32_t pc_insn_offset,
138 uint32_t target_method_idx) {
139 LinkerPatch patch(literal_offset, Type::kMethodRelative, target_dex_file);
Vladimir Marko20f85592015-03-19 10:07:02 +0000140 patch.method_idx_ = target_method_idx;
Vladimir Marko65979462017-05-19 17:25:12 +0100141 patch.pc_insn_offset_ = pc_insn_offset;
Vladimir Marko20f85592015-03-19 10:07:02 +0000142 return patch;
Vladimir Markof4da6752014-08-01 19:04:18 +0100143 }
144
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100145 static LinkerPatch MethodBssEntryPatch(size_t literal_offset,
146 const DexFile* target_dex_file,
147 uint32_t pc_insn_offset,
148 uint32_t target_method_idx) {
149 LinkerPatch patch(literal_offset, Type::kMethodBssEntry, target_dex_file);
150 patch.method_idx_ = target_method_idx;
151 patch.pc_insn_offset_ = pc_insn_offset;
152 return patch;
153 }
154
Vladimir Markof4da6752014-08-01 19:04:18 +0100155 static LinkerPatch CodePatch(size_t literal_offset,
156 const DexFile* target_dex_file,
157 uint32_t target_method_idx) {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100158 LinkerPatch patch(literal_offset, Type::kCall, target_dex_file);
Vladimir Marko20f85592015-03-19 10:07:02 +0000159 patch.method_idx_ = target_method_idx;
160 return patch;
Vladimir Markof4da6752014-08-01 19:04:18 +0100161 }
162
163 static LinkerPatch RelativeCodePatch(size_t literal_offset,
164 const DexFile* target_dex_file,
165 uint32_t target_method_idx) {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100166 LinkerPatch patch(literal_offset, Type::kCallRelative, target_dex_file);
Vladimir Marko20f85592015-03-19 10:07:02 +0000167 patch.method_idx_ = target_method_idx;
168 return patch;
Vladimir Markof4da6752014-08-01 19:04:18 +0100169 }
170
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100171 static LinkerPatch RelativeTypePatch(size_t literal_offset,
172 const DexFile* target_dex_file,
173 uint32_t pc_insn_offset,
174 uint32_t target_type_idx) {
175 LinkerPatch patch(literal_offset, Type::kTypeRelative, target_dex_file);
176 patch.type_idx_ = target_type_idx;
177 patch.pc_insn_offset_ = pc_insn_offset;
178 return patch;
179 }
180
Vladimir Marko94ec2db2017-09-06 17:21:03 +0100181 static LinkerPatch TypeClassTablePatch(size_t literal_offset,
182 const DexFile* target_dex_file,
183 uint32_t pc_insn_offset,
184 uint32_t target_type_idx) {
185 LinkerPatch patch(literal_offset, Type::kTypeClassTable, target_dex_file);
186 patch.type_idx_ = target_type_idx;
187 patch.pc_insn_offset_ = pc_insn_offset;
188 return patch;
189 }
190
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000191 static LinkerPatch TypeBssEntryPatch(size_t literal_offset,
192 const DexFile* target_dex_file,
193 uint32_t pc_insn_offset,
194 uint32_t target_type_idx) {
195 LinkerPatch patch(literal_offset, Type::kTypeBssEntry, target_dex_file);
196 patch.type_idx_ = target_type_idx;
197 patch.pc_insn_offset_ = pc_insn_offset;
198 return patch;
199 }
200
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000201 static LinkerPatch RelativeStringPatch(size_t literal_offset,
202 const DexFile* target_dex_file,
203 uint32_t pc_insn_offset,
204 uint32_t target_string_idx) {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100205 LinkerPatch patch(literal_offset, Type::kStringRelative, target_dex_file);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000206 patch.string_idx_ = target_string_idx;
207 patch.pc_insn_offset_ = pc_insn_offset;
208 return patch;
209 }
210
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100211 static LinkerPatch StringInternTablePatch(size_t literal_offset,
212 const DexFile* target_dex_file,
213 uint32_t pc_insn_offset,
214 uint32_t target_string_idx) {
215 LinkerPatch patch(literal_offset, Type::kStringInternTable, target_dex_file);
216 patch.string_idx_ = target_string_idx;
217 patch.pc_insn_offset_ = pc_insn_offset;
218 return patch;
219 }
220
Vladimir Markoaad75c62016-10-03 08:46:48 +0000221 static LinkerPatch StringBssEntryPatch(size_t literal_offset,
222 const DexFile* target_dex_file,
223 uint32_t pc_insn_offset,
224 uint32_t target_string_idx) {
225 LinkerPatch patch(literal_offset, Type::kStringBssEntry, target_dex_file);
226 patch.string_idx_ = target_string_idx;
227 patch.pc_insn_offset_ = pc_insn_offset;
228 return patch;
229 }
230
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000231 static LinkerPatch BakerReadBarrierBranchPatch(size_t literal_offset,
232 uint32_t custom_value1 = 0u,
233 uint32_t custom_value2 = 0u) {
234 LinkerPatch patch(literal_offset, Type::kBakerReadBarrierBranch, nullptr);
235 patch.baker_custom_value1_ = custom_value1;
236 patch.baker_custom_value2_ = custom_value2;
237 return patch;
238 }
239
Vladimir Markof4da6752014-08-01 19:04:18 +0100240 LinkerPatch(const LinkerPatch& other) = default;
241 LinkerPatch& operator=(const LinkerPatch& other) = default;
242
243 size_t LiteralOffset() const {
244 return literal_offset_;
245 }
246
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100247 Type GetType() const {
Vladimir Markof4da6752014-08-01 19:04:18 +0100248 return patch_type_;
249 }
250
Vladimir Marko20f85592015-03-19 10:07:02 +0000251 bool IsPcRelative() const {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100252 switch (GetType()) {
Vladimir Marko65979462017-05-19 17:25:12 +0100253 case Type::kMethodRelative:
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100254 case Type::kMethodBssEntry:
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100255 case Type::kCallRelative:
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100256 case Type::kTypeRelative:
Vladimir Marko94ec2db2017-09-06 17:21:03 +0100257 case Type::kTypeClassTable:
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000258 case Type::kTypeBssEntry:
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100259 case Type::kStringRelative:
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100260 case Type::kStringInternTable:
Vladimir Markoaad75c62016-10-03 08:46:48 +0000261 case Type::kStringBssEntry:
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000262 case Type::kBakerReadBarrierBranch:
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000263 return true;
264 default:
265 return false;
266 }
Vladimir Marko20f85592015-03-19 10:07:02 +0000267 }
268
Vladimir Markof4da6752014-08-01 19:04:18 +0100269 MethodReference TargetMethod() const {
Vladimir Marko65979462017-05-19 17:25:12 +0100270 DCHECK(patch_type_ == Type::kMethodRelative ||
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100271 patch_type_ == Type::kMethodBssEntry ||
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100272 patch_type_ == Type::kCall ||
273 patch_type_ == Type::kCallRelative);
Vladimir Marko20f85592015-03-19 10:07:02 +0000274 return MethodReference(target_dex_file_, method_idx_);
Vladimir Markof4da6752014-08-01 19:04:18 +0100275 }
276
277 const DexFile* TargetTypeDexFile() const {
Vladimir Marko764d4542017-05-16 10:31:41 +0100278 DCHECK(patch_type_ == Type::kTypeRelative ||
Vladimir Marko94ec2db2017-09-06 17:21:03 +0100279 patch_type_ == Type::kTypeClassTable ||
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000280 patch_type_ == Type::kTypeBssEntry);
Vladimir Markof4da6752014-08-01 19:04:18 +0100281 return target_dex_file_;
282 }
283
Andreas Gampea5b09a62016-11-17 15:21:22 -0800284 dex::TypeIndex TargetTypeIndex() const {
Vladimir Marko764d4542017-05-16 10:31:41 +0100285 DCHECK(patch_type_ == Type::kTypeRelative ||
Vladimir Marko94ec2db2017-09-06 17:21:03 +0100286 patch_type_ == Type::kTypeClassTable ||
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000287 patch_type_ == Type::kTypeBssEntry);
Andreas Gampea5b09a62016-11-17 15:21:22 -0800288 return dex::TypeIndex(type_idx_);
Vladimir Marko20f85592015-03-19 10:07:02 +0000289 }
290
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000291 const DexFile* TargetStringDexFile() const {
Vladimir Marko764d4542017-05-16 10:31:41 +0100292 DCHECK(patch_type_ == Type::kStringRelative ||
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100293 patch_type_ == Type::kStringInternTable ||
Vladimir Markoaad75c62016-10-03 08:46:48 +0000294 patch_type_ == Type::kStringBssEntry);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000295 return target_dex_file_;
296 }
297
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800298 dex::StringIndex TargetStringIndex() const {
Vladimir Marko764d4542017-05-16 10:31:41 +0100299 DCHECK(patch_type_ == Type::kStringRelative ||
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100300 patch_type_ == Type::kStringInternTable ||
Vladimir Markoaad75c62016-10-03 08:46:48 +0000301 patch_type_ == Type::kStringBssEntry);
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800302 return dex::StringIndex(string_idx_);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000303 }
304
Vladimir Marko20f85592015-03-19 10:07:02 +0000305 uint32_t PcInsnOffset() const {
Vladimir Marko65979462017-05-19 17:25:12 +0100306 DCHECK(patch_type_ == Type::kMethodRelative ||
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100307 patch_type_ == Type::kMethodBssEntry ||
Vladimir Marko65979462017-05-19 17:25:12 +0100308 patch_type_ == Type::kTypeRelative ||
Vladimir Marko94ec2db2017-09-06 17:21:03 +0100309 patch_type_ == Type::kTypeClassTable ||
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000310 patch_type_ == Type::kTypeBssEntry ||
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100311 patch_type_ == Type::kStringRelative ||
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100312 patch_type_ == Type::kStringInternTable ||
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100313 patch_type_ == Type::kStringBssEntry);
Vladimir Marko20f85592015-03-19 10:07:02 +0000314 return pc_insn_offset_;
Vladimir Markof4da6752014-08-01 19:04:18 +0100315 }
316
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000317 uint32_t GetBakerCustomValue1() const {
318 DCHECK(patch_type_ == Type::kBakerReadBarrierBranch);
319 return baker_custom_value1_;
320 }
321
322 uint32_t GetBakerCustomValue2() const {
323 DCHECK(patch_type_ == Type::kBakerReadBarrierBranch);
324 return baker_custom_value2_;
325 }
326
Vladimir Markof4da6752014-08-01 19:04:18 +0100327 private:
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100328 LinkerPatch(size_t literal_offset, Type patch_type, const DexFile* target_dex_file)
Vladimir Marko20f85592015-03-19 10:07:02 +0000329 : target_dex_file_(target_dex_file),
330 literal_offset_(literal_offset),
331 patch_type_(patch_type) {
332 cmp1_ = 0u;
333 cmp2_ = 0u;
334 // The compiler rejects methods that are too big, so the compiled code
335 // of a single method really shouln't be anywhere close to 16MiB.
336 DCHECK(IsUint<24>(literal_offset));
Vladimir Markof4da6752014-08-01 19:04:18 +0100337 }
338
Vladimir Markof4da6752014-08-01 19:04:18 +0100339 const DexFile* target_dex_file_;
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000340 // TODO: Clean up naming. Some patched locations are literals but others are not.
Vladimir Marko20f85592015-03-19 10:07:02 +0000341 uint32_t literal_offset_ : 24; // Method code size up to 16MiB.
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100342 Type patch_type_ : 8;
Vladimir Marko20f85592015-03-19 10:07:02 +0000343 union {
344 uint32_t cmp1_; // Used for relational operators.
345 uint32_t method_idx_; // Method index for Call/Method patches.
346 uint32_t type_idx_; // Type index for Type patches.
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000347 uint32_t string_idx_; // String index for String patches.
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000348 uint32_t baker_custom_value1_;
Vladimir Marko35831e82015-09-11 11:59:18 +0100349 static_assert(sizeof(method_idx_) == sizeof(cmp1_), "needed by relational operators");
350 static_assert(sizeof(type_idx_) == sizeof(cmp1_), "needed by relational operators");
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000351 static_assert(sizeof(string_idx_) == sizeof(cmp1_), "needed by relational operators");
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000352 static_assert(sizeof(baker_custom_value1_) == sizeof(cmp1_), "needed by relational operators");
Vladimir Marko20f85592015-03-19 10:07:02 +0000353 };
354 union {
Vladimir Marko34ed3af2016-02-04 20:01:32 +0000355 // Note: To avoid uninitialized padding on 64-bit systems, we use `size_t` for `cmp2_`.
356 // This allows a hashing function to treat an array of linker patches as raw memory.
357 size_t cmp2_; // Used for relational operators.
Vladimir Marko20f85592015-03-19 10:07:02 +0000358 // Literal offset of the insn loading PC (same as literal_offset if it's the same insn,
359 // may be different if the PC-relative addressing needs multiple insns).
360 uint32_t pc_insn_offset_;
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000361 uint32_t baker_custom_value2_;
Vladimir Marko34ed3af2016-02-04 20:01:32 +0000362 static_assert(sizeof(pc_insn_offset_) <= sizeof(cmp2_), "needed by relational operators");
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000363 static_assert(sizeof(baker_custom_value2_) <= sizeof(cmp2_), "needed by relational operators");
Vladimir Marko20f85592015-03-19 10:07:02 +0000364 };
Vladimir Markof4da6752014-08-01 19:04:18 +0100365
366 friend bool operator==(const LinkerPatch& lhs, const LinkerPatch& rhs);
367 friend bool operator<(const LinkerPatch& lhs, const LinkerPatch& rhs);
368};
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100369std::ostream& operator<<(std::ostream& os, const LinkerPatch::Type& type);
Vladimir Markof4da6752014-08-01 19:04:18 +0100370
371inline bool operator==(const LinkerPatch& lhs, const LinkerPatch& rhs) {
372 return lhs.literal_offset_ == rhs.literal_offset_ &&
373 lhs.patch_type_ == rhs.patch_type_ &&
Vladimir Marko20f85592015-03-19 10:07:02 +0000374 lhs.target_dex_file_ == rhs.target_dex_file_ &&
375 lhs.cmp1_ == rhs.cmp1_ &&
376 lhs.cmp2_ == rhs.cmp2_;
Vladimir Markof4da6752014-08-01 19:04:18 +0100377}
378
379inline bool operator<(const LinkerPatch& lhs, const LinkerPatch& rhs) {
380 return (lhs.literal_offset_ != rhs.literal_offset_) ? lhs.literal_offset_ < rhs.literal_offset_
381 : (lhs.patch_type_ != rhs.patch_type_) ? lhs.patch_type_ < rhs.patch_type_
Vladimir Marko20f85592015-03-19 10:07:02 +0000382 : (lhs.target_dex_file_ != rhs.target_dex_file_) ? lhs.target_dex_file_ < rhs.target_dex_file_
383 : (lhs.cmp1_ != rhs.cmp1_) ? lhs.cmp1_ < rhs.cmp1_
384 : lhs.cmp2_ < rhs.cmp2_;
Vladimir Markof4da6752014-08-01 19:04:18 +0100385}
386
Yevgeny Roubane3ea8382014-08-08 16:29:38 +0700387class CompiledMethod FINAL : public CompiledCode {
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700388 public:
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800389 // Constructs a CompiledMethod.
390 // Note: Consider using the static allocation methods below that will allocate the CompiledMethod
391 // in the swap space.
Ian Rogers72d32622014-05-06 16:20:11 -0700392 CompiledMethod(CompilerDriver* driver,
Mathieu Chartier193bad92013-08-29 18:46:00 -0700393 InstructionSet instruction_set,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800394 const ArrayRef<const uint8_t>& quick_code,
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700395 const size_t frame_size_in_bytes,
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700396 const uint32_t core_spill_mask,
397 const uint32_t fp_spill_mask,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700398 const ArrayRef<const uint8_t>& method_info,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800399 const ArrayRef<const uint8_t>& vmap_table,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800400 const ArrayRef<const uint8_t>& cfi_info,
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100401 const ArrayRef<const LinkerPatch>& patches);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700402
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800403 virtual ~CompiledMethod();
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700404
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800405 static CompiledMethod* SwapAllocCompiledMethod(
406 CompilerDriver* driver,
407 InstructionSet instruction_set,
408 const ArrayRef<const uint8_t>& quick_code,
409 const size_t frame_size_in_bytes,
410 const uint32_t core_spill_mask,
411 const uint32_t fp_spill_mask,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700412 const ArrayRef<const uint8_t>& method_info,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800413 const ArrayRef<const uint8_t>& vmap_table,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800414 const ArrayRef<const uint8_t>& cfi_info,
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100415 const ArrayRef<const LinkerPatch>& patches);
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800416
417 static void ReleaseSwapAllocatedCompiledMethod(CompilerDriver* driver, CompiledMethod* m);
418
Ian Rogers0c7abda2012-09-19 13:33:42 -0700419 size_t GetFrameSizeInBytes() const {
420 return frame_size_in_bytes_;
Logan Chien110bcba2012-04-16 19:11:28 +0800421 }
Ian Rogers0c7abda2012-09-19 13:33:42 -0700422
423 uint32_t GetCoreSpillMask() const {
424 return core_spill_mask_;
425 }
426
427 uint32_t GetFpSpillMask() const {
428 return fp_spill_mask_;
429 }
430
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700431 ArrayRef<const uint8_t> GetMethodInfo() const {
432 return GetArray(method_info_);
Yevgeny Roubane3ea8382014-08-08 16:29:38 +0700433 }
434
Vladimir Marko35831e82015-09-11 11:59:18 +0100435 ArrayRef<const uint8_t> GetVmapTable() const {
436 return GetArray(vmap_table_);
Ian Rogers0c7abda2012-09-19 13:33:42 -0700437 }
438
Vladimir Marko35831e82015-09-11 11:59:18 +0100439 ArrayRef<const uint8_t> GetCFIInfo() const {
440 return GetArray(cfi_info_);
Mark Mendellae9fd932014-02-10 16:14:35 -0800441 }
442
Vladimir Markob207e142015-04-02 21:25:21 +0100443 ArrayRef<const LinkerPatch> GetPatches() const {
Vladimir Marko35831e82015-09-11 11:59:18 +0100444 return GetArray(patches_);
Vladimir Markof4da6752014-08-01 19:04:18 +0100445 }
446
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700447 private:
Ian Rogersa1827042013-04-18 16:36:43 -0700448 // For quick code, the size of the activation used by the code.
Ian Rogers0c7abda2012-09-19 13:33:42 -0700449 const size_t frame_size_in_bytes_;
Ian Rogersa1827042013-04-18 16:36:43 -0700450 // For quick code, a bit mask describing spilled GPR callee-save registers.
Ian Rogers169c9a72011-11-13 20:13:17 -0800451 const uint32_t core_spill_mask_;
Ian Rogersa1827042013-04-18 16:36:43 -0700452 // For quick code, a bit mask describing spilled FPR callee-save registers.
Ian Rogers169c9a72011-11-13 20:13:17 -0800453 const uint32_t fp_spill_mask_;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700454 // For quick code, method specific information that is not very dedupe friendly (method indices).
455 const LengthPrefixedArray<uint8_t>* const method_info_;
456 // For quick code, holds code infos which contain stack maps, inline information, and etc.
Vladimir Marko35831e82015-09-11 11:59:18 +0100457 const LengthPrefixedArray<uint8_t>* const vmap_table_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800458 // For quick code, a FDE entry for the debug_frame section.
Vladimir Marko35831e82015-09-11 11:59:18 +0100459 const LengthPrefixedArray<uint8_t>* const cfi_info_;
Vladimir Markof4da6752014-08-01 19:04:18 +0100460 // For quick code, linker patches needed by the method.
Vladimir Marko35831e82015-09-11 11:59:18 +0100461 const LengthPrefixedArray<LinkerPatch>* const patches_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700462};
463
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700464} // namespace art
465
Mathieu Chartier193bad92013-08-29 18:46:00 -0700466#endif // ART_COMPILER_COMPILED_METHOD_H_