Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | */ |
| 16 | |
| 17 | #ifndef ART_RUNTIME_STACK_MAP_H_ |
| 18 | #define ART_RUNTIME_STACK_MAP_H_ |
| 19 | |
Andreas Gampe | 69489fa | 2017-06-08 18:03:25 -0700 | [diff] [blame] | 20 | #include <limits> |
| 21 | |
David Sehr | 1ce2b3b | 2018-04-05 11:02:03 -0700 | [diff] [blame] | 22 | #include "base/bit_memory_region.h" |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 23 | #include "base/bit_table.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 24 | #include "base/bit_utils.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 25 | #include "base/bit_vector.h" |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 26 | #include "base/leb128.h" |
David Sehr | 1ce2b3b | 2018-04-05 11:02:03 -0700 | [diff] [blame] | 27 | #include "base/memory_region.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 28 | #include "dex/dex_file_types.h" |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 29 | #include "dex_register_location.h" |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 30 | #include "method_info.h" |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 31 | #include "oat_quick_method_header.h" |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 35 | class VariableIndentationOutputStream; |
| 36 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 37 | // Size of a frame slot, in bytes. This constant is a signed value, |
| 38 | // to please the compiler in arithmetic operations involving int32_t |
| 39 | // (signed) values. |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 40 | static constexpr ssize_t kFrameSlotSize = 4; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 41 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 42 | class ArtMethod; |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 43 | class CodeInfo; |
| 44 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 45 | std::ostream& operator<<(std::ostream& stream, const DexRegisterLocation& reg); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 46 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 47 | // Information on Dex register locations for a specific PC. |
| 48 | // Effectively just a convenience wrapper for DexRegisterLocation vector. |
| 49 | // If the size is small enough, it keeps the data on the stack. |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 50 | class DexRegisterMap { |
| 51 | public: |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 52 | // Create map for given number of registers and initialize all locations to None. |
| 53 | explicit DexRegisterMap(size_t count) : count_(count), regs_small_{} { |
| 54 | if (count_ <= kSmallCount) { |
| 55 | std::fill_n(regs_small_.begin(), count, DexRegisterLocation::None()); |
| 56 | } else { |
| 57 | regs_large_.resize(count, DexRegisterLocation::None()); |
| 58 | } |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 59 | } |
| 60 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 61 | DexRegisterLocation* data() { |
| 62 | return count_ <= kSmallCount ? regs_small_.data() : regs_large_.data(); |
| 63 | } |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 64 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 65 | size_t size() const { return count_; } |
| 66 | |
| 67 | bool IsValid() const { return count_ != 0; } |
| 68 | |
| 69 | DexRegisterLocation Get(size_t index) const { |
| 70 | DCHECK_LT(index, count_); |
| 71 | return count_ <= kSmallCount ? regs_small_[index] : regs_large_[index]; |
| 72 | } |
| 73 | |
| 74 | DexRegisterLocation::Kind GetLocationKind(uint16_t dex_register_number) const { |
| 75 | return Get(dex_register_number).GetKind(); |
| 76 | } |
| 77 | |
| 78 | // TODO: Remove. |
| 79 | DexRegisterLocation::Kind GetLocationInternalKind(uint16_t dex_register_number) const { |
| 80 | return Get(dex_register_number).GetKind(); |
| 81 | } |
| 82 | |
| 83 | DexRegisterLocation GetDexRegisterLocation(uint16_t dex_register_number) const { |
| 84 | return Get(dex_register_number); |
| 85 | } |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 86 | |
David Srbecky | 21d45b4 | 2018-05-30 06:35:05 +0100 | [diff] [blame] | 87 | int32_t GetStackOffsetInBytes(uint16_t dex_register_number) const { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 88 | DexRegisterLocation location = Get(dex_register_number); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 89 | DCHECK(location.GetKind() == DexRegisterLocation::Kind::kInStack); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 90 | return location.GetValue(); |
| 91 | } |
| 92 | |
David Srbecky | 21d45b4 | 2018-05-30 06:35:05 +0100 | [diff] [blame] | 93 | int32_t GetConstant(uint16_t dex_register_number) const { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 94 | DexRegisterLocation location = Get(dex_register_number); |
| 95 | DCHECK(location.GetKind() == DexRegisterLocation::Kind::kConstant); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 96 | return location.GetValue(); |
| 97 | } |
| 98 | |
David Srbecky | 21d45b4 | 2018-05-30 06:35:05 +0100 | [diff] [blame] | 99 | int32_t GetMachineRegister(uint16_t dex_register_number) const { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 100 | DexRegisterLocation location = Get(dex_register_number); |
| 101 | DCHECK(location.GetKind() == DexRegisterLocation::Kind::kInRegister || |
| 102 | location.GetKind() == DexRegisterLocation::Kind::kInRegisterHigh || |
| 103 | location.GetKind() == DexRegisterLocation::Kind::kInFpuRegister || |
| 104 | location.GetKind() == DexRegisterLocation::Kind::kInFpuRegisterHigh); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 105 | return location.GetValue(); |
| 106 | } |
| 107 | |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 108 | ALWAYS_INLINE bool IsDexRegisterLive(uint16_t dex_register_number) const { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 109 | return Get(dex_register_number).IsLive(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 110 | } |
| 111 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 112 | size_t GetNumberOfLiveDexRegisters() const { |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 113 | size_t number_of_live_dex_registers = 0; |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 114 | for (size_t i = 0; i < count_; ++i) { |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 115 | if (IsDexRegisterLive(i)) { |
| 116 | ++number_of_live_dex_registers; |
| 117 | } |
| 118 | } |
| 119 | return number_of_live_dex_registers; |
| 120 | } |
| 121 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 122 | bool HasAnyLiveDexRegisters() const { |
| 123 | for (size_t i = 0; i < count_; ++i) { |
| 124 | if (IsDexRegisterLive(i)) { |
| 125 | return true; |
| 126 | } |
| 127 | } |
| 128 | return false; |
David Srbecky | 21d45b4 | 2018-05-30 06:35:05 +0100 | [diff] [blame] | 129 | } |
| 130 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 131 | private: |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 132 | // Store the data inline if the number of registers is small to avoid memory allocations. |
| 133 | // If count_ <= kSmallCount, we use the regs_small_ array, and regs_large_ otherwise. |
| 134 | static constexpr size_t kSmallCount = 16; |
| 135 | size_t count_; |
| 136 | std::array<DexRegisterLocation, kSmallCount> regs_small_; |
| 137 | dchecked_vector<DexRegisterLocation> regs_large_; |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 140 | /** |
| 141 | * A Stack Map holds compilation information for a specific PC necessary for: |
| 142 | * - Mapping it to a dex PC, |
| 143 | * - Knowing which stack entries are objects, |
| 144 | * - Knowing which registers hold objects, |
| 145 | * - Knowing the inlining information, |
| 146 | * - Knowing the values of dex registers. |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 147 | */ |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 148 | class StackMap : public BitTable<7>::Accessor { |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 149 | public: |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 150 | enum Field { |
David Srbecky | d02b23f | 2018-05-29 23:27:22 +0100 | [diff] [blame] | 151 | kPackedNativePc, |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 152 | kDexPc, |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 153 | kRegisterMaskIndex, |
| 154 | kStackMaskIndex, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 155 | kInlineInfoIndex, |
| 156 | kDexRegisterMaskIndex, |
| 157 | kDexRegisterMapIndex, |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 158 | kCount, |
| 159 | }; |
Nicolas Geoffray | e12997f | 2015-05-22 14:01:33 +0100 | [diff] [blame] | 160 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 161 | StackMap() : BitTable<kCount>::Accessor(nullptr, -1) {} |
| 162 | StackMap(const BitTable<kCount>* table, uint32_t row) |
| 163 | : BitTable<kCount>::Accessor(table, row) {} |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 164 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 165 | ALWAYS_INLINE uint32_t GetNativePcOffset(InstructionSet instruction_set) const { |
David Srbecky | d02b23f | 2018-05-29 23:27:22 +0100 | [diff] [blame] | 166 | return UnpackNativePc(Get<kPackedNativePc>(), instruction_set); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 167 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 168 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 169 | uint32_t GetDexPc() const { return Get<kDexPc>(); } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 170 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 171 | uint32_t GetDexRegisterMaskIndex() const { return Get<kDexRegisterMaskIndex>(); } |
| 172 | |
| 173 | uint32_t GetDexRegisterMapIndex() const { return Get<kDexRegisterMapIndex>(); } |
| 174 | bool HasDexRegisterMap() const { return GetDexRegisterMapIndex() != kNoValue; } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 175 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 176 | uint32_t GetInlineInfoIndex() const { return Get<kInlineInfoIndex>(); } |
| 177 | bool HasInlineInfo() const { return GetInlineInfoIndex() != kNoValue; } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 178 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 179 | uint32_t GetRegisterMaskIndex() const { return Get<kRegisterMaskIndex>(); } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 180 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 181 | uint32_t GetStackMaskIndex() const { return Get<kStackMaskIndex>(); } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 182 | |
David Srbecky | d02b23f | 2018-05-29 23:27:22 +0100 | [diff] [blame] | 183 | static uint32_t PackNativePc(uint32_t native_pc, InstructionSet isa) { |
David Srbecky | d775f96 | 2018-05-30 18:12:52 +0100 | [diff] [blame] | 184 | DCHECK_ALIGNED_PARAM(native_pc, GetInstructionSetInstructionAlignment(isa)); |
David Srbecky | d02b23f | 2018-05-29 23:27:22 +0100 | [diff] [blame] | 185 | return native_pc / GetInstructionSetInstructionAlignment(isa); |
| 186 | } |
| 187 | |
| 188 | static uint32_t UnpackNativePc(uint32_t packed_native_pc, InstructionSet isa) { |
| 189 | uint32_t native_pc = packed_native_pc * GetInstructionSetInstructionAlignment(isa); |
| 190 | DCHECK_EQ(native_pc / GetInstructionSetInstructionAlignment(isa), packed_native_pc); |
| 191 | return native_pc; |
| 192 | } |
| 193 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 194 | void Dump(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 195 | const CodeInfo& code_info, |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 196 | const MethodInfo& method_info, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 197 | uint32_t code_offset, |
| 198 | uint16_t number_of_dex_registers, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 199 | InstructionSet instruction_set) const; |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 202 | /** |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 203 | * Inline information for a specific PC. |
| 204 | * The row referenced from the StackMap holds information at depth 0. |
| 205 | * Following rows hold information for further depths. |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 206 | */ |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 207 | class InlineInfo : public BitTable<7>::Accessor { |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 208 | public: |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 209 | enum Field { |
| 210 | kIsLast, // Determines if there are further rows for further depths. |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 211 | kDexPc, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 212 | kMethodIndexIdx, |
| 213 | kArtMethodHi, // High bits of ArtMethod*. |
| 214 | kArtMethodLo, // Low bits of ArtMethod*. |
| 215 | kDexRegisterMaskIndex, |
| 216 | kDexRegisterMapIndex, |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 217 | kCount, |
| 218 | }; |
| 219 | static constexpr uint32_t kLast = -1; |
| 220 | static constexpr uint32_t kMore = 0; |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 221 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 222 | InlineInfo(const BitTable<kCount>* table, uint32_t row) |
| 223 | : BitTable<kCount>::Accessor(table, row) {} |
| 224 | |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 225 | uint32_t GetIsLast() const { return Get<kIsLast>(); } |
| 226 | |
| 227 | uint32_t GetMethodIndexIdx() const { |
| 228 | DCHECK(!EncodesArtMethod()); |
| 229 | return Get<kMethodIndexIdx>(); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 230 | } |
| 231 | |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 232 | uint32_t GetMethodIndex(const MethodInfo& method_info) const { |
| 233 | return method_info.GetMethodIndex(GetMethodIndexIdx()); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 234 | } |
| 235 | |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 236 | uint32_t GetDexPc() const { |
| 237 | return Get<kDexPc>(); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 238 | } |
| 239 | |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 240 | bool EncodesArtMethod() const { |
| 241 | return Get<kArtMethodLo>() != kNoValue; |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 242 | } |
| 243 | |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 244 | ArtMethod* GetArtMethod() const { |
| 245 | uint64_t lo = Get<kArtMethodLo>(); |
| 246 | uint64_t hi = Get<kArtMethodHi>(); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 247 | return reinterpret_cast<ArtMethod*>((hi << 32) | lo); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 248 | } |
| 249 | |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 250 | uint32_t GetDexRegisterMaskIndex() const { |
| 251 | return Get<kDexRegisterMaskIndex>(); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 252 | } |
| 253 | |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 254 | uint32_t GetDexRegisterMapIndex() const { |
| 255 | return Get<kDexRegisterMapIndex>(); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 256 | } |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 257 | bool HasDexRegisterMap() const { |
| 258 | return GetDexRegisterMapIndex() != kNoValue; |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 261 | void Dump(VariableIndentationOutputStream* vios, |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 262 | const CodeInfo& info, |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 263 | const StackMap& stack_map, |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 264 | const MethodInfo& method_info, |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 265 | uint16_t number_of_dex_registers) const; |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 266 | }; |
| 267 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 268 | class InvokeInfo : public BitTable<3>::Accessor { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 269 | public: |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 270 | enum Field { |
David Srbecky | d02b23f | 2018-05-29 23:27:22 +0100 | [diff] [blame] | 271 | kPackedNativePc, |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 272 | kInvokeType, |
| 273 | kMethodIndexIdx, |
| 274 | kCount, |
| 275 | }; |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 276 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 277 | InvokeInfo(const BitTable<kCount>* table, uint32_t row) |
| 278 | : BitTable<kCount>::Accessor(table, row) {} |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 279 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 280 | ALWAYS_INLINE uint32_t GetNativePcOffset(InstructionSet instruction_set) const { |
David Srbecky | d02b23f | 2018-05-29 23:27:22 +0100 | [diff] [blame] | 281 | return StackMap::UnpackNativePc(Get<kPackedNativePc>(), instruction_set); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 282 | } |
| 283 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 284 | uint32_t GetInvokeType() const { return Get<kInvokeType>(); } |
| 285 | |
| 286 | uint32_t GetMethodIndexIdx() const { return Get<kMethodIndexIdx>(); } |
| 287 | |
| 288 | uint32_t GetMethodIndex(MethodInfo method_info) const { |
| 289 | return method_info.GetMethodIndex(GetMethodIndexIdx()); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 290 | } |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 291 | }; |
| 292 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 293 | class DexRegisterInfo : public BitTable<2>::Accessor { |
| 294 | public: |
| 295 | enum Field { |
| 296 | kKind, |
| 297 | kPackedValue, |
| 298 | kCount, |
| 299 | }; |
| 300 | |
| 301 | DexRegisterInfo(const BitTable<kCount>* table, uint32_t row) |
| 302 | : BitTable<kCount>::Accessor(table, row) {} |
| 303 | |
| 304 | ALWAYS_INLINE DexRegisterLocation GetLocation() const { |
| 305 | DexRegisterLocation::Kind kind = static_cast<DexRegisterLocation::Kind>(Get<kKind>()); |
| 306 | return DexRegisterLocation(kind, UnpackValue(kind, Get<kPackedValue>())); |
| 307 | } |
| 308 | |
| 309 | static uint32_t PackValue(DexRegisterLocation::Kind kind, uint32_t value) { |
| 310 | uint32_t packed_value = value; |
| 311 | if (kind == DexRegisterLocation::Kind::kInStack) { |
| 312 | DCHECK(IsAligned<kFrameSlotSize>(packed_value)); |
| 313 | packed_value /= kFrameSlotSize; |
| 314 | } |
| 315 | return packed_value; |
| 316 | } |
| 317 | |
| 318 | static uint32_t UnpackValue(DexRegisterLocation::Kind kind, uint32_t packed_value) { |
| 319 | uint32_t value = packed_value; |
| 320 | if (kind == DexRegisterLocation::Kind::kInStack) { |
| 321 | value *= kFrameSlotSize; |
| 322 | } |
| 323 | return value; |
| 324 | } |
| 325 | }; |
| 326 | |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 327 | // Register masks tend to have many trailing zero bits (caller-saves are usually not encoded), |
| 328 | // therefore it is worth encoding the mask as value+shift. |
| 329 | class RegisterMask : public BitTable<2>::Accessor { |
| 330 | public: |
| 331 | enum Field { |
| 332 | kValue, |
| 333 | kShift, |
| 334 | kCount, |
| 335 | }; |
| 336 | |
| 337 | RegisterMask(const BitTable<kCount>* table, uint32_t row) |
| 338 | : BitTable<kCount>::Accessor(table, row) {} |
| 339 | |
| 340 | ALWAYS_INLINE uint32_t GetMask() const { |
| 341 | return Get<kValue>() << Get<kShift>(); |
| 342 | } |
| 343 | }; |
| 344 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 345 | /** |
| 346 | * Wrapper around all compiler information collected for a method. |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 347 | * See the Decode method at the end for the precise binary format. |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 348 | */ |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 349 | class CodeInfo { |
| 350 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 351 | explicit CodeInfo(const void* data) { |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 352 | Decode(reinterpret_cast<const uint8_t*>(data)); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 353 | } |
| 354 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 355 | explicit CodeInfo(MemoryRegion region) : CodeInfo(region.begin()) { |
| 356 | DCHECK_EQ(size_, region.size()); |
Nicolas Geoffray | 896f8f7 | 2015-03-30 15:44:25 +0100 | [diff] [blame] | 357 | } |
| 358 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 359 | explicit CodeInfo(const OatQuickMethodHeader* header) |
| 360 | : CodeInfo(header->GetOptimizedCodeInfoPtr()) { |
Nicolas Geoffray | 896f8f7 | 2015-03-30 15:44:25 +0100 | [diff] [blame] | 361 | } |
| 362 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 363 | size_t Size() const { |
| 364 | return size_; |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 365 | } |
| 366 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 367 | bool HasInlineInfo() const { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 368 | return inline_infos_.NumRows() > 0; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 369 | } |
| 370 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 371 | ALWAYS_INLINE StackMap GetStackMapAt(size_t index) const { |
| 372 | return StackMap(&stack_maps_, index); |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 373 | } |
| 374 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 375 | BitMemoryRegion GetStackMask(size_t index) const { |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 376 | return stack_masks_.GetBitMemoryRegion(index); |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 377 | } |
| 378 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 379 | BitMemoryRegion GetStackMaskOf(const StackMap& stack_map) const { |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 380 | uint32_t index = stack_map.GetStackMaskIndex(); |
| 381 | return (index == StackMap::kNoValue) ? BitMemoryRegion() : GetStackMask(index); |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 382 | } |
| 383 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 384 | uint32_t GetRegisterMaskOf(const StackMap& stack_map) const { |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 385 | uint32_t index = stack_map.GetRegisterMaskIndex(); |
| 386 | return (index == StackMap::kNoValue) ? 0 : RegisterMask(®ister_masks_, index).GetMask(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 387 | } |
| 388 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 389 | uint32_t GetNumberOfLocationCatalogEntries() const { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 390 | return dex_register_catalog_.NumRows(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 391 | } |
| 392 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 393 | ALWAYS_INLINE DexRegisterLocation GetDexRegisterCatalogEntry(size_t index) const { |
| 394 | return DexRegisterInfo(&dex_register_catalog_, index).GetLocation(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 395 | } |
| 396 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 397 | uint32_t GetNumberOfStackMaps() const { |
| 398 | return stack_maps_.NumRows(); |
Nicolas Geoffray | 6530baf | 2015-05-26 15:22:58 +0100 | [diff] [blame] | 399 | } |
| 400 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 401 | InvokeInfo GetInvokeInfo(size_t index) const { |
| 402 | return InvokeInfo(&invoke_infos_, index); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 403 | } |
| 404 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 405 | ALWAYS_INLINE DexRegisterMap GetDexRegisterMapOf(StackMap stack_map, |
| 406 | size_t num_dex_registers) const { |
| 407 | return DecodeDexRegisterMap(stack_map.GetDexRegisterMaskIndex(), |
| 408 | stack_map.GetDexRegisterMapIndex(), |
| 409 | num_dex_registers); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 410 | } |
| 411 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 412 | ALWAYS_INLINE DexRegisterMap GetDexRegisterMapAtDepth(uint8_t depth, |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 413 | StackMap stack_map, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 414 | size_t num_dex_registers) const { |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 415 | InlineInfo inline_info = GetInlineInfoAtDepth(stack_map, depth); |
| 416 | return DecodeDexRegisterMap(inline_info.GetDexRegisterMaskIndex(), |
| 417 | inline_info.GetDexRegisterMapIndex(), |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 418 | num_dex_registers); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 419 | } |
| 420 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 421 | InlineInfo GetInlineInfo(size_t index) const { |
| 422 | return InlineInfo(&inline_infos_, index); |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 423 | } |
| 424 | |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 425 | uint32_t GetInlineDepthOf(StackMap stack_map) const { |
| 426 | uint32_t depth = 0; |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 427 | uint32_t index = stack_map.GetInlineInfoIndex(); |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame^] | 428 | if (index != StackMap::kNoValue) { |
| 429 | while (GetInlineInfo(index + depth++).GetIsLast() == InlineInfo::kMore) { } |
| 430 | } |
| 431 | return depth; |
| 432 | } |
| 433 | |
| 434 | InlineInfo GetInlineInfoAtDepth(StackMap stack_map, uint32_t depth) const { |
| 435 | DCHECK(stack_map.HasInlineInfo()); |
| 436 | DCHECK_LT(depth, GetInlineDepthOf(stack_map)); |
| 437 | return GetInlineInfo(stack_map.GetInlineInfoIndex() + depth); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 438 | } |
| 439 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 440 | StackMap GetStackMapForDexPc(uint32_t dex_pc) const { |
| 441 | for (size_t i = 0, e = GetNumberOfStackMaps(); i < e; ++i) { |
| 442 | StackMap stack_map = GetStackMapAt(i); |
| 443 | if (stack_map.GetDexPc() == dex_pc) { |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 444 | return stack_map; |
| 445 | } |
| 446 | } |
Nicolas Geoffray | e12997f | 2015-05-22 14:01:33 +0100 | [diff] [blame] | 447 | return StackMap(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 448 | } |
| 449 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 450 | // Searches the stack map list backwards because catch stack maps are stored |
| 451 | // at the end. |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 452 | StackMap GetCatchStackMapForDexPc(uint32_t dex_pc) const { |
| 453 | for (size_t i = GetNumberOfStackMaps(); i > 0; --i) { |
| 454 | StackMap stack_map = GetStackMapAt(i - 1); |
| 455 | if (stack_map.GetDexPc() == dex_pc) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 456 | return stack_map; |
| 457 | } |
| 458 | } |
| 459 | return StackMap(); |
| 460 | } |
| 461 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 462 | StackMap GetOsrStackMapForDexPc(uint32_t dex_pc) const { |
| 463 | size_t e = GetNumberOfStackMaps(); |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 464 | if (e == 0) { |
| 465 | // There cannot be OSR stack map if there is no stack map. |
| 466 | return StackMap(); |
| 467 | } |
| 468 | // Walk over all stack maps. If two consecutive stack maps are identical, then we |
| 469 | // have found a stack map suitable for OSR. |
| 470 | for (size_t i = 0; i < e - 1; ++i) { |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 471 | StackMap stack_map = GetStackMapAt(i); |
| 472 | if (stack_map.GetDexPc() == dex_pc) { |
| 473 | StackMap other = GetStackMapAt(i + 1); |
| 474 | if (other.GetDexPc() == dex_pc && |
| 475 | other.GetNativePcOffset(kRuntimeISA) == |
| 476 | stack_map.GetNativePcOffset(kRuntimeISA)) { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 477 | DCHECK_EQ(other.GetDexRegisterMapIndex(), |
| 478 | stack_map.GetDexRegisterMapIndex()); |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 479 | if (i < e - 2) { |
| 480 | // Make sure there are not three identical stack maps following each other. |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 481 | DCHECK_NE( |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 482 | stack_map.GetNativePcOffset(kRuntimeISA), |
| 483 | GetStackMapAt(i + 2).GetNativePcOffset(kRuntimeISA)); |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 484 | } |
| 485 | return stack_map; |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | return StackMap(); |
| 490 | } |
| 491 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 492 | StackMap GetStackMapForNativePcOffset(uint32_t native_pc_offset) const { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 493 | // TODO: Safepoint stack maps are sorted by native_pc_offset but catch stack |
| 494 | // maps are not. If we knew that the method does not have try/catch, |
| 495 | // we could do binary search. |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 496 | for (size_t i = 0, e = GetNumberOfStackMaps(); i < e; ++i) { |
| 497 | StackMap stack_map = GetStackMapAt(i); |
| 498 | if (stack_map.GetNativePcOffset(kRuntimeISA) == native_pc_offset) { |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 499 | return stack_map; |
| 500 | } |
| 501 | } |
Nicolas Geoffray | e12997f | 2015-05-22 14:01:33 +0100 | [diff] [blame] | 502 | return StackMap(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 503 | } |
| 504 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 505 | InvokeInfo GetInvokeInfoForNativePcOffset(uint32_t native_pc_offset) { |
| 506 | for (size_t index = 0; index < invoke_infos_.NumRows(); index++) { |
| 507 | InvokeInfo item = GetInvokeInfo(index); |
| 508 | if (item.GetNativePcOffset(kRuntimeISA) == native_pc_offset) { |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 509 | return item; |
| 510 | } |
| 511 | } |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 512 | return InvokeInfo(&invoke_infos_, -1); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 513 | } |
| 514 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 515 | // Dump this CodeInfo object on `vios`. |
| 516 | // `code_offset` is the (absolute) native PC of the compiled method. |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 517 | void Dump(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 518 | uint32_t code_offset, |
| 519 | uint16_t number_of_dex_registers, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 520 | bool verbose, |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 521 | InstructionSet instruction_set, |
| 522 | const MethodInfo& method_info) const; |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 523 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 524 | private: |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 525 | ALWAYS_INLINE DexRegisterMap DecodeDexRegisterMap(uint32_t mask_index, |
| 526 | uint32_t map_index, |
| 527 | uint32_t num_dex_registers) const { |
| 528 | DexRegisterMap map(map_index == StackMap::kNoValue ? 0 : num_dex_registers); |
| 529 | if (mask_index != StackMap::kNoValue) { |
| 530 | BitMemoryRegion mask = dex_register_masks_.GetBitMemoryRegion(mask_index); |
| 531 | num_dex_registers = std::min<uint32_t>(num_dex_registers, mask.size_in_bits()); |
| 532 | DexRegisterLocation* regs = map.data(); |
| 533 | for (uint32_t r = 0; r < mask.size_in_bits(); r++) { |
| 534 | if (mask.LoadBit(r) /* is_live */) { |
| 535 | DCHECK_LT(r, map.size()); |
| 536 | regs[r] = GetDexRegisterCatalogEntry(dex_register_maps_.Get(map_index++)); |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | return map; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 541 | } |
| 542 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 543 | void Decode(const uint8_t* data) { |
| 544 | size_t non_header_size = DecodeUnsignedLeb128(&data); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 545 | BitMemoryRegion region(MemoryRegion(const_cast<uint8_t*>(data), non_header_size)); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 546 | size_t bit_offset = 0; |
| 547 | size_ = UnsignedLeb128Size(non_header_size) + non_header_size; |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 548 | stack_maps_.Decode(region, &bit_offset); |
| 549 | register_masks_.Decode(region, &bit_offset); |
| 550 | stack_masks_.Decode(region, &bit_offset); |
| 551 | invoke_infos_.Decode(region, &bit_offset); |
| 552 | inline_infos_.Decode(region, &bit_offset); |
| 553 | dex_register_masks_.Decode(region, &bit_offset); |
| 554 | dex_register_maps_.Decode(region, &bit_offset); |
| 555 | dex_register_catalog_.Decode(region, &bit_offset); |
| 556 | CHECK_EQ(non_header_size, BitsToBytesRoundUp(bit_offset)) << "Invalid CodeInfo"; |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | size_t size_; |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 560 | BitTable<StackMap::Field::kCount> stack_maps_; |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 561 | BitTable<RegisterMask::Field::kCount> register_masks_; |
| 562 | BitTable<1> stack_masks_; |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 563 | BitTable<InvokeInfo::Field::kCount> invoke_infos_; |
| 564 | BitTable<InlineInfo::Field::kCount> inline_infos_; |
| 565 | BitTable<1> dex_register_masks_; |
| 566 | BitTable<1> dex_register_maps_; |
| 567 | BitTable<DexRegisterInfo::Field::kCount> dex_register_catalog_; |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 568 | |
| 569 | friend class OatDumper; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 570 | }; |
| 571 | |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 572 | #undef ELEMENT_BYTE_OFFSET_AFTER |
| 573 | #undef ELEMENT_BIT_OFFSET_AFTER |
| 574 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 575 | } // namespace art |
| 576 | |
| 577 | #endif // ART_RUNTIME_STACK_MAP_H_ |