Skip to content

ZJIT: Get ZJIT allocation fastpath to run in debug/dev builds - #18033

Merged
luke-gru merged 3 commits into
ruby:masterfrom
luke-gruber:zjit_fastpath_debug_mode
Aug 7, 2026
Merged

ZJIT: Get ZJIT allocation fastpath to run in debug/dev builds#18033
luke-gru merged 3 commits into
ruby:masterfrom
luke-gruber:zjit_fastpath_debug_mode

Conversation

@luke-gruber

Copy link
Copy Markdown
Contributor

This allows us to run the allocation fastpath code in CI and during make zjit-test when configured with --enable-zjit=dev.

@matzbot
matzbot requested a review from a team July 23, 2026 16:02
@luke-gruber
luke-gruber force-pushed the zjit_fastpath_debug_mode branch 2 times, most recently from 210d5f2 to b4fa098 Compare July 23, 2026 18:49
@luke-gru

luke-gru commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Getting this to work required fixing a couple of bugs with the way the ZJIT alloc fastpath worked. There was an issue with GC.stat(:total_allocated_objects) where it was never incremented in the fastpath. There was also an issue where NEWOBJ hooks were never firing. These bug fixes are included in this PR. There are no added tests because these 2 bugs were caught by failing tests that exist already.

@luke-gruber
luke-gruber force-pushed the zjit_fastpath_debug_mode branch from b4fa098 to 0e3992f Compare July 23, 2026 19:16
@luke-gru
luke-gru requested a review from peterzhu2118 July 23, 2026 20:02
Comment thread hash.c Outdated
Comment thread zjit/src/codegen/gc_fastpath.rs Outdated
Comment thread zjit/src/hir.rs
Comment thread zjit/src/codegen/gc_fastpath.rs Outdated
Comment thread zjit/src/codegen/gc_fastpath.rs Outdated
Comment thread gc/default/zjit_fastpath.h Outdated
@luke-gruber
luke-gruber force-pushed the zjit_fastpath_debug_mode branch 2 times, most recently from 7e0792f to 34b6ec6 Compare July 31, 2026 20:05
@luke-gruber

Copy link
Copy Markdown
Contributor Author

@k0kubun I've addressed your comments. Waiting for final review/approval 👍

Comment thread zjit.c Outdated
size_t
rb_zjit_offset_ractor_pub_id(void)
{
return offsetof(rb_ractor_t, pub) + offsetof(struct rb_ractor_pub, id);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add these offsets (and maybe for rb_zjit_offset_ractor_newobj_cache as well) as part enum zjit_struct_offsets instead? We shouldn't need to make C function calls for them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to wait until ractor-local GC lands to make these changes because it removes the newobj cache.

@k0kubun k0kubun linked an issue Aug 6, 2026 that may be closed by this pull request
@luke-gruber
luke-gruber force-pushed the zjit_fastpath_debug_mode branch 2 times, most recently from 66b6517 to 07bc3e3 Compare August 7, 2026 20:15
Comment thread zjit.c Outdated
}

size_t
rb_zjit_offset_ractor_pub_id(void)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use #18256 for offsetof(rb_ractor_t, pub) and offsetof(struct rb_ractor_pub, id) instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RLGC got rid of this. We now track if an object belongs to the current ractor by GET_HEAP_PAGE(obj)->objspace == rb_ec_ractor_ptr(ec)->objspace. This is still only done in debug builds. It used to be that there was only 1 object space so we had to add space at the end of the object for its ractor_id.

This also enables the alloc fastpath where it previously wasn't enabled
when `-DRUBY_DEBUG` is set in cflags during compilation. This will allow
us to test the ZJIT alloc fastpath in CI and when running ZJIT tests
locally in dev (--enable-zjit=dev) or debug mode (cflags="-DRUBY_DEBUG=1").
The allocation fastpath just advances the cursor and we don't want to
emit code that checks for this rare case. Emit a patchpoint instead and
invalidate the allocation fastpath code when NEWOBJ hooks are enabled
for the first time.
1) Remove copied code in gc_fastpath.rs

2) RbGcZjitDefaultNewObjFastpath and RbGcZjitMmtkNewObjFastpath structs were
copied from the cruby_bindings file.

3) Get MMTK to use the newobj hook patchpoint for ZJIT's alloc fastpath.
Previously only the default GC used this patchpoint. MMTK had to check if
newobj hooks were enabled in its fastpath, which it no longer does.

4) ractor_belonging_id has been removed
@luke-gruber
luke-gruber force-pushed the zjit_fastpath_debug_mode branch from 07bc3e3 to 18ac3f2 Compare August 7, 2026 21:28
@luke-gru
luke-gru merged commit e085306 into ruby:master Aug 7, 2026
117 of 118 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jit YJIT, ZJIT, ...

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZJIT: [BUG] inconsistent live slot number

5 participants