SlideShare a Scribd company logo
JIT vs. AOT: Unity And Conflict of
Dynamic and Static Compilers
for Java
Nikita Lipsky
Excelsior LLC
JIT vs. AOT: Unity And Conflict of
Dynamic and Static Compilers
for Java
Nikita Lipsky
Excelsior LLC
3
Once upon a time,
when C++ was new and cool,
+++++++++
4
Once upon a time,
when C++ was new and cool,
+++++++++
5
Once upon a time,
when C++ was new and cool,
all compilers were static
6
Until into this world came…
Java
7
Until into this world came…
Java
Two Ways To Execute Java Bytecode
• Interpret
Slow but portable
• Compile to machine code
Runs on the actual hardware
9
When to compile to native code?
• At application run time
Dynamic (Just-In-Time, JIT) Compilation
• Before the application is launched/deployed
Static (Ahead-Of-Time, AOT) Compilation
10
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers
JIT vs. AOT: Agenda
• Myths around Java AOT
• Java AOT challenges and advantages
• Performance:
– JIT vs. AOT compiler optimizations comparison
• JIT and AOT in various fields of use:
– client-side, server-side, embedded, IOT, mobile
12
Nikita Lipsky
• 20+ years in software development
• Excelsior JET project initiator
– 16+ years of contributions
– compiler engineer
– team lead
– product lead
– etc.
• Twitter: @pjBooms
13
14
Who needs Java AOT
15
Кто знает про Excelsior JET?Кто знает про Excelsior JET?
Java AOT Compilation Myths
16
Myth 1. Java is “too dynamic”
Reflection Dynamic class loading
17
Myth 2. AOT kills WORA
WORA
Write Once
Run Anywhere
BORA
Build Once
Run Anywhere
18
!=
Myth 3. AOT = Small EXE
”I would get a small executable that works
without a JVM (as if I wrote my app in C)”
19
Myth 3. AOT = Small EXE
• What about thousands of standard classes?
• Who will collect the garbage?
• What about reflection?
20
AOT = Smaller Package
Yes, AOT compilation can help you create
a JRE-independent installer smaller than the JRE
installer alone
Javа Runtime Slim-Down:
www.excelsiorjet.com/solutions/java-download-size
21
Java IS “too dynamic”
22
Non-standard Class Loaders
• Override the default reference resolution logic
• Unique namespaces
• Dependency management frameworks
– OSGi: Felix, Equanox
Solve JAR hell problem
• Java EE servers, Eclipse RCP, plugin architectures
23
Non-standard Class Loaders
How to compile such classes statically?
• Compile each class in isolation
– Bad for performance
• Reproduce reference resolution logic of popular
class loaders
– Does not work for arbitrary class loaders
24
Non-standard Class Loaders
25
Classes
Classe
sClasses
Classes
CL1
CL2
CL3
CL4
Non-standard Class Loaders
26CLi: class loader
• CL4• CL3
• CL2• CL1
classes classes
classesclasses
Non-standard Class Loaders
27
• CL4• CL3
• CL2• CL1
classes
classes
classesclasses
Non-standard Class Loaders
28
• CL4• CL3
• CL2• CL1
classes classes
classesclasses
Non-standard Class Loaders
29
Non-standard Class Loaders
30
• CL4• CL3
• CL2• CL1
classes classes
classes
• CL4• CL3
• CL2• CL1
classes classes
Non-standard Class Loaders
31
Non-standard Class Loaders
AOT class loader support scheme:
• Reference resolver in the AOT compiler:
– Determines which class loaders will be created at
run time and assigns a static ID to each
– Breaks down the set of classes by class loader IDs
– Resolves references between classes
32
Non-standard Class Loaders
AOT class loader support scheme contd.:
• At application run time:
– For each class loader instance, compute its ID
– Knowing the ID, “load” the precompiled classes:
• Create a java.lang.Class instance
• Fill it with reflection information
• Let the O/S load code from the executable
33
Non-standard Class Loaders
AOT class loader support scheme contd.:
• At application run time:
– For each class loader instance, compute its ID
– Knowing the ID, “load” the precompiled classes
Known to work for Eclipse RCP
and Tomcat Web apps
34
Why AOT for Java?
35
Protect Code from Decompilers
36
Application Code Protection
• Bytecode emitted by javac is extremely easy to
decompile almost to original source
Proof: http://bytecodeviewer.com/
• Reflection makes name obfuscation labor-
consuming and error prone, hinders code
maintenance
• Possible to guess what obfuscated code does
References to JDK classes remain intact
37
Application Code Protection
• Native machine code can only be effectively
disassembled, but not decompiled
• Application structure not deductible
from disassembler output
• Aggressively optimized native code only
remotely resembles original
38
Application Startup Time
39
Cold Start vs Warm Start
Why a re-started application starts much faster?
– No need to load app code and data from disk
– No need to load system/third-party dynamic
libraries (.DLL, .so) either
40
AOT Is Faster?
• Native code is “thicker” than Java bytecode
• Reading code from disk often takes more
time than its execution, esp. on cold starts
41
AOT IS Faster!
1. Identify code that gets executed on startup
2. Place it at the beginning of the executable
3. Preload the entire “startup segment” in one
sequential read (Makes most difference on rotating media,
slow USB sticks, etc., not so much on SSDs)
42
43
Performance
44
Myth 4. AOT Is Faster
45
Myth 4. AOT Is Faster
“By compiling Java statically, we are making it
equivalent to C, C is faster than Java,
therefore statically compiled Java is faster”
46
Myth 5. JIT Is Faster
47
Myth 5. JIT Is Faster
“Effective optimization of a Java application
is only possible in the presence
of its dynamic execution profile”
48
Compiler Optimizations
– Constant propagation
– Dead code elimination
– Common subexpression
elimination
– Inline substitution
– Method specialization
– Loop unrolling
– Loop versioning
– Loop-invariant code motion
– Tail recursion elimination
– Call devirtualization
– On-stack allocation and
explosion of objects
– Runtime checks removal
– Excess synchronization removal
– Optimal code selection and
bundling
– Instruction scheduling
– Optimal register allocation
– etc.
49
Java == OOP
• Lots of methods
• Lots of small methods (get/set)
• Lots of virtual calls of small methods
50
Call Devirtualization
• Precondition for subsequent inline substitution
• Class hierarchy analysis
Method not overridden => non-virtual call
• Type analysis
new T().foo(); // Non-virtual
// call of T.foo()
• Profile guided
51
A a;
…
a.foo(); 
if (RT_Type(a) in CHA) {
inlined body of foo()
} else {
a.foo();
}
Idea: method not overriden => non-virtual call
Class Hierarchy Analysis (CHA)
52
Type Analysis
Idea:
new A().foo(); // non-virtual call. Always!
53
Type Analysis
A a = b ? new B() : new C();
a.foo();// is it virtual call?
// B, C extend A and do not override A.foo
54
Type Analysis
A a = b ? new B() : new C();
a.foo();
If neither B nor С override A.foo(),
then a.foo()is a non-virtual call again!
(can be inlined)
55
Type Analysis
A a = b ? bar() : baz();
…
a.foo();
If bar() only returns results of new B,
and baz() - only returns results of new С,
then a.foo() is again non-virtual
(can be inlined)
56
Type Analysis
How do we know
what bar() and baz() return?
57
Global Analysis
• Analyses all methods of the program, computing
useful information about each
– whether a method always returns new T();
– whether an argument of a method does not escape to
a shared memory
• Results are then used for optimization of each
particular method
58
Stack Allocation of Objects
• All Java objects are supposed to reside in dynamic
memory – on the Java heap
• But, most objects are small and temporary
• It is desirable to allocate them on the stack
Escape analysis determines whether a locally
created object escapes from the method
stack frame into shared memory
59
Example
for (Object o: getCollection()) {
doSomething(o);
}
60
Example
Iterator iter = getCollection().iterator();
while (iter.hasNext()) {
Object o = iter.next();
doSomething(o);
}
61
Example
Suppose analysis has shown that getCollection()
always returns an ArrayList
ArrayList list = getCollection();
Iterator iter = list.iterator();
while (iter.hasNext()) {
Object o = iter.next();
doSomething(o);
}
62
Example
ArrayList list = getCollection();
ArrayList.ListItr iter = new ListItr(list);
while (iter.hasNext()) {
Object o = iter.next();
doSomething(o);
}
63
Example
ArrayList list = getCollection();
ArrayList.ListItr iter = onStack ListItr();
iter.this$0 = list;
iter.cursor = 0;
iter.size = list.elemData.length;
while (iter.hasNext()) {
Object o = iter.next();
doSomething(o);
}
64
Example
ArrayList list = getCollection();
ArrayList.ListItr iter = onStack ListItr(list);
iter.this$0 = list;
iter.cursor = 0;
iter.size = list.elemData.length;
while (iter.cursor < iter.size) {
int index = iter.cursor++;
Object o = iter.this$0.elemData[index];
doSomething(o);
}
65
Example
ArrayList list = getCollection();
int cursor = 0;
int size = list.elemData.length;
while (cursor < size) {
Object o = list.elemData[cursor++];
doSomething(o);
}
66
Example
ArrayList list = getCollection();
int size = list.elemData.length;
for (int i = 0; i < size; i++) {
doSomething(list.elemData[i]);
}
67
Analysis & Optimizations…
• …are often quite complicated
• …require iterative re-computation
• …, if global, depend on the entire program
68
Analysis & Optimizations…
• …are often quite complicated
• …require iterative recomputation
• …, if global, depend on the entire program
Can a JIT compiler afford
all or any of that?
Analysis & Optimizations…
• …are often quite complicated
• …require iterative recomputations
• …, if global, depend on the entire program
Can a JIT compiler afford
all or any of that?
70
Analysis & Optimizations…
• …are often quite complicated
• …require iterative recomputations
• …, if global, depend on the entire program
Can a JIT compiler afford
all or any of that?
Dynamic Optimizations
• Profiling and selective compilation
• Inline substitution based on execution profile
• Hot execution traces optimization
• Optimal instruction selection
Hot Code vs Warm Code
Q: What happens when an app with no
distinctly hot code runs on a typical JVM?
A: Long warmup with results not stored
for future reuse
Typical case: UI-centric applications
73
JFCMark (Short Run)
0%
50%
100%
150%
200%
250%
2 core Celeron, 2.60Ghz 4 core i5, 3.8GZ
Excelsior JET
HotSpot client
HotSpot server
Bigger – better
74
JFCMark (Long Run)
0%
20%
40%
60%
80%
100%
120%
140%
160%
2 core Celeron, 2.60Ghz 4 core i5, 3.8GZ
Excelsior JET
HotSpot client
HotSpot server
75
Bigger – better
Profile Guided Optimizations
Can a static compiler use
dynamic execution profiles as input?
76
Server side
• CPU time in the cloud costs
money
• After some time, execution profile of a server app
stabilizes
• Why not pass it over to the AOT compiler?
77
AOT on the Server side
• Stable performance and predictable latency
– no code de-optimizations occur at run-time
• Work at full speed right from the start
– good for load balancing
• Better startup time
– good when many servers start simultaneously
• Still protects the code from decompilation
78
Embedded/IoT
• The less powerful the hardware, the more
expensive dynamic compilation becomes
• Embedded systems typically have less
computing power than desktops and servers
79
Mobile
• JVM on Mobile:
– Platform classes
– Memory Manager and GC
– Reflection
– JIT Compiler
What is missing?
80
Mobile
• JVM on Mobile:
– Platform classes
– Memory Manager and GC
– Reflection
– JIT Compiler
What is missing?
81
Mobile
• JVM on Mobile:
– Platform classes
– Memory Manager and GC
– Reflection
– JIT Compiler
What is missing?
82
Mobile
• JVM on Mobile:
– Platform classes
– Memory Manager and GC
– Reflection
– JIT Compiler
What is missing?
83
Mobile
• JVM on Mobile:
– Platform classes
– Memory Manager and GC
– Reflection
– JIT Compiler
What is missing?
84
Mobile
• JVM on Mobile:
– Platform classes
– Memory Manager and GC
– Reflection
– JIT Compiler
What is missing?
85
Mobile
• JVM on Mobile:
– Platform classes
– Memory Manager and GC
– Reflection
– JIT Compiler
Charger!
86
Mobile
• Wireless devices have batteries
• Does it make sense to spend power on
dynamic compilation?
87
iOS
• iOS policy prohibits creation of any native
code during application run time
• Getting Java apps to work on iOS requires
either an interpreting JVM or an AOT compiler
88
AOT Java Compilers in 2000
Desktop/Server:
BulletTrain
Excelsior JET
GNU Compiler for Java (GCJ)
IBM VisualAge for Java
Supercede/JOVE
TowerJ
Embedded/Mobile:
Diab FastJ
Esmertec Jbed ME
GCJ
IBM J9
Sun Java ME
(custom offerings)
89
AOT Java Compilers in 2017
Desktop/Server:
Excelsior JET
GCJ (RIP)
IBM Java SDK for AIX
IBM Java SDK for z/OS
Coming soon:
HotSpot AOT (JEP-295)
Embedded/Mobile:
Excelsior JET Embedded
IBM WebSphere Real Time
Oracle Java ME Embedded Client
Codename One
Avian
Android ART
RoboVM (RIP)
Multi-OS Engine
90
AOT Java Compilers in 2017
Desktop/Server:
Excelsior JET
GCJ (RIP)
IBM Java SDK for AIX
IBM Java SDK for z/OS
Coming soon:
HotSpot AOT (JEP-295)
Embedded/Mobile:
Excelsior JET Embedded
IBM WebSphere Real Time
Oracle Java ME Embedded Client
Codename One
Avian
Android ART
RoboVM (RIP)
Multi-OS Engine
91
Static compilation of Java apps:
92
Conclusion
Static compilation of Java apps:
93
Possible
Conclusion
Static compilation of Java apps:
94
Possible
Preserving all Java features
Conclusion
Static compilation of Java apps:
95
Possible
Preserving all Java features
Useful in many aspects
Conclusion
Conclusion
• JIT and AOT have their unique advantages
• Synthesis of two approaches will give
maximum benefits
96
Conclusion
• JIT and AOT have their unique advantages
• Synthesis of the two approaches will bring
maximum benefits
97
Q & A
Nikita Lipsky,
Excelsior
nlipsky@excelsior-usa.com
twitter: @pjBooms 98
Ad

