GraalVM

GraalVM

GraalVM

Virtual machine software


GraalVM is a Java Development Kit (JDK) written in Java. The open-source distribution of GraalVM is based on OpenJDK, and the enterprise distribution is based on Oracle JDK. As well as just-in-time (JIT) compilation, GraalVM can compile a Java application ahead of time. This allows for faster initialization, greater runtime performance, and decreased resource consumption, but the resulting executable can only run on the platform it was compiled for.

Quick Facts Developer(s), Stable release ...

It provides additional programming languages and execution modes. The first production-ready release, GraalVM 19.0, was distributed in May 2019.[4] The most recent release is GraalVM for JDK 22, made available in March 2024.[5]

Major differentiators of GraalVM compared to the base JDK include:

  • Graal Compiler, a just-in-time (JIT) compiler.
  • GraalVM Native Image is a technology to compile Java applications ahead of time.
  • Truffle Language Implementation Framework and GraalVM SDK, a Java-based framework and a collection of APIs for developing high-performance language runtimes.
  • GraalVM Polyglot API, an API to embed guest language code in a Java-based host application.
  • JavaScript Runtime, an ECMAScript 2023-compliant JavaScript runtime, as well as Node.js.
  • LLVM Runtime is a runtime to execute languages that can be transformed into LLVM bitcode.

Goals

  • To improve the performance of Java virtual machine (JVM)-based languages to match native languages.[6][7]
  • To reduce the startup time of JVM-based applications by compiling them ahead of time.
  • To enable GraalVM integration into the Oracle Database, OpenJDK, Android/iOS, and similar custom embeddings.
  • To enable embedding guest language code in a JVM-based host application.
  • To enable mixing of code from any programming language in a single application, billed as a "polyglot application."[6][8]

History

GraalVM has its roots in the Maxine Virtual Machine project at Sun Microsystems Laboratories (now Oracle Labs). The project's goal was to write a Java virtual machine in Java itself to avoid the problems of developing in C++, particularly manual memory management, and benefit from meta-circular optimizations. The project changed its focus to the compiler and to hook it into the HotSpot runtime as much as possible. The GraalVM compiler, Graal, was started by manually converting the code of the HotSpot client compiler (named "C1") into Java, replacing the previous Maxine compiler.[9]

Graal was included in HotSpot-based JDK releases such as OpenJDK from Java SE 9 through 15, to provide experimental ahead-of-time compilation. TheUseJVMCICompiler option also enabled the use of Graal as a replacement for the server compiler (named "C2").[10] The option was removed in Java SE 16 to eliminate the duplicate effort of maintaining a version in the JDK and a standalone GraalVM release. A similar function to create a native executable from a Java application is provided by the native-image tool of standalone GraalVM releases. The tool processes a Java application's classes and other metadata to create a binary for a specific operating system and architecture. It can be used to build a native executable or a native shared library.

Releases

