Skip to main content

Project Valhalla Ships in JDK 28. Your Cloud Bill Won't Notice

Value classes are real, and so are the constraints. A reality check for teams planning 2027-2030

Updated 14 min readMarkdown
Part of seriesJava General
Project Valhalla Ships in JDK 28. Your Cloud Bill Won't Notice

Value classes are real. So are the constraints. This is a reality check for Java teams planning a 2027-2030 roadmap.

Summary

  • JEP 401 (Value Classes and Objects) went into mainline OpenJDK in July 2026 and previews in JDK 28, due March 2027, behind --enable-preview.

  • Most of the spectacular numbers circulating right now (9x, 12x, "60-70% fewer allocations") were measured on primitive classes, a design OpenJDK dismantled years ago. That tier is not shipping.

  • What is shipping carries a constraint that rarely makes it into the posts: value objects with 64 bits or more of field data normally cannot be flattened. A typical 8-field DTO carries 320 bits of field data.

  • List<Point> still allocates on the heap. Null-restricted types, specialized generics and 128-bit encodings are all deferred to later JEPs.

  • The heap reduction people are waiting on Valhalla for has already shipped. Compact object headers (JEP 519) cut the object header from 12 bytes to 8, reached production status in JDK 25, and become the default in JDK 27 this September. Reported savings run 10-22%.

  • Valhalla matters for numeric kernels, in-memory data structures and tight loops. For the Spring Boot service sitting in front of your database, it is close to a no-op.

What actually landed

In July 2026, after roughly a decade of design work, JEP 401 was integrated into mainline OpenJDK as a patch of about 197,000 lines across 1,816 files. It previews in JDK 28, due March 2027.

The feature is well scoped. A value class has implicitly final fields, carries no identity, and cannot be synchronized on. == stops comparing references and performs a statewise comparison instead. In exchange, the JVM is permitted (though never required) to scalarize the object into registers, or to flatten it inline into a field or an array element.

Three JDK classes are migrated as part of the preview: java.lang.Integer, java.time.LocalDate and java.util.Optional, with the remaining primitive wrappers following.

That is an important change to the Java object model. It is also considerably narrower than the version being marketed.

The benchmarks everyone quotes measure a design that no longer exists

This is the correction that explains most of the hype.

The 2021-era Valhalla design had two tiers. Value classes were identity-free reference types. Primitive classes sat below them, with dual projections (Point.val and Point.ref, later Point! and Point?), no header, and relaxed alignment rules, behaving like true primitives. That two-tier model was judged too heavy for developers to reason about and was dropped in favour of a single concept. The current OpenJDK project page lists no "primitive classes" feature at all.

Nearly every viral figure, including the "9.7x faster sort", the "12.5x accumulator" and the "60-70% fewer allocations", comes from early-access builds of the tier that was cut.

How much does that matter? The most careful independent measurement I know of is the Clojure Goes Fast ray tracer benchmark, run in 2023 on a JDK 20 Valhalla EA build with all three variants side by side. On an M1 MacBook Pro:

Variant Time Allocated
Plain POJOs (baseline) ~13.7 s 3.4 GB
Value classes ~15.4 s 1.9 GB
Primitive classes ~12.3 s 224 MB

On a Steam Deck (x86-64) the spread was wider still: value classes ran 2x slower than plain POJOs, while primitive classes ran 1.9x faster.

So the tier that produced the dramatic numbers is the tier that was cancelled, and the tier that shipped came out slower than plain objects on that workload, because memory barriers stayed in the profile and the allocation savings did not pay for them.

That build is three years old and the implementation has improved considerably since, which is itself the useful lesson. The defensible conclusion is neither "Valhalla is 12x faster" nor "Valhalla is slower". It is that the effects depend on the workload and the hardware, and have to be measured. The benchmark author's own summary, that the effects "are unpredictable and require empiric evaluation", is a better guide than any single multiplier.

The 64-bit rule: why your DTO will not flatten

Here is the constraint that decides whether Valhalla touches your service at all.

Flattening means storing a value object's fields inline instead of behind a pointer. To do that safely, the JVM has to be able to read and write the whole flattened encoding atomically. Otherwise a racing thread could observe a half-written object, which the Java memory model does not permit for any object you can reach. On current hardware that atomic window is typically 64 bits.

The OpenJDK documentation is explicit: value objects with 64 bits or more of field data cannot normally be flattened. The 128-bit encodings and null-restricted types that would relax this are deferred to future JEPs.

Now apply that to the DTO used in the earlier version of this article, a typical Order record with 5 String fields, 2 long fields and 1 List field.

Today, on JDK 25 with compressed oops:

