Devirtualization of method calls
-
Upload
aragozin -
Category
Technology
-
view
2.116 -
download
2
description
Transcript of Devirtualization of method calls
![Page 2: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/2.jpg)
Old good C++
010110010010101010100110101010100101010101001010101010101010101010101010101010101010101010100010
00: methodA
02: methodC
03: methodD
CODEOBJECT
VTABLE
01: methodB
Simple case
![Page 3: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/3.jpg)
Old good C++
010110010010101010100110101010100101010101001010101010101010101010101010101010101010101010100010111010100100011110000010101001010100
00: methodA
02: methodC
03: methodD
CODEOBJECT
VTABLE
01: methodB
00: methodX
02: methodZ
01: methodY
VTABLE
Multiple inheritance
![Page 4: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/4.jpg)
Old good C++Multiple inheritance – more fun
A
B C
D D
A
B C
D
Vs
![Page 5: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/5.jpg)
Problems
Two memory reads before jump Memory access is serialized instruction pipeline is blocked
![Page 6: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/6.jpg)
Dynamic languages
Every call is virtual No predefined classes Multiple inheritance
Nightmare for super scalar CPU
![Page 7: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/7.jpg)
Call site polymorphism
A particular call sitein most case
would be callingexactly one method instance
Call sites are mostly monomorthic!
![Page 8: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/8.jpg)
Exploiting monomorthism
Tracing JIT JavaScript – Mozila TraceMonkey Python – PyPy
Profiling for whole method JIT JVM
![Page 9: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/9.jpg)
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
![Page 10: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/10.jpg)
Tracing JIT
Mozila’s TraceMonkey1. Incremental Dynamic Code Generation with Trace Trees
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 runtime1. http://tratt.net/laurie/research/pubs/papers/bolz_tratt__the_impact_of_metatrac
ing_on_vm_design_and_implementation.pdf
![Page 11: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/11.jpg)
Tracing JIT
Limitation Trace is EXPENSIVE Falling out of path is EXPENSIVE A lot of code is executed just once
– wasting resources on tracing
![Page 12: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/12.jpg)
Whole method JIT
JVM Classic whole method JIT Profile “morphism” of call sites Multi tier compiler Dynamics recompilation / decompilation
![Page 13: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/13.jpg)
Whole method JIT
Call sites Monomorphic Bimorphic Megamorphic
![Page 14: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/14.jpg)
Invoke dynamic
Problem Interpreters tends to produce
megamorphic sites
Invoke dynamic Detach call site into manageable object
![Page 15: Devirtualization of method calls](https://reader035.fdocuments.in/reader035/viewer/2022062319/55496fdbb4c905dd558b529e/html5/thumbnails/15.jpg)
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