3. 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
4. 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
5. 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
9. 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
10. 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
11. 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
12. 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
13. 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, ...)
14. 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
21. 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
22. 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
23. 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
24. 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
25. 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
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) – 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
30. Graal(VM) – performance and interoperability
SVM advantagas
Self-contained native executables
Fast process start
Small distribution size
Memory footprint may be smaller
31. 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:
32. 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
33. 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