Skip to content

ZJIT: Write JITFrame pointer for C frames#957

Open
k0kubun wants to merge 6 commits intomasterfrom
zjit-lightweight-frames
Open

ZJIT: Write JITFrame pointer for C frames#957
k0kubun wants to merge 6 commits intomasterfrom
zjit-lightweight-frames

Conversation

@k0kubun
Copy link
Member

@k0kubun k0kubun commented Mar 24, 2026

Summary

  • Write a JITFrame pointer to cfp->jit_return for C frames instead of 0, eliminating 2 memory writes (cfp->iseq = 0 and cfp->block_code = 0) per C method call
  • Add rb_zjit_cfp_has_iseq() and rb_zjit_cfp_has_pc() helpers that check JITFrame first when present (since cfp->iseq and cfp->pc may be stale)
  • Replace all cfp->iseq || CFP_JIT_RETURN(cfp) and cfp->pc || CFP_JIT_RETURN(cfp) patterns with the new helpers

k0kubun and others added 6 commits March 23, 2026 17:52
Co-authored-by: Alan Wu <alanwu@ruby-lang.org>
Instead of calling rb_zjit_materialize_frames in every side exit's
generated code, call zjit_materialize_frames once in jit_exec() and
JIT_EXEC() after the ZJIT entry trampoline returns. This reduces
generated code size by removing a C function call from each unique
side exit.
Instead of writing 3 fields to C frames (jit_return=0, iseq=0,
block_code=0), write a single JITFrame pointer with {pc=NULL,
iseq=NULL, materialize_block_code=true}. This eliminates 2 memory
writes per C method call.

Add rb_zjit_cfp_has_iseq() and rb_zjit_cfp_has_pc() helpers that
check JITFrame first when present, since cfp->iseq and cfp->pc may
be stale for frames with JITFrame. Replace all cfp->iseq ||
CFP_JIT_RETURN(cfp) and cfp->pc || CFP_JIT_RETURN(cfp) patterns
with the new helpers.
When CFP_JIT_RETURN is true for a C frame (iseq is NULL in JITFrame),
block_code in the CFP is stale and must not be passed to
rb_gc_location during GC compaction. Only relocate iseq and
block_code for ISEQ frames with JITFrame.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant