Core Java

Project Valhalla’s Value Classes Are Finally Real

What the new value keyword actually changes about heap layout, and why data-heavy Java applications should pay attention.

For more than a decade, Java developers have lived with a quiet trade-off. If you wanted speed, you reached for a primitive like int. If you wanted structure and meaning, you wrapped that primitive in a class, and paid for it with an object header, a heap allocation, and a pointer indirection every time you touched it. Project Valhalla was started in 2014 to close that gap, and after years of design changes, name changes, and rewritten prototypes, its centerpiece finally has a name and a shape that developers can actually try: JEP 401, Value Classes and Objects.

Early-access builds have been available for a while now, built on a JDK 26 baseline, and in June 2026 Oracle engineer Lois Foltan confirmed that the feature is heading into the OpenJDK mainline, targeting JDK 28 in March 2027 as a preview feature. So the honest framing is this: JEP 401 is not shipping as a finished feature in JDK 26, but the early-access builds tied to that codebase are exactly how most developers are trying it today, and the destination release has now been locked in.

The problem value classes are trying to fix

Every object you create in Java, even a tiny one like a coordinate pair or a currency amount, carries identity. Two Point objects with the same x and y are still different objects in memory, comparable with == only by reference, each with its own header of roughly 12 to 16 bytes sitting in front of the actual data. When you build an array of a thousand of these, you are not storing a thousand small objects, you are storing a thousand pointers to a thousand separately allocated objects scattered across the heap. Walking that array means chasing pointers, and chasing pointers means cache misses.

For business logic that creates a handful of objects, this overhead barely registers. It becomes a real cost in data-heavy code: financial systems processing transactions, event pipelines, trading engines, or anything that creates large numbers of small immutable values like dates, coordinates, or money amounts.

What the value keyword actually does

A value class looks almost like an ordinary class, but it gives up something on purpose: identity. Its fields must be final, it cannot be synchronized on, and the == operator no longer compares references, it compares the objects field by field. Two value objects with identical state are indistinguishable, even to the JVM itself.

That last part is the key. Because a program can never tell two equal value objects apart, the JVM is free to change how it stores them without anyone noticing. As the JEP itself puts it, invoking new on a value class does not have to allocate a fresh heap object. The runtime can flatten the value directly into an array slot, a field, or even keep it in CPU registers during a computation, instead of storing a reference to a separate heap object.

Here is roughly what declaring one looks like. This is a minimal, self-contained example that compiles as-is against a preview-enabled JDK build that supports JEP 401:

value class Point {
    private final int x;
    private final int y;

    Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    int x() { return x; }
    int y() { return y; }
}

To try it yourself, download a build from jdk.java.net/valhalla, then compile and run with preview features enabled, for example javac --enable-preview --release 26 Point.java followed by java --enable-preview Point. Nothing about the class body looks unusual. What changes is entirely underneath, in how the JVM lays the object out in memory.

Worth knowing: storing a value object into a field or upcasting it to an interface can still force a real heap allocation. Flattening is an optimization the JVM applies where it safely can, not a guarantee that applies to every single use of every value object.

Value class versus traditional class, side by side

PropertyTraditional classValue class
IdentityEvery instance is distinctNone, compared by field values
== behaviourReference equalityField-by-field equality
Heap allocationAlways, on every newOften avoided through flattening
synchronizedAllowedThrows an exception
FieldsMutable or finalMust be final
null supportYesYes, it is still a reference type

What the numbers actually show

Oracle’s own walkthrough of the feature, published on Inside.java, ran a small date-heavy computation five times, once with value objects enabled, to show what heap flattening buys you in practice. The raw timings dropped noticeably across the run, though the article itself is careful to note that results vary by machine and by array size, so treat this as a directional demo rather than a certified benchmark.

Timings (ms) from Oracle’s own DateTest walkthrough on Inside.java, five runs of the same computation with value objects enabled. Source: inside.java, October 2025.

Separately, engineers experimenting with the early-access builds have reported speedups in the range of roughly two to three times on parsing-heavy and heap-flattening workloads, though those figures come from individual blog experiments rather than an official Oracle benchmark suite, and should be read as illustrative rather than guaranteed.

To make the underlying mechanism concrete rather than just quoting someone else’s number, here is a simple, honest estimate built from well documented JVM facts: a HotSpot object header is typically 12 to 16 bytes, and a reference in a compressed-oops heap is 4 bytes. A small two-field Point stored the traditional way costs a 4-byte array reference plus a separately allocated object of roughly 24 bytes once headers and alignment are accounted for, versus just 8 bytes if the same two ints are flattened directly into the array.

Approximate bytes per element for a two-field Point stored in an array of 1,000, based on documented HotSpot header and reference sizes. This is a back-of-envelope illustration of the mechanism, not a published Oracle figure.

The migration path already underway

JEP 401 is not only about new code you write yourself. Some existing JDK classes, starting with Integer, are expected to migrate to value classes, and Optional is already flagged as a candidate for a future release, since it was designed from the start as what the JDK calls a value-based class. That migration will roll out gradually across several releases rather than all at once, so most existing code should keep working unchanged while quietly picking up the benefit where the JVM can apply it.

It is also worth setting expectations on timing. Brian Goetz, Oracle’s Java Language Architect, has been candid that hoping the feature exits preview by JDK 29 would be optimistic, which signals a preview window that could stretch across several releases rather than resolve quickly.

Should you care right now

If you maintain everyday business logic with a modest number of objects, the honest answer is: not urgently. The benefit concentrates in code that creates large volumes of small immutable values, think payment processing, event streaming, real-time analytics, or anything built around types like coordinates, money amounts, or timestamps. For that kind of workload, it is worth downloading an early-access build now, experimenting with the value keyword on a few candidate types, and watching how the feature matures through its preview releases before committing production code to it.

What we have learned

JEP 401 gives Java a real answer to a decade-old trade-off between object abstraction and primitive-like performance. The value keyword removes object identity, which lets the JVM flatten small immutable objects directly into arrays and fields instead of scattering heap allocations behind pointers. Oracle’s own walkthrough shows measurable gains on a date-heavy demo, and the underlying mechanics, header size and reference indirection, explain why data-heavy workloads stand to benefit the most. The feature is landing as a preview in JDK 28, not JDK 26, with early-access builds available today for anyone who wants to start experimenting ahead of that release.

Sources

Eleftheria Drosopoulou

Eleftheria is an Experienced Business Analyst with a robust background in the computer software industry. Proficient in Computer Software Training, Digital Marketing, HTML Scripting, and Microsoft Office, they bring a wealth of technical skills to the table. Additionally, she has a love for writing articles on various tech subjects, showcasing a talent for translating complex concepts into accessible content.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button