SlideShare a Scribd company logo
1 of 83
Download to read offline
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Everything You Wanted to Know About JIT
Compilation but Were Afraid to Ask
[CON3564]
David Buck
Principal Member of Technical Staff
Java Platform Group
October 3rd, 2017
Confidential – Oracle Internal/Restricted/Highly Restricted 3
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
Confidential – Oracle Internal/Restricted/Highly Restricted 4
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
• JVM Sustaining Engineer
• OpenJDK 8 Update Project
Maintainer
• JavaOne Rock Star
• Co-author of Oracle WebLogic
Server 11g 構築・運用ガイド
• @DavidBuckJP
• https://blogs.oracle.com/buck/
Who am I?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Who are you?
• Just about any Java programmer who uses HotSpot
Confidential – Oracle Internal/Restricted/Highly Restricted 6
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
What?
• Crash course on HotSpot's JIT compilation
Confidential – Oracle Internal/Restricted/Highly Restricted 7
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Why?
• Focus on what matters (no premature optimization)
• Better tuning / troubleshooting
• Fun
Confidential – Oracle Internal/Restricted/Highly Restricted 8
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Why Now?
• Still an area of frequent development
– Tiered compilation
– Interaction with new features
• Still an area of frequent misunderstanding / confusion / interest
– Premature optimization
Confidential – Oracle Internal/Restricted/Highly Restricted 9
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Program Agenda
Introduction
Implementation
Monitoring
Control
1
2
3
4
Confidential – Oracle Internal/Restricted/Highly Restricted 10
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Introduction
Confidential – Oracle Internal/Restricted/Highly Restricted 11
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
What is JIT?
Just-in-Time compilation
Confidential – Oracle Internal/Restricted/Highly Restricted 12
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Classic JIT
• All methods or functions
compiled immediately before use
• No interpreter
• Example: JRockit
Confidential – Oracle Internal/Restricted/Highly Restricted 13
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Classic JIT Example: JRockit
Confidential – Oracle Internal/Restricted/Highly Restricted 14
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JIT is very old
• LISP (John McCarthy, 1960)
• QED text editor regular expressions (Ken Thompson, 1968)
• Smalltalk (1983)
• Self (1990s?)
Confidential – Oracle Internal/Restricted/Highly Restricted 15
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JIT for Java is very old
• Microsoft and Symantec had their own JIT compilers for browsers
• Symantec deal with Sun (project java activator)
• JIT added to "Classic" JVM in JDK 1.2
• HotSpot available as an optional addition in 1.2
• HotSpot shipped with 1.3
Confidential – Oracle Internal/Restricted/Highly Restricted 16
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Static Compilation
• Pros:
– No runtime overhead
• Cons:
– Portability issues
– No ability to adapt
• To hardware
• To application behavior
Interpreter
• Pros:
– Portable
– Adaptable
• Cons:
– Interpretation overhead
Confidential – Oracle Internal/Restricted/Highly Restricted 17
Static Compilation vs. Interpreter
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Classic JIT compared to both compilation / interpreter
• Pros:
– No interpretation runtime overhead
– Portable
– Adaptable
• Cons:
– Runtime JIT compilation overhead
– Slower startup time
Confidential – Oracle Internal/Restricted/Highly Restricted 18
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Static Initializers
The poster boy for wasteful JIT overhead
static {
// important class-level
// initialization goes here!
}
Confidential – Oracle Internal/Restricted/Highly Restricted 19
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
HotSpot JIT Compilation
• Only JIT compile hot stuff (hotspots)
• Interpret the rest
Confidential – Oracle Internal/Restricted/Highly Restricted 20
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Why is this important?
• Don’t JIT stuff that is not hot
• No need to wait for a JIT to finish (asynchronous JIT)
Confidential – Oracle Internal/Restricted/Highly Restricted 21
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
HotSpot JIT compared to Classic JIT
• Pros
– Portable
– Adaptable
– Fast (startup and peak)
• Cons
– Complicated to implement
Confidential – Oracle Internal/Restricted/Highly Restricted 22
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
A Note on Nomenclature…
• HotSpot == Runtime Profiling used to identify candidates for JIT
compilation
• HotSpot == JVM
– Profiling technique
– JIT policy
• HotSpot does use JIT
Confidential – Oracle Internal/Restricted/Highly Restricted 23
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Implementation
Confidential – Oracle Internal/Restricted/Highly Restricted 24
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
JIT Compiler Design Goals
• Lightweight
– Fast startup
– Small memory footprint
– Low compilation overhead
• Generate high-performance code
– Many complex optimizations
– Based on heavy profiling of code
– Output peak performance often bests C/C++
Confidential – Oracle Internal/Restricted/Highly Restricted 25
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Client
• Short-lived processes
• Run on client machines with low
resources (desktops / laptops)
Server
(Application servers,
Batch processing)
• Long-lived processes
• Run on dedicated machines with
plentiful resources
Confidential – Oracle Internal/Restricted/Highly Restricted 26
Two Use Cases
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Client Compiler (C1):
• Only simple optimizations
• Quick compilation
• Low memory requirements
• Not dependent on profiling data
• Reasonable peak performance
Server Compiler (C2):
• Highly optimizing
• Slow compilation
• Heavy memory usage
• Dependent on profiling data
• Great peak performance
Confidential – Oracle Internal/Restricted/Highly Restricted 27
Two JIT Compilers
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Client Compiler (C1):
• Only simple optimizations
• Quick compilation
• Low memory requirements
• Not dependent on profiling data
• Reasonable peak performance
Server Compiler (C2):
• Highly optimizing
• Slow compilation
• Heavy memory usage
• Dependent on profiling data
• Great peak performance
Confidential – Oracle Internal/Restricted/Highly Restricted 28
Two JIT Compilers
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Profiling
Interpreter collets profiling information, basically free
• Invocation counter
• Backwards jumps
• Invokevirtual targets
• Branch prediction
Confidential – Oracle Internal/Restricted/Highly Restricted 29
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Client JVM
• Only C1 used
• Many tuning defaults / ergonomics
/ heuristics tuned for client usage
• Reaches peak performance quickly
Server JVM
• Traditionally only C2 used (more to
come)
• Many tuning defaults / ergonomics
/ heuristics tuned for server usage
• May take a while to reach peak
performance
• The only JVM to support 64-bit
Confidential – Oracle Internal/Restricted/Highly Restricted 30
A Tail of Two JVMs
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Java Launcher
Confidential – Oracle Internal/Restricted/Highly Restricted 31
bin/java
jre/lib/<arch>/server/libjvm.so
jre/lib/<arch>/client/libjvm.so
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Client JVM
• Only C1 used
• Many tuning defaults / ergonomics
/ heuristics tuned for client usage
• Reaches peak performance quickly
Server JVM
• Traditionally only C2 used (more to
come)
• Many tuning defaults / ergonomics
/ heuristics tuned for server usage
• May take a while to reach peak
performance
• The only JVM to support 64-bit
Confidential – Oracle Internal/Restricted/Highly Restricted 32
A Tail of Two JVMs
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
class A {
B b;
public void foo() {
y = b.get();
...do stuff...
z = b.get();
sum = y + z;
}
}
class B {
int value;
final int get() {
return value;
}
}
Confidential – Oracle Internal/Restricted/Highly Restricted 33
Optimization Example
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
class A {
B b;
public void foo() {
y = b.get();
...do stuff...
z = b.get();
sum = y + z;
}
}
class B {
int value;
final int get() {
return value;
}
}
Confidential – Oracle Internal/Restricted/Highly Restricted 34
Optimization Example
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
class A {
B b;
public void foo() {
y = b.value;
...do stuff...
z = b.value;
sum = y + z;
}
}
class B {
int value;
final int get() {
return value;
}
}
Confidential – Oracle Internal/Restricted/Highly Restricted 35
Optimization Example
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
class A {
B b;
public void foo() {
y = b.value;
...do stuff...
z = b.value;
sum = y + z;
}
}
class B {
int value;
final int get() {
return value;
}
}
Confidential – Oracle Internal/Restricted/Highly Restricted 36
Optimization Example
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
class A {
B b;
public void foo() {
y = b.value;
...do stuff...
z = b.value;
sum = y + z;
}
}
class B {
int value;
final int get() {
return value;
}
}
Confidential – Oracle Internal/Restricted/Highly Restricted 37
Optimization Example
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
class A {
B b;
public void foo() {
y = b.value;
...do stuff...
z = y;
sum = y + z;
}
}
class B {
int value;
final int get() {
return value;
}
}
Confidential – Oracle Internal/Restricted/Highly Restricted 38
Optimization Example
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
class A {
B b;
public void foo() {
y = b.value;
...do stuff...
z = y;
sum = y + z;
}
}
class B {
int value;
final int get() {
return value;
}
}
Confidential – Oracle Internal/Restricted/Highly Restricted 39
Optimization Example
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
class A {
B b;
public void foo() {
y = b.value;
...do stuff...
y = y;
sum = y + y;
}
}
class B {
int value;
final int get() {
return value;
}
}
Confidential – Oracle Internal/Restricted/Highly Restricted 40
Optimization Example
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
class A {
B b;
public void foo() {
y = b.value;
...do stuff...
y = y;
sum = y + y;
}
}
class B {
int value;
final int get() {
return value;
}
}
Confidential – Oracle Internal/Restricted/Highly Restricted 41
Optimization Example
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
class A {
B b;
public void foo() {
y = b.value;
...do stuff...
sum = y + y;
}
}
class B {
int value;
final int get() {
return value;
}
}
Confidential – Oracle Internal/Restricted/Highly Restricted 42
Optimization Example
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
class A {
B b;
public void foo() {
y = b.get();
...do stuff...
z = b.get();
sum = y + z;
}
}
class A {
B b;
public void foo() {
y = b.value;
...do stuff...
sum = y + y;
}
}
Confidential – Oracle Internal/Restricted/Highly Restricted 43
Optimization Example (Before and After)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Tiered Compilation
• Interpretation -> C1 -> C2
(very simplified version)
• Quick warmup of C1, but
with the higher peak
performance of C2
Confidential – Oracle Internal/Restricted/Highly Restricted 44
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Tiered Compilation
• Existed since early JDK 6 releases (not officially supported)
• Officially supported in JDK 7 (use not recommended)
• Enabled by default from JDK 8
Confidential – Oracle Internal/Restricted/Highly Restricted 45
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Tiered Compilation
• Level 0 - interpreter
• Level 1 - C1 with full optimization (no profiling)
• Level 2 - C1 with invocation and backedge counters
• Level 3 - C1 with full profiling (level 2 + MDO)
• Level 4 - C2
Confidential – Oracle Internal/Restricted/Highly Restricted 46
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Code Cache
• Contains:
– JITed code
– JNI wrapper / stubs
– HotSpot template interpreter
• Cleaned up by the “sweeper thread”
• Compiler disabled if you run out of space
Confidential – Oracle Internal/Restricted/Highly Restricted 47
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Monitoring
Confidential – Oracle Internal/Restricted/Highly Restricted 48
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
public static void main(String[] args) {
long i = 0;
while (true) {
i = addStuff(i, 1);
if (i % Long.MAX_VALUE == 0)
System.out.println(i);
}
}
private static long addStuff(long a, long b) {
return a+b;
}
Confidential – Oracle Internal/Restricted/Highly Restricted 49
A Rather Contrived Example…
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 50
$ java -XX:+PrintCompilation HotMethodDemo
156 24 3 HotMethodDemo::addStuff (4 bytes)
161 25 1 HotMethodDemo::addStuff (4 bytes)
161 24 3 HotMethodDemo::addStuff (4 bytes) made not entrant
Some Visibility
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 51
$ java -XX:+PrintCompilation HotMethodDemo
156 24 3 HotMethodDemo::addStuff (4 bytes)
161 25 1 HotMethodDemo::addStuff (4 bytes)
161 24 3 HotMethodDemo::addStuff (4 bytes) made not entrant
Timestamp Compilation ID Compilation Tier Method Size Other Information
Some Visibility
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 52
$ java -XX:+PrintCompilation HotMethodDemo
100 1 3 java.lang.String::hashCode (55 bytes)
101 2 3 java.lang.String::equals (81 bytes)
104 3 3 java.lang.String::indexOf (70 bytes)
105 4 3 java.lang.String::charAt (29 bytes)
106 5 3 java.lang.String::length (6 bytes)
107 6 3 java.lang.Object::<init> (1 bytes)
111 7 n 0 java.lang.System::arraycopy (native) (static)
113 8 3 java.lang.Math::min (11 bytes)
113 9 3 java.lang.AbstractStringBuilder::ensureCapacityInternal (27 bytes)
114 10 1 java.lang.Object::<init> (1 bytes)
114 6 3 java.lang.Object::<init> (1 bytes) made not entrant
115 11 1 java.lang.ref.Reference::get (5 bytes)
118 12 3 java.util.HashMap::hash (20 bytes)
118 13 3 java.util.Arrays::copyOfRange (63 bytes)
120 14 3 java.util.HashMap::getNode (148 bytes)
121 15 4 java.lang.String::equals (81 bytes)
124 16 3 java.util.LinkedList::indexOf (73 bytes)
125 17 3 java.util.HashMap::get (23 bytes)
133 18 ! 3 java.io.BufferedReader::readLine (304 bytes)
148 19 3 sun.misc.JarIndex::addToList (59 bytes)
149 20 3 java.util.LinkedList::add (7 bytes)
150 2 3 java.lang.String::equals (81 bytes) made not entrant
150 21 3 java.lang.String::<init> (82 bytes)
150 22 1 java.lang.ThreadLocal::access$400 (5 bytes)
151 23 3 java.lang.String::getChars (62 bytes)
156 24 3 HotMethodDemo::addStuff (4 bytes)
161 25 1 HotMethodDemo::addStuff (4 bytes)
161 24 3 HotMethodDemo::addStuff (4 bytes) made not entrant
163 26 % 3 HotMethodDemo::main @ 2 (28 bytes)
168 27 3 HotMethodDemo::main (28 bytes)
193 28 % 4 HotMethodDemo::main @ 2 (28 bytes)
Some Visibility
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Compilation Flags
b Blocking compile
% On stack replacement
! Method has exception handlers
s Method declared as synchronized
n Method declared as native
Confidential – Oracle Internal/Restricted/Highly Restricted 53
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Compilation Flags
b Blocking compile
% On stack replacement
! Method has exception handlers
s Method declared as synchronized
n Method declared as native
Confidential – Oracle Internal/Restricted/Highly Restricted 54
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Blocking Compilation
• Methods are compiled asynchronously by default
• Can force compilation to block with -Xbatch
Confidential – Oracle Internal/Restricted/Highly Restricted 55
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Compilation Flags
b Blocking compile
% On stack replacement
! Method has exception handlers
s Method declared as synchronized
n Method declared as native
Confidential – Oracle Internal/Restricted/Highly Restricted 56
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
public static void main(String[] args) {
long i = 0;
while (true) {
i = addStuff(i, 1);
if (i % Long.MAX_VALUE == 0)
System.out.println(i);
}
}
private static long addStuff(long a, long b) {
return a+b;
}
Confidential – Oracle Internal/Restricted/Highly Restricted 57
A Rather Contrived Example…
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
public static void main(String[] args) {
long i = 0;
while (true) {
i = addStuff(i, 1);
if (i % Long.MAX_VALUE == 0)
System.out.println(i);
}
}
private static long addStuff(long a, long b) {
return a+b;
}
Confidential – Oracle Internal/Restricted/Highly Restricted 58
A Rather Contrived Example…
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
On Stack Replacement
• JIT compile a method while it is being run
• ARs for Interpreter and JIT frames look very different
– Must convert interpreter frame to JIT frame
• JIT compiled method entry is in the middle of method
Confidential – Oracle Internal/Restricted/Highly Restricted 59
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 60
$ java -XX:+PrintCompilation HotMethodDemo
156 24 3 HotMethodDemo::addStuff (4 bytes)
161 25 1 HotMethodDemo::addStuff (4 bytes)
161 24 3 HotMethodDemo::addStuff (4 bytes) made not entrant
163 26 % 3 HotMethodDemo::main @ 2 (28 bytes)
168 27 3 HotMethodDemo::main (28 bytes)
193 28 % 4 HotMethodDemo::main @ 2 (28 bytes)
Some More Visibility
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 61
private static long addStuff(long, long);
descriptor: (JJ)J
flags: ACC_PRIVATE, ACC_STATIC
Code:
stack=4, locals=4, args_size=2
0: lload_0
1: lload_2
2: ladd
3: lreturn
Bytecode - addStuff
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 62
public static void main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=4, locals=3, args_size=1
0: lconst_0
1: lstore_1
2: lload_1
3: lconst_1
4: invokestatic #2 // Method addStuff:(JJ)J
7: lstore_1
8: lload_1
9: ldc2_w #4 // long 9223372036854775807l
12: lrem
13: lconst_0
14: lcmp
15: ifne 2
18: getstatic #6 // Field
java/lang/System.out:Ljava/io/PrintStream;
21: lload_1
22: invokevirtual #7 // Method java/io/PrintStream.println:(J)V
25: goto 2
Bytecode - main
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 63
$ java -XX:+PrintCompilation HotMethodDemo
156 24 3 HotMethodDemo::addStuff (4 bytes)
161 25 1 HotMethodDemo::addStuff (4 bytes)
161 24 3 HotMethodDemo::addStuff (4 bytes) made not entrant
163 26 % 3 HotMethodDemo::main @ 2 (28 bytes)
168 27 3 HotMethodDemo::main (28 bytes)
193 28 % 4 HotMethodDemo::main @ 2 (28 bytes)
Some More Visibility
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 64
$ java -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining HotMethodDemo
203 21 3 HotMethodDemo::addStuff (4 bytes)
212 22 1 HotMethodDemo::addStuff (4 bytes)
212 21 3 HotMethodDemo::addStuff (4 bytes) made not entrant
217 23 % 3 HotMethodDemo::main @ 2 (28 bytes)
@ 4 HotMethodDemo::addStuff (4 bytes)
@ 22 java/io/PrintStream::println (not loaded) not inlineable
218 24 3 HotMethodDemo::main (28 bytes)
@ 4 HotMethodDemo::addStuff (4 bytes)
@ 22 java/io/PrintStream::println (not loaded) not inlineable
220 25 % 4 HotMethodDemo::main @ 2 (28 bytes)
@ 4 HotMethodDemo::addStuff (4 bytes) inline (hot)
227 23 % 3 HotMethodDemo::main @ -2 (28 bytes) made not entrant
A Lot More Visibility
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Control
Confidential – Oracle Internal/Restricted/Highly Restricted 65
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
A Word of Warning…
• Performance tuning JIT compilation usually a waste of time
• Being able to troubleshoot / workaround bugs may be useful
Confidential – Oracle Internal/Restricted/Highly Restricted 66
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Most Important Options (All or Nothing)
• -Xint
– Interpreter only (disables all JIT)
– Good for trying to simplify test cases
• -Xcomp
– JIT only (disables interpreter)
– Good for trying to reproduce JIT issues / behavior
Confidential – Oracle Internal/Restricted/Highly Restricted 67
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Most Important Options (JVM Selection)
• -client
– Only available on 32-bit
– C1 compiler only
– Default compile threshold: 1,500
• -server
– Only option for 64-bit JVMs
– C2 compiler (and C1 w/ Tiered Compilation)
– Default compile threshold: 10,000
Confidential – Oracle Internal/Restricted/Highly Restricted 68
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Most Important Options (JIT Timing)
• XX:CompileThreshold
– Number of invocations before method is considered “hot”
– Default varies based on JVM (client / server)
• Xbatch
– Disables asynchronous compilation
– Makes compilation much more deterministic
Confidential – Oracle Internal/Restricted/Highly Restricted 69
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Most Important Options (Tiered Compilation)
• -XX:-TieredCompilation
– Effectively disables C1 on server JVMs
• -XX:TieredStopAtLevel
– TieredStopAtLevel=1 can be used to get “client like” behavior
Confidential – Oracle Internal/Restricted/Highly Restricted 70
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Most Important Options (Fine-grained Control)
• XX:CompileCommand
– help (does not list all commands)
– option
– log
– compileonly
– exclude
– print
– inline
– dontinline
Confidential – Oracle Internal/Restricted/Highly Restricted 71
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Compiler Control
• New in JDK 9 (JEP 165)
• Inspired by JRockit
• JSON-based configuration file
• Can be specified with XX:CompilerDirectivesFile
Confidential – Oracle Internal/Restricted/Highly Restricted 72
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Compiler Control: Example 1
{ // start of another directives block
// match ant method whose class end with 'Concurrent'
match: ["*Concurrent.*"],
c2: {
// disable compilation
Exclude:true,
}
// with the c1 directive unspecified the options remains default.
}
Confidential – Oracle Internal/Restricted/Highly Restricted 73
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Compiler Control: Example 2
{
match: ["java*.*", "oracle*.*"],
c1: {
// A bool option. Extra trailing comma should not cause a parse error
PrintAssembly:true,
},
c2: {
// force inline patters prepended with +, prevent with -
inline: ["+vm*.*","-*.*" ]
},
},
Confidential – Oracle Internal/Restricted/Highly Restricted 74
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Compiler Control: diagnostic commands
• jcmd <pid> Compiler.add_directives <file>
Add additional directives from the file. The new directives will be added on top of the old, with the first directive in the
file ending up on the top of the directives stack.
• jcmd <pid> Compiler.list_directives
List all directives on the directives stack from top to bottom.
• jcmd <pid> Compiler.clear_directives
Clear the directives stack
• jcmd <pid> Compiler.remove_directives
Remove the top element from the directives stack
Confidential – Oracle Internal/Restricted/Highly Restricted 75
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Conclusions
Confidential – Oracle Internal/Restricted/Highly Restricted 76
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
• JIT Compilation can do optimizations static compilers can not do
• You should avoid premature optimization
• JIT (especially C2) behavior can be very non-deterministic
Confidential – Oracle Internal/Restricted/Highly Restricted 77
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Thank You!
Confidential – Oracle Internal/Restricted/Highly Restricted 78
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
• The Java HotSpot Performance Engine Architecture
(A little out-of-date, but still a good primer)
http://www.oracle.com/technetwork/java/whitepaper-
135217.html
• PrintAssembly (HSDIS)
https://wiki.openjdk.java.net/display/HotSpot/PrintAsse
mbly
• It's All Relative - CompileCommand JVM option
http://jpbempel.blogspot.com/2016/03/compilecomman
d-jvm-option.html
• Kris Mok's PrintCompilation Notes
https://gist.github.com/rednaxelafx/1165804#file_notes.
md
• Java Performance, Hunt & John
https://www.pearson.com/us/higher-
education/program/Hunt-Java-
Performance/PGM182574.html
• Java Performance Companion, Hunt & Beckwith &
Parhar & Rutisson
https://www.pearson.com/us/higher-
education/program/Hunt-Java-Performance-
Companion/PGM168439.html
Confidential – Oracle Internal/Restricted/Highly Restricted 79
Resources
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Stay connected
• Join us: DevOps Corner (Developer Lounge – Moscone West)
• Learn more: openjdk.java.net | wercker.com/java
• Follow: @OpenJDK, @wercker #JavaOne #DevOps
80
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The preceding is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
Confidential – Oracle Internal/Restricted/Highly Restricted 81
Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [JavaOne 2017 CON3564]
Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [JavaOne 2017 CON3564]

