- Tracing vs method based
- Tracing: better best and avg case, and simpler, but worse worst-case
- Mozilla: TraceMonkey → JagerMonkey (method)
- Only LuaJIT and PyPy still use tracing
- Method based likely more complex: On-Stack Replacement (if the current method becomes "hot", it needs to be replaced by a compiled version), Inline Caches, Hidden Classes and Deoptimization
- HN
- Template interpreter: rather than a switch statement, each bytecode has a sequence of CPU instructions (template), so interpreter just jumps to corresponding template
- Copy and patch: pregenerate snippets beforehand, so less work at JIT time. Just twiddle the snippet holes.
Implementations
- PyPy: meta-tracing approach
- V8
- 3 tiers
- Ignition: interpreter
- Maglev: fast optimizing compiler
- TurboFan: slow optimizing compiler
- source
- JVM
- C1 / HotSpot Client: simple optimizing compiler
- C2 / HotSpot Server: sophisticated optimizing compiler
- invokedynamic: flexible way to invoke method handles, you can provide the dispatching logic
- Object repr: header + fields
- Header
- Reference to a class object
- Monitor (lock word)
- Identity hashcode
- GC flags
- Fields: may be reordered in sake of size optimization, alignment, or target
architecture specifics
- source