- The HotSpot JVM which i shared in the previous blog is suited and optimized for traditional on-premise based applications to provide high throughput and stability.
- New modern applications are being built for cloud as distributed systems developed using microservices, event driven, asynchronous and reactive design which should scale quickly and efficiently
- HotSpot JVM and JIT compiler is not an ideal environment to support such use cases and develop cloud native solutions, because of the way the compiler works. It takes lot of memory and CPU . More about that on this blog.
- For customers to leverage the full potential of clouds pay per use model , it is important to build applications with a smaller footprint, so that they don’t consume too much RAM and CPU.
- Small footprint means less resources and therefore less cost to run such applications which is an important metric for many organizations.
- Along with smaller footprint it is also important for applications to quickly boot up to start handling incoming request otherwise a good amount of traffic will be lost by the time application boots up
- Polyglot or an application to be developed using multiple programming languages is a reality. You may have a data processing being done by a Python program and invoke a Java based API to do some core business logic.
- It is important for these applications developed in multiple languages to seamlessly exchange messages between them
- Clearly HotSpot JVM in its current form is not built to handle these scenarios.
- GraalVM is a VM completely developed in Java to solve these problems and make Java a preferred language for cloud .
- GraalVM is a drop-in replacement for JDK, which means that all the applications that are currently running on JDK should run on GraalVM without any application code changes.
- It provides an extensible framework called Truffle that allows any language to be built and run on the platform.
- GraalVM is available as Community and Enterprise Editions.
- Community Edition (CE) is an open source edition built as an OpenJDK distribution.
- Enterprise Edition (EE) is a licensed version under the GraalVM OTN license agreement. This is free for evaluation and building non-production applications.
- High level architecture components of GraalVM are
- JVM HotSpot is the regular Java HotSpot VM. The C2 compiler, which is part of the HotSpot VM, is replaced with the Graal JIT compiler implementation. The Graal JIT compiler is an implementation of Java Virtual Machine Compiler Interface (JVMCI) and plugs into the Java VM.
- Java Virtual Machine Compiler Interface (JVMCI), JVMCI was introduced in Java 9 and this interface allowed compilers to be implemented as plugins that JVM can call for dynamic compilation. It provides an API and a protocol to build compilers with custom implementations and optimizations.
- The Graal compiler is built on JVMCI and provides a better JIT compiler implementation, with further optimizations. The Graal compiler also provides an Ahead Of Time (AOT) Graal AOT compilation option to build native images that can run standalone with embedded VMs.
- One of the differences between the JVM JIT compiler and Graal JIT is that Graal JIT is built to optimize the intermediate code representation (abstract syntax tree (AST))
- GraalVM is capable of optimizing and running code written in any language, as long as the code can be converted into an AST.
- The Truffle framework or Truffle is the underlying framework providing the polyglot programming experience on GraalVM. The Truffle framework is an open source library for building the interpreters and the tools/utilities (such as integrated development environments, debuggers, and profilers).
- Truffle provides the Polyglot Interoperability Protocol. This protocol defines the message that each language needs to implement and supports the passing of data between the Polyglot applications.
- Sulong is a system to execute LLVM-based languages (like C/C++) on a Java Virtual Machine. It uses the Truffle language implementation framework and Graal compiler to implement dynamic optimization
- Substrate VM is responsible for running the native image. (A native image) does not run on the Java VM, but includes necessary components like memory management and thread scheduling from a different virtual machine, called “Substrate VM”. Substrate VM is the name for the runtime components (like the deoptimizer, garbage collector, thread scheduling etc.). The resulting program has faster startup time and lower runtime memory overhead compared to a Java VM.
GraalVM’s performance, ability to generate optimized machine code with smaller footprint and polyglot support makes Java based applications and services once again a preferred technology to build cloud native solutions.
Thanks.. Please share your comments and thoughts !
5 thoughts on “GraalVM : A JVM written in Java for high performant applications !!”
As always very helpful 🙂
Thank You !!!!!!
sir, whats’t tools do you use with those diagram. it’s pretty good.
Hey Thanks, i use excalidraw for the diagrams. They have a docker version – https://hub.docker.com/r/excalidraw/excalidraw which can be used to run this locally and create diagrams.