diff --git a/jit.c b/jit.c index b24da7d8fe..a5e90f29fd 100644 --- a/jit.c +++ b/jit.c @@ -473,3 +473,14 @@ rb_jit_multi_ractor_p(void) { return rb_multi_ractor_p(); } + +// Acquire the VM lock and then signal all other Ruby threads (ractors) to +// contend for the VM lock, putting them to sleep. ZJIT and YJIT use this to +// evict threads running inside generated code so among other things, it can +// safely change memory protection of regions housing generated code. +void +rb_jit_vm_lock_then_barrier(unsigned int *recursive_lock_level, const char *file, int line) +{ + rb_vm_lock_enter(recursive_lock_level, file, line); + rb_vm_barrier(); +} diff --git a/yjit.c b/yjit.c index ee78d12e11..8c94b59dbf 100644 --- a/yjit.c +++ b/yjit.c @@ -686,17 +686,6 @@ rb_yjit_obj_written(VALUE old, VALUE young, const char *file, int line) rb_obj_written(old, Qundef, young, file, line); } -// Acquire the VM lock and then signal all other Ruby threads (ractors) to -// contend for the VM lock, putting them to sleep. YJIT uses this to evict -// threads running inside generated code so among other things, it can -// safely change memory protection of regions housing generated code. -void -rb_yjit_vm_lock_then_barrier(unsigned int *recursive_lock_level, const char *file, int line) -{ - rb_vm_lock_enter(recursive_lock_level, file, line); - rb_vm_barrier(); -} - // Release the VM lock. The lock level must point to the same integer used to // acquire the lock. void diff --git a/yjit/bindgen/src/main.rs b/yjit/bindgen/src/main.rs index 371a37ae0c..543f9992d6 100644 --- a/yjit/bindgen/src/main.rs +++ b/yjit/bindgen/src/main.rs @@ -328,7 +328,6 @@ fn main() { .allowlist_function("rb_set_cfp_(pc|sp)") .allowlist_function("rb_c_method_tracing_currently_enabled") .allowlist_function("rb_full_cfunc_return") - .allowlist_function("rb_yjit_vm_lock_then_barrier") .allowlist_function("rb_yjit_vm_unlock") .allowlist_function("rb_assert_(iseq|cme)_handle") .allowlist_function("rb_IMEMO_TYPE_P") @@ -355,6 +354,7 @@ fn main() { .allowlist_function("rb_assert_holding_vm_lock") .allowlist_function("rb_jit_shape_too_complex_p") .allowlist_function("rb_jit_multi_ractor_p") + .allowlist_function("rb_jit_vm_lock_then_barrier") .allowlist_type("robject_offsets") // from vm_sync.h diff --git a/yjit/src/cruby.rs b/yjit/src/cruby.rs index 38d931b8ae..493a92bff5 100644 --- a/yjit/src/cruby.rs +++ b/yjit/src/cruby.rs @@ -677,7 +677,7 @@ where let line = loc.line; let mut recursive_lock_level: c_uint = 0; - unsafe { rb_yjit_vm_lock_then_barrier(&mut recursive_lock_level, file, line) }; + unsafe { rb_jit_vm_lock_then_barrier(&mut recursive_lock_level, file, line) }; let ret = match catch_unwind(func) { Ok(result) => result, diff --git a/yjit/src/cruby_bindings.inc.rs b/yjit/src/cruby_bindings.inc.rs index 32a38135ec..f7971310f3 100644 --- a/yjit/src/cruby_bindings.inc.rs +++ b/yjit/src/cruby_bindings.inc.rs @@ -1226,11 +1226,6 @@ extern "C" { file: *const ::std::os::raw::c_char, line: ::std::os::raw::c_int, ); - pub fn rb_yjit_vm_lock_then_barrier( - recursive_lock_level: *mut ::std::os::raw::c_uint, - file: *const ::std::os::raw::c_char, - line: ::std::os::raw::c_int, - ); pub fn rb_yjit_vm_unlock( recursive_lock_level: *mut ::std::os::raw::c_uint, file: *const ::std::os::raw::c_char, @@ -1328,4 +1323,9 @@ extern "C" { pub fn rb_set_cfp_sp(cfp: *mut rb_control_frame_struct, sp: *mut VALUE); pub fn rb_jit_shape_too_complex_p(shape_id: shape_id_t) -> bool; pub fn rb_jit_multi_ractor_p() -> bool; + pub fn rb_jit_vm_lock_then_barrier( + recursive_lock_level: *mut ::std::os::raw::c_uint, + file: *const ::std::os::raw::c_char, + line: ::std::os::raw::c_int, + ); } diff --git a/zjit.c b/zjit.c index a5fcc7e1c8..25f840232d 100644 --- a/zjit.c +++ b/zjit.c @@ -238,17 +238,6 @@ rb_zjit_icache_invalidate(void *start, void *end) #endif } -// Acquire the VM lock and then signal all other Ruby threads (ractors) to -// contend for the VM lock, putting them to sleep. ZJIT uses this to evict -// threads running inside generated code so among other things, it can -// safely change memory protection of regions housing generated code. -void -rb_zjit_vm_lock_then_barrier(unsigned int *recursive_lock_level, const char *file, int line) -{ - rb_vm_lock_enter(recursive_lock_level, file, line); - rb_vm_barrier(); -} - // Convert a given ISEQ's instructions to zjit_* instructions void rb_zjit_profile_enable(const rb_iseq_t *iseq) diff --git a/zjit/bindgen/src/main.rs b/zjit/bindgen/src/main.rs index 13a8b76b39..859dab1862 100644 --- a/zjit/bindgen/src/main.rs +++ b/zjit/bindgen/src/main.rs @@ -347,7 +347,6 @@ fn main() { .allowlist_function("rb_set_cfp_(pc|sp)") .allowlist_function("rb_c_method_tracing_currently_enabled") .allowlist_function("rb_full_cfunc_return") - .allowlist_function("rb_zjit_vm_lock_then_barrier") .allowlist_function("rb_zjit_vm_unlock") .allowlist_function("rb_assert_(iseq|cme)_handle") .allowlist_function("rb_IMEMO_TYPE_P") @@ -368,6 +367,7 @@ fn main() { .allowlist_function("rb_assert_holding_vm_lock") .allowlist_function("rb_jit_shape_too_complex_p") .allowlist_function("rb_jit_multi_ractor_p") + .allowlist_function("rb_jit_vm_lock_then_barrier") .allowlist_type("robject_offsets") // from vm_sync.h diff --git a/zjit/src/cruby.rs b/zjit/src/cruby.rs index 5a34e5a8de..394bb7bb0f 100644 --- a/zjit/src/cruby.rs +++ b/zjit/src/cruby.rs @@ -825,7 +825,7 @@ where let line = loc.line; let mut recursive_lock_level: c_uint = 0; - unsafe { rb_zjit_vm_lock_then_barrier(&mut recursive_lock_level, file, line) }; + unsafe { rb_jit_vm_lock_then_barrier(&mut recursive_lock_level, file, line) }; let ret = match catch_unwind(func) { Ok(result) => result, diff --git a/zjit/src/cruby_bindings.inc.rs b/zjit/src/cruby_bindings.inc.rs index 95596d6982..fb642aba87 100644 --- a/zjit/src/cruby_bindings.inc.rs +++ b/zjit/src/cruby_bindings.inc.rs @@ -933,11 +933,6 @@ unsafe extern "C" { start: *mut ::std::os::raw::c_void, end: *mut ::std::os::raw::c_void, ); - pub fn rb_zjit_vm_lock_then_barrier( - recursive_lock_level: *mut ::std::os::raw::c_uint, - file: *const ::std::os::raw::c_char, - line: ::std::os::raw::c_int, - ); pub fn rb_zjit_iseq_insn_set( iseq: *const rb_iseq_t, insn_idx: ::std::os::raw::c_uint, @@ -1029,4 +1024,9 @@ unsafe extern "C" { pub fn rb_set_cfp_sp(cfp: *mut rb_control_frame_struct, sp: *mut VALUE); pub fn rb_jit_shape_too_complex_p(shape_id: shape_id_t) -> bool; pub fn rb_jit_multi_ractor_p() -> bool; + pub fn rb_jit_vm_lock_then_barrier( + recursive_lock_level: *mut ::std::os::raw::c_uint, + file: *const ::std::os::raw::c_char, + line: ::std::os::raw::c_int, + ); }