Remove use of DecodedInstruction at runtime.
This CL removes the use of DecodedInstruction while executing code. This is a
first step in removing its global use in Art.
Change-Id: Ic7264e0d614ffab99931fd50347394a68152a10c
diff --git a/src/common_throws.cc b/src/common_throws.cc
index 0bb9da2..dc3627a 100644
--- a/src/common_throws.cc
+++ b/src/common_throws.cc
@@ -19,7 +19,7 @@
#include "base/logging.h"
#include "class_linker-inl.h"
#include "dex_file-inl.h"
-#include "dex_instruction.h"
+#include "dex_instruction-inl.h"
#include "invoke_type.h"
#include "mirror/abstract_method-inl.h"
#include "mirror/class-inl.h"
@@ -298,19 +298,24 @@
uint32_t throw_dex_pc = throw_location.GetDexPc();
CHECK_LT(throw_dex_pc, code->insns_size_in_code_units_);
const Instruction* instr = Instruction::At(&code->insns_[throw_dex_pc]);
- DecodedInstruction dec_insn(instr);
switch (instr->Opcode()) {
case Instruction::INVOKE_DIRECT:
+ ThrowNullPointerExceptionForMethodAccess(throw_location, instr->VRegB_35c(), kDirect);
+ break;
case Instruction::INVOKE_DIRECT_RANGE:
- ThrowNullPointerExceptionForMethodAccess(throw_location, dec_insn.vB, kDirect);
+ ThrowNullPointerExceptionForMethodAccess(throw_location, instr->VRegB_3rc(), kDirect);
break;
case Instruction::INVOKE_VIRTUAL:
+ ThrowNullPointerExceptionForMethodAccess(throw_location, instr->VRegB_35c(), kVirtual);
+ break;
case Instruction::INVOKE_VIRTUAL_RANGE:
- ThrowNullPointerExceptionForMethodAccess(throw_location, dec_insn.vB, kVirtual);
+ ThrowNullPointerExceptionForMethodAccess(throw_location, instr->VRegB_3rc(), kVirtual);
break;
case Instruction::INVOKE_INTERFACE:
+ ThrowNullPointerExceptionForMethodAccess(throw_location, instr->VRegB_35c(), kInterface);
+ break;
case Instruction::INVOKE_INTERFACE_RANGE:
- ThrowNullPointerExceptionForMethodAccess(throw_location, dec_insn.vB, kInterface);
+ ThrowNullPointerExceptionForMethodAccess(throw_location, instr->VRegB_3rc(), kInterface);
break;
case Instruction::IGET:
case Instruction::IGET_WIDE:
@@ -320,7 +325,7 @@
case Instruction::IGET_CHAR:
case Instruction::IGET_SHORT: {
mirror::Field* field =
- Runtime::Current()->GetClassLinker()->ResolveField(dec_insn.vC,
+ Runtime::Current()->GetClassLinker()->ResolveField(instr->VRegC_22c(),
throw_location.GetMethod(), false);
ThrowNullPointerExceptionForFieldAccess(throw_location, field, true /* read */);
break;
@@ -333,7 +338,7 @@
case Instruction::IPUT_CHAR:
case Instruction::IPUT_SHORT: {
mirror::Field* field =
- Runtime::Current()->GetClassLinker()->ResolveField(dec_insn.vC,
+ Runtime::Current()->GetClassLinker()->ResolveField(instr->VRegC_22c(),
throw_location.GetMethod(), false);
ThrowNullPointerExceptionForFieldAccess(throw_location, field, false /* write */);
break;
diff --git a/src/dex_instruction.cc b/src/dex_instruction.cc
index 414e78f..1b7d3bb 100644
--- a/src/dex_instruction.cc
+++ b/src/dex_instruction.cc
@@ -262,44 +262,45 @@
}
std::string Instruction::DumpString(const DexFile* file) const {
- DecodedInstruction insn(this);
std::ostringstream os;
- const char* opcode = kInstructionNames[insn.opcode];
+ const char* opcode = kInstructionNames[Opcode()];
switch (FormatOf(Opcode())) {
case k10x: os << opcode; break;
- case k12x: os << StringPrintf("%s v%d, v%d", opcode, insn.vA, insn.vB); break;
- case k11n: os << StringPrintf("%s v%d, #%+d", opcode, insn.vA, insn.vB); break;
- case k11x: os << StringPrintf("%s v%d", opcode, insn.vA); break;
- case k10t: os << StringPrintf("%s %+d", opcode, insn.vA); break;
- case k20t: os << StringPrintf("%s %+d", opcode, insn.vA); break;
- case k22x: os << StringPrintf("%s v%d, v%d", opcode, insn.vA, insn.vB); break;
- case k21t: os << StringPrintf("%s v%d, %+d", opcode, insn.vA, insn.vB); break;
- case k21s: os << StringPrintf("%s v%d, #%+d", opcode, insn.vA, insn.vB); break;
+ case k12x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_12x(), VRegB_12x()); break;
+ case k11n: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_11n(), VRegB_11n()); break;
+ case k11x: os << StringPrintf("%s v%d", opcode, VRegA_11x()); break;
+ case k10t: os << StringPrintf("%s %+d", opcode, VRegA_10t()); break;
+ case k20t: os << StringPrintf("%s %+d", opcode, VRegA_20t()); break;
+ case k22x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_22x(), VRegB_22x()); break;
+ case k21t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_21t(), VRegB_21t()); break;
+ case k21s: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_21s(), VRegB_21s()); break;
case k21h: {
// op vAA, #+BBBB0000[00000000]
- if (insn.opcode == CONST_HIGH16) {
- uint32_t value = insn.vB << 16;
- os << StringPrintf("%s v%d, #int %+d // 0x%x", opcode, insn.vA, value, value);
+ if (Opcode() == CONST_HIGH16) {
+ uint32_t value = VRegB_21h() << 16;
+ os << StringPrintf("%s v%d, #int %+d // 0x%x", opcode, VRegA_21h(), value, value);
} else {
- uint64_t value = static_cast<uint64_t>(insn.vB) << 48;
- os << StringPrintf("%s v%d, #long %+lld // 0x%llx", opcode, insn.vA, value, value);
+ uint64_t value = static_cast<uint64_t>(VRegB_21h()) << 48;
+ os << StringPrintf("%s v%d, #long %+lld // 0x%llx", opcode, VRegA_21h(), value, value);
}
}
break;
case k21c: {
- switch (insn.opcode) {
+ switch (Opcode()) {
case CONST_STRING:
if (file != NULL) {
- os << StringPrintf("const-string v%d, %s // string@%d", insn.vA,
- PrintableString(file->StringDataByIdx(insn.vB)).c_str(), insn.vB);
+ uint32_t string_idx = VRegB_21c();
+ os << StringPrintf("const-string v%d, %s // string@%d", VRegA_21c(),
+ PrintableString(file->StringDataByIdx(string_idx)).c_str(), string_idx);
break;
} // else fall-through
case CHECK_CAST:
case CONST_CLASS:
case NEW_INSTANCE:
if (file != NULL) {
- os << opcode << " v" << insn.vA << ", " << PrettyType(insn.vB, *file)
- << " // type@" << insn.vB;
+ uint32_t type_idx = VRegB_21c();
+ os << opcode << " v" << VRegA_21c() << ", " << PrettyType(type_idx, *file)
+ << " // type@" << type_idx;
break;
} // else fall-through
case SGET:
@@ -310,8 +311,9 @@
case SGET_CHAR:
case SGET_SHORT:
if (file != NULL) {
- os << opcode << " v" << insn.vA << ", " << PrettyField(insn.vB, *file, true)
- << " // field@" << insn.vB;
+ uint32_t field_idx = VRegB_21c();
+ os << opcode << " v" << VRegA_21c() << ", " << PrettyField(field_idx, *file, true)
+ << " // field@" << field_idx;
break;
} // else fall-through
case SPUT:
@@ -322,22 +324,23 @@
case SPUT_CHAR:
case SPUT_SHORT:
if (file != NULL) {
- os << opcode << " v" << insn.vA << ", " << PrettyField(insn.vB, *file, true)
- << " // field@" << insn.vB;
+ uint32_t field_idx = VRegB_21c();
+ os << opcode << " v" << VRegA_21c() << ", " << PrettyField(field_idx, *file, true)
+ << " // field@" << field_idx;
break;
} // else fall-through
default:
- os << StringPrintf("%s v%d, thing@%d", opcode, insn.vA, insn.vB);
+ os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_21c(), VRegB_21c());
break;
}
break;
}
- case k23x: os << StringPrintf("%s v%d, v%d, v%d", opcode, insn.vA, insn.vB, insn.vC); break;
- case k22b: os << StringPrintf("%s v%d, v%d, #%+d", opcode, insn.vA, insn.vB, insn.vC); break;
- case k22t: os << StringPrintf("%s v%d, v%d, %+d", opcode, insn.vA, insn.vB, insn.vC); break;
- case k22s: os << StringPrintf("%s v%d, v%d, #%+d", opcode, insn.vA, insn.vB, insn.vC); break;
+ case k23x: os << StringPrintf("%s v%d, v%d, v%d", opcode, VRegA_23x(), VRegB_23x(), VRegC_23x()); break;
+ case k22b: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22b(), VRegB_22b(), VRegC_22b()); break;
+ case k22t: os << StringPrintf("%s v%d, v%d, %+d", opcode, VRegA_22t(), VRegB_22t(), VRegC_22t()); break;
+ case k22s: os << StringPrintf("%s v%d, v%d, #%+d", opcode, VRegA_22s(), VRegB_22s(), VRegC_22s()); break;
case k22c: {
- switch (insn.opcode) {
+ switch (Opcode()) {
case IGET:
case IGET_WIDE:
case IGET_OBJECT:
@@ -346,8 +349,9 @@
case IGET_CHAR:
case IGET_SHORT:
if (file != NULL) {
- os << opcode << " v" << insn.vA << ", v" << insn.vB << ", "
- << PrettyField(insn.vC, *file, true) << " // field@" << insn.vC;
+ uint32_t field_idx = VRegC_22c();
+ os << opcode << " v" << VRegA_22c() << ", v" << VRegB_22c() << ", "
+ << PrettyField(field_idx, *file, true) << " // field@" << field_idx;
break;
} // else fall-through
case IPUT:
@@ -358,35 +362,40 @@
case IPUT_CHAR:
case IPUT_SHORT:
if (file != NULL) {
- os << opcode << " v" << insn.vA << ", v" << insn.vB << ", "
- << PrettyField(insn.vC, *file, true) << " // field@" << insn.vC;
+ uint32_t field_idx = VRegC_22c();
+ os << opcode << " v" << VRegA_22c() << ", v" << VRegB_22c() << ", "
+ << PrettyField(field_idx, *file, true) << " // field@" << field_idx;
break;
} // else fall-through
case INSTANCE_OF:
if (file != NULL) {
- os << opcode << " v" << insn.vA << ", v" << insn.vB << ", "
- << PrettyType(insn.vC, *file) << " // type@" << insn.vC;
+ uint32_t type_idx = VRegC_22c();
+ os << opcode << " v" << VRegA_22c() << ", v" << VRegB_22c() << ", "
+ << PrettyType(type_idx, *file) << " // type@" << type_idx;
break;
}
case NEW_ARRAY:
if (file != NULL) {
- os << opcode << " v" << insn.vA << ", v" << insn.vB << ", "
- << PrettyType(insn.vC, *file) << " // type@" << insn.vC;
+ uint32_t type_idx = VRegC_22c();
+ os << opcode << " v" << VRegA_22c() << ", v" << VRegB_22c() << ", "
+ << PrettyType(type_idx, *file) << " // type@" << type_idx;
break;
} // else fall-through
default:
- os << StringPrintf("%s v%d, v%d, thing@%d", opcode, insn.vA, insn.vB, insn.vC);
+ os << StringPrintf("%s v%d, v%d, thing@%d", opcode, VRegA_22c(), VRegB_22c(), VRegC_22c());
break;
}
break;
}
- case k32x: os << StringPrintf("%s v%d, v%d", opcode, insn.vA, insn.vB); break;
- case k30t: os << StringPrintf("%s %+d", opcode, insn.vA); break;
- case k31t: os << StringPrintf("%s v%d, %+d", opcode, insn.vA, insn.vB); break;
- case k31i: os << StringPrintf("%s v%d, #%+d", opcode, insn.vA, insn.vB); break;
- case k31c: os << StringPrintf("%s v%d, thing@%d", opcode, insn.vA, insn.vB); break;
+ case k32x: os << StringPrintf("%s v%d, v%d", opcode, VRegA_32x(), VRegB_32x()); break;
+ case k30t: os << StringPrintf("%s %+d", opcode, VRegA_30t()); break;
+ case k31t: os << StringPrintf("%s v%d, %+d", opcode, VRegA_31t(), VRegB_31t()); break;
+ case k31i: os << StringPrintf("%s v%d, #%+d", opcode, VRegA_31i(), VRegB_31i()); break;
+ case k31c: os << StringPrintf("%s v%d, thing@%d", opcode, VRegA_31c(), VRegB_31c()); break;
case k35c: {
- switch (insn.opcode) {
+ uint32_t arg[5];
+ GetArgs(arg);
+ switch (Opcode()) {
case INVOKE_VIRTUAL:
case INVOKE_SUPER:
case INVOKE_DIRECT:
@@ -394,42 +403,44 @@
case INVOKE_INTERFACE:
if (file != NULL) {
os << opcode << " {";
- for (size_t i = 0; i < insn.vA; ++i) {
+ uint32_t method_idx = VRegB_35c();
+ for (size_t i = 0; i < VRegA_35c(); ++i) {
if (i != 0) {
os << ", ";
}
- os << "v" << insn.arg[i];
+ os << "v" << arg[i];
}
- os << "}, " << PrettyMethod(insn.vB, *file) << " // method@" << insn.vB;
+ os << "}, " << PrettyMethod(method_idx, *file) << " // method@" << method_idx;
break;
} // else fall-through
default:
- os << opcode << " {v" << insn.arg[0] << ", v" << insn.arg[1] << ", v" << insn.arg[2]
- << ", v" << insn.arg[3] << ", v" << insn.arg[4] << "}, thing@" << insn.vB;
+ os << opcode << " {v" << arg[0] << ", v" << arg[1] << ", v" << arg[2]
+ << ", v" << arg[3] << ", v" << arg[4] << "}, thing@" << VRegB_35c();
break;
}
break;
}
case k3rc: {
- switch (insn.opcode) {
+ switch (Opcode()) {
case INVOKE_VIRTUAL_RANGE:
case INVOKE_SUPER_RANGE:
case INVOKE_DIRECT_RANGE:
case INVOKE_STATIC_RANGE:
case INVOKE_INTERFACE_RANGE:
if (file != NULL) {
- os << StringPrintf("%s, {v%d .. v%d}, ", opcode, insn.vC, (insn.vC + insn.vA - 1))
- << PrettyMethod(insn.vB, *file) << " // method@" << insn.vB;
+ uint32_t method_idx = VRegB_3rc();
+ os << StringPrintf("%s, {v%d .. v%d}, ", opcode, VRegC_3rc(), (VRegC_3rc() + VRegA_3rc() - 1))
+ << PrettyMethod(method_idx, *file) << " // method@" << method_idx;
break;
} // else fall-through
default:
- os << StringPrintf("%s, {v%d .. v%d}, thing@%d", opcode, insn.vC, (insn.vC + insn.vA - 1),
- insn.vB);
+ os << StringPrintf("%s, {v%d .. v%d}, thing@%d", opcode, VRegC_3rc(),
+ (VRegC_3rc() + VRegA_3rc() - 1), VRegB_3rc());
break;
}
break;
}
- case k51l: os << StringPrintf("%s v%d, #%+d", opcode, insn.vA, insn.vB); break;
+ case k51l: os << StringPrintf("%s v%d, #%+lld", opcode, VRegA_51l(), VRegB_51l()); break;
default: os << " unknown format (" << DumpHex(5) << ")"; break;
}
return os.str();
diff --git a/src/oat/runtime/support_invoke.cc b/src/oat/runtime/support_invoke.cc
index 369858e..a96555d 100644
--- a/src/oat/runtime/support_invoke.cc
+++ b/src/oat/runtime/support_invoke.cc
@@ -15,7 +15,7 @@
*/
#include "callee_save_frame.h"
-#include "dex_instruction.h"
+#include "dex_instruction-inl.h"
#include "mirror/class-inl.h"
#include "mirror/abstract_method-inl.h"
#include "mirror/object-inl.h"
@@ -110,10 +110,15 @@
CHECK(instr_code == Instruction::INVOKE_INTERFACE ||
instr_code == Instruction::INVOKE_INTERFACE_RANGE)
<< "Unexpected call into interface trampoline: " << instr->DumpString(NULL);
- DecodedInstruction dec_insn(instr);
- uint32_t dex_method_idx = dec_insn.vB;
+ uint32_t dex_method_idx;
+ if (instr_code == Instruction::INVOKE_INTERFACE) {
+ dex_method_idx = instr->VRegB_35c();
+ } else {
+ DCHECK_EQ(instr_code, Instruction::INVOKE_INTERFACE_RANGE);
+ dex_method_idx = instr->VRegB_3rc();
+ }
method = FindMethodFromCode(dex_method_idx, this_object, caller_method, self,
- false, kInterface);
+ false, kInterface);
if (UNLIKELY(method == NULL)) {
CHECK(self->IsExceptionPending());
return 0; // Failure.
diff --git a/src/oat/runtime/support_stubs.cc b/src/oat/runtime/support_stubs.cc
index 161a7b2..df2dda2 100644
--- a/src/oat/runtime/support_stubs.cc
+++ b/src/oat/runtime/support_stubs.cc
@@ -17,7 +17,7 @@
#include "callee_save_frame.h"
#include "class_linker-inl.h"
#include "dex_file-inl.h"
-#include "dex_instruction.h"
+#include "dex_instruction-inl.h"
#include "mirror/class-inl.h"
#include "mirror/abstract_method-inl.h"
#include "mirror/object_array-inl.h"
@@ -40,35 +40,52 @@
ClassLinker* linker = Runtime::Current()->GetClassLinker();
InvokeType invoke_type;
- uint32_t dex_method_idx;
+ bool is_range;
if (called->IsRuntimeMethod()) {
const DexFile::CodeItem* code = MethodHelper(caller).GetCodeItem();
CHECK_LT(dex_pc, code->insns_size_in_code_units_);
const Instruction* instr = Instruction::At(&code->insns_[dex_pc]);
Instruction::Code instr_code = instr->Opcode();
switch (instr_code) {
- case Instruction::INVOKE_DIRECT: // Fall-through.
+ case Instruction::INVOKE_DIRECT:
+ invoke_type = kDirect;
+ is_range = false;
+ break;
case Instruction::INVOKE_DIRECT_RANGE:
invoke_type = kDirect;
+ is_range = true;
break;
- case Instruction::INVOKE_STATIC: // Fall-through.
+ case Instruction::INVOKE_STATIC:
+ invoke_type = kStatic;
+ is_range = false;
+ break;
case Instruction::INVOKE_STATIC_RANGE:
invoke_type = kStatic;
+ is_range = true;
break;
- case Instruction::INVOKE_SUPER: // Fall-through.
+ case Instruction::INVOKE_SUPER:
+ invoke_type = kSuper;
+ is_range = false;
+ break;
case Instruction::INVOKE_SUPER_RANGE:
invoke_type = kSuper;
+ is_range = true;
break;
- case Instruction::INVOKE_VIRTUAL: // Fall-through.
+ case Instruction::INVOKE_VIRTUAL:
+ invoke_type = kVirtual;
+ is_range = false;
+ break;
case Instruction::INVOKE_VIRTUAL_RANGE:
invoke_type = kVirtual;
+ is_range = true;
break;
default:
LOG(FATAL) << "Unexpected call into trampoline: " << instr->DumpString(NULL);
- invoke_type = kDirect; // Avoid used uninitialized warnings.
+ // Avoid used uninitialized warnings.
+ invoke_type = kDirect;
+ is_range = true;
}
- DecodedInstruction dec_insn(instr);
- dex_method_idx = dec_insn.vB;
+ uint32_t dex_method_idx = (is_range) ? instr->VRegB_3rc() : instr->VRegB_35c();
called = linker->ResolveMethod(dex_method_idx, caller, invoke_type);
} else {
CHECK(called->IsStatic()) << PrettyMethod(called);
@@ -210,29 +227,47 @@
CHECK_LT(dex_pc, code->insns_size_in_code_units_);
const Instruction* instr = Instruction::At(&code->insns_[dex_pc]);
Instruction::Code instr_code = instr->Opcode();
+ bool is_range;
switch (instr_code) {
- case Instruction::INVOKE_DIRECT: // Fall-through.
+ case Instruction::INVOKE_DIRECT:
+ invoke_type = kDirect;
+ is_range = false;
+ break;
case Instruction::INVOKE_DIRECT_RANGE:
invoke_type = kDirect;
+ is_range = true;
break;
- case Instruction::INVOKE_STATIC: // Fall-through.
+ case Instruction::INVOKE_STATIC:
+ invoke_type = kStatic;
+ is_range = false;
+ break;
case Instruction::INVOKE_STATIC_RANGE:
invoke_type = kStatic;
+ is_range = true;
break;
- case Instruction::INVOKE_SUPER: // Fall-through.
+ case Instruction::INVOKE_SUPER:
+ invoke_type = kSuper;
+ is_range = false;
+ break;
case Instruction::INVOKE_SUPER_RANGE:
invoke_type = kSuper;
+ is_range = true;
break;
- case Instruction::INVOKE_VIRTUAL: // Fall-through.
+ case Instruction::INVOKE_VIRTUAL:
+ invoke_type = kVirtual;
+ is_range = false;
+ break;
case Instruction::INVOKE_VIRTUAL_RANGE:
invoke_type = kVirtual;
+ is_range = true;
break;
default:
LOG(FATAL) << "Unexpected call into trampoline: " << instr->DumpString(NULL);
- invoke_type = kDirect; // Avoid used uninitialized warnings.
+ // Avoid used uninitialized warnings.
+ invoke_type = kDirect;
+ is_range = false;
}
- DecodedInstruction dec_insn(instr);
- dex_method_idx = dec_insn.vB;
+ dex_method_idx = (is_range) ? instr->VRegB_3rc() : instr->VRegB_35c();
#if !defined(__i386__)
shorty = linker->MethodShorty(dex_method_idx, caller, &shorty_len);
#endif