@@ -22,6 +22,10 @@ pub static mut OPTIONS: Option<Options> = None;
2222
2323#[ derive( Clone , Debug ) ]
2424pub struct Options {
25+ /// Hard limit of the executable memory block to allocate in bytes.
26+ /// Note that the command line argument is expressed in MiB and not bytes.
27+ pub exec_mem_bytes : usize ,
28+
2529 /// Number of times YARV instructions should be profiled.
2630 pub num_profiles : u8 ,
2731
@@ -58,6 +62,7 @@ pub struct Options {
5862impl Default for Options {
5963 fn default ( ) -> Self {
6064 Options {
65+ exec_mem_bytes : 64 * 1024 * 1024 ,
6166 num_profiles : 1 ,
6267 stats : false ,
6368 debug : false ,
@@ -74,12 +79,18 @@ impl Default for Options {
7479}
7580
7681/// `ruby --help` descriptions for user-facing options. Do not add options for ZJIT developers.
77- /// Note that --help allows only 80 chars per line, including indentation. 80-char limit --> |
82+ /// Note that --help allows only 80 chars per line, including indentation, and it also puts the
83+ /// description in a separate line if the option name is too long. 80-char limit --> | (any character beyond this `|` column fails the test)
7884pub const ZJIT_OPTIONS : & ' static [ ( & str , & str ) ] = & [
79- ( "--zjit-call-threshold=num" , "Number of calls to trigger JIT (default: 2)." ) ,
80- ( "--zjit-num-profiles=num" , "Number of profiled calls before JIT (default: 1, max: 255)." ) ,
81- ( "--zjit-stats" , "Enable collecting ZJIT statistics." ) ,
82- ( "--zjit-perf" , "Dump ISEQ symbols into /tmp/perf-{}.map for Linux perf." ) ,
85+ // TODO: Hide --zjit-exec-mem-size from ZJIT_OPTIONS once we add --zjit-mem-size (Shopify/ruby#686)
86+ ( "--zjit-exec-mem-size=num" ,
87+ "Size of executable memory block in MiB (default: 64)." ) ,
88+ ( "--zjit-call-threshold=num" ,
89+ "Number of calls to trigger JIT (default: 2)." ) ,
90+ ( "--zjit-num-profiles=num" ,
91+ "Number of profiled calls before JIT (default: 1, max: 255)." ) ,
92+ ( "--zjit-stats" , "Enable collecting ZJIT statistics." ) ,
93+ ( "--zjit-perf" , "Dump ISEQ symbols into /tmp/perf-{}.map for Linux perf." ) ,
8394 ( "--zjit-log-compiled-iseqs=path" ,
8495 "Log compiled ISEQs to the file. The file will be truncated." ) ,
8596] ;
@@ -163,6 +174,20 @@ fn parse_option(str_ptr: *const std::os::raw::c_char) -> Option<()> {
163174 match ( opt_name, opt_val) {
164175 ( "" , "" ) => { } , // Simply --zjit
165176
177+ ( "mem-size" , _) => match opt_val. parse :: < usize > ( ) {
178+ Ok ( n) => {
179+ // Reject 0 or too large values that could overflow.
180+ // The upper bound is 1 TiB but we could make it smaller.
181+ if n == 0 || n > 1024 * 1024 {
182+ return None
183+ }
184+
185+ // Convert from MiB to bytes internally for convenience
186+ options. exec_mem_bytes = n * 1024 * 1024 ;
187+ }
188+ Err ( _) => return None ,
189+ } ,
190+
166191 ( "call-threshold" , _) => match opt_val. parse ( ) {
167192 Ok ( n) => {
168193 unsafe { rb_zjit_call_threshold = n; }
0 commit comments