Devirtualization of method callsDirty tricks of JIT compilersAlexey Ragozinalexey.ragozin@gmail.comApr 2013
Old good C++01011001001010101010011010101010010101010100101010101010101010101010101010101010101010101010001000: methodA02:...
Old good C++01011001001010101010011010101010010101010100101010101010101010101010101010101010101010101010001011101010010001...
Old good C++Multiple inheritance – more funAB CD DAB CDVs
ProblemsTwo memory reads before jump Memory access is serialized instruction pipeline is blocked
Dynamic languages Every call is virtual No predefined classes Multiple inheritanceNightmare for super scalar CPU
Call site polymorphismA particular call sitein most casewould be callingexactly one method instanceCall sites are mostly m...
Exploiting monomorthismTracing JIT JavaScript – Mozila TraceMonkey Python – PyPyProfiling for whole method JIT JVM
Tracing JITInterpretation phase Record actions, record branch conditionsCompiling trace Actions compiled into branchless...
Tracing JITMozila’s TraceMonkey1. IncrementalDynamicCodeGenerationwithTraceTreeshttp://www.ics.uci.edu/~franz/Site/pubs-pd...
Tracing JITLimitation Trace is EXPENSIVE Falling out of path is EXPENSIVE A lot of code is executed just once– wasting ...
Whole method JITJVM Classic whole method JIT Profile “morphism” of call sites Multi tier compiler Dynamics recompilati...
Whole method JITCall sites Monomorphic Bimorphic Megamorphic
Invoke dynamicProblem Interpreters tends to producemegamorphic sitesInvoke dynamic Detach call site into manageable object
More JVM back magicOn stack replacement Code for method could be replaced withoutreentering to a methodScalar replacement...
THANK YOUalexey.ragozin@gmail.com
Upcoming SlideShare
Loading in …5
×

Devirtualization of method calls

3,042 views

Published on

JIT and method call devirtualization

Slide from meet up, 18 Apr 2013, Moscow

Published in: Technology, Health & Medicine
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,042
On SlideShare
0
From Embeds
0
Number of Embeds
1,197
Actions
Shares
0
Downloads
15
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

Devirtualization of method calls

  1. 1. Devirtualization of method callsDirty tricks of JIT compilersAlexey Ragozinalexey.ragozin@gmail.comApr 2013
  2. 2. Old good C++01011001001010101010011010101010010101010100101010101010101010101010101010101010101010101010001000: methodA02: methodC03: methodDCODEOBJECTVTABLE01: methodBSimple case
  3. 3. Old good C++01011001001010101010011010101010010101010100101010101010101010101010101010101010101010101010001011101010010001111000001010100101010000: methodA02: methodC03: methodDCODEOBJECTVTABLE01: methodB00: methodX02: methodZ01: methodYVTABLEMultiple inheritance
  4. 4. Old good C++Multiple inheritance – more funAB CD DAB CDVs
  5. 5. ProblemsTwo memory reads before jump Memory access is serialized instruction pipeline is blocked
  6. 6. Dynamic languages Every call is virtual No predefined classes Multiple inheritanceNightmare for super scalar CPU
  7. 7. Call site polymorphismA particular call sitein most casewould be callingexactly one method instanceCall sites are mostly monomorthic!
  8. 8. Exploiting monomorthismTracing JIT JavaScript – Mozila TraceMonkey Python – PyPyProfiling for whole method JIT JVM
  9. 9. Tracing JITInterpretation phase Record actions, record branch conditionsCompiling trace Actions compiled into branchless machine code Guards added for conditions If guard is broken – fall back to interpretation
  10. 10. Tracing JITMozila’s TraceMonkey1. IncrementalDynamicCodeGenerationwithTraceTreeshttp://www.ics.uci.edu/~franz/Site/pubs-pdf/ICS-TR-06-16.pdfPyPy RPython – restrict python dialect compiling to C Rpython based interpreter trace JITed by runtime1. http://tratt.net/laurie/research/pubs/papers/bolz_tratt__the_impact_of_metatracing_on_vm_design_and_implementation.pdf
  11. 11. Tracing JITLimitation Trace is EXPENSIVE Falling out of path is EXPENSIVE A lot of code is executed just once– wasting resources on tracing
  12. 12. Whole method JITJVM Classic whole method JIT Profile “morphism” of call sites Multi tier compiler Dynamics recompilation / decompilation
  13. 13. Whole method JITCall sites Monomorphic Bimorphic Megamorphic
  14. 14. Invoke dynamicProblem Interpreters tends to producemegamorphic sitesInvoke dynamic Detach call site into manageable object
  15. 15. More JVM back magicOn stack replacement Code for method could be replaced withoutreentering to a methodScalar replacement Object not leaving method scopecan be reduced to a number of local variables
  16. 16. THANK YOUalexey.ragozin@gmail.com

×