Background image
Alt Text!
Geschreven door Bjarni Coenen op donderdag, 16 januari 2020

GraalVM: a high performance polyglot Virtual Machine


GraalVM is made at Oracle Labs, which is the department of Oracle for research and development teams. GraalVM is a high performance polyglot virtual machine that supports many languages and is embeddable in native and Java applications. GraalVM is high performance which means it runs your programs fast. It is polyglot meaning that it will support running programs in different languages and that you can mix these languages inside a single program. It is embeddable, so you can enhance your existing application, whether it is a Java application or a native application. The project is open source and is completely written in Java.

Why GraalVM?

First of all, GraalVM is a very good run-time for running your applications. If you are writing or deploying or waiting to finish or process the user request of some data. It is very fast and can be faster than other choices.

GraalVM can compile your programs AOT (Ahead of Time). This will result in a fast/instant startup and a low memory footprint.

You can embed GraalVM in your software to enhance it. For example when you have a library where you want to expose that library to different ecosystems. Where a NodeJS application can experience null pointer exceptions.

GraalVM has interoperability where you can build systems using different languages without having overhead. For example, you can use R for data science in your Java application.

Currently supported are the JVM languages (Kotlin, Scala, Java, Groovy, Closure), Javascript, Python, Ruby, R and there is support for native languages that go through the LLVM toolchain.

You can run your applications in the JVM, you can run them for example as a node application and you can compile your applications AOT where it runs as a native binary without the JVM. You can just put the native binary in a docker container or run it on a server.

Deep Dive into GraalVM

Looking at GraalVM it is very similar to what you expect in the JDK. You have the normal java commands, the javac compiler, jar, the keytool. But there are also some new things like js, node, native-image.

As we look at the architecture GraalVM is built on the Java Hotspot VM, which is normal Java coming from the OpenJDK project. The Java Hotspot VM is enhanced with the GraalVM JIT (Just in Time) compiler that uses the JVM Compiler interface (JVMCI) to enable a third party JIT compiler. Through that, you can run all Java byte-code.

The JIT compiler works as follows:

The AOT compiler works as follows:

The support of other languages goes through another framework called Truffle. Truffle offers an API to implement language interpreters. Those interpreters will be compiled at run-time. The idea behind Truffle is based on the abstract syntax tree.

Truffle Framework: AST (Abstract Syntax Tree)

The Truffle framework can parse a programming language to an AST. Then you start interpreting this tree. During interpretation, profiling feedback is collected and then you specialize your tree. For example, you can specialize in a JavaScript class operation on adding up numbers. When this part is executed a lot it will be evaluated partially and compiled to machine code. When the assumptions based on the profiling are wrong then we have to de-optimize our program and redo the process by specializing again.


GraalVM can run and optimize as a JIT compiler in the context of the JVM. Or GraalVM can compile AOT with the native image utility. In that case, it builds a binary that you can execute. It gives you a great startup and a low memory footprint.

It takes your application, libraries and every needed to run. It runs an analysis where it determines what calls are made and optimizes it. The native-image compiles AOT and creates a binary.

With a JIT compiler, there is a lot to do to start an application. With an AOT compiler, it only needs to load the executable with the prepared heap and start the machine code.

For the memory footprint, this will be the same. With the JIT compiler, there is a lot to be loaded in memory. With the AOT compiler, only the executable and the application needs to be loaded.

Ben jij een IT-professional die zich breder wil ontwikkelen?
Neem dan contact met ons op!
Telefoon: 088-81 81 100

Deel dit Blog artikel