GraalVM Tutorial

Jakob Jenkov
Last update: 2022-01-05

GraalVM is a Java Virtual Machine that is capable of executing multiple languages (JavaScript, Python, Ruby, LLVM, Web Assembly etc) within the same application. GraalVM is also able to compile your Java (or multi-language (polyglot)) application to a native executable for Windows, Linux, MacOS, iOS and Android (and Raspberry PI - since it runs Linux).

GraalVM is made by Oracle and is available in a free community edition and a commercial enterprise edition. The main difference between these two versions is that the enterprise edition of GraalVM has higher performance, and a few extra tools (as far as I remember).

GraalVM Website

You can download GraalVM from its website at:

https://www.graalvm.org/

GraalVM Main Parts

GraalVM consist of the following important parts:

  • A Java Virtual Machine
  • Other language virtual machines
  • The Truffle language implementation framework
  • The polyglot API
  • Command line tools for building native images

I will go into a bit more detail about these parts in the following sections.

Java Virtual Machine

GraalVM is at its core a virtual machine. It's first language was Java - meaning GraalVM started out as a Java Virtual Machine (Java VM / JVM). You can download GraalVM from its website and unzip it into a directory, and use it like if you had downloaded and unzipped an OpenJDK version of the Java Virtual Machine.

One Virtual Machine - Multiple Languages

GraalVM is able to run multiple languages - also within the same application. In addition, GraalVM has command line tools to start up JavaScript and Python applications - just like you would with Node.js or the Python interpreter. On the outside it may look like different virtual machines, but on the inside all the languages are run by the same VM.

GraalVM Language Support

GraalVM already has language implementations for the languages listed below, and more are probably coming in the future:

  • Java
  • JavaScript
  • Python
  • Ruby
  • R
  • LLVM
  • Web Assembly (Wasm)

Some of these languages may have to be installed after you have installed GraalVM. You can see how to install the following languages here:

Truffle Language Implementation Framework

GraalVM Truffle is a Java library for implementing programming languages that can be executed by GraalVM. You do so by building a language interpreter using the Truffle library.

Polyglot API

The GraalVM polyglot API enables you to call a JavaScript, Python, Ruby and other languages implemented using the Truffle library from inside your Java applications. If you use GraalVM as a Java SDK, then the polyglot API classes are already available on the classpath.

I have explained the GraalVM polyglot API in a bit more detail in its own text about GraalVM Polyglot API.

Command Line Tools for Building Native Images

GraalVM comes with a set of command line tools that can build your Java or polyglot application into a native executable image for several different operating systems, including:

  • Windows
  • Linux
  • MacOS
  • iOS
  • Android
  • Raspberry Pi (because it runs Linux)

Raspberry Pi and iPhone's run on ARM CPUs, so GraalVM can build native images for Intel, AMD and ARM chipsets.

Jakob Jenkov

Featured Videos

Core Software Performance Optimization Principles

Thread Congestion in Java - Video Tutorial















Close TOC

All Trails

Trail TOC

Page TOC

Previous

Next