JEP 483: Ahead-of-Time Class Loading & Linking. Project Leyden in JDK 24

Transcript 


In this video, we'll look at JEP 483: Ahead-of-Time Class Loading and Linking, which is targeted for JDK 24 and marks the initial introduction of Project Leyden into the mainline OpenJDK. When Java applications start, necessary application classes and core JVM classes must be loaded and initialized. There can be thousands of classes, so this process affects the startup times of Java applications. The worst part is that this process repeats every time the application starts.

One way to deal with this issue is to use Application Class Data Sharing (AppCDS), a JVM feature that reads and parses a set of application and JVM classes, storing this data in a read-only archive. When the application starts, the JVM reads the data from the archive, speeding up the startup process. Ahead-of-Time (AOT) class loading and linking goes even further. It not only reads and parses but also loads and links classes, storing this data in an AOT cache. As a result, the JVM has even less work to do at startup. This feature aligns with the overall goal of Project Leyden, which aims to shift some computations from the production run to earlier stages, such as trial runs. AOT class loading and linking is the first step towards introducing Project Leyden to OpenJDK.

You create the AOT cache once, and it can be reused every time your application starts. This feature is compatible with any Java application and doesn’t require changes to the application code. The only requirement is to perform a training run for your application to record its AOT configuration. The more efficient the training run, the better the resulting AOT cache. The training run should mimic the production run, allowing the application to fully configure itself and execute production code paths.

Now, let’s try this feature with the early access builds of JDK 24. For this experiment, I’ve downloaded early access builds of JDK 24, which you can also get for your platform. Note that the results we’ll get are preliminary and may change when stable builds are released. But we’re just testing the waters, right? Take any Spring app you like. I’m using a Spring Boot-based CRUD application that manages personal tasks. It’s a simple app with basic functionality. You can follow along or experiment with your own application.

Let’s first create a JAR file using maven clean package. Running the executable JAR in production is not recommended by the Spring team, so we’ll create an exploded JAR instead. For this, we’ll use the Djarmode=tools option to extract the JAR. Now we have our extracted JAR with the lib subdirectory and the JAR file itself. Let’s first run the application with the JAR file to see how fast it starts without any optimizations. As you can see, the application started in about two seconds.

All right, let’s get down to business. To create an AOT cache, we need to perform two steps (although it’s planned to merge them into one step in the future). First, conduct a trial run of your application with two flags: -XX:AOTMode=record and -XX:AOTConfiguration to record its AOT configuration into the file app.aotconf. Now, push some buttons in the application so it performs useful operations. Next, use the configuration file to create the cache. For this, use three flags: -XX:AOTMode=create, -XX:AOTConfiguration pointing to app.aotconf, and -XX:AOTCache to create the cache named app.aot. This step doesn’t run the application; it only creates the cache.

Now we can run the application. This time, we only need one flag: -XX:AOTCache pointing to the cache file we created earlier. As you can see, the application started in just one second, which is pretty cool.

In this video, we explored a new JDK feature, Ahead-of-Time Class Loading and Linking, aimed at reducing the startup times of Java applications. If you like this video, subscribe to our channel. And until next time!

Summary

JEP 483 introduces Ahead-of-Time (AOT) Class Loading and Linking in JDK 24, which enhances Java application startup times by loading and linking classes ahead of time and storing them in a reusable AOT cache. This feature, part of Project Leyden, reduces the JVM's workload during startup without requiring changes to application code, though a training run mimicking production is needed to create an efficient cache. Early tests with a Spring Boot app showed significant improvements, cutting startup time from two seconds to just one second.

About Catherine

Java developer passionate about Spring Boot. Writer. Developer Advocate at BellSoft

Social Media

Videos
card image
Dec 9, 2024
How to use CRaC with Spring Boot in a Docker Container

CRaC (Coordinated Restore at Checkpoint) is an OpenJDK project designed to significantly reduce startup and warmup times of Java applications to milliseconds. This tutorial demonstrates using CRaC with a Spring Boot application running in a Docker container, specifically the Spring Boot Petclinic app (version 3.2 or later).

Videos
card image
Nov 29, 2024
OpenJDK Projects That We Anticipate

OpenJDK is actively evolving, with projects like Leyden, Valhalla, Babylon, and Lilliput aiming to enhance Java's performance and capabilities. Leyden focuses on faster startup and warmup by reusing precompiled code, while Valhalla introduces value objects, primitive classes, and specialized generics for better memory and runtime efficiency.

Further watching

Videos
card image
Jan 14, 2025
How to use AppCDS with Spring Boot

This tutorial demonstrates how to use Application Class Data Sharing (AppCDS) and Ahead-of-Time (AOT) processing with Spring Boot applications to reduce startup time by 40–50%. AppCDS creates an archive of parsed classes for faster loading, requiring no code changes, and works both locally and in containers. The tutorial covers building optimized Docker images using Dockerfiles or Buildpacks for efficient deployment and improved performance.

Videos
card image
Dec 28, 2024
JDK 24: The New Features in Java 24

JDK 24 is in Rampdown Phase One, which means, we know all the JEPs targeted to this release. And there are a lot of them, so it is time to discuss this new Java release!

Videos
card image
Dec 17, 2024
Master Java Profiling: Tools, Techniques, and Real-World Tips

Java profiling allows to rapidly identify and fix performance bottlenecks in your program. In this video we explain what is profiling, introduce popular profiling tools, list their pros and cons, and provide useful tips and code examples.