From 1e6cb63d77090ddc6aa19c755d7066f66e9ff87e Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Thu, 28 Nov 2013 16:27:29 +0000 Subject: 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 --- runtime/mapping_table.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'runtime/mapping_table.h') 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 @@ class MappingTable { 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(DecodeSignedLeb128(&encoded_table_ptr_)); } } else { // An iterator wanted from the end. DCHECK_EQ(table_->DexToPcSize(), element); @@ -87,8 +88,9 @@ class MappingTable { 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(DecodeSignedLeb128(&encoded_table_ptr_)); } } bool operator==(const DexToPcIterator& rhs) const { @@ -147,7 +149,8 @@ class MappingTable { 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(DecodeSignedLeb128(&encoded_table_ptr_)); } } else { // An iterator wanted from the end. DCHECK_EQ(table_->PcToDexSize(), element); @@ -162,8 +165,9 @@ class MappingTable { 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(DecodeSignedLeb128(&encoded_table_ptr_)); } } bool operator==(const PcToDexIterator& rhs) const { -- cgit v1.1