SlideShare une entreprise Scribd logo
1  sur  25
JAVA JIT
Compilation and optimization
AGENDA
o What is JIT
o Types - Client, Server, Tiered
o Main optimizations approach
o JIT tuning
o Conclusions
2
WHAT IS JIT
o Just In Time compiler
o Compilation done during execution of a
program – at run time – rather than prior to
execution
o First presented at 1960 in LISP
o Java, .NET, JS…
o Oracle HotSpot, IBM J9, Azul…
3
WHAT IS JIT
o JIT separates optimization from SD (just update JVM
- not improve code, tune for your platform)
o JIT'ing requires Profiling
• Because you don't want to JIT everything
o Profiling allows better code-gen
• Inline what’s hot
• Loop unrolling, range-check elimination, etc
• Branch prediction, spill-code-gen, scheduling
4
HOTSPOT JIT CLIENT (C1) WORKFLOW
5
Java
Source Bytecode compiler
Bytecode
Optimized
code
JIT Compiler
Run time
1.5K invocations 
JIT CLIENT (C1)
o Produced Compilations quickly
o Generated code runs relatively slowly
6
HOTSPOT JIT SERVER (C2) WORKFLOW
7
Java
Source Bytecode compiler
Bytecode
Optimized
code (native)
HotSpot info
Profiler
JIT compiler
(optimization)
Run time
JIT compiler
(deoptimization)
10K invocations
HOTSPOT JIT SERVER (C2)
o Produce compilations slowly (long warm-up)
o Generated code runs fast
o Profiler guided
o Speculative
8
HOTSPOT JIT TIERED (C2)
o Available from Java 7
o Default in Java 8
o Best of C1 and C2 approaches
o Level0=Interpreter
o Level1-3=C1
o #1 – C1 w/o profiling
o #2 – C1 with basic profiling (invocations)
o #3 – C1 w full profiling (~35% overhead)
o Level4=C2
9
KEYS FOR JIT VERSION
10
o -client
o -server (-d64)
o -server (-d64) -XX:+TieredCompilation
DEFAULT JIT VERSION
11
Install bits -client -server -d64
Linux 32-bit 32-bit client compiler 32-bit server compiler Error
Linux 64-bit 64-bit server compiler 64-bit server compiler 64-bit server compiler
Mac OS X 64-bit server compiler 64-bit server compiler 64-bit server compiler
Windows 32-bit 32-bit client compiler 32-bit server compiler Error
Windows 64-bit 64-bit server compiler 64-bit server compiler 64-bit server compiler
OS Default compiler
Windows, 32-bit, any number of CPUs -client
Windows, 64-bit, any number of CPUs -server
MacOS, any number of CPUs -server
Linux/Solaris, 32-bit, 1 CPU -client
Linux/Solaris, 32-bit, 2 or more CPUs -server
Linux, 64-bit, any number of CPUs -server
*In Java 8 the server compiler is the default in any of these cases
Information about default compiler
% java -version
java version "1.7.0" Java(TM) SE Runtime Environment (build
1.7.0-b147)
Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode)
OPTIMIZATIONS IN HOTSPOT JVM
12
• compiler tactics
• delayed compilation
• tiered compilation
• on-stack replacement
• delayed reoptimization
• program dependence graph rep.
• static single assignment rep.
• proof-based techniques
– exact type inference
– memory value inference
– memory value tracking
– constant folding
– reassociation
– operator strength reduction
– null check elimination
– type test strength reduction
– type test elimination
– algebraic simplification
– common subexpression elimination
– integer range typing
• flow-sensitive rewrites
– conditional constant propagation
– dominating test detection
– flow-carried type narrowing
– dead code elimination
• language-specific techniques
• class hierarchy analysis
• devirtualization
• symbolic constant propagation
• autobox elimination
• escape analysis
• lock elision
• lock fusion
• de-reflection
• speculative (profile-based) techniques
• optimistic nullness assertions
• optimistic type assertions
• optimistic type strengthening
• optimistic array length strengthening
• untaken branch pruning
• optimistic N-morphic inlining
• branch frequency prediction
• call frequency prediction
• memory and placement transformation
expression hoisting
expression sinking
redundant store elimination
adjacent store fusion
card-mark elimination
merge-point splitting
• loop transformations
• loop unrolling
• loop peeling
• safepoint elimination
• iteration range splitting
• range check elimination
• loop vectorization
• global code shaping
• inlining (graph integration)
• global code motion
• heat-based code layout
• switch balancing
• throw inlining
• control flow graph transformation
• local code scheduling
• local code bundling
• delay slot filling
• graph-coloring register allocation
• linear scan register allocation
• live range splitting
• copy coalescing
• constant splitting
• copy removal
• address mode matching
• instruction peepholing
• DFA-based code generator
INLINING – MOTHER OF OPTIMIZATION
13
Before After
*Using JVM Devirtualization if needed
Frequency and size matter
int addAll(int max){
int accum=0;
for (int i=0;i<max;i++) {
accum = add(accum, i);
}
return accum;
}
}
int add(int a, int b) {return a+b;}
int addAll(int max){
int accum=0;
for (int i=0;i<max;i++) {
accum = accum+i;
}
return accum;
}
}
int add(int a, int b) {return a+b;}
OSR – ON-STACK REPLACEMENT
14
oRunning method never exits?
oBut it’s getting really hot?
oGenerally means loops, back-branching
oCompile and replace while running
oNot typically useful in large systems
oLooks great on benchmarks!
ESCAPE ANALYSIS
15
oObject is referenced only inside some loop; no
other code can ever access that object?
oIt needn’t get a synchronization lock when
calling the methods working with object
oIt needn’t store the fields in memory; it can
keep that value in a register
oSimilarly it can store the objects references in a
register
ESCAPE ANALYSIS
16
public class Factorial {
private BigInteger factorial;
private int n;
public Factorial(int n) {
this.n = n;
}
public synchronized BigInteger getFactorial() {
if (factorial == null) factorial =...;
return factorial;
}
}
ArrayList< BigInteger > list = new ArrayList < BigInteger >();
for ( int i = 0 ; i < 100 ; i ++) {
Factorial factorial = new Factorial ( i );
list.add(factorial.getFactorial ());
}
ESCAPE ANALYSIS (SIMPLE CASE)
17
oIt needn’t get a synchronization lock when
calling the getFactorial() method.
oIt needn’t store the field n in memory; it can
keep that value in a register.
oIt can just keep track of the individual fields of
the object.
oSometime – it needn’t to execute it at all.
JIT TUNING
(THESE MIGHT SAVE YOU )
o -client , -server or -XX:+TieredCompilation
o -XX:ReservedCodeCacheSize=, -XX:InitialCodeCacheSize=
19
JIT TUNING
o -XX:CompileThreshold=invocation value for compiling
o -XX:CICompilerCount= number of threads
o -XX:MaxFreqInlineSize=for hot methods (default value 325
bytes)
o -XX:MaxInlineSize= method smaller this will be inlined anyway
(default value 35 bytes)
20
WANT TO GET MORE DETAILS?
(BE CAREFUL WITH USING THEM ON PRODUCTION)
o -XX:+UnlockDiagnosticVMOptions
o -XX:+TraceClassLoading
o -XX:+LogCompilation
o -XX:+PrintAssembly
o -XX:+PrintCompilation - info about compiled methods
o -XX:+PrintInlining – info about inlining decisions
o -XX:CompileCommand=… - to control compilation policy
21
WANT TO GET MORE DETAILS? – LOGS 
22
WANT TO GET MORE DETAILS – JITWATCH, JSTAT
23
CONCLUSIONS
o KISS, SOLID, DRY, YAGNI – all well-known principles are
perfect for JIT to make his job
o Your code will be optimized and compiled, de-compiled
o There is a lot of various algorithms to do it inside JVM
o You need to reserve memory for compiled code
(CodeCache inside Metaspace/Permgen)
o To get full performance throttle JVM needs to warm-up
o Micro benchmarks lie to you. All the time
24
WHAT WE DIDN’T TOUCH
o Deoptimazing
o Specific benchmark for compilers
o Specific compiled code examples
o …
25
Q&A
26

