SlideShare una empresa de Scribd logo
1 de 44
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Priming Java

for Speed at Market Open

!
Getting Fast & Staying Fast

Gil Tene, CTO & co-Founder, Azul Systems
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
http://www.infoq.com/presentations
/jvm-dynamic-optimizations
Presented at QCon New York
www.qconnewyork.com
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
High level agenda
Intro

Java realities at Market Open

A whole bunch of compiler optimization stuff

Deoptimization…

What we can do about it
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
About me: Gil Tene
co-founder, CTO @Azul
Systems

Have been working on “think
different” GC approaches
since 2002

At Azul we make JVMs that
dramatically improve latency
behavior

As a result, we end up
working a lot with low latency
trading systems

And (after GC is solved) the
Market Open problem seems
to dominate concerns * working on real-world trash compaction issues, circa 2004
©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
Starts slow, learns fast

Lazy loading & initialization

Aggressively optimized for
the common case

(temporarily) Reverts to
slower execution to adapt
Warmup
Deoptimization
. . .
Compiler Stuff
Some simple compiler tricks
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Code can be reordered...
int doMath(int x, int y, int z) {

int a = x + y;

int b = x - y;

int c = z + x;

return a + b;

}

Can be reordered to:

int doMath(int x, int y, int z) {

int c = z + x;

int b = x - y;

int a = x + y;

return a + b;

}
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Dead code can be removed
int doMath(int x, int y, int z) {

int a = x + y;

int b = x - y;

int c = z + x;

return a + b;

}

!
Can be reduced to:

!
int doMath(int x, int y, int z) {

int a = x + y;

int b = x - y;

return a + b;

}
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Values can be propagated
int doMath(int x, int y, int z) {

int a = x + y;

int b = x - y;

int c = z + x;

return a + b;

}

!
Can be reduced to:

!
int doMath(int x, int y, int z) {

return x + y + x - y;

}

!
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Math can be simplified
int doMath(int x, int y, int z) {

int a = x + y;

int b = x - y;

int c = z + x;

return a + b;

}

!
Can be reduced to:

!
int doMath(int x, int y, int z) {

return x + x;

}

!
Some more compiler tricks
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Reads can be cached
int distanceRatio(Object a) {

int distanceTo = a.getX() - start;

int distanceAfter = end - a.getX();

return distanceTo/distanceAfter;

}

Is the same as

int distanceRatio(Object a) {

int x = a.getX(); 

int distanceTo = x - start; 

int distanceAfter = end - x;

return distanceTo/distanceAfter;

}
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Reads can be cached
void loopUntilFlagSet(Object a) {

while (!a.flagIsSet()) {

loopcount++;

}

}

Is the same as:

void loopUntilFlagSet(Object a) {

boolean flagIsSet = a.flagIsSet();

while (!flagIsSet) {

loopcount++;

}

}

!
That’s what volatile is for...
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Writes can be eliminated
Intermediate values might never be visible

void updateDistance(Object a) {

int distance = 100;

a.setX(distance);

a.setX(distance * 2);

a.setX(distance * 3);

}

Is the same as

void updateDistance(Object a) {

a.setX(300);

}
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Writes can be eliminated
Intermediate values might never be visible

void updateDistance(Object a) {

a. setVisibleValue(0);

for (int i = 0; i < 1000000; i++) {

a.setInternalValue(i);

}

a.setVisibleValue(a.getInternalValue());

}

Is the same as

void updateDistance(Object a) {

a.setInternalValue(1000000);

a.setVisibleValue(1000000);

}
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Inlining...
public class Thing {

private int x;

public final int getX() { return x };

}

...

myX = thing.getX();

Is the same as

Class Thing {

int x;

}

...

myX = thing.x;
Speculative compiler tricks
JIT compilers can do things that
static compilers can have
a hard time with…
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Class Hierarchy Analysis (CHA)
Can perform global analysis on currently loaded code

Deduce stuff about inheritance, method overrides, etc.

