Leveraging Copy-and-Patch JIT for Low-Overhead Dynamic Program Analysis
Open Access
- 30 June 2026
- conference paper
- Published by Association for Computing Machinery (ACM)
- p. 49-60
Abstract
Copy-and-patch compilation is an approach for building baseline just-in-time compilers from AST or bytecode interpreters. It features very fast compilation times while generating good quality code. It has been used as a baseline tier for a number of languages including Lua, Python, and R. In this paper, we explore copy-and-patch as a foundation for dynamic program analysis, and implement four analyses on top of an existing copy-and-patch JIT for R: code instrumentation, code coverage, performance profiling, and native debugging. Two properties make copy-and-patch particularly well-suited for this purpose. First, since the code templates (stencils) are compiled by a standard C compiler, DWARF debug information is available as a by-product. This lets us reuse native tooling for profiling and debugging directly, with R and native code appearing in a single unified view. Second, analyses that operate at the bytecode level reduce to injecting stencils into the bytecode stream at JIT compile time, incurring minimal overhead. Our prototype evaluation yields instrumentation with no measurable overhead; code coverage that is faster than the existing solution while covering 17% more lines; and profiling that remains, on average, faster than GNU R.This publication has 18 references indexed in Scilit:
- Debugging WebAssembly? Put Some Whamm on It!Proceedings of the ACM on Programming Languages, 2025
- PolyDebug: A Framework for Polyglot DebuggingThe Art, Science, and Engineering of Programming, 2025
- Flexible Non-intrusive Dynamic Instrumentation for WebAssembly2024
- Copy-and-patch compilation: a fast compilation algorithm for high-level languages and bytecodeProceedings of the ACM on Programming Languages, 2021
- Contextual dispatch for function specializationProceedings of the ACM on Programming Languages, 2020
- Designing types for R, empiricallyProceedings of the ACM on Programming Languages, 2020
- Feature-Specific ProfilingACM Transactions on Programming Languages and Systems, 2018
- Fast, Flexible, Polyglot Instrumentation Support for Debuggers and other ToolsThe Art, Science, and Engineering of Programming, 2018
- Runtime and memory consumption analyses for machine learning R programsJournal of Statistical Computation and Simulation, 2014
- Pin2005