Contenu connexe

Tendances

Dissecting the Hotspot JVM
Dissecting the Hotspot JVMDissecting the Hotspot JVM
Dissecting the Hotspot JVMIvan Ivanov
 
不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)Douglas Chen
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance TuningMinh Hoang
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu WorksZhen Wei
 
Return-Oriented Programming: Exploits Without Code Injection
Return-Oriented Programming: Exploits Without Code InjectionReturn-Oriented Programming: Exploits Without Code Injection
Return-Oriented Programming: Exploits Without Code Injectionguest9f4856
 
Haskell Symposium 2010: An LLVM backend for GHC
Haskell Symposium 2010: An LLVM backend for GHCHaskell Symposium 2010: An LLVM backend for GHC
Haskell Symposium 2010: An LLVM backend for GHCdterei
 
Georgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityGeorgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityDefconRussia
 
Dive into ROP - a quick introduction to Return Oriented Programming
Dive into ROP - a quick introduction to Return Oriented ProgrammingDive into ROP - a quick introduction to Return Oriented Programming
Dive into ROP - a quick introduction to Return Oriented ProgrammingSaumil Shah
 
JVM and Garbage Collection Tuning
JVM and Garbage Collection TuningJVM and Garbage Collection Tuning
JVM and Garbage Collection TuningKai Koenig
 
