summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zjit/src/cruby.rs7
-rw-r--r--zjit/src/options.rs14
2 files changed, 17 insertions, 4 deletions
diff --git a/zjit/src/cruby.rs b/zjit/src/cruby.rs
index 4208af03f5..899ed4d892 100644
--- a/zjit/src/cruby.rs
+++ b/zjit/src/cruby.rs
@@ -979,7 +979,7 @@ pub use manual_defs::*;
pub mod test_utils {
use std::{ptr::null, sync::Once};
- use crate::{options::rb_zjit_prepare_options, state::rb_zjit_enabled_p, state::ZJITState};
+ use crate::{options::{internal_set_num_profiles, rb_zjit_call_threshold, rb_zjit_prepare_options, DEFAULT_CALL_THRESHOLD}, state::{rb_zjit_enabled_p, ZJITState}};
use super::*;
@@ -1004,6 +1004,11 @@ pub mod test_utils {
rb_zjit_prepare_options(); // enable `#with_jit` on builtins
ruby_init();
+ // The default rb_zjit_profile_threshold is too high, so lower it for HIR tests.
+ if rb_zjit_call_threshold == DEFAULT_CALL_THRESHOLD {
+ internal_set_num_profiles(1);
+ }
+
// Pass command line options so the VM loads core library methods defined in
// ruby such as from `kernel.rb`.
// We drive ZJIT manually in tests, so disable heuristic compilation triggers.
diff --git a/zjit/src/options.rs b/zjit/src/options.rs
index 155c3805ba..00fb9c50a5 100644
--- a/zjit/src/options.rs
+++ b/zjit/src/options.rs
@@ -3,18 +3,25 @@ use std::os::raw::{c_char, c_int, c_uint};
use crate::cruby::*;
use std::collections::HashSet;
+/// Default --zjit-num-profiles
+const DEFAULT_NUM_PROFILES: u8 = 5;
+
+/// Default --zjit-call-threshold. This should be large enough to avoid compiling
+/// warmup code, but small enough to perform well on micro-benchmarks.
+pub const DEFAULT_CALL_THRESHOLD: u64 = 30;
+
/// Number of calls to start profiling YARV instructions.
/// They are profiled `rb_zjit_call_threshold - rb_zjit_profile_threshold` times,
/// which is equal to --zjit-num-profiles.
#[unsafe(no_mangle)]
#[allow(non_upper_case_globals)]
-pub static mut rb_zjit_profile_threshold: u64 = 1;
+pub static mut rb_zjit_profile_threshold: u64 = DEFAULT_CALL_THRESHOLD - DEFAULT_NUM_PROFILES as u64;
/// Number of calls to compile ISEQ with ZJIT at jit_compile() in vm.c.
/// --zjit-call-threshold=1 compiles on first execution without profiling information.
#[unsafe(no_mangle)]
#[allow(non_upper_case_globals)]
-pub static mut rb_zjit_call_threshold: u64 = 2;
+pub static mut rb_zjit_call_threshold: u64 = DEFAULT_CALL_THRESHOLD;
/// ZJIT command-line options. This is set before rb_zjit_init() sets
/// ZJITState so that we can query some options while loading builtins.
@@ -67,7 +74,7 @@ impl Default for Options {
fn default() -> Self {
Options {
exec_mem_bytes: 64 * 1024 * 1024,
- num_profiles: 1,
+ num_profiles: DEFAULT_NUM_PROFILES,
stats: false,
debug: false,
disable_hir_opt: false,
@@ -279,6 +286,7 @@ fn update_profile_threshold() {
}
}
+#[cfg(test)]
pub fn internal_set_num_profiles(n: u8) {
let options = unsafe { OPTIONS.as_mut().unwrap() };
options.num_profiles = n;