SlideShare a Scribd company logo
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Winning with Java

At Market Open

Getting Fast & Staying Fast

Gil Tene, CTO & co-Founder, Azul Systems
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Are you fast at Market Open?
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java at Market Open
. . .
Market Open
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java’s “Just In Time” Reality
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java’s “Just In Time” Reality
Starts slow, learns fast
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java’s “Just In Time” Reality
Starts slow, learns fast
Lazy loading & initialization
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java’s “Just In Time” Reality
Starts slow, learns fast
Lazy loading & initialization
Aggressively optimized for
the common case
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java’s “Just In Time” Reality
Starts slow, learns fast
Lazy loading & initialization
Aggressively optimized for
the common case
(temporarily) Reverts to
slower execution to adapt
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java’s “Just In Time” Reality
Starts slow, learns fast
Lazy loading & initialization
Aggressively optimized for
the common case
(temporarily) Reverts to
slower execution to adapt
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java’s “Just In Time” Reality
Starts slow, learns fast
Lazy loading & initialization
Aggressively optimized for
the common case
(temporarily) Reverts to
slower execution to adapt
. . .
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java’s “Just In Time” Reality
Starts slow, learns fast
Lazy loading & initialization
Aggressively optimized for
the common case
(temporarily) Reverts to
slower execution to adapt
Warmup
. . .
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java’s “Just In Time” Reality
Starts slow, learns fast
Lazy loading & initialization
Aggressively optimized for
the common case
(temporarily) Reverts to
slower execution to adapt
Warmup
Deoptimization
. . .
Speculative compiler tricks
JIT compilers can do things that
static compilers can have
a hard time with…
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Untaken path example
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Untaken path example
“Never taken” paths can be optimized away with benefits:
void computeMagnitude(int val) {
if (val > 10) {
bias = computeBias(val);
else {
bias = 1;
}
return Math.log10(bias + 99);
}
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Untaken path example
“Never taken” paths can be optimized away with benefits:
void computeMagnitude(int val) {
if (val > 10) {
bias = computeBias(val);
else {
bias = 1;
}
return Math.log10(bias + 99);
}
When all values so far were <= 10 , can be optimized to:
void computeMagnitude(int val) {
if (val > 10) uncommonTrap();
return 2;
}
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Implicit Null Check example
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Implicit Null Check example
All field and array access in Java is null checked
x = foo.x;
is (in equivalent required machine code):
if (foo == null)
throw new NullPointerException();
x = foo.x;
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Implicit Null Check example
All field and array access in Java is null checked
x = foo.x;
is (in equivalent required machine code):
if (foo == null)
throw new NullPointerException();
x = foo.x;
But compiler can “hope” for non-nulls, and handle SEGV
<Point where later SEGV will appear to throw>
x = foo.x;
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Implicit Null Check example
All field and array access in Java is null checked
x = foo.x;
is (in equivalent required machine code):
if (foo == null)
throw new NullPointerException();
x = foo.x;
But compiler can “hope” for non-nulls, and handle SEGV
<Point where later SEGV will appear to throw>
x = foo.x;
This is faster *IF* no nulls are encountered…
Deoptimization
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Deoptimization:

Adaptive compilation is… adaptive
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Deoptimization:

Adaptive compilation is… adaptive
JIT Compilers are adaptive and speculative
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Deoptimization:

Adaptive compilation is… adaptive
JIT Compilers are adaptive and speculative
Leverage observations of behavior
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Deoptimization:

Adaptive compilation is… adaptive
JIT Compilers are adaptive and speculative
Leverage observations of behavior
Can “hope” about things and can recover if wrong
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Deoptimization:

Adaptive compilation is… adaptive
JIT Compilers are adaptive and speculative
Leverage observations of behavior
Can “hope” about things and can recover if wrong
Warming up code is a black art
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Deoptimization:

Adaptive compilation is… adaptive
JIT Compilers are adaptive and speculative
Leverage observations of behavior
Can “hope” about things and can recover if wrong
Warming up code is a black art
Running code long enough to compile is just the start…
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Deoptimization:

Adaptive compilation is… adaptive
JIT Compilers are adaptive and speculative
Leverage observations of behavior
Can “hope” about things and can recover if wrong
Warming up code is a black art
Running code long enough to compile is just the start…
Deoptimization can occur at any time
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Deoptimization:

Adaptive compilation is… adaptive
JIT Compilers are adaptive and speculative
Leverage observations of behavior
Can “hope” about things and can recover if wrong
Warming up code is a black art
Running code long enough to compile is just the start…
Deoptimization can occur at any time
often occur after you *think* the code is warmed up.
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Deoptimization:

Adaptive compilation is… adaptive
JIT Compilers are adaptive and speculative
Leverage observations of behavior
Can “hope” about things and can recover if wrong
Warming up code is a black art
Running code long enough to compile is just the start…
Deoptimization can occur at any time
often occur after you *think* the code is warmed up.
Deoptimization has many potential causes
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Warmup often doesn’t cut it…
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Warmup often doesn’t cut it…
Common Example:

Trading system wants to have the first trade be fast

So run 20,000 “fake” messages through the system to warm up

let JIT compilers optimize, learn, and deopt before actual trades
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Warmup often doesn’t cut it…
Common Example:

Trading system wants to have the first trade be fast

So run 20,000 “fake” messages through the system to warm up

let JIT compilers optimize, learn, and deopt before actual trades
What really happens

Code is written to do different things “if this is a fake message”

e.g. “Don’t send to the exchange if this is a fake message”

JITs optimize for fake path, including speculatively assuming “fake”

First real message through deopts...
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
A few example causes for
depotimization
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
A few example causes for
depotimization

Newly encountered code breaking prior assumptions
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
A few example causes for
depotimization

Newly encountered code breaking prior assumptions
First calls to method in an uninitialized class
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
A few example causes for
depotimization

Newly encountered code breaking prior assumptions
First calls to method in an uninitialized class
First call to a method in a not-yet-loaded class
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
A few example causes for
depotimization

Newly encountered code breaking prior assumptions
First calls to method in an uninitialized class
First call to a method in a not-yet-loaded class
Dynamic branch elimination hitting an unexpected path
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
A few example causes for
depotimization

Newly encountered code breaking prior assumptions
First calls to method in an uninitialized class
First call to a method in a not-yet-loaded class
Dynamic branch elimination hitting an unexpected path
Implicit Null Check hitting a null
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java’s “Just In Time” Reality
Starts slow, learns fast

Lazy loading & initialization

Aggressively optimized for
the common case

(temporarily) Reverts to
slower execution to adapt
Warmup
Deoptimization
. . .
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Starts slow, learns fast

Lazy loading & initialization

Aggressively optimized for
the common case

(temporarily) Reverts to
slower execution to adapt
What we have
Java’s “Just In Time” Reality
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Starts slow, learns fast

Lazy loading & initialization

Aggressively optimized for
the common case

(temporarily) Reverts to
slower execution to adapt
What we have What we want
Java’s “Just In Time” Reality
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Starts slow, learns fast

Lazy loading & initialization

Aggressively optimized for
the common case

(temporarily) Reverts to
slower execution to adapt
What we have What we want
No Slow Ops or Trades
Java’s “Just In Time” Reality
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Starts slow, learns fast

Lazy loading & initialization

Aggressively optimized for
the common case

(temporarily) Reverts to
slower execution to adapt
What we have What we want
No Slow Ops or Trades
ReadyNow!
to the rescue
Java’s “Just In Time” Reality
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
What can we do about it?
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
What can we do about it?
Azul’s Zing JVM has a feature set called “ReadyNow!”

Avoids deoptimization while keeping code fast

Allows code to reach optimized levels without requiring “exercise”
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
What can we do about it?
Azul’s Zing JVM has a feature set called “ReadyNow!”

Avoids deoptimization while keeping code fast

Allows code to reach optimized levels without requiring “exercise”
Learning and retaining optimizations

With Zing, your next run can learn from the previous one
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
What can we do about it?
Azul’s Zing JVM has a feature set called “ReadyNow!”

Avoids deoptimization while keeping code fast

Allows code to reach optimized levels without requiring “exercise”
Learning and retaining optimizations

With Zing, your next run can learn from the previous one
Fine grained control options

Per method compiler directives

…
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Logging & “replaying”optimizations
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Logging & “replaying”optimizations
Zing’s ReadyNow includes optimization logging

Records ongoing optimization decisions and stats

records optimization dependencies

Establishes “stable optimization state” at end of previous run
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Logging & “replaying”optimizations
Zing’s ReadyNow includes optimization logging

Records ongoing optimization decisions and stats

records optimization dependencies

Establishes “stable optimization state” at end of previous run
Zing can then read prior logs at startup

Prime JVM with knowledge of prior stable optimizations 

Optimizations are applied as their dependencies get resolved
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Logging & “replaying”optimizations
Zing’s ReadyNow includes optimization logging

Records ongoing optimization decisions and stats

records optimization dependencies

Establishes “stable optimization state” at end of previous run
Zing can then read prior logs at startup

Prime JVM with knowledge of prior stable optimizations 

Optimizations are applied as their dependencies get resolved
ReadyNow workflow promotes confidence

You’ll know if/when all optimizations have been applied

If some optimization haven’t been applied, you’ll know why…
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java at “Load Start”
. . .
Load Start
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java at “Load Start”
. . .
Load Start
Deoptimization
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java at “Load Start”
. . .
Load Start
Deoptimization
ReadyNow!
avoids
deoptimization
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java at “Load Start”
. . .
Load Start
With Zing & ReadyNow!
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java at “Load Start”
. . .
Load Start
With ReadyNow!
Warmup?
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java at “Load Start”
. . .
Load Start
With ReadyNow!
Warmup?
Fast From
The Start
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
. . .
Load Start
With ReadyNow! and
Start Fast & Stay Fast
Java at “Load Start”
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
. . .
Load Start
With Zing & ReadyNow!
Start Fast & Stay Fast
Java at “Load Start”
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
. . .
Load Start
With Zing & ReadyNow!
Start Fast & Stay Fast
Java at “Load Start”
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
. . .
Load Start
With Zing & ReadyNow!
Start Fast & Stay Fast
Java at “Load Start”
With
Confidence
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
One liner takeaway
. . .
Load Start
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
One liner takeaway
. . .
Zing: A cure for the Java hiccups
Load Start

More Related Content

PDF
Intelligent Trading Summit NY 2014: Understanding Latency: Key Lessons and Tools
PDF
DotCMS Bootcamp: Enabling Java in Latency Sensitivie Environments
PDF
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
PPTX
In what way does your media product use , develop or challenge forms and conv...
DOCX
PPTX
Enabling Java in Latency Sensitive Environments - Dallas JUG April 2015
PDF
BRAF mand CDKN2A deletion define a clinically distinct subgroup of childhood ...
DOC
Installation manual
Intelligent Trading Summit NY 2014: Understanding Latency: Key Lessons and Tools
DotCMS Bootcamp: Enabling Java in Latency Sensitivie Environments
OSGi Enterprise R6 specs are out! - David Bosschaert & Carsten Ziegeler
In what way does your media product use , develop or challenge forms and conv...
Enabling Java in Latency Sensitive Environments - Dallas JUG April 2015
BRAF mand CDKN2A deletion define a clinically distinct subgroup of childhood ...
Installation manual

Viewers also liked (11)

PPTX
bilogi annelida
PDF
Making Business Happen, Greater Birmingham
PDF
JVM Language Summit: Object layout presentation
PPTX
Git 들여다보기(1)
DOC
Chuyệ
PDF
Axx oms backup procedure remotely
PPTX
5 VARIABLES in MANUFACTURING PRODN
PDF
Portfolio
PPTX
La informática en el periodismo
PDF
CURRICULUM_VITAE.PDF
bilogi annelida
Making Business Happen, Greater Birmingham
JVM Language Summit: Object layout presentation
Git 들여다보기(1)
Chuyệ
Axx oms backup procedure remotely
5 VARIABLES in MANUFACTURING PRODN
Portfolio
La informática en el periodismo
CURRICULUM_VITAE.PDF
Ad

Similar to Winning With Java at Market Open (20)

PPTX
Start Fast and Stay Fast - Priming Java for Market Open with ReadyNow!
PDF
Enabling Java in Latency Sensitive Applications by Gil Tene, CTO, Azul Systems
PDF
Enabling Java in Latency-Sensitive Applications
PDF
JVM Mechanics: A Peek Under the Hood
PDF
How NOT to Measure Latency, Gil Tene, London, Oct. 2013
PDF
Priming Java for Speed at Market Open
PDF
Azul Zulu on Azure Overview -- OpenTech CEE Workshop, Warsaw, Poland
PPTX
AWS Summit Melbourne 2014 | The Path to Business Agility for Vodafone: How Am...
PDF
Understanding Hardware Transactional Memory
PDF
DevOps - Chaos Engineering on Kubernetes
PDF
Just-in-time Java EE - provisioning runtimes for enterprise applications - Ja...
PDF
Are Your Test Cases Fit For Automation?
PDF
AI Intelligence: Exploring the Future of Artificial Intelligence
PDF
Understanding Latency Response Time and Behavior
PDF
Integration Testing in AEM
PDF
Tales About Scala Performance
PDF
QCon London: Low latency Java in the real world - LMAX Exchange and the Zing JVM
PDF
Lynn cisco IOS Exploit Presentation
PDF
Enabling Java in Latency Sensitive Environments
PPTX
Why is Infrastructure-as-Code essential in the Cloud Age?
Start Fast and Stay Fast - Priming Java for Market Open with ReadyNow!
Enabling Java in Latency Sensitive Applications by Gil Tene, CTO, Azul Systems
Enabling Java in Latency-Sensitive Applications
JVM Mechanics: A Peek Under the Hood
How NOT to Measure Latency, Gil Tene, London, Oct. 2013
Priming Java for Speed at Market Open
Azul Zulu on Azure Overview -- OpenTech CEE Workshop, Warsaw, Poland
AWS Summit Melbourne 2014 | The Path to Business Agility for Vodafone: How Am...
Understanding Hardware Transactional Memory
DevOps - Chaos Engineering on Kubernetes
Just-in-time Java EE - provisioning runtimes for enterprise applications - Ja...
Are Your Test Cases Fit For Automation?
AI Intelligence: Exploring the Future of Artificial Intelligence
Understanding Latency Response Time and Behavior
Integration Testing in AEM
Tales About Scala Performance
QCon London: Low latency Java in the real world - LMAX Exchange and the Zing JVM
Lynn cisco IOS Exploit Presentation
Enabling Java in Latency Sensitive Environments
Why is Infrastructure-as-Code essential in the Cloud Age?
Ad

More from Azul Systems, Inc. (7)

PDF
Unleash the Power of Apache Cassandra
PDF
How NOT to Measure Latency
PPTX
Enabling Java in Latency-Sensitive Environments - Austin JUG April 2015
PDF
JVM Language Summit: Object layout workshop
PDF
What's New in the JVM in Java 8?
PDF
DC JUG: Understanding Java Garbage Collection
PDF
Silicon Valley JUG: JVM Mechanics
Unleash the Power of Apache Cassandra
How NOT to Measure Latency
Enabling Java in Latency-Sensitive Environments - Austin JUG April 2015
JVM Language Summit: Object layout workshop
What's New in the JVM in Java 8?
DC JUG: Understanding Java Garbage Collection
Silicon Valley JUG: JVM Mechanics

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation theory and applications.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
cuic standard and advanced reporting.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
DOCX
The AUB Centre for AI in Media Proposal.docx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
A Presentation on Artificial Intelligence
PPTX
Cloud computing and distributed systems.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation theory and applications.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Electronic commerce courselecture one. Pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectral efficient network and resource selection model in 5G networks
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
The AUB Centre for AI in Media Proposal.docx
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
A Presentation on Artificial Intelligence
Cloud computing and distributed systems.
20250228 LYD VKU AI Blended-Learning.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

Winning With Java at Market Open

  • 1. ©2013 Azul Systems, Inc. Winning with Java At Market Open Getting Fast & Staying Fast Gil Tene, CTO & co-Founder, Azul Systems
  • 2. ©2013 Azul Systems, Inc. Are you fast at Market Open?
  • 3. ©2013 Azul Systems, Inc. Java at Market Open . . . Market Open
  • 4. ©2013 Azul Systems, Inc. Java’s “Just In Time” Reality
  • 5. ©2013 Azul Systems, Inc. Java’s “Just In Time” Reality Starts slow, learns fast
  • 6. ©2013 Azul Systems, Inc. Java’s “Just In Time” Reality Starts slow, learns fast Lazy loading & initialization
  • 7. ©2013 Azul Systems, Inc. Java’s “Just In Time” Reality Starts slow, learns fast Lazy loading & initialization Aggressively optimized for the common case
  • 8. ©2013 Azul Systems, Inc. Java’s “Just In Time” Reality Starts slow, learns fast Lazy loading & initialization Aggressively optimized for the common case (temporarily) Reverts to slower execution to adapt
  • 9. ©2013 Azul Systems, Inc. Java’s “Just In Time” Reality Starts slow, learns fast Lazy loading & initialization Aggressively optimized for the common case (temporarily) Reverts to slower execution to adapt
  • 10. ©2013 Azul Systems, Inc. Java’s “Just In Time” Reality Starts slow, learns fast Lazy loading & initialization Aggressively optimized for the common case (temporarily) Reverts to slower execution to adapt . . .
  • 11. ©2013 Azul Systems, Inc. Java’s “Just In Time” Reality Starts slow, learns fast Lazy loading & initialization Aggressively optimized for the common case (temporarily) Reverts to slower execution to adapt Warmup . . .
  • 12. ©2013 Azul Systems, Inc. Java’s “Just In Time” Reality Starts slow, learns fast Lazy loading & initialization Aggressively optimized for the common case (temporarily) Reverts to slower execution to adapt Warmup Deoptimization . . .
  • 13. Speculative compiler tricks JIT compilers can do things that static compilers can have a hard time with…
  • 14. ©2012 Azul Systems, Inc. Untaken path example
  • 15. ©2012 Azul Systems, Inc. Untaken path example “Never taken” paths can be optimized away with benefits: void computeMagnitude(int val) { if (val > 10) { bias = computeBias(val); else { bias = 1; } return Math.log10(bias + 99); }
  • 16. ©2012 Azul Systems, Inc. Untaken path example “Never taken” paths can be optimized away with benefits: void computeMagnitude(int val) { if (val > 10) { bias = computeBias(val); else { bias = 1; } return Math.log10(bias + 99); } When all values so far were <= 10 , can be optimized to: void computeMagnitude(int val) { if (val > 10) uncommonTrap(); return 2; }
  • 17. ©2012 Azul Systems, Inc. Implicit Null Check example
  • 18. ©2012 Azul Systems, Inc. Implicit Null Check example All field and array access in Java is null checked x = foo.x; is (in equivalent required machine code): if (foo == null) throw new NullPointerException(); x = foo.x;
  • 19. ©2012 Azul Systems, Inc. Implicit Null Check example All field and array access in Java is null checked x = foo.x; is (in equivalent required machine code): if (foo == null) throw new NullPointerException(); x = foo.x; But compiler can “hope” for non-nulls, and handle SEGV <Point where later SEGV will appear to throw> x = foo.x;
  • 20. ©2012 Azul Systems, Inc. Implicit Null Check example All field and array access in Java is null checked x = foo.x; is (in equivalent required machine code): if (foo == null) throw new NullPointerException(); x = foo.x; But compiler can “hope” for non-nulls, and handle SEGV <Point where later SEGV will appear to throw> x = foo.x; This is faster *IF* no nulls are encountered…
  • 22. ©2012 Azul Systems, Inc. Deoptimization: Adaptive compilation is… adaptive
  • 23. ©2012 Azul Systems, Inc. Deoptimization: Adaptive compilation is… adaptive JIT Compilers are adaptive and speculative
  • 24. ©2012 Azul Systems, Inc. Deoptimization: Adaptive compilation is… adaptive JIT Compilers are adaptive and speculative Leverage observations of behavior
  • 25. ©2012 Azul Systems, Inc. Deoptimization: Adaptive compilation is… adaptive JIT Compilers are adaptive and speculative Leverage observations of behavior Can “hope” about things and can recover if wrong
  • 26. ©2012 Azul Systems, Inc. Deoptimization: Adaptive compilation is… adaptive JIT Compilers are adaptive and speculative Leverage observations of behavior Can “hope” about things and can recover if wrong Warming up code is a black art
  • 27. ©2012 Azul Systems, Inc. Deoptimization: Adaptive compilation is… adaptive JIT Compilers are adaptive and speculative Leverage observations of behavior Can “hope” about things and can recover if wrong Warming up code is a black art Running code long enough to compile is just the start…
  • 28. ©2012 Azul Systems, Inc. Deoptimization: Adaptive compilation is… adaptive JIT Compilers are adaptive and speculative Leverage observations of behavior Can “hope” about things and can recover if wrong Warming up code is a black art Running code long enough to compile is just the start… Deoptimization can occur at any time
  • 29. ©2012 Azul Systems, Inc. Deoptimization: Adaptive compilation is… adaptive JIT Compilers are adaptive and speculative Leverage observations of behavior Can “hope” about things and can recover if wrong Warming up code is a black art Running code long enough to compile is just the start… Deoptimization can occur at any time often occur after you *think* the code is warmed up.
  • 30. ©2012 Azul Systems, Inc. Deoptimization: Adaptive compilation is… adaptive JIT Compilers are adaptive and speculative Leverage observations of behavior Can “hope” about things and can recover if wrong Warming up code is a black art Running code long enough to compile is just the start… Deoptimization can occur at any time often occur after you *think* the code is warmed up. Deoptimization has many potential causes
  • 31. ©2012 Azul Systems, Inc. Warmup often doesn’t cut it…
  • 32. ©2012 Azul Systems, Inc. Warmup often doesn’t cut it… Common Example: Trading system wants to have the first trade be fast So run 20,000 “fake” messages through the system to warm up let JIT compilers optimize, learn, and deopt before actual trades
  • 33. ©2012 Azul Systems, Inc. Warmup often doesn’t cut it… Common Example: Trading system wants to have the first trade be fast So run 20,000 “fake” messages through the system to warm up let JIT compilers optimize, learn, and deopt before actual trades What really happens Code is written to do different things “if this is a fake message” e.g. “Don’t send to the exchange if this is a fake message” JITs optimize for fake path, including speculatively assuming “fake” First real message through deopts...
  • 34. ©2012 Azul Systems, Inc. A few example causes for depotimization
  • 35. ©2012 Azul Systems, Inc. A few example causes for depotimization Newly encountered code breaking prior assumptions
  • 36. ©2012 Azul Systems, Inc. A few example causes for depotimization Newly encountered code breaking prior assumptions First calls to method in an uninitialized class
  • 37. ©2012 Azul Systems, Inc. A few example causes for depotimization Newly encountered code breaking prior assumptions First calls to method in an uninitialized class First call to a method in a not-yet-loaded class
  • 38. ©2012 Azul Systems, Inc. A few example causes for depotimization Newly encountered code breaking prior assumptions First calls to method in an uninitialized class First call to a method in a not-yet-loaded class Dynamic branch elimination hitting an unexpected path
  • 39. ©2012 Azul Systems, Inc. A few example causes for depotimization Newly encountered code breaking prior assumptions First calls to method in an uninitialized class First call to a method in a not-yet-loaded class Dynamic branch elimination hitting an unexpected path Implicit Null Check hitting a null
  • 40. ©2013 Azul Systems, Inc. Java’s “Just In Time” Reality Starts slow, learns fast Lazy loading & initialization Aggressively optimized for the common case (temporarily) Reverts to slower execution to adapt Warmup Deoptimization . . .
  • 41. ©2013 Azul Systems, Inc. Starts slow, learns fast Lazy loading & initialization Aggressively optimized for the common case (temporarily) Reverts to slower execution to adapt What we have Java’s “Just In Time” Reality
  • 42. ©2013 Azul Systems, Inc. Starts slow, learns fast Lazy loading & initialization Aggressively optimized for the common case (temporarily) Reverts to slower execution to adapt What we have What we want Java’s “Just In Time” Reality
  • 43. ©2013 Azul Systems, Inc. Starts slow, learns fast Lazy loading & initialization Aggressively optimized for the common case (temporarily) Reverts to slower execution to adapt What we have What we want No Slow Ops or Trades Java’s “Just In Time” Reality
  • 44. ©2013 Azul Systems, Inc. Starts slow, learns fast Lazy loading & initialization Aggressively optimized for the common case (temporarily) Reverts to slower execution to adapt What we have What we want No Slow Ops or Trades ReadyNow! to the rescue Java’s “Just In Time” Reality
  • 45. ©2012 Azul Systems, Inc. What can we do about it?
  • 46. ©2012 Azul Systems, Inc. What can we do about it? Azul’s Zing JVM has a feature set called “ReadyNow!” Avoids deoptimization while keeping code fast Allows code to reach optimized levels without requiring “exercise”
  • 47. ©2012 Azul Systems, Inc. What can we do about it? Azul’s Zing JVM has a feature set called “ReadyNow!” Avoids deoptimization while keeping code fast Allows code to reach optimized levels without requiring “exercise” Learning and retaining optimizations With Zing, your next run can learn from the previous one
  • 48. ©2012 Azul Systems, Inc. What can we do about it? Azul’s Zing JVM has a feature set called “ReadyNow!” Avoids deoptimization while keeping code fast Allows code to reach optimized levels without requiring “exercise” Learning and retaining optimizations With Zing, your next run can learn from the previous one Fine grained control options Per method compiler directives …
  • 49. ©2012 Azul Systems, Inc. Logging & “replaying”optimizations
  • 50. ©2012 Azul Systems, Inc. Logging & “replaying”optimizations Zing’s ReadyNow includes optimization logging Records ongoing optimization decisions and stats records optimization dependencies Establishes “stable optimization state” at end of previous run
  • 51. ©2012 Azul Systems, Inc. Logging & “replaying”optimizations Zing’s ReadyNow includes optimization logging Records ongoing optimization decisions and stats records optimization dependencies Establishes “stable optimization state” at end of previous run Zing can then read prior logs at startup Prime JVM with knowledge of prior stable optimizations Optimizations are applied as their dependencies get resolved
  • 52. ©2012 Azul Systems, Inc. Logging & “replaying”optimizations Zing’s ReadyNow includes optimization logging Records ongoing optimization decisions and stats records optimization dependencies Establishes “stable optimization state” at end of previous run Zing can then read prior logs at startup Prime JVM with knowledge of prior stable optimizations Optimizations are applied as their dependencies get resolved ReadyNow workflow promotes confidence You’ll know if/when all optimizations have been applied If some optimization haven’t been applied, you’ll know why…
  • 53. ©2013 Azul Systems, Inc. Java at “Load Start” . . . Load Start
  • 54. ©2013 Azul Systems, Inc. Java at “Load Start” . . . Load Start Deoptimization
  • 55. ©2013 Azul Systems, Inc. Java at “Load Start” . . . Load Start Deoptimization ReadyNow! avoids deoptimization
  • 56. ©2013 Azul Systems, Inc. Java at “Load Start” . . . Load Start With Zing & ReadyNow!
  • 57. ©2013 Azul Systems, Inc. Java at “Load Start” . . . Load Start With ReadyNow! Warmup?
  • 58. ©2013 Azul Systems, Inc. Java at “Load Start” . . . Load Start With ReadyNow! Warmup? Fast From The Start
  • 59. ©2013 Azul Systems, Inc. . . . Load Start With ReadyNow! and Start Fast & Stay Fast Java at “Load Start”
  • 60. ©2013 Azul Systems, Inc. . . . Load Start With Zing & ReadyNow! Start Fast & Stay Fast Java at “Load Start”
  • 61. ©2013 Azul Systems, Inc. . . . Load Start With Zing & ReadyNow! Start Fast & Stay Fast Java at “Load Start”
  • 62. ©2013 Azul Systems, Inc. . . . Load Start With Zing & ReadyNow! Start Fast & Stay Fast Java at “Load Start” With Confidence
  • 63. ©2013 Azul Systems, Inc. One liner takeaway . . . Load Start
  • 64. ©2013 Azul Systems, Inc. One liner takeaway . . . Zing: A cure for the Java hiccups Load Start