Java programming language was created to enhance developer productivity and to overcome difficult programming processes like memory pointers in C and C++ language. Since Java is dynamic it can run on any platform as it is compiled to byte code and that can go through just in time compilation by JVM to native machine code. In short, JVM is the key part that gives immense power to the Java language, and it continues to be the number one programming language.
Need for GraalVM
The software and hardware world has changed a lot and time has come for a major change in the VM part. The new alternative should perform better in the cloud-native computing world which should eventually help companies to save CPU time and cut costs. When we break monolith applications into microservices and deploy them to the cloud they can unintentionally consume more memory and CPU time even when the applications are idle. Also, today all the languages in the market do not have an efficient run time environment and they do not have a unified virtual machine. The answer for increasing the efficiency and unification of VMs is the GraalVM engine. GraalVM is a groundbreaking multilingual virtual machine based on OpenJDK – Hotspot, developed in Java.
Brief History
GraalVM development started as a research project in Oracle labs. The idea is to create a Java virtual machine in Java language itself and free it from the complexities of C++ language and get advantages of meta-circular interpreters (MCI). In a short time team understood that rewriting the whole VM in Java will take an ample amount of team, they decided to change only the compiler part and connect it to the exiting Hotspot VM and reuse the Hotspot run time. The hotspot is an existing JVM for desktop and server machines. So GraalVM compiler was created after 7 years of research by Oracle labs. The first version of Oracle GraalVM Enterprise Edition was announced on May 8, 2019, and the latest stable version is 22.0.0 released on January 18, 2022, with a major change that GraalVM Enterprise distributions will be based on JDK 11 and 17 only with this release and upcoming releases. The community edition is also available for an open-source license.
Advantages of GraalVM
- Faster: GraalVM will make applications faster. We can take the even existing production running applications in languages like Java, Scala, Kotlin, etc., and make it comparable to GraalVM and it’s going to give a good performance improvement. The main part of GraalVM is a GraalVM compiler written in Java language. This compiler has two modes of execution, Just in Time compilation (JIT) and Ahead of Time compilation (AOT). JIT compiler mode can generate native code from Java byte code which provides a faster and optimized compilation to native code. AOT compiler mode compiles JVM-based applications to native executable binaries and then the application can run even in a non-JVM environment.
- Cloud-Native Support with GraalVM Native Image: GraalVM helps Java to perform better in cloud-native and serverless deployment environments. This is possible due to the compilation of Java applications ahead of time to native binaries they can start up instantly and deliver good performance with no warmup time. This functionality supports JVM-based languages but can be applied for dynamic languages as well, developed on top of GraalVM with the Truffle framework. This native image option gives a small memory footprint as it takes only fewer resources when compared to otherwise taken by JVM. GraalVM Native image option has been embraced by leading frameworks like Spring, Micronaut, Helidon, and Quarkus.
- Polyglot enabled: GraalVM enables developers to create polyglot software programs that can transfer attributes between languages using the Truffle framework. For example, an R language application can run on the same JVM as same a Java application. A JVM host-based application and a third-party language can communicate with each other and transfer data to each other in the same computing memory area. Polyglot interoperability utility allows GraalVM to enable information sharing between any mixture of languages without requiring them to sense one another. With the Language API available in the Truffle framework, you can implement a language interpreter on top of GraalVM.
Recent Developments
The last stable release was version 22.0.0 on January 18, 2022.
- Due to speculative guard movement optimization recently, programs run even faster now in GraalVM
- Introduction of the Multilingual Engine (MLE) built on the GraalVM foundation. As a result of this Oracle Database can execute JavaScript
- Another big update recently was the release of Java on Truffle, also known as the Espresso project. Java on Truffle is a minified JVM that includes all major elements of a VM which is an implementation of the JVM Specification, JSE 8, and JSE 11, built upon GraalVM as a Truffle interpreter
- Improvement of GraalVM’s Web Assembly runtime compatibility with the Truffle framework is done by using the new Frame API
More updates are coming up which will still improve the computing power usage and cost expenditures along with fostering the polyglot programming culture.