Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Devirtualization of method calls

3,270 views

Published on

JIT and method call devirtualization

Slide from meet up, 18 Apr 2013, Moscow

Published in: Technology, Health & Medicine
  • Be the first to comment

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

×