Slide 1

Slide 1 text

GraalVM - Ein Überblick Martin Lippert (Pivotal, @martinlippert)

Slide 2

Slide 2 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Overview https://graalvm.org/: High-performance polyglot VM Basic idea: • One virtual machine that can execute all languages (Java, JavaScript, R, Ruby, Python, C, C++, Kotlin, Scala, etc.) • You can run all those languages without any boundaries between them

Slide 3

Slide 3 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ GraalVM Java Scala Kotlin JavaScript Ruby R Python C++ OpenJDK Node JS Oracle Database MySQL Native WebAssembly

Slide 4

Slide 4 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The Graal compiler • The Graal compiler is at the center of everything • it is a highly optimizing compiler • written in Java • In an OpenJDK setting, it replaces the HotSpot JIT compiler • and adds additional API to the outside world

Slide 5

Slide 5 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ GraalVM architecture (JVM languages) HotSpot VM Graal Compiler JVM languages

Slide 6

Slide 6 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Using Graal Compiler as C2 • Download JDK11 • Enable GraalVM as JIT compiler • -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI • Run your Java/Scala/Kotlin application • uses the Graal compiler as the C2 JIT compiler • performance and footprint improvements tend to vary

Slide 7

Slide 7 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Using Graal Compiler as C2 • Download the GraalVM package from GitHub and GO • can be used as a drop-in replacement for a JDK • plus contains packages for different languages (like JavaScript) • Run your Java/Scala/Kotlin application • uses the Graal compiler as the C2 JIT compiler (very latest version) • everything else is standard OpenJDK HotSpot VM

Slide 8

Slide 8 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo

Slide 9

Slide 9 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Polyglot

Slide 10

Slide 10 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ GraalVM Java Scala Kotlin JavaScript Ruby R Python C++ OpenJDK Node JS Oracle Database MySQL Native WebAssembly

Slide 11

Slide 11 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Non-JVM based languages • each language needs to be implemented for the Graal compiler • to make this easier, there is the Truffle framework (now called Language Implementation Framework) • you basically write an interpreter for the language based on an AST • the framework and the compiler turns this into high-performance compiled code for the language

Slide 12

Slide 12 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ GraalVM architecture HotSpot VM Graal Compiler JVM languages Truffle (Language Implementation Framework) JavaScript implementation Python implementation …

Slide 13

Slide 13 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo

Slide 14

Slide 14 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Mixing Languages • It is possible to mix languages • You can access objects across language boundaries without runtime overhead • The compiler can even optimize the code across the languages

Slide 15

Slide 15 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo

Slide 16

Slide 16 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Performance • JavaScript performance, for example, is comparable to V8

Slide 17

Slide 17 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Native Images

Slide 18

Slide 18 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Native Images in GraalVM • People often get confused, but: • GraalVM is not the same as native images using AOT compilation • It can be used to create native images for JVM-based languages

Slide 19

Slide 19 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Why? • Super fast startup • Lower memory footprint

Slide 20

Slide 20 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ SubstrateVM • Implements the missing pieces of the JVM in Java • Gets compiled into native code via the Graal compiler • Has limitations: • closed world assumption (no dynamic classloading) • No invokeDynamic or MethodHandles • Finalizers • Security Manager • Native VM interfaces (JVMTI, JMX, etc.)

Slide 21

Slide 21 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ SubstrateVM • Supported, but needs configuration: • reflection • resource loading • proxies supported (JDK proxies only) • JNI

Slide 22

Slide 22 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How does that work? Your Java code JDK SubstrateVM Binary Compiled Code Initial Heap static analysis AOT compilation + snapshotting intermediate model

Slide 23

Slide 23 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo

Slide 24

Slide 24 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Boot Language Server • Spring Boot application by itself, compiled to a native image using GraalVM and experimental Spring Boot support for GraalVM native images • early experiences • super fast startup • pretty good performance

Slide 25

Slide 25 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Startup time (ms) needed to startup language server to be ready to use JDK 11.0.4 Graal native image 0 550 1100 1650 2200

Slide 26

Slide 26 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Example: ASTParser and type resolving • compiled as part of the native-image • pretty straight-forward • not a lot to configure for the native-image builder • But: • works for Java8 projects only • Java9 module file system loaded ad-hoc via newly created classloader from different JDKs (hard to fit this into the closed-world assumption)

Slide 27

Slide 27 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Performance time (ms) needed to parse java source code using JDT JDK 11 / C1 Graal native image 0 950 1900 2850 3800

Slide 28

Slide 28 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Profile-Guided Optimization • Collect profiling information at runtime first • Then feed that profiling data into the native-image builder • better peek performance • but you need to make sure the profiling data was recorded for the right case • (Enterprise Edition only)

Slide 29

Slide 29 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Open questions • How do I make sure the native-image is correct? • Debugging in native-images is back to println - fun, fun, fun • Building native-images takes a long time (CPU and memory intensive work) • nothing you can do within short turn-around cycles • Libraries not always compatible, need workarounds (but that will improve, I guess) • Not yet suitable for long-living server applications (HotSpotVM still provides better runtime characteristics)

Slide 30

Slide 30 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Conclusion

Slide 31

Slide 31 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Community vs. Enterprise Edition • Community Edition is free to use (and open-source) • Enterprise Edition provides additional value • more performance optimizations • security enhancements • and more

Slide 32

Slide 32 text

Unless otherwise indicated, these slides are © 2013-2019 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Conclusion • The Graal compiler is a very promising technology • written in Java • maintainable • more and more optimizations coming over time • (will probably replace the C2 compiler in HotSpot sometime) • Native image • super quick startup, lower memory footprint is great • especially feasible for specific environments (short-lived runtimes, serverless, command-line tools) • many open questions

Slide 33

Slide 33 text

Stay Connected. mlippert@pivotal.io @martinlippert #springone @s1p