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 | |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 22 | #include "arch/code_offset.h" |
David Sehr | 1ce2b3b | 2018-04-05 11:02:03 -0700 | [diff] [blame] | 23 | #include "base/bit_memory_region.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" |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 29 | #include "method_info.h" |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 30 | |
| 31 | namespace art { |
| 32 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 33 | class VariableIndentationOutputStream; |
| 34 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 35 | // Size of a frame slot, in bytes. This constant is a signed value, |
| 36 | // to please the compiler in arithmetic operations involving int32_t |
| 37 | // (signed) values. |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 38 | static constexpr ssize_t kFrameSlotSize = 4; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 39 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 40 | class ArtMethod; |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 41 | class CodeInfo; |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 42 | class StackMapEncoding; |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 43 | struct CodeInfoEncoding; |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 44 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 45 | /** |
| 46 | * Classes in the following file are wrapper on stack map information backed |
| 47 | * by a MemoryRegion. As such they read and write to the region, they don't have |
| 48 | * their own fields. |
| 49 | */ |
| 50 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 51 | // Dex register location container used by DexRegisterMap and StackMapStream. |
| 52 | class DexRegisterLocation { |
| 53 | public: |
| 54 | /* |
| 55 | * The location kind used to populate the Dex register information in a |
| 56 | * StackMapStream can either be: |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 57 | * - kStack: vreg stored on the stack, value holds the stack offset; |
| 58 | * - kInRegister: vreg stored in low 32 bits of a core physical register, |
| 59 | * value holds the register number; |
| 60 | * - kInRegisterHigh: vreg stored in high 32 bits of a core physical register, |
| 61 | * value holds the register number; |
| 62 | * - kInFpuRegister: vreg stored in low 32 bits of an FPU register, |
| 63 | * value holds the register number; |
| 64 | * - kInFpuRegisterHigh: vreg stored in high 32 bits of an FPU register, |
| 65 | * value holds the register number; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 66 | * - kConstant: value holds the constant; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 67 | * |
| 68 | * In addition, DexRegisterMap also uses these values: |
| 69 | * - kInStackLargeOffset: value holds a "large" stack offset (greater than |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 70 | * or equal to 128 bytes); |
| 71 | * - kConstantLargeValue: value holds a "large" constant (lower than 0, or |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 72 | * or greater than or equal to 32); |
| 73 | * - kNone: the register has no location, meaning it has not been set. |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 74 | */ |
| 75 | enum class Kind : uint8_t { |
| 76 | // Short location kinds, for entries fitting on one byte (3 bits |
| 77 | // for the kind, 5 bits for the value) in a DexRegisterMap. |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 78 | kInStack = 0, // 0b000 |
| 79 | kInRegister = 1, // 0b001 |
| 80 | kInRegisterHigh = 2, // 0b010 |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 81 | kInFpuRegister = 3, // 0b011 |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 82 | kInFpuRegisterHigh = 4, // 0b100 |
| 83 | kConstant = 5, // 0b101 |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 84 | |
| 85 | // Large location kinds, requiring a 5-byte encoding (1 byte for the |
| 86 | // kind, 4 bytes for the value). |
| 87 | |
| 88 | // Stack location at a large offset, meaning that the offset value |
| 89 | // divided by the stack frame slot size (4 bytes) cannot fit on a |
| 90 | // 5-bit unsigned integer (i.e., this offset value is greater than |
| 91 | // or equal to 2^5 * 4 = 128 bytes). |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 92 | kInStackLargeOffset = 6, // 0b110 |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 93 | |
| 94 | // Large constant, that cannot fit on a 5-bit signed integer (i.e., |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 95 | // lower than 0, or greater than or equal to 2^5 = 32). |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 96 | kConstantLargeValue = 7, // 0b111 |
| 97 | |
| 98 | // Entries with no location are not stored and do not need own marker. |
| 99 | kNone = static_cast<uint8_t>(-1), |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 100 | |
| 101 | kLastLocationKind = kConstantLargeValue |
| 102 | }; |
| 103 | |
| 104 | static_assert( |
| 105 | sizeof(Kind) == 1u, |
| 106 | "art::DexRegisterLocation::Kind has a size different from one byte."); |
| 107 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 108 | static bool IsShortLocationKind(Kind kind) { |
| 109 | switch (kind) { |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 110 | case Kind::kInStack: |
| 111 | case Kind::kInRegister: |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 112 | case Kind::kInRegisterHigh: |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 113 | case Kind::kInFpuRegister: |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 114 | case Kind::kInFpuRegisterHigh: |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 115 | case Kind::kConstant: |
| 116 | return true; |
| 117 | |
| 118 | case Kind::kInStackLargeOffset: |
| 119 | case Kind::kConstantLargeValue: |
| 120 | return false; |
| 121 | |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 122 | case Kind::kNone: |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 123 | LOG(FATAL) << "Unexpected location kind"; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 124 | } |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 125 | UNREACHABLE(); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | // Convert `kind` to a "surface" kind, i.e. one that doesn't include |
| 129 | // any value with a "large" qualifier. |
| 130 | // TODO: Introduce another enum type for the surface kind? |
| 131 | static Kind ConvertToSurfaceKind(Kind kind) { |
| 132 | switch (kind) { |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 133 | case Kind::kInStack: |
| 134 | case Kind::kInRegister: |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 135 | case Kind::kInRegisterHigh: |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 136 | case Kind::kInFpuRegister: |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 137 | case Kind::kInFpuRegisterHigh: |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 138 | case Kind::kConstant: |
| 139 | return kind; |
| 140 | |
| 141 | case Kind::kInStackLargeOffset: |
| 142 | return Kind::kInStack; |
| 143 | |
| 144 | case Kind::kConstantLargeValue: |
| 145 | return Kind::kConstant; |
| 146 | |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 147 | case Kind::kNone: |
| 148 | return kind; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 149 | } |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 150 | UNREACHABLE(); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 153 | // Required by art::StackMapStream::LocationCatalogEntriesIndices. |
| 154 | DexRegisterLocation() : kind_(Kind::kNone), value_(0) {} |
| 155 | |
| 156 | DexRegisterLocation(Kind kind, int32_t value) : kind_(kind), value_(value) {} |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 157 | |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 158 | static DexRegisterLocation None() { |
| 159 | return DexRegisterLocation(Kind::kNone, 0); |
| 160 | } |
| 161 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 162 | // Get the "surface" kind of the location, i.e., the one that doesn't |
| 163 | // include any value with a "large" qualifier. |
| 164 | Kind GetKind() const { |
| 165 | return ConvertToSurfaceKind(kind_); |
| 166 | } |
| 167 | |
| 168 | // Get the value of the location. |
| 169 | int32_t GetValue() const { return value_; } |
| 170 | |
| 171 | // Get the actual kind of the location. |
| 172 | Kind GetInternalKind() const { return kind_; } |
| 173 | |
Calin Juravle | 6ae7096 | 2015-03-18 16:31:28 +0000 | [diff] [blame] | 174 | bool operator==(DexRegisterLocation other) const { |
| 175 | return kind_ == other.kind_ && value_ == other.value_; |
| 176 | } |
| 177 | |
| 178 | bool operator!=(DexRegisterLocation other) const { |
| 179 | return !(*this == other); |
| 180 | } |
| 181 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 182 | private: |
| 183 | Kind kind_; |
| 184 | int32_t value_; |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 185 | |
| 186 | friend class DexRegisterLocationHashFn; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 187 | }; |
| 188 | |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 189 | std::ostream& operator<<(std::ostream& stream, const DexRegisterLocation::Kind& kind); |
| 190 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 191 | /** |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 192 | * Store information on unique Dex register locations used in a method. |
| 193 | * The information is of the form: |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 194 | * |
| 195 | * [DexRegisterLocation+]. |
| 196 | * |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 197 | * DexRegisterLocations are either 1- or 5-byte wide (see art::DexRegisterLocation::Kind). |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 198 | */ |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 199 | class DexRegisterLocationCatalog { |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 200 | public: |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 201 | explicit DexRegisterLocationCatalog(MemoryRegion region) : region_(region) {} |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 202 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 203 | // Short (compressed) location, fitting on one byte. |
| 204 | typedef uint8_t ShortLocation; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 205 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 206 | void SetRegisterInfo(size_t offset, const DexRegisterLocation& dex_register_location) { |
| 207 | DexRegisterLocation::Kind kind = ComputeCompressedKind(dex_register_location); |
| 208 | int32_t value = dex_register_location.GetValue(); |
| 209 | if (DexRegisterLocation::IsShortLocationKind(kind)) { |
| 210 | // Short location. Compress the kind and the value as a single byte. |
| 211 | if (kind == DexRegisterLocation::Kind::kInStack) { |
| 212 | // Instead of storing stack offsets expressed in bytes for |
| 213 | // short stack locations, store slot offsets. A stack offset |
| 214 | // is a multiple of 4 (kFrameSlotSize). This means that by |
| 215 | // dividing it by 4, we can fit values from the [0, 128) |
| 216 | // interval in a short stack location, and not just values |
| 217 | // from the [0, 32) interval. |
| 218 | DCHECK_EQ(value % kFrameSlotSize, 0); |
| 219 | value /= kFrameSlotSize; |
| 220 | } |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 221 | DCHECK(IsShortValue(value)) << value; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 222 | region_.StoreUnaligned<ShortLocation>(offset, MakeShortLocation(kind, value)); |
| 223 | } else { |
| 224 | // Large location. Write the location on one byte and the value |
| 225 | // on 4 bytes. |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 226 | DCHECK(!IsShortValue(value)) << value; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 227 | if (kind == DexRegisterLocation::Kind::kInStackLargeOffset) { |
| 228 | // Also divide large stack offsets by 4 for the sake of consistency. |
| 229 | DCHECK_EQ(value % kFrameSlotSize, 0); |
| 230 | value /= kFrameSlotSize; |
| 231 | } |
| 232 | // Data can be unaligned as the written Dex register locations can |
| 233 | // either be 1-byte or 5-byte wide. Use |
| 234 | // art::MemoryRegion::StoreUnaligned instead of |
| 235 | // art::MemoryRegion::Store to prevent unligned word accesses on ARM. |
| 236 | region_.StoreUnaligned<DexRegisterLocation::Kind>(offset, kind); |
| 237 | region_.StoreUnaligned<int32_t>(offset + sizeof(DexRegisterLocation::Kind), value); |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 241 | // Find the offset of the location catalog entry number `location_catalog_entry_index`. |
| 242 | size_t FindLocationOffset(size_t location_catalog_entry_index) const { |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 243 | size_t offset = kFixedSize; |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 244 | // Skip the first `location_catalog_entry_index - 1` entries. |
| 245 | for (uint16_t i = 0; i < location_catalog_entry_index; ++i) { |
| 246 | // Read the first next byte and inspect its first 3 bits to decide |
| 247 | // whether it is a short or a large location. |
| 248 | DexRegisterLocation::Kind kind = ExtractKindAtOffset(offset); |
| 249 | if (DexRegisterLocation::IsShortLocationKind(kind)) { |
| 250 | // Short location. Skip the current byte. |
| 251 | offset += SingleShortEntrySize(); |
| 252 | } else { |
| 253 | // Large location. Skip the 5 next bytes. |
| 254 | offset += SingleLargeEntrySize(); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | return offset; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 258 | } |
| 259 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 260 | // Get the internal kind of entry at `location_catalog_entry_index`. |
| 261 | DexRegisterLocation::Kind GetLocationInternalKind(size_t location_catalog_entry_index) const { |
| 262 | if (location_catalog_entry_index == kNoLocationEntryIndex) { |
| 263 | return DexRegisterLocation::Kind::kNone; |
| 264 | } |
| 265 | return ExtractKindAtOffset(FindLocationOffset(location_catalog_entry_index)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 266 | } |
| 267 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 268 | // Get the (surface) kind and value of entry at `location_catalog_entry_index`. |
| 269 | DexRegisterLocation GetDexRegisterLocation(size_t location_catalog_entry_index) const { |
| 270 | if (location_catalog_entry_index == kNoLocationEntryIndex) { |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 271 | return DexRegisterLocation::None(); |
| 272 | } |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 273 | size_t offset = FindLocationOffset(location_catalog_entry_index); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 274 | // Read the first byte and inspect its first 3 bits to get the location. |
| 275 | ShortLocation first_byte = region_.LoadUnaligned<ShortLocation>(offset); |
| 276 | DexRegisterLocation::Kind kind = ExtractKindFromShortLocation(first_byte); |
| 277 | if (DexRegisterLocation::IsShortLocationKind(kind)) { |
| 278 | // Short location. Extract the value from the remaining 5 bits. |
| 279 | int32_t value = ExtractValueFromShortLocation(first_byte); |
| 280 | if (kind == DexRegisterLocation::Kind::kInStack) { |
| 281 | // Convert the stack slot (short) offset to a byte offset value. |
| 282 | value *= kFrameSlotSize; |
| 283 | } |
| 284 | return DexRegisterLocation(kind, value); |
| 285 | } else { |
| 286 | // Large location. Read the four next bytes to get the value. |
| 287 | int32_t value = region_.LoadUnaligned<int32_t>(offset + sizeof(DexRegisterLocation::Kind)); |
| 288 | if (kind == DexRegisterLocation::Kind::kInStackLargeOffset) { |
| 289 | // Convert the stack slot (large) offset to a byte offset value. |
| 290 | value *= kFrameSlotSize; |
| 291 | } |
| 292 | return DexRegisterLocation(kind, value); |
| 293 | } |
Sebastien Hertz | 7cde48c | 2015-01-20 16:06:43 +0100 | [diff] [blame] | 294 | } |
| 295 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 296 | // Compute the compressed kind of `location`. |
| 297 | static DexRegisterLocation::Kind ComputeCompressedKind(const DexRegisterLocation& location) { |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 298 | DexRegisterLocation::Kind kind = location.GetInternalKind(); |
| 299 | switch (kind) { |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 300 | case DexRegisterLocation::Kind::kInStack: |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 301 | return IsShortStackOffsetValue(location.GetValue()) |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 302 | ? DexRegisterLocation::Kind::kInStack |
| 303 | : DexRegisterLocation::Kind::kInStackLargeOffset; |
| 304 | |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 305 | case DexRegisterLocation::Kind::kInRegister: |
| 306 | case DexRegisterLocation::Kind::kInRegisterHigh: |
| 307 | DCHECK_GE(location.GetValue(), 0); |
| 308 | DCHECK_LT(location.GetValue(), 1 << kValueBits); |
| 309 | return kind; |
| 310 | |
| 311 | case DexRegisterLocation::Kind::kInFpuRegister: |
| 312 | case DexRegisterLocation::Kind::kInFpuRegisterHigh: |
| 313 | DCHECK_GE(location.GetValue(), 0); |
| 314 | DCHECK_LT(location.GetValue(), 1 << kValueBits); |
| 315 | return kind; |
| 316 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 317 | case DexRegisterLocation::Kind::kConstant: |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 318 | return IsShortConstantValue(location.GetValue()) |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 319 | ? DexRegisterLocation::Kind::kConstant |
| 320 | : DexRegisterLocation::Kind::kConstantLargeValue; |
| 321 | |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 322 | case DexRegisterLocation::Kind::kConstantLargeValue: |
| 323 | case DexRegisterLocation::Kind::kInStackLargeOffset: |
| 324 | case DexRegisterLocation::Kind::kNone: |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 325 | LOG(FATAL) << "Unexpected location kind " << kind; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 326 | } |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 327 | UNREACHABLE(); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | // Can `location` be turned into a short location? |
| 331 | static bool CanBeEncodedAsShortLocation(const DexRegisterLocation& location) { |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 332 | DexRegisterLocation::Kind kind = location.GetInternalKind(); |
| 333 | switch (kind) { |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 334 | case DexRegisterLocation::Kind::kInStack: |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 335 | return IsShortStackOffsetValue(location.GetValue()); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 336 | |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 337 | case DexRegisterLocation::Kind::kInRegister: |
| 338 | case DexRegisterLocation::Kind::kInRegisterHigh: |
| 339 | case DexRegisterLocation::Kind::kInFpuRegister: |
| 340 | case DexRegisterLocation::Kind::kInFpuRegisterHigh: |
| 341 | return true; |
| 342 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 343 | case DexRegisterLocation::Kind::kConstant: |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 344 | return IsShortConstantValue(location.GetValue()); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 345 | |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 346 | case DexRegisterLocation::Kind::kConstantLargeValue: |
| 347 | case DexRegisterLocation::Kind::kInStackLargeOffset: |
| 348 | case DexRegisterLocation::Kind::kNone: |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 349 | LOG(FATAL) << "Unexpected location kind " << kind; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 350 | } |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 351 | UNREACHABLE(); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | static size_t EntrySize(const DexRegisterLocation& location) { |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 355 | return CanBeEncodedAsShortLocation(location) ? SingleShortEntrySize() : SingleLargeEntrySize(); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static size_t SingleShortEntrySize() { |
| 359 | return sizeof(ShortLocation); |
| 360 | } |
| 361 | |
| 362 | static size_t SingleLargeEntrySize() { |
| 363 | return sizeof(DexRegisterLocation::Kind) + sizeof(int32_t); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 364 | } |
| 365 | |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 366 | size_t Size() const { |
| 367 | return region_.size(); |
| 368 | } |
| 369 | |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 370 | void Dump(VariableIndentationOutputStream* vios, |
| 371 | const CodeInfo& code_info); |
Roland Levillain | 0396ed7 | 2015-05-27 15:12:19 +0100 | [diff] [blame] | 372 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 373 | // Special (invalid) Dex register location catalog entry index meaning |
| 374 | // that there is no location for a given Dex register (i.e., it is |
| 375 | // mapped to a DexRegisterLocation::Kind::kNone location). |
| 376 | static constexpr size_t kNoLocationEntryIndex = -1; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 377 | |
Roland Levillain | 12baf47 | 2015-03-05 12:41:42 +0000 | [diff] [blame] | 378 | private: |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 379 | static constexpr int kFixedSize = 0; |
| 380 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 381 | // Width of the kind "field" in a short location, in bits. |
| 382 | static constexpr size_t kKindBits = 3; |
| 383 | // Width of the value "field" in a short location, in bits. |
| 384 | static constexpr size_t kValueBits = 5; |
| 385 | |
| 386 | static constexpr uint8_t kKindMask = (1 << kKindBits) - 1; |
| 387 | static constexpr int32_t kValueMask = (1 << kValueBits) - 1; |
| 388 | static constexpr size_t kKindOffset = 0; |
| 389 | static constexpr size_t kValueOffset = kKindBits; |
| 390 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 391 | static bool IsShortStackOffsetValue(int32_t value) { |
| 392 | DCHECK_EQ(value % kFrameSlotSize, 0); |
| 393 | return IsShortValue(value / kFrameSlotSize); |
| 394 | } |
| 395 | |
| 396 | static bool IsShortConstantValue(int32_t value) { |
| 397 | return IsShortValue(value); |
| 398 | } |
| 399 | |
| 400 | static bool IsShortValue(int32_t value) { |
| 401 | return IsUint<kValueBits>(value); |
| 402 | } |
| 403 | |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 404 | static ShortLocation MakeShortLocation(DexRegisterLocation::Kind kind, int32_t value) { |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 405 | uint8_t kind_integer_value = static_cast<uint8_t>(kind); |
| 406 | DCHECK(IsUint<kKindBits>(kind_integer_value)) << kind_integer_value; |
| 407 | DCHECK(IsShortValue(value)) << value; |
| 408 | return (kind_integer_value & kKindMask) << kKindOffset |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 409 | | (value & kValueMask) << kValueOffset; |
| 410 | } |
| 411 | |
| 412 | static DexRegisterLocation::Kind ExtractKindFromShortLocation(ShortLocation location) { |
| 413 | uint8_t kind = (location >> kKindOffset) & kKindMask; |
| 414 | DCHECK_LE(kind, static_cast<uint8_t>(DexRegisterLocation::Kind::kLastLocationKind)); |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 415 | // We do not encode kNone locations in the stack map. |
| 416 | DCHECK_NE(kind, static_cast<uint8_t>(DexRegisterLocation::Kind::kNone)); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 417 | return static_cast<DexRegisterLocation::Kind>(kind); |
| 418 | } |
| 419 | |
| 420 | static int32_t ExtractValueFromShortLocation(ShortLocation location) { |
| 421 | return (location >> kValueOffset) & kValueMask; |
| 422 | } |
| 423 | |
| 424 | // Extract a location kind from the byte at position `offset`. |
| 425 | DexRegisterLocation::Kind ExtractKindAtOffset(size_t offset) const { |
| 426 | ShortLocation first_byte = region_.LoadUnaligned<ShortLocation>(offset); |
| 427 | return ExtractKindFromShortLocation(first_byte); |
| 428 | } |
| 429 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 430 | MemoryRegion region_; |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 431 | |
| 432 | friend class CodeInfo; |
| 433 | friend class StackMapStream; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 434 | }; |
| 435 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 436 | /* Information on Dex register locations for a specific PC, mapping a |
| 437 | * stack map's Dex register to a location entry in a DexRegisterLocationCatalog. |
| 438 | * The information is of the form: |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 439 | * |
| 440 | * [live_bit_mask, entries*] |
| 441 | * |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 442 | * where entries are concatenated unsigned integer values encoded on a number |
| 443 | * of bits (fixed per DexRegisterMap instances of a CodeInfo object) depending |
| 444 | * on the number of entries in the Dex register location catalog |
| 445 | * (see DexRegisterMap::SingleEntrySizeInBits). The map is 1-byte aligned. |
| 446 | */ |
| 447 | class DexRegisterMap { |
| 448 | public: |
| 449 | explicit DexRegisterMap(MemoryRegion region) : region_(region) {} |
Nicolas Geoffray | 012fc4e | 2016-01-08 15:58:19 +0000 | [diff] [blame] | 450 | DexRegisterMap() {} |
| 451 | |
David Srbecky | 68fefac | 2018-05-10 17:49:33 +0100 | [diff] [blame] | 452 | bool IsValid() const { return region_.IsValid(); } |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 453 | |
| 454 | // Get the surface kind of Dex register `dex_register_number`. |
| 455 | DexRegisterLocation::Kind GetLocationKind(uint16_t dex_register_number, |
| 456 | uint16_t number_of_dex_registers, |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 457 | const CodeInfo& code_info, |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 458 | const CodeInfoEncoding& enc) const { |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 459 | return DexRegisterLocation::ConvertToSurfaceKind( |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 460 | GetLocationInternalKind(dex_register_number, number_of_dex_registers, code_info, enc)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | // Get the internal kind of Dex register `dex_register_number`. |
| 464 | DexRegisterLocation::Kind GetLocationInternalKind(uint16_t dex_register_number, |
| 465 | uint16_t number_of_dex_registers, |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 466 | const CodeInfo& code_info, |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 467 | const CodeInfoEncoding& enc) const; |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 468 | |
| 469 | // Get the Dex register location `dex_register_number`. |
| 470 | DexRegisterLocation GetDexRegisterLocation(uint16_t dex_register_number, |
| 471 | uint16_t number_of_dex_registers, |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 472 | const CodeInfo& code_info, |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 473 | const CodeInfoEncoding& enc) const; |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 474 | |
| 475 | int32_t GetStackOffsetInBytes(uint16_t dex_register_number, |
| 476 | uint16_t number_of_dex_registers, |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 477 | const CodeInfo& code_info, |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 478 | const CodeInfoEncoding& enc) const { |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 479 | DexRegisterLocation location = |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 480 | GetDexRegisterLocation(dex_register_number, number_of_dex_registers, code_info, enc); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 481 | DCHECK(location.GetKind() == DexRegisterLocation::Kind::kInStack); |
| 482 | // GetDexRegisterLocation returns the offset in bytes. |
| 483 | return location.GetValue(); |
| 484 | } |
| 485 | |
| 486 | int32_t GetConstant(uint16_t dex_register_number, |
| 487 | uint16_t number_of_dex_registers, |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 488 | const CodeInfo& code_info, |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 489 | const CodeInfoEncoding& enc) const { |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 490 | DexRegisterLocation location = |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 491 | GetDexRegisterLocation(dex_register_number, number_of_dex_registers, code_info, enc); |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 492 | DCHECK_EQ(location.GetKind(), DexRegisterLocation::Kind::kConstant); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 493 | return location.GetValue(); |
| 494 | } |
| 495 | |
| 496 | int32_t GetMachineRegister(uint16_t dex_register_number, |
| 497 | uint16_t number_of_dex_registers, |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 498 | const CodeInfo& code_info, |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 499 | const CodeInfoEncoding& enc) const { |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 500 | DexRegisterLocation location = |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 501 | GetDexRegisterLocation(dex_register_number, number_of_dex_registers, code_info, enc); |
David Brazdil | d9cb68e | 2015-08-25 13:52:43 +0100 | [diff] [blame] | 502 | DCHECK(location.GetInternalKind() == DexRegisterLocation::Kind::kInRegister || |
| 503 | location.GetInternalKind() == DexRegisterLocation::Kind::kInRegisterHigh || |
| 504 | location.GetInternalKind() == DexRegisterLocation::Kind::kInFpuRegister || |
| 505 | location.GetInternalKind() == DexRegisterLocation::Kind::kInFpuRegisterHigh) |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 506 | << location.GetInternalKind(); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 507 | return location.GetValue(); |
| 508 | } |
| 509 | |
| 510 | // Get the index of the entry in the Dex register location catalog |
| 511 | // corresponding to `dex_register_number`. |
| 512 | size_t GetLocationCatalogEntryIndex(uint16_t dex_register_number, |
| 513 | uint16_t number_of_dex_registers, |
| 514 | size_t number_of_location_catalog_entries) const { |
| 515 | if (!IsDexRegisterLive(dex_register_number)) { |
| 516 | return DexRegisterLocationCatalog::kNoLocationEntryIndex; |
| 517 | } |
| 518 | |
| 519 | if (number_of_location_catalog_entries == 1) { |
| 520 | // We do not allocate space for location maps in the case of a |
| 521 | // single-entry location catalog, as it is useless. The only valid |
| 522 | // entry index is 0; |
| 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | // The bit offset of the beginning of the map locations. |
| 527 | size_t map_locations_offset_in_bits = |
| 528 | GetLocationMappingDataOffset(number_of_dex_registers) * kBitsPerByte; |
| 529 | size_t index_in_dex_register_map = GetIndexInDexRegisterMap(dex_register_number); |
| 530 | DCHECK_LT(index_in_dex_register_map, GetNumberOfLiveDexRegisters(number_of_dex_registers)); |
| 531 | // The bit size of an entry. |
| 532 | size_t map_entry_size_in_bits = SingleEntrySizeInBits(number_of_location_catalog_entries); |
| 533 | // The bit offset where `index_in_dex_register_map` is located. |
| 534 | size_t entry_offset_in_bits = |
| 535 | map_locations_offset_in_bits + index_in_dex_register_map * map_entry_size_in_bits; |
| 536 | size_t location_catalog_entry_index = |
| 537 | region_.LoadBits(entry_offset_in_bits, map_entry_size_in_bits); |
| 538 | DCHECK_LT(location_catalog_entry_index, number_of_location_catalog_entries); |
| 539 | return location_catalog_entry_index; |
| 540 | } |
| 541 | |
| 542 | // Map entry at `index_in_dex_register_map` to `location_catalog_entry_index`. |
| 543 | void SetLocationCatalogEntryIndex(size_t index_in_dex_register_map, |
| 544 | size_t location_catalog_entry_index, |
| 545 | uint16_t number_of_dex_registers, |
| 546 | size_t number_of_location_catalog_entries) { |
| 547 | DCHECK_LT(index_in_dex_register_map, GetNumberOfLiveDexRegisters(number_of_dex_registers)); |
| 548 | DCHECK_LT(location_catalog_entry_index, number_of_location_catalog_entries); |
| 549 | |
| 550 | if (number_of_location_catalog_entries == 1) { |
| 551 | // We do not allocate space for location maps in the case of a |
| 552 | // single-entry location catalog, as it is useless. |
| 553 | return; |
| 554 | } |
| 555 | |
| 556 | // The bit offset of the beginning of the map locations. |
| 557 | size_t map_locations_offset_in_bits = |
| 558 | GetLocationMappingDataOffset(number_of_dex_registers) * kBitsPerByte; |
| 559 | // The bit size of an entry. |
| 560 | size_t map_entry_size_in_bits = SingleEntrySizeInBits(number_of_location_catalog_entries); |
| 561 | // The bit offset where `index_in_dex_register_map` is located. |
| 562 | size_t entry_offset_in_bits = |
| 563 | map_locations_offset_in_bits + index_in_dex_register_map * map_entry_size_in_bits; |
| 564 | region_.StoreBits(entry_offset_in_bits, location_catalog_entry_index, map_entry_size_in_bits); |
| 565 | } |
| 566 | |
| 567 | void SetLiveBitMask(uint16_t number_of_dex_registers, |
| 568 | const BitVector& live_dex_registers_mask) { |
| 569 | size_t live_bit_mask_offset_in_bits = GetLiveBitMaskOffset() * kBitsPerByte; |
| 570 | for (uint16_t i = 0; i < number_of_dex_registers; ++i) { |
| 571 | region_.StoreBit(live_bit_mask_offset_in_bits + i, live_dex_registers_mask.IsBitSet(i)); |
| 572 | } |
| 573 | } |
| 574 | |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 575 | ALWAYS_INLINE bool IsDexRegisterLive(uint16_t dex_register_number) const { |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 576 | size_t live_bit_mask_offset_in_bits = GetLiveBitMaskOffset() * kBitsPerByte; |
| 577 | return region_.LoadBit(live_bit_mask_offset_in_bits + dex_register_number); |
| 578 | } |
| 579 | |
| 580 | size_t GetNumberOfLiveDexRegisters(uint16_t number_of_dex_registers) const { |
| 581 | size_t number_of_live_dex_registers = 0; |
| 582 | for (size_t i = 0; i < number_of_dex_registers; ++i) { |
| 583 | if (IsDexRegisterLive(i)) { |
| 584 | ++number_of_live_dex_registers; |
| 585 | } |
| 586 | } |
| 587 | return number_of_live_dex_registers; |
| 588 | } |
| 589 | |
| 590 | static size_t GetLiveBitMaskOffset() { |
| 591 | return kFixedSize; |
| 592 | } |
| 593 | |
| 594 | // Compute the size of the live register bit mask (in bytes), for a |
| 595 | // method having `number_of_dex_registers` Dex registers. |
| 596 | static size_t GetLiveBitMaskSize(uint16_t number_of_dex_registers) { |
| 597 | return RoundUp(number_of_dex_registers, kBitsPerByte) / kBitsPerByte; |
| 598 | } |
| 599 | |
| 600 | static size_t GetLocationMappingDataOffset(uint16_t number_of_dex_registers) { |
| 601 | return GetLiveBitMaskOffset() + GetLiveBitMaskSize(number_of_dex_registers); |
| 602 | } |
| 603 | |
| 604 | size_t GetLocationMappingDataSize(uint16_t number_of_dex_registers, |
| 605 | size_t number_of_location_catalog_entries) const { |
| 606 | size_t location_mapping_data_size_in_bits = |
| 607 | GetNumberOfLiveDexRegisters(number_of_dex_registers) |
| 608 | * SingleEntrySizeInBits(number_of_location_catalog_entries); |
| 609 | return RoundUp(location_mapping_data_size_in_bits, kBitsPerByte) / kBitsPerByte; |
| 610 | } |
| 611 | |
| 612 | // Return the size of a map entry in bits. Note that if |
| 613 | // `number_of_location_catalog_entries` equals 1, this function returns 0, |
| 614 | // which is fine, as there is no need to allocate a map for a |
| 615 | // single-entry location catalog; the only valid location catalog entry index |
| 616 | // for a live register in this case is 0 and there is no need to |
| 617 | // store it. |
| 618 | static size_t SingleEntrySizeInBits(size_t number_of_location_catalog_entries) { |
| 619 | // Handle the case of 0, as we cannot pass 0 to art::WhichPowerOf2. |
| 620 | return number_of_location_catalog_entries == 0 |
| 621 | ? 0u |
| 622 | : WhichPowerOf2(RoundUpToPowerOfTwo(number_of_location_catalog_entries)); |
| 623 | } |
| 624 | |
| 625 | // Return the size of the DexRegisterMap object, in bytes. |
| 626 | size_t Size() const { |
David Srbecky | 68fefac | 2018-05-10 17:49:33 +0100 | [diff] [blame] | 627 | return BitsToBytesRoundUp(region_.size_in_bits()); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 630 | void Dump(VariableIndentationOutputStream* vios, |
| 631 | const CodeInfo& code_info, uint16_t number_of_dex_registers) const; |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 632 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 633 | private: |
| 634 | // Return the index in the Dex register map corresponding to the Dex |
| 635 | // register number `dex_register_number`. |
| 636 | size_t GetIndexInDexRegisterMap(uint16_t dex_register_number) const { |
| 637 | if (!IsDexRegisterLive(dex_register_number)) { |
| 638 | return kInvalidIndexInDexRegisterMap; |
| 639 | } |
| 640 | return GetNumberOfLiveDexRegisters(dex_register_number); |
| 641 | } |
| 642 | |
| 643 | // Special (invalid) Dex register map entry index meaning that there |
| 644 | // is no index in the map for a given Dex register (i.e., it must |
| 645 | // have been mapped to a DexRegisterLocation::Kind::kNone location). |
| 646 | static constexpr size_t kInvalidIndexInDexRegisterMap = -1; |
| 647 | |
| 648 | static constexpr int kFixedSize = 0; |
| 649 | |
David Srbecky | 68fefac | 2018-05-10 17:49:33 +0100 | [diff] [blame] | 650 | BitMemoryRegion region_; |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 651 | |
| 652 | friend class CodeInfo; |
| 653 | friend class StackMapStream; |
| 654 | }; |
| 655 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 656 | // Represents bit range of bit-packed integer field. |
| 657 | // We reuse the idea from ULEB128p1 to support encoding of -1 (aka 0xFFFFFFFF). |
| 658 | // If min_value is set to -1, we implicitly subtract one from any loaded value, |
| 659 | // and add one to any stored value. This is generalized to any negative values. |
| 660 | // In other words, min_value acts as a base and the stored value is added to it. |
| 661 | struct FieldEncoding { |
| 662 | FieldEncoding(size_t start_offset, size_t end_offset, int32_t min_value = 0) |
| 663 | : start_offset_(start_offset), end_offset_(end_offset), min_value_(min_value) { |
| 664 | DCHECK_LE(start_offset_, end_offset_); |
| 665 | DCHECK_LE(BitSize(), 32u); |
| 666 | } |
| 667 | |
| 668 | ALWAYS_INLINE size_t BitSize() const { return end_offset_ - start_offset_; } |
| 669 | |
Mathieu Chartier | 12f1b99 | 2017-01-19 18:00:45 -0800 | [diff] [blame] | 670 | template <typename Region> |
| 671 | ALWAYS_INLINE int32_t Load(const Region& region) const { |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 672 | DCHECK_LE(end_offset_, region.size_in_bits()); |
Mathieu Chartier | 3ceedc0 | 2017-01-25 11:11:02 -0800 | [diff] [blame] | 673 | return static_cast<int32_t>(region.LoadBits(start_offset_, BitSize())) + min_value_; |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Mathieu Chartier | 12f1b99 | 2017-01-19 18:00:45 -0800 | [diff] [blame] | 676 | template <typename Region> |
| 677 | ALWAYS_INLINE void Store(Region region, int32_t value) const { |
David Srbecky | 68fefac | 2018-05-10 17:49:33 +0100 | [diff] [blame] | 678 | region.StoreBits(start_offset_, static_cast<uint32_t>(value - min_value_), BitSize()); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 679 | DCHECK_EQ(Load(region), value); |
| 680 | } |
| 681 | |
| 682 | private: |
| 683 | size_t start_offset_; |
| 684 | size_t end_offset_; |
| 685 | int32_t min_value_; |
| 686 | }; |
| 687 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 688 | class StackMapEncoding { |
| 689 | public: |
Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 690 | StackMapEncoding() |
| 691 | : dex_pc_bit_offset_(0), |
| 692 | dex_register_map_bit_offset_(0), |
| 693 | inline_info_bit_offset_(0), |
| 694 | register_mask_index_bit_offset_(0), |
| 695 | stack_mask_index_bit_offset_(0), |
| 696 | total_bit_size_(0) {} |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 697 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 698 | // Set stack map bit layout based on given sizes. |
Mathieu Chartier | 12f1b99 | 2017-01-19 18:00:45 -0800 | [diff] [blame] | 699 | // Returns the size of stack map in bits. |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 700 | size_t SetFromSizes(size_t native_pc_max, |
| 701 | size_t dex_pc_max, |
| 702 | size_t dex_register_map_size, |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 703 | size_t number_of_inline_info, |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 704 | size_t number_of_register_masks, |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 705 | size_t number_of_stack_masks) { |
| 706 | total_bit_size_ = 0; |
| 707 | DCHECK_EQ(kNativePcBitOffset, total_bit_size_); |
| 708 | total_bit_size_ += MinimumBitsToStore(native_pc_max); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 709 | |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 710 | dex_pc_bit_offset_ = total_bit_size_; |
Vladimir Marko | 92f7f3c | 2017-10-31 11:38:30 +0000 | [diff] [blame] | 711 | // Note: We're not encoding the dex pc if there is none. That's the case |
| 712 | // for an intrinsified native method, such as String.charAt(). |
| 713 | if (dex_pc_max != dex::kDexNoIndex) { |
| 714 | total_bit_size_ += MinimumBitsToStore(1 /* kNoDexPc */ + dex_pc_max); |
| 715 | } |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 716 | |
| 717 | // We also need +1 for kNoDexRegisterMap, but since the size is strictly |
| 718 | // greater than any offset we might try to encode, we already implicitly have it. |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 719 | dex_register_map_bit_offset_ = total_bit_size_; |
| 720 | total_bit_size_ += MinimumBitsToStore(dex_register_map_size); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 721 | |
| 722 | // We also need +1 for kNoInlineInfo, but since the inline_info_size is strictly |
| 723 | // greater than the offset we might try to encode, we already implicitly have it. |
| 724 | // If inline_info_size is zero, we can encode only kNoInlineInfo (in zero bits). |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 725 | inline_info_bit_offset_ = total_bit_size_; |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 726 | total_bit_size_ += MinimumBitsToStore(number_of_inline_info); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 727 | |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 728 | register_mask_index_bit_offset_ = total_bit_size_; |
| 729 | total_bit_size_ += MinimumBitsToStore(number_of_register_masks); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 730 | |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 731 | stack_mask_index_bit_offset_ = total_bit_size_; |
| 732 | total_bit_size_ += MinimumBitsToStore(number_of_stack_masks); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 733 | |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 734 | return total_bit_size_; |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 735 | } |
| 736 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 737 | ALWAYS_INLINE FieldEncoding GetNativePcEncoding() const { |
| 738 | return FieldEncoding(kNativePcBitOffset, dex_pc_bit_offset_); |
| 739 | } |
| 740 | ALWAYS_INLINE FieldEncoding GetDexPcEncoding() const { |
| 741 | return FieldEncoding(dex_pc_bit_offset_, dex_register_map_bit_offset_, -1 /* min_value */); |
| 742 | } |
| 743 | ALWAYS_INLINE FieldEncoding GetDexRegisterMapEncoding() const { |
| 744 | return FieldEncoding(dex_register_map_bit_offset_, inline_info_bit_offset_, -1 /* min_value */); |
| 745 | } |
| 746 | ALWAYS_INLINE FieldEncoding GetInlineInfoEncoding() const { |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 747 | return FieldEncoding(inline_info_bit_offset_, |
| 748 | register_mask_index_bit_offset_, |
| 749 | -1 /* min_value */); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 750 | } |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 751 | ALWAYS_INLINE FieldEncoding GetRegisterMaskIndexEncoding() const { |
| 752 | return FieldEncoding(register_mask_index_bit_offset_, stack_mask_index_bit_offset_); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 753 | } |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 754 | ALWAYS_INLINE FieldEncoding GetStackMaskIndexEncoding() const { |
| 755 | return FieldEncoding(stack_mask_index_bit_offset_, total_bit_size_); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 756 | } |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 757 | ALWAYS_INLINE size_t BitSize() const { |
| 758 | return total_bit_size_; |
Mathieu Chartier | 12f1b99 | 2017-01-19 18:00:45 -0800 | [diff] [blame] | 759 | } |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 760 | |
Mathieu Chartier | c420a80 | 2017-02-14 15:16:19 -0800 | [diff] [blame] | 761 | // Encode the encoding into the vector. |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 762 | template<typename Vector> |
| 763 | void Encode(Vector* dest) const { |
| 764 | static_assert(alignof(StackMapEncoding) == 1, "Should not require alignment"); |
| 765 | const uint8_t* ptr = reinterpret_cast<const uint8_t*>(this); |
| 766 | dest->insert(dest->end(), ptr, ptr + sizeof(*this)); |
| 767 | } |
| 768 | |
Mathieu Chartier | c420a80 | 2017-02-14 15:16:19 -0800 | [diff] [blame] | 769 | // Decode the encoding from a pointer, updates the pointer. |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 770 | void Decode(const uint8_t** ptr) { |
| 771 | *this = *reinterpret_cast<const StackMapEncoding*>(*ptr); |
| 772 | *ptr += sizeof(*this); |
| 773 | } |
| 774 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 775 | void Dump(VariableIndentationOutputStream* vios) const; |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 776 | |
| 777 | private: |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 778 | static constexpr size_t kNativePcBitOffset = 0; |
| 779 | uint8_t dex_pc_bit_offset_; |
| 780 | uint8_t dex_register_map_bit_offset_; |
| 781 | uint8_t inline_info_bit_offset_; |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 782 | uint8_t register_mask_index_bit_offset_; |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 783 | uint8_t stack_mask_index_bit_offset_; |
| 784 | uint8_t total_bit_size_; |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 785 | }; |
| 786 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 787 | /** |
| 788 | * A Stack Map holds compilation information for a specific PC necessary for: |
| 789 | * - Mapping it to a dex PC, |
| 790 | * - Knowing which stack entries are objects, |
| 791 | * - Knowing which registers hold objects, |
| 792 | * - Knowing the inlining information, |
| 793 | * - Knowing the values of dex registers. |
| 794 | * |
| 795 | * The information is of the form: |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 796 | * |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 797 | * [native_pc_offset, dex_pc, dex_register_map_offset, inlining_info_index, register_mask_index, |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 798 | * stack_mask_index]. |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 799 | */ |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 800 | class StackMap { |
| 801 | public: |
Nicolas Geoffray | e12997f | 2015-05-22 14:01:33 +0100 | [diff] [blame] | 802 | StackMap() {} |
Mathieu Chartier | 12f1b99 | 2017-01-19 18:00:45 -0800 | [diff] [blame] | 803 | explicit StackMap(BitMemoryRegion region) : region_(region) {} |
Nicolas Geoffray | e12997f | 2015-05-22 14:01:33 +0100 | [diff] [blame] | 804 | |
David Srbecky | 68fefac | 2018-05-10 17:49:33 +0100 | [diff] [blame] | 805 | ALWAYS_INLINE bool IsValid() const { return region_.IsValid(); } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 806 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 807 | ALWAYS_INLINE uint32_t GetDexPc(const StackMapEncoding& encoding) const { |
| 808 | return encoding.GetDexPcEncoding().Load(region_); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 809 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 810 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 811 | ALWAYS_INLINE void SetDexPc(const StackMapEncoding& encoding, uint32_t dex_pc) { |
| 812 | encoding.GetDexPcEncoding().Store(region_, dex_pc); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 813 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 814 | |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 815 | ALWAYS_INLINE uint32_t GetNativePcOffset(const StackMapEncoding& encoding, |
| 816 | InstructionSet instruction_set) const { |
| 817 | CodeOffset offset( |
| 818 | CodeOffset::FromCompressedOffset(encoding.GetNativePcEncoding().Load(region_))); |
| 819 | return offset.Uint32Value(instruction_set); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 820 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 821 | |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 822 | ALWAYS_INLINE void SetNativePcCodeOffset(const StackMapEncoding& encoding, |
| 823 | CodeOffset native_pc_offset) { |
| 824 | encoding.GetNativePcEncoding().Store(region_, native_pc_offset.CompressedValue()); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 825 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 826 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 827 | ALWAYS_INLINE uint32_t GetDexRegisterMapOffset(const StackMapEncoding& encoding) const { |
| 828 | return encoding.GetDexRegisterMapEncoding().Load(region_); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 829 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 830 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 831 | ALWAYS_INLINE void SetDexRegisterMapOffset(const StackMapEncoding& encoding, uint32_t offset) { |
| 832 | encoding.GetDexRegisterMapEncoding().Store(region_, offset); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 833 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 834 | |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 835 | ALWAYS_INLINE uint32_t GetInlineInfoIndex(const StackMapEncoding& encoding) const { |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 836 | return encoding.GetInlineInfoEncoding().Load(region_); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 837 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 838 | |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 839 | ALWAYS_INLINE void SetInlineInfoIndex(const StackMapEncoding& encoding, uint32_t index) { |
| 840 | encoding.GetInlineInfoEncoding().Store(region_, index); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 841 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 842 | |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 843 | ALWAYS_INLINE uint32_t GetRegisterMaskIndex(const StackMapEncoding& encoding) const { |
| 844 | return encoding.GetRegisterMaskIndexEncoding().Load(region_); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 845 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 846 | |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 847 | ALWAYS_INLINE void SetRegisterMaskIndex(const StackMapEncoding& encoding, uint32_t mask) { |
| 848 | encoding.GetRegisterMaskIndexEncoding().Store(region_, mask); |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 849 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 850 | |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 851 | ALWAYS_INLINE uint32_t GetStackMaskIndex(const StackMapEncoding& encoding) const { |
| 852 | return encoding.GetStackMaskIndexEncoding().Load(region_); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 853 | } |
| 854 | |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 855 | ALWAYS_INLINE void SetStackMaskIndex(const StackMapEncoding& encoding, uint32_t mask) { |
| 856 | encoding.GetStackMaskIndexEncoding().Store(region_, mask); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | ALWAYS_INLINE bool HasDexRegisterMap(const StackMapEncoding& encoding) const { |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 860 | return GetDexRegisterMapOffset(encoding) != kNoDexRegisterMap; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 861 | } |
| 862 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 863 | ALWAYS_INLINE bool HasInlineInfo(const StackMapEncoding& encoding) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 864 | return GetInlineInfoIndex(encoding) != kNoInlineInfo; |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 865 | } |
| 866 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 867 | ALWAYS_INLINE bool Equals(const StackMap& other) const { |
David Srbecky | 68fefac | 2018-05-10 17:49:33 +0100 | [diff] [blame] | 868 | return region_.Equals(other.region_); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 869 | } |
| 870 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 871 | void Dump(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 872 | const CodeInfo& code_info, |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 873 | const CodeInfoEncoding& encoding, |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 874 | const MethodInfo& method_info, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 875 | uint32_t code_offset, |
| 876 | uint16_t number_of_dex_registers, |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 877 | InstructionSet instruction_set, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 878 | const std::string& header_suffix = "") const; |
| 879 | |
Roland Levillain | 442b46a | 2015-02-18 16:54:21 +0000 | [diff] [blame] | 880 | // Special (invalid) offset for the DexRegisterMapOffset field meaning |
| 881 | // that there is no Dex register map for this stack map. |
| 882 | static constexpr uint32_t kNoDexRegisterMap = -1; |
| 883 | |
| 884 | // Special (invalid) offset for the InlineDescriptorOffset field meaning |
| 885 | // that there is no inline info for this stack map. |
| 886 | static constexpr uint32_t kNoInlineInfo = -1; |
| 887 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 888 | private: |
Nicolas Geoffray | 896f8f7 | 2015-03-30 15:44:25 +0100 | [diff] [blame] | 889 | static constexpr int kFixedSize = 0; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 890 | |
Mathieu Chartier | 12f1b99 | 2017-01-19 18:00:45 -0800 | [diff] [blame] | 891 | BitMemoryRegion region_; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 892 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 893 | friend class StackMapStream; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 894 | }; |
| 895 | |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 896 | class InlineInfoEncoding { |
| 897 | public: |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 898 | void SetFromSizes(size_t method_index_idx_max, |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 899 | size_t dex_pc_max, |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 900 | size_t extra_data_max, |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 901 | size_t dex_register_map_size) { |
| 902 | total_bit_size_ = kMethodIndexBitOffset; |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 903 | total_bit_size_ += MinimumBitsToStore(method_index_idx_max); |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 904 | |
| 905 | dex_pc_bit_offset_ = dchecked_integral_cast<uint8_t>(total_bit_size_); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 906 | // Note: We're not encoding the dex pc if there is none. That's the case |
| 907 | // for an intrinsified native method, such as String.charAt(). |
Andreas Gampe | 04c6ab9 | 2017-06-08 21:49:14 -0700 | [diff] [blame] | 908 | if (dex_pc_max != dex::kDexNoIndex) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 909 | total_bit_size_ += MinimumBitsToStore(1 /* kNoDexPc */ + dex_pc_max); |
| 910 | } |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 911 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 912 | extra_data_bit_offset_ = dchecked_integral_cast<uint8_t>(total_bit_size_); |
| 913 | total_bit_size_ += MinimumBitsToStore(extra_data_max); |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 914 | |
| 915 | // We also need +1 for kNoDexRegisterMap, but since the size is strictly |
| 916 | // greater than any offset we might try to encode, we already implicitly have it. |
| 917 | dex_register_map_bit_offset_ = dchecked_integral_cast<uint8_t>(total_bit_size_); |
| 918 | total_bit_size_ += MinimumBitsToStore(dex_register_map_size); |
| 919 | } |
| 920 | |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 921 | ALWAYS_INLINE FieldEncoding GetMethodIndexIdxEncoding() const { |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 922 | return FieldEncoding(kMethodIndexBitOffset, dex_pc_bit_offset_); |
| 923 | } |
| 924 | ALWAYS_INLINE FieldEncoding GetDexPcEncoding() const { |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 925 | return FieldEncoding(dex_pc_bit_offset_, extra_data_bit_offset_, -1 /* min_value */); |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 926 | } |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 927 | ALWAYS_INLINE FieldEncoding GetExtraDataEncoding() const { |
| 928 | return FieldEncoding(extra_data_bit_offset_, dex_register_map_bit_offset_); |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 929 | } |
| 930 | ALWAYS_INLINE FieldEncoding GetDexRegisterMapEncoding() const { |
| 931 | return FieldEncoding(dex_register_map_bit_offset_, total_bit_size_, -1 /* min_value */); |
| 932 | } |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 933 | ALWAYS_INLINE size_t BitSize() const { |
| 934 | return total_bit_size_; |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | void Dump(VariableIndentationOutputStream* vios) const; |
| 938 | |
Mathieu Chartier | c420a80 | 2017-02-14 15:16:19 -0800 | [diff] [blame] | 939 | // Encode the encoding into the vector. |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 940 | template<typename Vector> |
| 941 | void Encode(Vector* dest) const { |
| 942 | static_assert(alignof(InlineInfoEncoding) == 1, "Should not require alignment"); |
| 943 | const uint8_t* ptr = reinterpret_cast<const uint8_t*>(this); |
| 944 | dest->insert(dest->end(), ptr, ptr + sizeof(*this)); |
| 945 | } |
| 946 | |
Mathieu Chartier | c420a80 | 2017-02-14 15:16:19 -0800 | [diff] [blame] | 947 | // Decode the encoding from a pointer, updates the pointer. |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 948 | void Decode(const uint8_t** ptr) { |
| 949 | *this = *reinterpret_cast<const InlineInfoEncoding*>(*ptr); |
| 950 | *ptr += sizeof(*this); |
| 951 | } |
| 952 | |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 953 | private: |
| 954 | static constexpr uint8_t kIsLastBitOffset = 0; |
| 955 | static constexpr uint8_t kMethodIndexBitOffset = 1; |
| 956 | uint8_t dex_pc_bit_offset_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 957 | uint8_t extra_data_bit_offset_; |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 958 | uint8_t dex_register_map_bit_offset_; |
| 959 | uint8_t total_bit_size_; |
| 960 | }; |
| 961 | |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 962 | /** |
| 963 | * Inline information for a specific PC. The information is of the form: |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 964 | * |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 965 | * [is_last, |
| 966 | * method_index (or ArtMethod high bits), |
| 967 | * dex_pc, |
| 968 | * extra_data (ArtMethod low bits or 1), |
| 969 | * dex_register_map_offset]+. |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 970 | */ |
| 971 | class InlineInfo { |
| 972 | public: |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 973 | explicit InlineInfo(BitMemoryRegion region) : region_(region) {} |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 974 | |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 975 | ALWAYS_INLINE uint32_t GetDepth(const InlineInfoEncoding& encoding) const { |
| 976 | size_t depth = 0; |
| 977 | while (!GetRegionAtDepth(encoding, depth++).LoadBit(0)) { } // Check is_last bit. |
| 978 | return depth; |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 979 | } |
| 980 | |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 981 | ALWAYS_INLINE void SetDepth(const InlineInfoEncoding& encoding, uint32_t depth) { |
| 982 | DCHECK_GT(depth, 0u); |
| 983 | for (size_t d = 0; d < depth; ++d) { |
| 984 | GetRegionAtDepth(encoding, d).StoreBit(0, d == depth - 1); // Set is_last bit. |
| 985 | } |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 986 | } |
| 987 | |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 988 | ALWAYS_INLINE uint32_t GetMethodIndexIdxAtDepth(const InlineInfoEncoding& encoding, |
| 989 | uint32_t depth) const { |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 990 | DCHECK(!EncodesArtMethodAtDepth(encoding, depth)); |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 991 | return encoding.GetMethodIndexIdxEncoding().Load(GetRegionAtDepth(encoding, depth)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 992 | } |
| 993 | |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 994 | ALWAYS_INLINE void SetMethodIndexIdxAtDepth(const InlineInfoEncoding& encoding, |
| 995 | uint32_t depth, |
| 996 | uint32_t index) { |
| 997 | encoding.GetMethodIndexIdxEncoding().Store(GetRegionAtDepth(encoding, depth), index); |
| 998 | } |
| 999 | |
| 1000 | |
| 1001 | ALWAYS_INLINE uint32_t GetMethodIndexAtDepth(const InlineInfoEncoding& encoding, |
| 1002 | const MethodInfo& method_info, |
| 1003 | uint32_t depth) const { |
| 1004 | return method_info.GetMethodIndex(GetMethodIndexIdxAtDepth(encoding, depth)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 1005 | } |
| 1006 | |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 1007 | ALWAYS_INLINE uint32_t GetDexPcAtDepth(const InlineInfoEncoding& encoding, |
| 1008 | uint32_t depth) const { |
| 1009 | return encoding.GetDexPcEncoding().Load(GetRegionAtDepth(encoding, depth)); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 1012 | ALWAYS_INLINE void SetDexPcAtDepth(const InlineInfoEncoding& encoding, |
| 1013 | uint32_t depth, |
| 1014 | uint32_t dex_pc) { |
| 1015 | encoding.GetDexPcEncoding().Store(GetRegionAtDepth(encoding, depth), dex_pc); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1016 | } |
| 1017 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1018 | ALWAYS_INLINE bool EncodesArtMethodAtDepth(const InlineInfoEncoding& encoding, |
| 1019 | uint32_t depth) const { |
| 1020 | return (encoding.GetExtraDataEncoding().Load(GetRegionAtDepth(encoding, depth)) & 1) == 0; |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1023 | ALWAYS_INLINE void SetExtraDataAtDepth(const InlineInfoEncoding& encoding, |
| 1024 | uint32_t depth, |
| 1025 | uint32_t extra_data) { |
| 1026 | encoding.GetExtraDataEncoding().Store(GetRegionAtDepth(encoding, depth), extra_data); |
| 1027 | } |
| 1028 | |
| 1029 | ALWAYS_INLINE ArtMethod* GetArtMethodAtDepth(const InlineInfoEncoding& encoding, |
| 1030 | uint32_t depth) const { |
| 1031 | uint32_t low_bits = encoding.GetExtraDataEncoding().Load(GetRegionAtDepth(encoding, depth)); |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 1032 | uint32_t high_bits = encoding.GetMethodIndexIdxEncoding().Load( |
| 1033 | GetRegionAtDepth(encoding, depth)); |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1034 | if (high_bits == 0) { |
| 1035 | return reinterpret_cast<ArtMethod*>(low_bits); |
| 1036 | } else { |
| 1037 | uint64_t address = high_bits; |
| 1038 | address = address << 32; |
| 1039 | return reinterpret_cast<ArtMethod*>(address | low_bits); |
| 1040 | } |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 1041 | } |
| 1042 | |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 1043 | ALWAYS_INLINE uint32_t GetDexRegisterMapOffsetAtDepth(const InlineInfoEncoding& encoding, |
| 1044 | uint32_t depth) const { |
| 1045 | return encoding.GetDexRegisterMapEncoding().Load(GetRegionAtDepth(encoding, depth)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 1048 | ALWAYS_INLINE void SetDexRegisterMapOffsetAtDepth(const InlineInfoEncoding& encoding, |
| 1049 | uint32_t depth, |
| 1050 | uint32_t offset) { |
| 1051 | encoding.GetDexRegisterMapEncoding().Store(GetRegionAtDepth(encoding, depth), offset); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 1052 | } |
| 1053 | |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 1054 | ALWAYS_INLINE bool HasDexRegisterMapAtDepth(const InlineInfoEncoding& encoding, |
| 1055 | uint32_t depth) const { |
| 1056 | return GetDexRegisterMapOffsetAtDepth(encoding, depth) != StackMap::kNoDexRegisterMap; |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 1057 | } |
| 1058 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1059 | void Dump(VariableIndentationOutputStream* vios, |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 1060 | const CodeInfo& info, |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 1061 | const MethodInfo& method_info, |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 1062 | uint16_t* number_of_dex_registers) const; |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 1063 | |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 1064 | private: |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1065 | ALWAYS_INLINE BitMemoryRegion GetRegionAtDepth(const InlineInfoEncoding& encoding, |
| 1066 | uint32_t depth) const { |
| 1067 | size_t entry_size = encoding.BitSize(); |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 1068 | DCHECK_GT(entry_size, 0u); |
| 1069 | return region_.Subregion(depth * entry_size, entry_size); |
| 1070 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1071 | |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1072 | BitMemoryRegion region_; |
| 1073 | }; |
| 1074 | |
| 1075 | // Bit sized region encoding, may be more than 255 bits. |
| 1076 | class BitRegionEncoding { |
| 1077 | public: |
| 1078 | uint32_t num_bits = 0; |
| 1079 | |
| 1080 | ALWAYS_INLINE size_t BitSize() const { |
| 1081 | return num_bits; |
| 1082 | } |
| 1083 | |
| 1084 | template<typename Vector> |
| 1085 | void Encode(Vector* dest) const { |
| 1086 | EncodeUnsignedLeb128(dest, num_bits); // Use leb in case num_bits is greater than 255. |
| 1087 | } |
| 1088 | |
| 1089 | void Decode(const uint8_t** ptr) { |
| 1090 | num_bits = DecodeUnsignedLeb128(ptr); |
| 1091 | } |
| 1092 | }; |
| 1093 | |
| 1094 | // A table of bit sized encodings. |
| 1095 | template <typename Encoding> |
| 1096 | struct BitEncodingTable { |
| 1097 | static constexpr size_t kInvalidOffset = static_cast<size_t>(-1); |
| 1098 | // How the encoding is laid out (serialized). |
| 1099 | Encoding encoding; |
| 1100 | |
| 1101 | // Number of entries in the table (serialized). |
| 1102 | size_t num_entries; |
| 1103 | |
| 1104 | // Bit offset for the base of the table (computed). |
| 1105 | size_t bit_offset = kInvalidOffset; |
| 1106 | |
| 1107 | template<typename Vector> |
| 1108 | void Encode(Vector* dest) const { |
| 1109 | EncodeUnsignedLeb128(dest, num_entries); |
| 1110 | encoding.Encode(dest); |
| 1111 | } |
| 1112 | |
| 1113 | ALWAYS_INLINE void Decode(const uint8_t** ptr) { |
| 1114 | num_entries = DecodeUnsignedLeb128(ptr); |
| 1115 | encoding.Decode(ptr); |
| 1116 | } |
| 1117 | |
| 1118 | // Set the bit offset in the table and adds the space used by the table to offset. |
| 1119 | void UpdateBitOffset(size_t* offset) { |
| 1120 | DCHECK(offset != nullptr); |
| 1121 | bit_offset = *offset; |
| 1122 | *offset += encoding.BitSize() * num_entries; |
| 1123 | } |
| 1124 | |
| 1125 | // Return the bit region for the map at index i. |
| 1126 | ALWAYS_INLINE BitMemoryRegion BitRegion(MemoryRegion region, size_t index) const { |
| 1127 | DCHECK_NE(bit_offset, kInvalidOffset) << "Invalid table offset"; |
| 1128 | DCHECK_LT(index, num_entries); |
| 1129 | const size_t map_size = encoding.BitSize(); |
| 1130 | return BitMemoryRegion(region, bit_offset + index * map_size, map_size); |
| 1131 | } |
| 1132 | }; |
| 1133 | |
| 1134 | // A byte sized table of possible variable sized encodings. |
| 1135 | struct ByteSizedTable { |
| 1136 | static constexpr size_t kInvalidOffset = static_cast<size_t>(-1); |
| 1137 | |
| 1138 | // Number of entries in the table (serialized). |
| 1139 | size_t num_entries = 0; |
| 1140 | |
| 1141 | // Number of bytes of the table (serialized). |
| 1142 | size_t num_bytes; |
| 1143 | |
| 1144 | // Bit offset for the base of the table (computed). |
| 1145 | size_t byte_offset = kInvalidOffset; |
| 1146 | |
| 1147 | template<typename Vector> |
| 1148 | void Encode(Vector* dest) const { |
| 1149 | EncodeUnsignedLeb128(dest, num_entries); |
| 1150 | EncodeUnsignedLeb128(dest, num_bytes); |
| 1151 | } |
| 1152 | |
| 1153 | ALWAYS_INLINE void Decode(const uint8_t** ptr) { |
| 1154 | num_entries = DecodeUnsignedLeb128(ptr); |
| 1155 | num_bytes = DecodeUnsignedLeb128(ptr); |
| 1156 | } |
| 1157 | |
| 1158 | // Set the bit offset of the table. Adds the total bit size of the table to offset. |
| 1159 | void UpdateBitOffset(size_t* offset) { |
| 1160 | DCHECK(offset != nullptr); |
| 1161 | DCHECK_ALIGNED(*offset, kBitsPerByte); |
| 1162 | byte_offset = *offset / kBitsPerByte; |
| 1163 | *offset += num_bytes * kBitsPerByte; |
| 1164 | } |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 1165 | }; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1166 | |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1167 | // Format is [native pc, invoke type, method index]. |
| 1168 | class InvokeInfoEncoding { |
| 1169 | public: |
| 1170 | void SetFromSizes(size_t native_pc_max, |
| 1171 | size_t invoke_type_max, |
| 1172 | size_t method_index_max) { |
| 1173 | total_bit_size_ = 0; |
| 1174 | DCHECK_EQ(kNativePcBitOffset, total_bit_size_); |
| 1175 | total_bit_size_ += MinimumBitsToStore(native_pc_max); |
| 1176 | invoke_type_bit_offset_ = total_bit_size_; |
| 1177 | total_bit_size_ += MinimumBitsToStore(invoke_type_max); |
| 1178 | method_index_bit_offset_ = total_bit_size_; |
| 1179 | total_bit_size_ += MinimumBitsToStore(method_index_max); |
| 1180 | } |
| 1181 | |
| 1182 | ALWAYS_INLINE FieldEncoding GetNativePcEncoding() const { |
| 1183 | return FieldEncoding(kNativePcBitOffset, invoke_type_bit_offset_); |
| 1184 | } |
| 1185 | |
| 1186 | ALWAYS_INLINE FieldEncoding GetInvokeTypeEncoding() const { |
| 1187 | return FieldEncoding(invoke_type_bit_offset_, method_index_bit_offset_); |
| 1188 | } |
| 1189 | |
| 1190 | ALWAYS_INLINE FieldEncoding GetMethodIndexEncoding() const { |
| 1191 | return FieldEncoding(method_index_bit_offset_, total_bit_size_); |
| 1192 | } |
| 1193 | |
| 1194 | ALWAYS_INLINE size_t BitSize() const { |
| 1195 | return total_bit_size_; |
| 1196 | } |
| 1197 | |
| 1198 | template<typename Vector> |
| 1199 | void Encode(Vector* dest) const { |
| 1200 | static_assert(alignof(InvokeInfoEncoding) == 1, "Should not require alignment"); |
| 1201 | const uint8_t* ptr = reinterpret_cast<const uint8_t*>(this); |
| 1202 | dest->insert(dest->end(), ptr, ptr + sizeof(*this)); |
| 1203 | } |
| 1204 | |
| 1205 | void Decode(const uint8_t** ptr) { |
| 1206 | *this = *reinterpret_cast<const InvokeInfoEncoding*>(*ptr); |
| 1207 | *ptr += sizeof(*this); |
| 1208 | } |
| 1209 | |
| 1210 | private: |
| 1211 | static constexpr uint8_t kNativePcBitOffset = 0; |
| 1212 | uint8_t invoke_type_bit_offset_; |
| 1213 | uint8_t method_index_bit_offset_; |
| 1214 | uint8_t total_bit_size_; |
| 1215 | }; |
| 1216 | |
| 1217 | class InvokeInfo { |
| 1218 | public: |
| 1219 | explicit InvokeInfo(BitMemoryRegion region) : region_(region) {} |
| 1220 | |
| 1221 | ALWAYS_INLINE uint32_t GetNativePcOffset(const InvokeInfoEncoding& encoding, |
| 1222 | InstructionSet instruction_set) const { |
| 1223 | CodeOffset offset( |
| 1224 | CodeOffset::FromCompressedOffset(encoding.GetNativePcEncoding().Load(region_))); |
| 1225 | return offset.Uint32Value(instruction_set); |
| 1226 | } |
| 1227 | |
| 1228 | ALWAYS_INLINE void SetNativePcCodeOffset(const InvokeInfoEncoding& encoding, |
| 1229 | CodeOffset native_pc_offset) { |
| 1230 | encoding.GetNativePcEncoding().Store(region_, native_pc_offset.CompressedValue()); |
| 1231 | } |
| 1232 | |
| 1233 | ALWAYS_INLINE uint32_t GetInvokeType(const InvokeInfoEncoding& encoding) const { |
| 1234 | return encoding.GetInvokeTypeEncoding().Load(region_); |
| 1235 | } |
| 1236 | |
| 1237 | ALWAYS_INLINE void SetInvokeType(const InvokeInfoEncoding& encoding, uint32_t invoke_type) { |
| 1238 | encoding.GetInvokeTypeEncoding().Store(region_, invoke_type); |
| 1239 | } |
| 1240 | |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 1241 | ALWAYS_INLINE uint32_t GetMethodIndexIdx(const InvokeInfoEncoding& encoding) const { |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1242 | return encoding.GetMethodIndexEncoding().Load(region_); |
| 1243 | } |
| 1244 | |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 1245 | ALWAYS_INLINE void SetMethodIndexIdx(const InvokeInfoEncoding& encoding, |
| 1246 | uint32_t method_index_idx) { |
| 1247 | encoding.GetMethodIndexEncoding().Store(region_, method_index_idx); |
| 1248 | } |
| 1249 | |
| 1250 | ALWAYS_INLINE uint32_t GetMethodIndex(const InvokeInfoEncoding& encoding, |
| 1251 | MethodInfo method_info) const { |
| 1252 | return method_info.GetMethodIndex(GetMethodIndexIdx(encoding)); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1253 | } |
| 1254 | |
David Srbecky | 68fefac | 2018-05-10 17:49:33 +0100 | [diff] [blame] | 1255 | bool IsValid() const { return region_.IsValid(); } |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1256 | |
| 1257 | private: |
| 1258 | BitMemoryRegion region_; |
| 1259 | }; |
| 1260 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1261 | // Most of the fields are encoded as ULEB128 to save space. |
| 1262 | struct CodeInfoEncoding { |
Andreas Gampe | 69489fa | 2017-06-08 18:03:25 -0700 | [diff] [blame] | 1263 | using SizeType = uint32_t; |
| 1264 | |
| 1265 | static constexpr SizeType kInvalidSize = std::numeric_limits<SizeType>::max(); |
| 1266 | |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1267 | // Byte sized tables go first to avoid unnecessary alignment bits. |
| 1268 | ByteSizedTable dex_register_map; |
| 1269 | ByteSizedTable location_catalog; |
| 1270 | BitEncodingTable<StackMapEncoding> stack_map; |
| 1271 | BitEncodingTable<BitRegionEncoding> register_mask; |
| 1272 | BitEncodingTable<BitRegionEncoding> stack_mask; |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1273 | BitEncodingTable<InvokeInfoEncoding> invoke_info; |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1274 | BitEncodingTable<InlineInfoEncoding> inline_info; |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1275 | |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1276 | CodeInfoEncoding() {} |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1277 | |
| 1278 | explicit CodeInfoEncoding(const void* data) { |
| 1279 | const uint8_t* ptr = reinterpret_cast<const uint8_t*>(data); |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1280 | dex_register_map.Decode(&ptr); |
| 1281 | location_catalog.Decode(&ptr); |
| 1282 | stack_map.Decode(&ptr); |
| 1283 | register_mask.Decode(&ptr); |
| 1284 | stack_mask.Decode(&ptr); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1285 | invoke_info.Decode(&ptr); |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1286 | if (stack_map.encoding.GetInlineInfoEncoding().BitSize() > 0) { |
| 1287 | inline_info.Decode(&ptr); |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 1288 | } else { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1289 | inline_info = BitEncodingTable<InlineInfoEncoding>(); |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 1290 | } |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1291 | cache_header_size = |
Andreas Gampe | 69489fa | 2017-06-08 18:03:25 -0700 | [diff] [blame] | 1292 | dchecked_integral_cast<SizeType>(ptr - reinterpret_cast<const uint8_t*>(data)); |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1293 | ComputeTableOffsets(); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
Mathieu Chartier | c420a80 | 2017-02-14 15:16:19 -0800 | [diff] [blame] | 1296 | // Compress is not const since it calculates cache_header_size. This is used by PrepareForFillIn. |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1297 | template<typename Vector> |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1298 | void Compress(Vector* dest) { |
| 1299 | dex_register_map.Encode(dest); |
| 1300 | location_catalog.Encode(dest); |
| 1301 | stack_map.Encode(dest); |
| 1302 | register_mask.Encode(dest); |
| 1303 | stack_mask.Encode(dest); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1304 | invoke_info.Encode(dest); |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1305 | if (stack_map.encoding.GetInlineInfoEncoding().BitSize() > 0) { |
| 1306 | inline_info.Encode(dest); |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 1307 | } |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1308 | cache_header_size = dest->size(); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1309 | } |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1310 | |
| 1311 | ALWAYS_INLINE void ComputeTableOffsets() { |
| 1312 | // Skip the header. |
| 1313 | size_t bit_offset = HeaderSize() * kBitsPerByte; |
| 1314 | // The byte tables must be aligned so they must go first. |
| 1315 | dex_register_map.UpdateBitOffset(&bit_offset); |
| 1316 | location_catalog.UpdateBitOffset(&bit_offset); |
| 1317 | // Other tables don't require alignment. |
| 1318 | stack_map.UpdateBitOffset(&bit_offset); |
| 1319 | register_mask.UpdateBitOffset(&bit_offset); |
| 1320 | stack_mask.UpdateBitOffset(&bit_offset); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1321 | invoke_info.UpdateBitOffset(&bit_offset); |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1322 | inline_info.UpdateBitOffset(&bit_offset); |
| 1323 | cache_non_header_size = RoundUp(bit_offset, kBitsPerByte) / kBitsPerByte - HeaderSize(); |
| 1324 | } |
| 1325 | |
| 1326 | ALWAYS_INLINE size_t HeaderSize() const { |
| 1327 | DCHECK_NE(cache_header_size, kInvalidSize) << "Uninitialized"; |
| 1328 | return cache_header_size; |
| 1329 | } |
| 1330 | |
| 1331 | ALWAYS_INLINE size_t NonHeaderSize() const { |
| 1332 | DCHECK_NE(cache_non_header_size, kInvalidSize) << "Uninitialized"; |
| 1333 | return cache_non_header_size; |
| 1334 | } |
| 1335 | |
| 1336 | private: |
| 1337 | // Computed fields (not serialized). |
Mathieu Chartier | c420a80 | 2017-02-14 15:16:19 -0800 | [diff] [blame] | 1338 | // Header size in bytes, cached to avoid needing to re-decoding the encoding in HeaderSize. |
Andreas Gampe | 69489fa | 2017-06-08 18:03:25 -0700 | [diff] [blame] | 1339 | SizeType cache_header_size = kInvalidSize; |
Mathieu Chartier | c420a80 | 2017-02-14 15:16:19 -0800 | [diff] [blame] | 1340 | // Non header size in bytes, cached to avoid needing to re-decoding the encoding in NonHeaderSize. |
Andreas Gampe | 69489fa | 2017-06-08 18:03:25 -0700 | [diff] [blame] | 1341 | SizeType cache_non_header_size = kInvalidSize; |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1342 | }; |
| 1343 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1344 | /** |
| 1345 | * Wrapper around all compiler information collected for a method. |
| 1346 | * The information is of the form: |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 1347 | * |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1348 | * [CodeInfoEncoding, DexRegisterMap+, DexLocationCatalog+, StackMap+, RegisterMask+, StackMask+, |
Mathieu Chartier | c420a80 | 2017-02-14 15:16:19 -0800 | [diff] [blame] | 1349 | * InlineInfo*] |
| 1350 | * |
| 1351 | * where CodeInfoEncoding is of the form: |
| 1352 | * |
| 1353 | * [ByteSizedTable(dex_register_map), ByteSizedTable(location_catalog), |
| 1354 | * BitEncodingTable<StackMapEncoding>, BitEncodingTable<BitRegionEncoding>, |
| 1355 | * BitEncodingTable<BitRegionEncoding>, BitEncodingTable<InlineInfoEncoding>] |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1356 | */ |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1357 | class CodeInfo { |
| 1358 | public: |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1359 | explicit CodeInfo(MemoryRegion region) : region_(region) { |
| 1360 | } |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1361 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1362 | explicit CodeInfo(const void* data) { |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1363 | CodeInfoEncoding encoding = CodeInfoEncoding(data); |
| 1364 | region_ = MemoryRegion(const_cast<void*>(data), |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1365 | encoding.HeaderSize() + encoding.NonHeaderSize()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1366 | } |
| 1367 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1368 | CodeInfoEncoding ExtractEncoding() const { |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 1369 | CodeInfoEncoding encoding(region_.begin()); |
Mathieu Chartier | 01c7814 | 2017-01-05 10:17:55 -0800 | [diff] [blame] | 1370 | AssertValidStackMap(encoding); |
| 1371 | return encoding; |
Nicolas Geoffray | 896f8f7 | 2015-03-30 15:44:25 +0100 | [diff] [blame] | 1372 | } |
| 1373 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1374 | bool HasInlineInfo(const CodeInfoEncoding& encoding) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1375 | return encoding.stack_map.encoding.GetInlineInfoEncoding().BitSize() > 0; |
Nicolas Geoffray | 896f8f7 | 2015-03-30 15:44:25 +0100 | [diff] [blame] | 1376 | } |
| 1377 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1378 | DexRegisterLocationCatalog GetDexRegisterLocationCatalog(const CodeInfoEncoding& encoding) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1379 | return DexRegisterLocationCatalog(region_.Subregion(encoding.location_catalog.byte_offset, |
| 1380 | encoding.location_catalog.num_bytes)); |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
Mathieu Chartier | 12f1b99 | 2017-01-19 18:00:45 -0800 | [diff] [blame] | 1383 | ALWAYS_INLINE size_t GetNumberOfStackMaskBits(const CodeInfoEncoding& encoding) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1384 | return encoding.stack_mask.encoding.BitSize(); |
Mathieu Chartier | 12f1b99 | 2017-01-19 18:00:45 -0800 | [diff] [blame] | 1385 | } |
| 1386 | |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1387 | ALWAYS_INLINE StackMap GetStackMapAt(size_t index, const CodeInfoEncoding& encoding) const { |
| 1388 | return StackMap(encoding.stack_map.BitRegion(region_, index)); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1389 | } |
| 1390 | |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1391 | BitMemoryRegion GetStackMask(size_t index, const CodeInfoEncoding& encoding) const { |
| 1392 | return encoding.stack_mask.BitRegion(region_, index); |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | BitMemoryRegion GetStackMaskOf(const CodeInfoEncoding& encoding, |
| 1396 | const StackMap& stack_map) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1397 | return GetStackMask(stack_map.GetStackMaskIndex(encoding.stack_map.encoding), encoding); |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1400 | BitMemoryRegion GetRegisterMask(size_t index, const CodeInfoEncoding& encoding) const { |
| 1401 | return encoding.register_mask.BitRegion(region_, index); |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | uint32_t GetRegisterMaskOf(const CodeInfoEncoding& encoding, const StackMap& stack_map) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1405 | size_t index = stack_map.GetRegisterMaskIndex(encoding.stack_map.encoding); |
| 1406 | return GetRegisterMask(index, encoding).LoadBits(0u, encoding.register_mask.encoding.BitSize()); |
Mathieu Chartier | 1a20b68 | 2017-01-31 14:25:16 -0800 | [diff] [blame] | 1407 | } |
| 1408 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1409 | uint32_t GetNumberOfLocationCatalogEntries(const CodeInfoEncoding& encoding) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1410 | return encoding.location_catalog.num_entries; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1411 | } |
| 1412 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1413 | uint32_t GetDexRegisterLocationCatalogSize(const CodeInfoEncoding& encoding) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1414 | return encoding.location_catalog.num_bytes; |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1417 | uint32_t GetNumberOfStackMaps(const CodeInfoEncoding& encoding) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1418 | return encoding.stack_map.num_entries; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1419 | } |
| 1420 | |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 1421 | // Get the size of all the stack maps of this CodeInfo object, in bits. Not byte aligned. |
| 1422 | ALWAYS_INLINE size_t GetStackMapsSizeInBits(const CodeInfoEncoding& encoding) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1423 | return encoding.stack_map.encoding.BitSize() * GetNumberOfStackMaps(encoding); |
Nicolas Geoffray | 6530baf | 2015-05-26 15:22:58 +0100 | [diff] [blame] | 1424 | } |
| 1425 | |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1426 | InvokeInfo GetInvokeInfo(const CodeInfoEncoding& encoding, size_t index) const { |
| 1427 | return InvokeInfo(encoding.invoke_info.BitRegion(region_, index)); |
| 1428 | } |
| 1429 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 1430 | DexRegisterMap GetDexRegisterMapOf(StackMap stack_map, |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1431 | const CodeInfoEncoding& encoding, |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1432 | size_t number_of_dex_registers) const { |
| 1433 | if (!stack_map.HasDexRegisterMap(encoding.stack_map.encoding)) { |
Nicolas Geoffray | 012fc4e | 2016-01-08 15:58:19 +0000 | [diff] [blame] | 1434 | return DexRegisterMap(); |
Nicolas Geoffray | 012fc4e | 2016-01-08 15:58:19 +0000 | [diff] [blame] | 1435 | } |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1436 | const uint32_t offset = encoding.dex_register_map.byte_offset + |
| 1437 | stack_map.GetDexRegisterMapOffset(encoding.stack_map.encoding); |
| 1438 | size_t size = ComputeDexRegisterMapSizeOf(encoding, offset, number_of_dex_registers); |
| 1439 | return DexRegisterMap(region_.Subregion(offset, size)); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1440 | } |
| 1441 | |
Mathieu Chartier | 5e7c6a9 | 2017-01-17 16:38:30 -0800 | [diff] [blame] | 1442 | size_t GetDexRegisterMapsSize(const CodeInfoEncoding& encoding, |
| 1443 | uint32_t number_of_dex_registers) const { |
| 1444 | size_t total = 0; |
| 1445 | for (size_t i = 0, e = GetNumberOfStackMaps(encoding); i < e; ++i) { |
| 1446 | StackMap stack_map = GetStackMapAt(i, encoding); |
| 1447 | DexRegisterMap map(GetDexRegisterMapOf(stack_map, encoding, number_of_dex_registers)); |
| 1448 | total += map.Size(); |
| 1449 | } |
| 1450 | return total; |
| 1451 | } |
| 1452 | |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 1453 | // Return the `DexRegisterMap` pointed by `inline_info` at depth `depth`. |
| 1454 | DexRegisterMap GetDexRegisterMapAtDepth(uint8_t depth, |
| 1455 | InlineInfo inline_info, |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1456 | const CodeInfoEncoding& encoding, |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 1457 | uint32_t number_of_dex_registers) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1458 | if (!inline_info.HasDexRegisterMapAtDepth(encoding.inline_info.encoding, depth)) { |
Nicolas Geoffray | 012fc4e | 2016-01-08 15:58:19 +0000 | [diff] [blame] | 1459 | return DexRegisterMap(); |
| 1460 | } else { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1461 | uint32_t offset = encoding.dex_register_map.byte_offset + |
| 1462 | inline_info.GetDexRegisterMapOffsetAtDepth(encoding.inline_info.encoding, depth); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1463 | size_t size = ComputeDexRegisterMapSizeOf(encoding, offset, number_of_dex_registers); |
Nicolas Geoffray | 012fc4e | 2016-01-08 15:58:19 +0000 | [diff] [blame] | 1464 | return DexRegisterMap(region_.Subregion(offset, size)); |
| 1465 | } |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 1466 | } |
| 1467 | |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1468 | InlineInfo GetInlineInfo(size_t index, const CodeInfoEncoding& encoding) const { |
Mathieu Chartier | c420a80 | 2017-02-14 15:16:19 -0800 | [diff] [blame] | 1469 | // Since we do not know the depth, we just return the whole remaining map. The caller may |
| 1470 | // access the inline info for arbitrary depths. To return the precise inline info we would need |
| 1471 | // to count the depth before returning. |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1472 | // TODO: Clean this up. |
| 1473 | const size_t bit_offset = encoding.inline_info.bit_offset + |
| 1474 | index * encoding.inline_info.encoding.BitSize(); |
| 1475 | return InlineInfo(BitMemoryRegion(region_, bit_offset, region_.size_in_bits() - bit_offset)); |
| 1476 | } |
| 1477 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1478 | InlineInfo GetInlineInfoOf(StackMap stack_map, const CodeInfoEncoding& encoding) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1479 | DCHECK(stack_map.HasInlineInfo(encoding.stack_map.encoding)); |
| 1480 | uint32_t index = stack_map.GetInlineInfoIndex(encoding.stack_map.encoding); |
| 1481 | return GetInlineInfo(index, encoding); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1482 | } |
| 1483 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1484 | StackMap GetStackMapForDexPc(uint32_t dex_pc, const CodeInfoEncoding& encoding) const { |
| 1485 | for (size_t i = 0, e = GetNumberOfStackMaps(encoding); i < e; ++i) { |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 1486 | StackMap stack_map = GetStackMapAt(i, encoding); |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1487 | if (stack_map.GetDexPc(encoding.stack_map.encoding) == dex_pc) { |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1488 | return stack_map; |
| 1489 | } |
| 1490 | } |
Nicolas Geoffray | e12997f | 2015-05-22 14:01:33 +0100 | [diff] [blame] | 1491 | return StackMap(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1492 | } |
| 1493 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 1494 | // Searches the stack map list backwards because catch stack maps are stored |
| 1495 | // at the end. |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1496 | StackMap GetCatchStackMapForDexPc(uint32_t dex_pc, const CodeInfoEncoding& encoding) const { |
| 1497 | for (size_t i = GetNumberOfStackMaps(encoding); i > 0; --i) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 1498 | StackMap stack_map = GetStackMapAt(i - 1, encoding); |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1499 | if (stack_map.GetDexPc(encoding.stack_map.encoding) == dex_pc) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 1500 | return stack_map; |
| 1501 | } |
| 1502 | } |
| 1503 | return StackMap(); |
| 1504 | } |
| 1505 | |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1506 | StackMap GetOsrStackMapForDexPc(uint32_t dex_pc, const CodeInfoEncoding& encoding) const { |
| 1507 | size_t e = GetNumberOfStackMaps(encoding); |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 1508 | if (e == 0) { |
| 1509 | // There cannot be OSR stack map if there is no stack map. |
| 1510 | return StackMap(); |
| 1511 | } |
| 1512 | // Walk over all stack maps. If two consecutive stack maps are identical, then we |
| 1513 | // have found a stack map suitable for OSR. |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1514 | const StackMapEncoding& stack_map_encoding = encoding.stack_map.encoding; |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 1515 | for (size_t i = 0; i < e - 1; ++i) { |
| 1516 | StackMap stack_map = GetStackMapAt(i, encoding); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1517 | if (stack_map.GetDexPc(stack_map_encoding) == dex_pc) { |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 1518 | StackMap other = GetStackMapAt(i + 1, encoding); |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1519 | if (other.GetDexPc(stack_map_encoding) == dex_pc && |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1520 | other.GetNativePcOffset(stack_map_encoding, kRuntimeISA) == |
| 1521 | stack_map.GetNativePcOffset(stack_map_encoding, kRuntimeISA)) { |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1522 | DCHECK_EQ(other.GetDexRegisterMapOffset(stack_map_encoding), |
| 1523 | stack_map.GetDexRegisterMapOffset(stack_map_encoding)); |
| 1524 | DCHECK(!stack_map.HasInlineInfo(stack_map_encoding)); |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 1525 | if (i < e - 2) { |
| 1526 | // Make sure there are not three identical stack maps following each other. |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1527 | DCHECK_NE( |
| 1528 | stack_map.GetNativePcOffset(stack_map_encoding, kRuntimeISA), |
| 1529 | GetStackMapAt(i + 2, encoding).GetNativePcOffset(stack_map_encoding, kRuntimeISA)); |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 1530 | } |
| 1531 | return stack_map; |
| 1532 | } |
| 1533 | } |
| 1534 | } |
| 1535 | return StackMap(); |
| 1536 | } |
| 1537 | |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 1538 | StackMap GetStackMapForNativePcOffset(uint32_t native_pc_offset, |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1539 | const CodeInfoEncoding& encoding) const { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 1540 | // TODO: Safepoint stack maps are sorted by native_pc_offset but catch stack |
| 1541 | // maps are not. If we knew that the method does not have try/catch, |
| 1542 | // we could do binary search. |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1543 | for (size_t i = 0, e = GetNumberOfStackMaps(encoding); i < e; ++i) { |
David Brazdil | f677ebf | 2015-05-29 16:29:43 +0100 | [diff] [blame] | 1544 | StackMap stack_map = GetStackMapAt(i, encoding); |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1545 | if (stack_map.GetNativePcOffset(encoding.stack_map.encoding, kRuntimeISA) == |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1546 | native_pc_offset) { |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1547 | return stack_map; |
| 1548 | } |
| 1549 | } |
Nicolas Geoffray | e12997f | 2015-05-22 14:01:33 +0100 | [diff] [blame] | 1550 | return StackMap(); |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1551 | } |
| 1552 | |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1553 | InvokeInfo GetInvokeInfoForNativePcOffset(uint32_t native_pc_offset, |
| 1554 | const CodeInfoEncoding& encoding) { |
| 1555 | for (size_t index = 0; index < encoding.invoke_info.num_entries; index++) { |
| 1556 | InvokeInfo item = GetInvokeInfo(encoding, index); |
| 1557 | if (item.GetNativePcOffset(encoding.invoke_info.encoding, kRuntimeISA) == native_pc_offset) { |
| 1558 | return item; |
| 1559 | } |
| 1560 | } |
| 1561 | return InvokeInfo(BitMemoryRegion()); |
| 1562 | } |
| 1563 | |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1564 | // Dump this CodeInfo object on `os`. `code_offset` is the (absolute) |
| 1565 | // native PC of the compiled method and `number_of_dex_registers` the |
| 1566 | // number of Dex virtual registers used in this method. If |
| 1567 | // `dump_stack_maps` is true, also dump the stack maps and the |
| 1568 | // associated Dex register maps. |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 1569 | void Dump(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 1570 | uint32_t code_offset, |
| 1571 | uint16_t number_of_dex_registers, |
Mathieu Chartier | a2f526f | 2017-01-19 14:48:48 -0800 | [diff] [blame] | 1572 | bool dump_stack_maps, |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 1573 | InstructionSet instruction_set, |
| 1574 | const MethodInfo& method_info) const; |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 1575 | |
Mathieu Chartier | 01c7814 | 2017-01-05 10:17:55 -0800 | [diff] [blame] | 1576 | // Check that the code info has valid stack map and abort if it does not. |
| 1577 | void AssertValidStackMap(const CodeInfoEncoding& encoding) const { |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1578 | if (region_.size() != 0 && region_.size_in_bits() < GetStackMapsSizeInBits(encoding)) { |
Mathieu Chartier | 01c7814 | 2017-01-05 10:17:55 -0800 | [diff] [blame] | 1579 | LOG(FATAL) << region_.size() << "\n" |
Mathieu Chartier | 575d3e6 | 2017-02-06 11:00:40 -0800 | [diff] [blame] | 1580 | << encoding.HeaderSize() << "\n" |
| 1581 | << encoding.NonHeaderSize() << "\n" |
| 1582 | << encoding.location_catalog.num_entries << "\n" |
| 1583 | << encoding.stack_map.num_entries << "\n" |
| 1584 | << encoding.stack_map.encoding.BitSize(); |
Mathieu Chartier | 01c7814 | 2017-01-05 10:17:55 -0800 | [diff] [blame] | 1585 | } |
| 1586 | } |
| 1587 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1588 | private: |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 1589 | // Compute the size of the Dex register map associated to the stack map at |
| 1590 | // `dex_register_map_offset_in_code_info`. |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1591 | size_t ComputeDexRegisterMapSizeOf(const CodeInfoEncoding& encoding, |
| 1592 | uint32_t dex_register_map_offset_in_code_info, |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 1593 | uint16_t number_of_dex_registers) const { |
| 1594 | // Offset where the actual mapping data starts within art::DexRegisterMap. |
| 1595 | size_t location_mapping_data_offset_in_dex_register_map = |
| 1596 | DexRegisterMap::GetLocationMappingDataOffset(number_of_dex_registers); |
| 1597 | // Create a temporary art::DexRegisterMap to be able to call |
| 1598 | // art::DexRegisterMap::GetNumberOfLiveDexRegisters and |
| 1599 | DexRegisterMap dex_register_map_without_locations( |
| 1600 | MemoryRegion(region_.Subregion(dex_register_map_offset_in_code_info, |
| 1601 | location_mapping_data_offset_in_dex_register_map))); |
| 1602 | size_t number_of_live_dex_registers = |
| 1603 | dex_register_map_without_locations.GetNumberOfLiveDexRegisters(number_of_dex_registers); |
| 1604 | size_t location_mapping_data_size_in_bits = |
David Srbecky | 09ed098 | 2016-02-12 21:58:43 +0000 | [diff] [blame] | 1605 | DexRegisterMap::SingleEntrySizeInBits(GetNumberOfLocationCatalogEntries(encoding)) |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 1606 | * number_of_live_dex_registers; |
| 1607 | size_t location_mapping_data_size_in_bytes = |
| 1608 | RoundUp(location_mapping_data_size_in_bits, kBitsPerByte) / kBitsPerByte; |
| 1609 | size_t dex_register_map_size = |
| 1610 | location_mapping_data_offset_in_dex_register_map + location_mapping_data_size_in_bytes; |
| 1611 | return dex_register_map_size; |
| 1612 | } |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 1613 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 1614 | // Compute the size of a Dex register location catalog starting at offset `origin` |
| 1615 | // in `region_` and containing `number_of_dex_locations` entries. |
| 1616 | size_t ComputeDexRegisterLocationCatalogSize(uint32_t origin, |
| 1617 | uint32_t number_of_dex_locations) const { |
| 1618 | // TODO: Ideally, we would like to use art::DexRegisterLocationCatalog::Size or |
| 1619 | // art::DexRegisterLocationCatalog::FindLocationOffset, but the |
| 1620 | // DexRegisterLocationCatalog is not yet built. Try to factor common code. |
| 1621 | size_t offset = origin + DexRegisterLocationCatalog::kFixedSize; |
Nicolas Geoffray | fead4e4 | 2015-03-13 14:39:40 +0000 | [diff] [blame] | 1622 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 1623 | // Skip the first `number_of_dex_locations - 1` entries. |
| 1624 | for (uint16_t i = 0; i < number_of_dex_locations; ++i) { |
| 1625 | // Read the first next byte and inspect its first 3 bits to decide |
| 1626 | // whether it is a short or a large location. |
| 1627 | DexRegisterLocationCatalog::ShortLocation first_byte = |
| 1628 | region_.LoadUnaligned<DexRegisterLocationCatalog::ShortLocation>(offset); |
| 1629 | DexRegisterLocation::Kind kind = |
| 1630 | DexRegisterLocationCatalog::ExtractKindFromShortLocation(first_byte); |
| 1631 | if (DexRegisterLocation::IsShortLocationKind(kind)) { |
| 1632 | // Short location. Skip the current byte. |
| 1633 | offset += DexRegisterLocationCatalog::SingleShortEntrySize(); |
| 1634 | } else { |
| 1635 | // Large location. Skip the 5 next bytes. |
| 1636 | offset += DexRegisterLocationCatalog::SingleLargeEntrySize(); |
Roland Levillain | a2d8ec6 | 2015-03-12 15:25:29 +0000 | [diff] [blame] | 1637 | } |
| 1638 | } |
| 1639 | size_t size = offset - origin; |
| 1640 | return size; |
| 1641 | } |
| 1642 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1643 | MemoryRegion region_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1644 | friend class StackMapStream; |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1645 | }; |
| 1646 | |
Roland Levillain | 1c1da43 | 2015-07-16 11:54:44 +0100 | [diff] [blame] | 1647 | #undef ELEMENT_BYTE_OFFSET_AFTER |
| 1648 | #undef ELEMENT_BIT_OFFSET_AFTER |
| 1649 | |
Nicolas Geoffray | 99ea58c | 2014-07-02 15:08:17 +0100 | [diff] [blame] | 1650 | } // namespace art |
| 1651 | |
| 1652 | #endif // ART_RUNTIME_STACK_MAP_H_ |