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 | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 30 | // The callback is used to inform the caller about memory bounds of the bit-tables. |
| 31 | template<typename DecodeCallback> |
| 32 | CodeInfo::CodeInfo(const uint8_t* data, size_t* num_read_bits, DecodeCallback callback) { |
David Srbecky | 3aaaa21 | 2018-07-30 16:46:53 +0100 | [diff] [blame] | 33 | BitMemoryReader reader(data); |
David Srbecky | 6c4ec5c | 2019-06-20 07:23:19 +0000 | [diff] [blame] | 34 | std::array<uint32_t, kNumHeaders> header = reader.ReadInterleavedVarints<kNumHeaders>(); |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 35 | ForEachHeaderField([this, &header](size_t i, auto member_pointer) { |
| 36 | this->*member_pointer = header[i]; |
| 37 | }); |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 38 | ForEachBitTableField([this, &reader, &callback](size_t i, auto member_pointer) { |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 39 | auto& table = this->*member_pointer; |
David Srbecky | 6c4ec5c | 2019-06-20 07:23:19 +0000 | [diff] [blame] | 40 | if (LIKELY(HasBitTable(i))) { |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 41 | if (UNLIKELY(IsBitTableDeduped(i))) { |
| 42 | ssize_t bit_offset = reader.NumberOfReadBits() - reader.ReadVarint(); |
| 43 | BitMemoryReader reader2(reader.data(), bit_offset); // The offset is negative. |
| 44 | table.Decode(reader2); |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 45 | callback(i, &table, reader2.GetReadRegion()); |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 46 | } else { |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 47 | ssize_t bit_offset = reader.NumberOfReadBits(); |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 48 | table.Decode(reader); |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 49 | callback(i, &table, reader.GetReadRegion().Subregion(bit_offset)); |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 50 | } |
| 51 | } |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 52 | }); |
| 53 | if (num_read_bits != nullptr) { |
| 54 | *num_read_bits = reader.NumberOfReadBits(); |
David Srbecky | e42a4b9 | 2019-05-26 00:10:25 +0100 | [diff] [blame] | 55 | } |
David Srbecky | 078d7ba | 2018-06-21 15:36:48 +0100 | [diff] [blame] | 56 | } |
| 57 | |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 58 | CodeInfo::CodeInfo(const uint8_t* data, size_t* num_read_bits) |
| 59 | : CodeInfo(data, num_read_bits, [](size_t, auto*, BitMemoryRegion){}) {} |
| 60 | |
| 61 | CodeInfo::CodeInfo(const OatQuickMethodHeader* header) |
| 62 | : CodeInfo(header->GetOptimizedCodeInfoPtr()) {} |
| 63 | |
| 64 | QuickMethodFrameInfo CodeInfo::DecodeFrameInfo(const uint8_t* data) { |
| 65 | CodeInfo code_info(data); |
| 66 | return QuickMethodFrameInfo(code_info.packed_frame_size_ * kStackAlignment, |
| 67 | code_info.core_spill_mask_, |
| 68 | code_info.fp_spill_mask_); |
| 69 | } |
| 70 | |
| 71 | CodeInfo CodeInfo::DecodeGcMasksOnly(const OatQuickMethodHeader* header) { |
| 72 | CodeInfo code_info(header->GetOptimizedCodeInfoPtr()); |
| 73 | CodeInfo copy; // Copy to dead-code-eliminate all fields that we do not need. |
| 74 | copy.stack_maps_ = code_info.stack_maps_; |
| 75 | copy.register_masks_ = code_info.register_masks_; |
| 76 | copy.stack_masks_ = code_info.stack_masks_; |
| 77 | return copy; |
| 78 | } |
| 79 | |
| 80 | CodeInfo CodeInfo::DecodeInlineInfoOnly(const OatQuickMethodHeader* header) { |
| 81 | CodeInfo code_info(header->GetOptimizedCodeInfoPtr()); |
| 82 | CodeInfo copy; // Copy to dead-code-eliminate all fields that we do not need. |
| 83 | copy.number_of_dex_registers_ = code_info.number_of_dex_registers_; |
| 84 | copy.stack_maps_ = code_info.stack_maps_; |
| 85 | copy.inline_infos_ = code_info.inline_infos_; |
| 86 | copy.method_infos_ = code_info.method_infos_; |
| 87 | return copy; |
| 88 | } |
| 89 | |
David Srbecky | 17b4d2b | 2021-03-02 18:14:31 +0000 | [diff] [blame^] | 90 | uint32_t CodeInfo::DecodeCodeSize(const OatQuickMethodHeader* header) { |
| 91 | return CodeInfo(header->GetOptimizedCodeInfoPtr()).code_size_; |
| 92 | } |
| 93 | |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 94 | size_t CodeInfo::Deduper::Dedupe(const uint8_t* code_info_data) { |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame] | 95 | writer_.ByteAlign(); |
| 96 | size_t deduped_offset = writer_.NumberOfWrittenBits() / kBitsPerByte; |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 97 | |
David Srbecky | 6c4ec5c | 2019-06-20 07:23:19 +0000 | [diff] [blame] | 98 | // The back-reference offset takes space so dedupe is not worth it for tiny tables. |
| 99 | constexpr size_t kMinDedupSize = 32; // Assume 32-bit offset on average. |
| 100 | |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 101 | // Read the existing code info and find (and keep) dedup-map iterator for each table. |
| 102 | // The iterator stores BitMemoryRegion and bit_offset of previous identical BitTable. |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 103 | std::map<BitMemoryRegion, uint32_t, BitMemoryRegion::Less>::iterator it[kNumBitTables]; |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 104 | CodeInfo code_info(code_info_data, nullptr, [&](size_t i, auto*, BitMemoryRegion region) { |
| 105 | it[i] = dedupe_map_.emplace(region, /*bit_offset=*/0).first; |
| 106 | if (it[i]->second != 0 && region.size_in_bits() > kMinDedupSize) { // Seen before and large? |
| 107 | code_info.SetBitTableDeduped(i); // Mark as deduped before we write header. |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 108 | } |
| 109 | }); |
| 110 | |
| 111 | // Write the code info back, but replace deduped tables with relative offsets. |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 112 | std::array<uint32_t, kNumHeaders> header; |
David Srbecky | 6c4ec5c | 2019-06-20 07:23:19 +0000 | [diff] [blame] | 113 | ForEachHeaderField([&code_info, &header](size_t i, auto member_pointer) { |
| 114 | header[i] = code_info.*member_pointer; |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 115 | }); |
David Srbecky | 6c4ec5c | 2019-06-20 07:23:19 +0000 | [diff] [blame] | 116 | writer_.WriteInterleavedVarints(header); |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 117 | ForEachBitTableField([this, &code_info, &it](size_t i, auto) { |
| 118 | if (code_info.HasBitTable(i)) { |
| 119 | uint32_t& bit_offset = it[i]->second; |
| 120 | if (code_info.IsBitTableDeduped(i)) { |
| 121 | DCHECK_NE(bit_offset, 0u); |
| 122 | writer_.WriteVarint(writer_.NumberOfWrittenBits() - bit_offset); |
| 123 | } else { |
| 124 | bit_offset = writer_.NumberOfWrittenBits(); // Store offset in dedup map. |
| 125 | writer_.WriteRegion(it[i]->first); |
| 126 | } |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 127 | } |
| 128 | }); |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame] | 129 | |
| 130 | if (kIsDebugBuild) { |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 131 | CodeInfo old_code_info(code_info_data); |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame] | 132 | CodeInfo new_code_info(writer_.data() + deduped_offset); |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 133 | ForEachHeaderField([&old_code_info, &new_code_info](size_t, auto member_pointer) { |
| 134 | if (member_pointer != &CodeInfo::bit_table_flags_) { // Expected to differ. |
| 135 | DCHECK_EQ(old_code_info.*member_pointer, new_code_info.*member_pointer); |
| 136 | } |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 137 | }); |
David Srbecky | 6c4ec5c | 2019-06-20 07:23:19 +0000 | [diff] [blame] | 138 | ForEachBitTableField([&old_code_info, &new_code_info](size_t i, auto member_pointer) { |
| 139 | DCHECK_EQ(old_code_info.HasBitTable(i), new_code_info.HasBitTable(i)); |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 140 | DCHECK((old_code_info.*member_pointer).Equals(new_code_info.*member_pointer)); |
| 141 | }); |
David Srbecky | d160641 | 2018-07-31 15:05:14 +0100 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | return deduped_offset; |
David Srbecky | b73323c | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Eric Holk | f1e1dd1 | 2020-08-21 15:38:12 -0700 | [diff] [blame] | 147 | StackMap CodeInfo::GetStackMapForNativePcOffset(uintptr_t pc, InstructionSet isa) const { |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 148 | uint32_t packed_pc = StackMap::PackNativePc(pc, isa); |
| 149 | // Binary search. All catch stack maps are stored separately at the end. |
| 150 | auto it = std::partition_point( |
David Srbecky | 0b4e5a3 | 2018-06-11 16:25:29 +0100 | [diff] [blame] | 151 | stack_maps_.begin(), |
| 152 | stack_maps_.end(), |
| 153 | [packed_pc](const StackMap& sm) { |
| 154 | return sm.GetPackedNativePc() < packed_pc && sm.GetKind() != StackMap::Kind::Catch; |
| 155 | }); |
David Srbecky | 0b4e5a3 | 2018-06-11 16:25:29 +0100 | [diff] [blame] | 156 | // Start at the lower bound and iterate over all stack maps with the given native pc. |
| 157 | for (; it != stack_maps_.end() && (*it).GetNativePcOffset(isa) == pc; ++it) { |
| 158 | StackMap::Kind kind = static_cast<StackMap::Kind>((*it).GetKind()); |
| 159 | if (kind == StackMap::Kind::Default || kind == StackMap::Kind::OSR) { |
| 160 | return *it; |
| 161 | } |
| 162 | } |
David Srbecky | a45a85c | 2018-06-21 16:03:12 +0100 | [diff] [blame] | 163 | return stack_maps_.GetInvalidRow(); |
David Srbecky | 0b4e5a3 | 2018-06-11 16:25:29 +0100 | [diff] [blame] | 164 | } |
| 165 | |
David Srbecky | 6de8833 | 2018-06-03 12:00:11 +0100 | [diff] [blame] | 166 | // Scan backward to determine dex register locations at given stack map. |
| 167 | // All registers for a stack map are combined - inlined registers are just appended, |
| 168 | // therefore 'first_dex_register' allows us to select a sub-range to decode. |
| 169 | void CodeInfo::DecodeDexRegisterMap(uint32_t stack_map_index, |
| 170 | uint32_t first_dex_register, |
| 171 | /*out*/ DexRegisterMap* map) const { |
| 172 | // Count remaining work so we know when we have finished. |
| 173 | uint32_t remaining_registers = map->size(); |
| 174 | |
| 175 | // Keep scanning backwards and collect the most recent location of each register. |
| 176 | for (int32_t s = stack_map_index; s >= 0 && remaining_registers != 0; s--) { |
| 177 | StackMap stack_map = GetStackMapAt(s); |
| 178 | DCHECK_LE(stack_map_index - s, kMaxDexRegisterMapSearchDistance) << "Unbounded search"; |
| 179 | |
| 180 | // The mask specifies which registers where modified in this stack map. |
| 181 | // NB: the mask can be shorter than expected if trailing zero bits were removed. |
| 182 | uint32_t mask_index = stack_map.GetDexRegisterMaskIndex(); |
| 183 | if (mask_index == StackMap::kNoValue) { |
| 184 | continue; // Nothing changed at this stack map. |
| 185 | } |
| 186 | BitMemoryRegion mask = dex_register_masks_.GetBitMemoryRegion(mask_index); |
| 187 | if (mask.size_in_bits() <= first_dex_register) { |
| 188 | continue; // Nothing changed after the first register we are interested in. |
| 189 | } |
| 190 | |
| 191 | // The map stores one catalogue index per each modified register location. |
| 192 | uint32_t map_index = stack_map.GetDexRegisterMapIndex(); |
| 193 | DCHECK_NE(map_index, StackMap::kNoValue); |
| 194 | |
| 195 | // Skip initial registers which we are not interested in (to get to inlined registers). |
| 196 | map_index += mask.PopCount(0, first_dex_register); |
| 197 | mask = mask.Subregion(first_dex_register, mask.size_in_bits() - first_dex_register); |
| 198 | |
| 199 | // Update registers that we see for first time (i.e. most recent value). |
| 200 | DexRegisterLocation* regs = map->data(); |
| 201 | const uint32_t end = std::min<uint32_t>(map->size(), mask.size_in_bits()); |
| 202 | const size_t kNumBits = BitSizeOf<uint32_t>(); |
| 203 | for (uint32_t reg = 0; reg < end; reg += kNumBits) { |
| 204 | // Process the mask in chunks of kNumBits for performance. |
| 205 | uint32_t bits = mask.LoadBits(reg, std::min<uint32_t>(end - reg, kNumBits)); |
| 206 | while (bits != 0) { |
| 207 | uint32_t bit = CTZ(bits); |
| 208 | if (regs[reg + bit].GetKind() == DexRegisterLocation::Kind::kInvalid) { |
| 209 | regs[reg + bit] = GetDexRegisterCatalogEntry(dex_register_maps_.Get(map_index)); |
| 210 | remaining_registers--; |
| 211 | } |
| 212 | map_index++; |
| 213 | bits ^= 1u << bit; // Clear the bit. |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | // Set any remaining registers to None (which is the default state at first stack map). |
| 219 | if (remaining_registers != 0) { |
| 220 | DexRegisterLocation* regs = map->data(); |
| 221 | for (uint32_t r = 0; r < map->size(); r++) { |
| 222 | if (regs[r].GetKind() == DexRegisterLocation::Kind::kInvalid) { |
| 223 | regs[r] = DexRegisterLocation::None(); |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 229 | // Decode the CodeInfo while collecting size statistics. |
| 230 | void CodeInfo::CollectSizeStats(const uint8_t* code_info_data, /*out*/ Stats* parent) { |
| 231 | Stats* codeinfo_stats = parent->Child("CodeInfo"); |
| 232 | BitMemoryReader reader(code_info_data); |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 233 | reader.ReadInterleavedVarints<kNumHeaders>(); |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 234 | codeinfo_stats->Child("Header")->AddBits(reader.NumberOfReadBits()); |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 235 | size_t num_bits; |
| 236 | CodeInfo code_info(code_info_data, &num_bits, [&](size_t i, auto* table, BitMemoryRegion region) { |
| 237 | if (!code_info.IsBitTableDeduped(i)) { |
| 238 | Stats* table_stats = codeinfo_stats->Child(table->GetName()); |
| 239 | table_stats->AddBits(region.size_in_bits()); |
| 240 | const char* const* column_names = table->GetColumnNames(); |
| 241 | for (size_t c = 0; c < table->NumColumns(); c++) { |
| 242 | if (table->NumColumnBits(c) > 0) { |
| 243 | Stats* column_stats = table_stats->Child(column_names[c]); |
| 244 | column_stats->AddBits(table->NumRows() * table->NumColumnBits(c), table->NumRows()); |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 245 | } |
| 246 | } |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 247 | } |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 248 | }); |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 249 | codeinfo_stats->AddBytes(BitsToBytesRoundUp(num_bits)); |
David Srbecky | 86decb6 | 2018-06-05 06:41:10 +0100 | [diff] [blame] | 250 | } |
| 251 | |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 252 | void DexRegisterMap::Dump(VariableIndentationOutputStream* vios) const { |
| 253 | if (HasAnyLiveDexRegisters()) { |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 254 | ScopedIndentation indent1(vios); |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 255 | for (size_t i = 0; i < size(); ++i) { |
| 256 | DexRegisterLocation reg = (*this)[i]; |
| 257 | if (reg.IsLive()) { |
| 258 | vios->Stream() << "v" << i << ":" << reg << " "; |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | vios->Stream() << "\n"; |
| 262 | } |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 265 | void CodeInfo::Dump(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 266 | uint32_t code_offset, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 267 | bool verbose, |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 268 | InstructionSet instruction_set) const { |
David Srbecky | 0d4567f | 2019-05-30 22:45:40 +0100 | [diff] [blame] | 269 | vios->Stream() << "CodeInfo " |
David Srbecky | 17b4d2b | 2021-03-02 18:14:31 +0000 | [diff] [blame^] | 270 | << " CodeSize:" << code_size_ |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 271 | << " FrameSize:" << packed_frame_size_ * kStackAlignment |
| 272 | << " CoreSpillMask:" << std::hex << core_spill_mask_ |
| 273 | << " FpSpillMask:" << std::hex << fp_spill_mask_ |
| 274 | << " NumberOfDexRegisters:" << std::dec << number_of_dex_registers_ |
| 275 | << "\n"; |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 276 | ScopedIndentation indent1(vios); |
David Srbecky | 697c47a | 2019-06-16 21:53:07 +0100 | [diff] [blame] | 277 | ForEachBitTableField([this, &vios, verbose](size_t, auto member_pointer) { |
David Srbecky | 42deda8 | 2018-08-10 11:23:27 +0100 | [diff] [blame] | 278 | const auto& table = this->*member_pointer; |
| 279 | if (table.NumRows() != 0) { |
| 280 | vios->Stream() << table.GetName() << " BitSize=" << table.DataBitSize(); |
| 281 | vios->Stream() << " Rows=" << table.NumRows() << " Bits={"; |
| 282 | const char* const* column_names = table.GetColumnNames(); |
| 283 | for (size_t c = 0; c < table.NumColumns(); c++) { |
| 284 | vios->Stream() << (c != 0 ? " " : ""); |
| 285 | vios->Stream() << column_names[c] << "=" << table.NumColumnBits(c); |
| 286 | } |
| 287 | vios->Stream() << "}\n"; |
| 288 | if (verbose) { |
| 289 | ScopedIndentation indent1(vios); |
| 290 | for (size_t r = 0; r < table.NumRows(); r++) { |
| 291 | vios->Stream() << "[" << std::right << std::setw(3) << r << "]={"; |
| 292 | for (size_t c = 0; c < table.NumColumns(); c++) { |
| 293 | vios->Stream() << (c != 0 ? " " : ""); |
| 294 | if (&table == static_cast<const void*>(&stack_masks_) || |
| 295 | &table == static_cast<const void*>(&dex_register_masks_)) { |
| 296 | BitMemoryRegion bits = table.GetBitMemoryRegion(r, c); |
| 297 | for (size_t b = 0, e = bits.size_in_bits(); b < e; b++) { |
| 298 | vios->Stream() << bits.LoadBit(e - b - 1); |
| 299 | } |
| 300 | } else { |
| 301 | vios->Stream() << std::right << std::setw(8) << static_cast<int32_t>(table.Get(r, c)); |
| 302 | } |
| 303 | } |
| 304 | vios->Stream() << "}\n"; |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | }); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 309 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 310 | // Display stack maps along with (live) Dex register maps. |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 311 | if (verbose) { |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 312 | for (StackMap stack_map : stack_maps_) { |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 313 | stack_map.Dump(vios, *this, code_offset, instruction_set); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 318 | void StackMap::Dump(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 319 | const CodeInfo& code_info, |
| 320 | uint32_t code_offset, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 321 | InstructionSet instruction_set) const { |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 322 | const uint32_t pc_offset = GetNativePcOffset(instruction_set); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 323 | vios->Stream() |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 324 | << "StackMap[" << Row() << "]" |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 325 | << std::hex |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame] | 326 | << " (native_pc=0x" << code_offset + pc_offset |
| 327 | << ", dex_pc=0x" << GetDexPc() |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 328 | << ", register_mask=0x" << code_info.GetRegisterMaskOf(*this) |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 329 | << std::dec |
| 330 | << ", stack_mask=0b"; |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 331 | BitMemoryRegion stack_mask = code_info.GetStackMaskOf(*this); |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 332 | 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] | 333 | vios->Stream() << stack_mask.LoadBit(e - i - 1); |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 334 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 335 | vios->Stream() << ")\n"; |
David Srbecky | e140212 | 2018-06-13 18:20:45 +0100 | [diff] [blame] | 336 | code_info.GetDexRegisterMapOf(*this).Dump(vios); |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 337 | for (InlineInfo inline_info : code_info.GetInlineInfosOf(*this)) { |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 338 | inline_info.Dump(vios, code_info, *this); |
Nicolas Geoffray | 12bdb72 | 2015-06-17 09:44:43 +0100 | [diff] [blame] | 339 | } |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 340 | } |
| 341 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 342 | void InlineInfo::Dump(VariableIndentationOutputStream* vios, |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 343 | const CodeInfo& code_info, |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 344 | const StackMap& stack_map) const { |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame] | 345 | uint32_t depth = Row() - stack_map.GetInlineInfoIndex(); |
| 346 | vios->Stream() |
| 347 | << "InlineInfo[" << Row() << "]" |
| 348 | << " (depth=" << depth |
| 349 | << std::hex |
| 350 | << ", dex_pc=0x" << GetDexPc(); |
| 351 | if (EncodesArtMethod()) { |
| 352 | ScopedObjectAccess soa(Thread::Current()); |
| 353 | vios->Stream() << ", method=" << GetArtMethod()->PrettyMethod(); |
| 354 | } else { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 355 | vios->Stream() |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame] | 356 | << std::dec |
David Srbecky | 8cd5454 | 2018-07-15 23:58:44 +0100 | [diff] [blame] | 357 | << ", method_index=" << code_info.GetMethodIndexOf(*this); |
David Srbecky | 6e69e52 | 2018-06-03 12:00:14 +0100 | [diff] [blame] | 358 | } |
| 359 | vios->Stream() << ")\n"; |
David Srbecky | 93bd361 | 2018-07-02 19:30:18 +0100 | [diff] [blame] | 360 | code_info.GetInlineDexRegisterMapOf(stack_map, *this).Dump(vios); |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | } // namespace art |