한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32HANCOM MDS
 
JVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesJVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesKris Mok
 
Instruction Combine in LLVM
Instruction Combine in LLVMInstruction Combine in LLVM
Instruction Combine in LLVMWang Hsiangkai
 
An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
 An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
An Open Discussion of RISC-V BitManip, trends, and comparisons _ ClaireRISC-V International
 
SystemVerilog Assertions verification with SVAUnit - DVCon US 2016 Tutorial
SystemVerilog Assertions verification with SVAUnit - DVCon US 2016 TutorialSystemVerilog Assertions verification with SVAUnit - DVCon US 2016 Tutorial
SystemVerilog Assertions verification with SVAUnit - DVCon US 2016 TutorialAmiq Consulting
 
Java performance monitoring
Java performance monitoringJava performance monitoring
Java performance monitoringSimon Ritter
 
Translation Cache Policies for Dynamic Binary Translation
Translation Cache Policies for Dynamic Binary TranslationTranslation Cache Policies for Dynamic Binary Translation
Translation Cache Policies for Dynamic Binary TranslationSaber Ferjani
 

Tendances (20)

Dissecting the Hotspot JVM
Dissecting the Hotspot JVMDissecting the Hotspot JVM
Dissecting the Hotspot JVM
 
不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
Qemu JIT Code Generator and System Emulation
Qemu JIT Code Generator and System EmulationQemu JIT Code Generator and System Emulation
Qemu JIT Code Generator and System Emulation
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
 
Return-Oriented Programming: Exploits Without Code Injection
Return-Oriented Programming: Exploits Without Code InjectionReturn-Oriented Programming: Exploits Without Code Injection
Return-Oriented Programming: Exploits Without Code Injection
 
Haskell Symposium 2010: An LLVM backend for GHC
Haskell Symposium 2010: An LLVM backend for GHCHaskell Symposium 2010: An LLVM backend for GHC
Haskell Symposium 2010: An LLVM backend for GHC
 
Boosting Developer Productivity with Clang
Boosting Developer Productivity with ClangBoosting Developer Productivity with Clang
Boosting Developer Productivity with Clang
 
Georgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityGeorgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software security
 
Dive into ROP - a quick introduction to Return Oriented Programming
Dive into ROP - a quick introduction to Return Oriented ProgrammingDive into ROP - a quick introduction to Return Oriented Programming
Dive into ROP - a quick introduction to Return Oriented Programming
 
JVM and Garbage Collection Tuning
JVM and Garbage Collection TuningJVM and Garbage Collection Tuning
JVM and Garbage Collection Tuning
 
한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32
 
Opal compiler
Opal compilerOpal compiler
Opal compiler
 
JVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesJVM: A Platform for Multiple Languages
JVM: A Platform for Multiple Languages
 
Instruction Combine in LLVM
Instruction Combine in LLVMInstruction Combine in LLVM
Instruction Combine in LLVM
 
An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
 An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
An Open Discussion of RISC-V BitManip, trends, and comparisons _ Claire
 
SystemVerilog Assertions verification with SVAUnit - DVCon US 2016 Tutorial
SystemVerilog Assertions verification with SVAUnit - DVCon US 2016 TutorialSystemVerilog Assertions verification with SVAUnit - DVCon US 2016 Tutorial
SystemVerilog Assertions verification with SVAUnit - DVCon US 2016 Tutorial
 
Java performance monitoring
Java performance monitoringJava performance monitoring
Java performance monitoring
 
JVM++: The Graal VM
JVM++: The Graal VMJVM++: The Graal VM
JVM++: The Graal VM
 
Translation Cache Policies for Dynamic Binary Translation
Translation Cache Policies for Dynamic Binary TranslationTranslation Cache Policies for Dynamic Binary Translation
Translation Cache Policies for Dynamic Binary Translation
 

