<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/ruby.git/yjit, branch ruby_3_2</title>
<subtitle>github.com: ruby/ruby.git
</subtitle>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby.git/'/>
<entry>
<title>merge revision(s) 0eb634ae73cb327ede833b72492f912792a4a9d5: [Backport #19464]</title>
<updated>2023-03-15T07:36:32+00:00</updated>
<author>
<name>NARUSE, Yui</name>
<email>naruse@airemix.jp</email>
</author>
<published>2023-03-15T07:36:32+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby.git/commit/?id=b73a07359758a9034996752e981e09ddaffe8d87'/>
<id>b73a07359758a9034996752e981e09ddaffe8d87</id>
<content type='text'>
	YJIT: Detect and reject `send(:alias_for_send, :foo)`

	Previously, YJIT failed to put the stack into the correct shape when
	`BasicObject#send` calls an alias method for the send method itself.
	This can manifest as strange `NoMethodError`s in the final non-send
	receiver, as [seen][1] with the kt-paperclip gem. I also found a case
	where it makes YJIT fail the stack size assertion while compiling
	`leave`.

	YJIT's `BasicObject#__send__` implementation already rejects sends to
	`send`, but didn't detect sends to aliases of `send`. Adjust the
	detection and reject these cases.

	Fixes [Bug #19464]

	[1]: https://github.com/Shopify/yjit/issues/306
	---
	 test/ruby/test_yjit.rb | 20 ++++++++++++++++++++
	 yjit/src/codegen.rs    | 25 ++++++++++---------------
	 2 files changed, 30 insertions(+), 15 deletions(-)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	YJIT: Detect and reject `send(:alias_for_send, :foo)`

	Previously, YJIT failed to put the stack into the correct shape when
	`BasicObject#send` calls an alias method for the send method itself.
	This can manifest as strange `NoMethodError`s in the final non-send
	receiver, as [seen][1] with the kt-paperclip gem. I also found a case
	where it makes YJIT fail the stack size assertion while compiling
	`leave`.

	YJIT's `BasicObject#__send__` implementation already rejects sends to
	`send`, but didn't detect sends to aliases of `send`. Adjust the
	detection and reject these cases.

	Fixes [Bug #19464]

	[1]: https://github.com/Shopify/yjit/issues/306
	---
	 test/ruby/test_yjit.rb | 20 ++++++++++++++++++++
	 yjit/src/codegen.rs    | 25 ++++++++++---------------
	 2 files changed, 30 insertions(+), 15 deletions(-)
</pre>
</div>
</content>
</entry>
<entry>
<title>merge revision(s) c178926fbe879045fa711444a1fd9e906af23e3b,a4b7ec12298c78392797e5ba7704076550e4f100: [Backport #19444]</title>
<updated>2023-03-07T10:48:32+00:00</updated>
<author>
<name>NARUSE, Yui</name>
<email>naruse@airemix.jp</email>
</author>
<published>2023-03-07T10:48:32+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby.git/commit/?id=4d75035e1762a23d38c5192b30bb47f40b752bee'/>
<id>4d75035e1762a23d38c5192b30bb47f40b752bee</id>
<content type='text'>
	YJIT: jit_prepare_routine_call() for String#+@ missing

	We saw SEGVs due to this when running with StackProf, which needs a
	correct PC for RUBY_INTERNAL_EVENT_NEWOBJ, the same event used for
	ObjectSpace allocation tracing.

	[Bug #19444]
	---
	 test/ruby/test_yjit.rb | 27 +++++++++++++++++++++++++++
	 yjit/src/codegen.rs    |  5 ++++-
	 2 files changed, 31 insertions(+), 1 deletion(-)

	YJIT: Fix false assumption that String#+@ =&gt; ::String

	Could return a subclass.

	[Bug #19444]
	---
	 test/ruby/test_yjit.rb | 17 +++++++++++++++++
	 yjit/src/codegen.rs    | 10 +++++++---
	 2 files changed, 24 insertions(+), 3 deletions(-)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	YJIT: jit_prepare_routine_call() for String#+@ missing

	We saw SEGVs due to this when running with StackProf, which needs a
	correct PC for RUBY_INTERNAL_EVENT_NEWOBJ, the same event used for
	ObjectSpace allocation tracing.

	[Bug #19444]
	---
	 test/ruby/test_yjit.rb | 27 +++++++++++++++++++++++++++
	 yjit/src/codegen.rs    |  5 ++++-
	 2 files changed, 31 insertions(+), 1 deletion(-)

	YJIT: Fix false assumption that String#+@ =&gt; ::String

	Could return a subclass.

	[Bug #19444]
	---
	 test/ruby/test_yjit.rb | 17 +++++++++++++++++
	 yjit/src/codegen.rs    | 10 +++++++---
	 2 files changed, 24 insertions(+), 3 deletions(-)
</pre>
</div>
</content>
</entry>
<entry>
<title>merge revision(s) b78f871d838c168789648738e5c67b071beb8a19,ecd0cdaf820af789f355f1a18c31d6adfe8aad94: [Backport #19400]</title>
<updated>2023-03-04T06:39:47+00:00</updated>
<author>
<name>NARUSE, Yui</name>
<email>naruse@airemix.jp</email>
</author>
<published>2023-03-04T06:39:47+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby.git/commit/?id=f93c7b9f58966fd04496bfeb2538fb1ff41f788e'/>
<id>f93c7b9f58966fd04496bfeb2538fb1ff41f788e</id>
<content type='text'>
	YJIT: Use the system page size when the code page size is too small
	 (#7267)

	Previously on ARM64 Linux systems that use 64 KiB pages
	(`CONFIG_ARM64_64K_PAGES=y`), YJIT was panicking on boot due to a failed
	assertion.

	The assertion was making sure that code GC can free the last code page
	that YJIT manages without freeing unrelated memory. YJIT prefers picking
	16 KiB as the granularity at which to free code memory, but when the
	system can only free at 64 KiB granularity, that is not possible.

	The fix is to use the system page size as the code page size when the
	system page size is 64 KiB. Continue to use 16 KiB as the code page size
	on common systems that use 16/4 KiB pages.

	Add asserts to code_gc() and free_page() about code GC's assumptions.

	Fixes [Bug #19400]
	---
	 yjit/src/asm/mod.rs    | 78 ++++++++++++++++++++++++++++++++------------------
	 yjit/src/codegen.rs    |  2 --
	 yjit/src/virtualmem.rs | 13 +++++++++
	 3 files changed, 63 insertions(+), 30 deletions(-)

	YJIT: Fix assertion for partially mapped last pages (#7337)

	Follows up [Bug #19400]
	---
	 test/ruby/test_yjit.rb | 19 +++++++++++++++++++
	 yjit/src/asm/mod.rs    |  2 +-
	 yjit/src/virtualmem.rs | 18 +++++++++++++-----
	 3 files changed, 33 insertions(+), 6 deletions(-)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	YJIT: Use the system page size when the code page size is too small
	 (#7267)

	Previously on ARM64 Linux systems that use 64 KiB pages
	(`CONFIG_ARM64_64K_PAGES=y`), YJIT was panicking on boot due to a failed
	assertion.

	The assertion was making sure that code GC can free the last code page
	that YJIT manages without freeing unrelated memory. YJIT prefers picking
	16 KiB as the granularity at which to free code memory, but when the
	system can only free at 64 KiB granularity, that is not possible.

	The fix is to use the system page size as the code page size when the
	system page size is 64 KiB. Continue to use 16 KiB as the code page size
	on common systems that use 16/4 KiB pages.

	Add asserts to code_gc() and free_page() about code GC's assumptions.

	Fixes [Bug #19400]
	---
	 yjit/src/asm/mod.rs    | 78 ++++++++++++++++++++++++++++++++------------------
	 yjit/src/codegen.rs    |  2 --
	 yjit/src/virtualmem.rs | 13 +++++++++
	 3 files changed, 63 insertions(+), 30 deletions(-)

	YJIT: Fix assertion for partially mapped last pages (#7337)

	Follows up [Bug #19400]
	---
	 test/ruby/test_yjit.rb | 19 +++++++++++++++++++
	 yjit/src/asm/mod.rs    |  2 +-
	 yjit/src/virtualmem.rs | 18 +++++++++++++-----
	 3 files changed, 33 insertions(+), 6 deletions(-)
</pre>
</div>
</content>
</entry>
<entry>
<title>merge revision(s) 3b83b265f11965582d4b9b439eff8a501792ab68: [Backport #19404]</title>
<updated>2023-02-06T05:00:47+00:00</updated>
<author>
<name>NARUSE, Yui</name>
<email>naruse@airemix.jp</email>
</author>
<published>2023-02-06T05:00:47+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby.git/commit/?id=3a88589399f7f1059be245f766809c49790ad939'/>
<id>3a88589399f7f1059be245f766809c49790ad939</id>
<content type='text'>
	YJIT: Crash with rb_bug() when panicking

	Helps with getting good bug reports in the wild. Intended to be
	backported to the 3.2.x series.
	---
	 yjit/bindgen/src/main.rs       |  3 +++
	 yjit/src/cruby_bindings.inc.rs |  1 +
	 yjit/src/yjit.rs               | 29 +++++++++++++++++++++++++++--
	 3 files changed, 31 insertions(+), 2 deletions(-)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	YJIT: Crash with rb_bug() when panicking

	Helps with getting good bug reports in the wild. Intended to be
	backported to the 3.2.x series.
	---
	 yjit/bindgen/src/main.rs       |  3 +++
	 yjit/src/cruby_bindings.inc.rs |  1 +
	 yjit/src/yjit.rs               | 29 +++++++++++++++++++++++++++--
	 3 files changed, 31 insertions(+), 2 deletions(-)
</pre>
</div>
</content>
</entry>
<entry>
<title>merge revision(s) 188688a53e7708d25ab80e14d05e70ffcf792e13: [Backport #19385]</title>
<updated>2023-02-03T05:13:09+00:00</updated>
<author>
<name>NARUSE, Yui</name>
<email>naruse@airemix.jp</email>
</author>
<published>2023-02-03T05:13:02+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby.git/commit/?id=535d863f34e6c36a2378683e7c2d3b7369e3d076'/>
<id>535d863f34e6c36a2378683e7c2d3b7369e3d076</id>
<content type='text'>
	[PATCH 1/4] YJIT: Move CodegenGlobals::freed_pages into an Rc

	This allows for supplying a freed_pages vec in Rust tests. We need it so we
	can test scenarios that occur after code GC.
	---
	 yjit/src/asm/mod.rs | 48 +++++++++++++++++++++++++++++++++------------
	 yjit/src/codegen.rs | 16 ++++-----------
	 2 files changed, 39 insertions(+), 25 deletions(-)

	Subject: [PATCH 2/4] YJIT: other_cb is None in tests

	Since the other cb is in CodegenGlobals, and we want Rust tests to be
	self-contained.
	---
	 yjit/src/asm/mod.rs | 1 +
	 1 file changed, 1 insertion(+)

	Subject: [PATCH 3/4] YJIT: ARM64: Move functions out of arm64_emit()

	---
	 yjit/src/backend/arm64/mod.rs | 180 +++++++++++++++++-----------------
	 1 file changed, 90 insertions(+), 90 deletions(-)

	Subject: [PATCH 4/4] YJIT: ARM64: Fix long jumps to labels

	Previously, with Code GC, YJIT panicked while trying to emit a B.cond
	instruction with an offset that is not encodable in 19 bits. This only
	happens when the code in an assembler instance straddles two pages.

	To fix this, when we detect that a jump to a label can land on a
	different page, we switch to a fresh new page and regenerate all the
	code in the assembler there. We still assume that no one assembler has
	so much code that it wouldn't fit inside a fresh new page.

	[Bug #19385]
	---
	 yjit/src/backend/arm64/mod.rs | 65 ++++++++++++++++++++++++++++++++---
	 1 file changed, 60 insertions(+), 5 deletions(-)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	[PATCH 1/4] YJIT: Move CodegenGlobals::freed_pages into an Rc

	This allows for supplying a freed_pages vec in Rust tests. We need it so we
	can test scenarios that occur after code GC.
	---
	 yjit/src/asm/mod.rs | 48 +++++++++++++++++++++++++++++++++------------
	 yjit/src/codegen.rs | 16 ++++-----------
	 2 files changed, 39 insertions(+), 25 deletions(-)

	Subject: [PATCH 2/4] YJIT: other_cb is None in tests

	Since the other cb is in CodegenGlobals, and we want Rust tests to be
	self-contained.
	---
	 yjit/src/asm/mod.rs | 1 +
	 1 file changed, 1 insertion(+)

	Subject: [PATCH 3/4] YJIT: ARM64: Move functions out of arm64_emit()

	---
	 yjit/src/backend/arm64/mod.rs | 180 +++++++++++++++++-----------------
	 1 file changed, 90 insertions(+), 90 deletions(-)

	Subject: [PATCH 4/4] YJIT: ARM64: Fix long jumps to labels

	Previously, with Code GC, YJIT panicked while trying to emit a B.cond
	instruction with an offset that is not encodable in 19 bits. This only
	happens when the code in an assembler instance straddles two pages.

	To fix this, when we detect that a jump to a label can land on a
	different page, we switch to a fresh new page and regenerate all the
	code in the assembler there. We still assume that no one assembler has
	so much code that it wouldn't fit inside a fresh new page.

	[Bug #19385]
	---
	 yjit/src/backend/arm64/mod.rs | 65 ++++++++++++++++++++++++++++++++---
	 1 file changed, 60 insertions(+), 5 deletions(-)
</pre>
</div>
</content>
</entry>
<entry>
<title>merge revision(s) aeddc19340c7116d48fac3080553fbb823857d16: [Backport #19316]</title>
<updated>2023-01-18T09:56:51+00:00</updated>
<author>
<name>NARUSE, Yui</name>
<email>naruse@airemix.jp</email>
</author>
<published>2023-01-18T09:56:51+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby.git/commit/?id=1fb5eb5740d4c4f1fc34a4a50bc0482eac27b545'/>
<id>1fb5eb5740d4c4f1fc34a4a50bc0482eac27b545</id>
<content type='text'>
	YJIT: Save PC and SP before calling leaf builtins (#7090)

	Previously, we did not update `cfp-&gt;sp` before calling the C function of
	ISEQs marked with `Primitive.attr! "inline"` (leaf builtins). This
	caused the GC to miss temporary values on the stack in case the function
	allocates and triggers a GC run. Right now, there is only a few leaf
	builtins in numeric.rb on Integer methods such as `Integer#~`. Since
	these methods only allocate when operating on big numbers, we missed
	this issue.

	Fix by saving PC and SP before calling the functions -- our usual
	protocol for calling C functions that may allocate on the GC heap.

	[Bug #19316]
	---
	 test/ruby/test_yjit.rb | 16 ++++++++++++++++
	 yjit/src/codegen.rs    |  4 ++++
	 2 files changed, 20 insertions(+)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	YJIT: Save PC and SP before calling leaf builtins (#7090)

	Previously, we did not update `cfp-&gt;sp` before calling the C function of
	ISEQs marked with `Primitive.attr! "inline"` (leaf builtins). This
	caused the GC to miss temporary values on the stack in case the function
	allocates and triggers a GC run. Right now, there is only a few leaf
	builtins in numeric.rb on Integer methods such as `Integer#~`. Since
	these methods only allocate when operating on big numbers, we missed
	this issue.

	Fix by saving PC and SP before calling the functions -- our usual
	protocol for calling C functions that may allocate on the GC heap.

	[Bug #19316]
	---
	 test/ruby/test_yjit.rb | 16 ++++++++++++++++
	 yjit/src/codegen.rs    |  4 ++++
	 2 files changed, 20 insertions(+)
</pre>
</div>
</content>
</entry>
<entry>
<title>merge revision(s) 43ff0c2c488c80aaf83b486d45bcd4a92ebe3848: [Backport #19299]</title>
<updated>2023-01-18T08:18:44+00:00</updated>
<author>
<name>NARUSE, Yui</name>
<email>naruse@airemix.jp</email>
</author>
<published>2023-01-18T08:18:44+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby.git/commit/?id=97c32b49e2fe4de8b57ce05146e63b2aa64c7a44'/>
<id>97c32b49e2fe4de8b57ce05146e63b2aa64c7a44</id>
<content type='text'>
	YJIT: Fix `yield` into block with &gt;=30 locals on ARM

	It's a register spill issue. Fix by moving the Qnil fill snippet to
	after registers are released.

	[Bug #19299]
	---
	 test/ruby/test_yjit.rb | 14 ++++++++++++++
	 yjit/src/codegen.rs    | 29 ++++++++++++++---------------
	 2 files changed, 28 insertions(+), 15 deletions(-)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	YJIT: Fix `yield` into block with &gt;=30 locals on ARM

	It's a register spill issue. Fix by moving the Qnil fill snippet to
	after registers are released.

	[Bug #19299]
	---
	 test/ruby/test_yjit.rb | 14 ++++++++++++++
	 yjit/src/codegen.rs    | 29 ++++++++++++++---------------
	 2 files changed, 28 insertions(+), 15 deletions(-)
</pre>
</div>
</content>
</entry>
<entry>
<title>MJIT: Export fewer shape functions (#7007)</title>
<updated>2022-12-23T18:18:57+00:00</updated>
<author>
<name>Takashi Kokubun</name>
<email>takashikkbn@gmail.com</email>
</author>
<published>2022-12-23T18:18:57+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby.git/commit/?id=1d3bfd804cdba027ab9ec79678692b607c43b798'/>
<id>1d3bfd804cdba027ab9ec79678692b607c43b798</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Use a BOP for Hash#default</title>
<updated>2022-12-17T22:51:49+00:00</updated>
<author>
<name>John Hawthorn</name>
<email>john@hawthorn.email</email>
</author>
<published>2022-12-15T18:46:24+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby.git/commit/?id=fbaa5db44a3b0622e2755fd00e0519a603aa9bcb'/>
<id>fbaa5db44a3b0622e2755fd00e0519a603aa9bcb</id>
<content type='text'>
On a hash miss we need to call default if it is redefined in order to
return the default value to be used. Previously we checked this with
rb_method_basic_definition_p, which avoids the method call but requires
a method lookup.

This commit replaces the previous check with BASIC_OP_UNREDEFINED_P and
a new BOP_DEFAULT. We still need to fall back to
rb_method_basic_definition_p when called on a subclasss of hash.

    |                |compare-ruby|built-ruby|
    |:---------------|-----------:|---------:|
    |hash_aref_miss  |       2.692|     3.531|
    |                |           -|     1.31x|

Co-authored-by: Daniel Colson &lt;danieljamescolson@gmail.com&gt;
Co-authored-by: "Ian C. Anderson" &lt;ian@iancanderson.com&gt;
Co-authored-by: Jack McCracken &lt;me@jackmc.xyz&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
On a hash miss we need to call default if it is redefined in order to
return the default value to be used. Previously we checked this with
rb_method_basic_definition_p, which avoids the method call but requires
a method lookup.

This commit replaces the previous check with BASIC_OP_UNREDEFINED_P and
a new BOP_DEFAULT. We still need to fall back to
rb_method_basic_definition_p when called on a subclasss of hash.

    |                |compare-ruby|built-ruby|
    |:---------------|-----------:|---------:|
    |hash_aref_miss  |       2.692|     3.531|
    |                |           -|     1.31x|

Co-authored-by: Daniel Colson &lt;danieljamescolson@gmail.com&gt;
Co-authored-by: "Ian C. Anderson" &lt;ian@iancanderson.com&gt;
Co-authored-by: Jack McCracken &lt;me@jackmc.xyz&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>YJIT: Fix `obj.send(:call)`</title>
<updated>2022-12-15T23:10:28+00:00</updated>
<author>
<name>Alan Wu</name>
<email>XrXr@users.noreply.github.com</email>
</author>
<published>2022-12-15T23:10:28+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/ruby.git/commit/?id=14158f1f8c50069f076f99e08405c5006ca65df9'/>
<id>14158f1f8c50069f076f99e08405c5006ca65df9</id>
<content type='text'>
All the method call types need to handle argument shifting in case they're
called by `.send`, and we weren't handling that in `OPTIMIZED_METHOD_TYPE_CALL`.

Lack of shifting caused the stack size assertion in gen_leave() to fail.

Discovered by Rails CI: https://buildkite.com/rails/rails/builds/91705#018516c4-f8f8-469e-bc2d-ddeb25ca8317/1920-2067
Diagnosed with help from `@eileencodes` and `@k0kubun`.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
All the method call types need to handle argument shifting in case they're
called by `.send`, and we weren't handling that in `OPTIMIZED_METHOD_TYPE_CALL`.

Lack of shifting caused the stack size assertion in gen_leave() to fail.

Discovered by Rails CI: https://buildkite.com/rails/rails/builds/91705#018516c4-f8f8-469e-bc2d-ddeb25ca8317/1920-2067
Diagnosed with help from `@eileencodes` and `@k0kubun`.</pre>
</div>
</content>
</entry>
</feed>