Can make optimization decisions based on assumptions

Re-evaluate assumptions when loading new classes

Throw away code that conflicts with assumptions
before class loading makes them invalid
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Inlining works without “final”
public class Thing {

private int x;

public int getX() { return x };

}

...

myX = thing.getX();

Is the same as

Class Thing {

int x;

}

...

myX = thing.x;

As long as there is only one implementer of getX()
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
The power of the “uncommon trap”

Being able throw away wrong code is very useful

E.g. Speculatively assuming callee type

polymorphic can be “monomorphic” or “megamorphic”

E.g. Can make virtual calls direct even without CHA

E.g. Can speculatively inline things

E.g. Speculatively assuming branch behavior

We’ve only ever seen this thing go one way, so....
More Speculative stuff
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Untaken path example
“Never taken” paths can be optimized away with benefits:

void computeMagnitude(int val) {

if (val > 10) {

scale = computeScale(val);

else {

scale = 1;

}

return scale + 9;

}

When all values so far were <= 10 can be compiled to:

void computeMagnitude(int val) {

if (val > 10) uncommonTrap();

return 10;

}
©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
Micro-benchmarking is a black art

So is the art of the Warmup

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.

Many potential causes
©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.	
 	
 	
 	
 	
 	
Fun In a Box:

A simple Deoptimization example
Deoptimization due to lazy loading/initialization

Two classes: ThingOne and ThingTwo

Both are actively called in the same method

But compiler kicks in before one is ever called

JIT cannot generate call for uninitialized class

So it leaves an uncommon trap on that path…

And deopts later if it ever gets there.
https://github.com/giltene/GilExamples/blob/master/src/main/java/FunInABox.java
public	
  class	
  FunInABox	
  {	
  
	
  	
  	
  	
  static	
  final	
  int	
  THING_ONE_THREASHOLD	
  =	
  20000000	
  
	
  	
  	
  	
  .	
  
	
  	
  	
  	
  .	
  
	
  	
  	
  	
  .	
  	
  	
  	
  	
  
	
  	
  	
  	
  static	
  public	
  class	
  ThingOne	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  static	
  long	
  valueOne	
  =	
  0;	
  
!
	
  	
  	
  	
  	
  	
  	
  	
  static	
  long	
  getValue()	
  {	
  return	
  valueOne++;	
  }	
  
	
  	
  	
  	
  }	
  
!
	
  	
  	
  	
  static	
  public	
  class	
  ThingTwo	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  static	
  long	
  valueTwo	
  =	
  3;	
  
!
	
  	
  	
  	
  	
  	
  	
  	
  static	
  long	
  getValue()	
  {	
  return	
  valueTwo++;	
  }	
  
	
  	
  	
  	
  }	
  
!
	
  	
  	
  	
  public	
  static	
  long	
  testRun(int	
  iterations)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  long	
  sum	
  =	
  0;	
  
!
	
  	
  	
  	
  	
  	
  	
  	
  for(int	
  iter	
  =	
  0;	
  iter	
  <	
  iterations;	
  iter++)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  if	
  (iter	
  >	
  THING_ONE_THREASHOLD)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  sum	
  +=	
  ThingOne.getValue();	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  else	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  sum	
  +=	
  ThingTwo.getValue();	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  sum;	
  
	
  	
  	
  	
  }
