jit compiler design - ittc
TRANSCRIPT
![Page 1: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/1.jpg)
JIT Compiler Design-Idhaya Elango
EECS 768
![Page 2: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/2.jpg)
Agenda
• Introduction
• JIT Compilation
-c1 compiler
-c2 compiler
-Tiered compilation
• C1 Compiler Design
-HIR
-LIR
-Optimizations
-Garbage Collection
-Exception Handling
• C2 Overview
![Page 3: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/3.jpg)
![Page 4: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/4.jpg)
![Page 5: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/5.jpg)
“Just-in-time”
-During Program Execution
-Time is needed to compile “hot” methods
-profiling at run time
-optimistic optimizations
![Page 6: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/6.jpg)
Compilers in Hotspot
![Page 7: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/7.jpg)
SimpleProgram.java
public class SimpleProgram {
static final int CHUNK_SIZE = 1_000;
public static void main(String[] args) {
for ( int i = 0; i < 250; ++i ) {
long startTime = System.nanoTime();
for ( int j = 0; j < CHUNK_SIZE; ++j ) {
new Object();
}
long endTime = System.nanoTime();
System.out.printf("%d\t%d%n", i, endTime - startTime);
}
}
}
![Page 8: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/8.jpg)
![Page 9: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/9.jpg)
![Page 10: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/10.jpg)
-XX:+PrintCompilation
![Page 11: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/11.jpg)
On-Stack-Replacement(OSR)
![Page 12: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/12.jpg)
C1 Compiler
![Page 13: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/13.jpg)
C2 Compiler
![Page 14: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/14.jpg)
Tiered Compilation
![Page 15: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/15.jpg)
Tiered Compilation (Cont’d)
![Page 16: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/16.jpg)
Tiered Compilation in detail
![Page 17: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/17.jpg)
Architecture of Java HotSpot VM
![Page 18: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/18.jpg)
Structure of Java HotSpot Client Compiler
![Page 19: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/19.jpg)
High Level Intermediate Representation(HIR)
![Page 20: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/20.jpg)
Static Single Assignment Form
![Page 21: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/21.jpg)
HIR Example with Control and data flow
![Page 22: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/22.jpg)
HIR Optimizations
![Page 23: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/23.jpg)
Low-Level Intermediate Representation (LIR)
![Page 24: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/24.jpg)
Machine Code
![Page 25: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/25.jpg)
Garbage Collection
• Uses exact garbage collection technique
• Memory split into three generations
Young generation –For new object
Old generation – For long lived objects
![Page 26: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/26.jpg)
Exception Handling
![Page 27: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/27.jpg)
Deoptimization
• Stop the machine code
• Undo the compiled optimizations
• Continue execution of method from Interpreter
![Page 28: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/28.jpg)
C2 Compiler
![Page 29: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/29.jpg)
References• T. Kotzmann, C. Wimmer, H. M¨ossenb¨ock, T. Rodriguez, K. Russell,
and D. Cox. Design of the Java Hotspot client compiler for Java 6. ACM Transactions on Architecture and Code Optimization, 5:7:1–7:32, May 2008. ISSN 1544-3566
• https://github.com/dougqh/jvm-mechanics/tree/d3483e5f54ea3a5ebf3e84caa1b55437f34ee635
• https://www.ethz.ch/content/dam/ethz/special-interest/infk/inst-cs/lst-dam/documents/Education/Classes/Fall2015/210_Compiler_Design/Slides/hotspot.pdf
• https://aboullaite.me/understanding-jit-compiler-just-in-time-compiler/
![Page 30: JIT Compiler Design - ITTC](https://reader030.vdocuments.net/reader030/viewer/2022012013/615870bda2769439874f2e18/html5/thumbnails/30.jpg)
Questions?