More Related Content

What's hot

What's hot (20)

A Tale of Two Toolkits
A Tale of Two ToolkitsA Tale of Two Toolkits
A Tale of Two Toolkits
 
VMworld 2013: Building a Validation Factory for VMware Partners
VMworld 2013: Building a Validation Factory for VMware Partners VMworld 2013: Building a Validation Factory for VMware Partners
VMworld 2013: Building a Validation Factory for VMware Partners
 
SOA Suite 12c Customer implementation
SOA Suite 12c Customer implementationSOA Suite 12c Customer implementation
SOA Suite 12c Customer implementation
 
G1 garbage collector performance tuning
G1 garbage collector performance tuning G1 garbage collector performance tuning
G1 garbage collector performance tuning
 
Apouc 2014-enterprise-manager-12c
Apouc 2014-enterprise-manager-12cApouc 2014-enterprise-manager-12c
Apouc 2014-enterprise-manager-12c
 
Functions and DevOps
Functions and DevOpsFunctions and DevOps
Functions and DevOps
 
Oracle Cloud: Anything as a Service
Oracle Cloud: Anything as a ServiceOracle Cloud: Anything as a Service
Oracle Cloud: Anything as a Service
 
Database Design Thoughts
Database Design ThoughtsDatabase Design Thoughts
Database Design Thoughts
 