Deopt example: Fun In a Box
Lumpy.local-40% !
Lumpy.local-40% java -XX:+PrintCompilation FunInABox
77 1 java.lang.String::hashCode (64 bytes)!
109 2 sun.nio.cs.UTF_8$Decoder::decodeArrayLoop (553 bytes)!
115 3 java.math.BigInteger::mulAdd (81 bytes)!
118 4 java.math.BigInteger::multiplyToLen (219 bytes)!
121 5 java.math.BigInteger::addOne (77 bytes)!
123 6 java.math.BigInteger::squareToLen (172 bytes)!
127 7 java.math.BigInteger::primitiveLeftShift (79 bytes)!
130 8 java.math.BigInteger::montReduce (99 bytes)!
140 1% java.math.BigInteger::multiplyToLen @ 138 (219 bytes)!
Starting warmup run (will only use ThingTwo):!
147 9 sun.security.provider.SHA::implCompress (491 bytes)!
153 10 java.lang.String::charAt (33 bytes)!
154 11 FunInABox$ThingTwo::getValue (10 bytes)!
154 2% FunInABox::testRun @ 4 (38 bytes)!
161 12 FunInABox::testRun (38 bytes)!
Warmup run [1000000 iterations] took 27 msec..!
!
...Then, out of the box!
Came Thing Two and Thing One!!
And they ran to us fast!
They said, "How do you do?"...!
!
Starting actual run (will start using ThingOne a bit after using
ThingTwo):!
5183 12 made not entrant FunInABox::testRun (38 bytes)!
5184 2% made not entrant FunInABox::testRun @ -2 (38 bytes)!
5184 3% FunInABox::testRun @ 4 (38 bytes)!
5184 13 FunInABox$ThingOne::getValue (10 bytes)!
Test run [200000000 iterations] took 1299 msec...
Deopt example: Fun In a Box
 	
  	
  	
  .	
  
	
  	
  	
  	
  .	
  
	
  	
  	
  	
  .	
  
	
  	
  	
  	
  public	
  static	
  <T>	
  Class<T>	
  forceInit(Class<T>	
  klass)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  //	
  Forces	
  actual	
  initialization	
  (not	
  just	
  loading)	
  of	
  the	
  class	
  klass:	
  
	
  	
  	
  	
  	
  	
  	
  	
  try	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Class.forName(klass.getName(),	
  true,	
  klass.getClassLoader());	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  catch	
  (ClassNotFoundException	
  e)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  throw	
  new	
  AssertionError(e);	
  	
  //	
  Can't	
  happen	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  klass;	
  
	
  	
  	
  	
  }	
  
!
	
  	
  	
  	
  public	
  static	
  void	
  tameTheThings()	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  forceInit(ThingOne.class);	
  
	
  	
  	
  	
  	
  	
  	
  	
  forceInit(ThingTwo.class);	
  
	
  	
  	
  	
  }	
  
	
  	
  	
  	
  .	
  
	
  	
  	
  	
  .	
  
	
  	
  	
  	
  .
Deopt example: Fun In a Box
https://github.com/giltene/GilExamples/blob/master/src/main/java/FunInABox.java
Lumpy.local-41% !
Lumpy.local-41% java -XX:+PrintCompilation FunInABox KeepThingsTame!
75 1 java.lang.String::hashCode (64 bytes)!
107 2 sun.nio.cs.UTF_8$Decoder::decodeArrayLoop (553 bytes)!
113 3 java.math.BigInteger::mulAdd (81 bytes)!
115 4 java.math.BigInteger::multiplyToLen (219 bytes)!
119 5 java.math.BigInteger::addOne (77 bytes)!
121 6 java.math.BigInteger::squareToLen (172 bytes)!
125 7 java.math.BigInteger::primitiveLeftShift (79 bytes)!
127 8 java.math.BigInteger::montReduce (99 bytes)!
133 1% java.math.BigInteger::multiplyToLen @ 138 (219 bytes)!
Keeping ThingOne and ThingTwo tame (by initializing them ahead of time):!
Starting warmup run (will only use ThingTwo):!
140 9 sun.security.provider.SHA::implCompress (491 bytes)!
147 10 java.lang.String::charAt (33 bytes)!
147 11 FunInABox$ThingTwo::getValue (10 bytes)!
147 2% FunInABox::testRun @ 4 (38 bytes)!
154 12 FunInABox::testRun (38 bytes)!
Warmup run [1000000 iterations] took 24 msec..!
!
...Then, out of the box!
Came Thing Two and Thing One!!
And they ran to us fast!
They said, "How do you do?"...!
!
Starting actual run (will start using ThingOne a bit after using
ThingTwo):!
5178 13 FunInABox$ThingOne::getValue (10 bytes)!
Test run [200000000 iterations] took 2164 msec...
Deopt example: Fun In a Box
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Example causes for depotimization

