Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Now it's time to compile by Dmitry Chuyko
Search
Riga Dev Day
March 13, 2016
57
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Now it's time to compile by Dmitry Chuyko
Riga Dev Day
March 13, 2016
More Decks by Riga Dev Day
See All by Riga Dev Day
Faster Java by Adding Structs (Sort Of)
rigadevday
0
170
Prepare for JDK 9! by Dalibor Topic
rigadevday
0
150
Little Important Things in Distributed Architectures by Andres Jaan Tack
rigadevday
0
150
Oracle 12c for Developers by Alex Nuijten
rigadevday
1
140
The Language of Regular Expressions. So You Think You Can Speak It? by Rustam Mehmandarov
rigadevday
0
78
Modern Java Component Design with Spring 4.3 by Juergen Hoeller
rigadevday
0
270
Open Source and OpenJDK: Do They Deliver? by Simon Ritter
rigadevday
0
72
Google Apps Integration in Oracle Apex by Richard Martens
rigadevday
0
300
Integration Testing from the Trenches by Nicolas Fränkel
rigadevday
0
240
Featured
See All Featured
Mind Mapping
helmedeiros
PRO
1
250
Documentation Writing (for coders)
carmenintech
77
5.4k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
Building the Perfect Custom Keyboard
takai
2
790
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
360
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Making the Leap to Tech Lead
cromwellryan
135
9.9k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
RailsConf 2023
tenderlove
30
1.5k
Producing Creativity
orderedlist
PRO
348
40k
Transcript
Hotspot & AOT Now it’s time to compile Dmitry Chuyko
Java SE Performance Team March 3, 2016 Copyright © 2016, Oracle and/or its affiliates. All rights reserved.
Contents 1. Introduction 2. The Current Situation 3. Ahead-of-time Compilation
4. Graal 5. JVM Compiler Interface 6. Artifacts Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 2/33
Safe Harbor Statement The following is intended to outline our
general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 3/33
Introduction Copyright © 2016, Oracle and/or its affiliates. All rights
reserved. 4/33
Reminder: It’s 2016 ∙ JDK 9 EA https://jdk9.java.net/ ∙ JDK
8u ∙ JDK 7 End of Public Updates in April 2015 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 5/33
Overview: Computing A long time ago in a galaxy far,
far away... ∙ Pre-computer machines appeared ∙ Computers and their machine codes ∙ Languages and compilers ∙ Scripts ∙ Computer science Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 6/33
Overview: Java ∙ Is a language ∙ Set of specifications
∙ Used to be called slow ’́Because it’s interpreted” (not true) ∙ ”Write once, run anywhere” (true) Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 7/33
Overview: JVM ∙ Is a code itself ∙ Can dynamically
execute arbitrary correct bytecode Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 8/33
Overview: JVM ∙ Is a code itself ∙ Can dynamically
execute arbitrary correct bytecode ∙ May be written in anything ∙ May produce native code and re-use the result Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 8/33
The Current Situation Copyright © 2016, Oracle and/or its affiliates.
All rights reserved. 9/33
Overview: Hospot ∙ Is a JVM ∙ Written in C++
∙ Native shared libraries (libjvm) ∙ Produces bytecode dynamically for its own purposes ∙ Does just-in-time compilation ∙ Supports many modes – Garbage collectors – Pointers encoding – etc. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 10/33
Overview: JIT in Hotspot ∙ Tiered compilation – Level 0.
Interpreter – Level 1. C1 without profiling (optimized), terminal – Level 2. C1 with basic profiling – Level 3. C1 with full profiling – Level 4. C2, terminal, expensive ∙ Unused method versions are thrown to save footprint ∙ Optimizations and effective compilation – ⇒ de-optimizations to level 0 ∙ All modes (if not switched off), CPU instruction set – Custom code Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 11/33
Problem: Application Warm-up Iterative workload ∙ Startup time ∙ Time
to performance Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 12/33
Problem: Application Latency ∙ Where is a line for interpreter?
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13/33
Problem: Application Latency ∙ Where is a line for interpreter?
∙ ≈ on slide 7 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13/33
Problem: Application Latency ∙ Where is a line for interpreter?
∙ ≈ on slide 7 ∙ Level 1 (C1) is relatively also slow Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13/33
Problem: Application Latency ∙ Wish it to be HFT. .
. @Transactional void buyOrSell(Quote quote) Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 14/33
Problem: Application Latency ∙ Wish it to be HFT. .
. @Transactional void buyOrSell(Quote quote) – De-optimization when flow changes – Training workloads ∙ And you meet void buy_or_sell [[db:transactional]] (Quote* quote) CFLAGS_ALL += -O3 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 14/33
Problem: Bootstrapping Meta-circular implementations ∙ It’s possible to write JVM
in Java, Scala or JavaScript ∙ ”My dear JVM existing as bytecode image, please start and make yourself efficient in execution of bytecode. Quickly” ∙ Actually the 3 problems above Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 15/33
Ahead-of-time Compilation Copyright © 2016, Oracle and/or its affiliates. All
rights reserved. 16/33
Solution: Startup time ∙ Pre-compile initialization code – No interpreter
for class loading, reflection etc. – No resources for compilation Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 17/33
Solution: Time to performance ∙ Pre-compile critical code – Start
with much better than interpreter performance – No resources for compilation ∙ Reach peak performance – Collect same profiling info – JIT with profile-guided optimizations Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 18/33
Solution: Latency ∙ Pre-compile critical code – High and stable
performance – Global optimizations – No de-optimization – No re-compilation Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 19/33
Pre-compilation: Different Solutions Exist ∙ AOT whole application to native
executable – Native exe/elf – Trial runs for better image layout – Bundled or shared VM – Deep dependency analysis – Pre-defined mode – JIT is secondary ∙ VM with JIT and AOT compilers – Optional cache for class data and code – Trial runs for methods filtering Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 20/33
Pre-compilation: For Hotspot ∙ Need to generate code – Mostly
no de-optimizations – Better than C1 ∙ No tight time budget ∙ Need to resolve and load generated code Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 21/33
Pre-compilation: For Hotspot ∙ Need to generate code – Mostly
no de-optimizations – Better than C1 ∙ No tight time budget ∙ Need to resolve and load generated code ∙ How about one more compiler? Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 21/33
Graal Copyright © 2016, Oracle and/or its affiliates. All rights
reserved. 22/33
Graal: Project ∙ Experimental dynamic compiler written in Java ∙
Supports Java ∙ OpenJDK project http://openjdk.java.net/projects/graal/ ∙ Oracle Labs team ∙ GraalVM based on Hotspot http://www.oracle.com/technetwork/oracle-labs/program- languages/overview/index.html Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 23/33
Graal: For AOT ∙ It proven to work – SubstrateVM
∙ Flexible and handy – Modular – Annotation based way ∙ Possible to avoid most de-optimizations – No speculative optimizations – Compile all paths ∙ Focused on performance Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 24/33
Graal: For AOT ∙ It proven to work – SubstrateVM
∙ Flexible and handy – Modular – Annotation based way ∙ Possible to avoid most de-optimizations – No speculative optimizations – Compile all paths ∙ Focused on performance ∙ How does it interact with Hotspot? Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 24/33
JVM Compiler Interface Copyright © 2016, Oracle and/or its affiliates.
All rights reserved. 25/33
JEP 243: Java-Level JVM Compiler Interface ∙ OpenJDK feature, already
in 9 http://openjdk.java.net/jeps/243 ∙ Goals – Allow the JVM to load Java plug-in code to examine and intercept JVM JIT activity. – Record events related to compilation, including counter overflow, compilation requests, speculation failure, and deoptimization. – Allow queries to relevant metadata, including loaded classes, method definitions, profile data, dependencies (speculative assertions), and compiled code cache. – Allow an external module to capture compilation requests and produce code to be used for compiled methods. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 26/33
JVMCI: Graal as C2 Replacement -XX:+EnableJVMCI -XX:+UseJVMCICompiler -Djvmci.compiler=graal Copyright ©
2016, Oracle and/or its affiliates. All rights reserved. 27/33
JVMCI: Details ∙ Not used for C1, C2 ∙ Special
module jdk.vm.ci ∙ Familiar extension patterns – CompilerFactory, StartupEventListener, HotSpotJVMCIBackendFactory, HotSpotVMEventListener. . . Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 28/33
JVMCI: How it works Hotspot ∙ Compilation Queue ∙ Metaspace
∙ Code Cache JVMCI Compiler ∙ Compilation Request ∙ jdk.internal.jvmci.meta ∙ byte[] Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 29/33
Artifacts Copyright © 2016, Oracle and/or its affiliates. All rights
reserved. 30/33
Code: AOT Modes ∙ Targeted at problem – Tiered. Similar
to Level 3 – Non-Tiered – Latency ∙ Targeted at VM mode Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 31/33
Code: Libraries ∙ Native shared library (ELF DSO) – OS
knows how to threat it right – Compatible with tools ∙ Modified Hotspot that works with compiled methods from shared libraries Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 32/33
Packaging: Self-contained Apps ∙ Java Packager – Prepares fancy .dmg
for shiny Mac – Bundled with 100 Mb JRE ∙ JEP 275: Modular Java Application Packaging http://openjdk.java.net/jeps/275 – jlink helps to generate a JRE image with the required modules only – Extensions – AOT libs can be created and added Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 33/33