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 Srbecky | f6ba5b3 | 2018-06-23 22:05:49 +0100 | [diff] [blame] | 22 | #include "arch/instruction_set.h" |
David Sehr | 1ce2b3b | 2018-04-05 11:02:03 -0700 | [diff] [blame] | 23 | #include "base/bit_memory_region.h" |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 24 | #include "base/bit_table.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 25 | #include "base/bit_utils.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 26 | #include "base/bit_vector.h" |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 27 | #include "base/leb128.h" |
David Sehr | 1ce2b3b | 2018-04-05 11:02:03 -0700 | [diff] [blame] | 28 | #include "base/memory_region.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 29 | #include "dex/dex_file_types.h" |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 30 | #include "dex_register_location.h" |
David Srbecky | f6ba5b3 | 2018-06-23 22:05:49 +0100 | [diff] [blame] | 31 | #include "quick/quick_method_frame_info.h" |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | |
David Srbecky | f6ba5b3 | 2018-06-23 22:05:49 +0100 | [diff] [blame] | 35 | class OatQuickMethodHeader; |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 36 | class VariableIndentationOutputStream; |
| 37 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 38 | // Size of a frame slot, in bytes. This constant is a signed value, |
| 39 | // to please the compiler in arithmetic operations involving int32_t |
| 40 | // (signed) values. |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 41 | static constexpr ssize_t kFrameSlotSize = 4; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 42 | |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 43 | // The delta compression of dex register maps means we need to scan the stackmaps backwards. |
| 44 | // We compress the data in such a way so that there is an upper bound on the search distance. |
| 45 | // Max distance 0 means each stack map must be fully defined and no scanning back is allowed. |
| 46 | // If this value is changed, the oat file version should be incremented (for DCHECK to pass). |
| 47 | static constexpr size_t kMaxDexRegisterMapSearchDistance = 32; |
| 48 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 49 | class ArtMethod; |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 50 | class CodeInfo; |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 51 | class Stats; |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 52 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 53 | std::ostream& operator<<(std::ostream& stream, const DexRegisterLocation& reg); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 54 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 55 | // Information on Dex register locations for a specific PC. |
| 56 | // Effectively just a convenience wrapper for DexRegisterLocation vector. |
| 57 | // If the size is small enough, it keeps the data on the stack. |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 58 | // TODO: Replace this with generic purpose "small-vector" implementation. |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 59 | class DexRegisterMap { |
| 60 | public: |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 61 | using iterator = DexRegisterLocation*; |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 62 | using const_iterator = const DexRegisterLocation*; |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 63 | |
| 64 | // Create map for given number of registers and initialize them to the given value. |
| 65 | DexRegisterMap(size_t count, DexRegisterLocation value) : count_(count), regs_small_{} { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 66 | if (count_ <= kSmallCount) { |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 67 | std::fill_n(regs_small_.begin(), count, value); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 68 | } else { |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 69 | regs_large_.resize(count, value); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 70 | } |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 71 | } |
| 72 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 73 | DexRegisterLocation* data() { |
| 74 | return count_ <= kSmallCount ? regs_small_.data() : regs_large_.data(); |
| 75 | } |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 76 | const DexRegisterLocation* data() const { |
| 77 | return count_ <= kSmallCount ? regs_small_.data() : regs_large_.data(); |
| 78 | } |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 79 | |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 80 | iterator begin() { return data(); } |
| 81 | iterator end() { return data() + count_; } |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 82 | const_iterator begin() const { return data(); } |
| 83 | const_iterator end() const { return data() + count_; } |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 84 | size_t size() const { return count_; } |
David Srbecky | fd89b07 | 2018-06-03 12:00:22 +0100 | [diff] [blame] | 85 | bool empty() const { return count_ == 0; } |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 86 | |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 87 | DexRegisterLocation& operator[](size_t index) { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 88 | DCHECK_LT(index, count_); |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 89 | return data()[index]; |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 90 | } |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 91 | const DexRegisterLocation& operator[](size_t index) const { |
| 92 | DCHECK_LT(index, count_); |
| 93 | return data()[index]; |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 94 | } |
| 95 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 96 | size_t GetNumberOfLiveDexRegisters() const { |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 97 | return std::count_if(begin(), end(), [](auto& loc) { return loc.IsLive(); }); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 98 | } |
| 99 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 100 | bool HasAnyLiveDexRegisters() const { |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 101 | return std::any_of(begin(), end(), [](auto& loc) { return loc.IsLive(); }); |
David Srbecky | 21d45b4 | 2018-05-30 06:35:05 +0100 | [diff] [blame] | 102 | } |
| 103 | |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 104 | void Dump(VariableIndentationOutputStream* vios) const; |
| 105 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 106 | private: |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 107 | // Store the data inline if the number of registers is small to avoid memory allocations. |
| 108 | // If count_ <= kSmallCount, we use the regs_small_ array, and regs_large_ otherwise. |
| 109 | static constexpr size_t kSmallCount = 16; |
| 110 | size_t count_; |
| 111 | std::array<DexRegisterLocation, kSmallCount> regs_small_; |
| 112 | dchecked_vector<DexRegisterLocation> regs_large_; |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 115 | /** |
| 116 | * A Stack Map holds compilation information for a specific PC necessary for: |
| 117 | * - Mapping it to a dex PC, |
| 118 | * - Knowing which stack entries are objects, |
| 119 | * - Knowing which registers hold objects, |
| 120 | * - Knowing the inlining information, |
| 121 | * - Knowing the values of dex registers. |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 122 | */ |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 123 | class StackMap : public BitTableAccessor<8> { |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 124 | public: |
David Srbecky | 50fac06 | 2018-06-13 18:55:35 +0100 | [diff] [blame] | 125 | enum Kind { |
| 126 | Default = -1, |
| 127 | Catch = 0, |
| 128 | OSR = 1, |
| 129 | Debug = 2, |
| 130 | }; |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 131 | BIT_TABLE_HEADER(StackMap) |
David Srbecky | 50fac06 | 2018-06-13 18:55:35 +0100 | [diff] [blame] | 132 | BIT_TABLE_COLUMN(0, Kind) |
| 133 | BIT_TABLE_COLUMN(1, PackedNativePc) |
| 134 | BIT_TABLE_COLUMN(2, DexPc) |
| 135 | BIT_TABLE_COLUMN(3, RegisterMaskIndex) |
| 136 | BIT_TABLE_COLUMN(4, StackMaskIndex) |
| 137 | BIT_TABLE_COLUMN(5, InlineInfoIndex) |
| 138 | BIT_TABLE_COLUMN(6, DexRegisterMaskIndex) |
| 139 | BIT_TABLE_COLUMN(7, DexRegisterMapIndex) |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 140 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 141 | ALWAYS_INLINE uint32_t GetNativePcOffset(InstructionSet instruction_set) const { |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 142 | return UnpackNativePc(GetPackedNativePc(), instruction_set); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 143 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 144 | |
David Srbecky | d97e082 | 2018-06-03 12:00:24 +0100 | [diff] [blame] | 145 | ALWAYS_INLINE bool HasInlineInfo() const { |
| 146 | return HasInlineInfoIndex(); |
| 147 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 148 | |
David Srbecky | d97e082 | 2018-06-03 12:00:24 +0100 | [diff] [blame] | 149 | ALWAYS_INLINE bool HasDexRegisterMap() const { |
| 150 | return HasDexRegisterMapIndex(); |
| 151 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 152 | |
David Srbecky | d02b23f | 2018-05-29 23:27:22 +0100 | [diff] [blame] | 153 | static uint32_t PackNativePc(uint32_t native_pc, InstructionSet isa) { |
David Srbecky | d775f96 | 2018-05-30 18:12:52 +0100 | [diff] [blame] | 154 | DCHECK_ALIGNED_PARAM(native_pc, GetInstructionSetInstructionAlignment(isa)); |
David Srbecky | d02b23f | 2018-05-29 23:27:22 +0100 | [diff] [blame] | 155 | return native_pc / GetInstructionSetInstructionAlignment(isa); |
| 156 | } |
| 157 | |
| 158 | static uint32_t UnpackNativePc(uint32_t packed_native_pc, InstructionSet isa) { |
| 159 | uint32_t native_pc = packed_native_pc * GetInstructionSetInstructionAlignment(isa); |
| 160 | DCHECK_EQ(native_pc / GetInstructionSetInstructionAlignment(isa), packed_native_pc); |
| 161 | return native_pc; |
| 162 | } |
| 163 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 164 | void Dump(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 165 | const CodeInfo& code_info, |
| 166 | uint32_t code_offset, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 167 | InstructionSet instruction_set) const; |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 170 | /** |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 171 | * Inline information for a specific PC. |
| 172 | * The row referenced from the StackMap holds information at depth 0. |
| 173 | * Following rows hold information for further depths. |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 174 | */ |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 175 | class InlineInfo : public BitTableAccessor<6> { |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 176 | public: |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 177 | BIT_TABLE_HEADER(InlineInfo) |
David Srbecky | d97e082 | 2018-06-03 12:00:24 +0100 | [diff] [blame] | 178 | BIT_TABLE_COLUMN(0, IsLast) // Determines if there are further rows for further depths. |
| 179 | BIT_TABLE_COLUMN(1, DexPc) |
| 180 | BIT_TABLE_COLUMN(2, MethodInfoIndex) |
| 181 | BIT_TABLE_COLUMN(3, ArtMethodHi) // High bits of ArtMethod*. |
| 182 | BIT_TABLE_COLUMN(4, ArtMethodLo) // Low bits of ArtMethod*. |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 183 | BIT_TABLE_COLUMN(5, NumberOfDexRegisters) // Includes outer levels and the main method. |
David Srbecky | d97e082 | 2018-06-03 12:00:24 +0100 | [diff] [blame] | 184 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 185 | static constexpr uint32_t kLast = -1; |
| 186 | static constexpr uint32_t kMore = 0; |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 187 | |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame] | 188 | bool EncodesArtMethod() const { |
David Srbecky | d97e082 | 2018-06-03 12:00:24 +0100 | [diff] [blame] | 189 | return HasArtMethodLo(); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 190 | } |
| 191 | |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame] | 192 | ArtMethod* GetArtMethod() const { |
David Srbecky | d97e082 | 2018-06-03 12:00:24 +0100 | [diff] [blame] | 193 | uint64_t lo = GetArtMethodLo(); |
| 194 | uint64_t hi = GetArtMethodHi(); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 195 | return reinterpret_cast<ArtMethod*>((hi << 32) | lo); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 196 | } |
| 197 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 198 | void Dump(VariableIndentationOutputStream* vios, |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 199 | const CodeInfo& info, |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 200 | const StackMap& stack_map) const; |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 201 | }; |
| 202 | |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 203 | class StackMask : public BitTableAccessor<1> { |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 204 | public: |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 205 | BIT_TABLE_HEADER(StackMask) |
| 206 | BIT_TABLE_COLUMN(0, Mask) |
| 207 | }; |
| 208 | |
| 209 | class DexRegisterMask : public BitTableAccessor<1> { |
| 210 | public: |
| 211 | BIT_TABLE_HEADER(DexRegisterMask) |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 212 | BIT_TABLE_COLUMN(0, Mask) |
| 213 | }; |
| 214 | |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 215 | class DexRegisterMapInfo : public BitTableAccessor<1> { |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 216 | public: |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 217 | BIT_TABLE_HEADER(DexRegisterMapInfo) |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 218 | BIT_TABLE_COLUMN(0, CatalogueIndex) |
| 219 | }; |
| 220 | |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 221 | class DexRegisterInfo : public BitTableAccessor<2> { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 222 | public: |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 223 | BIT_TABLE_HEADER(DexRegisterInfo) |
David Srbecky | d97e082 | 2018-06-03 12:00:24 +0100 | [diff] [blame] | 224 | BIT_TABLE_COLUMN(0, Kind) |
| 225 | BIT_TABLE_COLUMN(1, PackedValue) |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 226 | |
| 227 | ALWAYS_INLINE DexRegisterLocation GetLocation() const { |
David Srbecky | d97e082 | 2018-06-03 12:00:24 +0100 | [diff] [blame] | 228 | DexRegisterLocation::Kind kind = static_cast<DexRegisterLocation::Kind>(GetKind()); |
| 229 | return DexRegisterLocation(kind, UnpackValue(kind, GetPackedValue())); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static uint32_t PackValue(DexRegisterLocation::Kind kind, uint32_t value) { |
| 233 | uint32_t packed_value = value; |
| 234 | if (kind == DexRegisterLocation::Kind::kInStack) { |
| 235 | DCHECK(IsAligned<kFrameSlotSize>(packed_value)); |
| 236 | packed_value /= kFrameSlotSize; |
| 237 | } |
| 238 | return packed_value; |
| 239 | } |
| 240 | |
| 241 | static uint32_t UnpackValue(DexRegisterLocation::Kind kind, uint32_t packed_value) { |
| 242 | uint32_t value = packed_value; |
| 243 | if (kind == DexRegisterLocation::Kind::kInStack) { |
| 244 | value *= kFrameSlotSize; |
| 245 | } |
| 246 | return value; |
| 247 | } |
| 248 | }; |
| 249 | |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 250 | // Register masks tend to have many trailing zero bits (caller-saves are usually not encoded), |
| 251 | // therefore it is worth encoding the mask as value+shift. |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 252 | class RegisterMask : public BitTableAccessor<2> { |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 253 | public: |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 254 | BIT_TABLE_HEADER(RegisterMask) |
David Srbecky | d97e082 | 2018-06-03 12:00:24 +0100 | [diff] [blame] | 255 | BIT_TABLE_COLUMN(0, Value) |
| 256 | BIT_TABLE_COLUMN(1, Shift) |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 257 | |
| 258 | ALWAYS_INLINE uint32_t GetMask() const { |
David Srbecky | d97e082 | 2018-06-03 12:00:24 +0100 | [diff] [blame] | 259 | return GetValue() << GetShift(); |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 260 | } |
| 261 | }; |
| 262 | |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 263 | // Method indices are not very dedup friendly. |
| 264 | // Separating them greatly improves dedup efficiency of the other tables. |
| 265 | class MethodInfo : public BitTableAccessor<1> { |
| 266 | public: |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 267 | BIT_TABLE_HEADER(MethodInfo) |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 268 | BIT_TABLE_COLUMN(0, MethodIndex) |
| 269 | }; |
| 270 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 271 | /** |
| 272 | * Wrapper around all compiler information collected for a method. |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 273 | * See the Decode method at the end for the precise binary format. |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 274 | */ |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 275 | class CodeInfo { |
| 276 | public: |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame] | 277 | class Deduper { |
| 278 | public: |
| 279 | explicit Deduper(std::vector<uint8_t>* output) : writer_(output) { |
| 280 | DCHECK_EQ(output->size(), 0u); |
| 281 | } |
| 282 | |
| 283 | // Copy CodeInfo into output while de-duplicating the internal bit tables. |
| 284 | // It returns the byte offset of the copied CodeInfo within the output. |
| 285 | size_t Dedupe(const uint8_t* code_info); |
| 286 | |
| 287 | private: |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame] | 288 | BitMemoryWriter<std::vector<uint8_t>> writer_; |
| 289 | |
| 290 | // Deduplicate at BitTable level. The value is bit offset within the output. |
| 291 | std::map<BitMemoryRegion, uint32_t, BitMemoryRegion::Less> dedupe_map_; |
| 292 | }; |
| 293 | |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 294 | ALWAYS_INLINE CodeInfo() {} |
| 295 | ALWAYS_INLINE explicit CodeInfo(const uint8_t* data, size_t* num_read_bits = nullptr); |
| 296 | ALWAYS_INLINE explicit CodeInfo(const OatQuickMethodHeader* header); |
David Srbecky | 6ee06e9 | 2018-07-25 21:45:54 +0100 | [diff] [blame] | 297 | |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 298 | // The following methods decode only part of the data. |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 299 | static CodeInfo DecodeGcMasksOnly(const OatQuickMethodHeader* header); |
| 300 | static CodeInfo DecodeInlineInfoOnly(const OatQuickMethodHeader* header); |
David Srbecky | 0983f59 | 2021-04-08 16:36:19 +0100 | [diff] [blame] | 301 | |
| 302 | ALWAYS_INLINE static uint32_t DecodeCodeSize(const uint8_t* code_info_data) { |
| 303 | return DecodeHeaderOnly(code_info_data).code_size_; |
| 304 | } |
| 305 | |
| 306 | ALWAYS_INLINE static QuickMethodFrameInfo DecodeFrameInfo(const uint8_t* code_info_data) { |
| 307 | CodeInfo code_info = DecodeHeaderOnly(code_info_data); |
| 308 | return QuickMethodFrameInfo(code_info.packed_frame_size_ * kStackAlignment, |
| 309 | code_info.core_spill_mask_, |
| 310 | code_info.fp_spill_mask_); |
| 311 | } |
| 312 | |
| 313 | ALWAYS_INLINE static CodeInfo DecodeHeaderOnly(const uint8_t* code_info_data) { |
| 314 | CodeInfo code_info; |
| 315 | BitMemoryReader reader(code_info_data); |
| 316 | std::array<uint32_t, kNumHeaders> header = reader.ReadInterleavedVarints<kNumHeaders>(); |
| 317 | ForEachHeaderField([&code_info, &header](size_t i, auto member_pointer) { |
| 318 | code_info.*member_pointer = header[i]; |
| 319 | }); |
| 320 | return code_info; |
| 321 | } |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 322 | |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 323 | ALWAYS_INLINE const BitTable<StackMap>& GetStackMaps() const { |
| 324 | return stack_maps_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 325 | } |
| 326 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 327 | ALWAYS_INLINE StackMap GetStackMapAt(size_t index) const { |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 328 | return stack_maps_.GetRow(index); |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 329 | } |
| 330 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 331 | BitMemoryRegion GetStackMask(size_t index) const { |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 332 | return stack_masks_.GetBitMemoryRegion(index); |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 333 | } |
| 334 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 335 | BitMemoryRegion GetStackMaskOf(const StackMap& stack_map) const { |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 336 | uint32_t index = stack_map.GetStackMaskIndex(); |
| 337 | return (index == StackMap::kNoValue) ? BitMemoryRegion() : GetStackMask(index); |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 338 | } |
| 339 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 340 | uint32_t GetRegisterMaskOf(const StackMap& stack_map) const { |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 341 | uint32_t index = stack_map.GetRegisterMaskIndex(); |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 342 | return (index == StackMap::kNoValue) ? 0 : register_masks_.GetRow(index).GetMask(); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 343 | } |
| 344 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 345 | uint32_t GetNumberOfLocationCatalogEntries() const { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 346 | return dex_register_catalog_.NumRows(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 347 | } |
| 348 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 349 | ALWAYS_INLINE DexRegisterLocation GetDexRegisterCatalogEntry(size_t index) const { |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 350 | return (index == StackMap::kNoValue) |
| 351 | ? DexRegisterLocation::None() |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 352 | : dex_register_catalog_.GetRow(index).GetLocation(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 353 | } |
| 354 | |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 355 | bool HasInlineInfo() const { |
| 356 | return inline_infos_.NumRows() > 0; |
| 357 | } |
| 358 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 359 | uint32_t GetNumberOfStackMaps() const { |
| 360 | return stack_maps_.NumRows(); |
Nicolas Geoffray | 6530baf | 2015-05-26 15:22:58 +0100 | [diff] [blame] | 361 | } |
| 362 | |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 363 | uint32_t GetMethodIndexOf(InlineInfo inline_info) const { |
| 364 | return method_infos_.GetRow(inline_info.GetMethodInfoIndex()).GetMethodIndex(); |
| 365 | } |
| 366 | |
David Srbecky | fd89b07 | 2018-06-03 12:00:22 +0100 | [diff] [blame] | 367 | ALWAYS_INLINE DexRegisterMap GetDexRegisterMapOf(StackMap stack_map) const { |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 368 | if (stack_map.HasDexRegisterMap()) { |
| 369 | DexRegisterMap map(number_of_dex_registers_, DexRegisterLocation::Invalid()); |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 370 | DecodeDexRegisterMap(stack_map.Row(), /* first_dex_register= */ 0, &map); |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 371 | return map; |
| 372 | } |
| 373 | return DexRegisterMap(0, DexRegisterLocation::None()); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 374 | } |
| 375 | |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 376 | ALWAYS_INLINE DexRegisterMap GetInlineDexRegisterMapOf(StackMap stack_map, |
| 377 | InlineInfo inline_info) const { |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 378 | if (stack_map.HasDexRegisterMap()) { |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 379 | DCHECK(stack_map.HasInlineInfoIndex()); |
| 380 | uint32_t depth = inline_info.Row() - stack_map.GetInlineInfoIndex(); |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 381 | // The register counts are commutative and include all outer levels. |
| 382 | // This allows us to determine the range [first, last) in just two lookups. |
| 383 | // If we are at depth 0 (the first inlinee), the count from the main method is used. |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 384 | uint32_t first = (depth == 0) |
| 385 | ? number_of_dex_registers_ |
| 386 | : inline_infos_.GetRow(inline_info.Row() - 1).GetNumberOfDexRegisters(); |
| 387 | uint32_t last = inline_info.GetNumberOfDexRegisters(); |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 388 | DexRegisterMap map(last - first, DexRegisterLocation::Invalid()); |
| 389 | DecodeDexRegisterMap(stack_map.Row(), first, &map); |
| 390 | return map; |
| 391 | } |
| 392 | return DexRegisterMap(0, DexRegisterLocation::None()); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 393 | } |
| 394 | |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 395 | BitTableRange<InlineInfo> GetInlineInfosOf(StackMap stack_map) const { |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 396 | uint32_t index = stack_map.GetInlineInfoIndex(); |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame] | 397 | if (index != StackMap::kNoValue) { |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 398 | auto begin = inline_infos_.begin() + index; |
| 399 | auto end = begin; |
| 400 | while ((*end++).GetIsLast() == InlineInfo::kMore) { } |
| 401 | return BitTableRange<InlineInfo>(begin, end); |
| 402 | } else { |
| 403 | return BitTableRange<InlineInfo>(); |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame] | 404 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 405 | } |
| 406 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 407 | StackMap GetStackMapForDexPc(uint32_t dex_pc) const { |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 408 | for (StackMap stack_map : stack_maps_) { |
David Srbecky | 50fac06 | 2018-06-13 18:55:35 +0100 | [diff] [blame] | 409 | if (stack_map.GetDexPc() == dex_pc && stack_map.GetKind() != StackMap::Kind::Debug) { |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 410 | return stack_map; |
| 411 | } |
| 412 | } |
David Srbecky | a45a85c | 2018-06-21 16:03:12 +0100 | [diff] [blame] | 413 | return stack_maps_.GetInvalidRow(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 414 | } |
| 415 | |
David Srbecky | 50fac06 | 2018-06-13 18:55:35 +0100 | [diff] [blame] | 416 | // Searches the stack map list backwards because catch stack maps are stored at the end. |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 417 | StackMap GetCatchStackMapForDexPc(uint32_t dex_pc) const { |
| 418 | for (size_t i = GetNumberOfStackMaps(); i > 0; --i) { |
| 419 | StackMap stack_map = GetStackMapAt(i - 1); |
David Srbecky | 50fac06 | 2018-06-13 18:55:35 +0100 | [diff] [blame] | 420 | if (stack_map.GetDexPc() == dex_pc && stack_map.GetKind() == StackMap::Kind::Catch) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 421 | return stack_map; |
| 422 | } |
| 423 | } |
David Srbecky | a45a85c | 2018-06-21 16:03:12 +0100 | [diff] [blame] | 424 | return stack_maps_.GetInvalidRow(); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 425 | } |
| 426 | |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 427 | StackMap GetOsrStackMapForDexPc(uint32_t dex_pc) const { |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 428 | for (StackMap stack_map : stack_maps_) { |
David Srbecky | 50fac06 | 2018-06-13 18:55:35 +0100 | [diff] [blame] | 429 | if (stack_map.GetDexPc() == dex_pc && stack_map.GetKind() == StackMap::Kind::OSR) { |
| 430 | return stack_map; |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 431 | } |
| 432 | } |
David Srbecky | a45a85c | 2018-06-21 16:03:12 +0100 | [diff] [blame] | 433 | return stack_maps_.GetInvalidRow(); |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Eric Holk | f1e1dd1 | 2020-08-21 15:38:12 -0700 | [diff] [blame] | 436 | StackMap GetStackMapForNativePcOffset(uintptr_t pc, InstructionSet isa = kRuntimeISA) const; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 437 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 438 | // Dump this CodeInfo object on `vios`. |
| 439 | // `code_offset` is the (absolute) native PC of the compiled method. |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 440 | void Dump(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 441 | uint32_t code_offset, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 442 | bool verbose, |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 443 | InstructionSet instruction_set) const; |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 444 | |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 445 | // Accumulate code info size statistics into the given Stats tree. |
David Srbecky | 81b1d78 | 2021-03-07 21:33:28 +0000 | [diff] [blame] | 446 | static void CollectSizeStats(const uint8_t* code_info, /*out*/ Stats& parent); |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 447 | |
David Srbecky | e42a4b9 | 2019-05-26 00:10:25 +0100 | [diff] [blame] | 448 | ALWAYS_INLINE static bool HasInlineInfo(const uint8_t* code_info_data) { |
| 449 | return (*code_info_data & kHasInlineInfo) != 0; |
| 450 | } |
| 451 | |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 452 | ALWAYS_INLINE static bool IsBaseline(const uint8_t* code_info_data) { |
| 453 | return (*code_info_data & kIsBaseline) != 0; |
| 454 | } |
| 455 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 456 | private: |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 457 | // Scan backward to determine dex register locations at given stack map. |
| 458 | void DecodeDexRegisterMap(uint32_t stack_map_index, |
| 459 | uint32_t first_dex_register, |
| 460 | /*out*/ DexRegisterMap* map) const; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 461 | |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 462 | template<typename DecodeCallback> // (size_t index, BitTable<...>*, BitMemoryRegion). |
| 463 | ALWAYS_INLINE CodeInfo(const uint8_t* data, size_t* num_read_bits, DecodeCallback callback); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 464 | |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 465 | // Invokes the callback with index and member pointer of each header field. |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 466 | template<typename Callback> |
| 467 | ALWAYS_INLINE static void ForEachHeaderField(Callback callback) { |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 468 | size_t index = 0; |
| 469 | callback(index++, &CodeInfo::flags_); |
David Srbecky | 17b4d2b | 2021-03-02 18:14:31 +0000 | [diff] [blame] | 470 | callback(index++, &CodeInfo::code_size_); |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 471 | callback(index++, &CodeInfo::packed_frame_size_); |
| 472 | callback(index++, &CodeInfo::core_spill_mask_); |
| 473 | callback(index++, &CodeInfo::fp_spill_mask_); |
| 474 | callback(index++, &CodeInfo::number_of_dex_registers_); |
| 475 | callback(index++, &CodeInfo::bit_table_flags_); |
| 476 | DCHECK_EQ(index, kNumHeaders); |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 477 | } |
| 478 | |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 479 | // Invokes the callback with index and member pointer of each BitTable field. |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 480 | template<typename Callback> |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 481 | ALWAYS_INLINE static void ForEachBitTableField(Callback callback) { |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 482 | size_t index = 0; |
| 483 | callback(index++, &CodeInfo::stack_maps_); |
| 484 | callback(index++, &CodeInfo::register_masks_); |
| 485 | callback(index++, &CodeInfo::stack_masks_); |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 486 | callback(index++, &CodeInfo::inline_infos_); |
| 487 | callback(index++, &CodeInfo::method_infos_); |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 488 | callback(index++, &CodeInfo::dex_register_masks_); |
| 489 | callback(index++, &CodeInfo::dex_register_maps_); |
| 490 | callback(index++, &CodeInfo::dex_register_catalog_); |
| 491 | DCHECK_EQ(index, kNumBitTables); |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 492 | } |
| 493 | |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 494 | bool HasBitTable(size_t i) { return ((bit_table_flags_ >> i) & 1) != 0; } |
| 495 | bool IsBitTableDeduped(size_t i) { return ((bit_table_flags_ >> (kNumBitTables + i)) & 1) != 0; } |
| 496 | void SetBitTableDeduped(size_t i) { bit_table_flags_ |= 1 << (kNumBitTables + i); } |
| 497 | |
David Srbecky | e42a4b9 | 2019-05-26 00:10:25 +0100 | [diff] [blame] | 498 | enum Flags { |
| 499 | kHasInlineInfo = 1 << 0, |
Nicolas Geoffray | a59af8a | 2019-11-27 17:42:32 +0000 | [diff] [blame] | 500 | kIsBaseline = 1 << 1, |
David Srbecky | e42a4b9 | 2019-05-26 00:10:25 +0100 | [diff] [blame] | 501 | }; |
| 502 | |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 503 | // The CodeInfo starts with sequence of variable-length bit-encoded integers. |
David Srbecky | 17b4d2b | 2021-03-02 18:14:31 +0000 | [diff] [blame] | 504 | static constexpr size_t kNumHeaders = 7; |
| 505 | uint32_t flags_ = 0; // Note that the space is limited to three bits. |
| 506 | uint32_t code_size_ = 0; // The size of native PC range in bytes. |
David Srbecky | 2259f1c | 2019-01-16 23:18:30 +0000 | [diff] [blame] | 507 | uint32_t packed_frame_size_ = 0; // Frame size in kStackAlignment units. |
| 508 | uint32_t core_spill_mask_ = 0; |
| 509 | uint32_t fp_spill_mask_ = 0; |
| 510 | uint32_t number_of_dex_registers_ = 0; |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 511 | uint32_t bit_table_flags_ = 0; |
| 512 | |
| 513 | // The encoded bit-tables follow the header. Based on the above flags field, |
| 514 | // bit-tables might be omitted or replaced by relative bit-offset if deduped. |
| 515 | static constexpr size_t kNumBitTables = 8; |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 516 | BitTable<StackMap> stack_maps_; |
| 517 | BitTable<RegisterMask> register_masks_; |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 518 | BitTable<StackMask> stack_masks_; |
David Srbecky | a2d29a3 | 2018-08-03 11:06:38 +0100 | [diff] [blame] | 519 | BitTable<InlineInfo> inline_infos_; |
| 520 | BitTable<MethodInfo> method_infos_; |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 521 | BitTable<DexRegisterMask> dex_register_masks_; |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 522 | BitTable<DexRegisterMapInfo> dex_register_maps_; |
| 523 | BitTable<DexRegisterInfo> dex_register_catalog_; |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 524 | |
David Srbecky | 67ba872 | 2019-05-23 15:32:18 +0100 | [diff] [blame] | 525 | friend class StackMapStream; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 526 | }; |
| 527 | |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 528 | #undef ELEMENT_BYTE_OFFSET_AFTER |
| 529 | #undef ELEMENT_BIT_OFFSET_AFTER |
| 530 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 531 | } // namespace art |
| 532 | |
| 533 | #endif // ART_RUNTIME_STACK_MAP_H_ |