Similaire à Java Jit. Compilation and optimization by Andrey Kovalenko

JVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixJVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixCodemotion Tel Aviv
 
Eclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JITEclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JITEclipse Day India
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceESUG
 
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
The Performance Engineer's Guide To HotSpot Just-in-Time CompilationThe Performance Engineer's Guide To HotSpot Just-in-Time Compilation
The Performance Engineer's Guide To HotSpot Just-in-Time CompilationMonica Beckwith
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance TunningTerry Cho
 
Exploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Exploiting GPU's for Columnar DataFrrames by Kiran LonikarExploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Exploiting GPU's for Columnar DataFrrames by Kiran LonikarSpark Summit
 
SMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgiSMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgiTakuya ASADA
 
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...Databricks
 
Clr jvm implementation differences
Clr jvm implementation differencesClr jvm implementation differences
Clr jvm implementation differencesJean-Philippe BEMPEL
 
Building an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent ConnectionsBuilding an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent Connections Renaun Erickson
 
Experience on porting HIGHMEM and KASAN to RISC-V at COSCUP 2020
Experience on porting HIGHMEM and KASAN to RISC-V at COSCUP 2020Experience on porting HIGHMEM and KASAN to RISC-V at COSCUP 2020
Experience on porting HIGHMEM and KASAN to RISC-V at COSCUP 2020Eric Lin
 
So You Want To Write Your Own Benchmark
So You Want To Write Your Own BenchmarkSo You Want To Write Your Own Benchmark
So You Want To Write Your Own BenchmarkDror Bereznitsky
 
SPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic librarySPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic libraryAdaCore
 
Digging for Android Kernel Bugs
Digging for Android Kernel BugsDigging for Android Kernel Bugs
Digging for Android Kernel BugsJiahong Fang
 
Code lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzCode lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzIvan Krylov
 
12 Monkeys Inside JS Engine
12 Monkeys Inside JS Engine12 Monkeys Inside JS Engine
12 Monkeys Inside JS EngineChengHui Weng
 
Bh ad-12-stealing-from-thieves-saher-slides
Bh ad-12-stealing-from-thieves-saher-slidesBh ad-12-stealing-from-thieves-saher-slides
Bh ad-12-stealing-from-thieves-saher-slidesMatt Kocubinski
 
Stealing from Thieves: Breaking IonCUBE VM to RE Exploit Kits
Stealing from Thieves: Breaking IonCUBE VM to RE Exploit KitsStealing from Thieves: Breaking IonCUBE VM to RE Exploit Kits
Stealing from Thieves: Breaking IonCUBE VM to RE Exploit KitsМохачёк Сахер
 

Similaire à Java Jit. Compilation and optimization by Andrey Kovalenko (20)

JVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixJVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, Wix
 
Eclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JITEclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JIT
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performance
 
Jvm memory model
Jvm memory modelJvm memory model
Jvm memory model
 
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
The Performance Engineer's Guide To HotSpot Just-in-Time CompilationThe Performance Engineer's Guide To HotSpot Just-in-Time Compilation
The Performance Engineer's Guide To HotSpot Just-in-Time Compilation
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunning
 
Exploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Exploiting GPU's for Columnar DataFrrames by Kiran LonikarExploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Exploiting GPU's for Columnar DataFrrames by Kiran Lonikar
 
SMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgiSMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgi
 
Fedor Polyakov - Optimizing computer vision problems on mobile platforms
Fedor Polyakov - Optimizing computer vision problems on mobile platforms Fedor Polyakov - Optimizing computer vision problems on mobile platforms
Fedor Polyakov - Optimizing computer vision problems on mobile platforms
 
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
 
Clr jvm implementation differences
Clr jvm implementation differencesClr jvm implementation differences
Clr jvm implementation differences
 
Building an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent ConnectionsBuilding an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent Connections
 
Experience on porting HIGHMEM and KASAN to RISC-V at COSCUP 2020
Experience on porting HIGHMEM and KASAN to RISC-V at COSCUP 2020Experience on porting HIGHMEM and KASAN to RISC-V at COSCUP 2020
Experience on porting HIGHMEM and KASAN to RISC-V at COSCUP 2020
 
So You Want To Write Your Own Benchmark
So You Want To Write Your Own BenchmarkSo You Want To Write Your Own Benchmark
So You Want To Write Your Own Benchmark
 
SPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic librarySPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic library
 
