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
Jan 30, 2025
Dockerize Spring Boot Wisely: 6 tips to improve the container images of your Spring Boot apps

Your Spring Boot applications deserve a top-notch package!

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.

Further watching

Videos
card image
Feb 25, 2025
PF4J: Plugin Framework for Java. Plugin Systems for Backend

PF4J (Plugin Framework for Java) is a lightweight framework that allows developers to create modular applications using plugins. It enables the integration of custom code into applications through extension points, with support for lifecycle management and Spring integration for dependency injection. PF4J is useful for both desktop and web applications, offering flexibility in scaling and extending functionality without altering the core system.

Videos
card image
Feb 13, 2025
How to Profile Java Applications in Docker Containers with JFR

Java applications in Docker containers using Java Flight Recorder (JFR), a built-in OpenJDK tool. It covers three profiling methods: enabling JFR at application startup, attaching to a running container using an ephemeral container with jcmd, and monitoring real-time performance with JDK Mission Control via remote JVM connections.

Videos
card image
Feb 7, 2025
How to Create Dynamic SQL Queries with Spring Boot

Build SQL queries dynamically based on the user input with the Specification interface. Use the JPA Static Model Generator to create type-safe queries. Run the tests to check your application.