<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ruby.git/test/ruby/test_gc_compact.rb, branch v3_2_11</title>
<subtitle>The Ruby Programming Language</subtitle>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/'/>
<entry>
<title>Removed extra assertions for Ruby 3.2</title>
<updated>2024-11-21T23:06:01+00:00</updated>
<author>
<name>Hiroshi SHIBATA</name>
<email>hsbt@ruby-lang.org</email>
</author>
<published>2024-11-21T03:14:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=d3098d2068770f8bdeca8fda06736cbebb8d3a5b'/>
<id>d3098d2068770f8bdeca8fda06736cbebb8d3a5b</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix flaky "Expected 499 to be &gt;= 500" assertion in test_gc_compact.rb</title>
<updated>2024-11-21T23:06:01+00:00</updated>
<author>
<name>KJ Tsanaktsidis</name>
<email>kj@kjtsanaktsidis.id.au</email>
</author>
<published>2023-11-27T06:33:08+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=9e1a78059dc1c2bee1159f7626a15de689f4fc1c'/>
<id>9e1a78059dc1c2bee1159f7626a15de689f4fc1c</id>
<content type='text'>
There have been some sproradically flaky tests related to GC compaction,
which fail with:

  1) Failure:
TestGCCompact#test_moving_hashes_down_size_pools [/test/ruby/test_gc_compact.rb:442]:
Expected 499 to be &gt;= 500.

What's happening here, is that, _sometimes_, depending on very unlucky
combinations of machine things, one of the expected-to-be-moved hashes
might be found on the machine stack during GC, and thus pinned.

One factor which seems to make this _more_ likely is that GCC 11 on
Ubuntu 22.04 seems to want to allocate 440 bytes of stack space for
`gc_start`, which is much more than it actually uses on the common code
path. The result is that there are some 50-odd VALUE-sized cells "live"
on the stack which may well contain valid heap pointers from previous
function calls, and will need to be pinned.

This is, of course, totally normal and expected; Ruby's GC is
conservative and if there is the possibility that a VALUE might be live
on the machine stack, it can't be moved. However, it does make these
tests flaky.

This commit "fixes" the tests by performing the work in a fiber; the
fiber goes out of scope and should be collected by the call to
verify_compaction_references, so there should be no references to the
to-be-moved objects floating around on the machine stack.

Fixes [#20021]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
There have been some sproradically flaky tests related to GC compaction,
which fail with:

  1) Failure:
TestGCCompact#test_moving_hashes_down_size_pools [/test/ruby/test_gc_compact.rb:442]:
Expected 499 to be &gt;= 500.

What's happening here, is that, _sometimes_, depending on very unlucky
combinations of machine things, one of the expected-to-be-moved hashes
might be found on the machine stack during GC, and thus pinned.

One factor which seems to make this _more_ likely is that GCC 11 on
Ubuntu 22.04 seems to want to allocate 440 bytes of stack space for
`gc_start`, which is much more than it actually uses on the common code
path. The result is that there are some 50-odd VALUE-sized cells "live"
on the stack which may well contain valid heap pointers from previous
function calls, and will need to be pinned.

This is, of course, totally normal and expected; Ruby's GC is
conservative and if there is the possibility that a VALUE might be live
on the machine stack, it can't be moved. However, it does make these
tests flaky.

This commit "fixes" the tests by performing the work in a fiber; the
fiber goes out of scope and should be collected by the call to
verify_compaction_references, so there should be no references to the
to-be-moved objects floating around on the machine stack.