OOW-TBE-12c-CON7307-Sharable
OOW-TBE-12c-CON7307-SharableOOW-TBE-12c-CON7307-Sharable
OOW-TBE-12c-CON7307-Sharable
 
Sakai Technical Future Musings
Sakai Technical Future MusingsSakai Technical Future Musings
Sakai Technical Future Musings
 
Oracle Fusion Middleware on Exalogic Best Practises
Oracle Fusion Middleware on Exalogic Best PractisesOracle Fusion Middleware on Exalogic Best Practises
Oracle Fusion Middleware on Exalogic Best Practises
 
ClearCase Escape Plan
ClearCase Escape PlanClearCase Escape Plan
ClearCase Escape Plan
 
Oracle SPARC T7 a M7 servery
Oracle SPARC T7 a M7 serveryOracle SPARC T7 a M7 servery
Oracle SPARC T7 a M7 servery
 
Oracle Ravello
Oracle Ravello Oracle Ravello
Oracle Ravello
 
DevOps Culture & Enablement with Postgres Plus Cloud Database
DevOps Culture & Enablement with Postgres Plus Cloud DatabaseDevOps Culture & Enablement with Postgres Plus Cloud Database
DevOps Culture & Enablement with Postgres Plus Cloud Database
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
Continuous Availability for Private Database Clouds
Continuous Availability for Private Database CloudsContinuous Availability for Private Database Clouds
Continuous Availability for Private Database Clouds
 
