SlideShare a Scribd company logo
1 of 89
Download to read offline
Douglas Q. Hawkins
VM Engineer
VM MechanicsWhen Does the JVM JIT & Deoptimize?
J
https://github.com/dougqh/jvm-mechanics
About Azul Systems
Zulu®
Multi-Platform OpenJDK
Cloud Support including Docker and Azure
Embedded Support
Zing®
Highly ScalableVM
Continuously Concurrent Compacting Collector
ReadyNow! for Low Latency Applications
http://www.azulsystems.com/
HotSpot Lifecycle
1 2
34
Interpret Profile
Just-in-Time
CompilationDeoptimize
?Why?
public class SimpleProgram {
static final int CHUNK_SIZE = 1_000;
public static void main(String[] args) {
for ( int i = 0; i < 250; ++i ) {
long startTime = System.nanoTime();
for ( int j = 0; j < CHUNK_SIZE; ++j ) {
new Object();
}
long endTime = System.nanoTime();
System.out.printf("%dt%d%n", i, endTime - startTime);
}
}
}
A Simple Program
example01a.SimpleProgram
Code Reference
0
400000
800000
1200000
1600000
0
13
26
39
52
65
78
91
104
117
130
143
156
169
182
195
208
221
234
247
Simple Program Performance
GC Pauses!
1
1000
1000000
0
12
24
36
48
60
72
84
96
108
120
132
144
156
168
180
192
204
216
228
240
Interpreter 1st JIT 2nd JIT
Log Scale
public class NotSoSimpleProgram {
static final int CHUNK_SIZE = 1_000;
public static void main(String[] args) {
Object trap = null;
for ( int i = 0; i < 250; ++i ) {
long startTime = System.nanoTime();
for ( int j = 0; j < CHUNK_SIZE; ++j ) {
new Object();
if ( trap != null ) {
System.out.println("trap!");
trap = null;
}
}
if ( i == 200 ) trap = new Object();
long endTime = System.nanoTime();
System.out.printf("%dt%d%n", i, endTime - startTime);
}
}
}
Not So Simple Program
example01b.NotSoSimpleProgram
Deoptimization
1
1000
1000000
0
12
24
36
48
60
72
84
96
108
120
132
144
156
168
180
192
204
216
228
240
behavioral change,
deoptimize!
Dynamically Generated
Threaded Interpreter
Identify “Hot Spots”
Slow!
10000x
Interpreter
http://openjdk.java.net/groups/hotspot/docs/RuntimeOverview.html
Invocation Counter
example02.InvocationCounter
public class InvocationCounter {
public static void main(final String[] args)
throws InterruptedException
{
for ( int i = 0; i < 20_000; ++i ) {
hotMethod();
}
System.out.println("Waiting for compiler...");
Thread.sleep(5_000);
}
static void hotMethod() {}
}
-XX:+PrintCompilation
example02.InvocationCounter
299 1 % java.lang.String::indexOf @ 37 (70 bytes)
332 2 java.lang.String::indexOf (70 bytes)
364 3 example02.InvocationCounter::hotMethod (1 bytes)
365 4 % example02.InvocationCounter::main @ 5 (33 bytes)
Waiting for compiler...
Invocation Counter
Compilation Log
5328 50 n java.io.FileOutputStream::writeBytes (native)
5330 27 java.nio.CharBuffer::wrap (20 bytes)
5333 31 s java.io.BufferedOutputStream::flush (12 bytes)
5477 56 % CompilationExample::main @ 37 (82 bytes)
timestamp (since VM start)
compilation ID method name method size
native
exception handler
synchronized method
on-stack replacement loop bytecode index
!
synchronized is try/finally
synchronized ( foo.getBar() ) {
...
}
tmp = foo.getBar();
monitor_enter(tmp);
try {
...
} finally {
monitor_exit(tmp);
}
Duplicate Methods &
Overloading
5208 4 java.nio.Buffer::position (5 bytes)
...
5223 8 java.nio.Buffer::position (43 bytes)
Invisible Overloads
via Bridge Methods
public interface Supplier<T> {
public abstract T get();
}
new Supplier<String>() {
public final String get() { return “foo”; }
};
145 4 InvisibleOverload$1::get (5 bytes)
145 5 InvisibleOverload$1::get (3 bytes)
public class BackedgeCounter {
public static void main(final String[] args)
throws InterruptedException
{
for ( int i = 0; i < 20_000; ++i ) {
hotMethod();
}
System.out.println("Waiting for compiler...");
Thread.sleep(5_000);
for ( int i = 0; i < 20_000; ++i ) {
hotMethod();
}
System.out.println("Waiting for compiler...");
Thread.sleep(5_000);
}
static void hotMethod() {}
}
Backedge Counter
example03.BackedgeCounter
163 1 java.lang.String::charAt (29 bytes)
166 2 java.lang.String::hashCode (55 bytes)
171 3 java.lang.String::indexOf (70 bytes)
193 4 example03.BackedgeCounter::hotMethod (1 bytes)
194 5 % example03.BackedgeCounter::main @ 5 (65 bytes)
Waiting for compiler...
5196 6 % example03.BackedgeCounter::main @ 37 (65 bytes)
Waiting for compiler...
-XX:+PrintCompilation
example03.BackedgeCounter
Backedge Counter
On-Stack Replacement
eventLoop
...
...
main
eventLoop @ 20
...
...
main
interpreter frame
compiled frame
Both Counters
public class BothCounters {
public static void main(final String[] args)
throws InterruptedException
{
for ( int i = 0; i < 2; ++i ) {
outerMethod();
}
System.out.println("Waiting for compiler...");
Thread.sleep(5000);
}
static void outerMethod() {
for ( int i = 0; i < 10_000; ++i ) {
innerMethod();
}
}
static void innerMethod() {}
}
example04.BothCounters
-XX:+PrintCompilation
example04.BothCounters
Both Counters
115 1 % java.lang.String::indexOf @ 37 (70 bytes)
123 2 example04.BothCounters::innerMethod (1 bytes)
124 3 example04.BothCounters::outerMethod (19 bytes)
125 4 % example04.BothCounters::outerMethod @ 5 (19 bytes)
Waiting for compiler...
HotSpot:
A Tale of Two Compilers
C1client C2 server
C1 ClientVM
The Fast Acting Compiler
Compiles with Count > 1,000
(2,000 in Tiered)
Produces Compilations Quickly
Generated Code Runs Relatively Slowly
Compiles with Count > 10,000
(15,000 in Tiered)
Profile Guided
C2 ServerVM
The Smart compiler
Speculative
2xSpeed!
Produces Compilations Slowly
Generated Code Runs Fast
Tiered Compilation
Available in Java 7 - default in Java 8
Best of Both Worlds - C1 & C2
Interpreter
> 2,000 > 15,000
C1 C2
http://www.slideshare.net/maddocig/tiered
0
0
0
interpreter
3 4
2 3 4
1 3
c1 c2
none
basic
counters detailed
common
c2 busy
trivial
method
Tiered Compilation
public final class TieredCompilation {
public static final void main(final String[] args)
throws InterruptedException
{
for ( int i = 0; i < 3_000; ++i ) {
method();
}
System.out.println("Waiting for the compiler...");
Thread.sleep(5_000);
for ( int i = 0; i < 20_000; ++i ) {
method();
}
System.out.println("Waiting for the compiler...");
Thread.sleep(5_000);
}
private static final void method() {
// Do something while doing nothing.
System.out.print('0');
}
}
example05.TieredCompilation
Tiered Compilation
183 69 3 sun...SingleByte$Encoder::encodeArrayLoop (236 bytes)
...
5237 101 4 sun...SingleByte$Encoder::encodeArrayLoop (236 bytes)
5255 69 3 sun...SingleByte$Encoder::encodeArrayLoop (236 bytes) made not entrant
131 3 3 java.lang.Object::<init> (1 bytes)
...
140 15 1 java.lang.Object::<init> (1 bytes)
141 3 3 java.lang.Object::<init> (1 bytes) made not entrant
126 6 n 0 java.lang.System::arraycopy (native) (static)
-XX:+TieredCompilation
-XX:+PrintCompilation
example05.TieredCompilation
Tiered Compilation
tier
1
1000
1000000
0
12
24
36
48
60
72
84
96
108
120
132
144
156
168
180
192
204
216
228
240
Interpreter Tier 3 (c1) Tier 4 (c2)
Tiered Compilation
Optimizations
Intrinsics
Special code built-into theVM for a particular method
Built-in to theVM - not written in Java (usually)
For Example...
System.arraycopy
Math.sin / cos / tan
Often use special hardware capabilities:
MMX,AVX2, etc
http://en.wikipedia.org/wiki/Common_subexpression_elimination
Common Sub-Expression
Elimination
int a = b * c + g;
int d = b * c * e;
int tmp = b * c;
int a = tmp + g;
int d = tmp * e;
bool isDebugEnabled = LOGGER.isDebugEnabled();
for ( User user: users ) {
...do something...
if ( isDebugEnabled ) {
LOGGER.debug(user.getName());
}
}
bool isDebugEnabled = LOGGER.isDebugEnabled();
if ( isDebugEnabled ) {
for ( User user: users ) {
...do something...
LOGGER.debug(user.getName());
}
} else {
for ( User user: users ) {
...do something...
}
}
Loop Unswitching
http://en.wikipedia.org/wiki/Loop_unswitching
Dead Code Elimination
http://en.wikipedia.org/wiki/Dead_code_elimination
public int ArrayList::indexOf(Object o) {
if (o == null) {
for (int i = 0; i < size; i++)
if (elementData[i]==null)
return i;
} else {
for (int i = 0; i < size; i++)
if (o.equals(elementData[i]))
return i;
}
return -1;
}
Lock Coarsening
StringBuffer buffer = ...
buffer.append(“Hello”);
buffer.append(name);
buffer.append(“n”);
StringBuffer buffer = ...
lock(buffer); buffer.append(“Hello”); unlock(buffer);
lock(buffer); buffer.append(name); unlock(buffer);
lock(buffer); buffer.append(“n”); unlock(buffer);
StringBuffer buffer = ...
lock(buffer);
buffer.append(“Hello”);
buffer.append(name);
buffer.append(“n”);
unlock(buffer);
http://www.ibm.com/developerworks/library/j-jtp10185/index.html
Inlining
“The mother of all optimizations.”
IPO: Inter-procedural Optimization
Intrinsic Inlining
public class Intrinsics {
public static void main(String[] args)
throws InterruptedException
{
int[] data = randomInts(100_000);
int min = Integer.MAX_VALUE;
for ( int x: data ) {
min = Math.min(min, x);
}
Thread.sleep(5_000);
System.out.println(min);
}
static final int[] randomInts(int size) {
…
}
}
example06.Intrinsics
-XX:+PrintCompilation
-XX:+UnlockDiagnosticVMOptions
-XX:+PrintInlining
376 8 % example06.Intrinsics::randomInts @ 13 (30 bytes)
@ 16 java.util.concurrent.ThreadLocalRandom::nextInt (8 bytes) inline (hot)
@ 1 java.util.concurrent.ThreadLocalRandom::nextSeed (32 bytes) inline (hot)
@ 3 java.lang.Thread::currentThread (0 bytes) (intrinsic)
@ 18 sun.misc.Unsafe::getLong (0 bytes) (intrinsic)
@ 27 sun.misc.Unsafe::putLong (0 bytes) (intrinsic)
@ 4 java.util.concurrent.ThreadLocalRandom::mix32 (26 bytes) inline (hot)
379 9 java.lang.Math::min (11 bytes)
379 10 % example06.Intrinsics::main @ 22 (58 bytes)
@ 30 java.lang.Math::min (11 bytes) (intrinsic)
Intrinsic Inlining
Direct Call Inlining
public class Inlining {
public static void main(String[] args)
throws InterruptedException
{
System.setOut(new NullPrintStream());
for ( int i = 0; i < 20_000; ++i ) {
hotMethod();
}
Thread.sleep(5_000);
}
public static void hotMethod() {
System.out.println(square(7));
System.out.println(square(9));
}
static int square(int x) {
return x * x;
}
}
public static void hotMethod() {
System.out.println(7 * 7);
System.out.println(9 * 9);
}
example07.DirectInlining
static, private, constructor calls
Direct Call Inlining
226 53 example07.DirectInlining::hotMethod (23 bytes)
@ 5 example07.DirectInlining::square (4 bytes) inline (hot)
!m @ 8 java.io.PrintStream::println (24 bytes) already compiled into a big method
@ 16 example07.DirectInlining::square (4 bytes) inline (hot)
!m @ 19 java.io.PrintStream::println (24 bytes) already compiled into a big method
228 54 % example07.DirectInlining::main @ 15 (35 bytes)
@ 15 example07.DirectInlining::hotMethod (23 bytes) inline (hot)
@ 5 example07.DirectInlining::square (4 bytes) inline (hot)
!m @ 8 java.io.PrintStream::println (24 bytes) already compiled into a big method
@ 16 example07.DirectInlining::square (4 bytes) inline (hot)
!m @ 19 java.io.PrintStream::println (24 bytes) already compiled into a big method
-XX:+PrintCompilation
-XX:+UnlockDiagnosticVMOptions
-XX:+PrintInlining
Printing Assembly
for a Method
Download hsdis-amd64 dynamic library
Copy to jre/lib directory
Run HotSpot with...
-XX:+UnlockDiagnosticVMOptions
-XX:CompileCommand=print,{package/Class::method}
0x0000000106c57843: mov $0x31,%edx
0x0000000106c57848: data32 xchg %ax,%ax
0x0000000106c5784b: callq 0x0000000106c10b60
; OopMap{rbp=Oop off=48}
;*invokevirtual println
; - DirectInlining::hotMethod@7 (line 17)
; {optimized virtual_call}
0x0000000106c5785d: mov $0x51,%edx
0x0000000106c57862: nop
0x0000000106c57863: callq 0x0000000106c10b60
; OopMap{off=72}
;*invokevirtual println
; - DirectInlining::hotMethod@17 (line 18)
; {optimized virtual_call}
-XX:+UnlockDiagnosticVMOptions
-XX:CompileCommand=print,example07/DirectInlining::hotMethod
Direct Call Inlining
Escape Analysis
long sum = 0;
for ( Long x: list ) {
sum += iter.next();
}
long sum = 0;
for ( Iterator<Long> iter = list.iterator();
iter.hasNext(); )
{
sum += iter.next();
}
Escape Analysis
http://psy-lob-saw.blogspot.ru/2014/12/the-escape-of-arraylistiterator.html
long sum = 0;
// ArrayList$Itr.<init>
int iter$size = list.size();
int iter$cursor = 0;
int iter$lastRet = -1;