header:                 12 bytes
5 reference fields:     20 bytes
2 long fields:          16 bytes
1 reference field:       4 bytes
padding to 8:            4 bytes
                        --------
                        56 bytes

As a value class in JDK 28, the field data comes to 20 + 16 + 4 = 40 bytes, or 320 bits. That is five times over the flattening budget, so the object stays on the heap with a header. The saving is zero.

With compact object headers, available today:

header:                  8 bytes
5 reference fields:     20 bytes
2 long fields:          16 bytes
1 reference field:       4 bytes
                        --------
                        48 bytes

Eight bytes per object, no source changes, one JVM flag, and on by default from JDK 27.

The claim in circulation was that Valhalla saves 16 bytes on this object. In JDK 28 it saves nothing, while the flag most teams have not enabled yet already delivers half of what Valhalla was credited with.

Two further constraints are worth knowing:

  • Scalarization only kicks in after C2 compiles the method. During warmup, value objects allocate normally. For short-lived processes and serverless functions, that window is a meaningful fraction of total runtime.

  • List<Point> does not flatten. Generic collections still materialize value objects as heap objects. Flat generics require the Parametric JVM work, which is a separate and later phase, so the ArrayList<Point> in your hot path is unaffected.

Redoing the Kafka math

Take a Kafka consumer handling 10,000 JSON messages per second, deserialized with Jackson.

Where does the memory actually go? Per message, roughly 1.5-2.5 KB spread across perhaps 30-60 objects: Jackson's internal buffers, the byte[] backing each string, intermediate String instances, Map and List nodes, and the DTO itself.

One note on string cost, since the inflated figure travels widely. A 50-character Latin-1 String on JDK 9+ is about 96 bytes, not 150. Compact strings (JEP 254) replaced the char[] with a byte[] back in Java 9. The String object itself is 24 bytes (12-byte header, hash, coder, hashIsZero, one reference, padded), and the byte[] is 16 + 50 = 66, padded to 72.

Now compare the two interventions on this workload.

Valhalla in JDK 28 does essentially nothing here. The DTO is over the 64-bit flattening budget, so it does not flatten. String needs identity for HashMap keys and interning, so it can never become a value class. Jackson's ObjectMapper internals are mutable and identity-bearing.

Compact object headers, by contrast, take 4 bytes off every one of those 30-60 objects per message. At around 40 objects that is roughly 160 bytes per message, or 6-11% of total allocation, which lines up with the 10-20% heap reduction reported in JEP 519 and the 22% Amazon measured on its own workloads. Reported throughput gains sit in the 6-11% range, mostly from better cache density.

One of these is a flag. The other is a language migration that, on this workload, buys you nothing.

What actually reduces your heap and your bill

In rough priority order:

  1. Turn on compact object headers. Use -XX:+UseCompactObjectHeaders on JDK 25; it is the default from JDK 27. Reported figures are 10-22% heap reduction and 6-11% throughput, with zero source changes. This is the highest-leverage JVM flag of the last five years.

  2. Fix your deserialization. Records plus Jackson Blackbird (the Java 11+ successor to Afterburner, which does not sit well with the module system on 17+) replaces reflection with generated accessors. Better still, move the hot topics to Avro, Protobuf or MessagePack and delete the JSON parse entirely.

  3. Stop materializing what you never read. Streaming or lazy deserialization on wide events often beats every object-layout optimization combined.

  4. Get onto Java 25. Generational ZGC has been the default since JDK 23, the non-generational mode was removed in JDK 24, and virtual thread pinning on synchronized was fixed in the same release.

  5. Profile before optimizing. JFR and async-profiler will tell you in an afternoon whether allocation is even your problem. In most services it is not. The memory goes to connection pools, caches, framework metadata and thread stacks, and Valhalla touches none of them.

Value classes are not on this list, and will not be for at least two more LTS releases.

The migration risks nobody is posting about

If your organization does eventually adopt value classes, these are the items that will consume the schedule.

== changes meaning. For value objects it performs a statewise comparison. Any code that deliberately used reference comparison as a fast path or an identity check needs review.

Integer, Long and Double become value classes. This has the widest blast radius, because it affects code that never opted in. Synchronizing on a value object throws IdentityException, so synchronized (someLong), a common enough pattern in older code, becomes a runtime failure. Code relying on Integer cache identity behaves differently. Creating a WeakReference or SoftReference to a value object also throws.

Deep reflection and serialization are constrained. Frameworks that set final fields reflectively after construction, a technique several serialization and ORM layers depend on, do not work against value classes.

JPA entity roots cannot be value classes. Hibernate's dirty checking needs mutable state and lazy loading needs proxy identity. @Embeddable components can convert; entity roots cannot. The heart of most enterprise Java gets no direct benefit.

