Delta-encoding of mapping tables.
Both PC offsets and dalvik offsets are delta-encoded. Since
PC offsets are increasing, the deltas are then compressed as
unsigned LEB128. Dalvik offsets are not monotonic, so their
deltas are compressed as signed LEB128.
This reduces the size of the mapping tables by about 30%
on average, 25% from the PC offset and 5% from the dalvik
offset delta encoding.
Bug: 9437697
Change-Id: I600ab9c22dec178088d4947a811cca3bc8bd4cf4
diff --git a/runtime/mapping_table.h b/runtime/mapping_table.h
index c468c1e..a82bc1c 100644
--- a/runtime/mapping_table.h
+++ b/runtime/mapping_table.h
@@ -72,7 +72,8 @@
if (end_ > 0) {
encoded_table_ptr_ = table_->FirstDexToPcPtr();
native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
- dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ // First delta is always positive.
+ dex_pc_ = static_cast<uint32_t>(DecodeSignedLeb128(&encoded_table_ptr_));
}
} else { // An iterator wanted from the end.
DCHECK_EQ(table_->DexToPcSize(), element);
@@ -87,8 +88,9 @@
void operator++() {
++element_;
if (element_ != end_) { // Avoid reading beyond the end of the table.
- native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
- dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ native_pc_offset_ += DecodeUnsignedLeb128(&encoded_table_ptr_);
+ // For negative delta, unsigned overflow after static_cast does exactly what we need.
+ dex_pc_ += static_cast<uint32_t>(DecodeSignedLeb128(&encoded_table_ptr_));
}
}
bool operator==(const DexToPcIterator& rhs) const {
@@ -147,7 +149,8 @@
if (end_ > 0) {
encoded_table_ptr_ = table_->FirstPcToDexPtr();
native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
- dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ // First delta is always positive.
+ dex_pc_ = static_cast<uint32_t>(DecodeSignedLeb128(&encoded_table_ptr_));
}
} else { // An iterator wanted from the end.
DCHECK_EQ(table_->PcToDexSize(), element);
@@ -162,8 +165,9 @@
void operator++() {
++element_;
if (element_ != end_) { // Avoid reading beyond the end of the table.
- native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
- dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ native_pc_offset_ += DecodeUnsignedLeb128(&encoded_table_ptr_);
+ // For negative delta, unsigned overflow after static_cast does exactly what we need.
+ dex_pc_ += static_cast<uint32_t>(DecodeSignedLeb128(&encoded_table_ptr_));
}
}
bool operator==(const PcToDexIterator& rhs) const {