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> |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 21 | #include <iosfwd> |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 22 | #include <string> |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 23 | #include <vector> |
| 24 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 25 | #include "arch/instruction_set.h" |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 26 | #include "base/array_ref.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 27 | #include "base/bit_utils.h" |
Alex Light | e64300b | 2015-12-15 15:02:47 -0800 | [diff] [blame] | 28 | #include "base/length_prefixed_array.h" |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 29 | #include "dex_file_types.h" |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 30 | #include "method_reference.h" |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 31 | |
| 32 | namespace art { |
| 33 | |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 34 | class CompilerDriver; |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 35 | class CompiledMethodStorage; |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 36 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 37 | class CompiledCode { |
| 38 | public: |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 39 | // For Quick to supply an code blob |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 40 | CompiledCode(CompilerDriver* compiler_driver, InstructionSet instruction_set, |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 41 | const ArrayRef<const uint8_t>& quick_code); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 42 | |
| 43 | virtual ~CompiledCode(); |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 44 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 45 | InstructionSet GetInstructionSet() const { |
| 46 | return instruction_set_; |
| 47 | } |
| 48 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 49 | ArrayRef<const uint8_t> GetQuickCode() const { |
| 50 | return GetArray(quick_code_); |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 51 | } |
| 52 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 53 | bool operator==(const CompiledCode& rhs) const; |
| 54 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 55 | // 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 Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 58 | size_t AlignCode(size_t offset) const; |
| 59 | static size_t AlignCode(size_t offset, InstructionSet instruction_set); |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 60 | |
| 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 Allison | 50abf0a | 2014-06-23 13:19:59 -0700 | [diff] [blame] | 64 | static size_t CodeDelta(InstructionSet instruction_set); |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 65 | |
| 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 Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 72 | 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 Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 85 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 86 | private: |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 87 | CompilerDriver* const compiler_driver_; |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 88 | |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 89 | const InstructionSet instruction_set_; |
Brian Carlstrom | 8227cc1 | 2013-03-06 14:26:48 -0800 | [diff] [blame] | 90 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 91 | // Used to store the PIC code for Quick. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 92 | const LengthPrefixedArray<uint8_t>* const quick_code_; |
Logan Chien | 598c513 | 2012-04-28 22:00:44 +0800 | [diff] [blame] | 93 | }; |
| 94 | |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 95 | class SrcMapElem { |
| 96 | public: |
| 97 | uint32_t from_; |
| 98 | int32_t to_; |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 99 | }; |
| 100 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 101 | inline 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 | |
| 108 | inline bool operator==(const SrcMapElem& lhs, const SrcMapElem& rhs) { |
| 109 | return lhs.from_ == rhs.from_ && lhs.to_ == rhs.to_; |
| 110 | } |
| 111 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 112 | class LinkerPatch { |
| 113 | public: |
Vladimir Marko | ef88a11 | 2016-03-31 12:34:48 +0100 | [diff] [blame] | 114 | // 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 Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 122 | kMethodRelative, // NOTE: Actual patching is instruction_set-dependent. |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 123 | kMethodBssEntry, // NOTE: Actual patching is instruction_set-dependent. |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 124 | kCall, |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 125 | kCallRelative, // NOTE: Actual patching is instruction_set-dependent. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 126 | kTypeRelative, // NOTE: Actual patching is instruction_set-dependent. |
| 127 | kTypeBssEntry, // NOTE: Actual patching is instruction_set-dependent. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 128 | kStringRelative, // NOTE: Actual patching is instruction_set-dependent. |
| 129 | kStringBssEntry, // NOTE: Actual patching is instruction_set-dependent. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 130 | kBakerReadBarrierBranch, // NOTE: Actual patching is instruction_set-dependent. |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 131 | }; |
| 132 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 133 | static LinkerPatch RelativeMethodPatch(size_t literal_offset, |
| 134 | const DexFile* target_dex_file, |
| 135 | uint32_t pc_insn_offset, |
| 136 | uint32_t target_method_idx) { |
| 137 | LinkerPatch patch(literal_offset, Type::kMethodRelative, target_dex_file); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 138 | patch.method_idx_ = target_method_idx; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 139 | patch.pc_insn_offset_ = pc_insn_offset; |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 140 | return patch; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 141 | } |
| 142 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 143 | static LinkerPatch MethodBssEntryPatch(size_t literal_offset, |
| 144 | const DexFile* target_dex_file, |
| 145 | uint32_t pc_insn_offset, |
| 146 | uint32_t target_method_idx) { |
| 147 | LinkerPatch patch(literal_offset, Type::kMethodBssEntry, target_dex_file); |
| 148 | patch.method_idx_ = target_method_idx; |
| 149 | patch.pc_insn_offset_ = pc_insn_offset; |
| 150 | return patch; |
| 151 | } |
| 152 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 153 | static LinkerPatch CodePatch(size_t literal_offset, |
| 154 | const DexFile* target_dex_file, |
| 155 | uint32_t target_method_idx) { |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 156 | LinkerPatch patch(literal_offset, Type::kCall, target_dex_file); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 157 | patch.method_idx_ = target_method_idx; |
| 158 | return patch; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static LinkerPatch RelativeCodePatch(size_t literal_offset, |
| 162 | const DexFile* target_dex_file, |
| 163 | uint32_t target_method_idx) { |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 164 | LinkerPatch patch(literal_offset, Type::kCallRelative, target_dex_file); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 165 | patch.method_idx_ = target_method_idx; |
| 166 | return patch; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 169 | static LinkerPatch RelativeTypePatch(size_t literal_offset, |
| 170 | const DexFile* target_dex_file, |
| 171 | uint32_t pc_insn_offset, |
| 172 | uint32_t target_type_idx) { |
| 173 | LinkerPatch patch(literal_offset, Type::kTypeRelative, target_dex_file); |
| 174 | patch.type_idx_ = target_type_idx; |
| 175 | patch.pc_insn_offset_ = pc_insn_offset; |
| 176 | return patch; |
| 177 | } |
| 178 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 179 | static LinkerPatch TypeBssEntryPatch(size_t literal_offset, |
| 180 | const DexFile* target_dex_file, |
| 181 | uint32_t pc_insn_offset, |
| 182 | uint32_t target_type_idx) { |
| 183 | LinkerPatch patch(literal_offset, Type::kTypeBssEntry, target_dex_file); |
| 184 | patch.type_idx_ = target_type_idx; |
| 185 | patch.pc_insn_offset_ = pc_insn_offset; |
| 186 | return patch; |
| 187 | } |
| 188 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 189 | static LinkerPatch RelativeStringPatch(size_t literal_offset, |
| 190 | const DexFile* target_dex_file, |
| 191 | uint32_t pc_insn_offset, |
| 192 | uint32_t target_string_idx) { |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 193 | LinkerPatch patch(literal_offset, Type::kStringRelative, target_dex_file); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 194 | patch.string_idx_ = target_string_idx; |
| 195 | patch.pc_insn_offset_ = pc_insn_offset; |
| 196 | return patch; |
| 197 | } |
| 198 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 199 | static LinkerPatch StringBssEntryPatch(size_t literal_offset, |
| 200 | const DexFile* target_dex_file, |
| 201 | uint32_t pc_insn_offset, |
| 202 | uint32_t target_string_idx) { |
| 203 | LinkerPatch patch(literal_offset, Type::kStringBssEntry, target_dex_file); |
| 204 | patch.string_idx_ = target_string_idx; |
| 205 | patch.pc_insn_offset_ = pc_insn_offset; |
| 206 | return patch; |
| 207 | } |
| 208 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 209 | static LinkerPatch BakerReadBarrierBranchPatch(size_t literal_offset, |
| 210 | uint32_t custom_value1 = 0u, |
| 211 | uint32_t custom_value2 = 0u) { |
| 212 | LinkerPatch patch(literal_offset, Type::kBakerReadBarrierBranch, nullptr); |
| 213 | patch.baker_custom_value1_ = custom_value1; |
| 214 | patch.baker_custom_value2_ = custom_value2; |
| 215 | return patch; |
| 216 | } |
| 217 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 218 | LinkerPatch(const LinkerPatch& other) = default; |
| 219 | LinkerPatch& operator=(const LinkerPatch& other) = default; |
| 220 | |
| 221 | size_t LiteralOffset() const { |
| 222 | return literal_offset_; |
| 223 | } |
| 224 | |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 225 | Type GetType() const { |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 226 | return patch_type_; |
| 227 | } |
| 228 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 229 | bool IsPcRelative() const { |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 230 | switch (GetType()) { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 231 | case Type::kMethodRelative: |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 232 | case Type::kMethodBssEntry: |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 233 | case Type::kCallRelative: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 234 | case Type::kTypeRelative: |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 235 | case Type::kTypeBssEntry: |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 236 | case Type::kStringRelative: |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 237 | case Type::kStringBssEntry: |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 238 | case Type::kBakerReadBarrierBranch: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 239 | return true; |
| 240 | default: |
| 241 | return false; |
| 242 | } |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 245 | MethodReference TargetMethod() const { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 246 | DCHECK(patch_type_ == Type::kMethodRelative || |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 247 | patch_type_ == Type::kMethodBssEntry || |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 248 | patch_type_ == Type::kCall || |
| 249 | patch_type_ == Type::kCallRelative); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 250 | return MethodReference(target_dex_file_, method_idx_); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | const DexFile* TargetTypeDexFile() const { |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 254 | DCHECK(patch_type_ == Type::kTypeRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 255 | patch_type_ == Type::kTypeBssEntry); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 256 | return target_dex_file_; |
| 257 | } |
| 258 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 259 | dex::TypeIndex TargetTypeIndex() const { |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 260 | DCHECK(patch_type_ == Type::kTypeRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 261 | patch_type_ == Type::kTypeBssEntry); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 262 | return dex::TypeIndex(type_idx_); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 265 | const DexFile* TargetStringDexFile() const { |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 266 | DCHECK(patch_type_ == Type::kStringRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 267 | patch_type_ == Type::kStringBssEntry); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 268 | return target_dex_file_; |
| 269 | } |
| 270 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 271 | dex::StringIndex TargetStringIndex() const { |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 272 | DCHECK(patch_type_ == Type::kStringRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 273 | patch_type_ == Type::kStringBssEntry); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 274 | return dex::StringIndex(string_idx_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 277 | uint32_t PcInsnOffset() const { |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 278 | DCHECK(patch_type_ == Type::kMethodRelative || |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 279 | patch_type_ == Type::kMethodBssEntry || |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 280 | patch_type_ == Type::kTypeRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 281 | patch_type_ == Type::kTypeBssEntry || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 282 | patch_type_ == Type::kStringRelative || |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 283 | patch_type_ == Type::kStringBssEntry); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 284 | return pc_insn_offset_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 287 | uint32_t GetBakerCustomValue1() const { |
| 288 | DCHECK(patch_type_ == Type::kBakerReadBarrierBranch); |
| 289 | return baker_custom_value1_; |
| 290 | } |
| 291 | |
| 292 | uint32_t GetBakerCustomValue2() const { |
| 293 | DCHECK(patch_type_ == Type::kBakerReadBarrierBranch); |
| 294 | return baker_custom_value2_; |
| 295 | } |
| 296 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 297 | private: |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 298 | LinkerPatch(size_t literal_offset, Type patch_type, const DexFile* target_dex_file) |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 299 | : target_dex_file_(target_dex_file), |
| 300 | literal_offset_(literal_offset), |
| 301 | patch_type_(patch_type) { |
| 302 | cmp1_ = 0u; |
| 303 | cmp2_ = 0u; |
| 304 | // The compiler rejects methods that are too big, so the compiled code |
| 305 | // of a single method really shouln't be anywhere close to 16MiB. |
| 306 | DCHECK(IsUint<24>(literal_offset)); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 307 | } |
| 308 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 309 | const DexFile* target_dex_file_; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 310 | // TODO: Clean up naming. Some patched locations are literals but others are not. |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 311 | uint32_t literal_offset_ : 24; // Method code size up to 16MiB. |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 312 | Type patch_type_ : 8; |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 313 | union { |
| 314 | uint32_t cmp1_; // Used for relational operators. |
| 315 | uint32_t method_idx_; // Method index for Call/Method patches. |
| 316 | uint32_t type_idx_; // Type index for Type patches. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 317 | uint32_t string_idx_; // String index for String patches. |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 318 | uint32_t baker_custom_value1_; |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 319 | static_assert(sizeof(method_idx_) == sizeof(cmp1_), "needed by relational operators"); |
| 320 | static_assert(sizeof(type_idx_) == sizeof(cmp1_), "needed by relational operators"); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 321 | static_assert(sizeof(string_idx_) == sizeof(cmp1_), "needed by relational operators"); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 322 | static_assert(sizeof(baker_custom_value1_) == sizeof(cmp1_), "needed by relational operators"); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 323 | }; |
| 324 | union { |
Vladimir Marko | 34ed3af | 2016-02-04 20:01:32 +0000 | [diff] [blame] | 325 | // Note: To avoid uninitialized padding on 64-bit systems, we use `size_t` for `cmp2_`. |
| 326 | // This allows a hashing function to treat an array of linker patches as raw memory. |
| 327 | size_t cmp2_; // Used for relational operators. |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 328 | // Literal offset of the insn loading PC (same as literal_offset if it's the same insn, |
| 329 | // may be different if the PC-relative addressing needs multiple insns). |
| 330 | uint32_t pc_insn_offset_; |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 331 | uint32_t baker_custom_value2_; |
Vladimir Marko | 34ed3af | 2016-02-04 20:01:32 +0000 | [diff] [blame] | 332 | static_assert(sizeof(pc_insn_offset_) <= sizeof(cmp2_), "needed by relational operators"); |
Vladimir Marko | f4f2daa | 2017-03-20 18:26:59 +0000 | [diff] [blame] | 333 | static_assert(sizeof(baker_custom_value2_) <= sizeof(cmp2_), "needed by relational operators"); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 334 | }; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 335 | |
| 336 | friend bool operator==(const LinkerPatch& lhs, const LinkerPatch& rhs); |
| 337 | friend bool operator<(const LinkerPatch& lhs, const LinkerPatch& rhs); |
| 338 | }; |
Vladimir Marko | db8e62d | 2016-03-30 16:30:21 +0100 | [diff] [blame] | 339 | std::ostream& operator<<(std::ostream& os, const LinkerPatch::Type& type); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 340 | |
| 341 | inline bool operator==(const LinkerPatch& lhs, const LinkerPatch& rhs) { |
| 342 | return lhs.literal_offset_ == rhs.literal_offset_ && |
| 343 | lhs.patch_type_ == rhs.patch_type_ && |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 344 | lhs.target_dex_file_ == rhs.target_dex_file_ && |
| 345 | lhs.cmp1_ == rhs.cmp1_ && |
| 346 | lhs.cmp2_ == rhs.cmp2_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | inline bool operator<(const LinkerPatch& lhs, const LinkerPatch& rhs) { |
| 350 | return (lhs.literal_offset_ != rhs.literal_offset_) ? lhs.literal_offset_ < rhs.literal_offset_ |
| 351 | : (lhs.patch_type_ != rhs.patch_type_) ? lhs.patch_type_ < rhs.patch_type_ |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 352 | : (lhs.target_dex_file_ != rhs.target_dex_file_) ? lhs.target_dex_file_ < rhs.target_dex_file_ |
| 353 | : (lhs.cmp1_ != rhs.cmp1_) ? lhs.cmp1_ < rhs.cmp1_ |
| 354 | : lhs.cmp2_ < rhs.cmp2_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 355 | } |
| 356 | |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 357 | class CompiledMethod FINAL : public CompiledCode { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 358 | public: |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 359 | // Constructs a CompiledMethod. |
| 360 | // Note: Consider using the static allocation methods below that will allocate the CompiledMethod |
| 361 | // in the swap space. |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 362 | CompiledMethod(CompilerDriver* driver, |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 363 | InstructionSet instruction_set, |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 364 | const ArrayRef<const uint8_t>& quick_code, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 365 | const size_t frame_size_in_bytes, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 366 | const uint32_t core_spill_mask, |
| 367 | const uint32_t fp_spill_mask, |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 368 | const ArrayRef<const uint8_t>& method_info, |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 369 | const ArrayRef<const uint8_t>& vmap_table, |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 370 | const ArrayRef<const uint8_t>& cfi_info, |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 371 | const ArrayRef<const LinkerPatch>& patches); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 372 | |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 373 | virtual ~CompiledMethod(); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 374 | |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 375 | static CompiledMethod* SwapAllocCompiledMethod( |
| 376 | CompilerDriver* driver, |
| 377 | InstructionSet instruction_set, |
| 378 | const ArrayRef<const uint8_t>& quick_code, |
| 379 | const size_t frame_size_in_bytes, |
| 380 | const uint32_t core_spill_mask, |
| 381 | const uint32_t fp_spill_mask, |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 382 | const ArrayRef<const uint8_t>& method_info, |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 383 | const ArrayRef<const uint8_t>& vmap_table, |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 384 | const ArrayRef<const uint8_t>& cfi_info, |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 385 | const ArrayRef<const LinkerPatch>& patches); |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 386 | |
| 387 | static void ReleaseSwapAllocatedCompiledMethod(CompilerDriver* driver, CompiledMethod* m); |
| 388 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 389 | size_t GetFrameSizeInBytes() const { |
| 390 | return frame_size_in_bytes_; |
Logan Chien | 110bcba | 2012-04-16 19:11:28 +0800 | [diff] [blame] | 391 | } |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 392 | |
| 393 | uint32_t GetCoreSpillMask() const { |
| 394 | return core_spill_mask_; |
| 395 | } |
| 396 | |
| 397 | uint32_t GetFpSpillMask() const { |
| 398 | return fp_spill_mask_; |
| 399 | } |
| 400 | |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 401 | ArrayRef<const uint8_t> GetMethodInfo() const { |
| 402 | return GetArray(method_info_); |
Yevgeny Rouban | e3ea838 | 2014-08-08 16:29:38 +0700 | [diff] [blame] | 403 | } |
| 404 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 405 | ArrayRef<const uint8_t> GetVmapTable() const { |
| 406 | return GetArray(vmap_table_); |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 409 | ArrayRef<const uint8_t> GetCFIInfo() const { |
| 410 | return GetArray(cfi_info_); |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 411 | } |
| 412 | |
Vladimir Marko | b207e14 | 2015-04-02 21:25:21 +0100 | [diff] [blame] | 413 | ArrayRef<const LinkerPatch> GetPatches() const { |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 414 | return GetArray(patches_); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 415 | } |
| 416 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 417 | private: |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 418 | // For quick code, the size of the activation used by the code. |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 419 | const size_t frame_size_in_bytes_; |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 420 | // For quick code, a bit mask describing spilled GPR callee-save registers. |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 421 | const uint32_t core_spill_mask_; |
Ian Rogers | a182704 | 2013-04-18 16:36:43 -0700 | [diff] [blame] | 422 | // For quick code, a bit mask describing spilled FPR callee-save registers. |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 423 | const uint32_t fp_spill_mask_; |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 424 | // For quick code, method specific information that is not very dedupe friendly (method indices). |
| 425 | const LengthPrefixedArray<uint8_t>* const method_info_; |
| 426 | // For quick code, holds code infos which contain stack maps, inline information, and etc. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 427 | const LengthPrefixedArray<uint8_t>* const vmap_table_; |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 428 | // For quick code, a FDE entry for the debug_frame section. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 429 | const LengthPrefixedArray<uint8_t>* const cfi_info_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 430 | // For quick code, linker patches needed by the method. |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 431 | const LengthPrefixedArray<LinkerPatch>* const patches_; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 432 | }; |
| 433 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 434 | } // namespace art |
| 435 | |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 436 | #endif // ART_COMPILER_COMPILED_METHOD_H_ |