Java APIs - the missing manual
Java APIs - the missing manualJava APIs - the missing manual
Java APIs - the missing manual
 
JAVA FPGA An Application for Space af Jens A. Hansen, CISS
JAVA FPGA An Application for Space af Jens A. Hansen, CISSJAVA FPGA An Application for Space af Jens A. Hansen, CISS
JAVA FPGA An Application for Space af Jens A. Hansen, CISS
 
VMworld 2013: Failsafe at PCIe Level: Enabling PCIe Hot Swap
VMworld 2013: Failsafe at PCIe Level: Enabling PCIe Hot Swap VMworld 2013: Failsafe at PCIe Level: Enabling PCIe Hot Swap
VMworld 2013: Failsafe at PCIe Level: Enabling PCIe Hot Swap
 

Similar to Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [JavaOne 2017 CON3564]

Top 10 Tips for an Effective Postgres Deployment
Top 10 Tips for an Effective Postgres DeploymentTop 10 Tips for an Effective Postgres Deployment
Top 10 Tips for an Effective Postgres Deployment
EDB
 

Similar to Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [JavaOne 2017 CON3564] (20)

Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]
Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]
Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]
 
OpenJDK: How to Join In on All the Fun [JavaOne 2017 CON3667]
OpenJDK: How to Join In on All the Fun [JavaOne 2017 CON3667]OpenJDK: How to Join In on All the Fun [JavaOne 2017 CON3667]
OpenJDK: How to Join In on All the Fun [JavaOne 2017 CON3667]
 
Java and Serverless - A Match Made In Heaven, Part 1
Java and Serverless - A Match Made In Heaven, Part 1Java and Serverless - A Match Made In Heaven, Part 1
Java and Serverless - A Match Made In Heaven, Part 1
 
Oracle EM12c Release 4 New Features!
Oracle EM12c Release 4 New Features!Oracle EM12c Release 4 New Features!
Oracle EM12c Release 4 New Features!
 
Oracle GoldenGate Performance Tuning
Oracle GoldenGate Performance TuningOracle GoldenGate Performance Tuning
Oracle GoldenGate Performance Tuning
 
Oracle Database Appliance, ODA, X7-2 portfolio.
Oracle Database Appliance, ODA, X7-2 portfolio.Oracle Database Appliance, ODA, X7-2 portfolio.
Oracle Database Appliance, ODA, X7-2 portfolio.
 
Serverless Kotlin
Serverless KotlinServerless Kotlin
Serverless Kotlin
 
Cloud Native Java:GraalVM
Cloud Native Java:GraalVMCloud Native Java:GraalVM
Cloud Native Java:GraalVM
 
Cloud Native 자바 플랫폼: Graalvm Overview
Cloud Native 자바 플랫폼: Graalvm OverviewCloud Native 자바 플랫폼: Graalvm Overview
Cloud Native 자바 플랫폼: Graalvm Overview
 
Dev ops in the cloud use case and best practices meetup
Dev ops in the cloud use case and best practices   meetupDev ops in the cloud use case and best practices   meetup
Dev ops in the cloud use case and best practices meetup
 
Getting Started with JDK Mission Control
Getting Started with JDK Mission ControlGetting Started with JDK Mission Control
Getting Started with JDK Mission Control
 
OUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source CodeOUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source Code
 
