Compress the Dex register maps built by the optimizing compiler.
- Replace the current list-based (fixed-size) Dex register
encoding in stack maps emitted by the optimizing compiler
with another list-based variable-size Dex register
encoding compressing short locations on 1 byte (3 bits for
the location kind, 5 bits for the value); other (large)
values remain encoded on 5 bytes.
- In addition, use slot offsets instead of byte offsets to
encode the location of Dex registers placed in stack
slots at small offsets, as it enables more values to use
the short (1-byte wide) encoding instead of the large
(5-byte wide) one.
- Rename art::DexRegisterMap::LocationKind as
art::DexRegisterLocation::Kind, turn it into a
strongly-typed enum based on a uint8_t, and extend it to
support new kinds (kInStackLargeOffset and
kConstantLargeValue).
- Move art::DexRegisterEntry from
compiler/optimizing/stack_map_stream.h to
runtime/stack_map.h and rename it as
art::DexRegisterLocation.
- Adjust art::StackMapStream,
art::CodeGenerator::RecordPcInfo,
art::CheckReferenceMapVisitor::CheckOptimizedMethod,
art::StackVisitor::GetVRegFromOptimizedCode, and
art::StackVisitor::SetVRegFromOptimizedCode.
- Implement unaligned memory accesses in art::MemoryRegion.
- Use them to manipulate data in Dex register maps.
- Adjust oatdump to support the new Dex register encoding.
- Update compiler/optimizing/stack_map_test.cc.
Change-Id: Icefaa2e2b36b3c80bb1b882fe7ea2f77ba85c505
diff --git a/runtime/stack.cc b/runtime/stack.cc
index 48becf6..e420c57 100644
--- a/runtime/stack.cc
+++ b/runtime/stack.cc
@@ -204,29 +204,32 @@
DCHECK(code_item != nullptr) << PrettyMethod(m); // Can't be NULL or how would we compile
// its instructions?
DCHECK_LT(vreg, code_item->registers_size_);
- DexRegisterMap dex_register_map = code_info.GetDexRegisterMapOf(stack_map,
- code_item->registers_size_);
- DexRegisterMap::LocationKind location_kind = dex_register_map.GetLocationKind(vreg);
+ DexRegisterMap dex_register_map =
+ code_info.GetDexRegisterMapOf(stack_map, code_item->registers_size_);
+ DexRegisterLocation::Kind location_kind = dex_register_map.GetLocationKind(vreg);
switch (location_kind) {
- case DexRegisterMap::kInStack: {
+ case DexRegisterLocation::Kind::kInStack: {
const int32_t offset = dex_register_map.GetStackOffsetInBytes(vreg);
const uint8_t* addr = reinterpret_cast<const uint8_t*>(cur_quick_frame_) + offset;
*val = *reinterpret_cast<const uint32_t*>(addr);
return true;
}
- case DexRegisterMap::kInRegister:
- case DexRegisterMap::kInFpuRegister: {
+ case DexRegisterLocation::Kind::kInRegister:
+ case DexRegisterLocation::Kind::kInFpuRegister: {
uint32_t reg = dex_register_map.GetMachineRegister(vreg);
return GetRegisterIfAccessible(reg, kind, val);
}
- case DexRegisterMap::kConstant:
+ case DexRegisterLocation::Kind::kConstant:
*val = dex_register_map.GetConstant(vreg);
return true;
- case DexRegisterMap::kNone:
+ case DexRegisterLocation::Kind::kNone:
return false;
+ default:
+ LOG(FATAL)
+ << "Unexpected location kind"
+ << DexRegisterLocation::PrettyDescriptor(dex_register_map.GetLocationInternalKind(vreg));
+ UNREACHABLE();
}
- UNREACHABLE();
- return false;
}
bool StackVisitor::GetRegisterIfAccessible(uint32_t reg, VRegKind kind, uint32_t* val) const {
@@ -386,29 +389,29 @@
DCHECK(code_item != nullptr) << PrettyMethod(m); // Can't be NULL or how would we compile
// its instructions?
DCHECK_LT(vreg, code_item->registers_size_);
- DexRegisterMap dex_register_map = code_info.GetDexRegisterMapOf(stack_map,
- code_item->registers_size_);
- DexRegisterMap::LocationKind location_kind = dex_register_map.GetLocationKind(vreg);
+ DexRegisterMap dex_register_map =
+ code_info.GetDexRegisterMapOf(stack_map, code_item->registers_size_);
+ DexRegisterLocation::Kind location_kind = dex_register_map.GetLocationKind(vreg);
uint32_t dex_pc = m->ToDexPc(cur_quick_frame_pc_, false);
switch (location_kind) {
- case DexRegisterMap::kInStack: {
+ case DexRegisterLocation::Kind::kInStack: {
const int32_t offset = dex_register_map.GetStackOffsetInBytes(vreg);
uint8_t* addr = reinterpret_cast<uint8_t*>(cur_quick_frame_) + offset;
*reinterpret_cast<uint32_t*>(addr) = new_value;
return true;
}
- case DexRegisterMap::kInRegister:
- case DexRegisterMap::kInFpuRegister: {
+ case DexRegisterLocation::Kind::kInRegister:
+ case DexRegisterLocation::Kind::kInFpuRegister: {
uint32_t reg = dex_register_map.GetMachineRegister(vreg);
return SetRegisterIfAccessible(reg, new_value, kind);
}
- case DexRegisterMap::kConstant:
+ case DexRegisterLocation::Kind::kConstant:
LOG(ERROR) << StringPrintf("Cannot change value of DEX register v%u used as a constant at "
"DEX pc 0x%x (native pc 0x%x) of method %s",
vreg, dex_pc, native_pc_offset,
PrettyMethod(cur_quick_frame_->AsMirrorPtr()).c_str());
return false;
- case DexRegisterMap::kNone:
+ case DexRegisterLocation::Kind::kNone:
LOG(ERROR) << StringPrintf("No location for DEX register v%u at DEX pc 0x%x "
"(native pc 0x%x) of method %s",
vreg, dex_pc, native_pc_offset,