Retrofitting JIT Compilers into C Interpreters
16 hours ago
- #meta-tracing
- #language implementation
- #JIT compilers
- The yk system enables automatic conversion of C interpreters into JIT-compiling VMs with minimal code changes, offering better performance while maintaining compatibility with reference implementations like Lua and Python.
- yk uses meta-tracing on C interpreters, leveraging LLVM (ykllvm) to record traces, optimize them, and generate machine code, with optimizations like promotion, idempotent functions, and backward code generation.
- Key technical challenges include deoptimization through stackmaps and safepoints, handling speculation with guards, and using a shadow stack for pointers to ensure correct stack layout between JIT and AOT code.
- While yk is in alpha and has limitations (e.g., incomplete optimizations, x64-only support), it shows promising results, such as ~2x speedup in Lua benchmarks and easy portability to new interpreter versions (e.g., updating yklua to Lua 5.5 in under 2 hours).
- The system reduces JIT compiler development effort by automating trace recording and optimization, allowing interpreter authors to add performance gains with features like yk_promote and yk_idempotent annotations.