GraalVM is available as Oracle GraalVM under the GraalVM Free Terms and Conditions (GFTC) license, as Oracle GraalVM Enterprise Edition accessible by accepting the "OTN License Agreement Oracle GraalVM Enterprise Edition Including License for Early Adopter Versions" [1 or as a Community Edition with an open-source license. Oracle Corporation announced the release of Oracle GraalVM Enterprise Edition on May 8, 2019, and Oracle GraalVM on June 13, 2023, introducing a new GraalVM Free Terms and Conditions (GFTC) license. GraalVM can substitute for a default JDK on Linux and macOS platforms on x64 and AArch64 CPUs, and on a Windows x64 platform. The release schedule is at the Oracle Help Center and the GraalVM website.

More information Release, Date ...

Components

The GraalVM compiler, Graal, is shipped with the components of a normal Java virtual machine (OpenJDK). Additional components are included in GraalVM to enable new execution modes (GraalVM Native Image) or programming languages (LLVM runtime, GraalVM JavaScript as a potential replacement to the deprecated Nashorn engine, TRegex as a regular expression engine).

GraalVM Compiler

The GraalVM compiler, Graal, is a modern Java (JIT) compiler. It complements or replaces the existing compilers (C1/C2 in HotSpot). In contrast to those existing compilers, Graal is written in a modular, maintainable and extendable fashion in Java itself. It is released under GPL version 2 with the classpath exception.

GraalVM Native Image

GraalVM Native Image is an ahead-of-time compilation technology that produces executable binaries of class files.[11] It is released as an early adopter technology, which means it is production-ready but may include backport incompatible updates in future releases.

This functionality supports JVM-,based languages, but can optionally run dynamic languages, developed on top of GraalVM with the Truffle framework. The executable file does not run on a JVM and uses necessary runtime components such as thread scheduling or GC from a minimal bespoke virtual machine called Substrate VM. Since the resulting native binary includes application classes, JDK dependencies and libraries already, the startup and execution time are reduced significantly.

GraalVM Native Image is officially supported by the Fn, Gluon, Helidon, Micronaut, Picocli, Quarkus, Vert.x and Spring Boot Java frameworks.[12][13]

In September 2016, Oracle detailed plans to add ahead-of-time compilation to the OpenJDK using the GraalVM compiler for Java SE 9.[14][15] This proposal, tracked by JEP 295: Ahead-of-Time Compilation, was included in Java SE 9.[16] The experimental use of GraalVM as a just-in-time compiler was added for the Linux x64 platform for Java SE 10.[17]

In Java SE versions 9 to 15, the jaotc command creates an executable.[18] The experimental -XX:+EnableJVMCIProduct flag enables the use of Graal JIT compiler.[19] The functionality is since available in the Native Image component of standalone GraalVM releases.[20]

Truffle Language Implementation Framework

In association with GraalVM, Oracle Labs developed a language abstract syntax tree (AST) interpreter called "Truffle" which would enable it to implement languages on top of GraalVM.[21][22] Many languages have been implemented in Truffle, including a C interpreter claiming to be about as fast as GCC and Clang.[23]

The Truffle framework and its dependent part, GraalVM SDK, are released under the Universal Permissive License, version 1.0, to encourage the use of the framework for projects that do not want to be bound by the copyright or other parent rights.

Instrumentation-Based Tool Support

A major advantage of the GraalVM ecosystem is language-agnostic, fully dynamic instrumentation support directly built into the VM runtime. Execution events can be captured by API clients with overhead that is extremely low in fully optimized code.[24][25]

The core GraalVM installation provides a language-agnostic debugger, profiler, heap viewer, and others based on instrumentation and other VM support.[26] GraalVM also includes a backend implementation of the Chrome Inspector remote debugging protocol.[27] Although designed originally for JavaScript debugging, it can be used to debug all GraalVM languages from a browser.

Embedding languages

Another advantage of GraalVM is the possibility to embed code from a guest language in Java and write "polyglot" applications.[8] A developer can integrate JavaScript, Python, or other supported languages inside Java source code, granting them the characteristic advantages of those languages. A host Java application and a guest language pass data back and forth in the same memory space. It is possible thanks to the Truffle Language Implementation Framework[28] and the GraalVM Polyglot API. Below is the example how to call a function defined in Python from Java:

try (Context context = Context.create()) {
    Value function = context.eval("python", "lambda x: x + 1");
    assert function.canExecute();
    int x = function.execute(41).asInt();
    assert x == 42;
}

The Python function increments of a unit the value provided and then returns it to the host language. From Java, for security purposes, we ask first if the variable function can be executed via the canExecute() call, and then we invoke the function with the execute() call. Find more examples in the Embedding Languages reference documentation.

Language and runtime support

GraalVM is written in and for the Java ecosystem. It can run applications written in all languages that compile to the Java bytecode format, for example, Java, Scala, Kotlin, and more.

Based on the Truffle Language Implementation Framework, the following additional languages are designed for use with GraalVM:

Support for additional languages can be implemented by users of GraalVM. Some notable third-party language implementations are grCuda,[36] SOMns,[37] TruffleSqueak,[38][39] and Yona.[40]

Adoption

GraalVM is used in various industrial scenarios:

  • Disney:[41] utilizes Native Image technology to reduce the cold-start time of some of its AWS microservices.
  • Facebook:[42] uses GraalVM to speed-up Apache Spark workloads reducing the memory footprint and the utilization of the CPU.
  • Twitter:[43] accelerates some of the microservices of the platform.
  • Goldman Sachs:[44] the international investment bank rewrote its internal programming language Slang via the Truffle framework.

References

  1. "GraalVM FAQ". Archived from the original on 2020-04-13. Retrieved 2018-04-25.
  2. "graal/README.md". GitHub. Retrieved 2018-04-25.
  3. "GraalVM for JDK 22 Release Notes". GraalVM for JDK 22 Release Notes. Oracle Corporation. Retrieved 26 March 2024.
  4. "Why GraalVM". Retrieved 2018-04-25.
  5. "Graal : Un compilateur dynamique pour Java". lemondeinformatique.fr. 2012-02-13. Retrieved 2013-08-23.
  6. "Reference Manual for Polyglot Applications". Archived from the original on 2020-10-23. Retrieved 2018-04-25.
  7. "Native Images". www.graalvm.org. Archived from the original on 2018-04-20.
  8. "Ahead-of-Time (AOT) Compilation May Come to OpenJDK HotSpot in Java 9". InfoQ.com. 2016-10-01. Retrieved 2016-10-06. AOT brings about a new tool called 'jaotc' which uses Graal as the backend (to generate code)
  9. Vladimir Kozlov (2016-09-14). "JDK-8166089: Ahead-of-Time Compilation". Oracle Corporation. Retrieved 2016-10-06. Compile an application's Java classes to native code prior to launching the virtual machine.
  10. Vladimir Kozlov (2016-10-13). "JEP 295: Ahead-of-Time Compilation". Oracle Corporation. Retrieved 2016-10-13. Compile Java classes to native code prior to launching the virtual machine.
  11. Vladimir Kozlov (2017-10-20). "JEP 317: Experimental Java-Based JIT Compiler". Oracle Corporation. Retrieved 2018-01-21. JEP 317: Experimental Java-Based JIT Compiler
  12. "OpenJDK: Graal". openjdk.java.net.
  13. Van De Vanter, Michael; Seaton, Chris; Haupt, Michael; Humer, Christian; Würthinger, Thomas (March 9, 2018). "Fast, Flexible, Polyglot Instrumentation Support for Debuggers and other Tools". The Art, Science, and Engineering of Programming. 2 (3, Article 14): 30. arXiv:1803.10201. doi:10.22152/programming-journal.org/2018/2/14. S2CID 4382172.
  14. "Getting started with Instruments in GraalVM". www.graalvm.org. Retrieved 2019-04-08. Truffle instruments can track very fine-grained VM-level runtime events to profile, inspect, and analyze the runtime behavior of applications running on GraalVM.
  15. "GraalVM Debugging and Monitoring Tools". www.graalvm.org. Archived from the original on 2019-04-25. Retrieved 2019-04-08. GraalVM provides a set of tools for developers, integrators, and IT administrators to debug and monitor GraalVM and deployed applications.
  16. "Chrome DevTools". developers.google.com. Retrieved 2019-04-08. Chrome DevTools is a set of web developer tools built directly into the Google Chrome browser. DevTools can help you edit pages on-the-fly and diagnose problems quickly, which ultimately helps you build better websites, faster.
  17. Prokopec, Aleksandar (2019-12-02). "Announcing GraalWasm — a WebAssembly engine in GraalVM". Medium. Retrieved 2020-01-15.
  18. Niephaus, Fabio; Felgentreff, Tim; Hirschfeld, Robert (2019). "GraalSqueak: Toward a Smalltalk-based Tooling Platform for Polyglot Programming". Proceedings of the 16th ACM SIGPLAN International Conference on Managed Programming Languages and Runtimes - MPLR 2019. ACM Digital Library. pp. 14–26. doi:10.1145/3357390.3361024. ISBN 9781450369770. S2CID 204728643. Retrieved 2020-11-08.

Share this article:

This article uses material from the Wikipedia article GraalVM, and is written by contributors. Text is available under a CC BY-SA 4.0 International License; additional terms may apply. Images, videos and audio are available under their respective licenses.