at Market Open
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 What we want
No Slow Trades
ReadyNow!
to the rescue
Java’s “Just In Time” Reality
©2012 Azul Systems, Inc.	
 	
 	
 	
 	
 	
What can we do about it?
Zing has a new feature set called “ReadyNow!”

Focused on avoiding deoptimization while keeping code fast

First of all, paying attention matters

E.g. Some of those dynamic branch eliminations have no benefit…

Adds optional controls for helpful things like:

Aggressive class loading (load when they come into scope)

Safe pre-initialization of classes with empty static initializers

Per method compiler directives (e.g. disable ImplicitNullChecks)

…

The feature set keep growing…
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java at Market Open
. . .
Market Open
Deoptimization
ReadyNow!
avoids
deoptimization
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java at Market Open
. . .
Market Open
With Zing & ReadyNow!
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
Java at Market Open
. . .
Market Open
With ReadyNow!
Warmup?
Avoids
Restarts
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
. . .
Market Open
With ReadyNow! and
No Overnight Restarts
!
Start Fast & Stay Fast
Java at Market Open
©2013 Azul Systems, Inc.	
 	
 	
 	
 	
 	
One liner takeaway
. . .
Zing: A cure for the Java hiccups
Market Open
Watch the video with slide synchronization on
InfoQ.com!
http://www.infoq.com/presentations/jvm-
dynamic-optimizations

Más contenido relacionado

Más de C4Media

Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideC4Media
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDC4Media
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine LearningC4Media
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at SpeedC4Media
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsC4Media
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsC4Media
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleC4Media
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeC4Media
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereC4Media
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing ForC4Media
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data EngineeringC4Media
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreC4Media
 
Navigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsNavigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsC4Media
 
High Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechHigh Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechC4Media
 
Rust's Journey to Async/await
Rust's Journey to Async/awaitRust's Journey to Async/await
Rust's Journey to Async/awaitC4Media
 
Opportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven UtopiaOpportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven UtopiaC4Media
 
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/DayDatadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/DayC4Media
 
Are We Really Cloud-Native?
Are We Really Cloud-Native?Are We Really Cloud-Native?
Are We Really Cloud-Native?C4Media
 
CockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL DatabaseCockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL DatabaseC4Media
 

Más de C4Media (20)

Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate Guide
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 
Navigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsNavigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery Teams
 
High Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechHigh Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in Adtech
 
Rust's Journey to Async/await
Rust's Journey to Async/awaitRust's Journey to Async/await
Rust's Journey to Async/await
 
Opportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven UtopiaOpportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven Utopia
 
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/DayDatadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
 
Are We Really Cloud-Native?
Are We Really Cloud-Native?Are We Really Cloud-Native?
Are We Really Cloud-Native?
 
CockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL DatabaseCockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL Database
 

Último

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 

