mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 04:24:23 +00:00
ZJIT: Fix --zjit-mem-size and add --zjit-exec-mem-size (#15041)
ZJIT: Fix --zjit-mem-size and resurrect --zjit-exec-mem-size
This commit is contained in:
parent
7a0d730ee3
commit
a0376eb2cc
Notes:
git
2025-11-04 21:57:04 +00:00
Merged-By: k0kubun <takashikkbn@gmail.com>
@ -117,7 +117,7 @@ impl Default for Options {
|
||||
/// description in a separate line if the option name is too long. 80-char limit --> | (any character beyond this `|` column fails the test)
|
||||
pub const ZJIT_OPTIONS: &[(&str, &str)] = &[
|
||||
("--zjit-mem-size=num",
|
||||
"Max amount of memory that ZJIT can use (in MiB)."),
|
||||
"Max amount of memory that ZJIT can use in MiB (default: 128)."),
|
||||
("--zjit-call-threshold=num",
|
||||
"Number of calls to trigger JIT (default: 30)."),
|
||||
("--zjit-num-profiles=num",
|
||||
@ -175,6 +175,10 @@ const DUMP_LIR_ALL: &[DumpLIR] = &[
|
||||
DumpLIR::scratch_split,
|
||||
];
|
||||
|
||||
/// Mamximum value for --zjit-mem-size/--zjit-exec-mem-size in MiB.
|
||||
/// We set 1TiB just to avoid overflow. We could make it smaller.
|
||||
const MAX_MEM_MIB: usize = 1024 * 1024;
|
||||
|
||||
/// Macro to dump LIR if --zjit-dump-lir is specified
|
||||
macro_rules! asm_dump {
|
||||
($asm:expr, $target:ident) => {
|
||||
@ -257,17 +261,19 @@ fn parse_option(str_ptr: *const std::os::raw::c_char) -> Option<()> {
|
||||
("", "") => {}, // Simply --zjit
|
||||
|
||||
("mem-size", _) => match opt_val.parse::<usize>() {
|
||||
Ok(n) => {
|
||||
// Reject 0 or too large values that could overflow.
|
||||
// The upper bound is 1 TiB but we could make it smaller.
|
||||
if n == 0 || n > 1024 * 1024 {
|
||||
return None
|
||||
}
|
||||
Ok(n) if (1..=MAX_MEM_MIB).contains(&n) => {
|
||||
// Convert from MiB to bytes internally for convenience
|
||||
options.mem_bytes = n * 1024 * 1024;
|
||||
}
|
||||
_ => return None,
|
||||
},
|
||||
|
||||
("exec-mem-size", _) => match opt_val.parse::<usize>() {
|
||||
Ok(n) if (1..=MAX_MEM_MIB).contains(&n) => {
|
||||
// Convert from MiB to bytes internally for convenience
|
||||
options.exec_mem_bytes = n * 1024 * 1024;
|
||||
}
|
||||
Err(_) => return None,
|
||||
_ => return None,
|
||||
},
|
||||
|
||||
("call-threshold", _) => match opt_val.parse() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user