New availability features in oracle rac 12c release 2 anair ss
New availability features in oracle rac 12c release 2 anair   ssNew availability features in oracle rac 12c release 2 anair   ss
New availability features in oracle rac 12c release 2 anair ss
 
Let’s Write Our Own Chip-8 Interpreter! [JavaOne 2017 CON3584]
Let’s Write Our Own Chip-8 Interpreter! [JavaOne 2017 CON3584] Let’s Write Our Own Chip-8 Interpreter! [JavaOne 2017 CON3584]
Let’s Write Our Own Chip-8 Interpreter! [JavaOne 2017 CON3584]
 
Kscope Not Your Father's Enterprise Manager
Kscope Not Your Father's Enterprise ManagerKscope Not Your Father's Enterprise Manager
Kscope Not Your Father's Enterprise Manager
 
Meetup Oracle Database: 3 Analizar, Aconsejar, Automatizar… las nuevas funcio...
Meetup Oracle Database: 3 Analizar, Aconsejar, Automatizar… las nuevas funcio...Meetup Oracle Database: 3 Analizar, Aconsejar, Automatizar… las nuevas funcio...
Meetup Oracle Database: 3 Analizar, Aconsejar, Automatizar… las nuevas funcio...
 
Javantura v6 - JDK 11 & JDK 12 - Dalibor Topic
Javantura v6 - JDK 11 & JDK 12 - Dalibor TopicJavantura v6 - JDK 11 & JDK 12 - Dalibor Topic
Javantura v6 - JDK 11 & JDK 12 - Dalibor Topic
 
Oracle Storage a ochrana dat
Oracle Storage a ochrana datOracle Storage a ochrana dat
Oracle Storage a ochrana dat
 
Top 10 Tips for an Effective Postgres Deployment
Top 10 Tips for an Effective Postgres DeploymentTop 10 Tips for an Effective Postgres Deployment
Top 10 Tips for an Effective Postgres Deployment
 
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQLMySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
 

More from David Buck

More from David Buck (20)

JDK 13 New Features [MeetUp with Java Experts! @Gaienmae/Dojima 2019]
JDK 13 New Features [MeetUp with Java Experts! @Gaienmae/Dojima 2019]JDK 13 New Features [MeetUp with Java Experts! @Gaienmae/Dojima 2019]
JDK 13 New Features [MeetUp with Java Experts! @Gaienmae/Dojima 2019]
 
JDK Mission Control: Where We Are, Where We Are Going [Groundbreakers APAC 20...
JDK Mission Control: Where We Are, Where We Are Going [Groundbreakers APAC 20...JDK Mission Control: Where We Are, Where We Are Going [Groundbreakers APAC 20...
JDK Mission Control: Where We Are, Where We Are Going [Groundbreakers APAC 20...
 
Java Bytecode Crash Course [Code One 2019]
Java Bytecode Crash Course [Code One 2019]Java Bytecode Crash Course [Code One 2019]
Java Bytecode Crash Course [Code One 2019]
 
CSI (Crash Scene Investigation) HotSpot: Common JVM Crash Causes and Solution...
CSI (Crash Scene Investigation) HotSpot: Common JVM Crash Causes and Solution...CSI (Crash Scene Investigation) HotSpot: Common JVM Crash Causes and Solution...
CSI (Crash Scene Investigation) HotSpot: Common JVM Crash Causes and Solution...
 
invokedynamic for Mere Mortals [Code One 2019]
invokedynamic for Mere Mortals [Code One 2019]invokedynamic for Mere Mortals [Code One 2019]
invokedynamic for Mere Mortals [Code One 2019]
 
Hangs, Slowdowns, Starvation—Oh My! A Deep Dive into the Life of a Java Threa...
Hangs, Slowdowns, Starvation—Oh My! A Deep Dive into the Life of a Java Threa...Hangs, Slowdowns, Starvation—Oh My! A Deep Dive into the Life of a Java Threa...
Hangs, Slowdowns, Starvation—Oh My! A Deep Dive into the Life of a Java Threa...
 
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
 
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
 
Z Garbage Collector
Z Garbage CollectorZ Garbage Collector
Z Garbage Collector
 
Valhalla Update JJUG CCC Spring 2019
Valhalla Update JJUG CCC Spring 2019Valhalla Update JJUG CCC Spring 2019
Valhalla Update JJUG CCC Spring 2019
 
Var handles jjug_ccc_spring_2018
Var handles jjug_ccc_spring_2018Var handles jjug_ccc_spring_2018
Var handles jjug_ccc_spring_2018
 
JDK 10 へようこそ
JDK 10 へようこそJDK 10 へようこそ
JDK 10 へようこそ
 
Java SE 8におけるHotSpotの進化 [Java Day Tokyo 2014 C-2]
Java SE 8におけるHotSpotの進化 [Java Day Tokyo 2014 C-2]Java SE 8におけるHotSpotの進化 [Java Day Tokyo 2014 C-2]
Java SE 8におけるHotSpotの進化 [Java Day Tokyo 2014 C-2]
 
HotSpot のロック: A Peek Under the Hood [JJUG ナイトセミナ JVM 特集 2015年8月]
HotSpot のロック: A Peek Under the Hood [JJUG ナイトセミナ  JVM 特集  2015年8月]HotSpot のロック: A Peek Under the Hood [JJUG ナイトセミナ  JVM 特集  2015年8月]
HotSpot のロック: A Peek Under the Hood [JJUG ナイトセミナ JVM 特集 2015年8月]
 
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
 
Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]
Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]
Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]
 
Java Debuggers: A Peek Under the Hood [JavaOne 2016 CON1503]
Java Debuggers: A Peek Under the Hood [JavaOne 2016 CON1503]Java Debuggers: A Peek Under the Hood [JavaOne 2016 CON1503]
Java Debuggers: A Peek Under the Hood [JavaOne 2016 CON1503]
 
Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]
Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]
Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]
 
Java Concurrency, A(nother) Peek Under the Hood [Java Day Tokyo 2016 3-C]
Java Concurrency, A(nother) Peek Under the Hood [Java Day Tokyo 2016 3-C]Java Concurrency, A(nother) Peek Under the Hood [Java Day Tokyo 2016 3-C]
Java Concurrency, A(nother) Peek Under the Hood [Java Day Tokyo 2016 3-C]
 
Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]
Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]
Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]
 

