diff options
| author | 2016-04-04 13:35:53 +0000 | |
|---|---|---|
| committer | 2016-04-04 13:35:53 +0000 | |
| commit | 2f92ec8a52faa4bc566af8fa34212f3e749e82c8 (patch) | |
| tree | 78b9ee38ae016f1198bc21ae7d913bc961f7624a /compiler/optimizing | |
| parent | 75ee5c28ab583c532066b64d6337a5f78d6aa2ad (diff) | |
| parent | 61b28a17d9b6e8e998103646e98e4a9772e11927 (diff) | |
Merge "Use bit-level packing for InlineInfo in stackmaps as well."
Diffstat (limited to 'compiler/optimizing')
| -rw-r--r-- | compiler/optimizing/stack_map_stream.cc | 58 | ||||
| -rw-r--r-- | compiler/optimizing/stack_map_stream.h | 3 | ||||
| -rw-r--r-- | compiler/optimizing/stack_map_test.cc | 74 |
3 files changed, 80 insertions, 55 deletions
diff --git a/compiler/optimizing/stack_map_stream.cc b/compiler/optimizing/stack_map_stream.cc index c571312faa..11a254ef63 100644 --- a/compiler/optimizing/stack_map_stream.cc +++ b/compiler/optimizing/stack_map_stream.cc @@ -137,8 +137,9 @@ uint32_t StackMapStream::ComputeMaxNativePcOffset() const { size_t StackMapStream::PrepareForFillIn() { int stack_mask_number_of_bits = stack_mask_max_ + 1; // Need room for max element too. - inline_info_size_ = ComputeInlineInfoSize(); dex_register_maps_size_ = ComputeDexRegisterMapsSize(); + ComputeInlineInfoEncoding(); // needs dex_register_maps_size_. + inline_info_size_ = inline_infos_.size() * inline_info_encoding_.GetEntrySize(); uint32_t max_native_pc_offset = ComputeMaxNativePcOffset(); size_t stack_map_size = stack_map_encoding_.SetFromSizes(max_native_pc_offset, dex_pc_max_, @@ -158,9 +159,10 @@ size_t StackMapStream::PrepareForFillIn() { // Prepare the CodeInfo variable-sized encoding. CodeInfoEncoding code_info_encoding; code_info_encoding.non_header_size = non_header_size; - code_info_encoding.stack_map_encoding = stack_map_encoding_; code_info_encoding.number_of_stack_maps = stack_maps_.size(); code_info_encoding.stack_map_size_in_bytes = stack_map_size; + code_info_encoding.stack_map_encoding = stack_map_encoding_; + code_info_encoding.inline_info_encoding = inline_info_encoding_; code_info_encoding.number_of_location_catalog_entries = location_catalog_entries_.size(); code_info_encoding.Compress(&code_info_encoding_); @@ -224,10 +226,26 @@ size_t StackMapStream::ComputeDexRegisterMapsSize() const { return size; } -size_t StackMapStream::ComputeInlineInfoSize() const { - return inline_infos_.size() * InlineInfo::SingleEntrySize() - // For encoding the depth. - + (number_of_stack_maps_with_inline_info_ * InlineInfo::kFixedSize); +void StackMapStream::ComputeInlineInfoEncoding() { + uint32_t method_index_max = 0; + uint32_t dex_pc_max = 0; + uint32_t invoke_type_max = 0; + + uint32_t inline_info_index = 0; + for (const StackMapEntry& entry : stack_maps_) { + for (size_t j = 0; j < entry.inlining_depth; ++j) { + InlineInfoEntry inline_entry = inline_infos_[inline_info_index++]; + method_index_max = std::max(method_index_max, inline_entry.method_index); + dex_pc_max = std::max(dex_pc_max, inline_entry.dex_pc); + invoke_type_max = std::max(invoke_type_max, static_cast<uint32_t>(inline_entry.invoke_type)); + } + } + DCHECK_EQ(inline_info_index, inline_infos_.size()); + + inline_info_encoding_.SetFromSizes(method_index_max, + dex_pc_max, + invoke_type_max, + dex_register_maps_size_); } void StackMapStream::FillIn(MemoryRegion region) { @@ -321,7 +339,7 @@ void StackMapStream::FillIn(MemoryRegion region) { if (entry.inlining_depth != 0) { MemoryRegion inline_region = inline_infos_region.Subregion( next_inline_info_offset, - InlineInfo::kFixedSize + entry.inlining_depth * InlineInfo::SingleEntrySize()); + entry.inlining_depth * inline_info_encoding_.GetEntrySize()); next_inline_info_offset += inline_region.size(); InlineInfo inline_info(inline_region); @@ -329,16 +347,18 @@ void StackMapStream::FillIn(MemoryRegion region) { stack_map.SetInlineDescriptorOffset( stack_map_encoding_, inline_region.start() - dex_register_locations_region.start()); - inline_info.SetDepth(entry.inlining_depth); + inline_info.SetDepth(inline_info_encoding_, entry.inlining_depth); DCHECK_LE(entry.inline_infos_start_index + entry.inlining_depth, inline_infos_.size()); for (size_t depth = 0; depth < entry.inlining_depth; ++depth) { InlineInfoEntry inline_entry = inline_infos_[depth + entry.inline_infos_start_index]; - inline_info.SetMethodIndexAtDepth(depth, inline_entry.method_index); - inline_info.SetDexPcAtDepth(depth, inline_entry.dex_pc); - inline_info.SetInvokeTypeAtDepth(depth, inline_entry.invoke_type); + inline_info.SetMethodIndexAtDepth(inline_info_encoding_, depth, inline_entry.method_index); + inline_info.SetDexPcAtDepth(inline_info_encoding_, depth, inline_entry.dex_pc); + inline_info.SetInvokeTypeAtDepth(inline_info_encoding_, depth, inline_entry.invoke_type); if (inline_entry.num_dex_registers == 0) { // No dex map available. - inline_info.SetDexRegisterMapOffsetAtDepth(depth, StackMap::kNoDexRegisterMap); + inline_info.SetDexRegisterMapOffsetAtDepth(inline_info_encoding_, + depth, + StackMap::kNoDexRegisterMap); DCHECK(inline_entry.live_dex_registers_mask == nullptr); } else { MemoryRegion register_region = dex_register_locations_region.Subregion( @@ -348,7 +368,8 @@ void StackMapStream::FillIn(MemoryRegion region) { next_dex_register_map_offset += register_region.size(); DexRegisterMap dex_register_map(register_region); inline_info.SetDexRegisterMapOffsetAtDepth( - depth, register_region.start() - dex_register_locations_region.start()); + inline_info_encoding_, + depth, register_region.start() - dex_register_locations_region.start()); FillInDexRegisterMap(dex_register_map, inline_entry.num_dex_registers, @@ -513,14 +534,17 @@ void StackMapStream::CheckCodeInfo(MemoryRegion region) const { DCHECK_EQ(stack_map.HasInlineInfo(stack_map_encoding), (entry.inlining_depth != 0)); if (entry.inlining_depth != 0) { InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map, encoding); - DCHECK_EQ(inline_info.GetDepth(), entry.inlining_depth); + DCHECK_EQ(inline_info.GetDepth(encoding.inline_info_encoding), entry.inlining_depth); for (size_t d = 0; d < entry.inlining_depth; ++d) { size_t inline_info_index = entry.inline_infos_start_index + d; DCHECK_LT(inline_info_index, inline_infos_.size()); InlineInfoEntry inline_entry = inline_infos_[inline_info_index]; - DCHECK_EQ(inline_info.GetDexPcAtDepth(d), inline_entry.dex_pc); - DCHECK_EQ(inline_info.GetMethodIndexAtDepth(d), inline_entry.method_index); - DCHECK_EQ(inline_info.GetInvokeTypeAtDepth(d), inline_entry.invoke_type); + DCHECK_EQ(inline_info.GetDexPcAtDepth(encoding.inline_info_encoding, d), + inline_entry.dex_pc); + DCHECK_EQ(inline_info.GetMethodIndexAtDepth(encoding.inline_info_encoding, d), + inline_entry.method_index); + DCHECK_EQ(inline_info.GetInvokeTypeAtDepth(encoding.inline_info_encoding, d), + inline_entry.invoke_type); CheckDexRegisterMap(code_info, code_info.GetDexRegisterMapAtDepth( diff --git a/compiler/optimizing/stack_map_stream.h b/compiler/optimizing/stack_map_stream.h index b686748802..41f72f508b 100644 --- a/compiler/optimizing/stack_map_stream.h +++ b/compiler/optimizing/stack_map_stream.h @@ -156,7 +156,7 @@ class StackMapStream : public ValueObject { size_t ComputeDexRegisterMapSize(uint32_t num_dex_registers, const BitVector* live_dex_registers_mask) const; size_t ComputeDexRegisterMapsSize() const; - size_t ComputeInlineInfoSize() const; + void ComputeInlineInfoEncoding(); // Returns the index of an entry with the same dex register map as the current_entry, // or kNoSameDexMapFound if no such entry exists. @@ -200,6 +200,7 @@ class StackMapStream : public ValueObject { StackMapEntry current_entry_; InlineInfoEntry current_inline_info_; StackMapEncoding stack_map_encoding_; + InlineInfoEncoding inline_info_encoding_; ArenaVector<uint8_t> code_info_encoding_; size_t inline_info_size_; size_t dex_register_maps_size_; diff --git a/compiler/optimizing/stack_map_test.cc b/compiler/optimizing/stack_map_test.cc index 35524877e3..967fd96561 100644 --- a/compiler/optimizing/stack_map_test.cc +++ b/compiler/optimizing/stack_map_test.cc @@ -237,13 +237,13 @@ TEST(StackMapTest, Test2) { ASSERT_TRUE(stack_map.HasInlineInfo(encoding.stack_map_encoding)); InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map, encoding); - ASSERT_EQ(2u, inline_info.GetDepth()); - ASSERT_EQ(82u, inline_info.GetMethodIndexAtDepth(0)); - ASSERT_EQ(42u, inline_info.GetMethodIndexAtDepth(1)); - ASSERT_EQ(3u, inline_info.GetDexPcAtDepth(0)); - ASSERT_EQ(2u, inline_info.GetDexPcAtDepth(1)); - ASSERT_EQ(kDirect, inline_info.GetInvokeTypeAtDepth(0)); - ASSERT_EQ(kStatic, inline_info.GetInvokeTypeAtDepth(1)); + ASSERT_EQ(2u, inline_info.GetDepth(encoding.inline_info_encoding)); + ASSERT_EQ(82u, inline_info.GetMethodIndexAtDepth(encoding.inline_info_encoding, 0)); + ASSERT_EQ(42u, inline_info.GetMethodIndexAtDepth(encoding.inline_info_encoding, 1)); + ASSERT_EQ(3u, inline_info.GetDexPcAtDepth(encoding.inline_info_encoding, 0)); + ASSERT_EQ(2u, inline_info.GetDexPcAtDepth(encoding.inline_info_encoding, 1)); + ASSERT_EQ(kDirect, inline_info.GetInvokeTypeAtDepth(encoding.inline_info_encoding, 0)); + ASSERT_EQ(kStatic, inline_info.GetInvokeTypeAtDepth(encoding.inline_info_encoding, 1)); } // Second stack map. @@ -741,13 +741,13 @@ TEST(StackMapTest, InlineTest) { ASSERT_EQ(4, dex_registers0.GetConstant(1, 2, ci, encoding)); InlineInfo if0 = ci.GetInlineInfoOf(sm0, encoding); - ASSERT_EQ(2u, if0.GetDepth()); - ASSERT_EQ(2u, if0.GetDexPcAtDepth(0)); - ASSERT_EQ(42u, if0.GetMethodIndexAtDepth(0)); - ASSERT_EQ(kStatic, if0.GetInvokeTypeAtDepth(0)); - ASSERT_EQ(3u, if0.GetDexPcAtDepth(1)); - ASSERT_EQ(82u, if0.GetMethodIndexAtDepth(1)); - ASSERT_EQ(kStatic, if0.GetInvokeTypeAtDepth(1)); + ASSERT_EQ(2u, if0.GetDepth(encoding.inline_info_encoding)); + ASSERT_EQ(2u, if0.GetDexPcAtDepth(encoding.inline_info_encoding, 0)); + ASSERT_EQ(42u, if0.GetMethodIndexAtDepth(encoding.inline_info_encoding, 0)); + ASSERT_EQ(kStatic, if0.GetInvokeTypeAtDepth(encoding.inline_info_encoding, 0)); + ASSERT_EQ(3u, if0.GetDexPcAtDepth(encoding.inline_info_encoding, 1)); + ASSERT_EQ(82u, if0.GetMethodIndexAtDepth(encoding.inline_info_encoding, 1)); + ASSERT_EQ(kStatic, if0.GetInvokeTypeAtDepth(encoding.inline_info_encoding, 1)); DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(0, if0, encoding, 1); ASSERT_EQ(8, dex_registers1.GetStackOffsetInBytes(0, 1, ci, encoding)); @@ -767,16 +767,16 @@ TEST(StackMapTest, InlineTest) { ASSERT_EQ(0, dex_registers0.GetConstant(1, 2, ci, encoding)); InlineInfo if1 = ci.GetInlineInfoOf(sm1, encoding); - ASSERT_EQ(3u, if1.GetDepth()); - ASSERT_EQ(2u, if1.GetDexPcAtDepth(0)); - ASSERT_EQ(42u, if1.GetMethodIndexAtDepth(0)); - ASSERT_EQ(kDirect, if1.GetInvokeTypeAtDepth(0)); - ASSERT_EQ(3u, if1.GetDexPcAtDepth(1)); - ASSERT_EQ(82u, if1.GetMethodIndexAtDepth(1)); - ASSERT_EQ(kStatic, if1.GetInvokeTypeAtDepth(1)); - ASSERT_EQ(5u, if1.GetDexPcAtDepth(2)); - ASSERT_EQ(52u, if1.GetMethodIndexAtDepth(2)); - ASSERT_EQ(kVirtual, if1.GetInvokeTypeAtDepth(2)); + ASSERT_EQ(3u, if1.GetDepth(encoding.inline_info_encoding)); + ASSERT_EQ(2u, if1.GetDexPcAtDepth(encoding.inline_info_encoding, 0)); + ASSERT_EQ(42u, if1.GetMethodIndexAtDepth(encoding.inline_info_encoding, 0)); + ASSERT_EQ(kDirect, if1.GetInvokeTypeAtDepth(encoding.inline_info_encoding, 0)); + ASSERT_EQ(3u, if1.GetDexPcAtDepth(encoding.inline_info_encoding, 1)); + ASSERT_EQ(82u, if1.GetMethodIndexAtDepth(encoding.inline_info_encoding, 1)); + ASSERT_EQ(kStatic, if1.GetInvokeTypeAtDepth(encoding.inline_info_encoding, 1)); + ASSERT_EQ(5u, if1.GetDexPcAtDepth(encoding.inline_info_encoding, 2)); + ASSERT_EQ(52u, if1.GetMethodIndexAtDepth(encoding.inline_info_encoding, 2)); + ASSERT_EQ(kVirtual, if1.GetInvokeTypeAtDepth(encoding.inline_info_encoding, 2)); DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(0, if1, encoding, 1); ASSERT_EQ(12, dex_registers1.GetStackOffsetInBytes(0, 1, ci, encoding)); @@ -786,7 +786,7 @@ TEST(StackMapTest, InlineTest) { ASSERT_EQ(10, dex_registers2.GetConstant(1, 3, ci, encoding)); ASSERT_EQ(5, dex_registers2.GetMachineRegister(2, 3, ci, encoding)); - ASSERT_FALSE(if1.HasDexRegisterMapAtDepth(2)); + ASSERT_FALSE(if1.HasDexRegisterMapAtDepth(encoding.inline_info_encoding, 2)); } { @@ -808,18 +808,18 @@ TEST(StackMapTest, InlineTest) { ASSERT_EQ(0, dex_registers0.GetConstant(1, 2, ci, encoding)); InlineInfo if2 = ci.GetInlineInfoOf(sm3, encoding); - ASSERT_EQ(3u, if2.GetDepth()); - ASSERT_EQ(2u, if2.GetDexPcAtDepth(0)); - ASSERT_EQ(42u, if2.GetMethodIndexAtDepth(0)); - ASSERT_EQ(kVirtual, if2.GetInvokeTypeAtDepth(0)); - ASSERT_EQ(5u, if2.GetDexPcAtDepth(1)); - ASSERT_EQ(52u, if2.GetMethodIndexAtDepth(1)); - ASSERT_EQ(kInterface, if2.GetInvokeTypeAtDepth(1)); - ASSERT_EQ(10u, if2.GetDexPcAtDepth(2)); - ASSERT_EQ(52u, if2.GetMethodIndexAtDepth(2)); - ASSERT_EQ(kStatic, if2.GetInvokeTypeAtDepth(2)); - - ASSERT_FALSE(if2.HasDexRegisterMapAtDepth(0)); + ASSERT_EQ(3u, if2.GetDepth(encoding.inline_info_encoding)); + ASSERT_EQ(2u, if2.GetDexPcAtDepth(encoding.inline_info_encoding, 0)); + ASSERT_EQ(42u, if2.GetMethodIndexAtDepth(encoding.inline_info_encoding, 0)); + ASSERT_EQ(kVirtual, if2.GetInvokeTypeAtDepth(encoding.inline_info_encoding, 0)); + ASSERT_EQ(5u, if2.GetDexPcAtDepth(encoding.inline_info_encoding, 1)); + ASSERT_EQ(52u, if2.GetMethodIndexAtDepth(encoding.inline_info_encoding, 1)); + ASSERT_EQ(kInterface, if2.GetInvokeTypeAtDepth(encoding.inline_info_encoding, 1)); + ASSERT_EQ(10u, if2.GetDexPcAtDepth(encoding.inline_info_encoding, 2)); + ASSERT_EQ(52u, if2.GetMethodIndexAtDepth(encoding.inline_info_encoding, 2)); + ASSERT_EQ(kStatic, if2.GetInvokeTypeAtDepth(encoding.inline_info_encoding, 2)); + + ASSERT_FALSE(if2.HasDexRegisterMapAtDepth(encoding.inline_info_encoding, 0)); DexRegisterMap dex_registers1 = ci.GetDexRegisterMapAtDepth(1, if2, encoding, 1); ASSERT_EQ(2, dex_registers1.GetMachineRegister(0, 1, ci, encoding)); |