JavaScript Memory Model JSMM
The memory model of JavaScript, based on the C11 model. Like C11 it suffers from the thin-air problem and so provides only the internal DRF guarantee, but — unlike C11 — it does not treat racy non-atomic accesses as undefined behaviour. Because its main shared primitive is the SharedArrayBuffer, a linear mutable byte buffer, the model naturally supports mixed-size accesses. It was repaired and mechanised by Watt et al.
Properties
Property vector survey-sourced — from Tables 1–2 of the Moiseenko et al. survey, except cells that cite a specific source.
- Compilation optimal mapping to
- yes x86
- yes POWER
- yes Armv7
- yes Armv8
- Reasoning guarantees
- no External DRF
- no Coherence
- yes No undefined behaviour
- no In-order execution
- no No out-of-thin-air
Ordering relationships
- Equivalent to
- WebAssembly Memory Model (Wasm) — Watt et al. 2019 §6.3 (Prop. 6.2): dropping Wasm's two strengthening conditions (†,‡) yields exactly the consistency behaviours of the (uncorrected) JavaScript model on shared array buffers. The paper proposes adding (†,‡) to JavaScript as a strict strengthening; TC39 adopted them, and the repaired model is this dataset's JSMM — so full Wasm and JSMM agree on the shared-memory data-access (SharedArrayBuffer) fragment (excluding traps, memory growth, and mixed-size beyond the shared subset).
- Incomparable with
- C11/C++11 Memory Model — The JavaScript model is based on C11 and shares its thin-air problem (only internal DRF), but — unlike C11 — it does not treat racy non-atomic accesses as undefined behaviour and it natively supports mixed-size accesses over SharedArrayBuffer. Neither contains the other.
References
- Conrad Watt, Christopher Pulte, Anton Podkopaev, Guillaume Barbier, Stephen Dolan, Shaked Flur, Jean Pichon-Pharabod, Shu-yu Guo. Repairing and Mechanising the JavaScript Relaxed Memory Model. PLDI 2020, 2020. doi:10.1145/3385412.3385973
- Evgenii Moiseenko, Anton Podkopaev, Dmitrii Koznov. A Survey of Programming Language Memory Models. Programming and Computer Software 47(6), pp. 439–456, 2021. doi:10.1134/S0361768821060050