BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF
HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH
BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF
HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH
Graal(VM)
– new era in JVM performance
and languages interoperability
Gilles DuboscqGilles Duboscq
Jonatan KazmierczakJonatan Kazmierczak
Andy MoncsekAndy Moncsek
Copyright © 2018, Oracle and/or its aliates. All rights reserved.
●
Working at Oracle Labs Zürich
●
Working on Graal for 7 years
●
Research interests:
●
Virtual machines
●
Compilers
●
Specula-ve op-miza-ons
Gilles Duboscq
Graal(VM) – performance and interoperability
Jonatan Kazmierczak
 senior consultant at Trivadis
 creator of Class Visualizer
 contributor to Graal
 uses Java for 20+ years
 creates software for 29 years
Graal(VM) – performance and interoperability
Andy Moncsek
n principal consultant at Trivadis
n creator of ... see my github
n Wrote his first program on a 2.5MHz PC
n conference speaker
n Likes coffee  HiFi
Graal(VM) – performance and interoperability
Agenda
 Introduction
 JVM, JIT, AOT, SVM – what are we talking about?
 More details and some demos
 GraalVM, Graal, Substrate VM
 Time of the truth
– benchmark results
 Summary + Q  A
Copyright © 2018, Oracle and/or its aliates. All rights reserved.
Safe Harbor Statement
The following is intended to provide some insight into a line of research in Oracle Labs. It
is intended for informa-on purposes only, and may not be incorporated into any contract.
It is not a commitment to deliver any material, code, or func-onality, and should not be
relied upon in making purchasing decisions. The development, release, and -ming of any
features or func-onality described in connec-on with any Oracle product or service
remains at the sole discre-on of Oracle. Any views expressed in this presenta-on are my
own and do not necessarily re6ect the views of Oracle.
2
Graal(VM) – performance and interoperability
IntroductionIntroduction
Graal(VM) – performance and interoperability
What is JIT compiler?
Graal(VM) – performance and interoperability
What is JIT compiler?
Just-in-time compiler working at runtime:
 performs advanced optimizations of Java bytecode
 compiles Java bytecode to platform-speci3c machine code
and stores it in memory
 recompilations are possible
Graal(VM) – performance and interoperability
What is AOT compiler?
Ahead-of-time compiler:
 performs simple optimizations of Java bytecode
 transforms Java bytecode into machine code
and stores it in an OS-speci3c binary 3le
Graal(VM) – performance and interoperability
What is C2 ?
 JIT compiler used by default by JVM
 Introduced about 20 years ago (long before Java 8)
– not enough support for modern language features
 written in C++
– extremely di6cult to maintain and extend
Graal(VM) – performance and interoperability
What is Graal ?
 modern compiler available as experimental feature
– can be used as JIT compiler and AOT compiler
 introduced in JDK 9
 supports language features introduced in Java 8
 written in Java
– modular and easily maintainable
Graal(VM) – performance and interoperability
What is GraalVM ?
 universal virtual machine for running applications written in
various languages
 it removes the isolation between programming languages and
enables interoperability in a shared runtime
 it can be integrated in various native and managed
deployments (OpenJDK, Node.js, Oracle DB, MySQL, ...)
Graal(VM) – performance and interoperability
What is Substrate VM (SVM)?
 it is an embeddable VM
 written for and in a subset of Java
 optimized to execute dynamic languages
 ahead-of-time compiled using Graal
 integrating with native development tools
Graal(VM) – performance and interoperability
GraalVMGraalVM
Copyright © 2018, Oracle and/or its aliates. All rights reserved. 4
Why GraalVM: Polyglot Challenges
Only languages with high industry a:en-on achieve high performance.
Languages require di;erent tools for conguring, debugging, proling…
Languages execute in their own box with costly serializa-on between boxes.
Copyright © 2018, Oracle and/or its aliates. All rights reserved. 5
GraalVM Vision
High performance for all languages
Common plaorm for shared manageability and tooling
Zero overhead interoperability between languages
Copyright © 2018, Oracle and/or its aliates. All rights reserved. 6
GraalVM Extended Vision
High performance, polyglot, common pla@orm…
embeddable across the stack in na-ve and JVM-based applica-ons.
Copyright © 2018, Oracle and/or its aliates. All rights reserved. 7
GraalVM Extended Vision
Graal(VM) – performance and interoperability
GraalGraal
Graal(VM) – performance and interoperability
Sample application
 real world solution
 simple microservice
 depends only on 2 JDK modules:
 java.base
 jdk.httpserver
 link to the project:
