Revolutionizing Java with GraalVM Native Image

Click for: original source

GraalVM has caused a revolution in Java development since it launched three years ago. One of the most discussed features of GraalVM is Native Image, which is based on an ahead-of-time (AOT) compilation. By Alina Yurenko and Karsten Silz.

Native image build process

Source: https://www.infoq.com/articles/native-java-graalvm

Java dominates enterprise applications. But in the cloud, Java is more expensive than some competitors. Native compilation makes Java in the cloud cheaper: It creates applications that start much faster and use less memory.

The article then walks you over:

  • Traditional execution of Java applications
  • GraalVM for the Win
  • How native image works
  • Taking Java startup performance to the next level
  • Peak performance on par with JVM

… and much more. We liked the comparison of startup time effect of native image modes and JIT.

JIT AOT
Operating system loads the JVM executable Operating system loads executable with prepared heap
VM loads classes from the file system Application starts immediately with optimized machine code
Bytecode is verified
Bytecode interpretation starts
Static initializers run
First-tier compilation (C1)
Profiling metrics gathered
… (after some time)
Second-tier compilation (C2/ Graal compiler)
Finally running with optimized machine code)

A native executable requires neither the JVM and its JIT compilation infrastructure nor memory for compiled code, profile data, and bytecode caches. All it needs is memory for the executable and the application data. Typical savings looks like 200 MB in JIT mode vs. 40 MB for the native executable. Good read!

[Read More]

Tags java programming kotlin jvm scala performance