Quick revision
The short answer
Compressed oops store each reference as a 32-bit offset that the JVM multiplies by the 8-byte object alignment, which can address about 32 GB. From 32 GB upwards the JVM must use full 64-bit references, so every reference field and array slot doubles in size; a reference-heavy heap at -Xmx33g can then hold less live data than at -Xmx31g, and fewer objects fit in CPU caches. Raising ObjectAlignmentInBytes to 16 extends the range at the cost of padding, the active mode is visible with -Xlog:gc+heap+coops or PrintFlagsFinal, and ZGC does not use compressed oops, so the trade-off differs for it.
What to remember
In this answer, we saw that compressed oops store references as 32-bit offsets scaled by 8, which reach about 32 GB, and that crossing that limit doubles every reference, so a reference-heavy heap at 33 GB can have less free space and worse cache behaviour than at 31 GB. ObjectAlignmentInBytes of 16 extends the range at the cost of padding, the JVM picks 32-bit, zero-based or non-zero-based modes depending on heap placement, -Xlog:gc+heap+coops shows the mode, and ZGC always uses 8-byte references.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Compressed oops store each reference as a 32-bit offset that the JVM multiplies by the 8-byte object alignment, which can address about 32 GB. From 32 GB upwards the JVM must use full 64-bit references, so every reference field and array slot doubles in size; a reference-heavy heap at -Xmx33g can then hold less live data than at -Xmx31g, and fewer objects fit in CPU caches. Raising ObjectAlignmentInBytes to 16 extends the range at the cost of padding, the active mode is visible with -Xlog:gc+heap+coops or PrintFlagsFinal, and ZGC does not use compressed oops, so the trade-off differs for it.
Why this question is asked
The jump from 31 GB to 33 GB looks like a small increase in heap, but for many applications it is a decrease in usable memory and a drop in performance. It is one of the best known cliffs in JVM sizing, and it still catches teams who raise a container limit and let the JVM derive the heap from it. Interviewers ask this to see whether we understand compressed oops well enough to predict the effect and to check it. In this answer, we will recap the encoding, see exactly why 32 GB is the limit, calculate what happens at 33 GB, look at the alignment trick and the modes the JVM can choose, and see how ZGC changes the picture.
1A Quick Recap of the Encoding
An oop is HotSpot's term for a reference to a heap object. HotSpot aligns every object to 8 bytes, so the lowest three bits of every object address are zero. Compressed oops drop those bits and store the offset from the heap base in 32 bits. Decoding is a shift left by 3 and, if the heap does not start at address zero, an add of the base. With 2 to the power 32 possible values, each standing for an 8-byte step, we can reach 2 to the power 35 bytes, which is 32 GB.
2Why 33 GB Can Hold Less Than 31 GB
At 32 GB or more the offsets no longer fit, so the JVM turns compressed oops off and stores every reference as a full 8-byte address. The object header stays 12 bytes because compressed class pointers are independent, but every reference field, every element of an Object[] and every slot in a HashMap table doubles.
Let us calculate for a typical reference-heavy service. Suppose its 31 GB heap holds 20 GB of live data and about 40 percent of that, 8 GB, is reference fields and reference arrays. At 33 GB, the same data needs those 8 GB to become 16 GB, plus some extra padding, so the live set grows to roughly 28 GB. The heap gained 2 GB but the data grew by 8 GB, so free space shrank from 11 GB to about 5 GB, GC runs more often, and pauses get longer.
| -Xmx31g | -Xmx33g | |
|---|---|---|
| Reference size | 4 bytes | 8 bytes |
| Live data | 20 GB (8 GB of it references) | about 28 GB (references now 16 GB) |
| Free heap after GC | about 11 GB | about 5 GB |
| Objects per 64-byte cache line | more | fewer |
| GC frequency | lower | higher |
3Why Performance Drops Too
Memory is not the only cost. Larger objects mean fewer of them fit in each CPU cache line and in the caches as a whole, so traversing a map or a tree misses the cache more often. Memory bandwidth is spent moving bigger pointers. The GC also has more bytes to copy and scan for the same number of objects. Together, these effects often make the 33 GB JVM measurably slower than the 31 GB one, not just tighter on memory.
4Extending the Range With Alignment, and the Modes
The 32 GB limit comes from an 8-byte alignment. If we raise -XX:ObjectAlignmentInBytes to 16, the shift becomes 4 and 32 bits can address 64 GB, so a 48 GB heap can keep 4-byte references. The price is that every object is padded to a multiple of 16 bytes, so small objects waste more space; an Integer still takes 16 bytes, but a 24-byte object becomes 32. Whether this pays off depends on the object sizes, and it must be measured.
Within the compressed range, the JVM picks the cheapest of three encodings depending on where it can place the heap in virtual memory. If the heap ends below 4 GB, it uses 32-bit unscaled references, with no shift at all. If the heap ends below 32 GB, it uses zero-based mode, with a shift but no base to add. Otherwise it uses a non-zero base, which needs both.
Notice how the log names the mode directly. Adding this line to startup logs in production makes it easy to see when a container change has pushed a service over the edge.
5How ZGC Changes the Trade-off
ZGC stores metadata bits in its references for concurrent relocation and marking, so it never uses compressed oops. Its references are 8 bytes at every heap size, which means there is no cliff at 32 GB, but also no 4-byte saving below it. A service moving from G1 at 16 GB to ZGC at 16 GB will see its reference-heavy data grow, and should be given more heap. Above 32 GB, ZGC loses nothing compared with other collectors, which, together with its short pauses, is one reason it suits very large heaps.
6Follow-up questions
What is zero-based compressed oops mode and when do you get it?
In zero-based mode the JVM places the heap so that it ends below 32 GB in virtual address space, which lets it treat the heap base as zero. Decoding a reference then needs only a shift by 3, with no base to add, which saves an instruction and a register on every decode. We get it when the maximum heap plus its placement fits under the 32 GB address, which on most 64-bit systems is the case for heaps up to roughly 26 to 31 GB, depending on what else is mapped in low memory. Smaller heaps that fit under 4 GB get the even cheaper 32-bit mode with no shift.
Does the limit apply to -Xmx or to the heap in use?
To the maximum heap, -Xmx or the value derived from MaxRAMPercentage. The JVM decides at startup, so even if the application only ever uses 10 GB, a 33 GB maximum means 8-byte references from the first allocation.
How would you size a service that needs about 40 GB of live data?
Measure both options: G1 at 31 GB is impossible, so compare G1 or ZGC at 56 GB or more with 8-byte references, against G1 at around 48 GB with 16-byte alignment and compressed oops. Generational ZGC at the larger size is often the simplest choice when latency matters.
7Conclusion
In this answer, we saw that compressed oops store references as 32-bit offsets scaled by 8, which reach about 32 GB, and that crossing that limit doubles every reference, so a reference-heavy heap at 33 GB can have less free space and worse cache behaviour than at 31 GB. ObjectAlignmentInBytes of 16 extends the range at the cost of padding, the JVM picks 32-bit, zero-based or non-zero-based modes depending on heap placement, -Xlog:gc+heap+coops shows the mode, and ZGC always uses 8-byte references.
Open with
Compressed oops are 4-byte references. HotSpot aligns objects to 8 bytes, so it can store the offset from the heap base divided by 8 in 32 bits, and decode it with a shift by 3 plus the base. 32 bits of 8-byte steps cover 32 GB, so once the maximum heap reaches 32 GB the JVM switches compressed oops off and every reference field and every array slot becomes 8 bytes.
Then, if they want more
That is why 33 GB can be worse than 31 GB.
If 40 percent of a 20 GB live set is references, those 8 GB become 16 GB, so the live data grows by more than the 2 GB of extra heap and free space actually shrinks, GC runs more often, and fewer objects fit in CPU caches, which costs throughput too.
There is an escape hatch: ObjectAlignmentInBytes set to 16 raises the range to 64 GB, but every object is then padded to 16 bytes, so it has to be measured.
I check the mode with Xlog gc plus heap plus coops, which prints whether it is 32-bit, zero based or non-zero based and the shift amount, or with PrintFlagsFinal looking at UseCompressedOops. And ZGC never uses compressed oops, so with ZGC there is no cliff, but also no saving below 32 GB, which changes how I would size it.
About this answer
- Last updated
- 12 November 2026
- 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 "What are compressed oops, why does a heap of 32 GB or more lose them, and why can...": https://scrivio-interview-library.netlify.app/java/memory-layout/c2765da9e5/