blob: d04087aca3d24e1c5f1259ef6acceedc382e6be3 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Shapiro12eb78e2011-06-24 14:51:06 -070016
Sebastien Hertz807a2562013-04-15 09:33:39 +020017#include "dex_instruction-inl.h"
Carl Shapiro12eb78e2011-06-24 14:51:06 -070018
Ian Rogersb574c182014-01-23 19:51:19 -080019#include <inttypes.h>
20
21#include <iomanip>
Ian Rogersc7dd2952014-10-21 23:31:19 -070022#include <sstream>
Ian Rogersb574c182014-01-23 19:51:19 -080023
Ian Rogers576ca0c2014-06-06 15:58:22 -070024#include "base/stringprintf.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070025#include "dex_file-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026#include "utils.h"
Ian Rogersd81871c2011-10-03 13:57:23 -070027
Carl Shapiro12eb78e2011-06-24 14:51:06 -070028namespace art {
29
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070030const char* const Instruction::kInstructionNames[] = {
Narayan Kamathbd48b342016-08-01 17:32:37 +010031#define INSTRUCTION_NAME(o, c, pname, f, i, a, v) pname,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070032#include "dex_instruction_list.h"
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070033 DEX_INSTRUCTION_LIST(INSTRUCTION_NAME)
34#undef DEX_INSTRUCTION_LIST
35#undef INSTRUCTION_NAME
36};
37
Elliott Hughesadb8c672012-03-06 16:49:32 -080038Instruction::Format const Instruction::kInstructionFormats[] = {
Narayan Kamathbd48b342016-08-01 17:32:37 +010039#define INSTRUCTION_FORMAT(o, c, p, format, i, a, v) format,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070040#include "dex_instruction_list.h"
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070041 DEX_INSTRUCTION_LIST(INSTRUCTION_FORMAT)
42#undef DEX_INSTRUCTION_LIST
43#undef INSTRUCTION_FORMAT
44};
45
Aart Bikb1f37532015-06-29 11:03:55 -070046Instruction::IndexType const Instruction::kInstructionIndexTypes[] = {
Narayan Kamathbd48b342016-08-01 17:32:37 +010047#define INSTRUCTION_INDEX_TYPE(o, c, p, f, index, a, v) index,
Aart Bikb1f37532015-06-29 11:03:55 -070048#include "dex_instruction_list.h"
49 DEX_INSTRUCTION_LIST(INSTRUCTION_INDEX_TYPE)
50#undef DEX_INSTRUCTION_LIST
51#undef INSTRUCTION_FLAGS
52};
53
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070054int const Instruction::kInstructionFlags[] = {
Narayan Kamathbd48b342016-08-01 17:32:37 +010055#define INSTRUCTION_FLAGS(o, c, p, f, i, flags, v) flags,
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070056#include "dex_instruction_list.h"
Carl Shapiroe4c1ce42011-07-09 02:31:57 -070057 DEX_INSTRUCTION_LIST(INSTRUCTION_FLAGS)
58#undef DEX_INSTRUCTION_LIST
59#undef INSTRUCTION_FLAGS
60};
61
jeffhaoba5ebb92011-08-25 17:24:37 -070062int const Instruction::kInstructionVerifyFlags[] = {
Narayan Kamathbd48b342016-08-01 17:32:37 +010063#define INSTRUCTION_VERIFY_FLAGS(o, c, p, f, i, a, vflags) vflags,
jeffhaoba5ebb92011-08-25 17:24:37 -070064#include "dex_instruction_list.h"
65 DEX_INSTRUCTION_LIST(INSTRUCTION_VERIFY_FLAGS)
66#undef DEX_INSTRUCTION_LIST
67#undef INSTRUCTION_VERIFY_FLAGS
68};
69
Ian Rogersa75a0132012-09-28 11:41:42 -070070int const Instruction::kInstructionSizeInCodeUnits[] = {
Narayan Kamathbd48b342016-08-01 17:32:37 +010071#define INSTRUCTION_SIZE(opcode, c, p, format, i, a, v) \
Chih-Hung Hsiehfba39972016-05-11 11:26:48 -070072 (((opcode) == NOP) ? -1 : \
73 (((format) >= k10x) && ((format) <= k10t)) ? 1 : \
74 (((format) >= k20t) && ((format) <= k25x)) ? 2 : \
75 (((format) >= k32x) && ((format) <= k3rc)) ? 3 : \
76 ((format) == k51l) ? 5 : -1),
Ian Rogersa75a0132012-09-28 11:41:42 -070077#include "dex_instruction_list.h"
78 DEX_INSTRUCTION_LIST(INSTRUCTION_SIZE)
79#undef DEX_INSTRUCTION_LIST
80#undef INSTRUCTION_SIZE
81};
82
Dragos Sbirlea39f99272013-06-25 13:17:36 -070083int32_t Instruction::GetTargetOffset() const {
84 switch (FormatOf(Opcode())) {
85 // Cases for conditional branches follow.
86 case k22t: return VRegC_22t();
87 case k21t: return VRegB_21t();
88 // Cases for unconditional branches follow.
89 case k10t: return VRegA_10t();
90 case k20t: return VRegA_20t();
91 case k30t: return VRegA_30t();
92 default: LOG(FATAL) << "Tried to access the branch offset of an instruction " << Name() <<
93 " which does not have a target operand.";
94 }
95 return 0;
96}
97
98bool Instruction::CanFlowThrough() const {
99 const uint16_t* insns = reinterpret_cast<const uint16_t*>(this);
100 uint16_t insn = *insns;
101 Code opcode = static_cast<Code>(insn & 0xFF);
102 return FlagsOf(opcode) & Instruction::kContinue;
103}
104
Ian Rogersa75a0132012-09-28 11:41:42 -0700105size_t Instruction::SizeInCodeUnitsComplexOpcode() const {
Carl Shapiro12eb78e2011-06-24 14:51:06 -0700106 const uint16_t* insns = reinterpret_cast<const uint16_t*>(this);
Ian Rogersa75a0132012-09-28 11:41:42 -0700107 // Handle special NOP encoded variable length sequences.
108 switch (*insns) {
109 case kPackedSwitchSignature:
110 return (4 + insns[1] * 2);
111 case kSparseSwitchSignature:
112 return (2 + insns[1] * 4);
113 case kArrayDataSignature: {
114 uint16_t element_size = insns[1];
115 uint32_t length = insns[2] | (((uint32_t)insns[3]) << 16);
116 // The plus 1 is to round up for odd size and width.
117 return (4 + (element_size * length + 1) / 2);
Carl Shapiroe4c1ce42011-07-09 02:31:57 -0700118 }
Ian Rogersa75a0132012-09-28 11:41:42 -0700119 default:
120 if ((*insns & 0xFF) == 0) {
121 return 1; // NOP.
122 } else {
Ian Rogersfc787ec2014-10-09 21:56:44 -0700123 LOG(FATAL) << "Unreachable: " << DumpString(nullptr);
Ian Rogers2c4257b2014-10-24 14:20:06 -0700124 UNREACHABLE();
Ian Rogersa75a0132012-09-28 11:41:42 -0700125 }
Carl Shapiroe4c1ce42011-07-09 02:31:57 -0700126 }
Ian Rogersd81871c2011-10-03 13:57:23 -0700127}
128
Ian Rogers2c8a8572011-10-24 17:11:36 -0700129std::string Instruction::DumpHex(size_t code_units) const {
Ian Rogersd81871c2011-10-03 13:57:23 -0700130 size_t inst_length = SizeInCodeUnits();
131 if (inst_length > code_units) {
132 inst_length = code_units;
133 }
Ian Rogers2c8a8572011-10-24 17:11:36 -0700134 std::ostringstream os;
Ian Rogersd81871c2011-10-03 13:57:23 -0700135 const uint16_t* insn = reinterpret_cast<const uint16_t*>(this);
136 for (size_t i = 0; i < inst_length; i++) {
Ian Rogers2c8a8572011-10-24 17:11:36 -0700137 os << StringPrintf("0x%04x", insn[i]) << " ";
Ian Rogersd81871c2011-10-03 13:57:23 -0700138 }
139 for (size_t i = inst_length; i < code_units; i++) {
140 os << " ";
141 }
Ian Rogers2c8a8572011-10-24 17:11:36 -0700142 return os.str();
Ian Rogersd81871c2011-10-03 13:57:23 -0700143}
144
Anestis Bechtsoudis32f500d2015-02-22 22:32:57 -0800145std::string Instruction::DumpHexLE(size_t instr_code_units) const {
146 size_t inst_length = SizeInCodeUnits();
147 if (inst_length > instr_code_units) {
148 inst_length = instr_code_units;
149 }
150 std::ostringstream os;
151 const uint16_t* insn = reinterpret_cast<const uint16_t*>(this);
152 for (size_t i = 0; i < inst_length; i++) {
Andreas Gampe4f0be4d2015-02-27 22:16:14 -0800153 os << StringPrintf("%02x%02x", static_cast<uint8_t>(insn[i] & 0x00FF),
154 static_cast<uint8_t>((insn[i] & 0xFF00) >> 8)) << " ";
Anestis Bechtsoudis32f500d2015-02-22 22:32:57 -0800155 }
156 for (size_t i = inst_length; i < instr_code_units; i++) {
Andreas Gampe4f0be4d2015-02-27 22:16:14 -0800157 os << " ";
Anestis Bechtsoudis32f500d2015-02-22 22:32:57 -0800158 }
159 return os.str();
160}
161
Ian Rogers2c8a8572011-10-24 17:11:36 -0700162std::string Instruction::DumpString(const DexFile* file) const {
Ian Rogers2c8a8572011-10-24 17:11:36 -0700163 std::ostringstream os;
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200164 const char* opcode = kInstructionNames[Opcode()];
Elliott Hughesadb8c672012-03-06 16:49:32 -0800165 switch (FormatOf(Opcode())) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800166 case k10x: os << opcode; break;
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200167 case k12x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_12x(), VRegB_12x()); break;
168 case k11n: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_11n(), VRegB_11n()); break;
169 case k11x: os << StringPrintf("%s v%d", opcode, VRegA_11x()); break;
170 case k10t: os << StringPrintf("%s %+d", opcode, VRegA_10t()); break;
171 case k20t: os << StringPrintf("%s %+d", opcode, VRegA_20t()); break;
172 case k22x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_22x(), VRegB_22x()); break;
173 case k21t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_21t(), VRegB_21t()); break;
174 case k21s: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_21s(), VRegB_21s()); break;
Elliott Hughes1b3d6ca2012-04-25 13:00:14 -0700175 case k21h: {
176 // op vAA, #+BBBB0000[00000000]
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200177 if (Opcode() == CONST_HIGH16) {
178 uint32_t value = VRegB_21h() << 16;
179 os << StringPrintf("%s v%d, #int %+d // 0x%x", opcode, VRegA_21h(), value, value);
Elliott Hughes1b3d6ca2012-04-25 13:00:14 -0700180 } else {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200181 uint64_t value = static_cast<uint64_t>(VRegB_21h()) << 48;
Ian Rogersb574c182014-01-23 19:51:19 -0800182 os << StringPrintf("%s v%d, #long %+" PRId64 " // 0x%" PRIx64, opcode, VRegA_21h(),
183 value, value);
Elliott Hughes1b3d6ca2012-04-25 13:00:14 -0700184 }
185 }
186 break;
Ian Rogers90334e52012-06-06 20:22:20 -0700187 case k21c: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200188 switch (Opcode()) {
Ian Rogers90334e52012-06-06 20:22:20 -0700189 case CONST_STRING:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700190 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200191 uint32_t string_idx = VRegB_21c();
Serdjuk, Nikolay Y67c5ddd2015-12-07 14:45:44 +0600192 if (string_idx < file->NumStringIds()) {
193 os << StringPrintf("const-string v%d, %s // string@%d",
194 VRegA_21c(),
195 PrintableString(file->StringDataByIdx(string_idx)).c_str(),
196 string_idx);
197 } else {
198 os << StringPrintf("const-string v%d, <<invalid-string-idx-%d>> // string@%d",
199 VRegA_21c(),
200 string_idx,
201 string_idx);
202 }
Ian Rogers90334e52012-06-06 20:22:20 -0700203 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700204 }
205 FALLTHROUGH_INTENDED;
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700206 case CHECK_CAST:
207 case CONST_CLASS:
Ian Rogers90334e52012-06-06 20:22:20 -0700208 case NEW_INSTANCE:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700209 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200210 uint32_t type_idx = VRegB_21c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700211 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyType(type_idx, *file)
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200212 << " // type@" << type_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700213 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700214 }
215 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700216 case SGET:
217 case SGET_WIDE:
218 case SGET_OBJECT:
219 case SGET_BOOLEAN:
220 case SGET_BYTE:
221 case SGET_CHAR:
222 case SGET_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700223 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200224 uint32_t field_idx = VRegB_21c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700225 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyField(field_idx, *file, true)
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200226 << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700227 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700228 }
229 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700230 case SPUT:
231 case SPUT_WIDE:
232 case SPUT_OBJECT:
233 case SPUT_BOOLEAN:
234 case SPUT_BYTE:
235 case SPUT_CHAR:
236 case SPUT_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700237 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200238 uint32_t field_idx = VRegB_21c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700239 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyField(field_idx, *file, true)
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200240 << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700241 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700242 }
243 FALLTHROUGH_INTENDED;
Igor Murashkin158f35c2015-06-10 15:55:30 -0700244 case CREATE_LAMBDA:
245 if (file != nullptr) {
246 uint32_t method_idx = VRegB_21c();
247 os << opcode << " v" << static_cast<int>(VRegA_21c()) << ", " << PrettyMethod(method_idx, *file, true)
248 << " // method@" << method_idx;
249 break;
250 }
251 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700252 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200253 os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_21c(), VRegB_21c());
Ian Rogers90334e52012-06-06 20:22:20 -0700254 break;
255 }
256 break;
257 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200258 case k23x: os << StringPrintf("%s v%d, v%d, v%d", opcode, VRegA_23x(), VRegB_23x(), VRegC_23x()); break;
259 case k22b: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22b(), VRegB_22b(), VRegC_22b()); break;
260 case k22t: os << StringPrintf("%s v%d, v%d, %+d", opcode, VRegA_22t(), VRegB_22t(), VRegC_22t()); break;
261 case k22s: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22s(), VRegB_22s(), VRegC_22s()); break;
Ian Rogers90334e52012-06-06 20:22:20 -0700262 case k22c: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200263 switch (Opcode()) {
Ian Rogers90334e52012-06-06 20:22:20 -0700264 case IGET:
265 case IGET_WIDE:
266 case IGET_OBJECT:
267 case IGET_BOOLEAN:
268 case IGET_BYTE:
269 case IGET_CHAR:
270 case IGET_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700271 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200272 uint32_t field_idx = VRegC_22c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700273 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200274 << PrettyField(field_idx, *file, true) << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700275 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700276 }
277 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200278 case IGET_QUICK:
279 case IGET_OBJECT_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700280 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200281 uint32_t field_idx = VRegC_22c();
282 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
283 << "// offset@" << field_idx;
284 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700285 }
286 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700287 case IPUT:
288 case IPUT_WIDE:
289 case IPUT_OBJECT:
290 case IPUT_BOOLEAN:
291 case IPUT_BYTE:
292 case IPUT_CHAR:
293 case IPUT_SHORT:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700294 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200295 uint32_t field_idx = VRegC_22c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700296 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200297 << PrettyField(field_idx, *file, true) << " // field@" << field_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700298 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700299 }
300 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200301 case IPUT_QUICK:
302 case IPUT_OBJECT_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700303 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200304 uint32_t field_idx = VRegC_22c();
305 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
306 << "// offset@" << field_idx;
307 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700308 }
309 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700310 case INSTANCE_OF:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700311 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200312 uint32_t type_idx = VRegC_22c();
Dragos Sbirlead4e868a2013-05-23 09:44:17 -0700313 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200314 << PrettyType(type_idx, *file) << " // type@" << type_idx;
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700315 break;
316 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700317 FALLTHROUGH_INTENDED;
Mathieu Chartier18c24b62012-09-10 08:54:25 -0700318 case NEW_ARRAY:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700319 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200320 uint32_t type_idx = VRegC_22c();
Dragos Sbirleab43cef32013-05-23 11:59:20 -0700321 os << opcode << " v" << static_cast<int>(VRegA_22c()) << ", v" << static_cast<int>(VRegB_22c()) << ", "
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200322 << PrettyType(type_idx, *file) << " // type@" << type_idx;
Ian Rogers90334e52012-06-06 20:22:20 -0700323 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700324 }
325 FALLTHROUGH_INTENDED;
Ian Rogers90334e52012-06-06 20:22:20 -0700326 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200327 os << StringPrintf("%s v%d, v%d, thing@%d", opcode, VRegA_22c(), VRegB_22c(), VRegC_22c());
Ian Rogers90334e52012-06-06 20:22:20 -0700328 break;
329 }
330 break;
331 }
Igor Murashkin158f35c2015-06-10 15:55:30 -0700332 case k25x: {
333 if (Opcode() == INVOKE_LAMBDA) {
Igor Murashkin6918bf12015-09-27 19:19:06 -0700334 uint32_t arg[kMaxVarArgRegs25x];
Igor Murashkin158f35c2015-06-10 15:55:30 -0700335 GetAllArgs25x(arg);
336 const size_t num_extra_var_args = VRegB_25x();
Igor Murashkin6918bf12015-09-27 19:19:06 -0700337 DCHECK_LE(num_extra_var_args + 2, arraysize(arg));
Igor Murashkin158f35c2015-06-10 15:55:30 -0700338
339 // invoke-lambda vC, {vD, vE, vF, vG}
340 os << opcode << " v" << arg[0] << ", {";
341 for (size_t i = 0; i < num_extra_var_args; ++i) {
342 if (i != 0) {
343 os << ", ";
344 }
Igor Murashkin30c475a2015-10-06 13:59:43 -0700345 os << "v" << arg[i + 2]; // Don't print the pair of vC registers. Pair is implicit.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700346 }
347 os << "}";
348 break;
349 }
350 FALLTHROUGH_INTENDED;
351 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200352 case k32x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_32x(), VRegB_32x()); break;
353 case k30t: os << StringPrintf("%s %+d", opcode, VRegA_30t()); break;
354 case k31t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_31t(), VRegB_31t()); break;
355 case k31i: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_31i(), VRegB_31i()); break;
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700356 case k31c:
357 if (Opcode() == CONST_STRING_JUMBO) {
358 uint32_t string_idx = VRegB_31c();
Ian Rogersfc787ec2014-10-09 21:56:44 -0700359 if (file != nullptr) {
Serdjuk, Nikolay Y67c5ddd2015-12-07 14:45:44 +0600360 if (string_idx < file->NumStringIds()) {
361 os << StringPrintf("%s v%d, %s // string@%d",
362 opcode,
363 VRegA_31c(),
364 PrintableString(file->StringDataByIdx(string_idx)).c_str(),
365 string_idx);
366 } else {
367 os << StringPrintf("%s v%d, <<invalid-string-idx-%d>> // string@%d",
368 opcode,
369 VRegA_31c(),
370 string_idx,
371 string_idx);
372 }
Ian Rogers7dfb28c2013-08-22 08:18:36 -0700373 } else {
374 os << StringPrintf("%s v%d, string@%d", opcode, VRegA_31c(), string_idx);
375 }
376 } else {
377 os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_31c(), VRegB_31c()); break;
378 }
379 break;
Ian Rogersd81871c2011-10-03 13:57:23 -0700380 case k35c: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200381 uint32_t arg[5];
Ian Rogers29a26482014-05-02 15:27:29 -0700382 GetVarArgs(arg);
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200383 switch (Opcode()) {
Andreas Gampe7aca91d2014-03-31 18:10:53 -0700384 case FILLED_NEW_ARRAY:
385 {
386 const int32_t a = VRegA_35c();
387 os << opcode << " {";
388 for (int i = 0; i < a; ++i) {
389 if (i > 0) {
390 os << ", ";
391 }
392 os << "v" << arg[i];
393 }
394 os << "}, type@" << VRegB_35c();
395 }
396 break;
397
Ian Rogersd81871c2011-10-03 13:57:23 -0700398 case INVOKE_VIRTUAL:
399 case INVOKE_SUPER:
400 case INVOKE_DIRECT:
401 case INVOKE_STATIC:
402 case INVOKE_INTERFACE:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700403 if (file != nullptr) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800404 os << opcode << " {";
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200405 uint32_t method_idx = VRegB_35c();
406 for (size_t i = 0; i < VRegA_35c(); ++i) {
Elliott Hughese3c845c2012-02-28 17:23:01 -0800407 if (i != 0) {
408 os << ", ";
409 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200410 os << "v" << arg[i];
Elliott Hughese3c845c2012-02-28 17:23:01 -0800411 }
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200412 os << "}, " << PrettyMethod(method_idx, *file) << " // method@" << method_idx;
Ian Rogersd81871c2011-10-03 13:57:23 -0700413 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700414 }
415 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200416 case INVOKE_VIRTUAL_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700417 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200418 os << opcode << " {";
419 uint32_t method_idx = VRegB_35c();
420 for (size_t i = 0; i < VRegA_35c(); ++i) {
421 if (i != 0) {
422 os << ", ";
423 }
424 os << "v" << arg[i];
425 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700426 os << "}, // vtable@" << method_idx;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200427 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700428 }
429 FALLTHROUGH_INTENDED;
Ian Rogersd81871c2011-10-03 13:57:23 -0700430 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200431 os << opcode << " {v" << arg[0] << ", v" << arg[1] << ", v" << arg[2]
432 << ", v" << arg[3] << ", v" << arg[4] << "}, thing@" << VRegB_35c();
Ian Rogersd81871c2011-10-03 13:57:23 -0700433 break;
434 }
435 break;
436 }
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700437 case k3rc: {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200438 switch (Opcode()) {
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700439 case INVOKE_VIRTUAL_RANGE:
440 case INVOKE_SUPER_RANGE:
441 case INVOKE_DIRECT_RANGE:
442 case INVOKE_STATIC_RANGE:
443 case INVOKE_INTERFACE_RANGE:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700444 if (file != nullptr) {
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200445 uint32_t method_idx = VRegB_3rc();
446 os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1))
447 << PrettyMethod(method_idx, *file) << " // method@" << method_idx;
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700448 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700449 }
450 FALLTHROUGH_INTENDED;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200451 case INVOKE_VIRTUAL_RANGE_QUICK:
Ian Rogersfc787ec2014-10-09 21:56:44 -0700452 if (file != nullptr) {
Sebastien Hertz2d6ba512013-05-17 11:31:37 +0200453 uint32_t method_idx = VRegB_3rc();
454 os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1))
455 << "// vtable@" << method_idx;
456 break;
Ian Rogersfc787ec2014-10-09 21:56:44 -0700457 }
458 FALLTHROUGH_INTENDED;
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700459 default:
Sebastien Hertz75b2a4a2013-05-21 09:25:10 +0200460 os << StringPrintf("%s, {v%d .. v%d}, thing@%d", opcode, VRegC_3rc(),
461 (VRegC_3rc() + VRegA_3rc() - 1), VRegB_3rc());
Ian Rogers4c5dd5a2012-09-07 11:27:28 -0700462 break;
463 }
464 break;
465 }
Ian Rogersb574c182014-01-23 19:51:19 -0800466 case k51l: os << StringPrintf("%s v%d, #%+" PRId64, opcode, VRegA_51l(), VRegB_51l()); break;
Ian Rogers2c8a8572011-10-24 17:11:36 -0700467 default: os << " unknown format (" << DumpHex(5) << ")"; break;
Ian Rogersd81871c2011-10-03 13:57:23 -0700468 }
Ian Rogers2c8a8572011-10-24 17:11:36 -0700469 return os.str();
Carl Shapiro12eb78e2011-06-24 14:51:06 -0700470}
471
Ian Rogersa75a0132012-09-28 11:41:42 -0700472std::ostream& operator<<(std::ostream& os, const Instruction::Code& code) {
473 return os << Instruction::Name(code);
Elliott Hughesadb8c672012-03-06 16:49:32 -0800474}
475
Carl Shapiro12eb78e2011-06-24 14:51:06 -0700476} // namespace art