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/stack.cc b/runtime/stack.cc
index 5ad1f7c..bbea48b 100644
--- a/runtime/stack.cc
+++ b/runtime/stack.cc
@@ -154,13 +154,13 @@
return cur_shadow_frame_->GetVRegReference(0);
}
} else {
- const DexFile::CodeItem* code_item = m->GetCodeItem();
- if (code_item == nullptr) {
+ CodeItemDataAccessor accessor(m);
+ if (!accessor.HasCodeItem()) {
UNIMPLEMENTED(ERROR) << "Failed to determine this object of abstract or proxy method: "
<< ArtMethod::PrettyMethod(m);
return nullptr;
} else {
- uint16_t reg = code_item->registers_size_ - code_item->ins_size_;
+ uint16_t reg = accessor.RegistersSize() - accessor.InsSize();
uint32_t value = 0;
bool success = GetVReg(m, reg, kReferenceVReg, &value);
// We currently always guarantee the `this` object is live throughout the method.
@@ -223,11 +223,11 @@
bool StackVisitor::GetVRegFromOptimizedCode(ArtMethod* m, uint16_t vreg, VRegKind kind,
uint32_t* val) const {
DCHECK_EQ(m, GetMethod());
- const DexFile::CodeItem* code_item = m->GetCodeItem();
- DCHECK(code_item != nullptr) << m->PrettyMethod(); // Can't be null or how would we compile
- // its instructions?
- uint16_t number_of_dex_registers = code_item->registers_size_;
- DCHECK_LT(vreg, code_item->registers_size_);
+ // Can't be null or how would we compile its instructions?
+ DCHECK(m->GetCodeItem() != nullptr) << m->PrettyMethod();
+ CodeItemDataAccessor accessor(m);
+ uint16_t number_of_dex_registers = accessor.RegistersSize();
+ DCHECK_LT(vreg, number_of_dex_registers);
const OatQuickMethodHeader* method_header = GetCurrentOatQuickMethodHeader();
CodeInfo code_info = method_header->GetOptimizedCodeInfo();
CodeInfoEncoding encoding = code_info.ExtractEncoding();
@@ -395,8 +395,8 @@
uint16_t vreg,
uint32_t new_value,
VRegKind kind) {
- const DexFile::CodeItem* code_item = m->GetCodeItem();
- if (code_item == nullptr) {
+ CodeItemDataAccessor accessor(m);
+ if (!accessor.HasCodeItem()) {
return false;
}
ShadowFrame* shadow_frame = GetCurrentShadowFrame();
@@ -404,7 +404,7 @@
// This is a compiled frame: we must prepare and update a shadow frame that will
// be executed by the interpreter after deoptimization of the stack.
const size_t frame_id = GetFrameId();
- const uint16_t num_regs = code_item->registers_size_;
+ const uint16_t num_regs = accessor.RegistersSize();
shadow_frame = thread_->FindOrCreateDebuggerShadowFrame(frame_id, num_regs, m, GetDexPc());
CHECK(shadow_frame != nullptr);
// Remember the vreg has been set for debugging and must not be overwritten by the
@@ -432,15 +432,15 @@
LOG(FATAL) << "Expected long or double: kind_lo=" << kind_lo << ", kind_hi=" << kind_hi;
UNREACHABLE();
}
- const DexFile::CodeItem* code_item = m->GetCodeItem();
- if (code_item == nullptr) {
+ CodeItemDataAccessor accessor(m);
+ if (!accessor.HasCodeItem()) {
return false;
}
ShadowFrame* shadow_frame = GetCurrentShadowFrame();
if (shadow_frame == nullptr) {
// This is a compiled frame: we must prepare for deoptimization (see SetVRegFromDebugger).
const size_t frame_id = GetFrameId();
- const uint16_t num_regs = code_item->registers_size_;
+ const uint16_t num_regs = accessor.RegistersSize();
shadow_frame = thread_->FindOrCreateDebuggerShadowFrame(frame_id, num_regs, m, GetDexPc());
CHECK(shadow_frame != nullptr);
// Remember the vreg pair has been set for debugging and must not be overwritten by the