graal
GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
Top Related Projects
GraalVM CE binaires built by the GraalVM community
JDK main-line development https://openjdk.org/projects/jdk
Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Eclipse Temurin™ build scripts - common across all releases/versions
Alibaba Dragonwell8 JDK
Quick Overview
GraalVM is a high-performance runtime that provides significant improvements in application performance and efficiency. It supports multiple programming languages and execution modes, including ahead-of-time compilation to native executables. GraalVM is designed to accelerate Java applications and enable polyglot programming.
Pros
- Improved performance for Java applications
- Support for multiple programming languages (Java, JavaScript, Python, Ruby, R, etc.)
- Native image compilation for faster startup and lower memory footprint
- Advanced optimization techniques, including partial evaluation and aggressive inlining
Cons
- Steep learning curve for advanced features
- Some limitations in native image support for certain Java frameworks
- Potential compatibility issues with some existing Java libraries
- Larger installation size compared to standard JVMs
Code Examples
- Hello World in Java using GraalVM
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, GraalVM!");
}
}
- Polyglot programming example (Java and JavaScript)
import org.graalvm.polyglot.*;
public class PolyglotExample {
public static void main(String[] args) {
Context context = Context.create("js");
Value result = context.eval("js", "40 + 2");
System.out.println(result.asInt()); // Outputs: 42
}
}
- Native image compilation
# Compile Java code
javac HelloWorld.java
# Generate native image
native-image HelloWorld
# Run the native executable
./helloworld
Getting Started
- Download and install GraalVM from the official website: https://www.graalvm.org/downloads/
- Set the
JAVA_HOME
environment variable to point to the GraalVM installation directory - Add GraalVM's
bin
directory to your system'sPATH
- Verify the installation by running:
java -version
- To use native image compilation, install the Native Image tool:
gu install native-image
Now you're ready to start using GraalVM for your Java applications and explore its polyglot capabilities.
Competitor Comparisons
GraalVM CE binaires built by the GraalVM community
Pros of graalvm-ce-builds
- Provides pre-built binaries for easier installation and use
- Focuses on the Community Edition, which is free and open-source
- Offers more frequent releases and updates
Cons of graalvm-ce-builds
- Limited to Community Edition features, lacking some enterprise capabilities
- May have less comprehensive documentation compared to the main Graal repository
- Potentially slower to incorporate cutting-edge features and experiments
Code Comparison
graal:
@Snippet
static int sumArray(int[] array) {
int sum = 0;
for (int i = 0; i < array.length; i++) {
sum += array[i];
}
return sum;
}
graalvm-ce-builds:
public static int sumArray(int[] array) {
return Arrays.stream(array).sum();
}
The graal repository often contains more low-level and experimental code, while graalvm-ce-builds focuses on stable, production-ready implementations. The code examples demonstrate this difference, with graal showing a more traditional loop-based approach and graalvm-ce-builds utilizing Java 8+ stream operations for concise and potentially more optimized code.
JDK main-line development https://openjdk.org/projects/jdk
Pros of JDK
- Broader community support and contributions
- More extensive documentation and resources
- Wider compatibility with existing Java applications
Cons of JDK
- Slower release cycle for new features
- Less optimized for specific use cases (e.g., microservices)
Code Comparison
JDK (HotSpot VM):
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Graal (GraalVM):
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
The code for a basic "Hello, World!" program is identical for both JDK and Graal. However, the underlying execution and optimization mechanisms differ:
- JDK uses the HotSpot VM, which performs just-in-time (JIT) compilation.
- Graal uses GraalVM, which can perform ahead-of-time (AOT) compilation and offers polyglot capabilities.
While the source code may look the same, Graal can potentially offer better performance for certain applications, especially those involving microservices or requiring native executables. JDK, on the other hand, provides a more standardized and widely supported environment for general Java development.
Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Pros of OpenJ9
- Lower memory footprint and faster startup times
- Better performance in cloud and containerized environments
- More extensive garbage collection options and tuning capabilities
Cons of OpenJ9
- Smaller community and ecosystem compared to GraalVM
- Less focus on ahead-of-time compilation and native image generation
- Limited support for non-Java languages
Code Comparison
OpenJ9:
// Example of OpenJ9-specific JIT compiler directive
@com.ibm.jit.JITCompilerDirective(
hotness = JITCompilerDirective.Hotness.SCORCHING,
name = "optimizeMethod"
)
public void performCriticalOperation() {
// Method implementation
}
GraalVM:
// Example of GraalVM-specific Truffle language implementation
@ExportLibrary(InteropLibrary.class)
public class CustomLanguageObject implements TruffleObject {
@ExportMessage
boolean isExecutable() {
return true;
}
}
Both projects aim to improve Java performance, but they take different approaches. OpenJ9 focuses on optimizing runtime performance and memory usage, making it well-suited for cloud deployments. GraalVM, on the other hand, emphasizes polyglot capabilities and ahead-of-time compilation, offering more flexibility for diverse language ecosystems and native image generation.
Eclipse Temurin™ build scripts - common across all releases/versions
Pros of Temurin-build
- Open-source and community-driven, ensuring transparency and collaborative development
- Supports multiple platforms and architectures, offering wider compatibility
- Provides a fully-featured JDK build system with extensive documentation
Cons of Temurin-build
- May have a steeper learning curve for newcomers compared to Graal
- Potentially slower release cycles due to community-driven development process
- Limited focus on advanced JVM technologies like ahead-of-time compilation
Code Comparison
Temurin-build (build script excerpt):
#!/bin/bash
set -eu
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$SCRIPT_DIR/common/common.sh"
Graal (Java code snippet):
@Snippet
public static int add(int a, int b) {
return a + b;
}
While Temurin-build focuses on build scripts and infrastructure, Graal emphasizes Java code optimization and compilation. Temurin-build's scripts are primarily shell-based, whereas Graal's core functionality is implemented in Java.
Temurin-build is ideal for those seeking a community-driven, open-source JDK build system with broad platform support. Graal, on the other hand, excels in advanced JVM technologies and performance optimizations, making it suitable for projects requiring cutting-edge Java performance.
Alibaba Dragonwell8 JDK
Pros of Dragonwell8
- Specifically optimized for large-scale, high-performance Java applications
- Includes additional features like enhanced monitoring and diagnostics tools
- Focuses on stability and reliability for enterprise-level deployments
Cons of Dragonwell8
- Limited to Java 8, while Graal supports multiple Java versions
- Smaller community and ecosystem compared to Graal
- Less frequent updates and potentially slower adoption of new Java features
Code Comparison
Dragonwell8 (JIT compilation example):
public static int sum(int a, int b) {
return a + b;
}
Graal (Polyglot example):
Context context = Context.create();
Value result = context.eval("js", "40 + 2");
System.out.println(result.asInt()); // Outputs: 42
While both projects aim to improve Java performance, they take different approaches. Dragonwell8 focuses on optimizing Java 8 for large-scale applications, while Graal offers a more versatile polyglot runtime with support for multiple languages and Java versions. The code examples highlight Dragonwell8's traditional JIT compilation approach versus Graal's polyglot capabilities.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
GraalVM is a high-performance JDK distribution that compiles your Java applications ahead of time into standalone binaries. These binaries start instantly, provide peak performance with no warmup, and use fewer resources. You can use GraalVM just like any other Java Development Kit in your IDE.
The project website at https://www.graalvm.org/ describes how to get started, how to stay connected, and how to contribute.
Documentation
Please refer to the GraalVM website for documentation. You can find most of the documentation sources in the docs/ directory in the same hierarchy as displayed on the website. Additional documentation including developer instructions for individual components can be found in corresponding docs/ sub-directories. The documentation for the Truffle framework, for example, is in truffle/docs/. This also applies to languages, tools, and other components maintained in related repositories.
Get Support
- Open a GitHub issue for bug reports, questions, or requests for enhancements.
- Join the GraalVM Slack to connect with the community and the GraalVM team.
- Report a security vulnerability according to the Reporting Vulnerabilities guide.
Repository Structure
This source repository is the main repository for GraalVM and includes the following components:
Directory | Description |
---|---|
.devcontainer/ | Configuration files for GitHub dev containers. |
.github/ | Configuration files for GitHub issues, workflows, …. |
compiler/ | Graal compiler, a modern, versatile compiler written in Java. |
espresso/ | Espresso, a meta-circular Java bytecode interpreter for the GraalVM. |
regex/ | TRegex, a regular expression engine for other GraalVM languages. |
sdk/ | GraalVM SDK, long-term supported APIs of GraalVM. |
substratevm/ | Framework for ahead-of-time (AOT) compilation with Native Image. |
sulong/ | Sulong, an engine for running LLVM bitcode on GraalVM. |
tools/ | Tools for GraalVM languages implemented with the instrumentation framework. |
truffle/ | GraalVM's language implementation framework for creating languages and tools. |
visualizer/ | Ideal Graph Visualizer (IGV), a tool for analyzing Graal compiler graphs. |
vm/ | Components for building GraalVM distributions. |
wasm/ | GraalWasm, an engine for running WebAssembly programs on GraalVM. |
Related Repositories
GraalVM provides additional languages, tools, and other components developed in related repositories. These are:
Name | Description |
---|---|
FastR | Implementation of the R language. |
GraalJS | Implementation of JavaScript and Node.js. |
GraalPy | Implementation of the Python language. |
GraalVM Demos | Several example applications illustrating GraalVM capabilities. |
Native Build Tools | Build tool plugins for GraalVM Native Image. |
SimpleLanguage | A simple example language built with the Truffle framework. |
SimpleTool | A simple example tool built with the Truffle framework. |
TruffleRuby | Implementation of the Ruby language. |
License
GraalVM Community Edition is open source and distributed under version 2 of the GNU General Public License with the “Classpath” Exception, which are the same terms as for Java. The licenses of the individual GraalVM components are generally derivative of the license of a particular language (see the table below).
Component(s) | License |
---|---|
Espresso, Ideal Graph Visualizer | GPL 2 |
GraalVM Compiler, SubstrateVM, Tools, VM | GPL 2 with Classpath Exception |
GraalVM SDK, GraalWasm, Truffle Framework, TRegex | Universal Permissive License |
Sulong | 3-clause BSD |
Top Related Projects
GraalVM CE binaires built by the GraalVM community
JDK main-line development https://openjdk.org/projects/jdk
Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Eclipse Temurin™ build scripts - common across all releases/versions
Alibaba Dragonwell8 JDK
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot