Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | #include "stack_map.h" |
| 18 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 19 | #include <iomanip> |
Nicolas Geoffray | 896f8f7 | 2015-03-30 15:44:25 +0100 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 22 | #include "art_method.h" |
David Sehr | 9c4a015 | 2018-04-05 12:23:54 -0700 | [diff] [blame] | 23 | #include "base/indenter.h" |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 24 | #include "base/stats.h" |
David Srbecky | f6ba5b3 | 2018-06-23 22:05:49 +0100 | [diff] [blame] | 25 | #include "oat_quick_method_header.h" |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 26 | #include "scoped_thread_state_change-inl.h" |
Roland Levillain | 0396ed7 | 2015-05-27 15:12:19 +0100 | [diff] [blame] | 27 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 28 | namespace art { |
| 29 | |
David Srbecky | 6ee06e9 | 2018-07-25 21:45:54 +0100 | [diff] [blame] | 30 | CodeInfo::CodeInfo(const OatQuickMethodHeader* header, DecodeFlags flags) |
| 31 | : CodeInfo(header->GetOptimizedCodeInfoPtr(), flags) { |
David Srbecky | f6ba5b3 | 2018-06-23 22:05:49 +0100 | [diff] [blame] | 32 | } |
| 33 | |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 34 | template<typename Accessor> |
| 35 | ALWAYS_INLINE static void DecodeTable(BitTable<Accessor>& table, |
| 36 | BitMemoryReader& reader, |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame^] | 37 | const uint8_t* reader_data) { |
| 38 | if (reader.ReadBit() /* is_deduped */) { |
| 39 | ssize_t bit_offset = reader.NumberOfReadBits() - DecodeVarintBits(reader); |
| 40 | BitMemoryReader reader2(reader_data, bit_offset); // The offset is negative. |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 41 | table.Decode(reader2); |
| 42 | } else { |
| 43 | table.Decode(reader); |
| 44 | } |
| 45 | } |
| 46 | |
David Srbecky | 6ee06e9 | 2018-07-25 21:45:54 +0100 | [diff] [blame] | 47 | void CodeInfo::Decode(const uint8_t* data, DecodeFlags flags) { |
David Srbecky | 3aaaa21 | 2018-07-30 16:46:53 +0100 | [diff] [blame] | 48 | BitMemoryReader reader(data); |
| 49 | packed_frame_size_ = DecodeVarintBits(reader); |
| 50 | core_spill_mask_ = DecodeVarintBits(reader); |
| 51 | fp_spill_mask_ = DecodeVarintBits(reader); |
| 52 | number_of_dex_registers_ = DecodeVarintBits(reader); |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 53 | DecodeTable(stack_maps_, reader, data); |
David Srbecky | a2d29a3 | 2018-08-03 11:06:38 +0100 | [diff] [blame] | 54 | DecodeTable(register_masks_, reader, data); |
| 55 | DecodeTable(stack_masks_, reader, data); |
| 56 | if (flags & DecodeFlags::GcMasksOnly) { |
| 57 | return; |
| 58 | } |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 59 | DecodeTable(inline_infos_, reader, data); |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 60 | DecodeTable(method_infos_, reader, data); |
David Srbecky | 6ee06e9 | 2018-07-25 21:45:54 +0100 | [diff] [blame] | 61 | if (flags & DecodeFlags::InlineInfoOnly) { |
| 62 | return; |
| 63 | } |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 64 | DecodeTable(dex_register_masks_, reader, data); |
| 65 | DecodeTable(dex_register_maps_, reader, data); |
| 66 | DecodeTable(dex_register_catalog_, reader, data); |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame^] | 67 | size_in_bits_ = reader.NumberOfReadBits(); |
David Srbecky | 078d7ba | 2018-06-21 15:36:48 +0100 | [diff] [blame] | 68 | } |
| 69 | |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 70 | template<typename Accessor> |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame^] | 71 | ALWAYS_INLINE void CodeInfo::Deduper::DedupeTable(BitMemoryReader& reader) { |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 72 | bool is_deduped = reader.ReadBit(); |
| 73 | DCHECK(!is_deduped); |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame^] | 74 | size_t bit_table_start = reader.NumberOfReadBits(); |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 75 | BitTable<Accessor> bit_table(reader); |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame^] | 76 | BitMemoryRegion region = reader.GetReadRegion().Subregion(bit_table_start); |
| 77 | auto it = dedupe_map_.insert(std::make_pair(region, /* placeholder */ 0)); |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 78 | if (it.second /* new bit table */ || region.size_in_bits() < 32) { |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame^] | 79 | writer_.WriteBit(false); // Is not deduped. |
| 80 | it.first->second = writer_.NumberOfWrittenBits(); |
| 81 | writer_.WriteRegion(region); |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 82 | } else { |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame^] | 83 | writer_.WriteBit(true); // Is deduped. |
| 84 | size_t bit_offset = writer_.NumberOfWrittenBits(); |
| 85 | EncodeVarintBits(writer_, bit_offset - it.first->second); |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame^] | 89 | size_t CodeInfo::Deduper::Dedupe(const uint8_t* code_info) { |
| 90 | writer_.ByteAlign(); |
| 91 | size_t deduped_offset = writer_.NumberOfWrittenBits() / kBitsPerByte; |
| 92 | BitMemoryReader reader(code_info); |
| 93 | EncodeVarintBits(writer_, DecodeVarintBits(reader)); // packed_frame_size_. |
| 94 | EncodeVarintBits(writer_, DecodeVarintBits(reader)); // core_spill_mask_. |
| 95 | EncodeVarintBits(writer_, DecodeVarintBits(reader)); // fp_spill_mask_. |
| 96 | EncodeVarintBits(writer_, DecodeVarintBits(reader)); // number_of_dex_registers_. |
| 97 | DedupeTable<StackMap>(reader); |
| 98 | DedupeTable<RegisterMask>(reader); |
| 99 | DedupeTable<MaskInfo>(reader); |
| 100 | DedupeTable<InlineInfo>(reader); |
| 101 | DedupeTable<MethodInfo>(reader); |
| 102 | DedupeTable<MaskInfo>(reader); |
| 103 | DedupeTable<DexRegisterMapInfo>(reader); |
| 104 | DedupeTable<DexRegisterInfo>(reader); |
| 105 | |
| 106 | if (kIsDebugBuild) { |
| 107 | CodeInfo old_code_info(code_info); |
| 108 | CodeInfo new_code_info(writer_.data() + deduped_offset); |
| 109 | DCHECK_EQ(old_code_info.packed_frame_size_, new_code_info.packed_frame_size_); |
| 110 | DCHECK_EQ(old_code_info.core_spill_mask_, new_code_info.core_spill_mask_); |
| 111 | DCHECK_EQ(old_code_info.fp_spill_mask_, new_code_info.fp_spill_mask_); |
| 112 | DCHECK_EQ(old_code_info.number_of_dex_registers_, new_code_info.number_of_dex_registers_); |
| 113 | DCHECK(old_code_info.stack_maps_.Equals(new_code_info.stack_maps_)); |
| 114 | DCHECK(old_code_info.register_masks_.Equals(new_code_info.register_masks_)); |
| 115 | DCHECK(old_code_info.stack_masks_.Equals(new_code_info.stack_masks_)); |
| 116 | DCHECK(old_code_info.inline_infos_.Equals(new_code_info.inline_infos_)); |
| 117 | DCHECK(old_code_info.method_infos_.Equals(new_code_info.method_infos_)); |
| 118 | DCHECK(old_code_info.dex_register_masks_.Equals(new_code_info.dex_register_masks_)); |
| 119 | DCHECK(old_code_info.dex_register_maps_.Equals(new_code_info.dex_register_maps_)); |
| 120 | DCHECK(old_code_info.dex_register_catalog_.Equals(new_code_info.dex_register_catalog_)); |
| 121 | } |
| 122 | |
| 123 | return deduped_offset; |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 124 | } |
| 125 | |
David Srbecky | 0b4e5a3 | 2018-06-11 16:25:29 +0100 | [diff] [blame] | 126 | BitTable<StackMap>::const_iterator CodeInfo::BinarySearchNativePc(uint32_t packed_pc) const { |
| 127 | return std::partition_point( |
| 128 | stack_maps_.begin(), |
| 129 | stack_maps_.end(), |
| 130 | [packed_pc](const StackMap& sm) { |
| 131 | return sm.GetPackedNativePc() < packed_pc && sm.GetKind() != StackMap::Kind::Catch; |
| 132 | }); |
| 133 | } |
| 134 | |
| 135 | StackMap CodeInfo::GetStackMapForNativePcOffset(uint32_t pc, InstructionSet isa) const { |
| 136 | auto it = BinarySearchNativePc(StackMap::PackNativePc(pc, isa)); |
| 137 | // Start at the lower bound and iterate over all stack maps with the given native pc. |
| 138 | for (; it != stack_maps_.end() && (*it).GetNativePcOffset(isa) == pc; ++it) { |
| 139 | StackMap::Kind kind = static_cast<StackMap::Kind>((*it).GetKind()); |
| 140 | if (kind == StackMap::Kind::Default || kind == StackMap::Kind::OSR) { |
| 141 | return *it; |
| 142 | } |
| 143 | } |
David Srbecky | a45a85c | 2018-06-21 16:03:12 +0100 | [diff] [blame] | 144 | return stack_maps_.GetInvalidRow(); |
David Srbecky | 0b4e5a3 | 2018-06-11 16:25:29 +0100 | [diff] [blame] | 145 | } |
| 146 | |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 147 | // Scan backward to determine dex register locations at given stack map. |
| 148 | // All registers for a stack map are combined - inlined registers are just appended, |
| 149 | // therefore 'first_dex_register' allows us to select a sub-range to decode. |
| 150 | void CodeInfo::DecodeDexRegisterMap(uint32_t stack_map_index, |
| 151 | uint32_t first_dex_register, |
| 152 | /*out*/ DexRegisterMap* map) const { |
| 153 | // Count remaining work so we know when we have finished. |
| 154 | uint32_t remaining_registers = map->size(); |
| 155 | |
| 156 | // Keep scanning backwards and collect the most recent location of each register. |
| 157 | for (int32_t s = stack_map_index; s >= 0 && remaining_registers != 0; s--) { |
| 158 | StackMap stack_map = GetStackMapAt(s); |
| 159 | DCHECK_LE(stack_map_index - s, kMaxDexRegisterMapSearchDistance) << "Unbounded search"; |
| 160 | |
| 161 | // The mask specifies which registers where modified in this stack map. |
| 162 | // NB: the mask can be shorter than expected if trailing zero bits were removed. |
| 163 | uint32_t mask_index = stack_map.GetDexRegisterMaskIndex(); |
| 164 | if (mask_index == StackMap::kNoValue) { |
| 165 | continue; // Nothing changed at this stack map. |
| 166 | } |
| 167 | BitMemoryRegion mask = dex_register_masks_.GetBitMemoryRegion(mask_index); |
| 168 | if (mask.size_in_bits() <= first_dex_register) { |
| 169 | continue; // Nothing changed after the first register we are interested in. |
| 170 | } |
| 171 | |
| 172 | // The map stores one catalogue index per each modified register location. |
| 173 | uint32_t map_index = stack_map.GetDexRegisterMapIndex(); |
| 174 | DCHECK_NE(map_index, StackMap::kNoValue); |
| 175 | |
| 176 | // Skip initial registers which we are not interested in (to get to inlined registers). |
| 177 | map_index += mask.PopCount(0, first_dex_register); |
| 178 | mask = mask.Subregion(first_dex_register, mask.size_in_bits() - first_dex_register); |
| 179 | |
| 180 | // Update registers that we see for first time (i.e. most recent value). |
| 181 | DexRegisterLocation* regs = map->data(); |
| 182 | const uint32_t end = std::min<uint32_t>(map->size(), mask.size_in_bits()); |
| 183 | const size_t kNumBits = BitSizeOf<uint32_t>(); |
| 184 | for (uint32_t reg = 0; reg < end; reg += kNumBits) { |
| 185 | // Process the mask in chunks of kNumBits for performance. |
| 186 | uint32_t bits = mask.LoadBits(reg, std::min<uint32_t>(end - reg, kNumBits)); |
| 187 | while (bits != 0) { |
| 188 | uint32_t bit = CTZ(bits); |
| 189 | if (regs[reg + bit].GetKind() == DexRegisterLocation::Kind::kInvalid) { |
| 190 | regs[reg + bit] = GetDexRegisterCatalogEntry(dex_register_maps_.Get(map_index)); |
| 191 | remaining_registers--; |
| 192 | } |
| 193 | map_index++; |
| 194 | bits ^= 1u << bit; // Clear the bit. |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // Set any remaining registers to None (which is the default state at first stack map). |
| 200 | if (remaining_registers != 0) { |
| 201 | DexRegisterLocation* regs = map->data(); |
| 202 | for (uint32_t r = 0; r < map->size(); r++) { |
| 203 | if (regs[r].GetKind() == DexRegisterLocation::Kind::kInvalid) { |
| 204 | regs[r] = DexRegisterLocation::None(); |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 210 | template<typename Accessor> |
| 211 | static void AddTableSizeStats(const char* table_name, |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 212 | const BitTable<Accessor>& table, |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 213 | /*out*/ Stats* parent) { |
| 214 | Stats* table_stats = parent->Child(table_name); |
| 215 | table_stats->AddBits(table.BitSize()); |
| 216 | table_stats->Child("Header")->AddBits(table.HeaderBitSize()); |
| 217 | const char* const* column_names = GetBitTableColumnNames<Accessor>(); |
| 218 | for (size_t c = 0; c < table.NumColumns(); c++) { |
| 219 | if (table.NumColumnBits(c) > 0) { |
| 220 | Stats* column_stats = table_stats->Child(column_names[c]); |
| 221 | column_stats->AddBits(table.NumRows() * table.NumColumnBits(c), table.NumRows()); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | void CodeInfo::AddSizeStats(/*out*/ Stats* parent) const { |
| 227 | Stats* stats = parent->Child("CodeInfo"); |
David Srbecky | a38e6cf | 2018-06-26 18:13:49 +0100 | [diff] [blame] | 228 | stats->AddBytes(Size()); |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 229 | AddTableSizeStats<StackMap>("StackMaps", stack_maps_, stats); |
| 230 | AddTableSizeStats<RegisterMask>("RegisterMasks", register_masks_, stats); |
| 231 | AddTableSizeStats<MaskInfo>("StackMasks", stack_masks_, stats); |
David Srbecky | a2d29a3 | 2018-08-03 11:06:38 +0100 | [diff] [blame] | 232 | AddTableSizeStats<InlineInfo>("InlineInfos", inline_infos_, stats); |
| 233 | AddTableSizeStats<MethodInfo>("MethodInfo", method_infos_, stats); |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 234 | AddTableSizeStats<MaskInfo>("DexRegisterMasks", dex_register_masks_, stats); |
| 235 | AddTableSizeStats<DexRegisterMapInfo>("DexRegisterMaps", dex_register_maps_, stats); |
| 236 | AddTableSizeStats<DexRegisterInfo>("DexRegisterCatalog", dex_register_catalog_, stats); |
| 237 | } |
| 238 | |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 239 | void DexRegisterMap::Dump(VariableIndentationOutputStream* vios) const { |
| 240 | if (HasAnyLiveDexRegisters()) { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 241 | ScopedIndentation indent1(vios); |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 242 | for (size_t i = 0; i < size(); ++i) { |
| 243 | DexRegisterLocation reg = (*this)[i]; |
| 244 | if (reg.IsLive()) { |
| 245 | vios->Stream() << "v" << i << ":" << reg << " "; |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | vios->Stream() << "\n"; |
| 249 | } |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 250 | } |
| 251 | |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 252 | template<typename Accessor> |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 253 | static void DumpTable(VariableIndentationOutputStream* vios, |
| 254 | const char* table_name, |
David Srbecky | cf7833e | 2018-06-14 16:45:22 +0100 | [diff] [blame] | 255 | const BitTable<Accessor>& table, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 256 | bool verbose, |
| 257 | bool is_mask = false) { |
| 258 | if (table.NumRows() != 0) { |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 259 | vios->Stream() << table_name << " BitSize=" << table.BitSize(); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 260 | vios->Stream() << " Rows=" << table.NumRows() << " Bits={"; |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 261 | const char* const* column_names = GetBitTableColumnNames<Accessor>(); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 262 | for (size_t c = 0; c < table.NumColumns(); c++) { |
| 263 | vios->Stream() << (c != 0 ? " " : ""); |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 264 | vios->Stream() << column_names[c] << "=" << table.NumColumnBits(c); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 265 | } |
| 266 | vios->Stream() << "}\n"; |
| 267 | if (verbose) { |
| 268 | ScopedIndentation indent1(vios); |
| 269 | for (size_t r = 0; r < table.NumRows(); r++) { |
| 270 | vios->Stream() << "[" << std::right << std::setw(3) << r << "]={"; |
| 271 | for (size_t c = 0; c < table.NumColumns(); c++) { |
| 272 | vios->Stream() << (c != 0 ? " " : ""); |
| 273 | if (is_mask) { |
| 274 | BitMemoryRegion bits = table.GetBitMemoryRegion(r, c); |
| 275 | for (size_t b = 0, e = bits.size_in_bits(); b < e; b++) { |
| 276 | vios->Stream() << bits.LoadBit(e - b - 1); |
| 277 | } |
| 278 | } else { |
| 279 | vios->Stream() << std::right << std::setw(8) << static_cast<int32_t>(table.Get(r, c)); |
| 280 | } |
| 281 | } |
| 282 | vios->Stream() << "}\n"; |
| 283 | } |
| 284 | } |
| 285 | } |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 288 | void CodeInfo::Dump(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 289 | uint32_t code_offset, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 290 | bool verbose, |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 291 | InstructionSet instruction_set) const { |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 292 | vios->Stream() << "CodeInfo\n"; |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 293 | ScopedIndentation indent1(vios); |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 294 | DumpTable<StackMap>(vios, "StackMaps", stack_maps_, verbose); |
| 295 | DumpTable<RegisterMask>(vios, "RegisterMasks", register_masks_, verbose); |
| 296 | DumpTable<MaskInfo>(vios, "StackMasks", stack_masks_, verbose, true /* is_mask */); |
David Srbecky | a2d29a3 | 2018-08-03 11:06:38 +0100 | [diff] [blame] | 297 | DumpTable<InlineInfo>(vios, "InlineInfos", inline_infos_, verbose); |
| 298 | DumpTable<MethodInfo>(vios, "MethodInfo", method_infos_, verbose); |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 299 | DumpTable<MaskInfo>(vios, "DexRegisterMasks", dex_register_masks_, verbose, true /* is_mask */); |
| 300 | DumpTable<DexRegisterMapInfo>(vios, "DexRegisterMaps", dex_register_maps_, verbose); |
| 301 | DumpTable<DexRegisterInfo>(vios, "DexRegisterCatalog", dex_register_catalog_, verbose); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 302 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 303 | // Display stack maps along with (live) Dex register maps. |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 304 | if (verbose) { |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 305 | for (StackMap stack_map : stack_maps_) { |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 306 | stack_map.Dump(vios, *this, code_offset, instruction_set); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 311 | void StackMap::Dump(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 312 | const CodeInfo& code_info, |
| 313 | uint32_t code_offset, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 314 | InstructionSet instruction_set) const { |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 315 | const uint32_t pc_offset = GetNativePcOffset(instruction_set); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 316 | vios->Stream() |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 317 | << "StackMap[" << Row() << "]" |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 318 | << std::hex |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 319 | << " (native_pc=0x" << code_offset + pc_offset |
| 320 | << ", dex_pc=0x" << GetDexPc() |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 321 | << ", register_mask=0x" << code_info.GetRegisterMaskOf(*this) |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 322 | << std::dec |
| 323 | << ", stack_mask=0b"; |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 324 | BitMemoryRegion stack_mask = code_info.GetStackMaskOf(*this); |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 325 | for (size_t i = 0, e = stack_mask.size_in_bits(); i < e; ++i) { |
David Srbecky | 45aa598 | 2016-03-18 02:15:09 +0000 | [diff] [blame] | 326 | vios->Stream() << stack_mask.LoadBit(e - i - 1); |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 327 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 328 | vios->Stream() << ")\n"; |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 329 | code_info.GetDexRegisterMapOf(*this).Dump(vios); |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 330 | for (InlineInfo inline_info : code_info.GetInlineInfosOf(*this)) { |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 331 | inline_info.Dump(vios, code_info, *this); |
Nicolas Geoffray | 12bdb72 | 2015-06-17 09:44:43 +0100 | [diff] [blame] | 332 | } |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 333 | } |
| 334 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 335 | void InlineInfo::Dump(VariableIndentationOutputStream* vios, |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 336 | const CodeInfo& code_info, |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 337 | const StackMap& stack_map) const { |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame] | 338 | uint32_t depth = Row() - stack_map.GetInlineInfoIndex(); |
| 339 | vios->Stream() |
| 340 | << "InlineInfo[" << Row() << "]" |
| 341 | << " (depth=" << depth |
| 342 | << std::hex |
| 343 | << ", dex_pc=0x" << GetDexPc(); |
| 344 | if (EncodesArtMethod()) { |
| 345 | ScopedObjectAccess soa(Thread::Current()); |
| 346 | vios->Stream() << ", method=" << GetArtMethod()->PrettyMethod(); |
| 347 | } else { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 348 | vios->Stream() |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame] | 349 | << std::dec |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 350 | << ", method_index=" << code_info.GetMethodIndexOf(*this); |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame] | 351 | } |
| 352 | vios->Stream() << ")\n"; |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 353 | code_info.GetInlineDexRegisterMapOf(stack_map, *this).Dump(vios); |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | } // namespace art |