This document discusses techniques used by just-in-time (JIT) compilers to optimize method calls in dynamic programming languages. It describes how call sites are often monomorphic, calling the same method, and how tracing JITs can exploit this by compiling call sequences into optimized machine code traces. Whole method JITs used in virtual machines like the JVM additionally profile call sites and can devirtualize polymorphic calls. The document outlines challenges for JITs in dynamic languages and techniques used to address these challenges.
9. Tracing JIT
Interpretation phase
Record actions, record branch conditions
Compiling trace
Actions compiled into branchless machine code
Guards added for conditions
If guard is broken – fall back to interpretation
10. Tracing JIT
Mozila’s TraceMonkey
1. IncrementalDynamicCodeGenerationwithTraceTrees
http://www.ics.uci.edu/~franz/Site/pubs-pdf/ICS-TR-06-16.pdf
PyPy
RPython – restrict python dialect compiling to C
Rpython based interpreter trace JITed by runtime
1. http://tratt.net/laurie/research/pubs/papers/bolz_tratt__the_impact_of_metatra
cing_on_vm_design_and_implementation.pdf
11. Tracing JIT
Limitation
Trace is EXPENSIVE
Falling out of path is EXPENSIVE
A lot of code is executed just once
– wasting resources on tracing
15. More JVM back magic
On stack replacement
Code for method could be replaced without
reentering to a method
Scalar replacement
Object not leaving method scope
can be reduced to a number of local variables