Value classes cannot be polymorphic in the flattened case, which rules out the abstract base class hierarchies common in domain models.

For a 200k-line codebase with 50+ third-party dependencies, the audit alone is a quarter of work, and on a typical CRUD service the payoff sits inside the noise floor.

Where Valhalla genuinely wins

None of this makes the feature unimportant. Oracle's own LocalDate demo iterates a 50-million-element array and drops from roughly 72-83 ms to 25-42 ms, close to a 3x improvement, driven by heap flattening of a small, primitive-backed, immutable type. That is the shape of the win, and it applies to:

  • Numeric and scientific kernels: vectors, matrices, complex numbers, geometry

  • Large arrays of small immutable records such as market data, time series and telemetry points

  • In-memory columnar structures and analytical engines

  • Anything iterating tens of millions of small objects in a tight loop

  • Optional and LocalDate becoming cheap, which benefits everyone passively

If you write that code, Valhalla is one of the most consequential Java changes in a decade. If you write REST controllers over a database, it is a footnote.

Timeline reality

Setting expectations correctly matters more here than any benchmark.

March 2027, JDK 28. First preview, --enable-preview required.

September 2027, JDK 29. The next LTS. A feature entering preview in 28 will realistically be in its second preview here rather than final, so expecting production-ready value classes in the 2027 LTS is optimistic.

2028-2029. A plausible window for final status, along with the follow-on JEPs (null-restricted types, enhanced primitive boxing) that extend flattening past the 64-bit limit.

Two to four years after that. Framework support, once Jackson, Hibernate and Spring have each decided how to handle identity-free types.

Then there is adoption. The 2026 ecosystem data puts Java 21 at roughly 45% of production workloads, Java 17 at 25-30%, and Java 8 and 11 together under 20%. That last figure is worth stating precisely, because "everyone in banking is still on Java 8" gets repeated more often than it is true. Java 8 is now a shrinking minority with a long tail, concentrated in regulated and legacy-heavy sectors, rather than the industry norm it was five years ago. Oracle's Extended Support for Java 8 running to December 2030 is the real reason the tail persists.

The direction of travel is clear enough, and it does not point at Valhalla. Teams still on 8 or 11 have a Java 25 migration in front of them that delivers compact object headers, generational ZGC and virtual threads, a package that will beat value classes on their workloads by a wide margin and that they can start this quarter.

Where should one start?

If you are on Java 25: turn on -XX:+UseCompactObjectHeaders in a canary and measure. That is an afternoon of work.

If you are on Java 17 or 21: plan the move to 25. The compact-headers and GC wins justify it on their own, independently of anything Valhalla does.

If you are on Java 8 or 11: Valhalla is not on your roadmap and should not be. Get to a modern LTS. Virtual threads alone will do more for your services than value classes ever will.

Everyone: when JDK 28 EA builds land, benchmark your actual hot paths on them. Identify candidates using the real criteria, which are immutable, identity-free, and under 64 bits of field data. That last filter will eliminate most of what you were considering, and knowing that in 2027 is worth more than a roadmap item.

Conclusion

Project Valhalla is a serious piece of engineering and a real improvement to the Java object model. The wins are also narrow, conditional, several years from production use, and largely unrelated to why most services consume the memory they consume.

The distance between the LinkedIn version and the OpenJDK version comes down to two things. The popular version quotes benchmarks from a design that was cancelled. And the design that actually shipped carries a 64-bit flattening limit that excludes most application objects, while the memory reduction being promised for 2028 is already sitting behind a JVM flag.

Java moves at the pace that thirty years of accumulated compatibility obligations allow. Which is why the highest-leverage change available to most Java teams this year is an eight-byte object header rather than a language feature.

Sources

About the author

  • Senior Software Architect and Co-Founder with 17+ years of enterprise software experience spanning insurance, telecom, healthcare, and fintech domains. Deep specialist in Java ecosystem architecture, Oracle database internals, JVM runtime engineering, and observability platform design. Proven capability in resolving chronic performance bottlenecks at both application and database layers in mission-critical production environments. Co-created Pingl APM — recognized as the world's first product to unify Java and Oracle execution traces under a single distributed TraceId. Beyond client engagements, maintains an intensive self-directed research practice covering compiler theory, language runtime internals, operating system design, network protocol engineering, and systems programming. Actively builds experimental tools in Go and Rust targeting enterprise observability and audit use cases — treating low-level systems engineering as both a professional discipline and an intellectual pursuit. Reads extensively across distributed systems literature, database internals, and computer science fundamentals, and applies that knowledge directly to architecture decisions and platform design.

No comments yet. Be the first to comment.

Java General

Part 1 of 1