just-in-time compilation
termKept 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
- V8 blog, Maglev: V8's Fastest Optimizing JIT, 5 December 2023: Ignition interpreter, Sparkplug (2021), Maglev (Chrome 117), TurboFan; feedback, speculation and deoptimization (read 2026-11-23)
- V8 blog, Firing up the Ignition interpreter, 23 August 2016: a register machine with an accumulator (read 2026-11-23)
- PEP 744, JIT Compilation: an experimental copy-and-patch JIT in CPython builds since 3.13, disabled by default (read 2026-11-23)
- MITRE CWE-843, Access of Resource Using Incompatible Type ('Type Confusion'): not unique to C and C++ (read 2026-11-23)
- CISA Known Exploited Vulnerabilities catalogue, JSON, version 2026.11.23: 37 entries naming type confusion, 20 of them in V8 (counted) (read 2026-11-23)
- John Aycock, University of Calgary, A Brief History of Just-In-Time, ACM Computing Surveys 35(2), June 2003, pp. 97-113 (course copy, Chang Gung University): JIT as any translation performed dynamically after a program starts; JIT systems 'completely unnecessary', only a means to improve efficiency; McCarthy 1960, the Michigan Executive System for the IBM 7090 (1966), Thompson 1968, Mitchell 1970 (read 2026-11-23)
- OpenJDK, HotSpot Glossary of Terms: C1 compiler, fast and lightly optimizing; C2 compiler, highly optimizing ('opto'); deoptimization converts a compiled stack frame into an interpreted one (read 2026-11-23)
- Johnathan Norman, Microsoft Browser Vulnerability Research, Super Duper Secure Mode, 4 August 2021: JITs introduced to browsers in 2008; roughly 45% of CVEs for V8 after 2019 related to the JIT engine; a Mozilla analysis of in-the-wild Chrome exploits; SDSM disables JIT (TurboFan/Sparkplug) and enables CET (read 2026-11-23)
- PaX Team, NOEXEC design document: if an application does not need to generate code at runtime then it should not be able to (read 2026-11-23)
- V8 blog, Maglev: V8's Fastest Optimizing JIT, 5 December 2023: until 2021 two tiers, Ignition and TurboFan, TurboFan running JetStream 4.35x as fast; Sparkplug (2021) compiling bytecode almost instantaneously, +45% on JetStream over Ignition; Maglev in Chrome M117 between Sparkplug and TurboFan (read 2026-11-23)