SlideShare a Scribd company logo
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 Proļ¬le
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/ļ¬nally
synchronized ( foo.getBar() ) {
...
}
tmp = foo.getBar();
monitor_enter(tmp);
try {
...
} ļ¬nally {
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 ļ¬nal 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)
Proļ¬le 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 (Proļ¬le 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 Proļ¬le
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 (Proļ¬le 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 ļ¬nal 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 (Proļ¬le 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

Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them All
Thomas Wuerthinger
Ā 
Clean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflixClean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflix
Victor Rentea
Ā 
Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19
JosƩ Paumard
Ā 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
Charles Nutter
Ā 
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
joaomatosf_
Ā 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
Charles Nutter
Ā 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
saber tabatabaee
Ā 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
Rafael Winterhalter
Ā 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
Luzan Baral
Ā 
An introduction to JVM performance
An introduction to JVM performanceAn introduction to JVM performance
An introduction to JVM performance
Rafael Winterhalter
Ā 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesCharles Nutter
Ā 
API Asynchrones en Java 8
API Asynchrones en Java 8API Asynchrones en Java 8
API Asynchrones en Java 8
JosƩ Paumard
Ā 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
Victor Rentea
Ā 
XXE: How to become a Jedi
XXE: How to become a JediXXE: How to become a Jedi
XXE: How to become a Jedi
Yaroslav Babin
Ā 
Java On CRaC
Java On CRaCJava On CRaC
Java On CRaC
Simon Ritter
Ā 
Percona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimizationPercona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimization
mysqlops
Ā 
Circuit Breaker.pptx
Circuit Breaker.pptxCircuit Breaker.pptx
Circuit Breaker.pptx
HrishikeshSarate
Ā 
OWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling PicklesOWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling Pickles
Christopher Frohoff
Ā 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
Rafael Winterhalter
Ā 
RxNetty vs Tomcat Performance Results
RxNetty vs Tomcat Performance ResultsRxNetty vs Tomcat Performance Results
RxNetty vs Tomcat Performance Results
Brendan Gregg
Ā 

What's hot (20)

Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them All
Ā 
Clean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflixClean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflix
Ā 
Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19
Ā 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
Ā 
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
Ā 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
Ā 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
Ā 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
Ā 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
Ā 
An introduction to JVM performance
An introduction to JVM performanceAn introduction to JVM performance
An introduction to JVM performance
Ā 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
Ā 
API Asynchrones en Java 8
API Asynchrones en Java 8API Asynchrones en Java 8
API Asynchrones en Java 8
Ā 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
Ā 
XXE: How to become a Jedi
XXE: How to become a JediXXE: How to become a Jedi
XXE: How to become a Jedi
Ā 
Java On CRaC
Java On CRaCJava On CRaC
Java On CRaC
Ā 
Percona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimizationPercona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimization
Ā 
Circuit Breaker.pptx
Circuit Breaker.pptxCircuit Breaker.pptx
Circuit Breaker.pptx
Ā 
OWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling PicklesOWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling Pickles
Ā 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
Ā 
RxNetty vs Tomcat Performance Results
RxNetty vs Tomcat Performance ResultsRxNetty vs Tomcat Performance Results
RxNetty vs Tomcat Performance Results
Ā 

Viewers also liked

Tiered Compilation in Hotspot JVM
Tiered Compilation in Hotspot JVMTiered Compilation in Hotspot JVM
Tiered Compilation in Hotspot JVM
Igor Veresov
Ā 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
National Cheng Kung University
Ā 
Understanding Garbage Collection
Understanding Garbage CollectionUnderstanding Garbage Collection
Understanding Garbage Collection
Doug Hawkins
Ā 
Understanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual MachineUnderstanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual Machine
National Cheng Kung University
Ā 
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
Charles 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 faster
Tim Ellison
Ā 
JVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesJVM: A Platform for Multiple Languages
JVM: A Platform for Multiple Languages
Kris Mok
Ā 
Garbage collection in JVM
Garbage collection in JVMGarbage collection in JVM
Garbage collection in JVM
aragozin
Ā 
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
DataWorks 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
Ā 
Intrinsic Methods in HotSpot VM
Intrinsic Methods in HotSpot VMIntrinsic Methods in HotSpot VM
Intrinsic Methods in HotSpot VM
Kris Mok
Ā 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
Mindfire Solutions
Ā 
Java GC
Java GCJava GC
Java GCRay Cheng
Ā 
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 Winter
banneker
Ā 
Facebook for Art
Facebook for ArtFacebook for Art
Facebook for Art
Bernard Goldbach
Ā 
The Music Industry
The Music IndustryThe Music Industry
The Music Industry
Ibrahim Shumon Khan
Ā 

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)
Ā 
Intrinsic Methods in HotSpot VM
Intrinsic Methods in HotSpot VMIntrinsic Methods in HotSpot VM
Intrinsic Methods in HotSpot VM
Ā 
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
Ā 

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 Mechanics
Azul Systems, Inc.
Ā 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
Ā 
Java Concurrency
Java ConcurrencyJava Concurrency
Java ConcurrencyCarol McDonald
Ā 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
Sylvain 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 Seal
Tzung-Bi Shih
Ā 
Java Fundamentals
Java FundamentalsJava Fundamentals
Java Fundamentals
Shalabh Chaudhary
Ā 
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
Thierry 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
Ā 
Android and cpp
Android and cppAndroid and cpp
Android and cpp
Joan Puig Sanz
Ā 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
MongoDB
Ā 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
HongAnhNguyn285885
Ā 
Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015Improving Java performance at JBCNConf 2015
Improving Java performance at JBCNConf 2015
Raimon RĆ fols
Ā 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
Apaichon Punopas
Ā 
20151224-games
20151224-games20151224-games
20151224-games
Noritada Shimizu
Ā 
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
n|u - The Open Security Community
Ā 
Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010
Chris 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 RxJava
Frank Lyaruu
Ā 
Iron python
Iron pythonIron python
Iron pythonGeorgeIshak
Ā 

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 Puzzlers
Doug Hawkins
Ā 
JVM Mechanics
JVM MechanicsJVM Mechanics
JVM Mechanics
Doug Hawkins
Ā 
Concurrency Concepts in Java
Concurrency Concepts in JavaConcurrency Concepts in Java
Concurrency Concepts in Java
Doug Hawkins
Ā 
JVM Internals - NHJUG Jan 2012
JVM Internals - NHJUG Jan 2012JVM Internals - NHJUG Jan 2012
JVM Internals - NHJUG Jan 2012
Doug 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 2011
Doug Hawkins
Ā 
JVM Internals - NEJUG Nov 2010
JVM Internals - NEJUG Nov 2010JVM Internals - NEJUG Nov 2010
JVM Internals - NEJUG Nov 2010
Doug 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 Code
Doug Hawkins
Ā 
JVM Internals - Garbage Collection & Runtime Optimizations
JVM Internals - Garbage Collection & Runtime OptimizationsJVM Internals - Garbage Collection & Runtime Optimizations
JVM Internals - Garbage Collection & Runtime Optimizations
Doug 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

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
Ā 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
Ā 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
Ā 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
Ā 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
Ā 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
Ā 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
Ā 
Dev Dives: Train smarter, not harder ā€“ active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder ā€“ active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder ā€“ active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder ā€“ active learning and UiPath LLMs for do...
UiPathCommunity
Ā 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
Ā 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
Ā 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
Ā 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
Ā 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
Ā 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
Ā 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
Ā 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
Ā 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
Ā 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
Ā 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
Ā 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
Ā 

Recently uploaded (20)

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Ā 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
Ā 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
Ā 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Ā 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Ā 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Ā 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
Ā 
Dev Dives: Train smarter, not harder ā€“ active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder ā€“ active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder ā€“ active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder ā€“ active learning and UiPath LLMs for do...
Ā 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Ā 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ā 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Ā 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Ā 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
Ā 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Ā 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Ā 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Ā 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Ā 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
Ā 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Ā 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Ā 

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 Proļ¬le 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/ļ¬nally synchronized ( foo.getBar() ) { ... } tmp = foo.getBar(); monitor_enter(tmp); try { ... } ļ¬nally { 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 ļ¬nal 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) Proļ¬le 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 (Proļ¬le 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 Proļ¬le 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 (Proļ¬le 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 ļ¬nal 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 (Proļ¬le 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