Memory

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

Memory · · Published 2026-11-23

A sheet of red and white "hello my name is" name tag stickers next to two black marker pens on a black surface
Every Java object carries a small label saying what it is. JDK 27 makes that label a third smaller by default. Photo: Nilo Velez, WordPress Photo Directory, CC0.

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:

ReleaseJEPStatus of compact headersHow to get them
JDK 24 (March 2025)JEP 450Experimental-XX:+UnlockExperimentalVMOptions -XX:+UseCompactObjectHeaders
JDK 25 (September 2025)JEP 519Product feature, off by default-XX:+UseCompactObjectHeaders
JDK 27 (September 2026)JEP 534Default layoutNothing; -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:

ObjectHeader + fields, classicSize, classicHeader + fields, compactSize, compact
new Object()12 + 016 bytes8 + 08 bytes
Integer (one int)12 + 416 bytes8 + 416 bytes
Two int fields12 + 824 bytes8 + 816 bytes
A node with three references12 + 1224 bytes8 + 1224 bytes
A record with a long and two references12 + 1632 bytes8 + 1624 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:

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:

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

Sources