Skip to content

Commit d3a5272

Browse files
k0kubunjacob-shops
authored andcommitted
ZJIT: Fix --zjit-mem-size and add --zjit-exec-mem-size (ruby#15041)
ZJIT: Fix --zjit-mem-size and resurrect --zjit-exec-mem-size
1 parent 1a19b3b commit d3a5272

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

zjit/src/options.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl Default for Options {
117117
/// description in a separate line if the option name is too long. 80-char limit --> | (any character beyond this `|` column fails the test)
118118
pub const ZJIT_OPTIONS: &[(&str, &str)] = &[
119119
("--zjit-mem-size=num",
120-
"Max amount of memory that ZJIT can use (in MiB)."),
120+
"Max amount of memory that ZJIT can use in MiB (default: 128)."),
121121
("--zjit-call-threshold=num",
122122
"Number of calls to trigger JIT (default: 30)."),
123123
("--zjit-num-profiles=num",
@@ -175,6 +175,10 @@ const DUMP_LIR_ALL: &[DumpLIR] = &[
175175
DumpLIR::scratch_split,
176176
];
177177

178+
/// Mamximum value for --zjit-mem-size/--zjit-exec-mem-size in MiB.
179+
/// We set 1TiB just to avoid overflow. We could make it smaller.
180+
const MAX_MEM_MIB: usize = 1024 * 1024;
181+
178182
/// Macro to dump LIR if --zjit-dump-lir is specified
179183
macro_rules! asm_dump {
180184
($asm:expr, $target:ident) => {
@@ -257,17 +261,19 @@ fn parse_option(str_ptr: *const std::os::raw::c_char) -> Option<()> {
257261
("", "") => {}, // Simply --zjit
258262

259263
("mem-size", _) => match opt_val.parse::<usize>() {
260-
Ok(n) => {
261-
// Reject 0 or too large values that could overflow.
262-
// The upper bound is 1 TiB but we could make it smaller.
263-
if n == 0 || n > 1024 * 1024 {
264-
return None
265-
}
264+
Ok(n) if (1..=MAX_MEM_MIB).contains(&n) => {
265+
// Convert from MiB to bytes internally for convenience
266+
options.mem_bytes = n * 1024 * 1024;
267+
}
268+
_ => return None,
269+
},
266270

271+
("exec-mem-size", _) => match opt_val.parse::<usize>() {
272+
Ok(n) if (1..=MAX_MEM_MIB).contains(&n) => {
267273
// Convert from MiB to bytes internally for convenience
268274
options.exec_mem_bytes = n * 1024 * 1024;
269275
}
270-
Err(_) => return None,
276+
_ => return None,
271277
},
272278

273279
("call-threshold", _) => match opt_val.parse() {

0 commit comments

Comments
 (0)