GraalVM is a
Java Development Kit
The Java Development Kit (JDK) is a distribution of Java technology by Oracle Corporation. It implements the Java Language Specification (JLS) and the Java Virtual Machine Specification (JVMS) and provides the Standard Edition (SE) of the Java ...
(JDK) written in Java. The open-source distribution of GraalVM is based on
OpenJDK
OpenJDK (Open Java Development Kit) is a free and open-source implementation of the Java Platform, Standard Edition (Java SE). It is the result of an effort Sun Microsystems began in 2006, four years before the company was acquired by Oracle Corp ...
, 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
In computer science, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded instruction (computer science), in ...
can only run on the platform it was compiled for.
It provides additional
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s and execution modes. The first production-ready release, GraalVM 19.0, was distributed in May 2019.
The most recent release is GraalVM for JDK 23, made available in September 2024.
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
ECMAScript (; ES) is a standard for scripting languages, including JavaScript, JScript, and ActionScript. It is best known as a JavaScript standard intended to ensure the interoperability of web pages across different web browsers. It is stan ...
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.
* To reduce the startup time of
JVM
A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally descri ...
-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
A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally descri ...
-based host application.
* To enable mixing of code from any programming language in a single application, billed as a "polyglot application."
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.
Graal was included in HotSpot-based JDK releases such as
OpenJDK
OpenJDK (Open Java Development Kit) is a free and open-source implementation of the Java Platform, Standard Edition (Java SE). It is the result of an effort Sun Microsystems began in 2006, four years before the company was acquired by Oracle Corp ...
from Java SE 9 through 15, to provide experimental ahead-of-time compilation. The option also enabled the use of Graal as a replacement for the server compiler (named "C2"). 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", 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.
Components
The GraalVM compiler, Graal, is shipped with the components of a normal Java virtual machine (
OpenJDK
OpenJDK (Open Java Development Kit) is a free and open-source implementation of the Java Platform, Standard Edition (Java SE). It is the result of an effort Sun Microsystems began in 2006, four years before the company was acquired by Oracle Corp ...
). 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
A regular expression (shortened as regex or regexp), sometimes referred to as rational expression, is a sequence of characters that specifies a match pattern in text. Usually such patterns are used by string-searching algorithms for "find" ...
engine).
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.
Native Image
GraalVM Native Image is an ahead-of-time compilation technology that produces executable binaries of class files. 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
Eclipse Vert.x is a Polyglot (computing), polyglot event-driven architecture, event-driven application framework that runs on the Java Virtual Machine.
Similar environments written in other programming languages include Node.js for JavaScript, Tw ...
and
Spring Boot Java frameworks.
In September 2016, Oracle detailed plans to add ahead-of-time compilation to the OpenJDK using the GraalVM compiler for
Java SE 9. This proposal, tracked b
JEP 295: Ahead-of-Time Compilation was included in Java SE 9. The experimental use of GraalVM as a
just-in-time compiler
In computing, just-in-time (JIT) compilation (also dynamic translation or run-time compilations) is compiler, compilation (of Source code, computer code) during execution of a program (at run time (program lifecycle phase), run time) rather than b ...
was added for the
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
x64 platform for
Java SE 10.
In Java SE versions 9 to 15, the command creates an executable. The experimental flag enables the use of Graal JIT compiler. The functionality is since available in the Native Image component of standalone GraalVM releases.
Truffle Language Implementation Framework
In association with GraalVM, Oracle Labs developed an
abstract syntax tree (AST) interpreter called "Truffle" that enables it to implement languages on top of GraalVM.
Many languages have been implemented in Truffle, including a
C interpreter claiming to be about as fast as
GCC and
Clang
Clang () is a compiler front end for the programming languages C, C++, Objective-C, Objective-C++, and the software frameworks OpenMP, OpenCL, RenderScript, CUDA, SYCL, and HIP. It acts as a drop-in replacement for the GNU Compiler ...
.
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
Instrumentation is a collective term for measuring instruments, used for indicating, measuring, and recording physical quantities. It is also a field of study about the art and science about making measurement instruments, involving the related ...
support directly built into the VM runtime. Execution events can be captured by
API
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build ...
clients with overhead that is extremely low in fully optimized code.
The core GraalVM installation provides a language-agnostic debugger, profiler, heap viewer, and others based on instrumentation and other VM support.
GraalVM also includes a backend implementation of the Chrome Inspector remote debugging protocol. 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.
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
and the GraalVM Polyglot API. Below is the example how to call a function defined in Python from Java:
try (Context context = Context.create())
The Python function increments its input value by one and returns the result 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 th
Embedding Languages reference documentation
Language and runtime support
GraalVM is written in and for the
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
ecosystem. It can run applications written in all languages that compile to the
Java bytecode
Java bytecode is the instruction set of the Java virtual machine (JVM), the language to which Java and other JVM-compatible source code is compiled. Each instruction is represented by a single byte, hence the name bytecode, making it a compact ...
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:
* GraalJS: An
ECMAScript
ECMAScript (; ES) is a standard for scripting languages, including JavaScript, JScript, and ActionScript. It is best known as a JavaScript standard intended to ensure the interoperability of web pages across different web browsers. It is stan ...
2023 compliant JavaScript runtime, with support for
Node.js
* GraalPy: A
Python 3 language implementation
* GraalVM LLVM Runtime (''Sulong''): An
LLVM
LLVM, also called LLVM Core, is a target-independent optimizer and code generator. It can be used to develop a Compiler#Front end, frontend for any programming language and a Compiler#Back end, backend for any instruction set architecture. LLVM i ...
bitcode interpreter implementation
* GraalWasm: A
WebAssembly
WebAssembly (Wasm) defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating communication between such programs and their host environment.
The main goal of ...
implementation
* TruffleRuby: A
Ruby
Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
language implementation with preliminary support for
Ruby on Rails
* FastR: An
R language implementation
Support for additional languages can be implemented by users of GraalVM. Some notable third-party language implementations are grCuda, SOMns, TruffleSqueak, and Yona.
Yona Language
/ref>
References
External links
*
{{Oracle FOSS
Cross-platform software
Java compilers
Java platform software
Java virtual machine
Oracle software
Stack-based virtual machines