Effectively running Java on ServerlessGraalVM Native Image2 min

GraalVM is a high-performance JDK designed to accelerate the execution of applications written in Java and other JVM languages while also providing run times for JavaScript, Python, and a number of other popular languages. GraalVM offers two ways to run Java applications:

  1. On the HotSpot JVM with Graal just-in-time (JIT) compiler, or
  2. As an ahead-of-time (AOT) compiled native executable

GraalVM Native Image

GraalVM native image uses the second approach mentioned above. It compiles Java code ahead-of-time to a binary executable. A native executable includes only the code required at run time, that is the application classes, standard-library classes, the language runtime, and statically-linked native code from the JDK.

Packaging GraalVM native image for AWS Lambda

GraalVMLambda

Normal JVM versus GraalVM Native image on AWS Lambda:

JVM GraalVM Native image
Compiled just-in-time (JIT) Compiled ahead-of-time (AOT)
Faster compile time Slower compile time because of AOT optimizations
Deployment with managed runtime Deployment with custom runtime
Dynamic Language Features (runtime proxies, reflection) Closed-world model, dynamic features need special treatment
Slower startup Faster startup
Uses more resources Uses fraction of resources, cheaper to run
Bigger artifact size Smaller artifact size
Higher cold start Delivers peak performance immediately
Wider attack surface Reduced attack surface because of close-world model

Refer the guide to learn more about the special treatments GraalVM native does to support dynamic features.


Created by:

Dhiraj Mahapatro
Dhiraj MahapatroPrincipal Specialist SA, Serverless, AWS.
Lavanya Tangutur
Lavanya TanguturSr. Technical Account Manager