Compact object headers are on by default in JDK 27: what shrinks, what does not, and when to switch them off

If you moved a service to JDK 27 this autumn and its heap looks a little emptier than before, you have not imagined it. Since that release, every object the HotSpot JVM allocates on x64 and AArch64 starts with an 8-byte header instead of a 12-byte one, unless you ask otherwise. Multiplied by the millions of small objects a busy service keeps alive, those four bytes add up. It is not uniform, though, and it is worth knowing where it comes from before you count on it.
Three releases to reach the default
The change came in deliberate steps, all under the umbrella of Project Lilliput, the OpenJDK project dedicated to shrinking object headers:
| Release | JEP | Status of compact headers | How to get them |
|---|---|---|---|
| JDK 24 (March 2025) | JEP 450 | Experimental | -XX:+UnlockExperimentalVMOptions -XX:+UseCompactObjectHeaders |
| JDK 25 (September 2025) | JEP 519 | Product feature, off by default | -XX:+UseCompactObjectHeaders |
| JDK 27 (September 2026) | JEP 534 | Default layout | Nothing; -XX:-UseCompactObjectHeaders to opt out |
The JDK 27 project page lists JEP 534 among the release's features, next to JEP 523, which makes G1 the default collector in every environment. JEP 534 states plainly that the old 96-bit layout is not removed yet, and that the OpenJDK developers "intend to deprecate the old object header layout in a future release".
What is actually in a header
JEP 450 describes the classic layout. Every object starts with a mark word, 64 bits on a 64-bit JVM, holding the identity hash code, the GC age bits and locking tag bits. It is followed by a class word that points to the object's class metadata. With compressed class pointers, which are on by default, the class word takes 32 bits, so the header is 96 bits, or 12 bytes. Without them, it is a full 128 bits.
Compact headers fold the class pointer into the mark word. The JEP gives the new 64-bit layout: 22 bits of compressed class pointer, 31 bits of hash code (unchanged in size), four bits reserved for Project Valhalla, four GC age bits, a "self-forwarded" bit and two tag bits. To make that possible, the class pointer encoding was squeezed from 32 to 22 bits, and the locking and GC-forwarding code was reworked so that nothing overwrites the class information any more. That last point explains most of the caveats further down.
JEP 450 also explains why this matters at all: experiments in Project Lilliput found average object sizes of 32 to 64 bytes on many workloads, which means "more than 20% of live data can be taken by object headers alone". Early adopters reported live data reduced by 10 to 20 percent.
Which objects get smaller, and which do not
Here the arithmetic gets less flattering. HotSpot aligns objects on 8 bytes by default, so a saving of four bytes only shows up if it lets the object drop to a lower multiple of eight. A few typical cases, with compressed oops on:
| Object | Header + fields, classic | Size, classic | Header + fields, compact | Size, compact |
|---|---|---|---|---|
new Object() | 12 + 0 | 16 bytes | 8 + 0 | 8 bytes |
Integer (one int) | 12 + 4 | 16 bytes | 8 + 4 | 16 bytes |
Two int fields | 12 + 8 | 24 bytes | 8 + 8 | 16 bytes |
| A node with three references | 12 + 12 | 24 bytes | 8 + 12 | 24 bytes |
A record with a long and two references | 12 + 16 | 32 bytes | 8 + 16 | 24 bytes |
So a boxed Integer stays at 16 bytes, while an empty lock object halves and a two-field value drops by a third. The real effect on your heap depends on the mix of shapes, which is why the published figures vary so much. JEP 519 and JEP 534 both cite a SPECjbb2015 run using "22% less heap space and 8% less CPU time", another setting with 15 percent fewer collections under G1 and Parallel, and a parallel JSON parser running 10 percent faster. InfoQ's report on JEP 519 notes that Amazon had already run the feature across hundreds of production services, mostly on backports to JDK 17 and 21, and HappyCoders' overview collects figures from Alibaba between 5 and 10 percent. Treat all of them as ranges, not a promise.
Field layout tools make the table above concrete for your own classes. Aleksey Shipilev's Java Objects Inside Out remains the best walk-through of headers, alignment and field packing, using the JOL tool to print the exact layout of an object; running JOL on the same class under both settings shows immediately whether a given type benefits.
Measuring the saving on your own service
The honest test is an A/B on the live set, not on configured heap sizes. On JDK 27, compare the default run with one started with -XX:-UseCompactObjectHeaders; on JDK 25, compare the default with -XX:+UseCompactObjectHeaders. Then look at the same three things on both sides:
- Live data after a full mark. In a unified GC log (see reading GC logs), the occupancy after a concurrent cycle or a full collection is the number that matters. Compare it at the same point in the load test.
- The class histogram.
jcmd <pid> GC.class_histogramprints instances and bytes per class. Divide bytes by instances for your top ten classes and you will see which ones lost four or eight bytes and which ones did not move. The same comparison works in a heap dump, as described in taking and reading a heap dump; check that your analysis tool understands the new layout before trusting its shallow sizes. - GC frequency and CPU. A smaller live set usually means fewer young collections for the same allocation rate.
To confirm what a running JVM is using, jcmd <pid> VM.flags -all | grep UseCompactObjectHeaders is enough. Remember that the flag may be on while the feature is silently off: the conditions below disable it at startup.
When the JVM turns them off, and when you should
JEP 450 lists two situations in which HotSpot quietly falls back to the classic layout. First, compact headers require compressed class pointers; running with -XX:-UseCompressedClassPointers rules them out, which the JEP says almost nobody needs, since that would only be useful for applications loading "more than about four million classes". Second, the new GC forwarding encoding addresses up to 8 TB of heap: with a larger heap and any collector other than ZGC, compact headers are disabled. The JEP also documents the incompatibility with the old stack-locking mode, which overwrote the header with a pointer to the thread's stack.
Reasons to opt out deliberately are rarer and mostly practical:
- Native or diagnostic code that reads object headers directly, such as some agents, serviceability tools or JNI code relying on fixed offsets. Arrays are a classic trap, because the header shrinks and the offset of the first element moves with it.
- A regression you can measure. JEP 450 set itself a budget of no more than 5 percent throughput or latency overhead, "only in infrequent cases". If your A/B shows one of those cases, keep the old layout while you report it upstream.
Vendors are converging. JEP 534 points out that SAP had already made compact headers the default in its downstream build, SapMachine, before upstream did.
How it fits with the rest of your memory budget
Compact headers do not replace compressed oops: reference fields are still four bytes below the 32 GB line and eight above it, as explained in compressed oops and the 32 GB heap boundary. They stack with it. A heap that sat just above 32 GB because of header overhead may now fit below it, and a container sized with MaxRAMPercentage may have room to spare; the arithmetic for that is in the JVM in containers. Native memory is not affected: Metaspace, thread stacks and the code cache keep their size.
A short checklist for a JDK 27 upgrade
- Check that no startup script still passes
-XX:-UseCompressedClassPointersor a copied experimental flag from JDK 24. - Run one load test with
-XX:-UseCompactObjectHeadersand compare live set, GC count and CPU with the default. - Re-check heap sizing after the upgrade: the same
-Xmxnow holds more data.
Sources
- JEP 450: Compact Object Headers (Experimental), OpenJDK (header layouts, 22-bit class pointers, 8 TB limit, locking and GC forwarding, Lilliput measurements)
- JEP 519: Compact Object Headers and JEP 534: Compact Object Headers by Default, OpenJDK (product status in JDK 25, default in JDK 27, benchmark figures, Amazon and SAP deployments)
- JDK 27 project page, OpenJDK (feature list and general availability on 15 September 2026). All pages consulted on 23 November 2026. Object sizes in the table are computed from the header sizes in JEP 450 with 8-byte alignment and compressed oops.
MemoryCompressed oops
Raise -Xmx from 31g to 32g and every reference doubles in size. How compressed oops work, how to see which mode you got, and when crossing the line is worth it.
MemoryTaking and reading a heap dump
Capture safely with jcmd, dump automatically on OOM, then read the dominator tree and paths to GC roots.
ProductionThe JVM in containers
How limits are detected, what MaxRAMPercentage really sets, and a budget that keeps the OOM killer away.