Skip to content

Commit

Permalink
Shape compaction tests
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Nov 16, 2023
1 parent c9d0fbc commit 757f473
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions test/ruby/test_shapes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,99 @@ def test_run_out_of_shape_for_class_ivar
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
i = 0
while RubyVM::Shape.shapes_available > 0
o = Class.new
o.instance_variable_set("@i#{i}", 1)
i += 1
end
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))
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
i = 0
while RubyVM::Shape.shapes_available > 0
o = Class.new
o.instance_variable_set("@i#{i}", 1)
i += 1
end
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))
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
i = 0
while RubyVM::Shape.shapes_available > 0
o = Class.new
o.instance_variable_set("@i#{i}", 1)
i += 1
end
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))
count.times do |ivar|
assert_equal "ivar-#{ivar}", c.instance_variable_get("@i#{ivar}")
end
end;
end

def test_run_out_of_shape_for_module_ivar
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
Expand Down

0 comments on commit 757f473

Please sign in to comment.