Scrivio Interview library
ConceptIntermediate7 min read · updated 12 November 2026

Which Java 22 to 25 runtime changes matter for performance and operations of services moving from 21 to 25?

For services moving from 21 to 25, the runtime changes that matter most are: virtual threads no longer pin their carrier inside synchronized blocks in most cases (JDK 24, JEP 491); compact object headers became a product feature in JDK 25 (JEP 519), enabled with a flag, shrinking every object's header; generational ZGC is the only ZGC mode since JDK 24, and generational Shenandoah is a product feature in 25; AOT class loading and linking (JEP 483) plus the AOT ergonomics and method profiling of JDK 25 improve startup and warm-up; and the Security Manager is permanently disabled since JDK 24.

Why this question is asked

Language features get the headlines, but for a team running services, four years of runtime work between 21 and 25 changes memory use, startup time, GC choices and even whether old code runs at all. Interviewers ask this to see whether we know what we gain and what we must test when we upgrade. In this answer, we will go through virtual thread pinning, compact object headers, the GC changes, ahead-of-time class loading, and the Security Manager, with the flags for each, and then discuss how to measure the effect of compact headers.

1Virtual Threads Stop Pinning in synchronized

On Java 21, a virtual thread that blocked inside a synchronized block stayed attached to its carrier, the OS thread running it. Because there are only about as many carriers as CPU cores, a few such threads could stall the whole application. Teams had to replace synchronized with ReentrantLock in hot paths and check that libraries did the same.

JDK 24, through JEP 491, reworked how monitors are implemented so that a virtual thread can unmount while holding or waiting for a monitor. The result is that synchronized, Object.wait() and blocking inside them no longer pin in most cases. Pinning can still happen during native calls and a few rare situations, so the JFR event jdk.VirtualThreadPinned is still worth watching. For a Spring Boot service with virtual threads enabled, this alone can be the main reason to move to 25.

2Compact Object Headers

Every Java object starts with a header that the JVM uses for locking, hashing, GC and finding the object's class. On 64-bit HotSpot this header is normally 12 bytes with compressed class pointers, and with 8-byte alignment even a tiny object takes 16 bytes or more. For small objects such as an Integer, a String object or a node in a HashMap, the header is a large share of the size.

Compact object headers reduce the header to 8 bytes. They were experimental in JDK 24 (JEP 450) and became a product feature in JDK 25 (JEP 519), but are still off by default, so we enable them explicitly.

Shell
java -XX:+UseCompactObjectHeaders -jar app.jar
// Rough effect on a small object, 64-bit JVM with compressed pointers
record Point(int x, int y) {}
// default headers: 12-byte header + 8 bytes of fields = 20, aligned to 24 bytes
// compact headers: 8-byte header + 8 bytes of fields = 16 bytes

Notice that a third of the size of this object disappears. The gain depends on how many small objects a service keeps alive; services with large arrays or big byte buffers see little change, while those with many small objects in caches and collections can see a noticeable drop in live heap and GC work.

3Garbage Collector Changes

ZGC gained a generational mode in Java 21, made it the default in 23, and in JDK 24 the old single-generation mode was removed (JEP 490). So on 25, -XX:+UseZGC always means generational ZGC, and the -XX:+ZGenerational flag is obsolete. Shenandoah followed: its generational mode became a product feature in JDK 25 (JEP 521), enabled with -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational, and not yet the default, so check your vendor's build.

G1, still the default collector, also improved in this range. Region pinning in JDK 22 (JEP 423) means G1 no longer has to stall garbage collection while a JNI critical region is active, which helps services that use native libraries. Startup scripts that set -XX:+ZGenerational or -XX:-ZGenerational should be cleaned up, since obsolete flags produce warnings and later errors.

Runtime changes between Java 22 and 25
ReleaseChangeWhat to do
22G1 region pinning for JNI (JEP 423)Nothing; fewer GC stalls with native code
24No pinning in synchronized (JEP 491)Re-test virtual thread services
24Non-generational ZGC removed (JEP 490)Drop ZGenerational flags
24AOT class loading and linking (JEP 483)Try a training run and cache
24Security Manager permanently disabled (JEP 486)Remove -Djava.security.manager
25Compact object headers product (JEP 519)Test -XX:+UseCompactObjectHeaders
25Generational Shenandoah product (JEP 521)Optional, by flag
25AOT ergonomics and method profiling (JEP 514, 515)One-step AOT cache, faster warm-up

4Ahead-of-Time Class Loading, Linking and Profiling