Recently uploaded

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 

Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [JavaOne 2017 CON3564]

  • 1.
  • 2.
  • 3. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [CON3564] David Buck Principal Member of Technical Staff Java Platform Group October 3rd, 2017 Confidential – Oracle Internal/Restricted/Highly Restricted 3
  • 4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. Confidential – Oracle Internal/Restricted/Highly Restricted 4
  • 5. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | • JVM Sustaining Engineer • OpenJDK 8 Update Project Maintainer • JavaOne Rock Star • Co-author of Oracle WebLogic Server 11g 構築・運用ガイド • @DavidBuckJP • https://blogs.oracle.com/buck/ Who am I?
  • 6. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Who are you? • Just about any Java programmer who uses HotSpot Confidential – Oracle Internal/Restricted/Highly Restricted 6
  • 7. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | What? • Crash course on HotSpot's JIT compilation Confidential – Oracle Internal/Restricted/Highly Restricted 7
  • 8. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Why? • Focus on what matters (no premature optimization) • Better tuning / troubleshooting • Fun Confidential – Oracle Internal/Restricted/Highly Restricted 8
  • 9. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Why Now? • Still an area of frequent development – Tiered compilation – Interaction with new features • Still an area of frequent misunderstanding / confusion / interest – Premature optimization Confidential – Oracle Internal/Restricted/Highly Restricted 9
  • 10. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Program Agenda Introduction Implementation Monitoring Control 1 2 3 4 Confidential – Oracle Internal/Restricted/Highly Restricted 10
  • 11. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Introduction Confidential – Oracle Internal/Restricted/Highly Restricted 11
  • 12. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | What is JIT? Just-in-Time compilation Confidential – Oracle Internal/Restricted/Highly Restricted 12
  • 13. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Classic JIT • All methods or functions compiled immediately before use • No interpreter • Example: JRockit Confidential – Oracle Internal/Restricted/Highly Restricted 13
  • 14. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Classic JIT Example: JRockit Confidential – Oracle Internal/Restricted/Highly Restricted 14
  • 15. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JIT is very old • LISP (John McCarthy, 1960) • QED text editor regular expressions (Ken Thompson, 1968) • Smalltalk (1983) • Self (1990s?) Confidential – Oracle Internal/Restricted/Highly Restricted 15
  • 16. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JIT for Java is very old • Microsoft and Symantec had their own JIT compilers for browsers • Symantec deal with Sun (project java activator) • JIT added to "Classic" JVM in JDK 1.2 • HotSpot available as an optional addition in 1.2 • HotSpot shipped with 1.3 Confidential – Oracle Internal/Restricted/Highly Restricted 16
  • 17. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Static Compilation • Pros: – No runtime overhead • Cons: – Portability issues – No ability to adapt • To hardware • To application behavior Interpreter • Pros: – Portable – Adaptable • Cons: – Interpretation overhead Confidential – Oracle Internal/Restricted/Highly Restricted 17 Static Compilation vs. Interpreter
  • 18. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Classic JIT compared to both compilation / interpreter • Pros: – No interpretation runtime overhead – Portable – Adaptable • Cons: – Runtime JIT compilation overhead – Slower startup time Confidential – Oracle Internal/Restricted/Highly Restricted 18
  • 19. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Static Initializers The poster boy for wasteful JIT overhead static { // important class-level // initialization goes here! } Confidential – Oracle Internal/Restricted/Highly Restricted 19
  • 20. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | HotSpot JIT Compilation • Only JIT compile hot stuff (hotspots) • Interpret the rest Confidential – Oracle Internal/Restricted/Highly Restricted 20
  • 21. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Why is this important? • Don’t JIT stuff that is not hot • No need to wait for a JIT to finish (asynchronous JIT) Confidential – Oracle Internal/Restricted/Highly Restricted 21
  • 22. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | HotSpot JIT compared to Classic JIT • Pros – Portable – Adaptable – Fast (startup and peak) • Cons – Complicated to implement Confidential – Oracle Internal/Restricted/Highly Restricted 22
  • 23. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | A Note on Nomenclature… • HotSpot == Runtime Profiling used to identify candidates for JIT compilation • HotSpot == JVM – Profiling technique – JIT policy • HotSpot does use JIT Confidential – Oracle Internal/Restricted/Highly Restricted 23
  • 24. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Implementation Confidential – Oracle Internal/Restricted/Highly Restricted 24
  • 25. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | JIT Compiler Design Goals • Lightweight – Fast startup – Small memory footprint – Low compilation overhead • Generate high-performance code – Many complex optimizations – Based on heavy profiling of code – Output peak performance often bests C/C++ Confidential – Oracle Internal/Restricted/Highly Restricted 25
  • 26. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Client • Short-lived processes • Run on client machines with low resources (desktops / laptops) Server (Application servers, Batch processing) • Long-lived processes • Run on dedicated machines with plentiful resources Confidential – Oracle Internal/Restricted/Highly Restricted 26 Two Use Cases
  • 27. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Client Compiler (C1): • Only simple optimizations • Quick compilation • Low memory requirements • Not dependent on profiling data • Reasonable peak performance Server Compiler (C2): • Highly optimizing • Slow compilation • Heavy memory usage • Dependent on profiling data • Great peak performance Confidential – Oracle Internal/Restricted/Highly Restricted 27 Two JIT Compilers
  • 28. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Client Compiler (C1): • Only simple optimizations • Quick compilation • Low memory requirements • Not dependent on profiling data • Reasonable peak performance Server Compiler (C2): • Highly optimizing • Slow compilation • Heavy memory usage • Dependent on profiling data • Great peak performance Confidential – Oracle Internal/Restricted/Highly Restricted 28 Two JIT Compilers
  • 29. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Profiling Interpreter collets profiling information, basically free • Invocation counter • Backwards jumps • Invokevirtual targets • Branch prediction Confidential – Oracle Internal/Restricted/Highly Restricted 29
  • 30. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Client JVM • Only C1 used • Many tuning defaults / ergonomics / heuristics tuned for client usage • Reaches peak performance quickly Server JVM • Traditionally only C2 used (more to come) • Many tuning defaults / ergonomics / heuristics tuned for server usage • May take a while to reach peak performance • The only JVM to support 64-bit Confidential – Oracle Internal/Restricted/Highly Restricted 30 A Tail of Two JVMs
  • 31. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Java Launcher Confidential – Oracle Internal/Restricted/Highly Restricted 31 bin/java jre/lib/<arch>/server/libjvm.so jre/lib/<arch>/client/libjvm.so
  • 32. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Client JVM • Only C1 used • Many tuning defaults / ergonomics / heuristics tuned for client usage • Reaches peak performance quickly Server JVM • Traditionally only C2 used (more to come) • Many tuning defaults / ergonomics / heuristics tuned for server usage • May take a while to reach peak performance • The only JVM to support 64-bit Confidential – Oracle Internal/Restricted/Highly Restricted 32 A Tail of Two JVMs
  • 33. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | class A { B b; public void foo() { y = b.get(); ...do stuff... z = b.get(); sum = y + z; } } class B { int value; final int get() { return value; } } Confidential – Oracle Internal/Restricted/Highly Restricted 33 Optimization Example
  • 34. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | class A { B b; public void foo() { y = b.get(); ...do stuff... z = b.get(); sum = y + z; } } class B { int value; final int get() { return value; } } Confidential – Oracle Internal/Restricted/Highly Restricted 34 Optimization Example
  • 35. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | class A { B b; public void foo() { y = b.value; ...do stuff... z = b.value; sum = y + z; } } class B { int value; final int get() { return value; } } Confidential – Oracle Internal/Restricted/Highly Restricted 35 Optimization Example
  • 36. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | class A { B b; public void foo() { y = b.value; ...do stuff... z = b.value; sum = y + z; } } class B { int value; final int get() { return value; } } Confidential – Oracle Internal/Restricted/Highly Restricted 36 Optimization Example
  • 37. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | class A { B b; public void foo() { y = b.value; ...do stuff... z = b.value; sum = y + z; } } class B { int value; final int get() { return value; } } Confidential – Oracle Internal/Restricted/Highly Restricted 37 Optimization Example
  • 38. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | class A { B b; public void foo() { y = b.value; ...do stuff... z = y; sum = y + z; } } class B { int value; final int get() { return value; } } Confidential – Oracle Internal/Restricted/Highly Restricted 38 Optimization Example
  • 39. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | class A { B b; public void foo() { y = b.value; ...do stuff... z = y; sum = y + z; } } class B { int value; final int get() { return value; } } Confidential – Oracle Internal/Restricted/Highly Restricted 39 Optimization Example
  • 40. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | class A { B b; public void foo() { y = b.value; ...do stuff... y = y; sum = y + y; } } class B { int value; final int get() { return value; } } Confidential – Oracle Internal/Restricted/Highly Restricted 40 Optimization Example
  • 41. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | class A { B b; public void foo() { y = b.value; ...do stuff... y = y; sum = y + y; } } class B { int value; final int get() { return value; } } Confidential – Oracle Internal/Restricted/Highly Restricted 41 Optimization Example
  • 42. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | class A { B b; public void foo() { y = b.value; ...do stuff... sum = y + y; } } class B { int value; final int get() { return value; } } Confidential – Oracle Internal/Restricted/Highly Restricted 42 Optimization Example
  • 43. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | class A { B b; public void foo() { y = b.get(); ...do stuff... z = b.get(); sum = y + z; } } class A { B b; public void foo() { y = b.value; ...do stuff... sum = y + y; } } Confidential – Oracle Internal/Restricted/Highly Restricted 43 Optimization Example (Before and After)
  • 44. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Tiered Compilation • Interpretation -> C1 -> C2 (very simplified version) • Quick warmup of C1, but with the higher peak performance of C2 Confidential – Oracle Internal/Restricted/Highly Restricted 44
  • 45. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Tiered Compilation • Existed since early JDK 6 releases (not officially supported) • Officially supported in JDK 7 (use not recommended) • Enabled by default from JDK 8 Confidential – Oracle Internal/Restricted/Highly Restricted 45
  • 46. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Tiered Compilation • Level 0 - interpreter • Level 1 - C1 with full optimization (no profiling) • Level 2 - C1 with invocation and backedge counters • Level 3 - C1 with full profiling (level 2 + MDO) • Level 4 - C2 Confidential – Oracle Internal/Restricted/Highly Restricted 46
  • 47. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Code Cache • Contains: – JITed code – JNI wrapper / stubs – HotSpot template interpreter • Cleaned up by the “sweeper thread” • Compiler disabled if you run out of space Confidential – Oracle Internal/Restricted/Highly Restricted 47
  • 48. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Monitoring Confidential – Oracle Internal/Restricted/Highly Restricted 48
  • 49. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | public static void main(String[] args) { long i = 0; while (true) { i = addStuff(i, 1); if (i % Long.MAX_VALUE == 0) System.out.println(i); } } private static long addStuff(long a, long b) { return a+b; } Confidential – Oracle Internal/Restricted/Highly Restricted 49 A Rather Contrived Example…
  • 50. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 50 $ java -XX:+PrintCompilation HotMethodDemo 156 24 3 HotMethodDemo::addStuff (4 bytes) 161 25 1 HotMethodDemo::addStuff (4 bytes) 161 24 3 HotMethodDemo::addStuff (4 bytes) made not entrant Some Visibility
  • 51. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 51 $ java -XX:+PrintCompilation HotMethodDemo 156 24 3 HotMethodDemo::addStuff (4 bytes) 161 25 1 HotMethodDemo::addStuff (4 bytes) 161 24 3 HotMethodDemo::addStuff (4 bytes) made not entrant Timestamp Compilation ID Compilation Tier Method Size Other Information Some Visibility
  • 52. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 52 $ java -XX:+PrintCompilation HotMethodDemo 100 1 3 java.lang.String::hashCode (55 bytes) 101 2 3 java.lang.String::equals (81 bytes) 104 3 3 java.lang.String::indexOf (70 bytes) 105 4 3 java.lang.String::charAt (29 bytes) 106 5 3 java.lang.String::length (6 bytes) 107 6 3 java.lang.Object::<init> (1 bytes) 111 7 n 0 java.lang.System::arraycopy (native) (static) 113 8 3 java.lang.Math::min (11 bytes) 113 9 3 java.lang.AbstractStringBuilder::ensureCapacityInternal (27 bytes) 114 10 1 java.lang.Object::<init> (1 bytes) 114 6 3 java.lang.Object::<init> (1 bytes) made not entrant 115 11 1 java.lang.ref.Reference::get (5 bytes) 118 12 3 java.util.HashMap::hash (20 bytes) 118 13 3 java.util.Arrays::copyOfRange (63 bytes) 120 14 3 java.util.HashMap::getNode (148 bytes) 121 15 4 java.lang.String::equals (81 bytes) 124 16 3 java.util.LinkedList::indexOf (73 bytes) 125 17 3 java.util.HashMap::get (23 bytes) 133 18 ! 3 java.io.BufferedReader::readLine (304 bytes) 148 19 3 sun.misc.JarIndex::addToList (59 bytes) 149 20 3 java.util.LinkedList::add (7 bytes) 150 2 3 java.lang.String::equals (81 bytes) made not entrant 150 21 3 java.lang.String::<init> (82 bytes) 150 22 1 java.lang.ThreadLocal::access$400 (5 bytes) 151 23 3 java.lang.String::getChars (62 bytes) 156 24 3 HotMethodDemo::addStuff (4 bytes) 161 25 1 HotMethodDemo::addStuff (4 bytes) 161 24 3 HotMethodDemo::addStuff (4 bytes) made not entrant 163 26 % 3 HotMethodDemo::main @ 2 (28 bytes) 168 27 3 HotMethodDemo::main (28 bytes) 193 28 % 4 HotMethodDemo::main @ 2 (28 bytes) Some Visibility
  • 53. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Compilation Flags b Blocking compile % On stack replacement ! Method has exception handlers s Method declared as synchronized n Method declared as native Confidential – Oracle Internal/Restricted/Highly Restricted 53
  • 54. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Compilation Flags b Blocking compile % On stack replacement ! Method has exception handlers s Method declared as synchronized n Method declared as native Confidential – Oracle Internal/Restricted/Highly Restricted 54
  • 55. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Blocking Compilation • Methods are compiled asynchronously by default • Can force compilation to block with -Xbatch Confidential – Oracle Internal/Restricted/Highly Restricted 55
  • 56. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Compilation Flags b Blocking compile % On stack replacement ! Method has exception handlers s Method declared as synchronized n Method declared as native Confidential – Oracle Internal/Restricted/Highly Restricted 56
  • 57. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | public static void main(String[] args) { long i = 0; while (true) { i = addStuff(i, 1); if (i % Long.MAX_VALUE == 0) System.out.println(i); } } private static long addStuff(long a, long b) { return a+b; } Confidential – Oracle Internal/Restricted/Highly Restricted 57 A Rather Contrived Example…
  • 58. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | public static void main(String[] args) { long i = 0; while (true) { i = addStuff(i, 1); if (i % Long.MAX_VALUE == 0) System.out.println(i); } } private static long addStuff(long a, long b) { return a+b; } Confidential – Oracle Internal/Restricted/Highly Restricted 58 A Rather Contrived Example…
  • 59. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | On Stack Replacement • JIT compile a method while it is being run • ARs for Interpreter and JIT frames look very different – Must convert interpreter frame to JIT frame • JIT compiled method entry is in the middle of method Confidential – Oracle Internal/Restricted/Highly Restricted 59
  • 60. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 60 $ java -XX:+PrintCompilation HotMethodDemo 156 24 3 HotMethodDemo::addStuff (4 bytes) 161 25 1 HotMethodDemo::addStuff (4 bytes) 161 24 3 HotMethodDemo::addStuff (4 bytes) made not entrant 163 26 % 3 HotMethodDemo::main @ 2 (28 bytes) 168 27 3 HotMethodDemo::main (28 bytes) 193 28 % 4 HotMethodDemo::main @ 2 (28 bytes) Some More Visibility
  • 61. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 61 private static long addStuff(long, long); descriptor: (JJ)J flags: ACC_PRIVATE, ACC_STATIC Code: stack=4, locals=4, args_size=2 0: lload_0 1: lload_2 2: ladd 3: lreturn Bytecode - addStuff
  • 62. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 62 public static void main(java.lang.String[]); descriptor: ([Ljava/lang/String;)V flags: ACC_PUBLIC, ACC_STATIC Code: stack=4, locals=3, args_size=1 0: lconst_0 1: lstore_1 2: lload_1 3: lconst_1 4: invokestatic #2 // Method addStuff:(JJ)J 7: lstore_1 8: lload_1 9: ldc2_w #4 // long 9223372036854775807l 12: lrem 13: lconst_0 14: lcmp 15: ifne 2 18: getstatic #6 // Field java/lang/System.out:Ljava/io/PrintStream; 21: lload_1 22: invokevirtual #7 // Method java/io/PrintStream.println:(J)V 25: goto 2 Bytecode - main
  • 63. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 63 $ java -XX:+PrintCompilation HotMethodDemo 156 24 3 HotMethodDemo::addStuff (4 bytes) 161 25 1 HotMethodDemo::addStuff (4 bytes) 161 24 3 HotMethodDemo::addStuff (4 bytes) made not entrant 163 26 % 3 HotMethodDemo::main @ 2 (28 bytes) 168 27 3 HotMethodDemo::main (28 bytes) 193 28 % 4 HotMethodDemo::main @ 2 (28 bytes) Some More Visibility
  • 64. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 64 $ java -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining HotMethodDemo 203 21 3 HotMethodDemo::addStuff (4 bytes) 212 22 1 HotMethodDemo::addStuff (4 bytes) 212 21 3 HotMethodDemo::addStuff (4 bytes) made not entrant 217 23 % 3 HotMethodDemo::main @ 2 (28 bytes) @ 4 HotMethodDemo::addStuff (4 bytes) @ 22 java/io/PrintStream::println (not loaded) not inlineable 218 24 3 HotMethodDemo::main (28 bytes) @ 4 HotMethodDemo::addStuff (4 bytes) @ 22 java/io/PrintStream::println (not loaded) not inlineable 220 25 % 4 HotMethodDemo::main @ 2 (28 bytes) @ 4 HotMethodDemo::addStuff (4 bytes) inline (hot) 227 23 % 3 HotMethodDemo::main @ -2 (28 bytes) made not entrant A Lot More Visibility
  • 65. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Control Confidential – Oracle Internal/Restricted/Highly Restricted 65
  • 66. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | A Word of Warning… • Performance tuning JIT compilation usually a waste of time • Being able to troubleshoot / workaround bugs may be useful Confidential – Oracle Internal/Restricted/Highly Restricted 66
  • 67. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Most Important Options (All or Nothing) • -Xint – Interpreter only (disables all JIT) – Good for trying to simplify test cases • -Xcomp – JIT only (disables interpreter) – Good for trying to reproduce JIT issues / behavior Confidential – Oracle Internal/Restricted/Highly Restricted 67
  • 68. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Most Important Options (JVM Selection) • -client – Only available on 32-bit – C1 compiler only – Default compile threshold: 1,500 • -server – Only option for 64-bit JVMs – C2 compiler (and C1 w/ Tiered Compilation) – Default compile threshold: 10,000 Confidential – Oracle Internal/Restricted/Highly Restricted 68
  • 69. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Most Important Options (JIT Timing) • XX:CompileThreshold – Number of invocations before method is considered “hot” – Default varies based on JVM (client / server) • Xbatch – Disables asynchronous compilation – Makes compilation much more deterministic Confidential – Oracle Internal/Restricted/Highly Restricted 69
  • 70. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Most Important Options (Tiered Compilation) • -XX:-TieredCompilation – Effectively disables C1 on server JVMs • -XX:TieredStopAtLevel – TieredStopAtLevel=1 can be used to get “client like” behavior Confidential – Oracle Internal/Restricted/Highly Restricted 70
  • 71. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Most Important Options (Fine-grained Control) • XX:CompileCommand – help (does not list all commands) – option – log – compileonly – exclude – print – inline – dontinline Confidential – Oracle Internal/Restricted/Highly Restricted 71
  • 72. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Compiler Control • New in JDK 9 (JEP 165) • Inspired by JRockit • JSON-based configuration file • Can be specified with XX:CompilerDirectivesFile Confidential – Oracle Internal/Restricted/Highly Restricted 72
  • 73. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Compiler Control: Example 1 { // start of another directives block // match ant method whose class end with 'Concurrent' match: ["*Concurrent.*"], c2: { // disable compilation Exclude:true, } // with the c1 directive unspecified the options remains default. } Confidential – Oracle Internal/Restricted/Highly Restricted 73
  • 74. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Compiler Control: Example 2 { match: ["java*.*", "oracle*.*"], c1: { // A bool option. Extra trailing comma should not cause a parse error PrintAssembly:true, }, c2: { // force inline patters prepended with +, prevent with - inline: ["+vm*.*","-*.*" ] }, }, Confidential – Oracle Internal/Restricted/Highly Restricted 74
  • 75. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Compiler Control: diagnostic commands • jcmd <pid> Compiler.add_directives <file> Add additional directives from the file. The new directives will be added on top of the old, with the first directive in the file ending up on the top of the directives stack. • jcmd <pid> Compiler.list_directives List all directives on the directives stack from top to bottom. • jcmd <pid> Compiler.clear_directives Clear the directives stack • jcmd <pid> Compiler.remove_directives Remove the top element from the directives stack Confidential – Oracle Internal/Restricted/Highly Restricted 75
  • 76. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Conclusions Confidential – Oracle Internal/Restricted/Highly Restricted 76
  • 77. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | • JIT Compilation can do optimizations static compilers can not do • You should avoid premature optimization • JIT (especially C2) behavior can be very non-deterministic Confidential – Oracle Internal/Restricted/Highly Restricted 77
  • 78. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Thank You! Confidential – Oracle Internal/Restricted/Highly Restricted 78
  • 79. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | • The Java HotSpot Performance Engine Architecture (A little out-of-date, but still a good primer) http://www.oracle.com/technetwork/java/whitepaper- 135217.html • PrintAssembly (HSDIS) https://wiki.openjdk.java.net/display/HotSpot/PrintAsse mbly • It's All Relative - CompileCommand JVM option http://jpbempel.blogspot.com/2016/03/compilecomman d-jvm-option.html • Kris Mok's PrintCompilation Notes https://gist.github.com/rednaxelafx/1165804#file_notes. md • Java Performance, Hunt & John https://www.pearson.com/us/higher- education/program/Hunt-Java- Performance/PGM182574.html • Java Performance Companion, Hunt & Beckwith & Parhar & Rutisson https://www.pearson.com/us/higher- education/program/Hunt-Java-Performance- Companion/PGM168439.html Confidential – Oracle Internal/Restricted/Highly Restricted 79 Resources
  • 80. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Stay connected • Join us: DevOps Corner (Developer Lounge – Moscone West) • Learn more: openjdk.java.net | wercker.com/java • Follow: @OpenJDK, @wercker #JavaOne #DevOps 80
  • 81. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. Confidential – Oracle Internal/Restricted/Highly Restricted 81