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