Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 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 | */ |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 16 | |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_COMPILED_METHOD_H_ |
| 18 | #define ART_COMPILER_COMPILED_METHOD_H_ |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 19 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 20 | #include <memory> |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 21 | #include <string> |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 24 | #include "arch/instruction_set.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 25 | #include "base/bit_utils.h" |
Alex Light | e64300b | 2015-12-15 15:02:47 -0800 | [diff] [blame] | 26 | #include "base/length_prefixed_array.h" |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 27 | #include "method_reference.h" |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 28 | #include "utils/array_ref.h" |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 29 | |
| 30 | namespace art { |
| 31 | |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 32 | class CompilerDriver; |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 33 | class CompiledMethodStorage; |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 34 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 35 | class CompiledCode { |
| 36 | public: |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 37 | // For Quick to supply an code blob |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 38 | CompiledCode(CompilerDriver* compiler_driver, InstructionSet instruction_set, |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 39 | const ArrayRef<const uint8_t>& quick_code); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 40 | |
| 41 | virtual ~CompiledCode(); |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 42 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 43 | InstructionSet GetInstructionSet() const { |
| 44 | return instruction_set_; |
| 45 | } |
| 46 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 47 | ArrayRef<const uint8_t> GetQuickCode() const { |
| 48 | return GetArray(quick_code_); |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 49 | } |
| 50 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 51 | bool operator==(const CompiledCode& rhs) const; |
| 52 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 53 | // To align an offset from a page-aligned value to make it suitable |
| 54 | // for code storage. For example on ARM, to ensure that PC relative |
| 55 | // valu computations work out as expected. |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 56 | size_t AlignCode(size_t offset) const; |
| 57 | static size_t AlignCode(size_t offset, InstructionSet instruction_set); |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 58 | |
| 59 | // returns the difference between the code address and a usable PC. |
| 60 | // mainly to cope with kThumb2 where the lower bit must be set. |
| 61 | size_t CodeDelta() const; |
Dave Allison | 50abf0a | 2014-06-23 13:19:59 -0700 | [diff] [blame] | 62 | static size_t CodeDelta(InstructionSet instruction_set); |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 63 | |
| 64 | // Returns a pointer suitable for invoking the code at the argument |
| 65 | // code_pointer address. Mainly to cope with kThumb2 where the |
| 66 | // lower bit must be set to indicate Thumb mode. |
| 67 | static const void* CodePointer(const void* code_pointer, |
| 68 | InstructionSet instruction_set); |
| 69 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 70 | protected: |
| 71 | template <typename T> |
| 72 | static ArrayRef<const T> GetArray(const LengthPrefixedArray<T>* array) { |
| 73 | if (array == nullptr) { |
| 74 | return ArrayRef<const T>(); |
| 75 | } |
| 76 | DCHECK_NE(array->size(), 0u); |
| 77 | return ArrayRef<const T>(&array->At(0), array->size()); |
| 78 | } |
| 79 | |
| 80 | CompilerDriver* GetCompilerDriver() { |
| 81 | return compiler_driver_; |
| 82 | } |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 83 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 84 | private: |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 85 | CompilerDriver* const compiler_driver_; |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 86 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 87 | const InstructionSet instruction_set_; |
Brian Carlstrom | 8227cc1 | 2013-03-06 14:26:48 -0800 | [diff] [blame] | 88 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 89 | // Used to store the PIC code for Quick. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 90 | const LengthPrefixedArray<uint8_t>* const quick_code_; |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 91 | }; |
| 92 | |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 93 | class SrcMapElem { |
| 94 | public: |
| 95 | uint32_t from_; |
| 96 | int32_t to_; |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 97 | }; |
| 98 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 99 | inline bool operator<(const SrcMapElem& lhs, const SrcMapElem& rhs) { |
| 100 | if (lhs.from_ != rhs.from_) { |
| 101 | return lhs.from_ < rhs.from_; |
| 102 | } |
| 103 | return lhs.to_ < rhs.to_; |
| 104 | } |
| 105 | |
| 106 | inline bool operator==(const SrcMapElem& lhs, const SrcMapElem& rhs) { |
| 107 | return lhs.from_ == rhs.from_ && lhs.to_ == rhs.to_; |
| 108 | } |
| 109 | |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 110 | template <class Allocator> |
| 111 | class SrcMap FINAL : public std::vector<SrcMapElem, Allocator> { |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 112 | public: |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 113 | using std::vector<SrcMapElem, Allocator>::begin; |
| 114 | using typename std::vector<SrcMapElem, Allocator>::const_iterator; |
| 115 | using std::vector<SrcMapElem, Allocator>::empty; |
| 116 | using std::vector<SrcMapElem, Allocator>::end; |
| 117 | using std::vector<SrcMapElem, Allocator>::resize; |
| 118 | using std::vector<SrcMapElem, Allocator>::shrink_to_fit; |
| 119 | using std::vector<SrcMapElem, Allocator>::size; |
| 120 | |
| 121 | explicit SrcMap() {} |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 122 | explicit SrcMap(const Allocator& alloc) : std::vector<SrcMapElem, Allocator>(alloc) {} |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 123 | |
| 124 | template <class InputIt> |
| 125 | SrcMap(InputIt first, InputIt last, const Allocator& alloc) |
| 126 | : std::vector<SrcMapElem, Allocator>(first, last, alloc) {} |
| 127 | |
David Srbecky | 6f71589 | 2015-03-30 14:21:42 +0100 | [diff] [blame] | 128 | void push_back(const SrcMapElem& elem) { |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 129 | if (!empty()) { |
David Srbecky | 6f71589 | 2015-03-30 14:21:42 +0100 | [diff] [blame] | 130 | // Check that the addresses are inserted in sorted order. |
| 131 | DCHECK_GE(elem.from_, this->back().from_); |
| 132 | // If two consequitive entries map to the same value, ignore the later. |
| 133 | // E.g. for map {{0, 1}, {4, 1}, {8, 2}}, all values in [0,8) map to 1. |
| 134 | if (elem.to_ == this->back().to_) { |
| 135 | return; |
| 136 | } |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 137 | } |
David Srbecky | 6f71589 | 2015-03-30 14:21:42 +0100 | [diff] [blame] | 138 | std::vector<SrcMapElem, Allocator>::push_back(elem); |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 139 | } |
| 140 | |
David Srbecky | 6f71589 | 2015-03-30 14:21:42 +0100 | [diff] [blame] | 141 | // Returns true and the corresponding "to" value if the mapping is found. |
| 142 | // Oterwise returns false and 0. |
| 143 | std::pair<bool, int32_t> Find(uint32_t from) const { |
| 144 | // Finds first mapping such that lb.from_ >= from. |
| 145 | auto lb = std::lower_bound(begin(), end(), SrcMapElem {from, INT32_MIN}); |
| 146 | if (lb != end() && lb->from_ == from) { |
| 147 | // Found exact match. |
| 148 | return std::make_pair(true, lb->to_); |
| 149 | } else if (lb != begin()) { |
| 150 | // The previous mapping is still in effect. |
| 151 | return std::make_pair(true, (--lb)->to_); |
| 152 | } else { |
| 153 | // Not found because 'from' is smaller than first entry in the map. |
| 154 | return std::make_pair(false, 0); |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | }; |
| 158 | |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 159 | using DefaultSrcMap = SrcMap<std::allocator<SrcMapElem>>; |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 160 | |
| 161 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 162 | enum LinkerPatchType { |
| 163 | kLinkerPatchMethod, |
| 164 | kLinkerPatchCall, |
| 165 | kLinkerPatchCallRelative, // NOTE: Actual patching is instruction_set-dependent. |
| 166 | kLinkerPatchType, |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 167 | kLinkerPatchDexCacheArray, // NOTE: Actual patching is instruction_set-dependent. |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | class LinkerPatch { |
| 171 | public: |
| 172 | static LinkerPatch MethodPatch(size_t literal_offset, |
| 173 | const DexFile* target_dex_file, |
| 174 | uint32_t target_method_idx) { |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 175 | LinkerPatch patch(literal_offset, kLinkerPatchMethod, target_dex_file); |
| 176 | patch.method_idx_ = target_method_idx; |
| 177 | return patch; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static LinkerPatch CodePatch(size_t literal_offset, |
| 181 | const DexFile* target_dex_file, |
| 182 | uint32_t target_method_idx) { |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 183 | LinkerPatch patch(literal_offset, kLinkerPatchCall, target_dex_file); |
| 184 | patch.method_idx_ = target_method_idx; |
| 185 | return patch; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static LinkerPatch RelativeCodePatch(size_t literal_offset, |
| 189 | const DexFile* target_dex_file, |
| 190 | uint32_t target_method_idx) { |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 191 | LinkerPatch patch(literal_offset, kLinkerPatchCallRelative, target_dex_file); |
| 192 | patch.method_idx_ = target_method_idx; |
| 193 | return patch; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static LinkerPatch TypePatch(size_t literal_offset, |
| 197 | const DexFile* target_dex_file, |
| 198 | uint32_t target_type_idx) { |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 199 | LinkerPatch patch(literal_offset, kLinkerPatchType, target_dex_file); |
| 200 | patch.type_idx_ = target_type_idx; |
| 201 | return patch; |
| 202 | } |
| 203 | |
| 204 | static LinkerPatch DexCacheArrayPatch(size_t literal_offset, |
| 205 | const DexFile* target_dex_file, |
| 206 | uint32_t pc_insn_offset, |
| 207 | size_t element_offset) { |
| 208 | DCHECK(IsUint<32>(element_offset)); |
| 209 | LinkerPatch patch(literal_offset, kLinkerPatchDexCacheArray, target_dex_file); |
| 210 | patch.pc_insn_offset_ = pc_insn_offset; |
| 211 | patch.element_offset_ = element_offset; |
| 212 | return patch; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | LinkerPatch(const LinkerPatch& other) = default; |
| 216 | LinkerPatch& operator=(const LinkerPatch& other) = default; |
| 217 | |
| 218 | size_t LiteralOffset() const { |
| 219 | return literal_offset_; |
| 220 | } |
| 221 | |
| 222 | LinkerPatchType Type() const { |
| 223 | return patch_type_; |
| 224 | } |
| 225 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 226 | bool IsPcRelative() const { |
| 227 | return Type() == kLinkerPatchCallRelative || Type() == kLinkerPatchDexCacheArray; |
| 228 | } |
| 229 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 230 | MethodReference TargetMethod() const { |
| 231 | DCHECK(patch_type_ == kLinkerPatchMethod || |
| 232 | patch_type_ == kLinkerPatchCall || patch_type_ == kLinkerPatchCallRelative); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 233 | return MethodReference(target_dex_file_, method_idx_); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | const DexFile* TargetTypeDexFile() const { |
| 237 | DCHECK(patch_type_ == kLinkerPatchType); |
| 238 | return target_dex_file_; |
| 239 | } |
| 240 | |
| 241 | uint32_t TargetTypeIndex() const { |
| 242 | DCHECK(patch_type_ == kLinkerPatchType); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 243 | return type_idx_; |
| 244 | } |
| 245 | |
| 246 | const DexFile* TargetDexCacheDexFile() const { |
| 247 | DCHECK(patch_type_ == kLinkerPatchDexCacheArray); |
| 248 | return target_dex_file_; |
| 249 | } |
| 250 | |
| 251 | size_t TargetDexCacheElementOffset() const { |
| 252 | DCHECK(patch_type_ == kLinkerPatchDexCacheArray); |
| 253 | return element_offset_; |
| 254 | } |
| 255 | |
| 256 | uint32_t PcInsnOffset() const { |
| 257 | DCHECK(patch_type_ == kLinkerPatchDexCacheArray); |
| 258 | return pc_insn_offset_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | private: |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 262 | LinkerPatch(size_t literal_offset, LinkerPatchType patch_type, const DexFile* target_dex_file) |
| 263 | : target_dex_file_(target_dex_file), |
| 264 | literal_offset_(literal_offset), |
| 265 | patch_type_(patch_type) { |
| 266 | cmp1_ = 0u; |
| 267 | cmp2_ = 0u; |
| 268 | // The compiler rejects methods that are too big, so the compiled code |
| 269 | // of a single method really shouln't be anywhere close to 16MiB. |
| 270 | DCHECK(IsUint<24>(literal_offset)); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 271 | } |
| 272 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 273 | const DexFile* target_dex_file_; |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 274 | uint32_t literal_offset_ : 24; // Method code size up to 16MiB. |
| 275 | LinkerPatchType patch_type_ : 8; |
| 276 | union { |
| 277 | uint32_t cmp1_; // Used for relational operators. |
| 278 | uint32_t method_idx_; // Method index for Call/Method patches. |
| 279 | uint32_t type_idx_; // Type index for Type patches. |
| 280 | uint32_t element_offset_; // Element offset in the dex cache arrays. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 281 | static_assert(sizeof(method_idx_) == sizeof(cmp1_), "needed by relational operators"); |
| 282 | static_assert(sizeof(type_idx_) == sizeof(cmp1_), "needed by relational operators"); |
| 283 | static_assert(sizeof(element_offset_) == sizeof(cmp1_), "needed by relational operators"); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 284 | }; |
| 285 | union { |
| 286 | uint32_t cmp2_; // Used for relational operators. |
| 287 | // Literal offset of the insn loading PC (same as literal_offset if it's the same insn, |
| 288 | // may be different if the PC-relative addressing needs multiple insns). |
| 289 | uint32_t pc_insn_offset_; |
| 290 | static_assert(sizeof(pc_insn_offset_) == sizeof(cmp2_), "needed by relational operators"); |
| 291 | }; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 292 | |
| 293 | friend bool operator==(const LinkerPatch& lhs, const LinkerPatch& rhs); |
| 294 | friend bool operator<(const LinkerPatch& lhs, const LinkerPatch& rhs); |
| 295 | }; |
| 296 | |
| 297 | inline bool operator==(const LinkerPatch& lhs, const LinkerPatch& rhs) { |
| 298 | return lhs.literal_offset_ == rhs.literal_offset_ && |
| 299 | lhs.patch_type_ == rhs.patch_type_ && |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 300 | lhs.target_dex_file_ == rhs.target_dex_file_ && |
| 301 | lhs.cmp1_ == rhs.cmp1_ && |
| 302 | lhs.cmp2_ == rhs.cmp2_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | inline bool operator<(const LinkerPatch& lhs, const LinkerPatch& rhs) { |
| 306 | return (lhs.literal_offset_ != rhs.literal_offset_) ? lhs.literal_offset_ < rhs.literal_offset_ |
| 307 | : (lhs.patch_type_ != rhs.patch_type_) ? lhs.patch_type_ < rhs.patch_type_ |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 308 | : (lhs.target_dex_file_ != rhs.target_dex_file_) ? lhs.target_dex_file_ < rhs.target_dex_file_ |
| 309 | : (lhs.cmp1_ != rhs.cmp1_) ? lhs.cmp1_ < rhs.cmp1_ |
| 310 | : lhs.cmp2_ < rhs.cmp2_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 311 | } |
| 312 | |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 313 | class CompiledMethod FINAL : public CompiledCode { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 314 | public: |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 315 | // Constructs a CompiledMethod. |
| 316 | // Note: Consider using the static allocation methods below that will allocate the CompiledMethod |
| 317 | // in the swap space. |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 318 | CompiledMethod(CompilerDriver* driver, |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 319 | InstructionSet instruction_set, |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 320 | const ArrayRef<const uint8_t>& quick_code, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 321 | const size_t frame_size_in_bytes, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 322 | const uint32_t core_spill_mask, |
| 323 | const uint32_t fp_spill_mask, |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 324 | const ArrayRef<const SrcMapElem>& src_mapping_table, |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 325 | const ArrayRef<const uint8_t>& mapping_table, |
| 326 | const ArrayRef<const uint8_t>& vmap_table, |
| 327 | const ArrayRef<const uint8_t>& native_gc_map, |
| 328 | const ArrayRef<const uint8_t>& cfi_info, |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 329 | const ArrayRef<const LinkerPatch>& patches); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 330 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 331 | virtual ~CompiledMethod(); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 332 | |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 333 | static CompiledMethod* SwapAllocCompiledMethod( |
| 334 | CompilerDriver* driver, |
| 335 | InstructionSet instruction_set, |
| 336 | const ArrayRef<const uint8_t>& quick_code, |
| 337 | const size_t frame_size_in_bytes, |
| 338 | const uint32_t core_spill_mask, |
| 339 | const uint32_t fp_spill_mask, |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 340 | const ArrayRef<const SrcMapElem>& src_mapping_table, |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 341 | const ArrayRef<const uint8_t>& mapping_table, |
| 342 | const ArrayRef<const uint8_t>& vmap_table, |
| 343 | const ArrayRef<const uint8_t>& native_gc_map, |
| 344 | const ArrayRef<const uint8_t>& cfi_info, |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 345 | const ArrayRef<const LinkerPatch>& patches); |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 346 | |
| 347 | static void ReleaseSwapAllocatedCompiledMethod(CompilerDriver* driver, CompiledMethod* m); |
| 348 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 349 | size_t GetFrameSizeInBytes() const { |
| 350 | return frame_size_in_bytes_; |
Logan Chien | 110bcba | 2012-04-16 19:11:28 +0800 | [diff] [blame] | 351 | } |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 352 | |
| 353 | uint32_t GetCoreSpillMask() const { |
| 354 | return core_spill_mask_; |
| 355 | } |
| 356 | |
| 357 | uint32_t GetFpSpillMask() const { |
| 358 | return fp_spill_mask_; |
| 359 | } |
| 360 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 361 | ArrayRef<const SrcMapElem> GetSrcMappingTable() const { |
| 362 | return GetArray(src_mapping_table_); |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 363 | } |
| 364 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 365 | ArrayRef<const uint8_t> GetMappingTable() const { |
| 366 | return GetArray(mapping_table_); |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 369 | ArrayRef<const uint8_t> GetVmapTable() const { |
| 370 | return GetArray(vmap_table_); |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 373 | ArrayRef<const uint8_t> GetGcMap() const { |
| 374 | return GetArray(gc_map_); |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 375 | } |
Logan Chien | 110bcba | 2012-04-16 19:11:28 +0800 | [diff] [blame] | 376 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 377 | ArrayRef<const uint8_t> GetCFIInfo() const { |
| 378 | return GetArray(cfi_info_); |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 379 | } |
| 380 | |
Vladimir Marko | b207e14 | 2015-04-02 21:25:21 +0100 | [diff] [blame] | 381 | ArrayRef<const LinkerPatch> GetPatches() const { |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 382 | return GetArray(patches_); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 385 | private: |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 386 | // For quick code, the size of the activation used by the code. |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 387 | const size_t frame_size_in_bytes_; |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 388 | // For quick code, a bit mask describing spilled GPR callee-save registers. |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 389 | const uint32_t core_spill_mask_; |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 390 | // For quick code, a bit mask describing spilled FPR callee-save registers. |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 391 | const uint32_t fp_spill_mask_; |
David Srbecky | 6f71589 | 2015-03-30 14:21:42 +0100 | [diff] [blame] | 392 | // For quick code, a set of pairs (PC, DEX) mapping from native PC offset to DEX offset. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 393 | const LengthPrefixedArray<SrcMapElem>* const src_mapping_table_; |
Ian Rogers | 96faf5b | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 394 | // For quick code, a uleb128 encoded map from native PC offset to dex PC aswell as dex PC to |
| 395 | // native PC offset. Size prefixed. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 396 | const LengthPrefixedArray<uint8_t>* const mapping_table_; |
Ian Rogers | 96faf5b | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 397 | // For quick code, a uleb128 encoded map from GPR/FPR register to dex register. Size prefixed. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 398 | const LengthPrefixedArray<uint8_t>* const vmap_table_; |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 399 | // For quick code, a map keyed by native PC indices to bitmaps describing what dalvik registers |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 400 | // are live. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 401 | const LengthPrefixedArray<uint8_t>* const gc_map_; |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 402 | // For quick code, a FDE entry for the debug_frame section. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 403 | const LengthPrefixedArray<uint8_t>* const cfi_info_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 404 | // For quick code, linker patches needed by the method. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 405 | const LengthPrefixedArray<LinkerPatch>* const patches_; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 406 | }; |
| 407 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 408 | } // namespace art |
| 409 | |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 410 | #endif // ART_COMPILER_COMPILED_METHOD_H_ |