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" |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 24 | #include "scoped_thread_state_change-inl.h" |
Roland Levillain | 0396ed7 | 2015-05-27 15:12:19 +0100 | [diff] [blame] | 25 | |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 26 | namespace art { |
| 27 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 28 | std::ostream& operator<<(std::ostream& stream, const DexRegisterLocation& reg) { |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 29 | using Kind = DexRegisterLocation::Kind; |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 30 | switch (reg.GetKind()) { |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 31 | case Kind::kNone: |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 32 | return stream << "None"; |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 33 | case Kind::kInStack: |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 34 | return stream << "sp+" << reg.GetValue(); |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 35 | case Kind::kInRegister: |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 36 | return stream << "r" << reg.GetValue(); |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 37 | case Kind::kInRegisterHigh: |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 38 | return stream << "r" << reg.GetValue() << "/hi"; |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 39 | case Kind::kInFpuRegister: |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 40 | return stream << "f" << reg.GetValue(); |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 41 | case Kind::kInFpuRegisterHigh: |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 42 | return stream << "f" << reg.GetValue() << "/hi"; |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 43 | case Kind::kConstant: |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 44 | return stream << "#" << reg.GetValue(); |
| 45 | default: |
| 46 | return stream << "DexRegisterLocation(" << static_cast<uint32_t>(reg.GetKind()) |
| 47 | << "," << reg.GetValue() << ")"; |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 48 | } |
David Srbecky | 7dc1178 | 2016-02-25 13:23:56 +0000 | [diff] [blame] | 49 | } |
| 50 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 51 | static void DumpDexRegisterMap(VariableIndentationOutputStream* vios, |
| 52 | const DexRegisterMap& map) { |
| 53 | if (map.IsValid()) { |
| 54 | ScopedIndentation indent1(vios); |
| 55 | for (size_t i = 0; i < map.size(); ++i) { |
| 56 | if (map.IsDexRegisterLive(i)) { |
| 57 | vios->Stream() << "v" << i << ":" << map.Get(i) << " "; |
| 58 | } |
| 59 | } |
| 60 | vios->Stream() << "\n"; |
| 61 | } |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 62 | } |
| 63 | |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 64 | template<uint32_t kNumColumns> |
| 65 | static void DumpTable(VariableIndentationOutputStream* vios, |
| 66 | const char* table_name, |
| 67 | const BitTable<kNumColumns>& table, |
| 68 | bool verbose, |
| 69 | bool is_mask = false) { |
| 70 | if (table.NumRows() != 0) { |
| 71 | vios->Stream() << table_name << " BitSize=" << table.NumRows() * table.NumRowBits(); |
| 72 | vios->Stream() << " Rows=" << table.NumRows() << " Bits={"; |
| 73 | for (size_t c = 0; c < table.NumColumns(); c++) { |
| 74 | vios->Stream() << (c != 0 ? " " : ""); |
| 75 | vios->Stream() << table.NumColumnBits(c); |
| 76 | } |
| 77 | vios->Stream() << "}\n"; |
| 78 | if (verbose) { |
| 79 | ScopedIndentation indent1(vios); |
| 80 | for (size_t r = 0; r < table.NumRows(); r++) { |
| 81 | vios->Stream() << "[" << std::right << std::setw(3) << r << "]={"; |
| 82 | for (size_t c = 0; c < table.NumColumns(); c++) { |
| 83 | vios->Stream() << (c != 0 ? " " : ""); |
| 84 | if (is_mask) { |
| 85 | BitMemoryRegion bits = table.GetBitMemoryRegion(r, c); |
| 86 | for (size_t b = 0, e = bits.size_in_bits(); b < e; b++) { |
| 87 | vios->Stream() << bits.LoadBit(e - b - 1); |
| 88 | } |
| 89 | } else { |
| 90 | vios->Stream() << std::right << std::setw(8) << static_cast<int32_t>(table.Get(r, c)); |
| 91 | } |
| 92 | } |
| 93 | vios->Stream() << "}\n"; |
| 94 | } |
| 95 | } |
| 96 | } |
David Srbecky | 61b28a1 | 2016-02-25 21:55:03 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 99 | void CodeInfo::Dump(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 100 | uint32_t code_offset, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 101 | uint16_t num_dex_registers, |
| 102 | bool verbose, |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 103 | InstructionSet instruction_set, |
| 104 | const MethodInfo& method_info) const { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 105 | vios->Stream() |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 106 | << "CodeInfo" |
| 107 | << " BitSize=" << size_ * kBitsPerByte |
| 108 | << "\n"; |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 109 | ScopedIndentation indent1(vios); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 110 | DumpTable(vios, "StackMaps", stack_maps_, verbose); |
| 111 | DumpTable(vios, "RegisterMasks", register_masks_, verbose); |
| 112 | DumpTable(vios, "StackMasks", stack_masks_, verbose, true /* is_mask */); |
| 113 | DumpTable(vios, "InvokeInfos", invoke_infos_, verbose); |
| 114 | DumpTable(vios, "InlineInfos", inline_infos_, verbose); |
| 115 | DumpTable(vios, "DexRegisterMasks", dex_register_masks_, verbose, true /* is_mask */); |
| 116 | DumpTable(vios, "DexRegisterMaps", dex_register_maps_, verbose); |
| 117 | DumpTable(vios, "DexRegisterCatalog", dex_register_catalog_, verbose); |
| 118 | |
Roland Levillain | a552e1c | 2015-03-26 15:01:03 +0000 | [diff] [blame] | 119 | // Display stack maps along with (live) Dex register maps. |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 120 | if (verbose) { |
| 121 | for (size_t i = 0; i < GetNumberOfStackMaps(); ++i) { |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 122 | StackMap stack_map = GetStackMapAt(i); |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 123 | stack_map.Dump(vios, *this, method_info, code_offset, num_dex_registers, instruction_set); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 128 | void StackMap::Dump(VariableIndentationOutputStream* vios, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 129 | const CodeInfo& code_info, |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 130 | const MethodInfo& method_info, |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 131 | uint32_t code_offset, |
| 132 | uint16_t number_of_dex_registers, |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 133 | InstructionSet instruction_set) const { |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 134 | const uint32_t pc_offset = GetNativePcOffset(instruction_set); |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 135 | vios->Stream() |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 136 | << "StackMap[" << Row() << "]" |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 137 | << std::hex |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 138 | << " (native_pc=0x" << code_offset + pc_offset |
| 139 | << ", dex_pc=0x" << GetDexPc() |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 140 | << ", register_mask=0x" << code_info.GetRegisterMaskOf(*this) |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 141 | << std::dec |
| 142 | << ", stack_mask=0b"; |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 143 | BitMemoryRegion stack_mask = code_info.GetStackMaskOf(*this); |
David Srbecky | 4b59d10 | 2018-05-29 21:46:10 +0000 | [diff] [blame] | 144 | 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] | 145 | vios->Stream() << stack_mask.LoadBit(e - i - 1); |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 146 | } |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 147 | vios->Stream() << ")\n"; |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 148 | DumpDexRegisterMap(vios, code_info.GetDexRegisterMapOf(*this, number_of_dex_registers)); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 149 | if (HasInlineInfo()) { |
| 150 | InlineInfo inline_info = code_info.GetInlineInfoOf(*this); |
Nicolas Geoffray | 12bdb72 | 2015-06-17 09:44:43 +0100 | [diff] [blame] | 151 | // We do not know the length of the dex register maps of inlined frames |
| 152 | // at this level, so we just pass null to `InlineInfo::Dump` to tell |
| 153 | // it not to look at these maps. |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 154 | inline_info.Dump(vios, code_info, method_info, nullptr); |
Nicolas Geoffray | 12bdb72 | 2015-06-17 09:44:43 +0100 | [diff] [blame] | 155 | } |
Roland Levillain | f2650d1 | 2015-05-28 14:53:28 +0100 | [diff] [blame] | 156 | } |
| 157 | |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 158 | void InlineInfo::Dump(VariableIndentationOutputStream* vios, |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 159 | const CodeInfo& code_info, |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 160 | const MethodInfo& method_info, |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 161 | uint16_t number_of_dex_registers[]) const { |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 162 | for (size_t i = 0; i < GetDepth(); ++i) { |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 163 | vios->Stream() |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 164 | << "InlineInfo[" << Row() + i << "]" |
| 165 | << " (depth=" << i |
Vladimir Marko | 8f1e08a | 2015-06-26 12:06:30 +0100 | [diff] [blame] | 166 | << std::hex |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 167 | << ", dex_pc=0x" << GetDexPcAtDepth(i); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 168 | if (EncodesArtMethodAtDepth(i)) { |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 169 | ScopedObjectAccess soa(Thread::Current()); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 170 | vios->Stream() << ", method=" << GetArtMethodAtDepth(i)->PrettyMethod(); |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 171 | } else { |
| 172 | vios->Stream() |
| 173 | << std::dec |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 174 | << ", method_index=" << GetMethodIndexAtDepth(method_info, i); |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 175 | } |
| 176 | vios->Stream() << ")\n"; |
David Srbecky | 71ec1cc | 2018-05-18 15:57:25 +0100 | [diff] [blame^] | 177 | if (number_of_dex_registers != nullptr) { |
| 178 | uint16_t vregs = number_of_dex_registers[i]; |
| 179 | DumpDexRegisterMap(vios, code_info.GetDexRegisterMapAtDepth(i, *this, vregs)); |
Nicolas Geoffray | b1d0f3f | 2015-05-14 12:41:51 +0100 | [diff] [blame] | 180 | } |
| 181 | } |
Nicolas Geoffray | 004c230 | 2015-03-20 10:06:38 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | } // namespace art |