blob: 912c96468de1e05684d08bbe9072ad38cecc1f30 [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
Ian Rogers700a4022014-05-19 16:49:03 -070020#include <memory>
Vladimir Markocac5a7e2016-02-22 10:39:50 +000021#include <iosfwd>
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 Markodb8e62d2016-03-30 16:30:21 +0100122 kMethod,
123 kCall,
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000124 kCallRelative, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000125 kTypeRelative, // NOTE: Actual patching is instruction_set-dependent.
126 kTypeBssEntry, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000127 kStringRelative, // NOTE: Actual patching is instruction_set-dependent.
128 kStringBssEntry, // NOTE: Actual patching is instruction_set-dependent.
129 kDexCacheArray, // NOTE: Actual patching is instruction_set-dependent.
130 kBakerReadBarrierBranch, // NOTE: Actual patching is instruction_set-dependent.
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100131 };
132
Vladimir Markof4da6752014-08-01 19:04:18 +0100133 static LinkerPatch MethodPatch(size_t literal_offset,
134 const DexFile* target_dex_file,
135 uint32_t target_method_idx) {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100136 LinkerPatch patch(literal_offset, Type::kMethod, target_dex_file);
Vladimir Marko20f85592015-03-19 10:07:02 +0000137 patch.method_idx_ = target_method_idx;
138 return patch;
Vladimir Markof4da6752014-08-01 19:04:18 +0100139 }
140
141 static LinkerPatch CodePatch(size_t literal_offset,
142 const DexFile* target_dex_file,
143 uint32_t target_method_idx) {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100144 LinkerPatch patch(literal_offset, Type::kCall, target_dex_file);
Vladimir Marko20f85592015-03-19 10:07:02 +0000145 patch.method_idx_ = target_method_idx;
146 return patch;
Vladimir Markof4da6752014-08-01 19:04:18 +0100147 }
148
149 static LinkerPatch RelativeCodePatch(size_t literal_offset,
150 const DexFile* target_dex_file,
151 uint32_t target_method_idx) {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100152 LinkerPatch patch(literal_offset, Type::kCallRelative, target_dex_file);
Vladimir Marko20f85592015-03-19 10:07:02 +0000153 patch.method_idx_ = target_method_idx;
154 return patch;
Vladimir Markof4da6752014-08-01 19:04:18 +0100155 }
156
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100157 static LinkerPatch RelativeTypePatch(size_t literal_offset,
158 const DexFile* target_dex_file,
159 uint32_t pc_insn_offset,
160 uint32_t target_type_idx) {
161 LinkerPatch patch(literal_offset, Type::kTypeRelative, target_dex_file);
162 patch.type_idx_ = target_type_idx;
163 patch.pc_insn_offset_ = pc_insn_offset;
164 return patch;
165 }
166
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000167 static LinkerPatch TypeBssEntryPatch(size_t literal_offset,
168 const DexFile* target_dex_file,
169 uint32_t pc_insn_offset,
170 uint32_t target_type_idx) {
171 LinkerPatch patch(literal_offset, Type::kTypeBssEntry, target_dex_file);
172 patch.type_idx_ = target_type_idx;
173 patch.pc_insn_offset_ = pc_insn_offset;
174 return patch;
175 }
176
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000177 static LinkerPatch RelativeStringPatch(size_t literal_offset,
178 const DexFile* target_dex_file,
179 uint32_t pc_insn_offset,
180 uint32_t target_string_idx) {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100181 LinkerPatch patch(literal_offset, Type::kStringRelative, target_dex_file);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000182 patch.string_idx_ = target_string_idx;
183 patch.pc_insn_offset_ = pc_insn_offset;
184 return patch;
185 }
186
Vladimir Markoaad75c62016-10-03 08:46:48 +0000187 static LinkerPatch StringBssEntryPatch(size_t literal_offset,
188 const DexFile* target_dex_file,
189 uint32_t pc_insn_offset,
190 uint32_t target_string_idx) {
191 LinkerPatch patch(literal_offset, Type::kStringBssEntry, target_dex_file);
192 patch.string_idx_ = target_string_idx;
193 patch.pc_insn_offset_ = pc_insn_offset;
194 return patch;
195 }
196
Vladimir Marko20f85592015-03-19 10:07:02 +0000197 static LinkerPatch DexCacheArrayPatch(size_t literal_offset,
198 const DexFile* target_dex_file,
199 uint32_t pc_insn_offset,
Vladimir Markoaad75c62016-10-03 08:46:48 +0000200 uint32_t element_offset) {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100201 LinkerPatch patch(literal_offset, Type::kDexCacheArray, target_dex_file);
Vladimir Marko20f85592015-03-19 10:07:02 +0000202 patch.pc_insn_offset_ = pc_insn_offset;
203 patch.element_offset_ = element_offset;
204 return patch;
Vladimir Markof4da6752014-08-01 19:04:18 +0100205 }
206
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000207 static LinkerPatch BakerReadBarrierBranchPatch(size_t literal_offset,
208 uint32_t custom_value1 = 0u,
209 uint32_t custom_value2 = 0u) {
210 LinkerPatch patch(literal_offset, Type::kBakerReadBarrierBranch, nullptr);
211 patch.baker_custom_value1_ = custom_value1;
212 patch.baker_custom_value2_ = custom_value2;
213 return patch;
214 }
215
Vladimir Markof4da6752014-08-01 19:04:18 +0100216 LinkerPatch(const LinkerPatch& other) = default;
217 LinkerPatch& operator=(const LinkerPatch& other) = default;
218
219 size_t LiteralOffset() const {
220 return literal_offset_;
221 }
222
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100223 Type GetType() const {
Vladimir Markof4da6752014-08-01 19:04:18 +0100224 return patch_type_;
225 }
226
Vladimir Marko20f85592015-03-19 10:07:02 +0000227 bool IsPcRelative() const {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100228 switch (GetType()) {
229 case Type::kCallRelative:
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100230 case Type::kTypeRelative:
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000231 case Type::kTypeBssEntry:
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100232 case Type::kStringRelative:
Vladimir Markoaad75c62016-10-03 08:46:48 +0000233 case Type::kStringBssEntry:
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100234 case Type::kDexCacheArray:
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000235 case Type::kBakerReadBarrierBranch:
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000236 return true;
237 default:
238 return false;
239 }
Vladimir Marko20f85592015-03-19 10:07:02 +0000240 }
241
Vladimir Markof4da6752014-08-01 19:04:18 +0100242 MethodReference TargetMethod() const {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100243 DCHECK(patch_type_ == Type::kMethod ||
244 patch_type_ == Type::kCall ||
245 patch_type_ == Type::kCallRelative);
Vladimir Marko20f85592015-03-19 10:07:02 +0000246 return MethodReference(target_dex_file_, method_idx_);
Vladimir Markof4da6752014-08-01 19:04:18 +0100247 }
248
249 const DexFile* TargetTypeDexFile() const {
Vladimir Marko764d4542017-05-16 10:31:41 +0100250 DCHECK(patch_type_ == Type::kTypeRelative ||
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000251 patch_type_ == Type::kTypeBssEntry);
Vladimir Markof4da6752014-08-01 19:04:18 +0100252 return target_dex_file_;
253 }
254
Andreas Gampea5b09a62016-11-17 15:21:22 -0800255 dex::TypeIndex TargetTypeIndex() const {
Vladimir Marko764d4542017-05-16 10:31:41 +0100256 DCHECK(patch_type_ == Type::kTypeRelative ||
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000257 patch_type_ == Type::kTypeBssEntry);
Andreas Gampea5b09a62016-11-17 15:21:22 -0800258 return dex::TypeIndex(type_idx_);
Vladimir Marko20f85592015-03-19 10:07:02 +0000259 }
260
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000261 const DexFile* TargetStringDexFile() const {
Vladimir Marko764d4542017-05-16 10:31:41 +0100262 DCHECK(patch_type_ == Type::kStringRelative ||
Vladimir Markoaad75c62016-10-03 08:46:48 +0000263 patch_type_ == Type::kStringBssEntry);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000264 return target_dex_file_;
265 }
266
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800267 dex::StringIndex TargetStringIndex() const {
Vladimir Marko764d4542017-05-16 10:31:41 +0100268 DCHECK(patch_type_ == Type::kStringRelative ||
Vladimir Markoaad75c62016-10-03 08:46:48 +0000269 patch_type_ == Type::kStringBssEntry);
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800270 return dex::StringIndex(string_idx_);
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000271 }
272
Vladimir Marko20f85592015-03-19 10:07:02 +0000273 const DexFile* TargetDexCacheDexFile() const {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100274 DCHECK(patch_type_ == Type::kDexCacheArray);
Vladimir Marko20f85592015-03-19 10:07:02 +0000275 return target_dex_file_;
276 }
277
278 size_t TargetDexCacheElementOffset() const {
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100279 DCHECK(patch_type_ == Type::kDexCacheArray);
Vladimir Marko20f85592015-03-19 10:07:02 +0000280 return element_offset_;
281 }
282
283 uint32_t PcInsnOffset() const {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100284 DCHECK(patch_type_ == Type::kTypeRelative ||
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000285 patch_type_ == Type::kTypeBssEntry ||
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100286 patch_type_ == Type::kStringRelative ||
Vladimir Markoaad75c62016-10-03 08:46:48 +0000287 patch_type_ == Type::kStringBssEntry ||
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100288 patch_type_ == Type::kDexCacheArray);
Vladimir Marko20f85592015-03-19 10:07:02 +0000289 return pc_insn_offset_;
Vladimir Markof4da6752014-08-01 19:04:18 +0100290 }
291
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000292 uint32_t GetBakerCustomValue1() const {
293 DCHECK(patch_type_ == Type::kBakerReadBarrierBranch);
294 return baker_custom_value1_;
295 }
296
297 uint32_t GetBakerCustomValue2() const {
298 DCHECK(patch_type_ == Type::kBakerReadBarrierBranch);
299 return baker_custom_value2_;
300 }
301
Vladimir Markof4da6752014-08-01 19:04:18 +0100302 private:
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100303 LinkerPatch(size_t literal_offset, Type patch_type, const DexFile* target_dex_file)
Vladimir Marko20f85592015-03-19 10:07:02 +0000304 : target_dex_file_(target_dex_file),
305 literal_offset_(literal_offset),
306 patch_type_(patch_type) {
307 cmp1_ = 0u;
308 cmp2_ = 0u;
309 // The compiler rejects methods that are too big, so the compiled code
310 // of a single method really shouln't be anywhere close to 16MiB.
311 DCHECK(IsUint<24>(literal_offset));
Vladimir Markof4da6752014-08-01 19:04:18 +0100312 }
313
Vladimir Markof4da6752014-08-01 19:04:18 +0100314 const DexFile* target_dex_file_;
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000315 // TODO: Clean up naming. Some patched locations are literals but others are not.
Vladimir Marko20f85592015-03-19 10:07:02 +0000316 uint32_t literal_offset_ : 24; // Method code size up to 16MiB.
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100317 Type patch_type_ : 8;
Vladimir Marko20f85592015-03-19 10:07:02 +0000318 union {
319 uint32_t cmp1_; // Used for relational operators.
320 uint32_t method_idx_; // Method index for Call/Method patches.
321 uint32_t type_idx_; // Type index for Type patches.
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000322 uint32_t string_idx_; // String index for String patches.
Vladimir Marko20f85592015-03-19 10:07:02 +0000323 uint32_t element_offset_; // Element offset in the dex cache arrays.
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000324 uint32_t baker_custom_value1_;
Vladimir Marko35831e82015-09-11 11:59:18 +0100325 static_assert(sizeof(method_idx_) == sizeof(cmp1_), "needed by relational operators");
326 static_assert(sizeof(type_idx_) == sizeof(cmp1_), "needed by relational operators");
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000327 static_assert(sizeof(string_idx_) == sizeof(cmp1_), "needed by relational operators");
Vladimir Marko35831e82015-09-11 11:59:18 +0100328 static_assert(sizeof(element_offset_) == sizeof(cmp1_), "needed by relational operators");
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000329 static_assert(sizeof(baker_custom_value1_) == sizeof(cmp1_), "needed by relational operators");
Vladimir Marko20f85592015-03-19 10:07:02 +0000330 };
331 union {
Vladimir Marko34ed3af2016-02-04 20:01:32 +0000332 // Note: To avoid uninitialized padding on 64-bit systems, we use `size_t` for `cmp2_`.
333 // This allows a hashing function to treat an array of linker patches as raw memory.
334 size_t cmp2_; // Used for relational operators.
Vladimir Marko20f85592015-03-19 10:07:02 +0000335 // Literal offset of the insn loading PC (same as literal_offset if it's the same insn,
336 // may be different if the PC-relative addressing needs multiple insns).
337 uint32_t pc_insn_offset_;
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000338 uint32_t baker_custom_value2_;
Vladimir Marko34ed3af2016-02-04 20:01:32 +0000339 static_assert(sizeof(pc_insn_offset_) <= sizeof(cmp2_), "needed by relational operators");
Vladimir Markof4f2daa2017-03-20 18:26:59 +0000340 static_assert(sizeof(baker_custom_value2_) <= sizeof(cmp2_), "needed by relational operators");
Vladimir Marko20f85592015-03-19 10:07:02 +0000341 };
Vladimir Markof4da6752014-08-01 19:04:18 +0100342
343 friend bool operator==(const LinkerPatch& lhs, const LinkerPatch& rhs);
344 friend bool operator<(const LinkerPatch& lhs, const LinkerPatch& rhs);
345};
Vladimir Markodb8e62d2016-03-30 16:30:21 +0100346std::ostream& operator<<(std::ostream& os, const LinkerPatch::Type& type);
Vladimir Markof4da6752014-08-01 19:04:18 +0100347
348inline bool operator==(const LinkerPatch& lhs, const LinkerPatch& rhs) {
349 return lhs.literal_offset_ == rhs.literal_offset_ &&
350 lhs.patch_type_ == rhs.patch_type_ &&
Vladimir Marko20f85592015-03-19 10:07:02 +0000351 lhs.target_dex_file_ == rhs.target_dex_file_ &&
352 lhs.cmp1_ == rhs.cmp1_ &&
353 lhs.cmp2_ == rhs.cmp2_;
Vladimir Markof4da6752014-08-01 19:04:18 +0100354}
355
356inline bool operator<(const LinkerPatch& lhs, const LinkerPatch& rhs) {
357 return (lhs.literal_offset_ != rhs.literal_offset_) ? lhs.literal_offset_ < rhs.literal_offset_
358 : (lhs.patch_type_ != rhs.patch_type_) ? lhs.patch_type_ < rhs.patch_type_
Vladimir Marko20f85592015-03-19 10:07:02 +0000359 : (lhs.target_dex_file_ != rhs.target_dex_file_) ? lhs.target_dex_file_ < rhs.target_dex_file_
360 : (lhs.cmp1_ != rhs.cmp1_) ? lhs.cmp1_ < rhs.cmp1_
361 : lhs.cmp2_ < rhs.cmp2_;
Vladimir Markof4da6752014-08-01 19:04:18 +0100362}
363
Yevgeny Roubane3ea8382014-08-08 16:29:38 +0700364class CompiledMethod FINAL : public CompiledCode {
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700365 public:
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800366 // Constructs a CompiledMethod.
367 // Note: Consider using the static allocation methods below that will allocate the CompiledMethod
368 // in the swap space.
Ian Rogers72d32622014-05-06 16:20:11 -0700369 CompiledMethod(CompilerDriver* driver,
Mathieu Chartier193bad92013-08-29 18:46:00 -0700370 InstructionSet instruction_set,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800371 const ArrayRef<const uint8_t>& quick_code,
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700372 const size_t frame_size_in_bytes,
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700373 const uint32_t core_spill_mask,
374 const uint32_t fp_spill_mask,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700375 const ArrayRef<const uint8_t>& method_info,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800376 const ArrayRef<const uint8_t>& vmap_table,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800377 const ArrayRef<const uint8_t>& cfi_info,
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100378 const ArrayRef<const LinkerPatch>& patches);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700379
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800380 virtual ~CompiledMethod();
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700381
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800382 static CompiledMethod* SwapAllocCompiledMethod(
383 CompilerDriver* driver,
384 InstructionSet instruction_set,
385 const ArrayRef<const uint8_t>& quick_code,
386 const size_t frame_size_in_bytes,
387 const uint32_t core_spill_mask,
388 const uint32_t fp_spill_mask,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700389 const ArrayRef<const uint8_t>& method_info,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800390 const ArrayRef<const uint8_t>& vmap_table,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800391 const ArrayRef<const uint8_t>& cfi_info,
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100392 const ArrayRef<const LinkerPatch>& patches);
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800393
394 static void ReleaseSwapAllocatedCompiledMethod(CompilerDriver* driver, CompiledMethod* m);
395
Ian Rogers0c7abda2012-09-19 13:33:42 -0700396 size_t GetFrameSizeInBytes() const {
397 return frame_size_in_bytes_;
Logan Chien110bcba2012-04-16 19:11:28 +0800398 }
Ian Rogers0c7abda2012-09-19 13:33:42 -0700399
400 uint32_t GetCoreSpillMask() const {
401 return core_spill_mask_;
402 }
403
404 uint32_t GetFpSpillMask() const {
405 return fp_spill_mask_;
406 }
407
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700408 ArrayRef<const uint8_t> GetMethodInfo() const {
409 return GetArray(method_info_);
Yevgeny Roubane3ea8382014-08-08 16:29:38 +0700410 }
411
Vladimir Marko35831e82015-09-11 11:59:18 +0100412 ArrayRef<const uint8_t> GetVmapTable() const {
413 return GetArray(vmap_table_);
Ian Rogers0c7abda2012-09-19 13:33:42 -0700414 }
415
Vladimir Marko35831e82015-09-11 11:59:18 +0100416 ArrayRef<const uint8_t> GetCFIInfo() const {
417 return GetArray(cfi_info_);
Mark Mendellae9fd932014-02-10 16:14:35 -0800418 }
419
Vladimir Markob207e142015-04-02 21:25:21 +0100420 ArrayRef<const LinkerPatch> GetPatches() const {
Vladimir Marko35831e82015-09-11 11:59:18 +0100421 return GetArray(patches_);
Vladimir Markof4da6752014-08-01 19:04:18 +0100422 }
423
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700424 private:
Ian Rogersa1827042013-04-18 16:36:43 -0700425 // For quick code, the size of the activation used by the code.
Ian Rogers0c7abda2012-09-19 13:33:42 -0700426 const size_t frame_size_in_bytes_;
Ian Rogersa1827042013-04-18 16:36:43 -0700427 // For quick code, a bit mask describing spilled GPR callee-save registers.
Ian Rogers169c9a72011-11-13 20:13:17 -0800428 const uint32_t core_spill_mask_;
Ian Rogersa1827042013-04-18 16:36:43 -0700429 // For quick code, a bit mask describing spilled FPR callee-save registers.
Ian Rogers169c9a72011-11-13 20:13:17 -0800430 const uint32_t fp_spill_mask_;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700431 // For quick code, method specific information that is not very dedupe friendly (method indices).
432 const LengthPrefixedArray<uint8_t>* const method_info_;
433 // For quick code, holds code infos which contain stack maps, inline information, and etc.
Vladimir Marko35831e82015-09-11 11:59:18 +0100434 const LengthPrefixedArray<uint8_t>* const vmap_table_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800435 // For quick code, a FDE entry for the debug_frame section.
Vladimir Marko35831e82015-09-11 11:59:18 +0100436 const LengthPrefixedArray<uint8_t>* const cfi_info_;
Vladimir Markof4da6752014-08-01 19:04:18 +0100437 // For quick code, linker patches needed by the method.
Vladimir Marko35831e82015-09-11 11:59:18 +0100438 const LengthPrefixedArray<LinkerPatch>* const patches_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700439};
440
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700441} // namespace art
442
Mathieu Chartier193bad92013-08-29 18:46:00 -0700443#endif // ART_COMPILER_COMPILED_METHOD_H_