Skip to content

Truly independent web browser

LibJS: Install finished JIT compiles at the next call of their function

Andreas Kling99ea20e39071
diff --git a/Libraries/LibJS/Rust/src/jit/tier_up.rs b/Libraries/LibJS/Rust/src/jit/tier_up.rs
index e01629c52e7..d81e3d989e5 100644
--- a/Libraries/LibJS/Rust/src/jit/tier_up.rs
+++ b/Libraries/LibJS/Rust/src/jit/tier_up.rs
@@ -68,12 +68,16 @@ fn warmup_budget(jit: &JitState) -> i32 {
randomized_budget(jit, i32::try_from(budget.max(1)).unwrap_or(i32::MAX))
}
-/// How much budget an executable gets while it waits for its compile job. Its next tier-up check installs the code if
-/// the job has finished.
+/// How much budget an executable gets once it has code while frames of it may still run in the interpreter, which
+/// keep counting so that their loops can continue in the code at an on-stack replacement entry.
fn compile_wait_budget(options: &Options) -> i32 {
(threshold_budget(options) / 8).max(tier_up_costs::FUNCTION_ENTRY)
}
+/// How much budget an executable gets while it waits for its compile job: one function entry, so that the next call
+/// or the next few loop iterations install the code if the job has finished, and run it.
+const QUEUED_BUDGET: i32 = tier_up_costs::FUNCTION_ENTRY;
+
/// The function to compile the running frame's executable for, if it should be compiled at all.
fn function_to_compile(vm: &Vm) -> Option<Gc<EcmascriptFunctionObject>> {
if vm.debugging_enabled() {
@@ -113,6 +117,18 @@ pub fn on_budget_exhausted(vm: &Vm, pc: u32, is_loop: bool) {
let executable = vm.current_executable();
let options = &vm.jit.options;
+ // NB: An executable whose compile job is queued checks at every call whether the job finished, so it does nothing
+ // else here.
+ if executable.jit_compile_state() == CompileState::Queued {
+ install_finished_compiles(vm);
+ match executable.jit_compile_state() {
+ CompileState::Queued => executable.head.tier_up_budget.set(QUEUED_BUDGET),
+ CompileState::Installed => executable.head.tier_up_budget.set(compile_wait_budget(options)),
+ _ => {}
+ }
+ return;
+ }
+
// A warm executable starts collecting feedback, and the tier-up threshold counts from here, unless the JIT would
// never compile it.
if executable.interpreter_tier() == InterpreterTier::WarmingUp {
@@ -151,10 +167,7 @@ pub fn on_budget_exhausted(vm: &Vm, pc: u32, is_loop: bool) {
install_finished_compiles(vm);
match executable.jit_compile_state() {
CompileState::None => {}
- CompileState::Queued => {
- executable.head.tier_up_budget.set(compile_wait_budget(options));
- return;
- }
+ CompileState::Queued => unreachable!("queued executables return early"),
CompileState::Discarding => {
// NB: Once no frame may still run the discarded code, the executable is compiled again.
if !executable.detach_discarded_jit_code_if_unused(vm) {
@@ -183,7 +196,7 @@ pub fn on_budget_exhausted(vm: &Vm, pc: u32, is_loop: bool) {
};
compile(vm, executable, function, is_loop.then_some(pc), options.sync);
if executable.jit_compile_state() == CompileState::Queued {
- executable.head.tier_up_budget.set(compile_wait_budget(options));
+ executable.head.tier_up_budget.set(QUEUED_BUDGET);
}
}