summaryrefslogtreecommitdiff
path: root/zjit
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2026-03-27 09:10:25 -0700
committerGitHub <noreply@github.com>2026-03-27 09:10:25 -0700
commit6b3cd4875ca8e368e6b649f8ecc7610f1e68fd3d (patch)
tree0c9b9819590af738a04c2843fafb7d5916f1babd /zjit
parent54d58909b579b4f97bca8fb131bf988e3eacdd84 (diff)
ZJIT: Check native stack before compiling ISEQs (#16576)
* ZJIT: Check native stack before compiling ISEQ When the native/machine stack is nearly exhausted, don't compile and enter ZJIT code. JIT-compiled code uses more native stack per call frame than the interpreter, so falling back to the interpreter avoids SystemStackError in cases where the interpreter would still have room. This matches what YJIT does in rb_yjit_iseq_gen_entry_point(). * ZJIT: Add skipped_native_stack_full counter
Diffstat (limited to 'zjit')
-rw-r--r--zjit/src/codegen.rs8
-rw-r--r--zjit/src/stats.rs1
2 files changed, 8 insertions, 1 deletions
diff --git a/zjit/src/codegen.rs b/zjit/src/codegen.rs
index 2f2454f41e..3a6d60af2d 100644
--- a/zjit/src/codegen.rs
+++ b/zjit/src/codegen.rs
@@ -144,7 +144,13 @@ define_split_jumps! {
/// If jit_exception is true, compile JIT code for handling exceptions.
/// See jit_compile_exception() for details.
#[unsafe(no_mangle)]
-pub extern "C" fn rb_zjit_iseq_gen_entry_point(iseq: IseqPtr, jit_exception: bool) -> *const u8 {
+pub extern "C" fn rb_zjit_iseq_gen_entry_point(iseq: IseqPtr, ec: EcPtr, jit_exception: bool) -> *const u8 {
+ // Don't compile when there is insufficient native stack space
+ if unsafe { rb_ec_stack_check(ec as _) } != 0 {
+ incr_counter!(skipped_native_stack_full);
+ return std::ptr::null();
+ }
+
// Take a lock to avoid writing to ISEQ in parallel with Ractors.
// with_vm_lock() does nothing if the program doesn't use Ractors.
with_vm_lock(src_loc!(), || {
diff --git a/zjit/src/stats.rs b/zjit/src/stats.rs
index bd36464bb7..b2e67afb16 100644
--- a/zjit/src/stats.rs
+++ b/zjit/src/stats.rs
@@ -156,6 +156,7 @@ make_counters! {
default {
compiled_iseq_count,
failed_iseq_count,
+ skipped_native_stack_full,
compile_time_ns,
profile_time_ns,