Exposing Call-Shared Stacks to a Meta-Tracing JIT Compiler
Abstract
Meta-tracing JIT compilers such as RPython's can optimize accesses to interpreter state when the state is represented in a form that the optimizer can track, such as fixed fields in virtualizable interpreter frames. However, interpreters for stack-based languages such as Forth and Factor use a shared data stack whose depth and per-call usage are not necessarily known statically. Keeping this stack in a heap array may leave memory accesses in compiled traces, while exposing the entire array to the optimizer makes the amount of exposed state depend on its allocated capacity. Conventional stack caching avoids some memory accesses but does not necessarily make cached values visible to a meta-tracing JIT compiler. We propose the stack fragment layout, which divides a shared data stack into a fixed-width top fragment and a shared spill array. The top fragment stores stack values in interpreter fields that a meta-tracing JIT compiler can optimize within traces, while the spill retains deeper values in memory. This representation bounds the amount of JIT-visible stack state independently of the total stack depth, without requiring static stack-effect information. We provide proof sketches showing that the layout preserves the modeled stack operations and, under stated assumptions, that the amount of stack state reconstructed at trace exits is bounded by the fragment width plus constant control state. We implement the layout in RPyForth, an RPython-based Forth interpreter, and RPyFactor, an interpreter for a subset of Factor. Controlled experiments isolate the benefit of exposing the top fragment to the meta-tracing JIT compiler from that of stack caching alone. Across three benchmark suites on two x86-64 machines, this optimization yields suite-level geometric-mean speedups of 1.44-2.11 in RPyForth and 1.42-1.56x in RPyFactor.
Create a lesson
Metadata
- Comments
- 38 pages, 15 figures, 4 tables
Related papers
Denotational Results in Compiler Correctness and Comparisons with Operational Approaches
Shared title terminologycs.PLJeremy G. Siek, Matthew Heimerdinger, Tianyu Chen et al.
What Field Enumeration Costs to Compile in C++26: Native Reflection, Structured-Binding Packs, Reflection Libraries and Hand-Written Serializers on GCC 16
Shared title terminologycs.PLDenys Kachalenko
Tenon: A Unified Programming Framework for Retargetable PIM Compilation
Shared title terminologycs.PLNiansong Zhang, Shiran Guo, Zhiru Zhang
A Compilation Model for Divergent Parallel Workloads
Shared title terminologycs.PLAlexander J Root, Christophe Gyurgyik, Devanshu Ladsaria et al.
CompCert4Lean: Porting a Verified C Compiler to Lean in Six Weeks with Parallel Coding Agents
Shared title terminologycs.PLCong Wang, Zhiyang Chen, Fan Long et al.
Compiling Imperative Hardware Protocol Specifications to Hardware
Shared title terminologycs.PLNikil V. Shyamsunder, Ernest Ng, Adrian Sampson et al.