// ArrayList$Itr.hasNext
for ( ; iter$cursor != iter$size; ) {
// ArrayList$Itr.next
int i = iter$cursor;
Object[] elementData = list.elementData;
iter$cursor = i + 1;
Long x = (Long)elementData[iter$lastRet = i];
sum += x;
}
public class SimpleProgram {
static final int CHUNK_SIZE = 1_000;
public static void main(String[] args) {
for ( int i = 0; i < 250; ++i ) {
long startTime = System.nanoTime();
for ( int j = 0; j < CHUNK_SIZE; ++j ) {
//new Object

obj = calloc(sizeof(Object));
obj.<init>(); // call ctor - empty
}
long endTime = System.nanoTime();
System.out.printf(
"%dt%d%n", i, endTime - startTime);
}
}
}
Simple Program Revisited
1: inlined
2: escape analysis /
dead store
3: empty loop /
eliminate loop
example01a.SimpleProgram
1
1000
1000000
0
12
24
36
48
60
72
84
96
108
120
132
144
156
168
180
192
204
216
228
240
Interpreter 1st JIT 2nd JIT
Simple Program Revisited
That’s Boring!
Speculative
Optimizations
!
Implicit Null Check
public class NullCheck {
public static void main(String[] args)
throws InterruptedException
{
for ( int i = 0; i < 20_000; ++i ) {
hotMethod("hello");
}
Thread.sleep(5_000);
for ( int i = 0; i < 10; ++i ) {
System.out.printf("tempting fate %d%n", i);
try {
hotMethod(null);
} catch ( NullPointerException e ) {
// ignore
}
}
}
static final void hotMethod(final Object value) {
value.hashCode();
}
}
example08a.NullCheckhttps://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/signals.html
-XX:+UnlockDiagnosticVMOptions
-XX:CompileCommand=print,example08a/NullCheck::hotMethod
0x000000010795f9c0: mov %eax,-0x14000(%rsp)
0x000000010795f9c7: push %rbp
0x000000010795f9c8: sub $0x50,%rsp
;*synchronization entry
example08a.NullCheck::hotMethod@-1 (line 26)
0x000000010795f9cc: mov 0x8(%rsi),%r10d
; implicit exception: dispatches to 0x000000010795fe1d
0x000000010795f9d0: movabs $0x7eaa80d10,%r11
; {oop(a 'java/lang/Class' = 'java/lang/System')}
0x000000010795f9da: mov 0x74(%r11),%r11d
;*getstatic out
Implicit Null Check
value.toString(); Possible, but
improbable NPE
if ( value == null ) {
throw new NullPointerException();
}
SEGVderef
value
signal
handler
throw
NPE
Implicit Null Check
Null Check Deoptimization
-XX:+PrintCompilation
124 1 java.lang.String::hashCode (55 bytes)
138 2 example08a.NullCheck::hotMethod (6 bytes)
138 3 % ! example08a.NullCheck::main @ 5 (69 bytes)
tempting fate 0
tempting fate 1
tempting fate 2
5147 2 example08a.NullCheck::hotMethod (6 bytes) made not entrant
tempting fate 3
tempting fate 4
tempting fate 5
tempting fate 6
tempting fate 7
tempting fate 8
tempting fate 9
Not Thrown Away
the First Time
Bail to Interpreter
Keep Compile?
Yes No, recompile when...
Now Later (Profile More)
If Less Than
3 Deopts?
Null Proportion: 0.100000 Caught: 10057 Unique: 2015
Null Proportion: 0.500000 Caught: 50096 Unique: 7191
Null Proportion: 0.900000 Caught: 89929 Unique: 11030
int caughtCount = 0;
Set<NullPointerException> nullPointerExceptions =
new HashSet<>();
for ( Object object : objects ) {
try {
object.toString();
} catch ( NullPointerException e ) {
nullPointerExceptions.add( e );
caughtCount += 1;
}
}
Hot Exception Optimization
example08b.HotExceptionDemohttp://www.javaspecialists.eu/archive/Issue187.html
Hot Exceptions
int caughtCount = 0;
HashSet<NullPointerException> nullPointerExceptions =
new HashSet<>();
for ( Object object : objects ) {
try {
object.toString();
} catch ( NullPointerException e ) {
boolean added = nullPointerExceptions.add(e);
if ( !added ) e.printStackTrace();
caughtCount += 1;
}
}
java.lang.NullPointerException
No StackTrace???
public class Unreached {
public static volatile Object thing = null;
public static void main(final String[] args)
throws InterruptedException
{
for ( int i = 0; i < 20_000; ++i ) {
hotMethod();
}
Thread.sleep(5_000);
thing = new Object();
for ( int i = 0; i < 20_000; ++i ) {
hotMethod();
}
Thread.sleep(5_000);
}
static final void hotMethod() {
if ( thing == null )
System.out.print("");
else
System.out.print("");
}
}
Unreached Deoptimization
example09.Unreached
phase change
static final void hotMethod() {
if ( thing == null )
System.out.print("");
else
uncommon_trap(unreached);
}
-XX:+PrintCompilation
Unreached Deoptimization
217 1 java.lang.String::hashCode (55 bytes)
235 2 java.lang.String::indexOf (70 bytes)
238 3 java.io.BufferedWriter::ensureOpen (18 bytes)
244 4 java.lang.String::length (6 bytes)
244 5 java.lang.String::indexOf (7 bytes)
245 6 java.nio.Buffer::position (5 bytes)
245 7 example09.Unreached::hotMethod (26 bytes)
…
265 14 java.io.OutputStreamWriter::flushBuffer (8 bytes)
265 15 ! sun.nio.cs.StreamEncoder::flushBuffer (42 bytes)
267 16 sun.nio.cs.StreamEncoder::isOpen (5 bytes)
267 17 sun.nio.cs.StreamEncoder::implFlushBuffer (15 bytes)
267 18 % example09.Unreached::main @ 5 (59 bytes)
5255 7 example09.Unreached::hotMethod (26 bytes) made not entrant
5257 19 example09.Unreached::hotMethod (26 bytes)
5257 20 % example09.Unreached::main @ 39 (59 bytes)
Bail to Interpreter
hotMethod
...
...
main
hotMethod
...
...
main
interpreter frame
compiled frame
Why Speculate?
y *= 2;
x = 0;
y = 25;
y = -20;
x = 0;
y = 25;
y = 30; trap!y = 15;
Not So Simple Program Revisited
1
1000
1000000
0
12
24
36
48
60
72
84
96
108
120
132
144
156
168
180
192
204
216
228
240
unreached deopt,
bail to interpreter!
Virtual Call Inlining
Func
+apply(double):double
Square
+apply(double):double
Sqrt
+apply(double):double
Class Hierarchy Analysis (CHA)
Type Profile
http://shipilev.net/blog/2015/black-magic-method-dispatch/
public class Monomorphic {
public static void main(String[] args)
throws InterruptedException
{
Func func = new Square();
for ( int i = 0; i < 20_000; ++i ) {
apply(func, i);
}
Thread.sleep(5_000);
}
static double apply(Func func, int x) {
return func.apply(x);
}
}
Monomorphic
example10a.Monomorphic
217 1 java.lang.String::hashCode (55 bytes)
234 3 example10.support.Square::apply (4 bytes)
234 2 example10a.Monomorphic::apply (7 bytes)
@ 3 example10.support.Square::apply (4 bytes) inline (hot)
234 4 % example10a.Monomorphic::main @ 13 (30 bytes)
@ 15 example10a.Monomorphic::apply (7 bytes) inline (hot)
@ 3 example10.support.Square::apply (4 bytes) inline (hot)
Monomorphic
-XX:+PrintCompilation
-XX:+UnlockDiagnosticVMOptions
-XX:+PrintInlining
Beyond Monomorphic
Func func = …
double result = func.apply(20);
Func func = …
//no type guard!
double result = 20 * 20;
More Types?
example10b.ChaStorm
public class ChaStorm {
public static void main(String[] args)
throws InterruptedException
{
Func func = new Square();
for ( int i = 0; i < 10_000; ++i ) {
apply1(func, i);
…
apply8(func, i);
}
System.out.println("Waiting for compiler...");
Thread.sleep(5_000);
System.out.println("Deoptimize...");
System.out.println(Sqrt.class);
Thread.sleep(5_000);
}
}
Potential for Deopt Storm
Potential for Deopt Storm
152 1 java.lang.String::hashCode (55 bytes)
166 2 example10.support.Square::apply (4 bytes)
173 3 example10b.ChaStorm::apply1 (7 bytes)
173 4 example10b.ChaStorm::apply2 (7 bytes)
Waiting for compiler...
174 5 example10b.ChaStorm::apply3 (7 bytes)
174 6 example10b.ChaStorm::apply4 (7 bytes)
174 7 example10b.ChaStorm::apply5 (7 bytes)
174 8 example10b.ChaStorm::apply6 (7 bytes)
174 9 example10b.ChaStorm::apply7 (7 bytes)
174 10 example10b.ChaStorm::apply8 (7 bytes)
Deoptimize...
5176 9 example10b.ChaStorm::apply7 (7 bytes) made not entrant
5176 8 example10b.ChaStorm::apply6 (7 bytes) made not entrant
5176 7 example10b.ChaStorm::apply5 (7 bytes) made not entrant
5176 5 example10b.ChaStorm::apply3 (7 bytes) made not entrant
5176 6 example10b.ChaStorm::apply4 (7 bytes) made not entrant
5176 4 example10b.ChaStorm::apply2 (7 bytes) made not entrant
5176 3 example10b.ChaStorm::apply1 (7 bytes) made not entrant
5176 10 example10b.ChaStorm::apply8 (7 bytes) made not entrant
class example10.support.Sqrt
-XX:+PrintCompilation
Another Way to Deopt
Bail to Interpreter
Keep Compile?
Yes No, recompile when...
Now Later (Profile More)
class load!
stop the world,
deopt now!
Total time for which application threads were stopped: 0.0001010 seconds
5096 10 example10b.ChaStorm::apply8 (7 bytes) made not entrant
5096 8 example10b.ChaStorm::apply6 (7 bytes) made not entrant
5096 7 example10b.ChaStorm::apply5 (7 bytes) made not entrant
5096 5 example10b.ChaStorm::apply3 (7 bytes) made not entrant
5096 6 example10b.ChaStorm::apply4 (7 bytes) made not entrant
5096 4 example10b.ChaStorm::apply2 (7 bytes) made not entrant
5096 9 example10b.ChaStorm::apply7 (7 bytes) made not entrant
5096 3 example10b.ChaStorm::apply1 (7 bytes) made not entrant
vmop [threads: total initially_running wait_to_block] …
5.096: Deoptimize [ 7 0 0 ] …
Another Way to Deopt
-XX:+PrintCompilation
-XX+PrintSafepointStatistics
-XX:PrintSafepointStatisticsCount=1
http://blog.ragozin.info/2012/10/safepoints-in-hotspot-jvm.html
Bimorphic
Func func = …
double result = func.apply(20);
Func func = …
//no type guard!
double result = 20 * 20;
add another type
Func func = …
double result;
if ( func.getClass().equals(Square.class) ) {
result = 20 * 20;
} else {
uncommon_trap(class_check);
}
give up!
public class ClassDevirtualization {
public static void main(String[] args) throws InterruptedException {
System.out.println("Using Square...");
Func func = new Square();
for ( int i = 0; i < 20_000; ++i ) {
apply1(func, i);
apply2(func, i);
}
Thread.sleep(5_000);
System.out.printf("Loading %s to Deopt Now!%n”, Sqrt.class);
System.out.println("Keep using Square in apply1...");
func = new Square();
for ( int i = 0; i < 20_000; ++i ) apply1(func, i);
Thread.sleep(5_000);
System.out.println("Use AlsoSquare in apply1...");
func = new AlsoSquare();
for ( int i = 0; i < 20_000; ++i ) apply1(func, i);
Thread.sleep(5_000);
System.out.println("Use AnotherSquare in apply1...");
func = new AnotherSquare();
for ( int i = 0; i < 20_000; ++i ) apply1(func, i);
Thread.sleep(5_000);
…after 3 types no more deopts…
}
}
stop the world,
deopt now!
class check
deopt!
bimorphic
deopt!
example10c.ClassDevirtualization
Class Devirtualization
89 1 java.lang.String::hashCode (55 bytes)
Using Square...
104 2 example10.support.Square::apply (4 bytes)
105 3 example10c.ClassDevirtualization::apply1 (7 bytes)
105 4 example10c.ClassDevirtualization::apply2 (7 bytes)
106 5 % example10c.ClassDevirtualization::main @ 21 (240 bytes)
5116 5 % example10c.ClassDevirtualization::main @ -2 (240 bytes) made not entrant
5116 4 example10c.ClassDevirtualization::apply2 (7 bytes) made not entrant
5116 3 example10c.ClassDevirtualization::apply1 (7 bytes) made not entrant
Loading class example10.support.Sqrt to Deoptimize Now!
Keep using Square in apply1...
5128 6 example10c.ClassDevirtualization::apply1 (7 bytes)
5128 7 % example10c.ClassDevirtualization::main @ 88 (240 bytes)
Use AlsoSquare in apply1...
10131 6 example10c.ClassDevirtualization::apply1 (7 bytes) made not entrant
10131 8 example10c.ClassDevirtualization::apply1 (7 bytes)
10132 9 % example10c.ClassDevirtualization::main @ 131 (240 bytes)
Use AnotherSquare in apply1...
15134 8 example10c.ClassDevirtualization::apply1 (7 bytes) made not entrant
15134 10 example10c.ClassDevirtualization::apply1 (7 bytes)
15135 11 % example10c.ClassDevirtualization::main @ 174 (240 bytes)
Use YetAnotherSquare in apply1...
20139 12 % example10c.ClassDevirtualization::main @ 217 (240 bytes)
Class Devirtualization
-XX:+PrintCompilation
WorseYet...
class AlsoSquare extends Square {}
class AnotherSquare extends Square {}
class Square extends Func {
double final apply(double x) {
return x * x;
}
}
classYetAnotherSquare extends Square {}
Unintentional
Megamorphism
new HashMap<String, Integer>() {{
put(“foo”, 20);
put(“bar”, 30);
}};
Func
+apply(double):double
Square
+apply(double):double
Sqrt
+apply(double):double
IFunc
+apply(double):double
No CHA for Interfaces
example10d.InterfaceDevirtualization
68 1 java.lang.String::hashCode (55 bytes)
Using Square...
79 2 example10.support.Square::apply (4 bytes)
80 3 example10d.InterfaceDevirtualization::apply1 (9 bytes)
80 4 example10d.InterfaceDevirtualization::apply2 (9 bytes)
81 5 % example10d.InterfaceDevirtualization::main @ 21 (240 bytes)
Loading class example10.support.Sqrt - no CHA for interfaces!
Keep using Square in apply1...
5090 6 % example10d.InterfaceDevirtualization::main @ 88 (240 bytes)
Use AlsoSquare in apply1...
10094 5 % example10d.InterfaceDevirtualization::main @ -2 (240 bytes) made not entrant
10094 6 % example10d.InterfaceDevirtualization::main @ -2 (240 bytes) made not entrant
10094 3 example10d.InterfaceDevirtualization::apply1 (9 bytes) made not entrant
10095 7 example10d.InterfaceDevirtualization::apply1 (9 bytes)
10095 8 % example10d.InterfaceDevirtualization::main @ 131 (240 bytes)
Use AnotherSquare in apply1...
15101 7 example10d.InterfaceDevirtualization::apply1 (9 bytes) made not entrant
15102 9 example10d.InterfaceDevirtualization::apply1 (9 bytes)
15102 10 % example10d.InterfaceDevirtualization::main @ 174 (240 bytes
No CHA for Interfaces
-XX:+PrintCompilation
MaxTrivialSize 6
MaxInlineSize 35
FreqInlineSize 325
MaxInlineLevel 9
MaxRecursiveInlineLevel 1
MinInliningThreshold 250
Tier1MaxInlineSize 8
Tier1FreqInlineSize 35
Inlining Numbers to Remember...
`java -XX:+PrintFlagsFinal`
“Fun” with Unloaded
public class UnloadedForever {
public static void main(String[] args) {
for ( int i = 0; i < 100_000; ++i ) {
try {
factory();
} catch ( Throwable t ) {
// ignore
}
}
}
static DoesNotExist factory() {
return new DoesNotExist();
}
}
example11a.UnloadedForever
-XX:+PrintCompilation
Unloaded Forever
72 1 java.lang.String::hashCode (55 bytes)
156 2 java.lang.Object::<init> (1 bytes)
183 3 s java.lang.Throwable::fillInStackTrace (29 bytes)
183 4 n java.lang.Throwable::fillInStackTrace (native)
183 5 java.lang.LinkageError::<init> (6 bytes)
184 6 java.lang.Error::<init> (6 bytes)
184 7 java.lang.Throwable::<init> (34 bytes)
185 8 example11a.UnloadedForever::factory (8 bytes)
186 9 java.lang.NoClassDefFoundError::<init> (6 bytes)
186 8 example11a.UnloadedForever::factory (8 bytes) made not entrant
223 10 % ! example11a.UnloadedForever::main @ 5 (23 bytes)
273 11 example11a.UnloadedForever::factory (8 bytes)
274 11 example11a.UnloadedForever::factory (8 bytes) made not entrant
358 12 example11a.UnloadedForever::factory (8 bytes)
358 12 example11a.UnloadedForever::factory (8 bytes) made not entrant
441 13 example11a.UnloadedForever::factory (8 bytes)
442 13 example11a.UnloadedForever::factory (8 bytes) made not entrant
528 14 example11a.UnloadedForever::factory (8 bytes)
978 8 example11a.UnloadedForever::factory (8 bytes) made zombie
“Fun” with Uninitialized
public class UninitializedForever {
static class Uninitialized {
static {
if ( true ) throw new RuntimeException();
}
}
public static void main(String[] args) {
for ( int i = 0; i < 100_000; ++i ) {
try {
new Uninitialized();
} catch ( Throwable t ) {
// ignore
}
}
}
}
example11b.UnintializedForever
-XX:+PrintCompilation
74 1 java.lang.String::hashCode (55 bytes)
162 2 java.lang.Object::<init> (1 bytes)
188 3 s java.lang.Throwable::fillInStackTrace (29 bytes)
189 4 n java.lang.Throwable::fillInStackTrace (native)
189 5 java.lang.LinkageError::<init> (6 bytes)
190 6 java.lang.Error::<init> (6 bytes)
190 7 java.lang.Throwable::<init> (34 bytes)
191 8 java.lang.NoClassDefFoundError::<init> (6 bytes)
233 9 % ! example11b.UninitializedForever::main @ 5 (25 bytes)
241 9 % ! example11b.UninitializedForever::main @ -2 (25 bytes) made not entrant
252 10 % ! example11b.UninitializedForever::main @ 5 (25 bytes)
263 10 % ! example11b.UninitializedForever::main @ -2 (25 bytes) made not entrant
272 11 % ! example11b.UninitializedForever::main @ 5 (25 bytes)
281 11 % ! example11b.UninitializedForever::main @ -2 (25 bytes) made not entrant
290 12 % ! example11b.UninitializedForever::main @ 5 (25 bytes)
299 12 % ! example11b.UninitializedForever::main @ -2 (25 bytes) made not entrant
308 13 % ! example11b.UninitializedForever::main @ 5 (25 bytes)
318 13 % ! example11b.UninitializedForever::main @ -2 (25 bytes) made not entrant
328 14 % ! example11b.UninitializedForever::main @ 5 (25 bytes)
337 14 % ! example11b.UninitializedForever::main @ -2 (25 bytes) made not entrant
Uninitialized Forever
null_check unexpected null or zero divisor
null_assert unexpected non-null or non-zero
range_check unexpected array index
class_check unexpected object class
array_check unexpected array class
intrinsic unexpected operand to intrinsic
bimorphic unexpected object class in bimorphic inlining
unloaded unloaded class or constant pool entry
uninitialized bad class state (uninitialized)
unreached code is not reached, compiler
unhandled arbitrary compiler limitation
constraint arbitrary runtime constraint violated
div0_check a null_check due to division by zero
age nmethod too old; tier threshold reached
predicate compiler generated predicate failed
loop_limit_check compiler generated loop limits check failed
Reasons for Deoptimizing...
none just interpret, do not invalidate nmethod
maybe_recompile recompile the nmethod; need not invalidate
make_not_entrant invalidate the nmethod, recompile (probably)
reinterpret invalidate the nmethod, reset IC, maybe recompile
make_not_compilable invalidate the nmethod and do not compile
Actions When
Deoptimizing...
Bail to Interpreter
Keep Compile?
Yes, recompile? No, recompile when...
Now Later (Profile More)No Yes
none
maybe
recompile
make
not entrant
reinterpret
class load!
stop the world,
deopt now!
uncommon trap!
null_check make_not_entrant
null_assert make_not_entrant
range_check make_not_entrant
class_check maybe_recompile
array_check maybe_recompile
intrinsic maybe_recompile, make_not_entrant
bimorphic maybe_recompile
unloaded reinterpret
uninitialized reinterpret
unreached reinterpret
unhandled none
constraint CHA - deopt now!
div0_check make_not_entrant
age maybe_recompile
predicate none?
loop_limit_check none?
Reasons & Actions
Does This Matter?
thread1
thread2
inlinedMethod2
inlinedMethod1
hotMethod
code cache
interpreter frame
compiled frame
inlinedMethod2
inlinedMethod1
hotMethod
...
...
run
inlinedMethod2
inlinedMethod1
hotMethod
...
...
run
ReadyNow!
http://www.azulsystems.com/solutions/zing/readynow
Recommending Reading
http://www.javaspecialists.eu
Brian Goetz
http://www.ibm.com/developerworks/views/java/libraryview.jsp?
contentarea_by=Java+technology&search_by=brian+goetz
Dr Heinz M Kabutz
https://wiki.openjdk.java.net/display/HotSpot
VM Developer Blogs
Aleksey Shipilëv
http://shipilev.net/
http://psy-lob-saw.blogspot.com/
Nitsan Wakart
https://twitter.com/maddocig
IgorVeresov
JITWatch
https://github.com/AdoptOpenJDK/jitwatch/
?
Questions?
Douglas Q. Hawkins
VM Engineer

More Related Content

What's hot

Kvm performance optimization for ubuntu
Kvm performance optimization for ubuntuKvm performance optimization for ubuntu
Kvm performance optimization for ubuntuSim Janghoon
 
Velocity 2015 linux perf tools
Velocity 2015 linux perf toolsVelocity 2015 linux perf tools
Velocity 2015 linux perf toolsBrendan Gregg
 
Performance Analysis: The USE Method
Performance Analysis: The USE MethodPerformance Analysis: The USE Method
Performance Analysis: The USE MethodBrendan Gregg
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBrendan Gregg
 
My Experiences as a Beginner of OpenJDK Contributor (JCConf Taiwan 2021)
My Experiences as a Beginner of OpenJDK Contributor (JCConf Taiwan 2021)My Experiences as a Beginner of OpenJDK Contributor (JCConf Taiwan 2021)
My Experiences as a Beginner of OpenJDK Contributor (JCConf Taiwan 2021)NTT DATA Technology & Innovation
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in GolangBo-Yi Wu
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageJelastic Multi-Cloud PaaS
 
JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013Vladimir Ivanov
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial IJim Yeh
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Monica Beckwith
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageKernel TLV
 
Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey J On The Beach
 
Exploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & BeyondExploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & BeyondKaushal Dhruw
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesBruno Borges
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and moreBrendan Gregg
 
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...Adrian Huang
 
Namespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containersNamespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containersKernel TLV
 

What's hot (20)

Kvm performance optimization for ubuntu
Kvm performance optimization for ubuntuKvm performance optimization for ubuntu
Kvm performance optimization for ubuntu
 
Learn C Programming Language by Using GDB
Learn C Programming Language by Using GDBLearn C Programming Language by Using GDB
Learn C Programming Language by Using GDB
 
Velocity 2015 linux perf tools
Velocity 2015 linux perf toolsVelocity 2015 linux perf tools
Velocity 2015 linux perf tools
 
Performance Analysis: The USE Method
Performance Analysis: The USE MethodPerformance Analysis: The USE Method
Performance Analysis: The USE Method
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame Graphs
 
My Experiences as a Beginner of OpenJDK Contributor (JCConf Taiwan 2021)
My Experiences as a Beginner of OpenJDK Contributor (JCConf Taiwan 2021)My Experiences as a Beginner of OpenJDK Contributor (JCConf Taiwan 2021)
My Experiences as a Beginner of OpenJDK Contributor (JCConf Taiwan 2021)
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
 
JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey
 
Exploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & BeyondExploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & Beyond
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on Kubernetes
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
 
How A Compiler Works: GNU Toolchain
How A Compiler Works: GNU ToolchainHow A Compiler Works: GNU Toolchain
How A Compiler Works: GNU Toolchain
 
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
 
Namespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containersNamespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containers
 

Viewers also liked

Tiered Compilation in Hotspot JVM
Tiered Compilation in Hotspot JVMTiered Compilation in Hotspot JVM
Tiered Compilation in Hotspot JVMIgor Veresov
 
Understanding Garbage Collection
Understanding Garbage CollectionUnderstanding Garbage Collection
Understanding Garbage CollectionDoug Hawkins
 
InvokeDynamic - You Ain't Seen Nothin Yet
InvokeDynamic - You Ain't Seen Nothin YetInvokeDynamic - You Ain't Seen Nothin Yet
InvokeDynamic - You Ain't Seen Nothin YetCharles Nutter
 
CSTalks - Named Data Networks - 9 Feb
CSTalks - Named Data Networks - 9 FebCSTalks - Named Data Networks - 9 Feb
CSTalks - Named Data Networks - 9 Febcstalks
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterTim Ellison
 
JVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesJVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesKris Mok
 
Garbage collection in JVM
Garbage collection in JVMGarbage collection in JVM
Garbage collection in JVMaragozin
 
Improvements to Flink & it's Applications in Alibaba Search
Improvements to Flink & it's Applications in Alibaba SearchImprovements to Flink & it's Applications in Alibaba Search
Improvements to Flink & it's Applications in Alibaba SearchDataWorks Summit/Hadoop Summit
 
Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Kris Mok
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it worksMindfire Solutions
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Javabackdoor
 
Blue ocean strategy martin limgenco
Blue ocean strategy   martin limgencoBlue ocean strategy   martin limgenco
Blue ocean strategy martin limgencobeltamayo
 
The Wonders Of Winter
The Wonders Of WinterThe Wonders Of Winter
The Wonders Of Winterbanneker
 
this is test api2
this is test api2this is test api2
this is test api251 lecture
 

Viewers also liked (20)

Tiered Compilation in Hotspot JVM
Tiered Compilation in Hotspot JVMTiered Compilation in Hotspot JVM
Tiered Compilation in Hotspot JVM
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
Understanding Garbage Collection
Understanding Garbage CollectionUnderstanding Garbage Collection
Understanding Garbage Collection
 
Understanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual MachineUnderstanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual Machine
 
InvokeDynamic - You Ain't Seen Nothin Yet
InvokeDynamic - You Ain't Seen Nothin YetInvokeDynamic - You Ain't Seen Nothin Yet
InvokeDynamic - You Ain't Seen Nothin Yet
 
CSTalks - Named Data Networks - 9 Feb
CSTalks - Named Data Networks - 9 FebCSTalks - Named Data Networks - 9 Feb
CSTalks - Named Data Networks - 9 Feb
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark faster
 
JVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesJVM: A Platform for Multiple Languages
JVM: A Platform for Multiple Languages
 
Garbage collection in JVM
Garbage collection in JVMGarbage collection in JVM
Garbage collection in JVM
 
Improvements to Flink & it's Applications in Alibaba Search
Improvements to Flink & it's Applications in Alibaba SearchImprovements to Flink & it's Applications in Alibaba Search
Improvements to Flink & it's Applications in Alibaba Search
 
Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
 
Java GC
Java GCJava GC
Java GC
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
Blue ocean strategy martin limgenco
Blue ocean strategy   martin limgencoBlue ocean strategy   martin limgenco
Blue ocean strategy martin limgenco
 
Zaragoza turismo-57
Zaragoza turismo-57Zaragoza turismo-57
Zaragoza turismo-57
 
The Wonders Of Winter
The Wonders Of WinterThe Wonders Of Winter
The Wonders Of Winter
 
Facebook for Art
Facebook for ArtFacebook for Art
Facebook for Art
 
The Music Industry
The Music IndustryThe Music Industry
The Music Industry
 
this is test api2
this is test api2this is test api2
this is test api2
 

Similar to JVM Mechanics: When Does the JVM JIT & Deoptimize?

Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsAzul Systems, Inc.
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVMSylvain Wallez
 
Global Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealGlobal Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealTzung-Bi Shih
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++Joan Puig Sanz
 
Google Developer Fest 2010
Google Developer Fest 2010Google Developer Fest 2010
Google Developer Fest 2010Chris Ramsdale
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksMongoDB
 
Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015Raimon Ràfols
 
Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Chris Ramsdale
 
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)PROIDEA
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaFrank Lyaruu
 

Similar to JVM Mechanics: When Does the JVM JIT & Deoptimize? (20)

Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
Global Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealGlobal Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the Seal
 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
 
Google Developer Fest 2010
Google Developer Fest 2010Google Developer Fest 2010
Google Developer Fest 2010
 
Android and cpp
Android and cppAndroid and cpp
Android and cpp
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 
Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
20151224-games
20151224-games20151224-games
20151224-games
 
nullcon 2010 - Intelligent debugging and in memory fuzzing
nullcon 2010 - Intelligent debugging and in memory fuzzingnullcon 2010 - Intelligent debugging and in memory fuzzing
nullcon 2010 - Intelligent debugging and in memory fuzzing
 
Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010
 
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
 
Iron python
Iron pythonIron python
Iron python
 

More from Doug Hawkins

ReadyNow: Azul's Unconventional "AOT"
ReadyNow: Azul's Unconventional "AOT"ReadyNow: Azul's Unconventional "AOT"
ReadyNow: Azul's Unconventional "AOT"Doug Hawkins
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance PuzzlersDoug Hawkins
 
Concurrency Concepts in Java
Concurrency Concepts in JavaConcurrency Concepts in Java
Concurrency Concepts in JavaDoug Hawkins
 
JVM Internals - NHJUG Jan 2012
JVM Internals - NHJUG Jan 2012JVM Internals - NHJUG Jan 2012
JVM Internals - NHJUG Jan 2012Doug Hawkins
 
Inside Android's Dalvik VM - NEJUG Nov 2011
Inside Android's Dalvik VM - NEJUG Nov 2011Inside Android's Dalvik VM - NEJUG Nov 2011
Inside Android's Dalvik VM - NEJUG Nov 2011Doug Hawkins
 
JVM Internals - NEJUG Nov 2010
JVM Internals - NEJUG Nov 2010JVM Internals - NEJUG Nov 2010
JVM Internals - NEJUG Nov 2010Doug Hawkins
 
Introduction to Class File Format & Byte Code
Introduction to Class File Format & Byte CodeIntroduction to Class File Format & Byte Code
Introduction to Class File Format & Byte CodeDoug Hawkins
 
JVM Internals - Garbage Collection & Runtime Optimizations
JVM Internals - Garbage Collection & Runtime OptimizationsJVM Internals - Garbage Collection & Runtime Optimizations
JVM Internals - Garbage Collection & Runtime OptimizationsDoug Hawkins
 

More from Doug Hawkins (9)

ReadyNow: Azul's Unconventional "AOT"
ReadyNow: Azul's Unconventional "AOT"ReadyNow: Azul's Unconventional "AOT"
ReadyNow: Azul's Unconventional "AOT"
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance Puzzlers
 
JVM Mechanics
JVM MechanicsJVM Mechanics
JVM Mechanics
 
Concurrency Concepts in Java
Concurrency Concepts in JavaConcurrency Concepts in Java
Concurrency Concepts in Java
 
JVM Internals - NHJUG Jan 2012
JVM Internals - NHJUG Jan 2012JVM Internals - NHJUG Jan 2012
JVM Internals - NHJUG Jan 2012
 
Inside Android's Dalvik VM - NEJUG Nov 2011
Inside Android's Dalvik VM - NEJUG Nov 2011Inside Android's Dalvik VM - NEJUG Nov 2011
Inside Android's Dalvik VM - NEJUG Nov 2011
 
JVM Internals - NEJUG Nov 2010
JVM Internals - NEJUG Nov 2010JVM Internals - NEJUG Nov 2010
JVM Internals - NEJUG Nov 2010
 
Introduction to Class File Format & Byte Code
Introduction to Class File Format & Byte CodeIntroduction to Class File Format & Byte Code
Introduction to Class File Format & Byte Code
 
JVM Internals - Garbage Collection & Runtime Optimizations
JVM Internals - Garbage Collection & Runtime OptimizationsJVM Internals - Garbage Collection & Runtime Optimizations
JVM Internals - Garbage Collection & Runtime Optimizations
 

Recently uploaded

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Recently uploaded (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

JVM Mechanics: When Does the JVM JIT & Deoptimize?

  • 1. Douglas Q. Hawkins VM Engineer VM MechanicsWhen Does the JVM JIT & Deoptimize? J https://github.com/dougqh/jvm-mechanics
  • 2. About Azul Systems Zulu® Multi-Platform OpenJDK Cloud Support including Docker and Azure Embedded Support Zing® Highly ScalableVM Continuously Concurrent Compacting Collector ReadyNow! for Low Latency Applications http://www.azulsystems.com/
  • 3. HotSpot Lifecycle 1 2 34 Interpret Profile Just-in-Time CompilationDeoptimize
  • 5. public class SimpleProgram { static final int CHUNK_SIZE = 1_000; public static void main(String[] args) { for ( int i = 0; i < 250; ++i ) { long startTime = System.nanoTime(); for ( int j = 0; j < CHUNK_SIZE; ++j ) { new Object(); } long endTime = System.nanoTime(); System.out.printf("%dt%d%n", i, endTime - startTime); } } } A Simple Program example01a.SimpleProgram Code Reference
  • 8. public class NotSoSimpleProgram { static final int CHUNK_SIZE = 1_000; public static void main(String[] args) { Object trap = null; for ( int i = 0; i < 250; ++i ) { long startTime = System.nanoTime(); for ( int j = 0; j < CHUNK_SIZE; ++j ) { new Object(); if ( trap != null ) { System.out.println("trap!"); trap = null; } } if ( i == 200 ) trap = new Object(); long endTime = System.nanoTime(); System.out.printf("%dt%d%n", i, endTime - startTime); } } } Not So Simple Program example01b.NotSoSimpleProgram
  • 10. Dynamically Generated Threaded Interpreter Identify “Hot Spots” Slow! 10000x Interpreter http://openjdk.java.net/groups/hotspot/docs/RuntimeOverview.html
  • 11. Invocation Counter example02.InvocationCounter public class InvocationCounter { public static void main(final String[] args) throws InterruptedException { for ( int i = 0; i < 20_000; ++i ) { hotMethod(); } System.out.println("Waiting for compiler..."); Thread.sleep(5_000); } static void hotMethod() {} }
  • 12. -XX:+PrintCompilation example02.InvocationCounter 299 1 % java.lang.String::indexOf @ 37 (70 bytes) 332 2 java.lang.String::indexOf (70 bytes) 364 3 example02.InvocationCounter::hotMethod (1 bytes) 365 4 % example02.InvocationCounter::main @ 5 (33 bytes) Waiting for compiler... Invocation Counter
  • 13. Compilation Log 5328 50 n java.io.FileOutputStream::writeBytes (native) 5330 27 java.nio.CharBuffer::wrap (20 bytes) 5333 31 s java.io.BufferedOutputStream::flush (12 bytes) 5477 56 % CompilationExample::main @ 37 (82 bytes) timestamp (since VM start) compilation ID method name method size native exception handler synchronized method on-stack replacement loop bytecode index !
  • 14. synchronized is try/finally synchronized ( foo.getBar() ) { ... } tmp = foo.getBar(); monitor_enter(tmp); try { ... } finally { monitor_exit(tmp); }
  • 15. Duplicate Methods & Overloading 5208 4 java.nio.Buffer::position (5 bytes) ... 5223 8 java.nio.Buffer::position (43 bytes)
  • 16. Invisible Overloads via Bridge Methods public interface Supplier<T> { public abstract T get(); } new Supplier<String>() { public final String get() { return “foo”; } }; 145 4 InvisibleOverload$1::get (5 bytes) 145 5 InvisibleOverload$1::get (3 bytes)
  • 17. public class BackedgeCounter { public static void main(final String[] args) throws InterruptedException { for ( int i = 0; i < 20_000; ++i ) { hotMethod(); } System.out.println("Waiting for compiler..."); Thread.sleep(5_000); for ( int i = 0; i < 20_000; ++i ) { hotMethod(); } System.out.println("Waiting for compiler..."); Thread.sleep(5_000); } static void hotMethod() {} } Backedge Counter example03.BackedgeCounter
  • 18. 163 1 java.lang.String::charAt (29 bytes) 166 2 java.lang.String::hashCode (55 bytes) 171 3 java.lang.String::indexOf (70 bytes) 193 4 example03.BackedgeCounter::hotMethod (1 bytes) 194 5 % example03.BackedgeCounter::main @ 5 (65 bytes) Waiting for compiler... 5196 6 % example03.BackedgeCounter::main @ 37 (65 bytes) Waiting for compiler... -XX:+PrintCompilation example03.BackedgeCounter Backedge Counter
  • 19. On-Stack Replacement eventLoop ... ... main eventLoop @ 20 ... ... main interpreter frame compiled frame
  • 20. Both Counters public class BothCounters { public static void main(final String[] args) throws InterruptedException { for ( int i = 0; i < 2; ++i ) { outerMethod(); } System.out.println("Waiting for compiler..."); Thread.sleep(5000); } static void outerMethod() { for ( int i = 0; i < 10_000; ++i ) { innerMethod(); } } static void innerMethod() {} } example04.BothCounters
  • 21. -XX:+PrintCompilation example04.BothCounters Both Counters 115 1 % java.lang.String::indexOf @ 37 (70 bytes) 123 2 example04.BothCounters::innerMethod (1 bytes) 124 3 example04.BothCounters::outerMethod (19 bytes) 125 4 % example04.BothCounters::outerMethod @ 5 (19 bytes) Waiting for compiler...
  • 22. HotSpot: A Tale of Two Compilers C1client C2 server
  • 23. C1 ClientVM The Fast Acting Compiler Compiles with Count > 1,000 (2,000 in Tiered) Produces Compilations Quickly Generated Code Runs Relatively Slowly
  • 24. Compiles with Count > 10,000 (15,000 in Tiered) Profile Guided C2 ServerVM The Smart compiler Speculative 2xSpeed! Produces Compilations Slowly Generated Code Runs Fast
  • 25. Tiered Compilation Available in Java 7 - default in Java 8 Best of Both Worlds - C1 & C2 Interpreter > 2,000 > 15,000 C1 C2 http://www.slideshare.net/maddocig/tiered
  • 26. 0 0 0 interpreter 3 4 2 3 4 1 3 c1 c2 none basic counters detailed common c2 busy trivial method Tiered Compilation
  • 27. public final class TieredCompilation { public static final void main(final String[] args) throws InterruptedException { for ( int i = 0; i < 3_000; ++i ) { method(); } System.out.println("Waiting for the compiler..."); Thread.sleep(5_000); for ( int i = 0; i < 20_000; ++i ) { method(); } System.out.println("Waiting for the compiler..."); Thread.sleep(5_000); } private static final void method() { // Do something while doing nothing. System.out.print('0'); } } example05.TieredCompilation Tiered Compilation
  • 28. 183 69 3 sun...SingleByte$Encoder::encodeArrayLoop (236 bytes) ... 5237 101 4 sun...SingleByte$Encoder::encodeArrayLoop (236 bytes) 5255 69 3 sun...SingleByte$Encoder::encodeArrayLoop (236 bytes) made not entrant 131 3 3 java.lang.Object::<init> (1 bytes) ... 140 15 1 java.lang.Object::<init> (1 bytes) 141 3 3 java.lang.Object::<init> (1 bytes) made not entrant 126 6 n 0 java.lang.System::arraycopy (native) (static) -XX:+TieredCompilation -XX:+PrintCompilation example05.TieredCompilation Tiered Compilation tier
  • 31. Intrinsics Special code built-into theVM for a particular method Built-in to theVM - not written in Java (usually) For Example... System.arraycopy Math.sin / cos / tan Often use special hardware capabilities: MMX,AVX2, etc
  • 32. http://en.wikipedia.org/wiki/Common_subexpression_elimination Common Sub-Expression Elimination int a = b * c + g; int d = b * c * e; int tmp = b * c; int a = tmp + g; int d = tmp * e;
  • 33. bool isDebugEnabled = LOGGER.isDebugEnabled(); for ( User user: users ) { ...do something... if ( isDebugEnabled ) { LOGGER.debug(user.getName()); } } bool isDebugEnabled = LOGGER.isDebugEnabled(); if ( isDebugEnabled ) { for ( User user: users ) { ...do something... LOGGER.debug(user.getName()); } } else { for ( User user: users ) { ...do something... } } Loop Unswitching http://en.wikipedia.org/wiki/Loop_unswitching
  • 34. Dead Code Elimination http://en.wikipedia.org/wiki/Dead_code_elimination public int ArrayList::indexOf(Object o) { if (o == null) { for (int i = 0; i < size; i++) if (elementData[i]==null) return i; } else { for (int i = 0; i < size; i++) if (o.equals(elementData[i])) return i; } return -1; }
  • 35. Lock Coarsening StringBuffer buffer = ... buffer.append(“Hello”); buffer.append(name); buffer.append(“n”); StringBuffer buffer = ... lock(buffer); buffer.append(“Hello”); unlock(buffer); lock(buffer); buffer.append(name); unlock(buffer); lock(buffer); buffer.append(“n”); unlock(buffer); StringBuffer buffer = ... lock(buffer); buffer.append(“Hello”); buffer.append(name); buffer.append(“n”); unlock(buffer); http://www.ibm.com/developerworks/library/j-jtp10185/index.html
  • 36. Inlining “The mother of all optimizations.” IPO: Inter-procedural Optimization
  • 37. Intrinsic Inlining public class Intrinsics { public static void main(String[] args) throws InterruptedException { int[] data = randomInts(100_000); int min = Integer.MAX_VALUE; for ( int x: data ) { min = Math.min(min, x); } Thread.sleep(5_000); System.out.println(min); } static final int[] randomInts(int size) { … } } example06.Intrinsics
  • 38. -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining 376 8 % example06.Intrinsics::randomInts @ 13 (30 bytes) @ 16 java.util.concurrent.ThreadLocalRandom::nextInt (8 bytes) inline (hot) @ 1 java.util.concurrent.ThreadLocalRandom::nextSeed (32 bytes) inline (hot) @ 3 java.lang.Thread::currentThread (0 bytes) (intrinsic) @ 18 sun.misc.Unsafe::getLong (0 bytes) (intrinsic) @ 27 sun.misc.Unsafe::putLong (0 bytes) (intrinsic) @ 4 java.util.concurrent.ThreadLocalRandom::mix32 (26 bytes) inline (hot) 379 9 java.lang.Math::min (11 bytes) 379 10 % example06.Intrinsics::main @ 22 (58 bytes) @ 30 java.lang.Math::min (11 bytes) (intrinsic) Intrinsic Inlining
  • 39. Direct Call Inlining public class Inlining { public static void main(String[] args) throws InterruptedException { System.setOut(new NullPrintStream()); for ( int i = 0; i < 20_000; ++i ) { hotMethod(); } Thread.sleep(5_000); } public static void hotMethod() { System.out.println(square(7)); System.out.println(square(9)); } static int square(int x) { return x * x; } } public static void hotMethod() { System.out.println(7 * 7); System.out.println(9 * 9); } example07.DirectInlining static, private, constructor calls
  • 40. Direct Call Inlining 226 53 example07.DirectInlining::hotMethod (23 bytes) @ 5 example07.DirectInlining::square (4 bytes) inline (hot) !m @ 8 java.io.PrintStream::println (24 bytes) already compiled into a big method @ 16 example07.DirectInlining::square (4 bytes) inline (hot) !m @ 19 java.io.PrintStream::println (24 bytes) already compiled into a big method 228 54 % example07.DirectInlining::main @ 15 (35 bytes) @ 15 example07.DirectInlining::hotMethod (23 bytes) inline (hot) @ 5 example07.DirectInlining::square (4 bytes) inline (hot) !m @ 8 java.io.PrintStream::println (24 bytes) already compiled into a big method @ 16 example07.DirectInlining::square (4 bytes) inline (hot) !m @ 19 java.io.PrintStream::println (24 bytes) already compiled into a big method -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining
  • 41. Printing Assembly for a Method Download hsdis-amd64 dynamic library Copy to jre/lib directory Run HotSpot with... -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,{package/Class::method}
  • 42. 0x0000000106c57843: mov $0x31,%edx 0x0000000106c57848: data32 xchg %ax,%ax 0x0000000106c5784b: callq 0x0000000106c10b60 ; OopMap{rbp=Oop off=48} ;*invokevirtual println ; - DirectInlining::hotMethod@7 (line 17) ; {optimized virtual_call} 0x0000000106c5785d: mov $0x51,%edx 0x0000000106c57862: nop 0x0000000106c57863: callq 0x0000000106c10b60 ; OopMap{off=72} ;*invokevirtual println ; - DirectInlining::hotMethod@17 (line 18) ; {optimized virtual_call} -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,example07/DirectInlining::hotMethod Direct Call Inlining
  • 43. Escape Analysis long sum = 0; for ( Long x: list ) { sum += iter.next(); } long sum = 0; for ( Iterator<Long> iter = list.iterator(); iter.hasNext(); ) { sum += iter.next(); }
  • 44. Escape Analysis http://psy-lob-saw.blogspot.ru/2014/12/the-escape-of-arraylistiterator.html long sum = 0; // ArrayList$Itr.<init> int iter$size = list.size(); int iter$cursor = 0; int iter$lastRet = -1; 
 // ArrayList$Itr.hasNext for ( ; iter$cursor != iter$size; ) { // ArrayList$Itr.next int i = iter$cursor; Object[] elementData = list.elementData; iter$cursor = i + 1; Long x = (Long)elementData[iter$lastRet = i]; sum += x; }
  • 45. public class SimpleProgram { static final int CHUNK_SIZE = 1_000; public static void main(String[] args) { for ( int i = 0; i < 250; ++i ) { long startTime = System.nanoTime(); for ( int j = 0; j < CHUNK_SIZE; ++j ) { //new Object
 obj = calloc(sizeof(Object)); obj.<init>(); // call ctor - empty } long endTime = System.nanoTime(); System.out.printf( "%dt%d%n", i, endTime - startTime); } } } Simple Program Revisited 1: inlined 2: escape analysis / dead store 3: empty loop / eliminate loop example01a.SimpleProgram
  • 48. Implicit Null Check public class NullCheck { public static void main(String[] args) throws InterruptedException { for ( int i = 0; i < 20_000; ++i ) { hotMethod("hello"); } Thread.sleep(5_000); for ( int i = 0; i < 10; ++i ) { System.out.printf("tempting fate %d%n", i); try { hotMethod(null); } catch ( NullPointerException e ) { // ignore } } } static final void hotMethod(final Object value) { value.hashCode(); } } example08a.NullCheckhttps://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/signals.html
  • 49. -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,example08a/NullCheck::hotMethod 0x000000010795f9c0: mov %eax,-0x14000(%rsp) 0x000000010795f9c7: push %rbp 0x000000010795f9c8: sub $0x50,%rsp ;*synchronization entry example08a.NullCheck::hotMethod@-1 (line 26) 0x000000010795f9cc: mov 0x8(%rsi),%r10d ; implicit exception: dispatches to 0x000000010795fe1d 0x000000010795f9d0: movabs $0x7eaa80d10,%r11 ; {oop(a 'java/lang/Class' = 'java/lang/System')} 0x000000010795f9da: mov 0x74(%r11),%r11d ;*getstatic out Implicit Null Check
  • 50. value.toString(); Possible, but improbable NPE if ( value == null ) { throw new NullPointerException(); } SEGVderef value signal handler throw NPE Implicit Null Check
  • 51. Null Check Deoptimization -XX:+PrintCompilation 124 1 java.lang.String::hashCode (55 bytes) 138 2 example08a.NullCheck::hotMethod (6 bytes) 138 3 % ! example08a.NullCheck::main @ 5 (69 bytes) tempting fate 0 tempting fate 1 tempting fate 2 5147 2 example08a.NullCheck::hotMethod (6 bytes) made not entrant tempting fate 3 tempting fate 4 tempting fate 5 tempting fate 6 tempting fate 7 tempting fate 8 tempting fate 9
  • 52. Not Thrown Away the First Time Bail to Interpreter Keep Compile? Yes No, recompile when... Now Later (Profile More) If Less Than 3 Deopts?
  • 53. Null Proportion: 0.100000 Caught: 10057 Unique: 2015 Null Proportion: 0.500000 Caught: 50096 Unique: 7191 Null Proportion: 0.900000 Caught: 89929 Unique: 11030 int caughtCount = 0; Set<NullPointerException> nullPointerExceptions = new HashSet<>(); for ( Object object : objects ) { try { object.toString(); } catch ( NullPointerException e ) { nullPointerExceptions.add( e ); caughtCount += 1; } } Hot Exception Optimization example08b.HotExceptionDemohttp://www.javaspecialists.eu/archive/Issue187.html
  • 54. Hot Exceptions int caughtCount = 0; HashSet<NullPointerException> nullPointerExceptions = new HashSet<>(); for ( Object object : objects ) { try { object.toString(); } catch ( NullPointerException e ) { boolean added = nullPointerExceptions.add(e); if ( !added ) e.printStackTrace(); caughtCount += 1; } } java.lang.NullPointerException No StackTrace???
  • 55. public class Unreached { public static volatile Object thing = null; public static void main(final String[] args) throws InterruptedException { for ( int i = 0; i < 20_000; ++i ) { hotMethod(); } Thread.sleep(5_000); thing = new Object(); for ( int i = 0; i < 20_000; ++i ) { hotMethod(); } Thread.sleep(5_000); } static final void hotMethod() { if ( thing == null ) System.out.print(""); else System.out.print(""); } } Unreached Deoptimization example09.Unreached phase change static final void hotMethod() { if ( thing == null ) System.out.print(""); else uncommon_trap(unreached); }
  • 56. -XX:+PrintCompilation Unreached Deoptimization 217 1 java.lang.String::hashCode (55 bytes) 235 2 java.lang.String::indexOf (70 bytes) 238 3 java.io.BufferedWriter::ensureOpen (18 bytes) 244 4 java.lang.String::length (6 bytes) 244 5 java.lang.String::indexOf (7 bytes) 245 6 java.nio.Buffer::position (5 bytes) 245 7 example09.Unreached::hotMethod (26 bytes) … 265 14 java.io.OutputStreamWriter::flushBuffer (8 bytes) 265 15 ! sun.nio.cs.StreamEncoder::flushBuffer (42 bytes) 267 16 sun.nio.cs.StreamEncoder::isOpen (5 bytes) 267 17 sun.nio.cs.StreamEncoder::implFlushBuffer (15 bytes) 267 18 % example09.Unreached::main @ 5 (59 bytes) 5255 7 example09.Unreached::hotMethod (26 bytes) made not entrant 5257 19 example09.Unreached::hotMethod (26 bytes) 5257 20 % example09.Unreached::main @ 39 (59 bytes)
  • 58. Why Speculate? y *= 2; x = 0; y = 25; y = -20; x = 0; y = 25; y = 30; trap!y = 15;
  • 59. Not So Simple Program Revisited 1 1000 1000000 0 12 24 36 48 60 72 84 96 108 120 132 144 156 168 180 192 204 216 228 240 unreached deopt, bail to interpreter!
  • 60. Virtual Call Inlining Func +apply(double):double Square +apply(double):double Sqrt +apply(double):double Class Hierarchy Analysis (CHA) Type Profile http://shipilev.net/blog/2015/black-magic-method-dispatch/
  • 61. public class Monomorphic { public static void main(String[] args) throws InterruptedException { Func func = new Square(); for ( int i = 0; i < 20_000; ++i ) { apply(func, i); } Thread.sleep(5_000); } static double apply(Func func, int x) { return func.apply(x); } } Monomorphic example10a.Monomorphic
  • 62. 217 1 java.lang.String::hashCode (55 bytes) 234 3 example10.support.Square::apply (4 bytes) 234 2 example10a.Monomorphic::apply (7 bytes) @ 3 example10.support.Square::apply (4 bytes) inline (hot) 234 4 % example10a.Monomorphic::main @ 13 (30 bytes) @ 15 example10a.Monomorphic::apply (7 bytes) inline (hot) @ 3 example10.support.Square::apply (4 bytes) inline (hot) Monomorphic -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining
  • 63. Beyond Monomorphic Func func = … double result = func.apply(20); Func func = … //no type guard! double result = 20 * 20; More Types?
  • 64. example10b.ChaStorm public class ChaStorm { public static void main(String[] args) throws InterruptedException { Func func = new Square(); for ( int i = 0; i < 10_000; ++i ) { apply1(func, i); … apply8(func, i); } System.out.println("Waiting for compiler..."); Thread.sleep(5_000); System.out.println("Deoptimize..."); System.out.println(Sqrt.class); Thread.sleep(5_000); } } Potential for Deopt Storm
  • 65. Potential for Deopt Storm 152 1 java.lang.String::hashCode (55 bytes) 166 2 example10.support.Square::apply (4 bytes) 173 3 example10b.ChaStorm::apply1 (7 bytes) 173 4 example10b.ChaStorm::apply2 (7 bytes) Waiting for compiler... 174 5 example10b.ChaStorm::apply3 (7 bytes) 174 6 example10b.ChaStorm::apply4 (7 bytes) 174 7 example10b.ChaStorm::apply5 (7 bytes) 174 8 example10b.ChaStorm::apply6 (7 bytes) 174 9 example10b.ChaStorm::apply7 (7 bytes) 174 10 example10b.ChaStorm::apply8 (7 bytes) Deoptimize... 5176 9 example10b.ChaStorm::apply7 (7 bytes) made not entrant 5176 8 example10b.ChaStorm::apply6 (7 bytes) made not entrant 5176 7 example10b.ChaStorm::apply5 (7 bytes) made not entrant 5176 5 example10b.ChaStorm::apply3 (7 bytes) made not entrant 5176 6 example10b.ChaStorm::apply4 (7 bytes) made not entrant 5176 4 example10b.ChaStorm::apply2 (7 bytes) made not entrant 5176 3 example10b.ChaStorm::apply1 (7 bytes) made not entrant 5176 10 example10b.ChaStorm::apply8 (7 bytes) made not entrant class example10.support.Sqrt -XX:+PrintCompilation
  • 66. Another Way to Deopt Bail to Interpreter Keep Compile? Yes No, recompile when... Now Later (Profile More) class load! stop the world, deopt now!
  • 67. Total time for which application threads were stopped: 0.0001010 seconds 5096 10 example10b.ChaStorm::apply8 (7 bytes) made not entrant 5096 8 example10b.ChaStorm::apply6 (7 bytes) made not entrant 5096 7 example10b.ChaStorm::apply5 (7 bytes) made not entrant 5096 5 example10b.ChaStorm::apply3 (7 bytes) made not entrant 5096 6 example10b.ChaStorm::apply4 (7 bytes) made not entrant 5096 4 example10b.ChaStorm::apply2 (7 bytes) made not entrant 5096 9 example10b.ChaStorm::apply7 (7 bytes) made not entrant 5096 3 example10b.ChaStorm::apply1 (7 bytes) made not entrant vmop [threads: total initially_running wait_to_block] … 5.096: Deoptimize [ 7 0 0 ] … Another Way to Deopt -XX:+PrintCompilation -XX+PrintSafepointStatistics -XX:PrintSafepointStatisticsCount=1 http://blog.ragozin.info/2012/10/safepoints-in-hotspot-jvm.html
  • 68. Bimorphic Func func = … double result = func.apply(20); Func func = … //no type guard! double result = 20 * 20; add another type Func func = … double result; if ( func.getClass().equals(Square.class) ) { result = 20 * 20; } else { uncommon_trap(class_check); } give up!
  • 69. public class ClassDevirtualization { public static void main(String[] args) throws InterruptedException { System.out.println("Using Square..."); Func func = new Square(); for ( int i = 0; i < 20_000; ++i ) { apply1(func, i); apply2(func, i); } Thread.sleep(5_000); System.out.printf("Loading %s to Deopt Now!%n”, Sqrt.class); System.out.println("Keep using Square in apply1..."); func = new Square(); for ( int i = 0; i < 20_000; ++i ) apply1(func, i); Thread.sleep(5_000); System.out.println("Use AlsoSquare in apply1..."); func = new AlsoSquare(); for ( int i = 0; i < 20_000; ++i ) apply1(func, i); Thread.sleep(5_000); System.out.println("Use AnotherSquare in apply1..."); func = new AnotherSquare(); for ( int i = 0; i < 20_000; ++i ) apply1(func, i); Thread.sleep(5_000); …after 3 types no more deopts… } } stop the world, deopt now! class check deopt! bimorphic deopt! example10c.ClassDevirtualization Class Devirtualization
  • 70. 89 1 java.lang.String::hashCode (55 bytes) Using Square... 104 2 example10.support.Square::apply (4 bytes) 105 3 example10c.ClassDevirtualization::apply1 (7 bytes) 105 4 example10c.ClassDevirtualization::apply2 (7 bytes) 106 5 % example10c.ClassDevirtualization::main @ 21 (240 bytes) 5116 5 % example10c.ClassDevirtualization::main @ -2 (240 bytes) made not entrant 5116 4 example10c.ClassDevirtualization::apply2 (7 bytes) made not entrant 5116 3 example10c.ClassDevirtualization::apply1 (7 bytes) made not entrant Loading class example10.support.Sqrt to Deoptimize Now! Keep using Square in apply1... 5128 6 example10c.ClassDevirtualization::apply1 (7 bytes) 5128 7 % example10c.ClassDevirtualization::main @ 88 (240 bytes) Use AlsoSquare in apply1... 10131 6 example10c.ClassDevirtualization::apply1 (7 bytes) made not entrant 10131 8 example10c.ClassDevirtualization::apply1 (7 bytes) 10132 9 % example10c.ClassDevirtualization::main @ 131 (240 bytes) Use AnotherSquare in apply1... 15134 8 example10c.ClassDevirtualization::apply1 (7 bytes) made not entrant 15134 10 example10c.ClassDevirtualization::apply1 (7 bytes) 15135 11 % example10c.ClassDevirtualization::main @ 174 (240 bytes) Use YetAnotherSquare in apply1... 20139 12 % example10c.ClassDevirtualization::main @ 217 (240 bytes) Class Devirtualization -XX:+PrintCompilation
  • 71. WorseYet... class AlsoSquare extends Square {} class AnotherSquare extends Square {} class Square extends Func { double final apply(double x) { return x * x; } } classYetAnotherSquare extends Square {}
  • 72. Unintentional Megamorphism new HashMap<String, Integer>() {{ put(“foo”, 20); put(“bar”, 30); }};
  • 74. 68 1 java.lang.String::hashCode (55 bytes) Using Square... 79 2 example10.support.Square::apply (4 bytes) 80 3 example10d.InterfaceDevirtualization::apply1 (9 bytes) 80 4 example10d.InterfaceDevirtualization::apply2 (9 bytes) 81 5 % example10d.InterfaceDevirtualization::main @ 21 (240 bytes) Loading class example10.support.Sqrt - no CHA for interfaces! Keep using Square in apply1... 5090 6 % example10d.InterfaceDevirtualization::main @ 88 (240 bytes) Use AlsoSquare in apply1... 10094 5 % example10d.InterfaceDevirtualization::main @ -2 (240 bytes) made not entrant 10094 6 % example10d.InterfaceDevirtualization::main @ -2 (240 bytes) made not entrant 10094 3 example10d.InterfaceDevirtualization::apply1 (9 bytes) made not entrant 10095 7 example10d.InterfaceDevirtualization::apply1 (9 bytes) 10095 8 % example10d.InterfaceDevirtualization::main @ 131 (240 bytes) Use AnotherSquare in apply1... 15101 7 example10d.InterfaceDevirtualization::apply1 (9 bytes) made not entrant 15102 9 example10d.InterfaceDevirtualization::apply1 (9 bytes) 15102 10 % example10d.InterfaceDevirtualization::main @ 174 (240 bytes No CHA for Interfaces -XX:+PrintCompilation
  • 75. MaxTrivialSize 6 MaxInlineSize 35 FreqInlineSize 325 MaxInlineLevel 9 MaxRecursiveInlineLevel 1 MinInliningThreshold 250 Tier1MaxInlineSize 8 Tier1FreqInlineSize 35 Inlining Numbers to Remember... `java -XX:+PrintFlagsFinal`
  • 76. “Fun” with Unloaded public class UnloadedForever { public static void main(String[] args) { for ( int i = 0; i < 100_000; ++i ) { try { factory(); } catch ( Throwable t ) { // ignore } } } static DoesNotExist factory() { return new DoesNotExist(); } } example11a.UnloadedForever
  • 77. -XX:+PrintCompilation Unloaded Forever 72 1 java.lang.String::hashCode (55 bytes) 156 2 java.lang.Object::<init> (1 bytes) 183 3 s java.lang.Throwable::fillInStackTrace (29 bytes) 183 4 n java.lang.Throwable::fillInStackTrace (native) 183 5 java.lang.LinkageError::<init> (6 bytes) 184 6 java.lang.Error::<init> (6 bytes) 184 7 java.lang.Throwable::<init> (34 bytes) 185 8 example11a.UnloadedForever::factory (8 bytes) 186 9 java.lang.NoClassDefFoundError::<init> (6 bytes) 186 8 example11a.UnloadedForever::factory (8 bytes) made not entrant 223 10 % ! example11a.UnloadedForever::main @ 5 (23 bytes) 273 11 example11a.UnloadedForever::factory (8 bytes) 274 11 example11a.UnloadedForever::factory (8 bytes) made not entrant 358 12 example11a.UnloadedForever::factory (8 bytes) 358 12 example11a.UnloadedForever::factory (8 bytes) made not entrant 441 13 example11a.UnloadedForever::factory (8 bytes) 442 13 example11a.UnloadedForever::factory (8 bytes) made not entrant 528 14 example11a.UnloadedForever::factory (8 bytes) 978 8 example11a.UnloadedForever::factory (8 bytes) made zombie
  • 78. “Fun” with Uninitialized public class UninitializedForever { static class Uninitialized { static { if ( true ) throw new RuntimeException(); } } public static void main(String[] args) { for ( int i = 0; i < 100_000; ++i ) { try { new Uninitialized(); } catch ( Throwable t ) { // ignore } } } } example11b.UnintializedForever
  • 79. -XX:+PrintCompilation 74 1 java.lang.String::hashCode (55 bytes) 162 2 java.lang.Object::<init> (1 bytes) 188 3 s java.lang.Throwable::fillInStackTrace (29 bytes) 189 4 n java.lang.Throwable::fillInStackTrace (native) 189 5 java.lang.LinkageError::<init> (6 bytes) 190 6 java.lang.Error::<init> (6 bytes) 190 7 java.lang.Throwable::<init> (34 bytes) 191 8 java.lang.NoClassDefFoundError::<init> (6 bytes) 233 9 % ! example11b.UninitializedForever::main @ 5 (25 bytes) 241 9 % ! example11b.UninitializedForever::main @ -2 (25 bytes) made not entrant 252 10 % ! example11b.UninitializedForever::main @ 5 (25 bytes) 263 10 % ! example11b.UninitializedForever::main @ -2 (25 bytes) made not entrant 272 11 % ! example11b.UninitializedForever::main @ 5 (25 bytes) 281 11 % ! example11b.UninitializedForever::main @ -2 (25 bytes) made not entrant 290 12 % ! example11b.UninitializedForever::main @ 5 (25 bytes) 299 12 % ! example11b.UninitializedForever::main @ -2 (25 bytes) made not entrant 308 13 % ! example11b.UninitializedForever::main @ 5 (25 bytes) 318 13 % ! example11b.UninitializedForever::main @ -2 (25 bytes) made not entrant 328 14 % ! example11b.UninitializedForever::main @ 5 (25 bytes) 337 14 % ! example11b.UninitializedForever::main @ -2 (25 bytes) made not entrant Uninitialized Forever
  • 80. null_check unexpected null or zero divisor null_assert unexpected non-null or non-zero range_check unexpected array index class_check unexpected object class array_check unexpected array class intrinsic unexpected operand to intrinsic bimorphic unexpected object class in bimorphic inlining unloaded unloaded class or constant pool entry uninitialized bad class state (uninitialized) unreached code is not reached, compiler unhandled arbitrary compiler limitation constraint arbitrary runtime constraint violated div0_check a null_check due to division by zero age nmethod too old; tier threshold reached predicate compiler generated predicate failed loop_limit_check compiler generated loop limits check failed Reasons for Deoptimizing...
  • 81. none just interpret, do not invalidate nmethod maybe_recompile recompile the nmethod; need not invalidate make_not_entrant invalidate the nmethod, recompile (probably) reinterpret invalidate the nmethod, reset IC, maybe recompile make_not_compilable invalidate the nmethod and do not compile Actions When Deoptimizing...
  • 82. Bail to Interpreter Keep Compile? Yes, recompile? No, recompile when... Now Later (Profile More)No Yes none maybe recompile make not entrant reinterpret class load! stop the world, deopt now! uncommon trap!
  • 83. null_check make_not_entrant null_assert make_not_entrant range_check make_not_entrant class_check maybe_recompile array_check maybe_recompile intrinsic maybe_recompile, make_not_entrant bimorphic maybe_recompile unloaded reinterpret uninitialized reinterpret unreached reinterpret unhandled none constraint CHA - deopt now! div0_check make_not_entrant age maybe_recompile predicate none? loop_limit_check none? Reasons & Actions
  • 84. Does This Matter? thread1 thread2 inlinedMethod2 inlinedMethod1 hotMethod code cache interpreter frame compiled frame inlinedMethod2 inlinedMethod1 hotMethod ... ... run inlinedMethod2 inlinedMethod1 hotMethod ... ... run
  • 87. VM Developer Blogs Aleksey Shipilëv http://shipilev.net/ http://psy-lob-saw.blogspot.com/ Nitsan Wakart https://twitter.com/maddocig IgorVeresov