Último (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

Priming Java for Speed at Market Open

  • 1. ©2013 Azul Systems, Inc. Priming Java for Speed at Market Open ! Getting Fast & Staying Fast Gil Tene, CTO & co-Founder, Azul Systems
  • 2. InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /jvm-dynamic-optimizations
  • 3. Presented at QCon New York www.qconnewyork.com Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide
  • 4. ©2012 Azul Systems, Inc. High level agenda Intro Java realities at Market Open A whole bunch of compiler optimization stuff Deoptimization… What we can do about it
  • 5. ©2013 Azul Systems, Inc. ©2013 Azul Systems, Inc. About me: Gil Tene co-founder, CTO @Azul Systems Have been working on “think different” GC approaches since 2002 At Azul we make JVMs that dramatically improve latency behavior As a result, we end up working a lot with low latency trading systems And (after GC is solved) the Market Open problem seems to dominate concerns * working on real-world trash compaction issues, circa 2004
  • 6. ©2013 Azul Systems, Inc. Are you fast at Market Open?
  • 7. ©2013 Azul Systems, Inc. Java at Market Open . . . Market Open
  • 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 Warmup Deoptimization . . .
  • 11. ©2012 Azul Systems, Inc. Code can be reordered... int doMath(int x, int y, int z) { int a = x + y; int b = x - y; int c = z + x; return a + b; } Can be reordered to: int doMath(int x, int y, int z) { int c = z + x; int b = x - y; int a = x + y; return a + b; }
  • 12. ©2012 Azul Systems, Inc. Dead code can be removed int doMath(int x, int y, int z) { int a = x + y; int b = x - y; int c = z + x; return a + b; } ! Can be reduced to: ! int doMath(int x, int y, int z) { int a = x + y; int b = x - y; return a + b; }
  • 13. ©2012 Azul Systems, Inc. Values can be propagated int doMath(int x, int y, int z) { int a = x + y; int b = x - y; int c = z + x; return a + b; } ! Can be reduced to: ! int doMath(int x, int y, int z) { return x + y + x - y; } !
  • 14. ©2012 Azul Systems, Inc. Math can be simplified int doMath(int x, int y, int z) { int a = x + y; int b = x - y; int c = z + x; return a + b; } ! Can be reduced to: ! int doMath(int x, int y, int z) { return x + x; } !
  • 16. ©2012 Azul Systems, Inc. Reads can be cached int distanceRatio(Object a) { int distanceTo = a.getX() - start; int distanceAfter = end - a.getX(); return distanceTo/distanceAfter; } Is the same as int distanceRatio(Object a) { int x = a.getX(); int distanceTo = x - start; int distanceAfter = end - x; return distanceTo/distanceAfter; }
  • 17. ©2012 Azul Systems, Inc. Reads can be cached void loopUntilFlagSet(Object a) { while (!a.flagIsSet()) { loopcount++; } } Is the same as: void loopUntilFlagSet(Object a) { boolean flagIsSet = a.flagIsSet(); while (!flagIsSet) { loopcount++; } } ! That’s what volatile is for...
  • 18. ©2012 Azul Systems, Inc. Writes can be eliminated Intermediate values might never be visible void updateDistance(Object a) { int distance = 100; a.setX(distance); a.setX(distance * 2); a.setX(distance * 3); } Is the same as void updateDistance(Object a) { a.setX(300); }
  • 19. ©2012 Azul Systems, Inc. Writes can be eliminated Intermediate values might never be visible void updateDistance(Object a) { a. setVisibleValue(0); for (int i = 0; i < 1000000; i++) { a.setInternalValue(i); } a.setVisibleValue(a.getInternalValue()); } Is the same as void updateDistance(Object a) { a.setInternalValue(1000000); a.setVisibleValue(1000000); }
  • 20. ©2012 Azul Systems, Inc. Inlining... public class Thing { private int x; public final int getX() { return x }; } ... myX = thing.getX(); Is the same as Class Thing { int x; } ... myX = thing.x;
  • 21. Speculative compiler tricks JIT compilers can do things that static compilers can have a hard time with…
  • 22. ©2012 Azul Systems, Inc. Class Hierarchy Analysis (CHA) Can perform global analysis on currently loaded code Deduce stuff about inheritance, method overrides, etc. Can make optimization decisions based on assumptions Re-evaluate assumptions when loading new classes Throw away code that conflicts with assumptions before class loading makes them invalid
  • 23. ©2012 Azul Systems, Inc. Inlining works without “final” public class Thing { private int x; public int getX() { return x }; } ... myX = thing.getX(); Is the same as Class Thing { int x; } ... myX = thing.x; As long as there is only one implementer of getX()
  • 24. ©2012 Azul Systems, Inc. The power of the “uncommon trap” Being able throw away wrong code is very useful E.g. Speculatively assuming callee type polymorphic can be “monomorphic” or “megamorphic” E.g. Can make virtual calls direct even without CHA E.g. Can speculatively inline things E.g. Speculatively assuming branch behavior We’ve only ever seen this thing go one way, so.... More Speculative stuff
  • 25. ©2012 Azul Systems, Inc. Untaken path example “Never taken” paths can be optimized away with benefits: void computeMagnitude(int val) { if (val > 10) { scale = computeScale(val); else { scale = 1; } return scale + 9; } When all values so far were <= 10 can be compiled to: void computeMagnitude(int val) { if (val > 10) uncommonTrap(); return 10; }
  • 26. ©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…
  • 28. ©2012 Azul Systems, Inc. Deoptimization: Adaptive compilation is… adaptive Micro-benchmarking is a black art So is the art of the Warmup 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. Many potential causes
  • 29. ©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...
  • 30. ©2012 Azul Systems, Inc. Fun In a Box: A simple Deoptimization example Deoptimization due to lazy loading/initialization Two classes: ThingOne and ThingTwo Both are actively called in the same method But compiler kicks in before one is ever called JIT cannot generate call for uninitialized class So it leaves an uncommon trap on that path… And deopts later if it ever gets there. https://github.com/giltene/GilExamples/blob/master/src/main/java/FunInABox.java
  • 31. public  class  FunInABox  {          static  final  int  THING_ONE_THREASHOLD  =  20000000          .          .          .                  static  public  class  ThingOne  {                  static  long  valueOne  =  0;   !                static  long  getValue()  {  return  valueOne++;  }          }   !        static  public  class  ThingTwo  {                  static  long  valueTwo  =  3;   !                static  long  getValue()  {  return  valueTwo++;  }          }   !        public  static  long  testRun(int  iterations)  {                  long  sum  =  0;   !                for(int  iter  =  0;  iter  <  iterations;  iter++)  {                          if  (iter  >  THING_ONE_THREASHOLD)                                  sum  +=  ThingOne.getValue();                          else                                  sum  +=  ThingTwo.getValue();                  }                  return  sum;          } Deopt example: Fun In a Box
  • 32. Lumpy.local-40% ! Lumpy.local-40% java -XX:+PrintCompilation FunInABox 77 1 java.lang.String::hashCode (64 bytes)! 109 2 sun.nio.cs.UTF_8$Decoder::decodeArrayLoop (553 bytes)! 115 3 java.math.BigInteger::mulAdd (81 bytes)! 118 4 java.math.BigInteger::multiplyToLen (219 bytes)! 121 5 java.math.BigInteger::addOne (77 bytes)! 123 6 java.math.BigInteger::squareToLen (172 bytes)! 127 7 java.math.BigInteger::primitiveLeftShift (79 bytes)! 130 8 java.math.BigInteger::montReduce (99 bytes)! 140 1% java.math.BigInteger::multiplyToLen @ 138 (219 bytes)! Starting warmup run (will only use ThingTwo):! 147 9 sun.security.provider.SHA::implCompress (491 bytes)! 153 10 java.lang.String::charAt (33 bytes)! 154 11 FunInABox$ThingTwo::getValue (10 bytes)! 154 2% FunInABox::testRun @ 4 (38 bytes)! 161 12 FunInABox::testRun (38 bytes)! Warmup run [1000000 iterations] took 27 msec..! ! ...Then, out of the box! Came Thing Two and Thing One!! And they ran to us fast! They said, "How do you do?"...! ! Starting actual run (will start using ThingOne a bit after using ThingTwo):! 5183 12 made not entrant FunInABox::testRun (38 bytes)! 5184 2% made not entrant FunInABox::testRun @ -2 (38 bytes)! 5184 3% FunInABox::testRun @ 4 (38 bytes)! 5184 13 FunInABox$ThingOne::getValue (10 bytes)! Test run [200000000 iterations] took 1299 msec... Deopt example: Fun In a Box
  • 33.        .          .          .          public  static  <T>  Class<T>  forceInit(Class<T>  klass)  {                  //  Forces  actual  initialization  (not  just  loading)  of  the  class  klass:                  try  {                          Class.forName(klass.getName(),  true,  klass.getClassLoader());                  }  catch  (ClassNotFoundException  e)  {                          throw  new  AssertionError(e);    //  Can't  happen                  }                  return  klass;          }   !        public  static  void  tameTheThings()  {                  forceInit(ThingOne.class);                  forceInit(ThingTwo.class);          }          .          .          . Deopt example: Fun In a Box https://github.com/giltene/GilExamples/blob/master/src/main/java/FunInABox.java
  • 34. Lumpy.local-41% ! Lumpy.local-41% java -XX:+PrintCompilation FunInABox KeepThingsTame! 75 1 java.lang.String::hashCode (64 bytes)! 107 2 sun.nio.cs.UTF_8$Decoder::decodeArrayLoop (553 bytes)! 113 3 java.math.BigInteger::mulAdd (81 bytes)! 115 4 java.math.BigInteger::multiplyToLen (219 bytes)! 119 5 java.math.BigInteger::addOne (77 bytes)! 121 6 java.math.BigInteger::squareToLen (172 bytes)! 125 7 java.math.BigInteger::primitiveLeftShift (79 bytes)! 127 8 java.math.BigInteger::montReduce (99 bytes)! 133 1% java.math.BigInteger::multiplyToLen @ 138 (219 bytes)! Keeping ThingOne and ThingTwo tame (by initializing them ahead of time):! Starting warmup run (will only use ThingTwo):! 140 9 sun.security.provider.SHA::implCompress (491 bytes)! 147 10 java.lang.String::charAt (33 bytes)! 147 11 FunInABox$ThingTwo::getValue (10 bytes)! 147 2% FunInABox::testRun @ 4 (38 bytes)! 154 12 FunInABox::testRun (38 bytes)! Warmup run [1000000 iterations] took 24 msec..! ! ...Then, out of the box! Came Thing Two and Thing One!! And they ran to us fast! They said, "How do you do?"...! ! Starting actual run (will start using ThingOne a bit after using ThingTwo):! 5178 13 FunInABox$ThingOne::getValue (10 bytes)! Test run [200000000 iterations] took 2164 msec... Deopt example: Fun In a Box
  • 35. ©2012 Azul Systems, Inc. Example causes for depotimization at Market Open 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
  • 36. ©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 . . .
  • 37. ©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 Trades ReadyNow! to the rescue Java’s “Just In Time” Reality
  • 38. ©2012 Azul Systems, Inc. What can we do about it? Zing has a new feature set called “ReadyNow!” Focused on avoiding deoptimization while keeping code fast First of all, paying attention matters E.g. Some of those dynamic branch eliminations have no benefit… Adds optional controls for helpful things like: Aggressive class loading (load when they come into scope) Safe pre-initialization of classes with empty static initializers Per method compiler directives (e.g. disable ImplicitNullChecks) … The feature set keep growing…
  • 39. ©2013 Azul Systems, Inc. Java at Market Open . . . Market Open Deoptimization ReadyNow! avoids deoptimization
  • 40. ©2013 Azul Systems, Inc. Java at Market Open . . . Market Open With Zing & ReadyNow!
  • 41. ©2013 Azul Systems, Inc. Java at Market Open . . . Market Open With ReadyNow! Warmup? Avoids Restarts
  • 42. ©2013 Azul Systems, Inc. . . . Market Open With ReadyNow! and No Overnight Restarts ! Start Fast & Stay Fast Java at Market Open
  • 43. ©2013 Azul Systems, Inc. One liner takeaway . . . Zing: A cure for the Java hiccups Market Open
  • 44. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations/jvm- dynamic-optimizations