Digging for Android Kernel Bugs
Digging for Android Kernel BugsDigging for Android Kernel Bugs
Digging for Android Kernel Bugs
 
Code lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzCode lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf Linz
 
12 Monkeys Inside JS Engine
12 Monkeys Inside JS Engine12 Monkeys Inside JS Engine
12 Monkeys Inside JS Engine
 
Bh ad-12-stealing-from-thieves-saher-slides
Bh ad-12-stealing-from-thieves-saher-slidesBh ad-12-stealing-from-thieves-saher-slides
Bh ad-12-stealing-from-thieves-saher-slides
 
Stealing from Thieves: Breaking IonCUBE VM to RE Exploit Kits
Stealing from Thieves: Breaking IonCUBE VM to RE Exploit KitsStealing from Thieves: Breaking IonCUBE VM to RE Exploit Kits
Stealing from Thieves: Breaking IonCUBE VM to RE Exploit Kits
 

Dernier

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 

Dernier (20)

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 

Java Jit. Compilation and optimization by Andrey Kovalenko

  • 2. AGENDA o What is JIT o Types - Client, Server, Tiered o Main optimizations approach o JIT tuning o Conclusions 2
  • 3. WHAT IS JIT o Just In Time compiler o Compilation done during execution of a program – at run time – rather than prior to execution o First presented at 1960 in LISP o Java, .NET, JS… o Oracle HotSpot, IBM J9, Azul… 3
  • 4. WHAT IS JIT o JIT separates optimization from SD (just update JVM - not improve code, tune for your platform) o JIT'ing requires Profiling • Because you don't want to JIT everything o Profiling allows better code-gen • Inline what’s hot • Loop unrolling, range-check elimination, etc • Branch prediction, spill-code-gen, scheduling 4
  • 5. HOTSPOT JIT CLIENT (C1) WORKFLOW 5 Java Source Bytecode compiler Bytecode Optimized code JIT Compiler Run time 1.5K invocations 
  • 6. JIT CLIENT (C1) o Produced Compilations quickly o Generated code runs relatively slowly 6
  • 7. HOTSPOT JIT SERVER (C2) WORKFLOW 7 Java Source Bytecode compiler Bytecode Optimized code (native) HotSpot info Profiler JIT compiler (optimization) Run time JIT compiler (deoptimization) 10K invocations
  • 8. HOTSPOT JIT SERVER (C2) o Produce compilations slowly (long warm-up) o Generated code runs fast o Profiler guided o Speculative 8
  • 9. HOTSPOT JIT TIERED (C2) o Available from Java 7 o Default in Java 8 o Best of C1 and C2 approaches o Level0=Interpreter o Level1-3=C1 o #1 – C1 w/o profiling o #2 – C1 with basic profiling (invocations) o #3 – C1 w full profiling (~35% overhead) o Level4=C2 9
  • 10. KEYS FOR JIT VERSION 10 o -client o -server (-d64) o -server (-d64) -XX:+TieredCompilation
  • 11. DEFAULT JIT VERSION 11 Install bits -client -server -d64 Linux 32-bit 32-bit client compiler 32-bit server compiler Error Linux 64-bit 64-bit server compiler 64-bit server compiler 64-bit server compiler Mac OS X 64-bit server compiler 64-bit server compiler 64-bit server compiler Windows 32-bit 32-bit client compiler 32-bit server compiler Error Windows 64-bit 64-bit server compiler 64-bit server compiler 64-bit server compiler OS Default compiler Windows, 32-bit, any number of CPUs -client Windows, 64-bit, any number of CPUs -server MacOS, any number of CPUs -server Linux/Solaris, 32-bit, 1 CPU -client Linux/Solaris, 32-bit, 2 or more CPUs -server Linux, 64-bit, any number of CPUs -server *In Java 8 the server compiler is the default in any of these cases Information about default compiler % java -version java version "1.7.0" Java(TM) SE Runtime Environment (build 1.7.0-b147) Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode)
  • 12. OPTIMIZATIONS IN HOTSPOT JVM 12 • compiler tactics • delayed compilation • tiered compilation • on-stack replacement • delayed reoptimization • program dependence graph rep. • static single assignment rep. • proof-based techniques – exact type inference – memory value inference – memory value tracking – constant folding – reassociation – operator strength reduction – null check elimination – type test strength reduction – type test elimination – algebraic simplification – common subexpression elimination – integer range typing • flow-sensitive rewrites – conditional constant propagation – dominating test detection – flow-carried type narrowing – dead code elimination • language-specific techniques • class hierarchy analysis • devirtualization • symbolic constant propagation • autobox elimination • escape analysis • lock elision • lock fusion • de-reflection • speculative (profile-based) techniques • optimistic nullness assertions • optimistic type assertions • optimistic type strengthening • optimistic array length strengthening • untaken branch pruning • optimistic N-morphic inlining • branch frequency prediction • call frequency prediction • memory and placement transformation expression hoisting expression sinking redundant store elimination adjacent store fusion card-mark elimination merge-point splitting • loop transformations • loop unrolling • loop peeling • safepoint elimination • iteration range splitting • range check elimination • loop vectorization • global code shaping • inlining (graph integration) • global code motion • heat-based code layout • switch balancing • throw inlining • control flow graph transformation • local code scheduling • local code bundling • delay slot filling • graph-coloring register allocation • linear scan register allocation • live range splitting • copy coalescing • constant splitting • copy removal • address mode matching • instruction peepholing • DFA-based code generator
  • 13. INLINING – MOTHER OF OPTIMIZATION 13 Before After *Using JVM Devirtualization if needed Frequency and size matter int addAll(int max){ int accum=0; for (int i=0;i<max;i++) { accum = add(accum, i); } return accum; } } int add(int a, int b) {return a+b;} int addAll(int max){ int accum=0; for (int i=0;i<max;i++) { accum = accum+i; } return accum; } } int add(int a, int b) {return a+b;}
  • 14. OSR – ON-STACK REPLACEMENT 14 oRunning method never exits? oBut it’s getting really hot? oGenerally means loops, back-branching oCompile and replace while running oNot typically useful in large systems oLooks great on benchmarks!
  • 15. ESCAPE ANALYSIS 15 oObject is referenced only inside some loop; no other code can ever access that object? oIt needn’t get a synchronization lock when calling the methods working with object oIt needn’t store the fields in memory; it can keep that value in a register oSimilarly it can store the objects references in a register
  • 16. ESCAPE ANALYSIS 16 public class Factorial { private BigInteger factorial; private int n; public Factorial(int n) { this.n = n; } public synchronized BigInteger getFactorial() { if (factorial == null) factorial =...; return factorial; } } ArrayList< BigInteger > list = new ArrayList < BigInteger >(); for ( int i = 0 ; i < 100 ; i ++) { Factorial factorial = new Factorial ( i ); list.add(factorial.getFactorial ()); }
  • 17. ESCAPE ANALYSIS (SIMPLE CASE) 17 oIt needn’t get a synchronization lock when calling the getFactorial() method. oIt needn’t store the field n in memory; it can keep that value in a register. oIt can just keep track of the individual fields of the object. oSometime – it needn’t to execute it at all.
  • 18. JIT TUNING (THESE MIGHT SAVE YOU ) o -client , -server or -XX:+TieredCompilation o -XX:ReservedCodeCacheSize=, -XX:InitialCodeCacheSize= 19
  • 19. JIT TUNING o -XX:CompileThreshold=invocation value for compiling o -XX:CICompilerCount= number of threads o -XX:MaxFreqInlineSize=for hot methods (default value 325 bytes) o -XX:MaxInlineSize= method smaller this will be inlined anyway (default value 35 bytes) 20
  • 20. WANT TO GET MORE DETAILS? (BE CAREFUL WITH USING THEM ON PRODUCTION) o -XX:+UnlockDiagnosticVMOptions o -XX:+TraceClassLoading o -XX:+LogCompilation o -XX:+PrintAssembly o -XX:+PrintCompilation - info about compiled methods o -XX:+PrintInlining – info about inlining decisions o -XX:CompileCommand=… - to control compilation policy 21
  • 21. WANT TO GET MORE DETAILS? – LOGS  22
  • 22. WANT TO GET MORE DETAILS – JITWATCH, JSTAT 23
  • 23. CONCLUSIONS o KISS, SOLID, DRY, YAGNI – all well-known principles are perfect for JIT to make his job o Your code will be optimized and compiled, de-compiled o There is a lot of various algorithms to do it inside JVM o You need to reserve memory for compiled code (CodeCache inside Metaspace/Permgen) o To get full performance throttle JVM needs to warm-up o Micro benchmarks lie to you. All the time 24
  • 24. WHAT WE DIDN’T TOUCH o Deoptimazing o Specific benchmark for compilers o Specific compiled code examples o … 25