ruby-changes:72364
From: Peter <ko1@a...>
Date: Thu, 30 Jun 2022 04:12:03 +0900 (JST)
Subject: [ruby-changes:72364] 66eb58d6bd (master): Refactor tests for moving strings with compaction
https://git.ruby-lang.org/ruby.git/commit/?id=66eb58d6bd From 66eb58d6bd50dd3ad8691fcc8eb72ad4d45bc04c Mon Sep 17 00:00:00 2001 From: Peter Zhu <peter@p...> Date: Wed, 29 Jun 2022 14:04:04 -0400 Subject: Refactor tests for moving strings with compaction --- test/ruby/test_gc_compact.rb | 50 +++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb index c312ac1ea2..802630b1a4 100644 --- a/test/ruby/test_gc_compact.rb +++ b/test/ruby/test_gc_compact.rb @@ -209,42 +209,36 @@ class TestGCCompact < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc_compact.rb#L209 assert_equal([:call, :line], results) end - def test_moving_strings_between_size_pools + def test_moving_strings_up_size_pools assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 10, signal: :SEGV) begin; - moveables = [] - small_slots = [] - large_slots = [] + STR_COUNT = 500 - # Ensure fragmentation in the large heap - base_slot_size = GC.stat_heap[0].fetch(:slot_size) - 500.times { - String.new(+"a" * base_slot_size).downcase - large_slots << String.new(+"a" * base_slot_size).downcase - } + GC.verify_compaction_references(double_heap: true, toward: :empty) - # Ensure fragmentation in the smaller heap - 500.times { - small_slots << Object.new - Object.new - } + str = "a" * GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] + ary = STR_COUNT.times.map { "" << str } - 500.times { - # strings are created as shared strings when initialized from literals - # use downcase to force the creation of an embedded string (it calls - # rb_str_new internally) - moveables << String.new(+"a" * base_slot_size).downcase + stats = GC.verify_compaction_references(double_heap: true, toward: :empty) - moveables << String.new("a").downcase - } - moveables.map { |s| s << ("bc" * base_slot_size) } - moveables.map { |s| s.squeeze! } - stats = GC.compact + assert_operator(stats[:moved_up][:T_STRING], :>=, STR_COUNT) + assert(ary) # warning: assigned but unused variable - ary + end; + end + + def test_moving_strings_down_size_pools + assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 10, signal: :SEGV) + begin; + STR_COUNT = 500 + + GC.verify_compaction_references(double_heap: true, toward: :empty) + + ary = STR_COUNT.times.map { ("a" * GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE]).squeeze! } - moved_strings = (stats.dig(:moved_up, :T_STRING) || 0) + - (stats.dig(:moved_down, :T_STRING) || 0) + stats = GC.verify_compaction_references(double_heap: true, toward: :empty) - assert_operator(moved_strings, :>, 0) + assert_operator(stats[:moved_down][:T_STRING], :>=, STR_COUNT) + assert(ary) # warning: assigned but unused variable - ary end; end end -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/