Skip to content

Commit aa5f192

Browse files
Update tests for new pool layout
1 parent b6658c1 commit aa5f192

7 files changed

Lines changed: 47 additions & 44 deletions

File tree

test/objspace/test_objspace.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,12 @@ def test_dump_object
473473
assert_include(info, '"embedded":true')
474474
assert_include(info, '"ivars":0')
475475

476-
# Non-embed object
476+
# Non-embed object (needs > 6 ivars to exceed pool 0 embed capacity)
477477
obj = klass.new
478-
5.times { |i| obj.instance_variable_set("@ivar#{i}", 0) }
478+
7.times { |i| obj.instance_variable_set("@ivar#{i}", 0) }
479479
info = ObjectSpace.dump(obj)
480480
assert_not_include(info, '"embedded":true')
481-
assert_include(info, '"ivars":5')
481+
assert_include(info, '"ivars":7')
482482
end
483483

484484
def test_dump_control_char
@@ -648,7 +648,8 @@ def dump_my_heap_please
648648
next if obj["type"] == "SHAPE"
649649

650650
assert_not_nil obj["slot_size"]
651-
assert_equal 0, obj["slot_size"] % GC.stat_heap(0, :slot_size)
651+
slot_sizes = GC::INTERNAL_CONSTANTS[:HEAP_COUNT].times.map { |i| GC.stat_heap(i, :slot_size) }
652+
assert_include slot_sizes, obj["slot_size"]
652653
}
653654
end
654655
end

test/ruby/test_gc.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def test_stat_heap
230230
GC.stat(stat)
231231
end
232232

233-
assert_equal GC.stat_heap(0, :slot_size) * (2**i), stat_heap[:slot_size]
233+
assert_equal GC.stat_heap(i, :slot_size), stat_heap[:slot_size]
234234
assert_operator stat_heap[:heap_live_slots], :<=, stat[:heap_live_slots]
235235
assert_operator stat_heap[:heap_free_slots], :<=, stat[:heap_free_slots]
236236
assert_operator stat_heap[:heap_final_slots], :<=, stat[:heap_final_slots]
@@ -773,7 +773,7 @@ def initialize
773773
end
774774

775775
def test_gc_stress_at_startup
776-
assert_in_out_err([{"RUBY_DEBUG"=>"gc_stress"}], '', [], [], '[Bug #15784]', success: true, timeout: 60)
776+
assert_in_out_err([{"RUBY_DEBUG"=>"gc_stress"}], '', [], [], '[Bug #15784]', success: true, timeout: 120)
777777
end
778778

779779
def test_gc_disabled_start

test/ruby/test_gc_compact.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def test_moving_arrays_up_heaps
315315
GC.verify_compaction_references(expand_heap: true, toward: :empty)
316316
317317
Fiber.new {
318-
ary = "hello".chars
318+
ary = "hello world".chars # > 6 elements to exceed pool 0 embed capacity
319319
$arys = ARY_COUNT.times.map do
320320
x = []
321321
ary.each { |e| x << e }

test/ruby/test_object.rb

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -358,38 +358,40 @@ def test_remove_instance_variable
358358
def test_remove_instance_variable_re_embed
359359
assert_separately(%w[-robjspace], "#{<<~"begin;"}\n#{<<~'end;'}")
360360
begin;
361-
c = Class.new do
362-
attr_reader :a, :b, :c
361+
# Determine the RVALUE pool's embed capacity from GC constants.
362+
rvalue_size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]
363+
rbasic_size = GC::INTERNAL_CONSTANTS[:RBASIC_SIZE]
364+
embed_cap = (rvalue_size - rbasic_size) / RbConfig::SIZEOF["void*"]
363365
364-
def initialize
365-
@a = nil
366-
@b = nil
367-
@c = nil
368-
end
369-
end
366+
# Build a class whose initialize sets embed_cap ivars so objects
367+
# are allocated in the RVALUE pool with embedded storage.
368+
init_body = embed_cap.times.map { |i| "@v#{i} = nil" }.join("; ")
369+
c = Class.new { class_eval("def initialize; #{init_body}; end") }
370370
371371
o1 = c.new
372372
o2 = c.new
373373
374-
o1.instance_variable_set(:@foo, 5)
375-
o1.instance_variable_set(:@a, 0)
376-
o1.instance_variable_set(:@b, 1)
377-
o1.instance_variable_set(:@c, 2)
374+
# All embed_cap ivars fit - should be embedded
375+
embed_cap.times { |i| o1.instance_variable_set(:"@v#{i}", i) }
376+
assert_includes ObjectSpace.dump(o1), '"embedded":true'
377+
378+
# One more ivar overflows embed capacity
379+
o1.instance_variable_set(:@overflow, 99)
378380
refute_includes ObjectSpace.dump(o1), '"embedded":true'
379-
o1.remove_instance_variable(:@foo)
381+
382+
# Remove the overflow ivar - should re-embed
383+
o1.remove_instance_variable(:@overflow)
380384
assert_includes ObjectSpace.dump(o1), '"embedded":true'
381385
382-
o2.instance_variable_set(:@a, 0)
383-
o2.instance_variable_set(:@b, 1)
384-
o2.instance_variable_set(:@c, 2)
386+
# An object that never overflowed is also embedded
387+
embed_cap.times { |i| o2.instance_variable_set(:"@v#{i}", i) }
385388
assert_includes ObjectSpace.dump(o2), '"embedded":true'
386389
387-
assert_equal(0, o1.a)
388-
assert_equal(1, o1.b)
389-
assert_equal(2, o1.c)
390-
assert_equal(0, o2.a)
391-
assert_equal(1, o2.b)
392-
assert_equal(2, o2.c)
390+
# Verify values survived re-embedding
391+
embed_cap.times do |i|
392+
assert_equal(i, o1.instance_variable_get(:"@v#{i}"))
393+
assert_equal(i, o2.instance_variable_get(:"@v#{i}"))
394+
end
393395
end;
394396
end
395397