Fixes [#20021]
</pre>
</div>
</content>
</entry>
<entry>
<title>Assert that at least one element has been embedded</title>
<updated>2024-11-21T23:06:01+00:00</updated>
<author>
<name>Peter Zhu</name>
<email>peter@peterzhu.ca</email>
</author>
<published>2023-07-31T14:26:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=9aa313f2f8ce2a437fe027a5d757f957b9aad5c8'/>
<id>9aa313f2f8ce2a437fe027a5d757f957b9aad5c8</id>
<content type='text'>
It's not guaranteed that the first element will always be embedded.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
It's not guaranteed that the first element will always be embedded.
</pre>
</div>
</content>
</entry>
<entry>
<title>Assert that resizing arrays will re-embed them</title>
<updated>2024-11-21T23:06:01+00:00</updated>
<author>
<name>Peter Zhu</name>
<email>peter@peterzhu.ca</email>
</author>
<published>2023-01-06T14:14:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=c692229197af9088538dfd8c1234807867326e35'/>
<id>c692229197af9088538dfd8c1234807867326e35</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Assert that resizing objects will re-embed them</title>
<updated>2024-11-21T23:06:01+00:00</updated>
<author>
<name>Peter Zhu</name>
<email>peter@peterzhu.ca</email>
</author>
<published>2023-01-06T14:11:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=605592b9becf55dab7fd00adfc9f10b9e4fa58b8'/>
<id>605592b9becf55dab7fd00adfc9f10b9e4fa58b8</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix Error in GC Compaction specs</title>
<updated>2024-11-21T23:06:01+00:00</updated>
<author>
<name>Matt Valentine-House</name>
<email>matt@eightbitraptor.com</email>
</author>
<published>2022-12-21T15:48:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=ed41225edd5e5488db13785aac7180e613c07915'/>
<id>ed41225edd5e5488db13785aac7180e613c07915</id>
<content type='text'>
Previously if any of the tests that move objects between size pools
failed to move anything, then the call to stats.dig would return `nil`
which would then cause assert_operator to error.

This should be a test Failure, rather than an Error so this commit uses
a default value of 0 if stats.dig fails to find a key.

Also refactor object movement tests to use stats.dig, rather than :[]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Previously if any of the tests that move objects between size pools
failed to move anything, then the call to stats.dig would return `nil`
which would then cause assert_operator to error.

This should be a test Failure, rather than an Error so this commit uses
a default value of 0 if stats.dig fails to find a key.

Also refactor object movement tests to use stats.dig, rather than :[]
</pre>
</div>
</content>
</entry>
<entry>
<title>merge revision(s) cb22d78354e201ca74eba68a8b4edefb593e6754: [Backport #19536]</title>
<updated>2023-03-22T23:11:23+00:00</updated>
<author>
<name>NARUSE, Yui</name>
<email>naruse@airemix.jp</email>
</author>
<published>2023-03-22T23:11:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=400ccb16eefe4e21c4e3eacab4fd0f208fc5e151'/>
<id>400ccb16eefe4e21c4e3eacab4fd0f208fc5e151</id>
<content type='text'>
	Fix frozen status loss when moving objects

	[Bug #19536]

	When objects are moved between size pools, their frozen status is lost
	in the shape. This will cause the frozen check to be bypassed when there
	is an inline cache. For example, the following script should raise a
	FrozenError, but doesn't on Ruby 3.2 and master.

	    class A
	      def add_ivars
	        @a = @b = @c = @d = 1
	      end

	      def set_a
	        @a = 10
	      end
	    end

	    a = A.new
	    a.add_ivars
	    a.freeze

	    b = A.new
	    b.add_ivars
	    b.set_a # Set the inline cache in set_a

	    GC.verify_compaction_references(expand_heap: true, toward: :empty)

	    a.set_a
	---
	 shape.c                      |  2 +-
	 test/ruby/test_gc_compact.rb | 28 ++++++++++++++++++++++++++++
	 2 files changed, 29 insertions(+), 1 deletion(-)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	Fix frozen status loss when moving objects

	[Bug #19536]

	When objects are moved between size pools, their frozen status is lost
	in the shape. This will cause the frozen check to be bypassed when there
	is an inline cache. For example, the following script should raise a
	FrozenError, but doesn't on Ruby 3.2 and master.

	    class A
	      def add_ivars
	        @a = @b = @c = @d = 1
	      end

	      def set_a
	        @a = 10
	      end
	    end

	    a = A.new
	    a.add_ivars
	    a.freeze

	    b = A.new
	    b.add_ivars
	    b.set_a # Set the inline cache in set_a

	    GC.verify_compaction_references(expand_heap: true, toward: :empty)

	    a.set_a
	---
	 shape.c                      |  2 +-
	 test/ruby/test_gc_compact.rb | 28 ++++++++++++++++++++++++++++
	 2 files changed, 29 insertions(+), 1 deletion(-)
</pre>
</div>
</content>
</entry>
<entry>
<title>merge revision(s) 3be2acfafd3b3c6168e2266c7c6561d143d7ae5c: [Backport #19327]</title>
<updated>2023-01-19T12:52:47+00:00</updated>
<author>
<name>NARUSE, Yui</name>
<email>naruse@airemix.jp</email>
</author>
<published>2023-01-19T12:52:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=6a8fcb50210f8414d76968298576e39b9fa82562'/>
<id>6a8fcb50210f8414d76968298576e39b9fa82562</id>
<content type='text'>
	Fix re-embedding of strings during compaction

	The reference updating code for strings is not re-embedding strings
	because the code is incorrectly wrapped inside of a
	`if (STR_SHARED_P(obj))` clause. Shared strings can't be re-embedded
	so this ends up being a no-op. This means that strings can be moved to a
	large size pool during compaction, but won't be re-embedded, which would
	waste the space.
	---
	 gc.c                         | 16 +++++++++-------
	 string.c                     | 12 ++++++++----
	 test/ruby/test_gc_compact.rb |  8 ++++----
	 3 files changed, 21 insertions(+), 15 deletions(-)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	Fix re-embedding of strings during compaction

	The reference updating code for strings is not re-embedding strings
	because the code is incorrectly wrapped inside of a
	`if (STR_SHARED_P(obj))` clause. Shared strings can't be re-embedded
	so this ends up being a no-op. This means that strings can be moved to a
	large size pool during compaction, but won't be re-embedded, which would
	waste the space.
	---
	 gc.c                         | 16 +++++++++-------
	 string.c                     | 12 ++++++++----
	 test/ruby/test_gc_compact.rb |  8 ++++----
	 3 files changed, 21 insertions(+), 15 deletions(-)
</pre>
</div>
</content>
</entry>
<entry>
<title>Add tests for compacting shared arrays</title>
<updated>2022-12-23T16:21:14+00:00</updated>
<author>
<name>Peter Zhu</name>
<email>peter@peterzhu.ca</email>
</author>
<published>2022-12-23T14:42:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=1876cda972ea226ee85faf14dae6d047e145a4c6'/>
<id>1876cda972ea226ee85faf14dae6d047e145a4c6</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Don't allow re-embedding frozen arrays</title>
<updated>2022-12-23T16:21:14+00:00</updated>
<author>
<name>Peter Zhu</name>
<email>peter@peterzhu.ca</email>
</author>
<published>2022-12-23T14:33:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=7891f9407184ca6b4636092555d2546e3830c2ff'/>
<id>7891f9407184ca6b4636092555d2546e3830c2ff</id>
<content type='text'>
Frozen arrays should not move from heap allocated to embedded because
frozen arrays could be shared roots for other (shared) arrays. If the
frozen array moves from heap allocated to embedded it would cause issues
since the shared array would no longer know where to set the pointer
in the shared root.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Frozen arrays should not move from heap allocated to embedded because
frozen arrays could be shared roots for other (shared) arrays. If the
frozen array moves from heap allocated to embedded it would cause issues
since the shared array would no longer know where to set the pointer
in the shared root.
</pre>
</div>
</content>
</entry>
</feed>
