summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorMatt Valentine-House <matt@eightbitraptor.com>2022-06-09 15:59:08 +0100
committerPeter Zhu <peter@peterzhu.ca>2022-07-12 08:50:33 -0400
commit214ed4cbc6f33675230602dd09268b436da96f7d (patch)
tree0c1cd73729447e53136643b7975b39385ee7a711 /test/ruby
parent0f8a0c5f371b0886e8e31e35a9095bc9843de27c (diff)
[Feature #18901] Support size pool movement for Arrays
This commit enables Arrays to move between size pools during compaction. This can occur if the array is mutated such that it would fit in a different size pool when embedded. The move is carried out in two stages: 1. The RVALUE is moved to a destination heap during object movement phase of compaction 2. The array data is re-embedded and the original buffer free'd if required. This happens during the update references step
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6099
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_gc_compact.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb
index 3927958e9c..8ecb41438a 100644
--- a/test/ruby/test_gc_compact.rb
+++ b/test/ruby/test_gc_compact.rb
@@ -209,6 +209,46 @@ class TestGCCompact < Test::Unit::TestCase
assert_equal([:call, :line], results)
end
+ def test_moving_arrays_down_size_pools
+ omit if !GC.using_rvargc?
+ assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 10, signal: :SEGV)
+ begin;
+ ARY_COUNT = 500
+
+ GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ arys = ARY_COUNT.times.map do
+ ary = "abbbbbbbbbb".chars
+ ary.uniq!
+ end
+
+ stats = GC.verify_compaction_references(expand_heap: true, toward: :empty)
+ assert_operator(stats.dig(:moved_down, :T_ARRAY), :>=, ARY_COUNT)
+ assert(arys) # warning: assigned but unused variable - arys
+ end;
+ end
+
+ def test_moving_arrays_up_size_pools
+ omit if !GC.using_rvargc?
+ assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 10, signal: :SEGV)
+ begin;
+ ARY_COUNT = 500
+
+ GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ ary = "hello".chars
+ arys = ARY_COUNT.times.map do
+ x = []
+ ary.each { |e| x << e }
+ x
+ end
+
+ stats = GC.verify_compaction_references(expand_heap: true, toward: :empty)
+ assert_operator(stats.dig(:moved_up, :T_ARRAY), :>=, ARY_COUNT)
+ assert(arys) # warning: assigned but unused variable - arys
+ end;
+ end
+
def test_moving_strings_up_size_pools
assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 10, signal: :SEGV)
begin;