From 7ec73b9ccdeaed30e813884f7765281be422bc21 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 20 Aug 2022 21:35:22 +0000 Subject: support Ruby 3.0.x HEAP_PAGE_SIZE no longer estimates malloc overhead in Ruby 3.0.x, but we can now rely on the GC::INTERNAL_CONSTANTS hash to access the true value. We also need to account for Ractors in 3.0+, and thus we need to rely on thread-specific `ruby_current_ec' instead of process-wide `ruby_current_execution_context_ptr' (which no longer exists in 3.0+). Finally, the VM seems prone to making some small immortal allocations in a few places we were not expecting in 2.7 and earlier. Account for that and loosen some exact checks to account for it. Tested on Ruby 3.0.3 and 3.0.4 --- test/test_mwrap.rb | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'test/test_mwrap.rb') diff --git a/test/test_mwrap.rb b/test/test_mwrap.rb index 48fba23..fadaef6 100644 --- a/test/test_mwrap.rb +++ b/test/test_mwrap.rb @@ -29,7 +29,8 @@ class TestMwrap < Test::Unit::TestCase tmp.rewind lines = tmp.readlines line_1 = lines.grep(/\s-e:1\b/)[0].strip - assert_equal '10001', line_1.split(/\s+/)[0] + bytes = line_1.split(/\s+/)[0].to_i + assert_operator bytes, :>=, 10001 end end @@ -42,7 +43,7 @@ class TestMwrap < Test::Unit::TestCase res = system(env, *cmd, { 5 => tmp }) assert res, $?.inspect tmp.rewind - assert_match(/\b10001\s+1\s+-e:1$/, tmp.read) + assert_match(/\b1\d{4}\s+[1-9]\d*\s+-e:1$/, tmp.read) env['MWRAP'] = 'dump_fd:1,dump_min:10000' tmp.rewind @@ -50,14 +51,14 @@ class TestMwrap < Test::Unit::TestCase res = system(env, *cmd, { 1 => tmp }) assert res, $?.inspect tmp.rewind - assert_match(/\b10001\s+1\s+-e:1$/, tmp.read) + assert_match(/\b1\d{4}\s+[1-9]\d*\s+-e:1$/, tmp.read) tmp.rewind tmp.truncate(0) env['MWRAP'] = "dump_path:#{tmp.path},dump_min:10000" res = system(env, *cmd) assert res, $?.inspect - assert_match(/\b10001\s+1\s+-e:1$/, tmp.read) + assert_match(/\b1\d{4}\s+[1-9]\d*\s+-e:1$/, tmp.read) tmp.rewind tmp.truncate(0) @@ -98,7 +99,7 @@ class TestMwrap < Test::Unit::TestCase tmp.rewind buf = tmp.read assert_not_match(/\s+-e:1$/, buf) - assert_match(/\b20001\s+1\s+-e:3$/, buf) + assert_match(/\b2\d{4}\s+[0-9]\d*\s+-e:3$/, buf) end end @@ -176,8 +177,8 @@ class TestMwrap < Test::Unit::TestCase -e GC.disable -e keep=("0"*10000) -e loc=Mwrap["-e:3"] - -e loc.each{|size,gen|p([size,gen,count])} - ) + -e + ) + [ 'loc.each{|size,gen|p([size,gen,count]) if size > 10000}' ] buf = IO.popen(@@env, cmd, &:read) assert_predicate $?, :success? assert_match(/\A\[\s*\d+,\s*\d+,\s*\d+\]\s*\z/s, buf) @@ -230,7 +231,8 @@ class TestMwrap < Test::Unit::TestCase loc.name == k or abort 'SourceLocation#name broken' loc.total >= 10000 or abort 'SourceLocation#total broken' loc.frees == 0 or abort 'SourceLocation#frees broken' - loc.allocations == 1 or abort 'SourceLocation#allocations broken' + loc.allocations >= 1 or + abort "SourceLocation#allocations broken: #{loc.allocations}" seen = false loc.each do |*x| seen = x end seen[1] == loc.total or 'SourceLocation#each broken' @@ -240,7 +242,9 @@ class TestMwrap < Test::Unit::TestCase freed = false until freed freed = true - loc.each do freed = false end + loc.each do |size, gen| + freed = false if size >= 10000 + end end loc.frees == 1 or abort 'SourceLocation#frees broken (after free)' Float === loc.mean_lifespan or abort 'mean_lifespan broken' @@ -264,8 +268,9 @@ class TestMwrap < Test::Unit::TestCase assert_separately(+"#{<<~"begin;"}\n#{<<~'end;'}") begin; require 'mwrap' - before = __LINE__ + before = nil res = Mwrap.quiet do |depth| + before = __LINE__ depth == 1 or abort 'depth is not 1' ('a' * 10000).clear Mwrap.quiet { |d| d == 2 or abort 'depth is not 2' } @@ -304,7 +309,7 @@ class TestMwrap < Test::Unit::TestCase gen <= GC.count && gen >= 0 or abort "bad generation: #{gen}" (0 == (addr & 16383)) or abort "addr not aligned: #{'%x' % addr}" end - nr == ap or abort 'HeapPageBody.each missed page' + nr == ap or abort "HeapPageBody.each missed page #{nr} != #{ap}" 10.times { (1..20000).to_a.map(&:to_s) } 3.times { GC.start } Mwrap::HeapPageBody.stat(h) -- cgit v1.2.3-24-ge0c7