summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/objspace/test_objspace.rb9
-rw-r--r--test/ruby/test_gc.rb4
-rw-r--r--test/ruby/test_gc_compact.rb2
-rw-r--r--test/ruby/test_object.rb46
-rw-r--r--test/ruby/test_time.rb5
-rw-r--r--test/ruby/test_transcode.rb2
-rw-r--r--zjit/src/hir/opt_tests.rs23
7 files changed, 47 insertions, 44 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index c1208cf424..8d019e587a 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -473,12 +473,12 @@ class TestObjSpace < Test::Unit::TestCase
assert_include(info, '"embedded":true')
assert_include(info, '"ivars":0')
- # Non-embed object
+ # Non-embed object (needs > 6 ivars to exceed pool 0 embed capacity)
obj = klass.new
- 5.times { |i| obj.instance_variable_set("@ivar#{i}", 0) }
+ 7.times { |i| obj.instance_variable_set("@ivar#{i}", 0) }
info = ObjectSpace.dump(obj)
assert_not_include(info, '"embedded":true')
- assert_include(info, '"ivars":5')
+ assert_include(info, '"ivars":7')
end
def test_dump_control_char
@@ -648,7 +648,8 @@ class TestObjSpace < Test::Unit::TestCase
next if obj["type"] == "SHAPE"
assert_not_nil obj["slot_size"]
- assert_equal 0, obj["slot_size"] % GC.stat_heap(0, :slot_size)
+ slot_sizes = GC::INTERNAL_CONSTANTS[:HEAP_COUNT].times.map { |i| GC.stat_heap(i, :slot_size) }
+ assert_include slot_sizes, obj["slot_size"]
}
end
end
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index 43540d4412..21448294c2 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -230,7 +230,7 @@ class TestGc < Test::Unit::TestCase
GC.stat(stat)
end
- assert_equal GC.stat_heap(0, :slot_size) * (2**i), stat_heap[:slot_size]
+ assert_equal GC.stat_heap(i, :slot_size), stat_heap[:slot_size]
assert_operator stat_heap[:heap_live_slots], :<=, stat[:heap_live_slots]
assert_operator stat_heap[:heap_free_slots], :<=, stat[:heap_free_slots]
assert_operator stat_heap[:heap_final_slots], :<=, stat[:heap_final_slots]
@@ -773,7 +773,7 @@ class TestGc < Test::Unit::TestCase
end
def test_gc_stress_at_startup
- assert_in_out_err([{"RUBY_DEBUG"=>"gc_stress"}], '', [], [], '[Bug #15784]', success: true, timeout: 60)
+ assert_in_out_err([{"RUBY_DEBUG"=>"gc_stress"}], '', [], [], '[Bug #15784]', success: true, timeout: 120)
end
def test_gc_disabled_start
diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb
index 95a3d031a7..b8d53d7197 100644
--- a/test/ruby/test_gc_compact.rb
+++ b/test/ruby/test_gc_compact.rb
@@ -315,7 +315,7 @@ class TestGCCompact < Test::Unit::TestCase
GC.verify_compaction_references(expand_heap: true, toward: :empty)
Fiber.new {
- ary = "hello".chars
+ ary = "hello world".chars # > 6 elements to exceed pool 0 embed capacity
$arys = ARY_COUNT.times.map do
x = []
ary.each { |e| x << e }
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index 7342b3f933..646244a43a 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -358,38 +358,40 @@ class TestObject < Test::Unit::TestCase
def test_remove_instance_variable_re_embed
assert_separately(%w[-robjspace], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
- c = Class.new do
- attr_reader :a, :b, :c
+ # Determine the RVALUE pool's embed capacity from GC constants.
+ rvalue_size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]
+ rbasic_size = GC::INTERNAL_CONSTANTS[:RBASIC_SIZE]
+ embed_cap = (rvalue_size - rbasic_size) / RbConfig::SIZEOF["void*"]
- def initialize
- @a = nil
- @b = nil
- @c = nil
- end
- end
+ # Build a class whose initialize sets embed_cap ivars so objects
+ # are allocated in the RVALUE pool with embedded storage.
+ init_body = embed_cap.times.map { |i| "@v#{i} = nil" }.join("; ")
+ c = Class.new { class_eval("def initialize; #{init_body}; end") }
o1 = c.new
o2 = c.new
- o1.instance_variable_set(:@foo, 5)
- o1.instance_variable_set(:@a, 0)
- o1.instance_variable_set(:@b, 1)
- o1.instance_variable_set(:@c, 2)
+ # All embed_cap ivars fit - should be embedded
+ embed_cap.times { |i| o1.instance_variable_set(:"@v#{i}", i) }
+ assert_includes ObjectSpace.dump(o1), '"embedded":true'
+
+ # One more ivar overflows embed capacity
+ o1.instance_variable_set(:@overflow, 99)
refute_includes ObjectSpace.dump(o1), '"embedded":true'
- o1.remove_instance_variable(:@foo)
+
+ # Remove the overflow ivar - should re-embed
+ o1.remove_instance_variable(:@overflow)
assert_includes ObjectSpace.dump(o1), '"embedded":true'
- o2.instance_variable_set(:@a, 0)
- o2.instance_variable_set(:@b, 1)
- o2.instance_variable_set(:@c, 2)
+ # An object that never overflowed is also embedded
+ embed_cap.times { |i| o2.instance_variable_set(:"@v#{i}", i) }
assert_includes ObjectSpace.dump(o2), '"embedded":true'
- assert_equal(0, o1.a)
- assert_equal(1, o1.b)
- assert_equal(2, o1.c)
- assert_equal(0, o2.a)
- assert_equal(1, o2.b)
- assert_equal(2, o2.c)
+ # Verify values survived re-embedding
+ embed_cap.times do |i|
+ assert_equal(i, o1.instance_variable_get(:"@v#{i}"))
+ assert_equal(i, o2.instance_variable_get(:"@v#{i}"))
+ end
end;
end
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index 7370a9d7ca..b2cbd06a9f 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -1433,7 +1433,10 @@ class TestTime < Test::Unit::TestCase
RbConfig::SIZEOF["void*"] # Same size as VALUE
end
sizeof_vtm = RbConfig::SIZEOF["void*"] * 4 + 8
- expect = GC.stat_heap(0, :slot_size) - GC::INTERNAL_CONSTANTS[:RVALUE_OVERHEAD] + sizeof_timew + sizeof_vtm
+ data_size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] + sizeof_timew + sizeof_vtm
+ # Round up to the smallest slot size that fits
+ slot_sizes = GC::INTERNAL_CONSTANTS[:HEAP_COUNT].times.map { |i| GC.stat_heap(i, :slot_size) }
+ expect = slot_sizes.find { |s| s >= data_size } || slot_sizes.last
assert_operator ObjectSpace.memsize_of(t), :<=, expect
rescue LoadError => e
omit "failed to load objspace: #{e.message}"
diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb
index 99b5ee8d43..2c4462eb71 100644
--- a/test/ruby/test_transcode.rb
+++ b/test/ruby/test_transcode.rb
@@ -2344,7 +2344,7 @@ class TestTranscode < Test::Unit::TestCase
def test_ractor_lazy_load_encoding_random
omit 'unstable on s390x and windows' if RUBY_PLATFORM =~ /s390x|mswin/
- assert_ractor("#{<<~"begin;"}\n#{<<~'end;'}")
+ assert_ractor("#{<<~"begin;"}\n#{<<~'end;'}", timeout: 30)
begin;
rs = []
100.times do
diff --git a/zjit/src/hir/opt_tests.rs b/zjit/src/hir/opt_tests.rs
index 71da70d2f3..fa7b045d5f 100644
--- a/zjit/src/hir/opt_tests.rs
+++ b/zjit/src/hir/opt_tests.rs
@@ -5517,10 +5517,7 @@ mod hir_opt_tests {
v14:HeapBasicObject = RefineType v6, HeapBasicObject
v17:Fixnum[2] = Const Value(2)
PatchPoint SingleRactorMode
- StoreField v14, :@bar@0x1004, v17
- WriteBarrier v14, v17
- v40:CShape[0x1005] = Const CShape(0x1005)
- StoreField v14, :_shape_id@0x1000, v40
+ SetIvar v14, :@bar, v17
CheckInterrupts
Return v17
");
@@ -14975,21 +14972,21 @@ mod hir_opt_tests {
v14:HeapBasicObject = RefineType v6, HeapBasicObject
v17:Fixnum[2] = Const Value(2)
PatchPoint SingleRactorMode
- StoreField v14, :@b@0x1004, v17
- WriteBarrier v14, v17
- v54:CShape[0x1005] = Const CShape(0x1005)
- StoreField v14, :_shape_id@0x1000, v54
+ SetIvar v14, :@b, v17
v21:HeapBasicObject = RefineType v14, HeapBasicObject
v24:Fixnum[3] = Const Value(3)
PatchPoint SingleRactorMode
- StoreField v21, :@c@0x1006, v24
- WriteBarrier v21, v24
- v61:CShape[0x1007] = Const CShape(0x1007)
- StoreField v21, :_shape_id@0x1000, v61
+ SetIvar v21, :@c, v24
v28:HeapBasicObject = RefineType v21, HeapBasicObject
v31:Fixnum[4] = Const Value(4)
PatchPoint SingleRactorMode
- SetIvar v28, :@d, v31
+ v50:CShape = LoadField v28, :_shape_id@0x1000
+ v51:CShape[0x1004] = GuardBitEquals v50, CShape(0x1004)
+ v52:CPtr = LoadField v28, :_as_heap@0x1002
+ StoreField v52, :@d@0x1005, v31
+ WriteBarrier v28, v31
+ v55:CShape[0x1006] = Const CShape(0x1006)
+ StoreField v28, :_shape_id@0x1000, v55
CheckInterrupts
Return v31
");