Estimate project
← All posts

JDK 26 and Project Leyden: AOT Caching Comes to ZGC

Project Leyden is a continuing effort to cut the startup and warmup times of the Java Virtual Machine (JVM). Extending the groundwork of JEP 483, JEP 514, and JEP 515, the forthcoming JDK 26 release will bring JEP 516: Ahead-of-Time (AOT) Object Caching with Any GC. This article describes exactly which problems the feature solves.

3 min read
JavaJVMApplication PerformanceProject Leyden

Project Leyden is a continuing effort to cut the startup and warmup times of the Java Virtual Machine (JVM). Extending the groundwork of JEP 483, JEP 514, and JEP 515, the forthcoming JDK 26 release will bring JEP 516: Ahead-of-Time (AOT) Object Caching with Any GC. This article describes exactly which problems the feature solves.

The problem

So far, Project Leyden has lacked support for the Z Garbage Collector (ZGC). ZGC is a low-latency collector built to hold application pause times below a millisecond, even with enormous heaps of up to 16TB.

The incompatibility comes down to the way ZGC treats object references compared with other GC implementations. ZGC relies on a technique known as colored pointers, embedding metadata bits straight into the object reference. This lets the collector do its job concurrently while the application keeps running.

Earlier versions of the AOT cache stored object references as literal memory addresses. Since ZGC’s distinctive reference format is so fundamentally different from ordinary pointers, the existing AOT cache could not work with it.

The solution

To close this gap, JEP 516 makes it possible to store object references as logical indices instead of physical memory addresses. When the application starts, the JVM reads these objects from the cache and streams them into memory, translating the indices into the right memory addresses for the current environment.

As a result, there are now two kinds of caches:

  • GC-specific cache: maps cached objects straight into memory
  • GC-agnostic cache: streams objects into memory

During the training run, the JVM relies on heuristics to decide which format to produce:

  1. The GC-specific cache is chosen when -XX:+UseCompressedOops is enabled (the default for heaps below 32GB). The underlying assumption is that production will match the training environment – in particular, that the heap will stay below 32GB and ZGC won’t be used.
  2. The GC-agnostic cache is selected automatically if any of these conditions hold during training:
  • ZGC is in use
  • -XX:-UseCompressedOops is set explicitly
  • The heap is larger than 32GB

You can also force a streamable cache to be created even with CompressedOops turned on, using: -XX:+AOTStreamableObjects (it has to come after the-XX:+UnlockDiagnosticVMOptions option).

The UseCompressedOops (Ordinary Object Pointers) option controls how large object references are: 32-bit when it’s on and 64-bit when it’s off. Because ZGC needs 64-bit (uncompressed) pointers to hold its metadata, it simply cannot work with the 32-bit GC-specific cache.

Thanks to the new GC-agnostic format, a cache can be trained with one collector and used in production with another. For instance, you can build a cache with the default G1GC (with compressed pointers turned off):

java -XX:AOTCacheOutput=cache.aot -XX:-UseCompressedOops -jar example.jar

and then run the very same application on ZGC without any hassle:

java -XX:AOTCache=cache.aot -XX:+UseZGC -jar example.jar

Testing

To measure how memory-mapped (GC-specific) and streamable (GC-agnostic) AOT caches compare, I ran tests on a Google Cloud Platform (GCP) VM with Debian GNU/Linux 12 (bookworm) on an Intel Xeon @ 2.20GHz (4 vCPUs, 16GB RAM).

The tests used the newest (as of 31.01.2026) early-access build of OpenJDK Runtime Environment (build 26-ea+33-2879), with the Spring Petclinic sample application serving as the benchmark subject.

I produced two separate caches:

  • GC-specific (memory-mapped)
java -XX:AOTCacheOutput=mapped/cache.aot -jar spring-petclinic-4.0.0-SNAPSHOT.jar
  • GC-agnostic (streamable)
java -XX:+UnlockDiagnosticVMOptions -XX:AOTCacheOutput=streamable-compressed/cache.aot -XX:+AOTStreamableObjects -jar spring-petclinic-4.0.0-SNAPSHOT.jar

I then took measurements with a simple-benchmark application, which I wrote a while back to compare various ways to speed up JVM-based application startup time.

Here are the results:

table%20JDK26

For this specific use case, they show:

  • ~28% quicker startup with the GC-specific cache
  • ~26% quicker startup with the GC-agnostic cache

So although the more flexible GC-agnostic cache was slightly slower than the GC-specific one, the two implementations produce AOT caches of almost identical size:

  • GC-specific - 123813888 bytes
  • GC-agnostic - 124047360 bytes

As usual, I’d urge you to run your own measurements. Performance can differ considerably depending on your particular application.

Conclusion

The forthcoming JDK 26 release adds another handy feature to Project Leyden. With the AOT cache now working with ZGC, the project becomes far more flexible across a variety of use cases.

It’s good to see Project Leyden making steady progress and shipping new JEPs with each JDK release.