just-in-time compilation

term

programmingsecurity

Kept in this browser · My desk

Compiling the parts of a program that run most often into machine code while the program is running, usually guided by what the running program has been observed to do.

V8, the JavaScript engine of Chrome and Node.js, interprets bytecode in Ignition, then compiles hot code with Sparkplug (since 2021), Maglev (since Chrome 117) and TurboFan, using recorded type feedback. CPython has included an experimental copy-and-patch just-in-time (JIT) compiler since 3.13, disabled by default.

What it is. Just-in-time (JIT) compilation translates the parts of a program that run most often into machine code while the program is running, usually guided by what the running program has been observed to do. John Aycock's survey, A Brief History of Just-In-Time (Computing Surveys of the Association for Computing Machinery, ACM, June 2003), defines it broadly as "any translation performed dynamically, after a program has started execution", and begins with a useful provocation: JIT systems "are completely unnecessary. They are only a means to improve the time and space efficiency of programs."

How it works. A JIT lets a dynamic language approach the speed of a compiled one. The engine records, at each operation, the types and object shapes it actually sees; the optimizing compiler then generates "often speculative" machine code for those types, guarded by checks, and "deoptimizes" back to the interpreter when a check fails, for example when a string arrives where only small integers had been seen. OpenJDK's HotSpot glossary defines deoptimization as converting "a compiled (or more optimized) stack frame into an interpreted (or less optimized) stack frame".

Tiers. Engines use several compilers, from fast and simple to slow and thorough. V8, the JavaScript engine of Chrome and Node.js, interprets bytecode in Ignition, then compiles hot code with Sparkplug (since 2021), Maglev (since Chrome 117) and TurboFan. The HotSpot Java virtual machine has a C1 compiler, "Fast, lightly optimizing", with linear scan register allocation, and a C2 compiler, "Highly optimizing", also known as opto. CPython has included an experimental copy-and-patch JIT compiler since 3.13, disabled by default, described in Python Enhancement Proposal (PEP) 744.

What each tier buys. The V8 team's own numbers show why engines keep several compilers. Until 2021 V8 had two tiers, the Ignition interpreter and the TurboFan optimizer, and on the JetStream benchmark suite TurboFan made V8 run "4.35x as fast". Because the gap in speed and compile time between the two was so large, the team added Sparkplug, a baseline JIT that compiles bytecode to equivalent machine code "almost instantaneously" and improved JetStream by 45% over Ignition alone. Maglev, introduced in Chrome 117 (the post is dated 5 December 2023), sits between Sparkplug and TurboFan as "a fast optimizing compiler that generates good enough code, fast enough", which also lets the engine wait longer before paying for TurboFan.

History. Aycock suspects that the earliest published work on JIT compilation was McCarthy's 1960 Lisp paper, which mentioned compiling functions into machine language fast enough that the output needn't be saved. The University of Michigan Executive System for the IBM 7090 noted in 1966 that its assembler could translate and load during execution; Ken Thompson's 1968 paper in the Communications of the ACM compiled regular expressions into IBM 7094 code; and James Mitchell observed around 1970 that compiled code could be derived from an interpreter at run time by recording what it did, an idea that later shaped the JITs of Smalltalk and Self, from which the Java HotSpot lineage descends.

The cost. A JIT costs memory, warm-up time and a large, complex compiler running inside the program on the program's input. It also needs memory that is first written and then executed, which collides with the rule that memory should never be both: the PaX project's NOEXEC design states that "if an application does not need to generate code at runtime then it should not be able to", and a JIT is exactly the application that does.

The security record. That is why JIT engines are a security boundary: a crafted input that breaks a speculative assumption without tripping the guard produces type confusion (CWE-843), and the Cybersecurity and Infrastructure Security Agency (CISA) Known Exploited Vulnerabilities catalogue listed, on 23 November 2026, 37 type-confusion entries, 20 of them in V8. Microsoft's browser vulnerability research team wrote on 4 August 2021 that JITs "were introduced to browsers in 2008", that Common Vulnerabilities and Exposures (CVE) data after 2019 showed "roughly 45% of CVEs issued for V8 were related to the JIT engine", and that a Mozilla analysis found over half of the in-the-wild Chrome exploits abused a JIT bug; its Super Duper Secure Mode experiment "disables JIT (TurboFan/Sparkplug) and enables CET", Intel's Control-flow Enforcement Technology, trading speed for a smaller attack surface. Some hardened environments turn JITs off for the same reason.

What goes wrong. Besides type confusion, JIT engines suffer from bounds checks wrongly removed by optimization, stale assumptions after deoptimization, and the writable-and-executable memory they need, which other exploits can abuse. Performance can surprise too: a program that keeps changing the types it uses deoptimizes repeatedly and runs slower than a plain interpreter.

Neighbours. JIT compilation starts from bytecode run by an interpreter, is a kind of compiler, depends on runtime type information, and is a main attack surface of JavaScript engines; memory safety and type confusion are the security words around it. Brazilian practice says compilação JIT or compilador JIT.

Also known as: JIT, JIT compiler, just-in-time compiler, compilação JIT, compilador JIT

Sources

← Back to J Back to the glossary