Skip to content

Commit

Permalink
YJIT: add --yjit-disable-code-gc
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Oct 10, 2023
1 parent b47e3f0 commit d538970
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ usage(const char *name, int help, int highlight, int columns)
static const struct ruby_opt_message yjit_options[] = {
M("--yjit-stats", "", "Enable collecting YJIT statistics"),
M("--yjit-exec-mem-size=num", "", "Size of executable memory block in MiB (default: 64)"),
M("--yjit-disable-code-gc", "", "Don't run code GC after exhausting exec-mem-size"),
M("--yjit-call-threshold=num", "", "Number of calls to trigger JIT (default: 10)"),
M("--yjit-max-versions=num", "", "Maximum number of versions per basic block (default: 4)"),
M("--yjit-greedy-versioning", "", "Greedy versioning mode (default: disabled)"),
Expand Down
16 changes: 13 additions & 3 deletions yjit/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,9 @@ pub fn gen_entry_point(iseq: IseqPtr, ec: EcPtr, jit_exception: bool) -> Option<
// Compilation failed
None => {
// Trigger code GC. This entry point will be recompiled later.
cb.code_gc();
if !get_option!(disable_code_gc) {
cb.code_gc();
}
return None;
}

Expand Down Expand Up @@ -1760,7 +1762,9 @@ fn entry_stub_hit_body(entry_ptr: *const c_void, ec: EcPtr) -> Option<*const u8>
get_or_create_iseq_payload(iseq).entries.push(pending_entry.into_entry());
} else { // No space
// Trigger code GC. This entry point will be recompiled later.
cb.code_gc();
if !get_option!(disable_code_gc) {
cb.code_gc();
}
}

cb.mark_all_executable();
Expand Down Expand Up @@ -1973,6 +1977,10 @@ fn branch_stub_hit_body(branch_ptr: *const c_void, target_idx: u32, ec: EcPtr) -
// So we do it here instead.
rb_set_cfp_sp(cfp, reconned_sp);

if get_option!(disable_code_gc) && (cb.has_dropped_bytes() || ocb.unwrap().has_dropped_bytes()) {
return CodegenGlobals::get_stub_exit_code().raw_ptr();
}

(cfp, original_interp_sp)
};

Expand Down Expand Up @@ -2053,7 +2061,9 @@ fn branch_stub_hit_body(branch_ptr: *const c_void, target_idx: u32, ec: EcPtr) -
// because incomplete code could be used when cb.dropped_bytes is flipped
// by code GC. So this place, after all compilation, is the safest place
// to hook code GC on branch_stub_hit.
cb.code_gc();
if !get_option!(disable_code_gc) {
cb.code_gc();
}
branch = branch_rc.borrow_mut();

// Failed to service the stub by generating a new block so now we
Expand Down
15 changes: 14 additions & 1 deletion yjit/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub struct Options {
// compile anything)
pub pause: bool,

/// Stop generating new code when exec_mem_size is reached. Don't run code GC
pub disable_code_gc: bool,

/// Dump compiled and executed instructions for debugging
pub dump_insns: bool,

Expand Down Expand Up @@ -66,6 +69,7 @@ pub static mut OPTIONS: Options = Options {
gen_stats: false,
gen_trace_exits: false,
pause: false,
disable_code_gc: false,
dump_insns: false,
dump_disasm: None,
verify_ctx: false,
Expand All @@ -86,7 +90,12 @@ macro_rules! get_option {
// Unsafe is ok here because options are initialized
// once before any Ruby code executes
($option_name:ident) => {
unsafe { OPTIONS.$option_name }
{
// make this a statement since attributes on expressions are experimental
#[allow(unused_unsafe)]
let ret = unsafe { OPTIONS.$option_name };
ret
}
};
}
pub(crate) use get_option;
Expand Down Expand Up @@ -160,6 +169,10 @@ pub fn parse_option(str_ptr: *const std::os::raw::c_char) -> Option<()> {
OPTIONS.pause = true;
},

("disable-code-gc", "") => unsafe {
OPTIONS.disable_code_gc = true;
}

("dump-disasm", _) => match opt_val.to_string().as_str() {
"" => unsafe { OPTIONS.dump_disasm = Some(DumpDisasm::Stdout) },
directory => {
Expand Down

0 comments on commit d538970

Please sign in to comment.