More Related Content Similar to Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [JavaOne 2017 CON3564] (20) More from David Buck (20) Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [JavaOne 2017 CON3564]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