test/ruby/test_time.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,10 @@ def test_memsize
14331433
RbConfig::SIZEOF["void*"] # Same size as VALUE
14341434
end
14351435
sizeof_vtm = RbConfig::SIZEOF["void*"] * 4 + 8
1436-
expect = GC.stat_heap(0, :slot_size) - GC::INTERNAL_CONSTANTS[:RVALUE_OVERHEAD] + sizeof_timew + sizeof_vtm
1436+
data_size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] + sizeof_timew + sizeof_vtm
1437+
# Round up to the smallest slot size that fits
1438+
slot_sizes = GC::INTERNAL_CONSTANTS[:HEAP_COUNT].times.map { |i| GC.stat_heap(i, :slot_size) }
1439+
expect = slot_sizes.find { |s| s >= data_size } || slot_sizes.last
14371440
assert_operator ObjectSpace.memsize_of(t), :<=, expect
14381441
rescue LoadError => e
14391442
omit "failed to load objspace: #{e.message}"

test/ruby/test_transcode.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,7 @@ def test_ractor_lazy_load_encoding
23442344

23452345
def test_ractor_lazy_load_encoding_random
23462346
omit 'unstable on s390x and windows' if RUBY_PLATFORM =~ /s390x|mswin/
2347-
assert_ractor("#{<<~"begin;"}\n#{<<~'end;'}")
2347+
assert_ractor("#{<<~"begin;"}\n#{<<~'end;'}", timeout: 30)
23482348
begin;
23492349
rs = []
23502350
100.times do

zjit/src/hir/opt_tests.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5517,10 +5517,7 @@ mod hir_opt_tests {
55175517
v14:HeapBasicObject = RefineType v6, HeapBasicObject
55185518
v17:Fixnum[2] = Const Value(2)
55195519
PatchPoint SingleRactorMode
5520-
StoreField v14, :@bar@0x1004, v17
5521-
WriteBarrier v14, v17
5522-
v40:CShape[0x1005] = Const CShape(0x1005)
5523-
StoreField v14, :_shape_id@0x1000, v40
5520+
SetIvar v14, :@bar, v17
55245521
CheckInterrupts
55255522
Return v17
55265523
");
@@ -14975,21 +14972,21 @@ mod hir_opt_tests {
1497514972
v14:HeapBasicObject = RefineType v6, HeapBasicObject
1497614973
v17:Fixnum[2] = Const Value(2)
1497714974
PatchPoint SingleRactorMode
14978-
StoreField v14, :@b@0x1004, v17
14979-
WriteBarrier v14, v17
14980-
v54:CShape[0x1005] = Const CShape(0x1005)
14981-
StoreField v14, :_shape_id@0x1000, v54
14975+
SetIvar v14, :@b, v17
1498214976
v21:HeapBasicObject = RefineType v14, HeapBasicObject
1498314977
v24:Fixnum[3] = Const Value(3)
1498414978
PatchPoint SingleRactorMode
14985-
StoreField v21, :@c@0x1006, v24
14986-
WriteBarrier v21, v24
14987-
v61:CShape[0x1007] = Const CShape(0x1007)
14988-
StoreField v21, :_shape_id@0x1000, v61
14979+
SetIvar v21, :@c, v24
1498914980
v28:HeapBasicObject = RefineType v21, HeapBasicObject
1499014981
v31:Fixnum[4] = Const Value(4)
1499114982
PatchPoint SingleRactorMode
14992-
SetIvar v28, :@d, v31
14983+
v50:CShape = LoadField v28, :_shape_id@0x1000
14984+
v51:CShape[0x1004] = GuardBitEquals v50, CShape(0x1004)
14985+
v52:CPtr = LoadField v28, :_as_heap@0x1002
14986+
StoreField v52, :@d@0x1005, v31
14987+
WriteBarrier v28, v31
14988+
v55:CShape[0x1006] = Const CShape(0x1006)
14989+
StoreField v28, :_shape_id@0x1000, v55
1499314990
CheckInterrupts
1499414991
Return v31
1499514992
");

0 commit comments

Comments
 (0)