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