Make CodeItem fields private
Make code item fields private and use accessors. Added a hand full of
friend classes to reduce the size of the change.
Changed default to be nullable and removed CreateNullable.
CreateNullable was a bad API since it defaulted to the unsafe, may
add a CreateNonNullable if it's important for performance.
Motivation:
Have a different layout for code items in cdex.
Bug: 63756964
Test: test-art-host-gtest
Test: test/testrunner/testrunner.py --host
Test: art/tools/run-jdwp-tests.sh '--mode=host' '--variant=X32' --debug
Change-Id: I42bc7435e20358682075cb6de52713b595f95bf9
diff --git a/runtime/common_throws.cc b/runtime/common_throws.cc
index 575d18e..707885c 100644
--- a/runtime/common_throws.cc
+++ b/runtime/common_throws.cc
@@ -551,43 +551,43 @@
void ThrowNullPointerExceptionFromDexPC(bool check_address, uintptr_t addr) {
uint32_t throw_dex_pc;
ArtMethod* method = Thread::Current()->GetCurrentMethod(&throw_dex_pc);
- const DexFile::CodeItem* code = method->GetCodeItem();
- CHECK_LT(throw_dex_pc, code->insns_size_in_code_units_);
- const Instruction* instr = Instruction::At(&code->insns_[throw_dex_pc]);
- if (check_address && !IsValidImplicitCheck(addr, *instr)) {
+ CodeItemInstructionAccessor accessor(method);
+ CHECK_LT(throw_dex_pc, accessor.InsnsSizeInCodeUnits());
+ const Instruction& instr = accessor.InstructionAt(throw_dex_pc);
+ if (check_address && !IsValidImplicitCheck(addr, instr)) {
const DexFile* dex_file = method->GetDeclaringClass()->GetDexCache()->GetDexFile();
LOG(FATAL) << "Invalid address for an implicit NullPointerException check: "
<< "0x" << std::hex << addr << std::dec
<< ", at "
- << instr->DumpString(dex_file)
+ << instr.DumpString(dex_file)
<< " in "
<< method->PrettyMethod();
}
- switch (instr->Opcode()) {
+ switch (instr.Opcode()) {
case Instruction::INVOKE_DIRECT:
- ThrowNullPointerExceptionForMethodAccess(instr->VRegB_35c(), kDirect);
+ ThrowNullPointerExceptionForMethodAccess(instr.VRegB_35c(), kDirect);
break;
case Instruction::INVOKE_DIRECT_RANGE:
- ThrowNullPointerExceptionForMethodAccess(instr->VRegB_3rc(), kDirect);
+ ThrowNullPointerExceptionForMethodAccess(instr.VRegB_3rc(), kDirect);
break;
case Instruction::INVOKE_VIRTUAL:
- ThrowNullPointerExceptionForMethodAccess(instr->VRegB_35c(), kVirtual);
+ ThrowNullPointerExceptionForMethodAccess(instr.VRegB_35c(), kVirtual);
break;
case Instruction::INVOKE_VIRTUAL_RANGE:
- ThrowNullPointerExceptionForMethodAccess(instr->VRegB_3rc(), kVirtual);
+ ThrowNullPointerExceptionForMethodAccess(instr.VRegB_3rc(), kVirtual);
break;
case Instruction::INVOKE_INTERFACE:
- ThrowNullPointerExceptionForMethodAccess(instr->VRegB_35c(), kInterface);
+ ThrowNullPointerExceptionForMethodAccess(instr.VRegB_35c(), kInterface);
break;
case Instruction::INVOKE_INTERFACE_RANGE:
- ThrowNullPointerExceptionForMethodAccess(instr->VRegB_3rc(), kInterface);
+ ThrowNullPointerExceptionForMethodAccess(instr.VRegB_3rc(), kInterface);
break;
case Instruction::INVOKE_POLYMORPHIC:
- ThrowNullPointerExceptionForMethodAccess(instr->VRegB_45cc(), kVirtual);
+ ThrowNullPointerExceptionForMethodAccess(instr.VRegB_45cc(), kVirtual);
break;
case Instruction::INVOKE_POLYMORPHIC_RANGE:
- ThrowNullPointerExceptionForMethodAccess(instr->VRegB_4rcc(), kVirtual);
+ ThrowNullPointerExceptionForMethodAccess(instr.VRegB_4rcc(), kVirtual);
break;
case Instruction::INVOKE_VIRTUAL_QUICK:
case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: {
@@ -612,7 +612,7 @@
case Instruction::IGET_CHAR:
case Instruction::IGET_SHORT: {
ArtField* field =
- Runtime::Current()->GetClassLinker()->ResolveField(instr->VRegC_22c(), method, false);
+ Runtime::Current()->GetClassLinker()->ResolveField(instr.VRegC_22c(), method, false);
ThrowNullPointerExceptionForFieldAccess(field, true /* read */);
break;
}
@@ -644,7 +644,7 @@
case Instruction::IPUT_CHAR:
case Instruction::IPUT_SHORT: {
ArtField* field =
- Runtime::Current()->GetClassLinker()->ResolveField(instr->VRegC_22c(), method, false);
+ Runtime::Current()->GetClassLinker()->ResolveField(instr.VRegC_22c(), method, false);
ThrowNullPointerExceptionForFieldAccess(field, false /* write */);
break;
}
@@ -707,7 +707,7 @@
const DexFile* dex_file =
method->GetDeclaringClass()->GetDexCache()->GetDexFile();
LOG(FATAL) << "NullPointerException at an unexpected instruction: "
- << instr->DumpString(dex_file)
+ << instr.DumpString(dex_file)
<< " in "
<< method->PrettyMethod();
break;