github.com/jonatan-kazmierczak/simple-microservice
Graal(VM) – performance and interoperability
How to turn on Graal JIT ?
 run a sample application on C2 JIT (default)
java -jar simple-microservice.jar
 run a sample application on Graal JIT
java -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler 
-jar simple-microservice.jar
Graal(VM) – performance and interoperability
JIT – Graal vs C2
 Pros
 Better performance of long-running applications
 Cons
 Slower startup time
 Heap used for compilations
– more heap space may be required
Graal(VM) – performance and interoperability
How to use Graal (JDK) AOT ?
 compile sample application using Graal (JDK) AOT
jaotc --output app.so --jar simple-microservice.jar 
--module jdk.httpserver --module java.base
 run a sample application using generated machine code
java -XX:AOTLibrary=./app.so -jar simple-microservice.jar
Graal(VM) – performance and interoperability
Execution – AOT-compiled vs JIT-compiled
 Pros
 Faster startup time
 Cons
 Worse performance of long-running applications
 Huge size of natively compiled code
Graal(VM) – performance and interoperability
SubstrateVMSubstrateVM
Substrate VM
Graal(VM) – performance and interoperability _
http://www.oracle.com/technetwork/java/jvmls2015-wimmer-2637907.pdf
Substrate VM
Graal(VM) – performance and interoperability _
http://www.oracle.com/technetwork/java/jvmls2015-wimmer-2637907.pdf
Graal(VM) – performance and interoperability
How to create a native app?
 Download  Install GraalVM (http://www.graalvm.org/docs/getting-started/)
 Build a (fat) jar (maven, gradle,…)
 native-image -jar simple-microservice.jar
 ./simple-microservice
Graal(VM) – performance and interoperability
SVM advantagas
 Self-contained native executables
 Fast process start
 Small distribution size
 Memory footprint may be smaller
Graal(VM) – performance and interoperability
Limitations SVM
{
name : java.lang.String,
fields : [
{ name : value },
{ name : hash }
],
methods : [
{ name : init, parameterTypes : [] },
{ name : init, parameterTypes : [char[]] }
}
Reflection configuration:
Graal(VM) – performance and interoperability
Limitations recap
 Not every JVM application can be compiled to SVM
 There is no JIT
 and no optimizations during run-time
 optimizations through instrumentations possible
 The garbage-collector is simpler
Graal(VM) – performance and interoperability
So why SVM  AOT?
n Different target group / alignment to HotSpot
n Cloud, Container, Functions, IoT
n Small  volatile
n Jakarte EE / Desktop out of scope
https://medium.com/oracledevs/helidon-takes-flight-fb7e9e390e9c
Graal(VM) – performance and interoperability
SummarySummary
withQAwithQA
Graal(VM) – performance and interoperability
Benchmark and statistics
Mode Initialization
[ms]
Execution
[µs]
UsedRAM
[MB]
Distributionsize
[MB]
C2JIT 990 66 424 0+JDK
GraalJIT 2100 59 420 0+JDK
JDKAOT 690 136 423 316(so/dll)+JDK
SVMAOT 1280 87 516 9(executable)
Copyright © 2018, Oracle and/or its aliates. All rights reserved.
Possibili$es
With GraalVM, you could:
• Run your exis-ng JVM applica-on more eciently
• Run your exis-ng R, Ruby, JS, Python applica-on more eciently
• Run those languages in the same VM with ecient interoperability
• Embed those languages in a JVM or na-ve applica-on
Graal compiler
available in the JDK
GraalVM
Copyright © 2018, Oracle and/or its aliates. All rights reserved.
Inspec$ng performance
• Use the perf tool on Linux
• Use Oracle Developer Studio’s
Performance Analyzer
Copyright © 2018, Oracle and/or its aliates. All rights reserved.
Future
• Pla@orms:
– Windows support  JDK 11 is coming to GraalVM
– libgraal
●
Separate heap to avoid interac-on with applica-on GC tuning
●
Removes start-up/warm-up costs of Graal
Copyright © 2018, Oracle and/or its aliates. All rights reserved.
Resources on GraalVM
11
graalvm.org
Thank you!Thank you!

TechEvent Graal(VM) Performance Interoperability

  • 1.
    BASEL BERN BRUGGDÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH Graal(VM) – new era in JVM performance and languages interoperability Gilles DuboscqGilles Duboscq Jonatan KazmierczakJonatan Kazmierczak Andy MoncsekAndy Moncsek
  • 2.
    Copyright © 2018,Oracle and/or its aliates. All rights reserved. ● Working at Oracle Labs Zürich ● Working on Graal for 7 years ● Research interests: ● Virtual machines ● Compilers ● Specula-ve op-miza-ons Gilles Duboscq
  • 3.
    Graal(VM) – performanceand interoperability Jonatan Kazmierczak  senior consultant at Trivadis  creator of Class Visualizer  contributor to Graal  uses Java for 20+ years  creates software for 29 years
  • 4.
    Graal(VM) – performanceand interoperability Andy Moncsek n principal consultant at Trivadis n creator of ... see my github n Wrote his first program on a 2.5MHz PC n conference speaker n Likes coffee HiFi
  • 5.
    Graal(VM) – performanceand interoperability Agenda  Introduction  JVM, JIT, AOT, SVM – what are we talking about?  More details and some demos  GraalVM, Graal, Substrate VM  Time of the truth – benchmark results  Summary + Q A
  • 6.
    Copyright © 2018,Oracle and/or its aliates. All rights reserved. Safe Harbor Statement The following is intended to provide some insight into a line of research in Oracle Labs. It is intended for informa-on purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or func-onality, and should not be relied upon in making purchasing decisions. The development, release, and -ming of any features or func-onality described in connec-on with any Oracle product or service remains at the sole discre-on of Oracle. Any views expressed in this presenta-on are my own and do not necessarily re6ect the views of Oracle. 2
  • 7.
    Graal(VM) – performanceand interoperability IntroductionIntroduction
  • 8.
    Graal(VM) – performanceand interoperability What is JIT compiler?
  • 9.
    Graal(VM) – performanceand interoperability What is JIT compiler? Just-in-time compiler working at runtime:  performs advanced optimizations of Java bytecode  compiles Java bytecode to platform-speci3c machine code and stores it in memory  recompilations are possible
  • 10.
    Graal(VM) – performanceand interoperability What is AOT compiler? Ahead-of-time compiler:  performs simple optimizations of Java bytecode  transforms Java bytecode into machine code and stores it in an OS-speci3c binary 3le
  • 11.
    Graal(VM) – performanceand interoperability What is C2 ?  JIT compiler used by default by JVM  Introduced about 20 years ago (long before Java 8) – not enough support for modern language features  written in C++ – extremely di6cult to maintain and extend
  • 12.
    Graal(VM) – performanceand interoperability What is Graal ?  modern compiler available as experimental feature – can be used as JIT compiler and AOT compiler  introduced in JDK 9  supports language features introduced in Java 8  written in Java – modular and easily maintainable
  • 13.
    Graal(VM) – performanceand interoperability What is GraalVM ?  universal virtual machine for running applications written in various languages  it removes the isolation between programming languages and enables interoperability in a shared runtime  it can be integrated in various native and managed deployments (OpenJDK, Node.js, Oracle DB, MySQL, ...)
  • 14.
    Graal(VM) – performanceand interoperability What is Substrate VM (SVM)?  it is an embeddable VM  written for and in a subset of Java  optimized to execute dynamic languages  ahead-of-time compiled using Graal  integrating with native development tools
  • 15.
    Graal(VM) – performanceand interoperability GraalVMGraalVM
  • 16.
    Copyright © 2018,Oracle and/or its aliates. All rights reserved. 4 Why GraalVM: Polyglot Challenges Only languages with high industry a:en-on achieve high performance. Languages require di;erent tools for conguring, debugging, proling… Languages execute in their own box with costly serializa-on between boxes.
  • 17.
    Copyright © 2018,Oracle and/or its aliates. All rights reserved. 5 GraalVM Vision High performance for all languages Common plaorm for shared manageability and tooling Zero overhead interoperability between languages
  • 18.
    Copyright © 2018,Oracle and/or its aliates. All rights reserved. 6 GraalVM Extended Vision High performance, polyglot, common pla@orm… embeddable across the stack in na-ve and JVM-based applica-ons.
  • 19.
    Copyright © 2018,Oracle and/or its aliates. All rights reserved. 7 GraalVM Extended Vision
  • 20.
    Graal(VM) – performanceand interoperability GraalGraal
  • 21.
    Graal(VM) – performanceand interoperability Sample application  real world solution  simple microservice  depends only on 2 JDK modules:  java.base  jdk.httpserver  link to the project: github.com/jonatan-kazmierczak/simple-microservice
  • 22.
    Graal(VM) – performanceand interoperability How to turn on Graal JIT ?  run a sample application on C2 JIT (default) java -jar simple-microservice.jar  run a sample application on Graal JIT java -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler -jar simple-microservice.jar
  • 23.
    Graal(VM) – performanceand interoperability JIT – Graal vs C2  Pros  Better performance of long-running applications  Cons  Slower startup time  Heap used for compilations – more heap space may be required
  • 24.
    Graal(VM) – performanceand interoperability How to use Graal (JDK) AOT ?  compile sample application using Graal (JDK) AOT jaotc --output app.so --jar simple-microservice.jar --module jdk.httpserver --module java.base  run a sample application using generated machine code java -XX:AOTLibrary=./app.so -jar simple-microservice.jar
  • 25.
    Graal(VM) – performanceand interoperability Execution – AOT-compiled vs JIT-compiled  Pros  Faster startup time  Cons  Worse performance of long-running applications  Huge size of natively compiled code
  • 26.
    Graal(VM) – performanceand interoperability SubstrateVMSubstrateVM
  • 27.
    Substrate VM Graal(VM) –performance and interoperability _ http://www.oracle.com/technetwork/java/jvmls2015-wimmer-2637907.pdf
  • 28.
    Substrate VM Graal(VM) –performance and interoperability _ http://www.oracle.com/technetwork/java/jvmls2015-wimmer-2637907.pdf
  • 29.
    Graal(VM) – performanceand interoperability How to create a native app?  Download Install GraalVM (http://www.graalvm.org/docs/getting-started/)  Build a (fat) jar (maven, gradle,…)  native-image -jar simple-microservice.jar  ./simple-microservice
  • 30.
    Graal(VM) – performanceand interoperability SVM advantagas  Self-contained native executables  Fast process start  Small distribution size  Memory footprint may be smaller
  • 31.
    Graal(VM) – performanceand interoperability Limitations SVM { name : java.lang.String, fields : [ { name : value }, { name : hash } ], methods : [ { name : init, parameterTypes : [] }, { name : init, parameterTypes : [char[]] } } Reflection configuration:
  • 32.
    Graal(VM) – performanceand interoperability Limitations recap  Not every JVM application can be compiled to SVM  There is no JIT  and no optimizations during run-time  optimizations through instrumentations possible  The garbage-collector is simpler
  • 33.
    Graal(VM) – performanceand interoperability So why SVM AOT? n Different target group / alignment to HotSpot n Cloud, Container, Functions, IoT n Small volatile n Jakarte EE / Desktop out of scope https://medium.com/oracledevs/helidon-takes-flight-fb7e9e390e9c
  • 34.
    Graal(VM) – performanceand interoperability SummarySummary withQAwithQA
  • 35.
    Graal(VM) – performanceand interoperability Benchmark and statistics Mode Initialization [ms] Execution [µs] UsedRAM [MB] Distributionsize [MB] C2JIT 990 66 424 0+JDK GraalJIT 2100 59 420 0+JDK JDKAOT 690 136 423 316(so/dll)+JDK SVMAOT 1280 87 516 9(executable)
  • 36.
    Copyright © 2018,Oracle and/or its aliates. All rights reserved. Possibili$es With GraalVM, you could: • Run your exis-ng JVM applica-on more eciently • Run your exis-ng R, Ruby, JS, Python applica-on more eciently • Run those languages in the same VM with ecient interoperability • Embed those languages in a JVM or na-ve applica-on Graal compiler available in the JDK GraalVM
  • 37.
    Copyright © 2018,Oracle and/or its aliates. All rights reserved. Inspec$ng performance • Use the perf tool on Linux • Use Oracle Developer Studio’s Performance Analyzer
  • 38.
    Copyright © 2018,Oracle and/or its aliates. All rights reserved. Future • Pla@orms: – Windows support JDK 11 is coming to GraalVM – libgraal ● Separate heap to avoid interac-on with applica-on GC tuning ● Removes start-up/warm-up costs of Graal
  • 39.
    Copyright © 2018,Oracle and/or its aliates. All rights reserved. Resources on GraalVM 11 graalvm.org
  • 40.