summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashi.kokubun@shopify.com>2025-11-04 13:56:35 -0800
committerGitHub <noreply@github.com>2025-11-04 13:56:35 -0800
commita0376eb2ccc8a893905d270c5363b73ccfcacd2d (patch)
treeaa5fccc94f3612eec21d849730abd130d51bf225
parent7a0d730ee320e8b7a46d8fd4719a1ec709fd958c (diff)
ZJIT: Fix --zjit-mem-size and add --zjit-exec-mem-size (#15041)
ZJIT: Fix --zjit-mem-size and resurrect --zjit-exec-mem-size
-rw-r--r--zjit/src/options.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/zjit/src/options.rs b/zjit/src/options.rs
index f6471b5461..cd3a643971 100644
--- a/zjit/src/options.rs
+++ b/zjit/src/options.rs
@@ -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() {