GraalVM - Introduction to the super VM

Akshay Mhetre
kodeyoga
Published in
2 min readApr 5, 2021
Image by: Pixabay

Java ecosystem has continuously been progressive with the introduction of new release policy. Changes are happening in all the aspects of the ecosystem, be it language or performance or security.

One of the striking entry to this ecosystem is GraalVM, a high-performance runtime improving applications throughput. Many frameworks have already adopted this VM, which makes it a silver bullet for modern JVM based applications.

What is GraalVM?

You can think GraalVM as modified/improved HotSpot JVM written in Java with introduction of following features:

  • Graal Compiler - New compiler intended to replace the existing C2 compiler with ability of AOT (Ahead of time compilation)
  • Truffle library — Making JVM polyglot and allow interoperability with different languages like (Javascript, Ruby, Python). With this you can also implement your own language.
  • Native Image generation (Substrate VM)- Using AOT, one can compile Java to native binary executables

This native code can run faster on conventional processors instead of JVM interpreting generated bytecode. JVM having JIT(Just In Time) compiler, which analyses Java bytecode while execution and converts frequently executing code to native code. To do that, it uses profiling information collected during execution. However, AOT directly converts to native code aims to improve warm up period.

Key Benefits we get

  • Fast Startup - With native image provision, all classes are already loaded and linked. This makes it a good fit for serverless application.
  • Low Memory Footprint - Again due to native image provision, no need to keep lot of profiling data for JIT and metadata for classloaders.

Let’s validate this

Here is a sample application created using Micronaut for demonstration purpose.

If I try to run application jar, it takes 5.9 sec to start the server and associated process takes 372 MB of memory :

If I create a native image using GraalVM with following command:

native-image -jar *-all.jar

This create an executable binary which takes 22ms to start the server and associated process takes 26MB of memory:

Final Thoughts

GraalVM provide interesting features which seems to significantly help applications which follow serverless or microservices architecture. There are still some open challenges to be dealt with, specially supporting the libraries/frameworks which are still using dynamic classloading and reflections.

However, big companies like Twitter already started using GraalVM in production. Spring boot has also introduced support of GraalVM to build native image for spring boot applications. Its adoption is increasing day by day, and I hope more and more development teams will take advantage of the features provided by GraalVM.

In short, this has to be in the watchlist of every developer.

Akshay Mhetre is an experienced, hands-on software architect at KodeYoga, he is involved in the architecture, design, and implementation of microservices, distributed systems and high performance cloud solutions.

--

--