Part of a Java service's startup time is spent reading, parsing, loading and linking thousands of classes, and part of its warm-up is the JIT compiler learning which methods are hot. Project Leyden attacks both. JDK 24's JEP 483 lets us do a training run of the application, record which classes it loads and links, and store them in an AOT cache that later runs load from directly. JDK 25 simplified the workflow to one step (JEP 514) and added method profiles to the cache (JEP 515), so the JIT can compile hot methods sooner.

Java
# JDK 25: one training run creates the cache
java -XX:AOTCacheOutput=app.aot -jar app.jar # exercise the app, then stop it
# Production runs use the cache
java -XX:AOTCache=app.aot -jar app.jar
# Illustrative Spring Boot result: startup 2.1 s -> about 1.2 s; measure your own

Notice that the cache must be created with the same JDK and the same class path as production, so it belongs in the image build. The gain is largest for frameworks that load many classes at startup, which describes most Spring Boot services. JDK 24 used a two-step record and create workflow with -XX:AOTMode, which still works; check your version.

5The Security Manager Is Gone

The Security Manager was a sandbox from the applet era that checked permissions for file, network and reflection access. It was deprecated for removal in Java 17, and JDK 24 (JEP 486) permanently disabled it: the JVM cannot enable it at startup, and System.setSecurityManager throws UnsupportedOperationException. The API classes remain for compatibility but do nothing useful.

Most services never used it, but some application servers, plugin systems and test frameworks did, and some startup scripts still pass -Djava.security.manager. Those fail on 24 and later, so the upgrade check is to search scripts and code for it. The replacement for isolation is the container or process boundary.

6Follow-up questions

How would you measure whether compact object headers help your service?

Run an A/B comparison under the same production-like load, with identical heap settings, one instance with -XX:+UseCompactObjectHeaders and one without. Compare the live heap after full GCs or old-generation collections, from GC logs or jcmd GC.heap_info, plus GC frequency, GC CPU time, p99 latency and throughput. A JFR recording with the object count or allocation views shows whether the service's heap is dominated by small objects. Run long enough to reach steady state, and repeat a few times, because noise between runs can be larger than the effect. If the live set drops by, say, 10 to 15 percent, we can lower the container memory or keep it and enjoy fewer collections.

Are compact object headers safe to turn on?

They are a product feature in 25, which means supported and tested, but not yet the default. The main risk is in agents or native code that make assumptions about object layout, which is rare. Test with your agents and profilers before enabling it fleet-wide.

Does the AOT cache work with containers that change memory limits?

Yes; the cache stores class data and profiles, not heap sizes. But it must be created with the same JDK build, the same jars and compatible JVM options, otherwise the JVM ignores it and starts normally, so check the startup log.

7Conclusion

In this answer, we went through the runtime changes between Java 22 and 25 that matter for services: virtual threads no longer pin in synchronized since JDK 24, compact object headers became a product feature in 25 and shrink object headers to 8 bytes with a flag, ZGC is only generational since 24 and generational Shenandoah is a product feature in 25, AOT class loading and linking with 25's simpler workflow and method profiles improve startup and warm-up, and the Security Manager is permanently disabled since 24. We also saw how to measure compact headers with a controlled A/B test.

What to say in the interviewAbout 90 seconds aloud

Open with

For operations, I would highlight five things between 21 and 25. First, JEP 491 in JDK 24: virtual threads no longer pin their carrier in synchronized blocks in most cases, so services that enabled virtual threads on 21 and had to replace synchronized with ReentrantLock get that fixed in the JVM.

Then, if they want more

Second, compact object headers, JEP 519, a product feature in 25 but off by default; with -XX:+UseCompactObjectHeaders the header shrinks from 12 to 8 bytes, which for services with lots of small objects means a smaller live heap and less GC work.

Third, GC: since 24, ZGC is only generational, so ZGenerational flags should be removed, and generational Shenandoah became a product option in 25. G1 also got region pinning for JNI in 22.

Fourth, startup: JEP 483 in 24 added an AOT cache of loaded and linked classes from a training run, and 25 made it one step with AOTCacheOutput and added method profiles, so Spring Boot services start and warm up noticeably faster; the cache must be built in the image with the same JDK and jars.

Fifth, the Security Manager is permanently disabled since 24, so any script passing java.security.manager will fail. To measure compact headers I would run an A/B under the same load and compare the live heap after GC, GC CPU, frequency and p99 latency.

About this answer

Last updated
12 November 2026
Versions it names
Java 24, Java 25, Java 21, Java 22
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Which Java 22 to 25 runtime changes matter for performance and operations of services...": https://scrivio-interview-library.netlify.app/java/java-versions/d68fc8ba03/