More Related Content

Similar to JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers (20)

SPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic librarySPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic library
AdaCore
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
Charles Nutter
 
iOS Programming Intro
iOS Programming IntroiOS Programming Intro
iOS Programming Intro
Lou Loizides
 
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
chen yuki
 
GOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesGOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter Slides
Alexandra Masterson
 
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
Nikita Lipsky
 
Tips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native codeTips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native code
Kenneth Geisshirt
 
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode DetectionEfficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Georg Wicherski
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Charles Nutter
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript Engine
Kris Mok
 
White and Black Magic on the JVM
White and Black Magic on the JVMWhite and Black Magic on the JVM
White and Black Magic on the JVM
Ivaylo Pashov
 
C++ Advanced Features
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced Features
Michael Redlich
 
C++ Advanced Features
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced Features
Michael Redlich
 
Triton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaTriton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON China
Wei-Bo Chen
 
Keeping Your Java Hot by Solving the JVM Warmup Problem
Keeping Your Java Hot by Solving the JVM Warmup ProblemKeeping Your Java Hot by Solving the JVM Warmup Problem
Keeping Your Java Hot by Solving the JVM Warmup Problem
Simon Ritter
 
Lifecycle of a JIT compiled code
Lifecycle of a JIT compiled codeLifecycle of a JIT compiled code
Lifecycle of a JIT compiled code
J On The Beach
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
Chris Adamson
 
Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++
Kenneth Geisshirt
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
Anton Arhipov
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
CodeFest
 
SPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic librarySPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic library
AdaCore
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
Charles Nutter
 
iOS Programming Intro
iOS Programming IntroiOS Programming Intro
iOS Programming Intro
Lou Loizides
 
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
chen yuki
 
GOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesGOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter Slides
Alexandra Masterson
 
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
JIT Versus AOT: Unity And Conflict of Dynamic and Static Compilers (JavaOne 2...
Nikita Lipsky
 
Tips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native codeTips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native code
Kenneth Geisshirt
 
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode DetectionEfficient Bytecode Analysis: Linespeed Shellcode Detection
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Georg Wicherski
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Charles Nutter
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript Engine
Kris Mok
 
White and Black Magic on the JVM
White and Black Magic on the JVMWhite and Black Magic on the JVM
White and Black Magic on the JVM
Ivaylo Pashov
 
Triton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaTriton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON China
Wei-Bo Chen
 
Keeping Your Java Hot by Solving the JVM Warmup Problem
Keeping Your Java Hot by Solving the JVM Warmup ProblemKeeping Your Java Hot by Solving the JVM Warmup Problem
Keeping Your Java Hot by Solving the JVM Warmup Problem
Simon Ritter
 
Lifecycle of a JIT compiled code
Lifecycle of a JIT compiled codeLifecycle of a JIT compiled code
Lifecycle of a JIT compiled code
J On The Beach
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
Chris Adamson
 
Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++
Kenneth Geisshirt
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
Anton Arhipov
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
CodeFest
 

More from Nikita Lipsky (20)

Escaping The Jar hell with Jigsaw Layers
Escaping The Jar hell with Jigsaw LayersEscaping The Jar hell with Jigsaw Layers
Escaping The Jar hell with Jigsaw Layers
Nikita Lipsky
 
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall DeposeJava 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Nikita Lipsky
 
Java 9 Модули. Почему не OSGi?
Java 9 Модули. Почему не OSGi?Java 9 Модули. Почему не OSGi?
Java 9 Модули. Почему не OSGi?
Nikita Lipsky
 
AOT для Java: Мифы и Challenges
AOT для Java: Мифы и ChallengesAOT для Java: Мифы и Challenges
AOT для Java: Мифы и Challenges
Nikita Lipsky
 
Верификация Java байткода: когда, как, а может отключить?
Верификация Java байткода: когда, как, а может отключить?Верификация Java байткода: когда, как, а может отключить?
Верификация Java байткода: когда, как, а может отключить?
Nikita Lipsky
 
Java 8 Support at the JVM Level
Java 8 Support at the JVM LevelJava 8 Support at the JVM Level
Java 8 Support at the JVM Level
Nikita Lipsky
 
JVM: краткий курс общей анатомии, JPoint 2016 Conference Edition
JVM: краткий курс общей анатомии, JPoint 2016 Conference EditionJVM: краткий курс общей анатомии, JPoint 2016 Conference Edition
JVM: краткий курс общей анатомии, JPoint 2016 Conference Edition
Nikita Lipsky
 
Поддержка Java 8 в Excelsior JET
Поддержка Java 8 в Excelsior JET Поддержка Java 8 в Excelsior JET
Поддержка Java 8 в Excelsior JET
Nikita Lipsky
 
JVM: краткий курс общей анатомии
JVM: краткий курс общей анатомииJVM: краткий курс общей анатомии
JVM: краткий курс общей анатомии
Nikita Lipsky
 
Клиентская Java вне браузера. Делаем нативные клиенты на Java
Клиентская Java вне браузера. Делаем нативные клиенты на JavaКлиентская Java вне браузера. Делаем нативные клиенты на Java
Клиентская Java вне браузера. Делаем нативные клиенты на Java
Nikita Lipsky
 
Delivering Native User Experience In Client Side Java Applications
Delivering Native User Experience In Client Side Java ApplicationsDelivering Native User Experience In Client Side Java Applications
Delivering Native User Experience In Client Side Java Applications
Nikita Lipsky
 
Java Restart with WebFX
Java Restart with WebFX Java Restart with WebFX
Java Restart with WebFX
Nikita Lipsky
 
Java худеет. Спроси меня как. Уменьшение размера дистрибутива Java приложения...
Java худеет. Спроси меня как. Уменьшение размера дистрибутива Java приложения...Java худеет. Спроси меня как. Уменьшение размера дистрибутива Java приложения...
Java худеет. Спроси меня как. Уменьшение размера дистрибутива Java приложения...
Nikita Lipsky
 
Java Ahead-Of-Time compilation
Java Ahead-Of-Time compilationJava Ahead-Of-Time compilation
Java Ahead-Of-Time compilation
Nikita Lipsky
 
Excelsior JET в действии
Excelsior JET в действииExcelsior JET в действии
Excelsior JET в действии
Nikita Lipsky
 
Веб 3.0. Есть ли будущее у Java в RIA и Mobile?
Веб 3.0. Есть ли будущее у Java в RIA и Mobile?Веб 3.0. Есть ли будущее у Java в RIA и Mobile?
Веб 3.0. Есть ли будущее у Java в RIA и Mobile?
Nikita Lipsky
 
Занимательные истории из жизни технической поддержки JVM
Занимательные истории из жизни технической поддержки JVMЗанимательные истории из жизни технической поддержки JVM
Занимательные истории из жизни технической поддержки JVM
Nikita Lipsky
 
Неумолимая близость десктопа, веба и мобайла
Неумолимая близость десктопа, веба и мобайлаНеумолимая близость десктопа, веба и мобайла
Неумолимая близость десктопа, веба и мобайла
Nikita Lipsky
 
Java худеет. Спроси меня как.
Java худеет. Спроси меня как.Java худеет. Спроси меня как.
Java худеет. Спроси меня как.
Nikita Lipsky
 
История одной JVM в картинках
История одной JVM в картинкахИстория одной JVM в картинках
История одной JVM в картинках
Nikita Lipsky
 
Escaping The Jar hell with Jigsaw Layers
Escaping The Jar hell with Jigsaw LayersEscaping The Jar hell with Jigsaw Layers
Escaping The Jar hell with Jigsaw Layers
Nikita Lipsky
 
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall DeposeJava 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Nikita Lipsky
 
Java 9 Модули. Почему не OSGi?
Java 9 Модули. Почему не OSGi?Java 9 Модули. Почему не OSGi?
Java 9 Модули. Почему не OSGi?
Nikita Lipsky
 
AOT для Java: Мифы и Challenges
AOT для Java: Мифы и ChallengesAOT для Java: Мифы и Challenges
AOT для Java: Мифы и Challenges
Nikita Lipsky
 
Верификация Java байткода: когда, как, а может отключить?
Верификация Java байткода: когда, как, а может отключить?Верификация Java байткода: когда, как, а может отключить?
Верификация Java байткода: когда, как, а может отключить?
Nikita Lipsky
 
Java 8 Support at the JVM Level
Java 8 Support at the JVM LevelJava 8 Support at the JVM Level
Java 8 Support at the JVM Level
Nikita Lipsky
 
JVM: краткий курс общей анатомии, JPoint 2016 Conference Edition
JVM: краткий курс общей анатомии, JPoint 2016 Conference EditionJVM: краткий курс общей анатомии, JPoint 2016 Conference Edition
JVM: краткий курс общей анатомии, JPoint 2016 Conference Edition
Nikita Lipsky
 
Поддержка Java 8 в Excelsior JET
Поддержка Java 8 в Excelsior JET Поддержка Java 8 в Excelsior JET
Поддержка Java 8 в Excelsior JET
Nikita Lipsky
 
JVM: краткий курс общей анатомии
JVM: краткий курс общей анатомииJVM: краткий курс общей анатомии
JVM: краткий курс общей анатомии
Nikita Lipsky
 
Клиентская Java вне браузера. Делаем нативные клиенты на Java
Клиентская Java вне браузера. Делаем нативные клиенты на JavaКлиентская Java вне браузера. Делаем нативные клиенты на Java
Клиентская Java вне браузера. Делаем нативные клиенты на Java
Nikita Lipsky
 
Delivering Native User Experience In Client Side Java Applications
Delivering Native User Experience In Client Side Java ApplicationsDelivering Native User Experience In Client Side Java Applications
Delivering Native User Experience In Client Side Java Applications
Nikita Lipsky
 
Java Restart with WebFX
Java Restart with WebFX Java Restart with WebFX
Java Restart with WebFX
Nikita Lipsky
 
Java худеет. Спроси меня как. Уменьшение размера дистрибутива Java приложения...
Java худеет. Спроси меня как. Уменьшение размера дистрибутива Java приложения...Java худеет. Спроси меня как. Уменьшение размера дистрибутива Java приложения...
Java худеет. Спроси меня как. Уменьшение размера дистрибутива Java приложения...
Nikita Lipsky
 
Java Ahead-Of-Time compilation
Java Ahead-Of-Time compilationJava Ahead-Of-Time compilation
Java Ahead-Of-Time compilation
Nikita Lipsky
 
Excelsior JET в действии
Excelsior JET в действииExcelsior JET в действии
Excelsior JET в действии
Nikita Lipsky
 
Веб 3.0. Есть ли будущее у Java в RIA и Mobile?
Веб 3.0. Есть ли будущее у Java в RIA и Mobile?Веб 3.0. Есть ли будущее у Java в RIA и Mobile?
Веб 3.0. Есть ли будущее у Java в RIA и Mobile?
Nikita Lipsky
 
Занимательные истории из жизни технической поддержки JVM
Занимательные истории из жизни технической поддержки JVMЗанимательные истории из жизни технической поддержки JVM
Занимательные истории из жизни технической поддержки JVM
Nikita Lipsky
 
Неумолимая близость десктопа, веба и мобайла
Неумолимая близость десктопа, веба и мобайлаНеумолимая близость десктопа, веба и мобайла
Неумолимая близость десктопа, веба и мобайла
Nikita Lipsky
 
Java худеет. Спроси меня как.
Java худеет. Спроси меня как.Java худеет. Спроси меня как.
Java худеет. Спроси меня как.
Nikita Lipsky
 
История одной JVM в картинках
История одной JVM в картинкахИстория одной JVM в картинках
История одной JVM в картинках
Nikita Lipsky
 
Ad

Recently uploaded (20)

WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Ad

JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers

  • 1. JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers for Java Nikita Lipsky Excelsior LLC
  • 2. JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers for Java Nikita Lipsky Excelsior LLC
  • 3. 3
  • 4. Once upon a time, when C++ was new and cool, +++++++++ 4
  • 5. Once upon a time, when C++ was new and cool, +++++++++ 5
  • 6. Once upon a time, when C++ was new and cool, all compilers were static 6
  • 7. Until into this world came… Java 7
  • 8. Until into this world came… Java
  • 9. Two Ways To Execute Java Bytecode • Interpret Slow but portable • Compile to machine code Runs on the actual hardware 9
  • 10. When to compile to native code? • At application run time Dynamic (Just-In-Time, JIT) Compilation • Before the application is launched/deployed Static (Ahead-Of-Time, AOT) Compilation 10
  • 12. JIT vs. AOT: Agenda • Myths around Java AOT • Java AOT challenges and advantages • Performance: – JIT vs. AOT compiler optimizations comparison • JIT and AOT in various fields of use: – client-side, server-side, embedded, IOT, mobile 12
  • 13. Nikita Lipsky • 20+ years in software development • Excelsior JET project initiator – 16+ years of contributions – compiler engineer – team lead – product lead – etc. • Twitter: @pjBooms 13
  • 14. 14
  • 15. Who needs Java AOT 15 Кто знает про Excelsior JET?Кто знает про Excelsior JET?
  • 17. Myth 1. Java is “too dynamic” Reflection Dynamic class loading 17
  • 18. Myth 2. AOT kills WORA WORA Write Once Run Anywhere BORA Build Once Run Anywhere 18 !=
  • 19. Myth 3. AOT = Small EXE ”I would get a small executable that works without a JVM (as if I wrote my app in C)” 19
  • 20. Myth 3. AOT = Small EXE • What about thousands of standard classes? • Who will collect the garbage? • What about reflection? 20
  • 21. AOT = Smaller Package Yes, AOT compilation can help you create a JRE-independent installer smaller than the JRE installer alone Javа Runtime Slim-Down: www.excelsiorjet.com/solutions/java-download-size 21
  • 22. Java IS “too dynamic” 22
  • 23. Non-standard Class Loaders • Override the default reference resolution logic • Unique namespaces • Dependency management frameworks – OSGi: Felix, Equanox Solve JAR hell problem • Java EE servers, Eclipse RCP, plugin architectures 23
  • 24. Non-standard Class Loaders How to compile such classes statically? • Compile each class in isolation – Bad for performance • Reproduce reference resolution logic of popular class loaders – Does not work for arbitrary class loaders 24
  • 27. • CL4• CL3 • CL2• CL1 classes classes classesclasses Non-standard Class Loaders 27
  • 28. • CL4• CL3 • CL2• CL1 classes classes classesclasses Non-standard Class Loaders 28
  • 29. • CL4• CL3 • CL2• CL1 classes classes classesclasses Non-standard Class Loaders 29
  • 30. Non-standard Class Loaders 30 • CL4• CL3 • CL2• CL1 classes classes classes
  • 31. • CL4• CL3 • CL2• CL1 classes classes Non-standard Class Loaders 31
  • 32. Non-standard Class Loaders AOT class loader support scheme: • Reference resolver in the AOT compiler: – Determines which class loaders will be created at run time and assigns a static ID to each – Breaks down the set of classes by class loader IDs – Resolves references between classes 32
  • 33. Non-standard Class Loaders AOT class loader support scheme contd.: • At application run time: – For each class loader instance, compute its ID – Knowing the ID, “load” the precompiled classes: • Create a java.lang.Class instance • Fill it with reflection information • Let the O/S load code from the executable 33
  • 34. Non-standard Class Loaders AOT class loader support scheme contd.: • At application run time: – For each class loader instance, compute its ID – Knowing the ID, “load” the precompiled classes Known to work for Eclipse RCP and Tomcat Web apps 34
  • 35. Why AOT for Java? 35
  • 36. Protect Code from Decompilers 36
  • 37. Application Code Protection • Bytecode emitted by javac is extremely easy to decompile almost to original source Proof: http://bytecodeviewer.com/ • Reflection makes name obfuscation labor- consuming and error prone, hinders code maintenance • Possible to guess what obfuscated code does References to JDK classes remain intact 37
  • 38. Application Code Protection • Native machine code can only be effectively disassembled, but not decompiled • Application structure not deductible from disassembler output • Aggressively optimized native code only remotely resembles original 38
  • 40. Cold Start vs Warm Start Why a re-started application starts much faster? – No need to load app code and data from disk – No need to load system/third-party dynamic libraries (.DLL, .so) either 40
  • 41. AOT Is Faster? • Native code is “thicker” than Java bytecode • Reading code from disk often takes more time than its execution, esp. on cold starts 41
  • 42. AOT IS Faster! 1. Identify code that gets executed on startup 2. Place it at the beginning of the executable 3. Preload the entire “startup segment” in one sequential read (Makes most difference on rotating media, slow USB sticks, etc., not so much on SSDs) 42
  • 43. 43
  • 45. Myth 4. AOT Is Faster 45
  • 46. Myth 4. AOT Is Faster “By compiling Java statically, we are making it equivalent to C, C is faster than Java, therefore statically compiled Java is faster” 46
  • 47. Myth 5. JIT Is Faster 47
  • 48. Myth 5. JIT Is Faster “Effective optimization of a Java application is only possible in the presence of its dynamic execution profile” 48
  • 49. Compiler Optimizations – Constant propagation – Dead code elimination – Common subexpression elimination – Inline substitution – Method specialization – Loop unrolling – Loop versioning – Loop-invariant code motion – Tail recursion elimination – Call devirtualization – On-stack allocation and explosion of objects – Runtime checks removal – Excess synchronization removal – Optimal code selection and bundling – Instruction scheduling – Optimal register allocation – etc. 49
  • 50. Java == OOP • Lots of methods • Lots of small methods (get/set) • Lots of virtual calls of small methods 50
  • 51. Call Devirtualization • Precondition for subsequent inline substitution • Class hierarchy analysis Method not overridden => non-virtual call • Type analysis new T().foo(); // Non-virtual // call of T.foo() • Profile guided 51
  • 52. A a; … a.foo();  if (RT_Type(a) in CHA) { inlined body of foo() } else { a.foo(); } Idea: method not overriden => non-virtual call Class Hierarchy Analysis (CHA) 52
  • 53. Type Analysis Idea: new A().foo(); // non-virtual call. Always! 53
  • 54. Type Analysis A a = b ? new B() : new C(); a.foo();// is it virtual call? // B, C extend A and do not override A.foo 54
  • 55. Type Analysis A a = b ? new B() : new C(); a.foo(); If neither B nor С override A.foo(), then a.foo()is a non-virtual call again! (can be inlined) 55
  • 56. Type Analysis A a = b ? bar() : baz(); … a.foo(); If bar() only returns results of new B, and baz() - only returns results of new С, then a.foo() is again non-virtual (can be inlined) 56
  • 57. Type Analysis How do we know what bar() and baz() return? 57
  • 58. Global Analysis • Analyses all methods of the program, computing useful information about each – whether a method always returns new T(); – whether an argument of a method does not escape to a shared memory • Results are then used for optimization of each particular method 58
  • 59. Stack Allocation of Objects • All Java objects are supposed to reside in dynamic memory – on the Java heap • But, most objects are small and temporary • It is desirable to allocate them on the stack Escape analysis determines whether a locally created object escapes from the method stack frame into shared memory 59
  • 60. Example for (Object o: getCollection()) { doSomething(o); } 60
  • 61. Example Iterator iter = getCollection().iterator(); while (iter.hasNext()) { Object o = iter.next(); doSomething(o); } 61
  • 62. Example Suppose analysis has shown that getCollection() always returns an ArrayList ArrayList list = getCollection(); Iterator iter = list.iterator(); while (iter.hasNext()) { Object o = iter.next(); doSomething(o); } 62
  • 63. Example ArrayList list = getCollection(); ArrayList.ListItr iter = new ListItr(list); while (iter.hasNext()) { Object o = iter.next(); doSomething(o); } 63
  • 64. Example ArrayList list = getCollection(); ArrayList.ListItr iter = onStack ListItr(); iter.this$0 = list; iter.cursor = 0; iter.size = list.elemData.length; while (iter.hasNext()) { Object o = iter.next(); doSomething(o); } 64
  • 65. Example ArrayList list = getCollection(); ArrayList.ListItr iter = onStack ListItr(list); iter.this$0 = list; iter.cursor = 0; iter.size = list.elemData.length; while (iter.cursor < iter.size) { int index = iter.cursor++; Object o = iter.this$0.elemData[index]; doSomething(o); } 65
  • 66. Example ArrayList list = getCollection(); int cursor = 0; int size = list.elemData.length; while (cursor < size) { Object o = list.elemData[cursor++]; doSomething(o); } 66
  • 67. Example ArrayList list = getCollection(); int size = list.elemData.length; for (int i = 0; i < size; i++) { doSomething(list.elemData[i]); } 67
  • 68. Analysis & Optimizations… • …are often quite complicated • …require iterative re-computation • …, if global, depend on the entire program 68
  • 69. Analysis & Optimizations… • …are often quite complicated • …require iterative recomputation • …, if global, depend on the entire program Can a JIT compiler afford all or any of that?
  • 70. Analysis & Optimizations… • …are often quite complicated • …require iterative recomputations • …, if global, depend on the entire program Can a JIT compiler afford all or any of that? 70
  • 71. Analysis & Optimizations… • …are often quite complicated • …require iterative recomputations • …, if global, depend on the entire program Can a JIT compiler afford all or any of that?
  • 72. Dynamic Optimizations • Profiling and selective compilation • Inline substitution based on execution profile • Hot execution traces optimization • Optimal instruction selection
  • 73. Hot Code vs Warm Code Q: What happens when an app with no distinctly hot code runs on a typical JVM? A: Long warmup with results not stored for future reuse Typical case: UI-centric applications 73
  • 74. JFCMark (Short Run) 0% 50% 100% 150% 200% 250% 2 core Celeron, 2.60Ghz 4 core i5, 3.8GZ Excelsior JET HotSpot client HotSpot server Bigger – better 74
  • 75. JFCMark (Long Run) 0% 20% 40% 60% 80% 100% 120% 140% 160% 2 core Celeron, 2.60Ghz 4 core i5, 3.8GZ Excelsior JET HotSpot client HotSpot server 75 Bigger – better
  • 76. Profile Guided Optimizations Can a static compiler use dynamic execution profiles as input? 76
  • 77. Server side • CPU time in the cloud costs money • After some time, execution profile of a server app stabilizes • Why not pass it over to the AOT compiler? 77
  • 78. AOT on the Server side • Stable performance and predictable latency – no code de-optimizations occur at run-time • Work at full speed right from the start – good for load balancing • Better startup time – good when many servers start simultaneously • Still protects the code from decompilation 78
  • 79. Embedded/IoT • The less powerful the hardware, the more expensive dynamic compilation becomes • Embedded systems typically have less computing power than desktops and servers 79
  • 80. Mobile • JVM on Mobile: – Platform classes – Memory Manager and GC – Reflection – JIT Compiler What is missing? 80
  • 81. Mobile • JVM on Mobile: – Platform classes – Memory Manager and GC – Reflection – JIT Compiler What is missing? 81
  • 82. Mobile • JVM on Mobile: – Platform classes – Memory Manager and GC – Reflection – JIT Compiler What is missing? 82
  • 83. Mobile • JVM on Mobile: – Platform classes – Memory Manager and GC – Reflection – JIT Compiler What is missing? 83
  • 84. Mobile • JVM on Mobile: – Platform classes – Memory Manager and GC – Reflection – JIT Compiler What is missing? 84
  • 85. Mobile • JVM on Mobile: – Platform classes – Memory Manager and GC – Reflection – JIT Compiler What is missing? 85
  • 86. Mobile • JVM on Mobile: – Platform classes – Memory Manager and GC – Reflection – JIT Compiler Charger! 86
  • 87. Mobile • Wireless devices have batteries • Does it make sense to spend power on dynamic compilation? 87
  • 88. iOS • iOS policy prohibits creation of any native code during application run time • Getting Java apps to work on iOS requires either an interpreting JVM or an AOT compiler 88
  • 89. AOT Java Compilers in 2000 Desktop/Server: BulletTrain Excelsior JET GNU Compiler for Java (GCJ) IBM VisualAge for Java Supercede/JOVE TowerJ Embedded/Mobile: Diab FastJ Esmertec Jbed ME GCJ IBM J9 Sun Java ME (custom offerings) 89
  • 90. AOT Java Compilers in 2017 Desktop/Server: Excelsior JET GCJ (RIP) IBM Java SDK for AIX IBM Java SDK for z/OS Coming soon: HotSpot AOT (JEP-295) Embedded/Mobile: Excelsior JET Embedded IBM WebSphere Real Time Oracle Java ME Embedded Client Codename One Avian Android ART RoboVM (RIP) Multi-OS Engine 90
  • 91. AOT Java Compilers in 2017 Desktop/Server: Excelsior JET GCJ (RIP) IBM Java SDK for AIX IBM Java SDK for z/OS Coming soon: HotSpot AOT (JEP-295) Embedded/Mobile: Excelsior JET Embedded IBM WebSphere Real Time Oracle Java ME Embedded Client Codename One Avian Android ART RoboVM (RIP) Multi-OS Engine 91
  • 92. Static compilation of Java apps: 92 Conclusion
  • 93. Static compilation of Java apps: 93 Possible Conclusion
  • 94. Static compilation of Java apps: 94 Possible Preserving all Java features Conclusion
  • 95. Static compilation of Java apps: 95 Possible Preserving all Java features Useful in many aspects Conclusion
  • 96. Conclusion • JIT and AOT have their unique advantages • Synthesis of two approaches will give maximum benefits 96
  • 97. Conclusion • JIT and AOT have their unique advantages • Synthesis of the two approaches will bring maximum benefits 97
  • 98. Q & A Nikita Lipsky, Excelsior [email protected] twitter: @pjBooms 98