Skip to content

Commit 4e5b0d3

Browse files
committed
ZJIT: Have JITFrame relocate itself via Rust function
Expose rb_zjit_jit_frame_update_references so vm.c can call into Rust to relocate the iseq pointer during GC compaction, instead of manually manipulating JITFrame fields in C. This keeps JITFrame field access consolidated in Rust.
1 parent bfcc31a commit 4e5b0d3

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

vm.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3672,11 +3672,7 @@ rb_execution_context_update(rb_execution_context_t *ec)
36723672
const VALUE *ep = cfp->ep;
36733673
cfp->self = rb_gc_location(cfp->self);
36743674
if (rb_zjit_enabled_p && CFP_HAS_JIT_RETURN(cfp)) {
3675-
zjit_jit_frame_t *jit_frame = (zjit_jit_frame_t *)cfp->jit_return;
3676-
if (jit_frame->iseq) {
3677-
// ISEQ frame with JITFrame: relocate iseq in JITFrame
3678-
jit_frame->iseq = (const rb_iseq_t *)rb_gc_location((VALUE)jit_frame->iseq);
3679-
}
3675+
rb_zjit_jit_frame_update_references((zjit_jit_frame_t *)cfp->jit_return);
36803676
// block_code must always be relocated. For ISEQ frames, the JIT caller
36813677
// may have written it (gen_block_handler_specval) for passing blocks.
36823678
// For C frames, rb_iterate0 may have written an ifunc to block_code

zjit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void rb_zjit_before_ractor_spawn(void);
4545
void rb_zjit_tracing_invalidate_all(void);
4646
void rb_zjit_invalidate_no_singleton_class(VALUE klass);
4747
void rb_zjit_invalidate_root_box(void);
48+
void rb_zjit_jit_frame_update_references(zjit_jit_frame_t *jit_frame);
4849
#else
4950
#define rb_zjit_entry 0
5051
static inline void rb_zjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception) {}
@@ -58,6 +59,7 @@ static inline void rb_zjit_before_ractor_spawn(void) {}
5859
static inline void rb_zjit_tracing_invalidate_all(void) {}
5960
static inline void rb_zjit_invalidate_no_singleton_class(VALUE klass) {}
6061
static inline void rb_zjit_invalidate_root_box(void) {}
62+
static inline void rb_zjit_jit_frame_update_references(zjit_jit_frame_t *jit_frame) {}
6163
#endif // #if USE_ZJIT
6264

6365
#define rb_zjit_enabled_p (rb_zjit_entry != 0)

zjit/src/jit_frame.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ impl JITFrame {
4343
}
4444
}
4545

46+
/// Update the iseq pointer in an on-stack JITFrame during GC compaction.
47+
/// Called from rb_execution_context_update in vm.c.
48+
#[unsafe(no_mangle)]
49+
pub extern "C" fn rb_zjit_jit_frame_update_references(jit_frame: *mut JITFrame) {
50+
unsafe { &mut *jit_frame }.update_references();
51+
}
52+
4653
#[cfg(test)]
4754
mod tests {
4855
use crate::cruby::{eval, inspect};

0 commit comments

Comments
 (0)