JEP draft: 4-byte Object Headers (Experimental)

Authorrkennke
OwnerRoman Kennke
TypeFeature
ScopeImplementation
StatusDraft
Componenthotspot / runtime
EffortL
DurationL
Created2025/01/30 13:03
Updated2025/01/30 13:04
Issue8349069

Summary

Reduce the size of object headers in the HotSpot JVM from between 64 and 128 bits down to 32 bits on 64-bit architectures. This will reduce heap size, improve deployment density, and increase data locality.

Goals

When enabled, this feature

When disabled, this feature

This experimental feature will have a broad impact on real-world applications. The code might have inefficiencies, bugs, and unanticipated non-bug behaviors. This feature must therefore be disabled by default and enabled only by explicit user request. We intend to enable it by default in later releases and eventually remove the code for legacy object headers altogether.

Non-Goals

It is not a goal to

Motivation

An object stored in the heap has metadata, which the HotSpot JVM stores in the object's header. The size of the header is constant; it is independent of object type, array shape, and content. In the 64-bit HotSpot JVM, object headers occupy between 64 bits (8 bytes) and 128 bits (16 bytes), depending on how the JVM is configured.

Objects in Java programs tend to be small. Experiments conducted as part of Project Lilliput show that many workloads have average object sizes of 256 to 512 bits (32 to 64 bytes). This implies that more than 20% of live data can be taken by object headers alone. Thus even a small improvement in object header size could yield a significant reduction in footprint, data locality, and reduced GC pressure. Early adopters of Project Lilliput who have tried it with real-world applications confirm that live data is typically reduced by 10%–20%.

JEP 450 introduced 'compact object headers' that reduced object header size to 8 bytes. This JEP builds on JEP 450 and goes even further and reduces object header size to just 4 bytes.

Description

Compact object headers is an experimental feature and therefore disabled by default. Compact object headers can be enabled with -XX:+UnlockExperimentalVMOptions -XX:+UseCompactObjectHeaders.

Current object header layouts

TBD

4-byte object header layout

TBD

Compact Identity Hash-Code

TBD

Compact GC Forwarding

TBD

Alternatives

Testing

Changing the header layout of Java heap objects touches many HotSpot JVM subsystems: the runtime, all garbage collectors, all just-in-time compilers, the interpreters, the serviceability agent, and the architecture-specific code for all supported platforms. Such massive changes warrant massive testing.

Compact object headers will be tested by:

Tier 1–4 tests, and possibly more testing tiers by vendors which have them; The SPECjvm, SPECjbb, DaCapo, and Renaissance benchmark suites to test both correctness and performance; JCStress, to test the new locking implementation; and Some real-world workloads. All of these tests will be executed with the feature turned on and off, with multiple combinations of GCs and JIT compilers, and on several hardware targets.

We will also deliver a new set of tests that measure the size of various objects, e.g., plain objects, primitive type arrays, reference arrays, and their headers.

The ultimate test for performance and correctness will be real-world workloads once this experimental feature is delivered.

Risks and Assumptions

Dependencies

This JEP builds on and extends JEP 450: Compact Object Headers (Experimental)