summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-08-15 09:14:35 -0400
committerPeter Zhu <peter@peterzhu.ca>2022-08-15 10:00:03 -0400
commit0264424d58e0eb3ff6fc42b7b4164b6e3b8ea8ca (patch)
tree4660725fbd501640ab76b0b603b62c9c12a446a2
parent8d40ede2e005439cbc84abfd50c98932a33448f4 (diff)
Add test for GC thrashing of young object creation
This test will prevent performance regressions like [Bug #18929].
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6243
-rw-r--r--test/ruby/test_gc.rb22
1 files changed, 22 insertions, 0 deletions
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]