diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2023-11-22 10:06:00 -0500 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2023-11-23 09:11:24 -0500 |
| commit | a31cdc6ee9bfe517e7eaffdca7c8bfeefd0c1df1 (patch) | |
| tree | 2c6633aeeedeafacce48d0fec9e38bfebac18b41 /test/ruby | |
| parent | 7f7613c2c7550d3b008fc132821ccf305f119cac (diff) | |
Add tests for compaction during evacuation of ivars
Extracted from PR #8932.
Co-Authored-By: Jean Boussier <byroot@ruby-lang.org>
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_shapes.rb | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/test/ruby/test_shapes.rb b/test/ruby/test_shapes.rb index cf1885bbdf..7919a210a7 100644 --- a/test/ruby/test_shapes.rb +++ b/test/ruby/test_shapes.rb @@ -256,6 +256,85 @@ class TestShapes < Test::Unit::TestCase end; end + def test_evacuate_class_ivar_and_compaction + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + count = 20 + + c = Class.new + count.times do |ivar| + c.instance_variable_set("@i#{ivar}", "ivar-#{ivar}") + end + + RubyVM::Shape.exhaust_shapes + + GC.auto_compact = true + GC.stress = true + # Cause evacuation + c.instance_variable_set(:@a, o = Object.new) + assert_equal(o, c.instance_variable_get(:@a)) + GC.stress = false + + count.times do |ivar| + assert_equal "ivar-#{ivar}", c.instance_variable_get("@i#{ivar}") + end + end; + end + + def test_evacuate_generic_ivar_and_compaction + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + count = 20 + + c = Hash.new + count.times do |ivar| + c.instance_variable_set("@i#{ivar}", "ivar-#{ivar}") + end + + RubyVM::Shape.exhaust_shapes + + GC.auto_compact = true + GC.stress = true + + # Cause evacuation + c.instance_variable_set(:@a, o = Object.new) + assert_equal(o, c.instance_variable_get(:@a)) + + GC.stress = false + + count.times do |ivar| + assert_equal "ivar-#{ivar}", c.instance_variable_get("@i#{ivar}") + end + end; + end + + def test_evacuate_object_ivar_and_compaction + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + count = 20 + + c = Object.new + count.times do |ivar| + c.instance_variable_set("@i#{ivar}", "ivar-#{ivar}") + end + + RubyVM::Shape.exhaust_shapes + + GC.auto_compact = true + GC.stress = true + + # Cause evacuation + c.instance_variable_set(:@a, o = Object.new) + assert_equal(o, c.instance_variable_get(:@a)) + + GC.stress = false + + count.times do |ivar| + assert_equal "ivar-#{ivar}", c.instance_variable_get("@i#{ivar}") + end + end; + end + def test_gc_stress_during_evacuate_generic_ivar assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") begin; |
