Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GraalVM - An Overview

GraalVM - An Overview

Martin Lippert

December 11, 2019
Tweet

More Decks by Martin Lippert

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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 …
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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.)
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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
  25. 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)
  26. 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
  27. 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)
  28. 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)
  29. 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
  30. 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
  31. 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