Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 16 | |
Sebastien Hertz | 807a256 | 2013-04-15 09:33:39 +0200 | [diff] [blame] | 17 | #include "dex_instruction-inl.h" |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 18 | |
Ian Rogers | b574c18 | 2014-01-23 19:51:19 -0800 | [diff] [blame] | 19 | #include <inttypes.h> |
| 20 | |
| 21 | #include <iomanip> |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 22 | #include <sstream> |
Ian Rogers | b574c18 | 2014-01-23 19:51:19 -0800 | [diff] [blame] | 23 | |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 24 | #include "base/stringprintf.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 25 | #include "dex_file-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 26 | #include "utils.h" |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 27 | |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 28 | namespace art { |
| 29 | |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 30 | const char* const Instruction::kInstructionNames[] = { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 31 | #define INSTRUCTION_NAME(o, c, pname, f, r, i, a, v) pname, |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 32 | #include "dex_instruction_list.h" |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 33 | DEX_INSTRUCTION_LIST(INSTRUCTION_NAME) |
| 34 | #undef DEX_INSTRUCTION_LIST |
| 35 | #undef INSTRUCTION_NAME |
| 36 | }; |
| 37 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 38 | Instruction::Format const Instruction::kInstructionFormats[] = { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 39 | #define INSTRUCTION_FORMAT(o, c, p, format, r, i, a, v) format, |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 40 | #include "dex_instruction_list.h" |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 41 | DEX_INSTRUCTION_LIST(INSTRUCTION_FORMAT) |
| 42 | #undef DEX_INSTRUCTION_LIST |
| 43 | #undef INSTRUCTION_FORMAT |
| 44 | }; |
| 45 | |
| 46 | int const Instruction::kInstructionFlags[] = { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 47 | #define INSTRUCTION_FLAGS(o, c, p, f, r, i, flags, v) flags, |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 48 | #include "dex_instruction_list.h" |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 49 | DEX_INSTRUCTION_LIST(INSTRUCTION_FLAGS) |
| 50 | #undef DEX_INSTRUCTION_LIST |
| 51 | #undef INSTRUCTION_FLAGS |
| 52 | }; |
| 53 | |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 54 | int const Instruction::kInstructionVerifyFlags[] = { |
| 55 | #define INSTRUCTION_VERIFY_FLAGS(o, c, p, f, r, i, a, vflags) vflags, |
| 56 | #include "dex_instruction_list.h" |
| 57 | DEX_INSTRUCTION_LIST(INSTRUCTION_VERIFY_FLAGS) |
| 58 | #undef DEX_INSTRUCTION_LIST |
| 59 | #undef INSTRUCTION_VERIFY_FLAGS |
| 60 | }; |
| 61 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 62 | int const Instruction::kInstructionSizeInCodeUnits[] = { |
| 63 | #define INSTRUCTION_SIZE(opcode, c, p, format, r, i, a, v) \ |
Brian Carlstrom | 6f485c6 | 2013-07-18 15:35:35 -0700 | [diff] [blame] | 64 | ((opcode == NOP) ? -1 : \ |
| 65 | ((format >= k10x) && (format <= k10t)) ? 1 : \ |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 66 | ((format >= k20t) && (format <= k25x)) ? 2 : \ |
Brian Carlstrom | 6f485c6 | 2013-07-18 15:35:35 -0700 | [diff] [blame] | 67 | ((format >= k32x) && (format <= k3rc)) ? 3 : \ |
| 68 | (format == k51l) ? 5 : -1), |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 69 | #include "dex_instruction_list.h" |
| 70 | DEX_INSTRUCTION_LIST(INSTRUCTION_SIZE) |
| 71 | #undef DEX_INSTRUCTION_LIST |
| 72 | #undef INSTRUCTION_SIZE |
| 73 | }; |
| 74 | |
Dragos Sbirlea | 39f9927 | 2013-06-25 13:17:36 -0700 | [diff] [blame] | 75 | int32_t Instruction::GetTargetOffset() const { |
| 76 | switch (FormatOf(Opcode())) { |
| 77 | // Cases for conditional branches follow. |
| 78 | case k22t: return VRegC_22t(); |
| 79 | case k21t: return VRegB_21t(); |
| 80 | // Cases for unconditional branches follow. |
| 81 | case k10t: return VRegA_10t(); |
| 82 | case k20t: return VRegA_20t(); |
| 83 | case k30t: return VRegA_30t(); |
| 84 | default: LOG(FATAL) << "Tried to access the branch offset of an instruction " << Name() << |
| 85 | " which does not have a target operand."; |
| 86 | } |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | bool Instruction::CanFlowThrough() const { |
| 91 | const uint16_t* insns = reinterpret_cast<const uint16_t*>(this); |
| 92 | uint16_t insn = *insns; |
| 93 | Code opcode = static_cast<Code>(insn & 0xFF); |
| 94 | return FlagsOf(opcode) & Instruction::kContinue; |
| 95 | } |
| 96 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 97 | size_t Instruction::SizeInCodeUnitsComplexOpcode() const { |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 98 | const uint16_t* insns = reinterpret_cast<const uint16_t*>(this); |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 99 | // Handle special NOP encoded variable length sequences. |
| 100 | switch (*insns) { |
| 101 | case kPackedSwitchSignature: |
| 102 | return (4 + insns[1] * 2); |
| 103 | case kSparseSwitchSignature: |
| 104 | return (2 + insns[1] * 4); |
| 105 | case kArrayDataSignature: { |
| 106 | uint16_t element_size = insns[1]; |
| 107 | uint32_t length = insns[2] | (((uint32_t)insns[3]) << 16); |
| 108 | // The plus 1 is to round up for odd size and width. |
| 109 | return (4 + (element_size * length + 1) / 2); |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 110 | } |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 111 | default: |
| 112 | if ((*insns & 0xFF) == 0) { |
| 113 | return 1; // NOP. |
| 114 | } else { |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 115 | LOG(FATAL) << "Unreachable: " << DumpString(nullptr); |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 116 | UNREACHABLE(); |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 117 | } |
Carl Shapiro | e4c1ce4 | 2011-07-09 02:31:57 -0700 | [diff] [blame] | 118 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 121 | std::string Instruction::DumpHex(size_t code_units) const { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 122 | size_t inst_length = SizeInCodeUnits(); |
| 123 | if (inst_length > code_units) { |
| 124 | inst_length = code_units; |
| 125 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 126 | std::ostringstream os; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 127 | const uint16_t* insn = reinterpret_cast<const uint16_t*>(this); |
| 128 | for (size_t i = 0; i < inst_length; i++) { |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 129 | os << StringPrintf("0x%04x", insn[i]) << " "; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 130 | } |
| 131 | for (size_t i = inst_length; i < code_units; i++) { |
| 132 | os << " "; |
| 133 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 134 | return os.str(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 137 | std::string Instruction::DumpHexLE(size_t instr_code_units) const { |
| 138 | size_t inst_length = SizeInCodeUnits(); |
| 139 | if (inst_length > instr_code_units) { |
| 140 | inst_length = instr_code_units; |
| 141 | } |
| 142 | std::ostringstream os; |
| 143 | const uint16_t* insn = reinterpret_cast<const uint16_t*>(this); |
| 144 | for (size_t i = 0; i < inst_length; i++) { |
Andreas Gampe | 4f0be4d | 2015-02-27 22:16:14 -0800 | [diff] [blame] | 145 | os << StringPrintf("%02x%02x", static_cast<uint8_t>(insn[i] & 0x00FF), |
| 146 | static_cast<uint8_t>((insn[i] & 0xFF00) >> 8)) << " "; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 147 | } |
| 148 | for (size_t i = inst_length; i < instr_code_units; i++) { |
Andreas Gampe | 4f0be4d | 2015-02-27 22:16:14 -0800 | [diff] [blame] | 149 | os << " "; |
Anestis Bechtsoudis | 32f500d | 2015-02-22 22:32:57 -0800 | [diff] [blame] | 150 | } |
| 151 | return os.str(); |
| 152 | } |
| 153 | |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 154 | std::string Instruction::DumpString(const DexFile* file) const { |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 155 | std::ostringstream os; |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 156 | const char* opcode = kInstructionNames[Opcode()]; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 157 | switch (FormatOf(Opcode())) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 158 | case k10x: os << opcode; break; |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 159 | case k12x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_12x(), VRegB_12x()); break; |
| 160 | case k11n: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_11n(), VRegB_11n()); break; |
| 161 | case k11x: os << StringPrintf("%s v%d", opcode, VRegA_11x()); break; |
| 162 | case k10t: os << StringPrintf("%s %+d", opcode, VRegA_10t()); break; |
| 163 | case k20t: os << StringPrintf("%s %+d", opcode, VRegA_20t()); break; |
| 164 | case k22x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_22x(), VRegB_22x()); break; |
| 165 | case k21t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_21t(), VRegB_21t()); break; |
| 166 | case k21s: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_21s(), VRegB_21s()); break; |
Elliott Hughes | 1b3d6ca | 2012-04-25 13:00:14 -0700 | [diff] [blame] | 167 | case k21h: { |
| 168 | // op vAA, #+BBBB0000[00000000] |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 169 | if (Opcode() == CONST_HIGH16) { |
| 170 | uint32_t value = VRegB_21h() << 16; |
| 171 | os << StringPrintf("%s v%d, #int %+d // 0x%x", opcode, VRegA_21h(), value, value); |
Elliott Hughes | 1b3d6ca | 2012-04-25 13:00:14 -0700 | [diff] [blame] | 172 | } else { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 173 | uint64_t value = static_cast<uint64_t>(VRegB_21h()) << 48; |
Ian Rogers | b574c18 | 2014-01-23 19:51:19 -0800 | [diff] [blame] | 174 | os << StringPrintf("%s v%d, #long %+" PRId64 " // 0x%" PRIx64, opcode, VRegA_21h(), |
| 175 | value, value); |
Elliott Hughes | 1b3d6ca | 2012-04-25 13:00:14 -0700 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | break; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 179 | case k21c: { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 180 | switch (Opcode()) { |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 181 | case CONST_STRING: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 182 | if (file != nullptr) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 183 | uint32_t string_idx = VRegB_21c(); |
| 184 | os << StringPrintf("const-string v%d, %s // string@%d", VRegA_21c(), |
| 185 | PrintableString(file->StringDataByIdx(string_idx)).c_str(), string_idx); |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 186 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 187 | } |
| 188 | FALLTHROUGH_INTENDED; |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 189 | case CHECK_CAST: |
| 190 | case CONST_CLASS: |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 191 | case NEW_INSTANCE: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 192 | if (file != nullptr) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 193 | uint32_t type_idx = VRegB_21c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 194 | os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyType(type_idx, *file) |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 195 | << " // type@" << type_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 196 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 197 | } |
| 198 | FALLTHROUGH_INTENDED; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 199 | case SGET: |
| 200 | case SGET_WIDE: |
| 201 | case SGET_OBJECT: |
| 202 | case SGET_BOOLEAN: |
| 203 | case SGET_BYTE: |
| 204 | case SGET_CHAR: |
| 205 | case SGET_SHORT: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 206 | if (file != nullptr) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 207 | uint32_t field_idx = VRegB_21c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 208 | os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyField(field_idx, *file, true) |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 209 | << " // field@" << field_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 210 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 211 | } |
| 212 | FALLTHROUGH_INTENDED; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 213 | case SPUT: |
| 214 | case SPUT_WIDE: |
| 215 | case SPUT_OBJECT: |
| 216 | case SPUT_BOOLEAN: |
| 217 | case SPUT_BYTE: |
| 218 | case SPUT_CHAR: |
| 219 | case SPUT_SHORT: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 220 | if (file != nullptr) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 221 | uint32_t field_idx = VRegB_21c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 222 | os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyField(field_idx, *file, true) |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 223 | << " // field@" << field_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 224 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 225 | } |
| 226 | FALLTHROUGH_INTENDED; |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 227 | case CREATE_LAMBDA: |
| 228 | if (file != nullptr) { |
| 229 | uint32_t method_idx = VRegB_21c(); |
| 230 | os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyMethod(method_idx, *file, true) |
| 231 | << " // method@" << method_idx; |
| 232 | break; |
| 233 | } |
| 234 | FALLTHROUGH_INTENDED; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 235 | default: |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 236 | os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_21c(), VRegB_21c()); |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 237 | break; |
| 238 | } |
| 239 | break; |
| 240 | } |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 241 | case k23x: os << StringPrintf("%s v%d, v%d, v%d", opcode, VRegA_23x(), VRegB_23x(), VRegC_23x()); break; |
| 242 | case k22b: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22b(), VRegB_22b(), VRegC_22b()); break; |
| 243 | case k22t: os << StringPrintf("%s v%d, v%d, %+d", opcode, VRegA_22t(), VRegB_22t(), VRegC_22t()); break; |
| 244 | case k22s: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22s(), VRegB_22s(), VRegC_22s()); break; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 245 | case k22c: { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 246 | switch (Opcode()) { |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 247 | case IGET: |
| 248 | case IGET_WIDE: |
| 249 | case IGET_OBJECT: |
| 250 | case IGET_BOOLEAN: |
| 251 | case IGET_BYTE: |
| 252 | case IGET_CHAR: |
| 253 | case IGET_SHORT: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 254 | if (file != nullptr) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 255 | uint32_t field_idx = VRegC_22c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 256 | os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", " |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 257 | << PrettyField(field_idx, *file, true) << " // field@" << field_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 258 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 259 | } |
| 260 | FALLTHROUGH_INTENDED; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 261 | case IGET_QUICK: |
| 262 | case IGET_OBJECT_QUICK: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 263 | if (file != nullptr) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 264 | uint32_t field_idx = VRegC_22c(); |
| 265 | os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", " |
| 266 | << "// offset@" << field_idx; |
| 267 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 268 | } |
| 269 | FALLTHROUGH_INTENDED; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 270 | case IPUT: |
| 271 | case IPUT_WIDE: |
| 272 | case IPUT_OBJECT: |
| 273 | case IPUT_BOOLEAN: |
| 274 | case IPUT_BYTE: |
| 275 | case IPUT_CHAR: |
| 276 | case IPUT_SHORT: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 277 | if (file != nullptr) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 278 | uint32_t field_idx = VRegC_22c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 279 | os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", " |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 280 | << PrettyField(field_idx, *file, true) << " // field@" << field_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 281 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 282 | } |
| 283 | FALLTHROUGH_INTENDED; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 284 | case IPUT_QUICK: |
| 285 | case IPUT_OBJECT_QUICK: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 286 | if (file != nullptr) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 287 | uint32_t field_idx = VRegC_22c(); |
| 288 | os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", " |
| 289 | << "// offset@" << field_idx; |
| 290 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 291 | } |
| 292 | FALLTHROUGH_INTENDED; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 293 | case INSTANCE_OF: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 294 | if (file != nullptr) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 295 | uint32_t type_idx = VRegC_22c(); |
Dragos Sbirlea | d4e868a | 2013-05-23 09:44:17 -0700 | [diff] [blame] | 296 | os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", " |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 297 | << PrettyType(type_idx, *file) << " // type@" << type_idx; |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 298 | break; |
| 299 | } |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 300 | FALLTHROUGH_INTENDED; |
Mathieu Chartier | 18c24b6 | 2012-09-10 08:54:25 -0700 | [diff] [blame] | 301 | case NEW_ARRAY: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 302 | if (file != nullptr) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 303 | uint32_t type_idx = VRegC_22c(); |
Dragos Sbirlea | b43cef3 | 2013-05-23 11:59:20 -0700 | [diff] [blame] | 304 | os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", " |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 305 | << PrettyType(type_idx, *file) << " // type@" << type_idx; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 306 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 307 | } |
| 308 | FALLTHROUGH_INTENDED; |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 309 | default: |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 310 | os << StringPrintf("%s v%d, v%d, thing@%d", opcode, VRegA_22c(), VRegB_22c(), VRegC_22c()); |
Ian Rogers | 90334e5 | 2012-06-06 20:22:20 -0700 | [diff] [blame] | 311 | break; |
| 312 | } |
| 313 | break; |
| 314 | } |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 315 | case k25x: { |
| 316 | if (Opcode() == INVOKE_LAMBDA) { |
| 317 | uint32_t arg[kMaxVarArgRegs]; |
| 318 | GetAllArgs25x(arg); |
| 319 | const size_t num_extra_var_args = VRegB_25x(); |
| 320 | DCHECK_LE(num_extra_var_args + 1, kMaxVarArgRegs); |
| 321 | |
| 322 | // invoke-lambda vC, {vD, vE, vF, vG} |
| 323 | os << opcode << " v" << arg[0] << ", {"; |
| 324 | for (size_t i = 0; i < num_extra_var_args; ++i) { |
| 325 | if (i != 0) { |
| 326 | os << ", "; |
| 327 | } |
| 328 | os << "v" << arg[i+1]; |
| 329 | } |
| 330 | os << "}"; |
| 331 | break; |
| 332 | } |
| 333 | FALLTHROUGH_INTENDED; |
| 334 | } |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 335 | case k32x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_32x(), VRegB_32x()); break; |
| 336 | case k30t: os << StringPrintf("%s %+d", opcode, VRegA_30t()); break; |
| 337 | case k31t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_31t(), VRegB_31t()); break; |
| 338 | case k31i: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_31i(), VRegB_31i()); break; |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 339 | case k31c: |
| 340 | if (Opcode() == CONST_STRING_JUMBO) { |
| 341 | uint32_t string_idx = VRegB_31c(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 342 | if (file != nullptr) { |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 343 | os << StringPrintf("%s v%d, %s // string@%d", opcode, VRegA_31c(), |
| 344 | PrintableString(file->StringDataByIdx(string_idx)).c_str(), |
| 345 | string_idx); |
| 346 | } else { |
| 347 | os << StringPrintf("%s v%d, string@%d", opcode, VRegA_31c(), string_idx); |
| 348 | } |
| 349 | } else { |
| 350 | os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_31c(), VRegB_31c()); break; |
| 351 | } |
| 352 | break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 353 | case k35c: { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 354 | uint32_t arg[5]; |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 355 | GetVarArgs(arg); |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 356 | switch (Opcode()) { |
Andreas Gampe | 7aca91d | 2014-03-31 18:10:53 -0700 | [diff] [blame] | 357 | case FILLED_NEW_ARRAY: |
| 358 | { |
| 359 | const int32_t a = VRegA_35c(); |
| 360 | os << opcode << " {"; |
| 361 | for (int i = 0; i < a; ++i) { |
| 362 | if (i > 0) { |
| 363 | os << ", "; |
| 364 | } |
| 365 | os << "v" << arg[i]; |
| 366 | } |
| 367 | os << "}, type@" << VRegB_35c(); |
| 368 | } |
| 369 | break; |
| 370 | |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 371 | case INVOKE_VIRTUAL: |
| 372 | case INVOKE_SUPER: |
| 373 | case INVOKE_DIRECT: |
| 374 | case INVOKE_STATIC: |
| 375 | case INVOKE_INTERFACE: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 376 | if (file != nullptr) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 377 | os << opcode << " {"; |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 378 | uint32_t method_idx = VRegB_35c(); |
| 379 | for (size_t i = 0; i < VRegA_35c(); ++i) { |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 380 | if (i != 0) { |
| 381 | os << ", "; |
| 382 | } |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 383 | os << "v" << arg[i]; |
Elliott Hughes | e3c845c | 2012-02-28 17:23:01 -0800 | [diff] [blame] | 384 | } |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 385 | os << "}, " << PrettyMethod(method_idx, *file) << " // method@" << method_idx; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 386 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 387 | } |
| 388 | FALLTHROUGH_INTENDED; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 389 | case INVOKE_VIRTUAL_QUICK: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 390 | if (file != nullptr) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 391 | os << opcode << " {"; |
| 392 | uint32_t method_idx = VRegB_35c(); |
| 393 | for (size_t i = 0; i < VRegA_35c(); ++i) { |
| 394 | if (i != 0) { |
| 395 | os << ", "; |
| 396 | } |
| 397 | os << "v" << arg[i]; |
| 398 | } |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 399 | os << "}, // vtable@" << method_idx; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 400 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 401 | } |
| 402 | FALLTHROUGH_INTENDED; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 403 | default: |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 404 | os << opcode << " {v" << arg[0] << ", v" << arg[1] << ", v" << arg[2] |
| 405 | << ", v" << arg[3] << ", v" << arg[4] << "}, thing@" << VRegB_35c(); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 406 | break; |
| 407 | } |
| 408 | break; |
| 409 | } |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 410 | case k3rc: { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 411 | switch (Opcode()) { |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 412 | case INVOKE_VIRTUAL_RANGE: |
| 413 | case INVOKE_SUPER_RANGE: |
| 414 | case INVOKE_DIRECT_RANGE: |
| 415 | case INVOKE_STATIC_RANGE: |
| 416 | case INVOKE_INTERFACE_RANGE: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 417 | if (file != nullptr) { |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 418 | uint32_t method_idx = VRegB_3rc(); |
| 419 | os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1)) |
| 420 | << PrettyMethod(method_idx, *file) << " // method@" << method_idx; |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 421 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 422 | } |
| 423 | FALLTHROUGH_INTENDED; |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 424 | case INVOKE_VIRTUAL_RANGE_QUICK: |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 425 | if (file != nullptr) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 426 | uint32_t method_idx = VRegB_3rc(); |
| 427 | os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1)) |
| 428 | << "// vtable@" << method_idx; |
| 429 | break; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 430 | } |
| 431 | FALLTHROUGH_INTENDED; |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 432 | default: |
Sebastien Hertz | 75b2a4a | 2013-05-21 09:25:10 +0200 | [diff] [blame] | 433 | os << StringPrintf("%s, {v%d .. v%d}, thing@%d", opcode, VRegC_3rc(), |
| 434 | (VRegC_3rc() + VRegA_3rc() - 1), VRegB_3rc()); |
Ian Rogers | 4c5dd5a | 2012-09-07 11:27:28 -0700 | [diff] [blame] | 435 | break; |
| 436 | } |
| 437 | break; |
| 438 | } |
Ian Rogers | b574c18 | 2014-01-23 19:51:19 -0800 | [diff] [blame] | 439 | case k51l: os << StringPrintf("%s v%d, #%+" PRId64, opcode, VRegA_51l(), VRegB_51l()); break; |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 440 | default: os << " unknown format (" << DumpHex(5) << ")"; break; |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 441 | } |
Ian Rogers | 2c8a857 | 2011-10-24 17:11:36 -0700 | [diff] [blame] | 442 | return os.str(); |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Ian Rogers | a75a013 | 2012-09-28 11:41:42 -0700 | [diff] [blame] | 445 | std::ostream& operator<<(std::ostream& os, const Instruction::Code& code) { |
| 446 | return os << Instruction::Name(code); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 447 | } |
| 448 | |
Carl Shapiro | 12eb78e | 2011-06-24 14:51:06 -0700 | [diff] [blame] | 449 | } // namespace art |