diff options
author | Peter Zhu <peter@peterzhu.ca> | 2022-02-01 09:25:12 -0500 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2022-02-02 09:52:04 -0500 |
commit | 7b77d46671685c837adc33b39ae0210e04cd8b24 (patch) | |
tree | 426dd92de0af81c4d6cbc3f0af732cc7fe80ede8 /test | |
parent | af107710457b4bd148c6e5ee7a336ed4961f5423 (diff) | |
download | ruby-7b77d46671685c837adc33b39ae0210e04cd8b24.tar.gz |
Decouple GC slot sizes from RVALUE
Add a new macro BASE_SLOT_SIZE that determines the slot size.
For Variable Width Allocation (compiled with USE_RVARGC=1), all slot
sizes are powers-of-2 multiples of BASE_SLOT_SIZE.
For USE_RVARGC=0, BASE_SLOT_SIZE is set to sizeof(RVALUE).
Diffstat (limited to 'test')
-rw-r--r-- | test/-ext-/string/test_capacity.rb | 9 | ||||
-rw-r--r-- | test/-ext-/string/test_set_len.rb | 8 | ||||
-rw-r--r-- | test/objspace/test_objspace.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_file_exhaustive.rb | 4 | ||||
-rw-r--r-- | test/ruby/test_gc.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_time.rb | 20 |
6 files changed, 25 insertions, 20 deletions
diff --git a/test/-ext-/string/test_capacity.rb b/test/-ext-/string/test_capacity.rb index 6b3172a46d..0cb7c00761 100644 --- a/test/-ext-/string/test_capacity.rb +++ b/test/-ext-/string/test_capacity.rb @@ -5,13 +5,14 @@ require 'rbconfig/sizeof' class Test_StringCapacity < Test::Unit::TestCase def test_capacity_embedded - assert_equal GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] - embed_header_size - 1, capa('foo') + assert_equal GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] - embed_header_size - 1, capa('foo') assert_equal max_embed_len, capa('1' * max_embed_len) assert_equal max_embed_len, capa('1' * (max_embed_len - 1)) end def test_capacity_shared - assert_equal 0, capa(:abcdefghijklmnopqrstuvwxyz.to_s) + sym = ("a" * GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE]).to_sym + assert_equal 0, capa(sym.to_s) end def test_capacity_normal @@ -46,13 +47,13 @@ class Test_StringCapacity < Test::Unit::TestCase def test_capacity_frozen s = String.new("I am testing", capacity: 1000) - s << "fstring capacity" + s << "a" * GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] s.freeze assert_equal(s.length, capa(s)) end def test_capacity_fstring - s = String.new("a" * max_embed_len, capacity: 1000) + s = String.new("a" * max_embed_len, capacity: max_embed_len * 3) s << "fstring capacity" s = -s assert_equal(s.length, capa(s)) diff --git a/test/-ext-/string/test_set_len.rb b/test/-ext-/string/test_set_len.rb index 5216e6195f..67ba961194 100644 --- a/test/-ext-/string/test_set_len.rb +++ b/test/-ext-/string/test_set_len.rb @@ -4,18 +4,20 @@ require "-test-/string" class Test_StrSetLen < Test::Unit::TestCase def setup - @s0 = [*"a".."z"].join("").freeze + # Make string long enough so that it is not embedded + @range_end = ("0".ord + GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE]).chr + @s0 = [*"0"..@range_end].join("").freeze @s1 = Bug::String.new(@s0) end def teardown - orig = [*"a".."z"].join("") + orig = [*"0"..@range_end].join("") assert_equal(orig, @s0) end def test_non_shared @s1.modify! - assert_equal("abc", @s1.set_len(3)) + assert_equal("012", @s1.set_len(3)) end def test_shared diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index a1954d56a9..b7342e899b 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -33,7 +33,7 @@ class TestObjSpace < Test::Unit::TestCase b = a.dup c = nil ObjectSpace.each_object(String) {|x| break c = x if x == a and x.frozen?} - rv_size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] + rv_size = GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] assert_equal([rv_size, rv_size, a.length + 1 + rv_size], [a, b, c].map {|x| ObjectSpace.memsize_of(x)}) end diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb index 2b274862c0..9ca991373e 100644 --- a/test/ruby/test_file_exhaustive.rb +++ b/test/ruby/test_file_exhaustive.rb @@ -872,9 +872,9 @@ class TestFileExhaustive < Test::Unit::TestCase bug9934 = '[ruby-core:63114] [Bug #9934]' require "objspace" path = File.expand_path("/foo") - assert_operator(ObjectSpace.memsize_of(path), :<=, path.bytesize + GC::INTERNAL_CONSTANTS[:RVALUE_SIZE], bug9934) + assert_operator(ObjectSpace.memsize_of(path), :<=, path.bytesize + GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE], bug9934) path = File.expand_path("/a"*25) - assert_equal(path.bytesize+1 + GC::INTERNAL_CONSTANTS[:RVALUE_SIZE], ObjectSpace.memsize_of(path), bug9934) + assert_equal(path.bytesize + 1 + GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE], ObjectSpace.memsize_of(path), bug9934) end def test_expand_path_encoding diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index 788f2974b5..fc49659c27 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -152,7 +152,7 @@ class TestGc < Test::Unit::TestCase GC.stat_heap(i, stat_heap) GC.stat(stat) - assert_equal GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] * (2**i), stat_heap[:slot_size] + assert_equal GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] * (2**i), stat_heap[:slot_size] assert_operator stat_heap[:heap_allocatable_pages], :<=, stat[:heap_allocatable_pages] assert_operator stat_heap[:heap_eden_pages], :<=, stat[:heap_eden_pages] assert_operator stat_heap[:heap_eden_slots], :>=, 0 diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index 445518ab57..8300681fe5 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -1312,15 +1312,17 @@ class TestTime < Test::Unit::TestCase omit "GC is in debug" if GC::INTERNAL_CONSTANTS[:DEBUG] require 'objspace' t = Time.at(0) - size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] - case size - when 20 then expect = 50 - when 24 then expect = 54 - when 40 then expect = 86 - when 48 then expect = 94 - else - flunk "Unsupported RVALUE_SIZE=#{size}, update test_memsize" - end + sizeof_timew = + if RbConfig::SIZEOF.key?("uint64_t") && RbConfig::SIZEOF["long"] * 2 <= RbConfig::SIZEOF["uint64_t"] + RbConfig::SIZEOF["uint64_t"] + else + RbConfig::SIZEOF["void*"] # Same size as VALUE + end + expect = + GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] + + sizeof_timew + + RbConfig::SIZEOF["void*"] * 4 + 5 + # vtm + 1 # tzmode, tm_got assert_equal expect, ObjectSpace.memsize_of(t) rescue LoadError => e omit "failed to load objspace: #{e.message}" |