Skip to content

Exposing Call-Shared Stacks to a Meta-Tracing JIT Compiler

Yusuke Izawa, Kota Hakamada

cs.PL

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