SlideShare une entreprise Scribd logo
1  sur  88
Télécharger pour lire hors ligne
Douglas Q. Hawkins
@dougqh
VM Engineer
Understanding
the JIT’s Tricks
Zing®
Highly ScalableVM
Continuously Concurrent Compacting Collector
ReadyNow! for Low Latency Applications
http://www.azulsystems.com/solutions/zing/readynow
Zulu®
Multi-Platform OpenJDK
Cloud Support including Docker and Azure
Embedded Support
http://zulu.org/
GOAL: Understand
ArrayList<E>.forEach(Consumer<? super E> action) {
for ( int i = 0; i < this.size; i++ ) {
action.accept(this.elementData[i]);
}
}
…
?5 Lines?
Actual Implementation
ArrayList<E>.forEach(Consumer<? super E> action) {
Objects.requireNonNull(action);
final int expectedModCount = modCount;
final E[] elementData = (E[]) this.elementData;
final int size = this.size;
for (int i=0; modCount == expectedModCount && i < size; i++) {
action.accept(elementData[i]);
}
if (modCount != expectedModCount) throw new CME();
}
The Just-in-Time Compiler
is a Compiler, but It’s a…
Profile Guided
Speculatively Optimizing
Compiler
So We Need to Understand…
Static Optimizations
Speculative Optimizations
Inter-procedural Analysis
Deoptimization
How They Fit Together
Understand What
You Can Rely on
OpenJDK’s JIT to do
!
REAL GOAL:
http://openjdk.java.net/groups/hotspot/docs/RuntimeOverview.html
?But First…
When Do We JIT?
public class Allocation {
static final int CHUNK_SIZE = 1_000;
public static void main(String[] args) {
for ( int i = 0; i < 500; ++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);
}
}
}
S:01A
1
100
10000
0 50 100 150 200 250 300 350 400 450
Warm-Up
interpreter 1st JIT 2nd JIT
logns
-XX:+PrintCompilation
80 29 3 java.util.HashMap::newNode (13 bytes)
81 30 3 java.util.HashMap::afterNodeInsertion
81 31 3 java.lang.String::indexOf (7 bytes)
96 73 % 3 example01a.Allocation::main @ 15 (78 bytes)
101 99 % 4 example01a.Allocation::main @ 15 (78 bytes)
?Two Compilations
of One Method?
What about Tiers 1 & 2?
When Exactly?
Thresholds
intx Tier2BackEdgeThreshold = 0 {product}
intx Tier2CompileThreshold = 0 {product}
intx Tier3BackEdgeThreshold = 60000 {product}
intx Tier3CompileThreshold = 2000 {product}
intx Tier3InvocationThreshold = 200 {product}
intx Tier3MinInvocationThreshold = 100 {product}
intx Tier4BackEdgeThreshold = 40000 {product}
intx Tier4CompileThreshold = 15000 {product}
intx Tier4InvocationThreshold = 5000 {product}
intx Tier4MinInvocationThreshold = 600 {product}
intx BackEdgeThreshold = 100000 {pd product}
intx CompileThreshold = 10000 {pd product}
Java 7 (Non-tiered) Thresholds
Java 8 (Tiered) Thresholds
-XX:+PrintFlagsFinal
Counters
Invocation Counter
Backedge (Loop) Counter
Backedge Counter > Backedge Threshold
Hot Loops
Invocation Counter > Invocation Threshold
Hot Methods
Invocation + Backedge Counter > Compile Threshold
Medium Hot Methods with Medium Hot Loops
Method or Loop JIT
If Loop Count (Backedges) > Threshold,
Compile Loop
On-Stack Replacement
On-Stack Replacement
sum
...
...
main
sum @ 20
...
...
main
interpreter frame
compiled frame
C2
C1Interpreter
time
Tiered Compilation
5x
10-100+x
0
0
0
interpreter
3 4
2 3 4
1 3
c1 c2
none
basic
counters detailed
common
c2 busy
trivial
method
Tiered Compilation
0 2 3 4
Made Not Entrant
12394 73 % 3 …Allocation::main @ -2 (78 bytes) made not entrant
Caller
Method
Callee
Method
Tier 3
Callee
Call
Dispatcher
calls
cached
Tier 4
Callee
caches
Lock Free Cache Invalidation
HotSpot’s Job is to
Find Hot Spots
Rules for Triggering the
JIT Keep Changing
HotSpot JITs…
Hot Methods
Hot Loops
Warm Methods with Warm Loops
?What Does
the JIT C2 Do?
Focus on Final Tier
non-sampling
period
sampling
period
full-speed
period
C2
C1Interpreter
time
C1
C2
re-sampling
period
stable
period
Deopt + Bail to Interpreter
Profiling + Deoptimization
5x
10-100+x
public class AllocationTrap {
static final int CHUNK_SIZE = 1_000;
public static void main(String[] args) {
Object trap = null;
for ( int i = 0; i < 500; ++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 == 400 ) trap = new Object();
long endTime = System.nanoTime();
System.out.printf("%dt%d%n", i, endTime - startTime);
}
}
}
S:01B
1
100
10000
0 50 100 150 200 250 300 350 400 450
Deoptimization
behavioral change,
deoptimize!
logns
Returning to forEach
ArrayList<E>.forEach(Consumer<? super E> action) {
for ( int i = 0; i < this.size; i++ ) {
action.accept(this.elementData[i]);
}
}
Something “Simpler”
ArrayStream<E>.forEach(Consumer<? super E> action) {
for ( int i = 0; i < this.elementData.length; i++ ) {
action.accept(this.elementData[i]);
}
}
“Simpler” Bound
Implied Safety Code
ArrayStream<E>.forEach(Consumer<? super E> action) {
if ( this == null ) throw new NPE();
if ( this.elementData == null ) throw new NPE();
for ( int i = 0; i < this.elementData.length; i++ ) {
if ( this == null ) throw new NPE();
if ( this.elementData == null ) throw new NPE();
if ( i < 0 ) throw new AIOBE();
if ( i >= this.elementData.length ) throw new AIOBE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[i]);
}
}
Null Check Elimination
ArrayStream<E>.forEach(Consumer<? super E> action) {
if ( this == null ) throw new NPE();
if ( this.elementData == null ) throw new NPE();
for ( int i = 0; i < this.elementData.length; i++ ) {
if ( this == null ) throw new NPE();
if ( this.elementData == null ) throw new NPE();
if ( i < 0 ) throw new AIOBE();
if ( i >= this.elementData.length ) throw new AIOBE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[i]);
}
}
this != null
Lower Bound Check Elimination
ArrayStream<E>.forEach(Consumer<? super E> action) {
if ( this.elementData == null ) throw new NPE();
for ( int i = 0; i < this.elementData.length; i++ ) {
if ( this.elementData == null ) throw new NPE();
if ( i < 0 ) throw new AIOBE();
if ( i >= this.elementData.length ) throw new AIOBE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[i]);
}
}
i >= 0
i <= INT_MAX
ArrayStream<E>.forEach(Consumer<? super E> action) {
if ( this.elementData == null ) throw new NPE();
for ( int i = 0; i < this.elementData.length; i++ ) {
if ( this.elementData == null ) throw new NPE();
if ( i >= this.elementData.length ) throw new AIOBE();
if ( !(i < this.elementData.length) ) throw new AIOBE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[i]);
}
}
Canonicalize Upper Bound
Canonicalize
ArrayStream<E>.forEach(Consumer<? super E> action) {
if ( this.elementData == null ) throw new NPE();
for ( int i = 0; i < this.elementData.length; i++ ) {
if ( this.elementData == null ) throw new NPE();
if ( !(i < this.elementData.length) ) throw new AIOBE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[i]);
}
}
Upper Bound Check Elimination
Common
Sub-
Expression
* Really GlobalValue Numbering
*
Cached Length isn’t Better!
public class ArrayStream<E> interface Stream<E> {
private final E[] elementData;
private final int size;
public ArrayStream(E… elements) {
this.elementData = elements;
this.size = elements.length;
}
forEach(Consumer<? super E> action) {
if ( this.elementData == null ) throw new NPE();
for ( int i = 0; i < this.size; i++ ) {
if ( this.elementData == null ) throw new NPE();
if ( i >= this.elementData.length ) throw new AIOBE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[i]);
}
}
}
mismatch!
Confuses the JIT
ArrayStream<E>.forEach(Consumer<? super E> action) {
if ( this.elementData == null ) throw new NPE();
for ( int i = 0; i < this.elementData.length; i++ ) {
if ( this.elementData == null ) throw new NPE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[i]);
}
}
What Else?
What Else
Can Be
Done?
ArrayStream<E>.forEach(Consumer<? super E> action) {
if ( this.elementData == null ) throw new NPE();
for ( int i = 0; i < this.elementData.length; i++ ) {
if ( this.elementData == null ) throw new NPE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[i]);
}
}
Null Pointer Checks
Required -
cannot
optimize
further?
Assume
non-null
from
above?
Required -
cannot
optimize
further?
Implicit Null Check
if ( this.elementData == null ) throw new NPE();
this.elementData.length;
Possible, but
improbable
SEGVderef
value
signal
handler
throw
NPE
0x10795f9cc: mov 0x8(%rsi),%r10d
; implicit exception: dispatches to 0x10795fe1d
Three Nulls,You Deopt!
-XX:+PrintCompilation
121 1 java.lang.String::hashCode (55 bytes)
135 2 …NullCheck::hotMethod (6 bytes)
136 3 % ! …NullCheck::main @ 5 (69 bytes)
tempting fate 0
tempting fate 1
tempting fate 2
5144 2 …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
S:02A
Stop the World
Need to Stop All Java Threads to...
Deoptimize
Lock Inflation / Deflation
Garbage Collect
Java Threads
read 0x1000
0x1000
SEGV
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
S:02B
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???
S:02B
ArrayStream<E>.forEach(Consumer<? super E> action) {
if ( this.elementData == null ) throw new NPE();
for ( int i = 0; i < this.elementData.length; i++ ) {
if ( this.elementData == null ) throw new NPE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[i]);
}
}
Total Elimination is Better!
Assume
non-null
from
above?
Common Sub-Expression
if ( this.elementData == null ) throw new NPE();
Requires knowing that…
null doesn’t change
this doesn’t change
this.elementData doesn’t change
easy
hard
for ( … ) {
if ( this.elementData == null ) throw new NPE();
}
The Other “Easy” One
LocalVariable: action
ArrayStream<E>.forEach(Consumer<? super E> action) {
if ( this.elementData == null ) throw new NPE();
for ( int i = 0; i < this.elementData.length; i++ ) {
if ( this.elementData == null ) throw new NPE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[i]);
}
}
CANNOT be changed by
another thread or method.
Loop Peeling
ArrayStream<E>.forEach(Consumer<? super E> action) {
if ( this.elementData == null ) throw new NPE();
// i=0 iteration
if ( 0 < this.elementData.length ) {
if ( this.elementData == null ) throw NPE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[0]);
}
// rest of the iterations
for ( int i = 1; i < this.elementData.length; i++ ) {
if ( this.elementData == null ) throw new NPE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[i]);
}
}
Back to this.elementData
CAN be changed by another thread.
Compiler Doesn’t Care!
Really?
No Synchronization Action -
Single Threaded Semantics
Loop Invariant Hoisting?
ArrayStream<E>.forEach(Consumer<? super E> action) {
E[] elementData = this.elementData;
int len = elementData.length;
if ( elementData == null ) throw new NPE();
// i=0 iteration
if ( 0 < len ) {
if ( elementData == null ) throw NPE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[0]);
}
// rest of the iterations
for ( int i = 1; i < elementData.length; i++ ) {
if ( elementData == null ) throw new NPE();
action.accept(elementData[i]);
}
}
Terrifying!
while ( !sharedDone );
print(sharedData);
sharedData = …;
sharedDone = true;
Consumer ThreadProducer Thread
Assume sharedData
is loop invariant!
localDone = sharedDone;
while ( !localDone );
print(sharedData);
Not So Fast
Single Threaded Side Effects
ArrayStream<E>.forEach(Consumer<? super E> action) {
if ( this.elementData == null ) throw new NPE();
// i=0 iteration
if ( 0 < this.elementData.length ) {
if ( this.elementData == null ) throw NPE();
if ( action == null ) throw new NPE();
action.accept(this.elementData[0]);
}
// rest of the iterations
for ( int i = 1; i < this.elementData.length; i++ ) {
if ( this.elementData == null ) throw new NPE();
action.accept(this.elementData[i]);
}
}
Can
this.elementData
change? YES
ArrayStream
NOT ArrayList
this.elementData is final!
Doesn’t matter - reflection!
A Call is a
“Black Box”
which may
contain
“Evils”!
Inter-procedural Analysis
Prove No
Side Effects / Evils
Inter-procedural Analysis
=
Inlining
Inlining
Copy & Paste Callee Into Caller
System.out.println(square(9));
inline
System.out.println(9 * 9);
constant folding
System.out.println(81);
Start with a Static Call
JMH: Java Measurement Harness
@Benchmark
public void cstyle() {
for ( int i = 0; i < this.elementData.length; ++i ) {
consume(this.elementData[i]);
}
}
static int sum = 0;
@CompilerControl(CompilerControl.Mode.INLINE | DONT_INLINE)
static consume(int x) {
sum += x;
}
Benchmark Mode Cnt Score Error Units
LoopInvariant.cstyle avgt 10 296.759 ± 3.619 ns/op
LoopInvariant.enhanced avgt 10 294.379 ± 7.461 ns/op
LoopInvariant.hoisted avgt 10 292.491 ± 7.623 ns/op
Inlined
Not Inlined
Benchmark Mode Cnt Score Error Units
LoopInvariant.cstyle avgt 10 2922.285 ± 48.199 ns/op
LoopInvariant.enhanced avgt 10 2301.793 ± 37.154 ns/op
LoopInvariant.hoisted avgt 10 2325.981 ± 39.935 ns/op
benchmarks.LoopInvariant
Not Just “Sugar”
for ( int x: this.elementData ) {
consume(x);
}
E[] elementData = this.elementData;
for ( int i = 0; i < elementData.length; ++i ) {
int x = elementData[i];
consume(x);
}
javac
More Terrifying!
while ( !sharedDone ) {
fn();
}
print(sharedData);
Consumer Thread
Assume sharedData
is loop invariant!
localDone = sharedDone;
while ( !localDone ) {
// inlined fn() …
}
print(sharedData);
Producer Thread
sharedData = …;
sharedDone = true;
Inlining Numbers to Remember...
-XX:+PrintFlagsFinal
MaxTrivialSize 6
MaxInlineSize 35
FreqInlineSize 325
MaxInlineLevel 9
MaxRecursiveInlineLevel 1
MinInliningThreshold 250
Tier1MaxInlineSize 8
Tier1FreqInlineSize 35
What About Dynamic Calls?
Consumer
+apply(Object):Object
ConsumerA ConsumerZ100 more
http://shipilev.net/blog/2015/black-magic-method-dispatch/
… …
Java is a Dynamic Language!
Dynamically Loaded
Dynamically Linked
Lazy Initialized
Typically Dynamically Dispatched
Even Dynamic Code Gen in JDK
Unloaded Class?!?
Fields in Class
Methods in Class
Parent Class
Interfaces
Anything?
…Don’t Know
!*#
Give Up!
uncommon_trap(:unloaded)
What? I give up!
Compile + Deopt Storm
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();
}
}
Compile + Deopt Storm
On-Stack Replacement
in Reverse
sum
...
...
main
sum
...
...
main
interpreter frame
compiled frame
Caller
Method
Callee
Method
Tier 4
Callee
Call
Dispatcher
calls
cached
caches
Lock Free — but Hurts
?
Lock Free — but Really Hurts
time
Deopt + Bail to Interpreter
5x
10-100+x
All new
calling
threads
Static Analysis
Class Hierarchy Analysis
TypeProfile
Unique Concrete Method
Back to Dynamic/Virtual Calls
4 Strategies to “Devirtualize”
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
S:04A
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);
}
}
Static Analysis
S:04A
217 1 java.lang.String::hashCode (55 bytes)
234 3 example03.support.Square::apply (4 bytes)
234 4 % example03a.Monomorphic::main @ 13 (30 bytes)
@ 15 example03a.Monomorphic::apply (7 bytes) inline (hot)
@ 3 example03.support.Square::apply (4 bytes) inline (hot)
234 2 example03a.Monomorphic::apply (7 bytes)
@ 3 example03.support.Square::apply (4 bytes) inline (hot)
Monomorphic
-XX:+PrintCompilation -XX:-BackgroundCompilation
-XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining
public class ChaStorm {
public static void main(String[] args) throws… {
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
S:04B
Potential for Deopt Storm
152 1 java.lang.String::hashCode (55 bytes)
166 2 example04.support.Square::apply (4 bytes)
173 3 example04b.ChaStorm::apply1 (7 bytes)
173 4 example04b.ChaStorm::apply2 (7 bytes)
Waiting for compiler...
174 5 example04b.ChaStorm::apply3 (7 bytes) …
174 9 example04b.ChaStorm::apply7 (7 bytes)
174 10 example04b.ChaStorm::apply8 (7 bytes)
Deoptimize...
5176 9 example04b.ChaStorm::apply7 (7 bytes) made not entrant
5176 8 example04b.ChaStorm::apply6 (7 bytes) made not entrant
…
5176 4 example04b.ChaStorm::apply2 (7 bytes) made not entrant
5176 3 example04b.ChaStorm::apply1 (7 bytes) made not entrant
5176 10 example04b.ChaStorm::apply8 (7 bytes) made not entrant
class example04.support.Sqrt
vmop [threads: total initially_running wait_to_block] …
5.096: Deoptimize
http://blog.ragozin.info/2012/10/safepoints-in-hotspot-jvm.html
[ 7 0 0 ] …
-XX:+PrintCompilation
-XX+PrintSafepointStatistics
-XX:PrintSafepointStatisticsCount=1
NOT Lock Free — and
Really, Really Hurts
new calls
bail!
returning
calls bail!
Interpreter C2
!*#No IHA
TypeProfile
Interpreter & C1 Gather Data
Track Types used at Each Call Site
-XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation
<klass id='780' name='Square' flags='1'/>
<klass id='781' name='Sqrt' flags='1'/>
<call method='783' count=‘23161'
prof_factor='1' virtual='1' inline='1'
receiver='780' receiver_count=‘19901'
receiver2='781' receiver2_count='3260'/>
Bimorphic
Func func = …
double result = func.apply(20);
func.apply(x);
if ( func.getClass().equals(Square.class) ) {
…
} else {
uncommon_trap(class_check);
}
if ( func.getClass().equals(Square.class) ) {
…
} else if ( func.getClass().equals(AlsoSquare.class) ) {
…
} else {
uncommon_trap(bimorphic);
}
Very Effective
Call-site specific
Works for 90-95% of call sites
Very few call sites are “megamorphic”
Slightly more overhead than
no check (3-5ns)
Why Trap?!?
if ( func.getClass().equals(Square.class) ) {
…
} else {
uncommon_trap(class_check);
}
Why not func.apply?
Solved? NO
ArrayList<E>.forEach(Consumer<? super E> action) {
for ( int i = 0; i < this.size; i++ ) {
action.accept(this.elementData[i]);
}
}
megamorphic,
no (incomplete)
inlining.
elementData
could change!
size could change!
Unless, Done Manually…
ArrayList<E>.forEach(Consumer<? super E> action) {
Objects.requireNonNull(action);
final int expectedModCount = modCount;
final E[] elementData = (E[]) this.elementData;
final int size = this.size;
for (int i=0;
modCount == expectedModCount && i < size;
i++)
{
action.accept(elementData[i]);
}
if (modCount != expectedModCount) throw new CME();
}
Goal Accomplished? NO
Handling this.size with an
uncommon trap
More loop optimizations…
Loop Unrolling
Loop Unswitching

Vectorization
Interactions with Garbage Collector
JIT (and All Compilers) Are Just
Complex Pattern Matchers.
Don’t Like
“Weird” Code
Big Methods
Mutability
Native Methods
Like
“Normal” Code
Small Methods
Immutability
LocalVariables
* except for intrinsics: arraycopy, tan, …
*
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/
Shameless Self-Promotion
http://shop.oreilly.com/product/0636920043560.do
Optimizing Java
Douglas Q. Hawkins
?
Questions?
Douglas Q. Hawkins
@dougqh
VM Engineer

Contenu connexe

Tendances

JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013Vladimir Ivanov
 
JVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovJVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovZeroTurnaround
 
Rules to Hack By - Offensivecon 2022 keynote
Rules to Hack By - Offensivecon 2022 keynoteRules to Hack By - Offensivecon 2022 keynote
Rules to Hack By - Offensivecon 2022 keynoteMarkDowd13
 
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionNeat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionMikhail Egorov
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by ExampleOlve Maudal
 
モダン PHP テクニック 12 選 ―PsalmとPHP 8.1で今はこんなこともできる!―
モダン PHP テクニック 12 選 ―PsalmとPHP 8.1で今はこんなこともできる!―モダン PHP テクニック 12 選 ―PsalmとPHP 8.1で今はこんなこともできる!―
モダン PHP テクニック 12 選 ―PsalmとPHP 8.1で今はこんなこともできる!―shinjiigarashi
 
Pentesting GraphQL Applications
Pentesting GraphQL ApplicationsPentesting GraphQL Applications
Pentesting GraphQL ApplicationsNeelu Tripathy
 
[KubeCon NA 2020] containerd: Rootless Containers 2020
[KubeCon NA 2020] containerd: Rootless Containers 2020[KubeCon NA 2020] containerd: Rootless Containers 2020
[KubeCon NA 2020] containerd: Rootless Containers 2020Akihiro Suda
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationWei-Ren Chen
 
Nginxを使ったオレオレCDNの構築
Nginxを使ったオレオレCDNの構築Nginxを使ったオレオレCDNの構築
Nginxを使ったオレオレCDNの構築ichikaway
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from insidejulien pauli
 
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedKernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedAnne Nicolas
 
Quarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java frameworkQuarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java frameworkSVDevOps
 

Tendances (20)

GCC LTO
GCC LTOGCC LTO
GCC LTO
 
Rust vs C++
Rust vs C++Rust vs C++
Rust vs C++
 
What Can Compilers Do for Us?
What Can Compilers Do for Us?What Can Compilers Do for Us?
What Can Compilers Do for Us?
 
JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013JVM JIT-compiler overview @ JavaOne Moscow 2013
JVM JIT-compiler overview @ JavaOne Moscow 2013
 
JVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir IvanovJVM JIT compilation overview by Vladimir Ivanov
JVM JIT compilation overview by Vladimir Ivanov
 
Rules to Hack By - Offensivecon 2022 keynote
Rules to Hack By - Offensivecon 2022 keynoteRules to Hack By - Offensivecon 2022 keynote
Rules to Hack By - Offensivecon 2022 keynote
 
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionNeat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protection
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
 
モダン PHP テクニック 12 選 ―PsalmとPHP 8.1で今はこんなこともできる!―
モダン PHP テクニック 12 選 ―PsalmとPHP 8.1で今はこんなこともできる!―モダン PHP テクニック 12 選 ―PsalmとPHP 8.1で今はこんなこともできる!―
モダン PHP テクニック 12 選 ―PsalmとPHP 8.1で今はこんなこともできる!―
 
Android binder-ipc
Android binder-ipcAndroid binder-ipc
Android binder-ipc
 
Pentesting GraphQL Applications
Pentesting GraphQL ApplicationsPentesting GraphQL Applications
Pentesting GraphQL Applications
 
[KubeCon NA 2020] containerd: Rootless Containers 2020
[KubeCon NA 2020] containerd: Rootless Containers 2020[KubeCon NA 2020] containerd: Rootless Containers 2020
[KubeCon NA 2020] containerd: Rootless Containers 2020
 
golang profiling の基礎
golang profiling の基礎golang profiling の基礎
golang profiling の基礎
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate Representation
 
Virtual Machine Constructions for Dummies
Virtual Machine Constructions for DummiesVirtual Machine Constructions for Dummies
Virtual Machine Constructions for Dummies
 
Nginxを使ったオレオレCDNの構築
Nginxを使ったオレオレCDNの構築Nginxを使ったオレオレCDNの構築
Nginxを使ったオレオレCDNの構築
 
Construct an Efficient and Secure Microkernel for IoT
Construct an Efficient and Secure Microkernel for IoTConstruct an Efficient and Secure Microkernel for IoT
Construct an Efficient and Secure Microkernel for IoT
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedKernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
 
Quarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java frameworkQuarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java framework
 

Similaire à JVM Mechanics: Understanding the JIT's Tricks

Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++nsm.nikhil
 
Testing for Educational Gaming and Educational Gaming for Testing
Testing for Educational Gaming and Educational Gaming for TestingTesting for Educational Gaming and Educational Gaming for Testing
Testing for Educational Gaming and Educational Gaming for TestingTao Xie
 
Introduction to nsubstitute
Introduction to nsubstituteIntroduction to nsubstitute
Introduction to nsubstituteSuresh Loganatha
 
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Intel® Software
 
Adam Sitnik "State of the .NET Performance"
Adam Sitnik "State of the .NET Performance"Adam Sitnik "State of the .NET Performance"
Adam Sitnik "State of the .NET Performance"Yulia Tsisyk
 
State of the .Net Performance
State of the .Net PerformanceState of the .Net Performance
State of the .Net PerformanceCUSTIS
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITEgor Bogatov
 
Next Generation Developer Testing: Parameterized Testing
Next Generation Developer Testing: Parameterized TestingNext Generation Developer Testing: Parameterized Testing
Next Generation Developer Testing: Parameterized TestingTao Xie
 
Be smart when testing your Akka code
Be smart when testing your Akka codeBe smart when testing your Akka code
Be smart when testing your Akka codeMykhailo Kotsur
 
Given below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdfGiven below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdfaptind
 
Given below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdfGiven below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdfaptind
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdfHans Jones
 
STAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Project
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithmK Hari Shankar
 
Node.js behind: V8 and its optimizations
Node.js behind: V8 and its optimizationsNode.js behind: V8 and its optimizations
Node.js behind: V8 and its optimizationsDawid Rusnak
 
Mutation Testing at BzhJUG
Mutation Testing at BzhJUGMutation Testing at BzhJUG
Mutation Testing at BzhJUGSTAMP Project
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdffantasiatheoutofthef
 

Similaire à JVM Mechanics: Understanding the JIT's Tricks (20)

Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++
 
Testing for Educational Gaming and Educational Gaming for Testing
Testing for Educational Gaming and Educational Gaming for TestingTesting for Educational Gaming and Educational Gaming for Testing
Testing for Educational Gaming and Educational Gaming for Testing
 
Introduction to nsubstitute
Introduction to nsubstituteIntroduction to nsubstitute
Introduction to nsubstitute
 
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*
 
Adam Sitnik "State of the .NET Performance"
Adam Sitnik "State of the .NET Performance"Adam Sitnik "State of the .NET Performance"
Adam Sitnik "State of the .NET Performance"
 
State of the .Net Performance
State of the .Net PerformanceState of the .Net Performance
State of the .Net Performance
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
 
Next Generation Developer Testing: Parameterized Testing
Next Generation Developer Testing: Parameterized TestingNext Generation Developer Testing: Parameterized Testing
Next Generation Developer Testing: Parameterized Testing
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
Be smart when testing your Akka code
Be smart when testing your Akka codeBe smart when testing your Akka code
Be smart when testing your Akka code
 
Given below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdfGiven below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdf
 
Given below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdfGiven below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdf
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
STAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Descartes Presentation
STAMP Descartes Presentation
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
 
Java programs
Java programsJava programs
Java programs
 
Node.js behind: V8 and its optimizations
Node.js behind: V8 and its optimizationsNode.js behind: V8 and its optimizations
Node.js behind: V8 and its optimizations
 
Mutation Testing at BzhJUG
Mutation Testing at BzhJUGMutation Testing at BzhJUG
Mutation Testing at BzhJUG
 
Mutation @ Spotify
Mutation @ Spotify Mutation @ Spotify
Mutation @ Spotify
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 

Plus de Doug Hawkins

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

Plus de Doug Hawkins (10)

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
 
Understanding Garbage Collection
Understanding Garbage CollectionUnderstanding Garbage Collection
Understanding Garbage Collection
 
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
 

Dernier

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Dernier (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 

JVM Mechanics: Understanding the JIT's Tricks

  • 1. Douglas Q. Hawkins @dougqh VM Engineer Understanding the JIT’s Tricks
  • 2. Zing® Highly ScalableVM Continuously Concurrent Compacting Collector ReadyNow! for Low Latency Applications http://www.azulsystems.com/solutions/zing/readynow
  • 3. Zulu® Multi-Platform OpenJDK Cloud Support including Docker and Azure Embedded Support http://zulu.org/
  • 4. GOAL: Understand ArrayList<E>.forEach(Consumer<? super E> action) { for ( int i = 0; i < this.size; i++ ) { action.accept(this.elementData[i]); } } …
  • 6. Actual Implementation ArrayList<E>.forEach(Consumer<? super E> action) { Objects.requireNonNull(action); final int expectedModCount = modCount; final E[] elementData = (E[]) this.elementData; final int size = this.size; for (int i=0; modCount == expectedModCount && i < size; i++) { action.accept(elementData[i]); } if (modCount != expectedModCount) throw new CME(); }
  • 7. The Just-in-Time Compiler is a Compiler, but It’s a… Profile Guided Speculatively Optimizing Compiler
  • 8. So We Need to Understand… Static Optimizations Speculative Optimizations Inter-procedural Analysis Deoptimization How They Fit Together
  • 9. Understand What You Can Rely on OpenJDK’s JIT to do ! REAL GOAL:
  • 11. public class Allocation { static final int CHUNK_SIZE = 1_000; public static void main(String[] args) { for ( int i = 0; i < 500; ++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); } } } S:01A
  • 12. 1 100 10000 0 50 100 150 200 250 300 350 400 450 Warm-Up interpreter 1st JIT 2nd JIT logns
  • 13. -XX:+PrintCompilation 80 29 3 java.util.HashMap::newNode (13 bytes) 81 30 3 java.util.HashMap::afterNodeInsertion 81 31 3 java.lang.String::indexOf (7 bytes) 96 73 % 3 example01a.Allocation::main @ 15 (78 bytes) 101 99 % 4 example01a.Allocation::main @ 15 (78 bytes)
  • 14. ?Two Compilations of One Method? What about Tiers 1 & 2? When Exactly?
  • 15. Thresholds intx Tier2BackEdgeThreshold = 0 {product} intx Tier2CompileThreshold = 0 {product} intx Tier3BackEdgeThreshold = 60000 {product} intx Tier3CompileThreshold = 2000 {product} intx Tier3InvocationThreshold = 200 {product} intx Tier3MinInvocationThreshold = 100 {product} intx Tier4BackEdgeThreshold = 40000 {product} intx Tier4CompileThreshold = 15000 {product} intx Tier4InvocationThreshold = 5000 {product} intx Tier4MinInvocationThreshold = 600 {product} intx BackEdgeThreshold = 100000 {pd product} intx CompileThreshold = 10000 {pd product} Java 7 (Non-tiered) Thresholds Java 8 (Tiered) Thresholds -XX:+PrintFlagsFinal
  • 16. Counters Invocation Counter Backedge (Loop) Counter Backedge Counter > Backedge Threshold Hot Loops Invocation Counter > Invocation Threshold Hot Methods Invocation + Backedge Counter > Compile Threshold Medium Hot Methods with Medium Hot Loops
  • 17. Method or Loop JIT If Loop Count (Backedges) > Threshold, Compile Loop On-Stack Replacement
  • 18. On-Stack Replacement sum ... ... main sum @ 20 ... ... main interpreter frame compiled frame
  • 20. 0 0 0 interpreter 3 4 2 3 4 1 3 c1 c2 none basic counters detailed common c2 busy trivial method Tiered Compilation
  • 21. 0 2 3 4 Made Not Entrant 12394 73 % 3 …Allocation::main @ -2 (78 bytes) made not entrant
  • 23. HotSpot’s Job is to Find Hot Spots Rules for Triggering the JIT Keep Changing HotSpot JITs… Hot Methods Hot Loops Warm Methods with Warm Loops
  • 24. ?What Does the JIT C2 Do? Focus on Final Tier
  • 26. public class AllocationTrap { static final int CHUNK_SIZE = 1_000; public static void main(String[] args) { Object trap = null; for ( int i = 0; i < 500; ++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 == 400 ) trap = new Object(); long endTime = System.nanoTime(); System.out.printf("%dt%d%n", i, endTime - startTime); } } } S:01B
  • 27. 1 100 10000 0 50 100 150 200 250 300 350 400 450 Deoptimization behavioral change, deoptimize! logns
  • 28. Returning to forEach ArrayList<E>.forEach(Consumer<? super E> action) { for ( int i = 0; i < this.size; i++ ) { action.accept(this.elementData[i]); } }
  • 29. Something “Simpler” ArrayStream<E>.forEach(Consumer<? super E> action) { for ( int i = 0; i < this.elementData.length; i++ ) { action.accept(this.elementData[i]); } } “Simpler” Bound
  • 30. Implied Safety Code ArrayStream<E>.forEach(Consumer<? super E> action) { if ( this == null ) throw new NPE(); if ( this.elementData == null ) throw new NPE(); for ( int i = 0; i < this.elementData.length; i++ ) { if ( this == null ) throw new NPE(); if ( this.elementData == null ) throw new NPE(); if ( i < 0 ) throw new AIOBE(); if ( i >= this.elementData.length ) throw new AIOBE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[i]); } }
  • 31. Null Check Elimination ArrayStream<E>.forEach(Consumer<? super E> action) { if ( this == null ) throw new NPE(); if ( this.elementData == null ) throw new NPE(); for ( int i = 0; i < this.elementData.length; i++ ) { if ( this == null ) throw new NPE(); if ( this.elementData == null ) throw new NPE(); if ( i < 0 ) throw new AIOBE(); if ( i >= this.elementData.length ) throw new AIOBE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[i]); } } this != null
  • 32. Lower Bound Check Elimination ArrayStream<E>.forEach(Consumer<? super E> action) { if ( this.elementData == null ) throw new NPE(); for ( int i = 0; i < this.elementData.length; i++ ) { if ( this.elementData == null ) throw new NPE(); if ( i < 0 ) throw new AIOBE(); if ( i >= this.elementData.length ) throw new AIOBE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[i]); } } i >= 0 i <= INT_MAX
  • 33. ArrayStream<E>.forEach(Consumer<? super E> action) { if ( this.elementData == null ) throw new NPE(); for ( int i = 0; i < this.elementData.length; i++ ) { if ( this.elementData == null ) throw new NPE(); if ( i >= this.elementData.length ) throw new AIOBE(); if ( !(i < this.elementData.length) ) throw new AIOBE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[i]); } } Canonicalize Upper Bound Canonicalize
  • 34. ArrayStream<E>.forEach(Consumer<? super E> action) { if ( this.elementData == null ) throw new NPE(); for ( int i = 0; i < this.elementData.length; i++ ) { if ( this.elementData == null ) throw new NPE(); if ( !(i < this.elementData.length) ) throw new AIOBE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[i]); } } Upper Bound Check Elimination Common Sub- Expression * Really GlobalValue Numbering *
  • 35. Cached Length isn’t Better! public class ArrayStream<E> interface Stream<E> { private final E[] elementData; private final int size; public ArrayStream(E… elements) { this.elementData = elements; this.size = elements.length; } forEach(Consumer<? super E> action) { if ( this.elementData == null ) throw new NPE(); for ( int i = 0; i < this.size; i++ ) { if ( this.elementData == null ) throw new NPE(); if ( i >= this.elementData.length ) throw new AIOBE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[i]); } } } mismatch! Confuses the JIT
  • 36. ArrayStream<E>.forEach(Consumer<? super E> action) { if ( this.elementData == null ) throw new NPE(); for ( int i = 0; i < this.elementData.length; i++ ) { if ( this.elementData == null ) throw new NPE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[i]); } } What Else? What Else Can Be Done?
  • 37. ArrayStream<E>.forEach(Consumer<? super E> action) { if ( this.elementData == null ) throw new NPE(); for ( int i = 0; i < this.elementData.length; i++ ) { if ( this.elementData == null ) throw new NPE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[i]); } } Null Pointer Checks Required - cannot optimize further? Assume non-null from above? Required - cannot optimize further?
  • 38. Implicit Null Check if ( this.elementData == null ) throw new NPE(); this.elementData.length; Possible, but improbable SEGVderef value signal handler throw NPE 0x10795f9cc: mov 0x8(%rsi),%r10d ; implicit exception: dispatches to 0x10795fe1d
  • 39. Three Nulls,You Deopt! -XX:+PrintCompilation 121 1 java.lang.String::hashCode (55 bytes) 135 2 …NullCheck::hotMethod (6 bytes) 136 3 % ! …NullCheck::main @ 5 (69 bytes) tempting fate 0 tempting fate 1 tempting fate 2 5144 2 …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 S:02A
  • 40. Stop the World Need to Stop All Java Threads to... Deoptimize Lock Inflation / Deflation Garbage Collect Java Threads read 0x1000 0x1000 SEGV
  • 41. 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 S:02B
  • 42. 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??? S:02B
  • 43. ArrayStream<E>.forEach(Consumer<? super E> action) { if ( this.elementData == null ) throw new NPE(); for ( int i = 0; i < this.elementData.length; i++ ) { if ( this.elementData == null ) throw new NPE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[i]); } } Total Elimination is Better! Assume non-null from above?
  • 44. Common Sub-Expression if ( this.elementData == null ) throw new NPE(); Requires knowing that… null doesn’t change this doesn’t change this.elementData doesn’t change easy hard for ( … ) { if ( this.elementData == null ) throw new NPE(); }
  • 45. The Other “Easy” One LocalVariable: action ArrayStream<E>.forEach(Consumer<? super E> action) { if ( this.elementData == null ) throw new NPE(); for ( int i = 0; i < this.elementData.length; i++ ) { if ( this.elementData == null ) throw new NPE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[i]); } } CANNOT be changed by another thread or method.
  • 46. Loop Peeling ArrayStream<E>.forEach(Consumer<? super E> action) { if ( this.elementData == null ) throw new NPE(); // i=0 iteration if ( 0 < this.elementData.length ) { if ( this.elementData == null ) throw NPE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[0]); } // rest of the iterations for ( int i = 1; i < this.elementData.length; i++ ) { if ( this.elementData == null ) throw new NPE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[i]); } }
  • 47. Back to this.elementData CAN be changed by another thread. Compiler Doesn’t Care! Really? No Synchronization Action - Single Threaded Semantics
  • 48. Loop Invariant Hoisting? ArrayStream<E>.forEach(Consumer<? super E> action) { E[] elementData = this.elementData; int len = elementData.length; if ( elementData == null ) throw new NPE(); // i=0 iteration if ( 0 < len ) { if ( elementData == null ) throw NPE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[0]); } // rest of the iterations for ( int i = 1; i < elementData.length; i++ ) { if ( elementData == null ) throw new NPE(); action.accept(elementData[i]); } }
  • 49. Terrifying! while ( !sharedDone ); print(sharedData); sharedData = …; sharedDone = true; Consumer ThreadProducer Thread Assume sharedData is loop invariant! localDone = sharedDone; while ( !localDone ); print(sharedData);
  • 50. Not So Fast Single Threaded Side Effects ArrayStream<E>.forEach(Consumer<? super E> action) { if ( this.elementData == null ) throw new NPE(); // i=0 iteration if ( 0 < this.elementData.length ) { if ( this.elementData == null ) throw NPE(); if ( action == null ) throw new NPE(); action.accept(this.elementData[0]); } // rest of the iterations for ( int i = 1; i < this.elementData.length; i++ ) { if ( this.elementData == null ) throw new NPE(); action.accept(this.elementData[i]); } } Can this.elementData change? YES
  • 51. ArrayStream NOT ArrayList this.elementData is final! Doesn’t matter - reflection!
  • 52. A Call is a “Black Box” which may contain “Evils”!
  • 53. Inter-procedural Analysis Prove No Side Effects / Evils Inter-procedural Analysis = Inlining
  • 54. Inlining Copy & Paste Callee Into Caller System.out.println(square(9)); inline System.out.println(9 * 9); constant folding System.out.println(81);
  • 55. Start with a Static Call JMH: Java Measurement Harness @Benchmark public void cstyle() { for ( int i = 0; i < this.elementData.length; ++i ) { consume(this.elementData[i]); } } static int sum = 0; @CompilerControl(CompilerControl.Mode.INLINE | DONT_INLINE) static consume(int x) { sum += x; }
  • 56. Benchmark Mode Cnt Score Error Units LoopInvariant.cstyle avgt 10 296.759 ± 3.619 ns/op LoopInvariant.enhanced avgt 10 294.379 ± 7.461 ns/op LoopInvariant.hoisted avgt 10 292.491 ± 7.623 ns/op Inlined Not Inlined Benchmark Mode Cnt Score Error Units LoopInvariant.cstyle avgt 10 2922.285 ± 48.199 ns/op LoopInvariant.enhanced avgt 10 2301.793 ± 37.154 ns/op LoopInvariant.hoisted avgt 10 2325.981 ± 39.935 ns/op benchmarks.LoopInvariant
  • 57. Not Just “Sugar” for ( int x: this.elementData ) { consume(x); } E[] elementData = this.elementData; for ( int i = 0; i < elementData.length; ++i ) { int x = elementData[i]; consume(x); } javac
  • 58. More Terrifying! while ( !sharedDone ) { fn(); } print(sharedData); Consumer Thread Assume sharedData is loop invariant! localDone = sharedDone; while ( !localDone ) { // inlined fn() … } print(sharedData); Producer Thread sharedData = …; sharedDone = true;
  • 59. Inlining Numbers to Remember... -XX:+PrintFlagsFinal MaxTrivialSize 6 MaxInlineSize 35 FreqInlineSize 325 MaxInlineLevel 9 MaxRecursiveInlineLevel 1 MinInliningThreshold 250 Tier1MaxInlineSize 8 Tier1FreqInlineSize 35
  • 60. What About Dynamic Calls? Consumer +apply(Object):Object ConsumerA ConsumerZ100 more http://shipilev.net/blog/2015/black-magic-method-dispatch/ … …
  • 61. Java is a Dynamic Language! Dynamically Loaded Dynamically Linked Lazy Initialized Typically Dynamically Dispatched Even Dynamic Code Gen in JDK
  • 62. Unloaded Class?!? Fields in Class Methods in Class Parent Class Interfaces Anything? …Don’t Know
  • 64. Compile + Deopt Storm 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(); } }
  • 68. Lock Free — but Really Hurts time Deopt + Bail to Interpreter 5x 10-100+x All new calling threads
  • 69. Static Analysis Class Hierarchy Analysis TypeProfile Unique Concrete Method Back to Dynamic/Virtual Calls 4 Strategies to “Devirtualize”
  • 70. 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 S:04A
  • 71. 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); } } Static Analysis S:04A
  • 72. 217 1 java.lang.String::hashCode (55 bytes) 234 3 example03.support.Square::apply (4 bytes) 234 4 % example03a.Monomorphic::main @ 13 (30 bytes) @ 15 example03a.Monomorphic::apply (7 bytes) inline (hot) @ 3 example03.support.Square::apply (4 bytes) inline (hot) 234 2 example03a.Monomorphic::apply (7 bytes) @ 3 example03.support.Square::apply (4 bytes) inline (hot) Monomorphic -XX:+PrintCompilation -XX:-BackgroundCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining
  • 73. public class ChaStorm { public static void main(String[] args) throws… { 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 S:04B
  • 74. Potential for Deopt Storm 152 1 java.lang.String::hashCode (55 bytes) 166 2 example04.support.Square::apply (4 bytes) 173 3 example04b.ChaStorm::apply1 (7 bytes) 173 4 example04b.ChaStorm::apply2 (7 bytes) Waiting for compiler... 174 5 example04b.ChaStorm::apply3 (7 bytes) … 174 9 example04b.ChaStorm::apply7 (7 bytes) 174 10 example04b.ChaStorm::apply8 (7 bytes) Deoptimize... 5176 9 example04b.ChaStorm::apply7 (7 bytes) made not entrant 5176 8 example04b.ChaStorm::apply6 (7 bytes) made not entrant … 5176 4 example04b.ChaStorm::apply2 (7 bytes) made not entrant 5176 3 example04b.ChaStorm::apply1 (7 bytes) made not entrant 5176 10 example04b.ChaStorm::apply8 (7 bytes) made not entrant class example04.support.Sqrt vmop [threads: total initially_running wait_to_block] … 5.096: Deoptimize http://blog.ragozin.info/2012/10/safepoints-in-hotspot-jvm.html [ 7 0 0 ] … -XX:+PrintCompilation -XX+PrintSafepointStatistics -XX:PrintSafepointStatisticsCount=1
  • 75. NOT Lock Free — and Really, Really Hurts new calls bail! returning calls bail! Interpreter C2
  • 77. TypeProfile Interpreter & C1 Gather Data Track Types used at Each Call Site -XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation <klass id='780' name='Square' flags='1'/> <klass id='781' name='Sqrt' flags='1'/> <call method='783' count=‘23161' prof_factor='1' virtual='1' inline='1' receiver='780' receiver_count=‘19901' receiver2='781' receiver2_count='3260'/>
  • 78. Bimorphic Func func = … double result = func.apply(20); func.apply(x); if ( func.getClass().equals(Square.class) ) { … } else { uncommon_trap(class_check); } if ( func.getClass().equals(Square.class) ) { … } else if ( func.getClass().equals(AlsoSquare.class) ) { … } else { uncommon_trap(bimorphic); }
  • 79. Very Effective Call-site specific Works for 90-95% of call sites Very few call sites are “megamorphic” Slightly more overhead than no check (3-5ns)
  • 80. Why Trap?!? if ( func.getClass().equals(Square.class) ) { … } else { uncommon_trap(class_check); } Why not func.apply?
  • 81. Solved? NO ArrayList<E>.forEach(Consumer<? super E> action) { for ( int i = 0; i < this.size; i++ ) { action.accept(this.elementData[i]); } } megamorphic, no (incomplete) inlining. elementData could change! size could change!
  • 82. Unless, Done Manually… ArrayList<E>.forEach(Consumer<? super E> action) { Objects.requireNonNull(action); final int expectedModCount = modCount; final E[] elementData = (E[]) this.elementData; final int size = this.size; for (int i=0; modCount == expectedModCount && i < size; i++) { action.accept(elementData[i]); } if (modCount != expectedModCount) throw new CME(); }
  • 83. Goal Accomplished? NO Handling this.size with an uncommon trap More loop optimizations… Loop Unrolling Loop Unswitching
 Vectorization Interactions with Garbage Collector
  • 84. JIT (and All Compilers) Are Just Complex Pattern Matchers. Don’t Like “Weird” Code Big Methods Mutability Native Methods Like “Normal” Code Small Methods Immutability LocalVariables * except for intrinsics: arraycopy, tan, … *
  • 85. VM Developer Blogs Aleksey Shipilëv http://shipilev.net/ http://psy-lob-saw.blogspot.com/ Nitsan Wakart https://twitter.com/maddocig IgorVeresov