From 0264424d58e0eb3ff6fc42b7b4164b6e3b8ea8ca Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 15 Aug 2022 09:14:35 -0400 Subject: Add test for GC thrashing of young object creation This test will prevent performance regressions like [Bug #18929]. --- test/ruby/test_gc.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index a5d7f4dbaa..a1e782daa9 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -402,6 +402,28 @@ class TestGc < Test::Unit::TestCase eom end + def test_thrashing_for_young_objects + # This test prevents bugs like [Bug #18929] + + assert_separately %w[--disable-gem], __FILE__, __LINE__, <<-RUBY + # Warmup to make sure heap stabilizes + 1_000_000.times { Object.new } + + before_stats = GC.stat + + 1_000_000.times { Object.new } + + after_stats = GC.stat + + # Should not be thrashing in page creation + assert_equal before_stats[:heap_allocated_pages], after_stats[:heap_allocated_pages] + assert_equal 0, after_stats[:heap_tomb_pages] + assert_equal 0, after_stats[:total_freed_pages] + # Only young objects, so should not trigger major GC + assert_equal before_stats[:major_gc_count], after_stats[:major_gc_count] + RUBY + end + def test_gc_internals assert_not_nil GC::INTERNAL_CONSTANTS[:HEAP_PAGE_OBJ_LIMIT] assert_not_nil GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] -- cgit v1.2.3