# Value Classes Still Need Compiler Sympathy

DevFeed: [Value Classes Still Need Compiler Sympathy](<https://devfeed.tech/articles/value-classes-still-need-compiler-sympathy-15126.md>)

Original publisher: [Read original article](<https://inside.java/2026/08/24/value-classes-compiler-sympathy/>)

Author: Johan Sjölén

Published: 2026-08-24T00:00:00Z

Content type: article

Language: en

Sources: [Inside Java](<https://devfeed.tech/sources/inside-java.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [Project Valhalla](<https://devfeed.tech/topics/project-valhalla.md>), [JEP-401](<https://devfeed.tech/topics/jep-401.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [inlining](<https://devfeed.tech/topics/inlining.md>), [code analysis](<https://devfeed.tech/topics/code-analysis.md>)

Tags: [abi](<https://devfeed.tech/tags/abi.md>), [abstraction](<https://devfeed.tech/tags/abstraction.md>), [adapter](<https://devfeed.tech/tags/adapter.md>), [analysis](<https://devfeed.tech/tags/analysis.md>), [annotation](<https://devfeed.tech/tags/annotation.md>), [apply](<https://devfeed.tech/tags/apply.md>), [argument](<https://devfeed.tech/tags/argument.md>), [c2](<https://devfeed.tech/tags/c2.md>), [class](<https://devfeed.tech/tags/class.md>), [classes](<https://devfeed.tech/tags/classes.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [identity](<https://devfeed.tech/tags/identity.md>), [jep-401](<https://devfeed.tech/tags/jep-401.md>), [jvm](<https://devfeed.tech/tags/jvm.md>), [openjdk](<https://devfeed.tech/tags/openjdk.md>), [optimize](<https://devfeed.tech/tags/optimize.md>), [profiling](<https://devfeed.tech/tags/profiling.md>), [project-valhalla](<https://devfeed.tech/tags/project-valhalla.md>), [semantic](<https://devfeed.tech/tags/semantic.md>), [state](<https://devfeed.tech/tags/state.md>), [valhalla](<https://devfeed.tech/tags/valhalla.md>), [value](<https://devfeed.tech/tags/value.md>), [values](<https://devfeed.tech/tags/values.md>)

## AI overview

JDK 28's preview value classes can enable flattening and scalarization, but they do not guarantee faster code. The source shows that immutable final fields can hold large values in flattened form, while mutable fields may use references to preserve tear-free assignment. C2 can eliminate allocations in a value transformation loop; the comparable identity-record example retained allocations. A further allocation source is generic type erasure: a megamorphic call through an inherited `Object apply(Object)` descriptor forces scalarized values to be materialized as heap references. Explicitly redeclaring the typed method in the interface (`Carrier apply(LargeValue)`) lets values cross that dynamic call boundary scalarized; in the reported reproducer, allocation fell from 192 bytes per invocation to zero. The author recommends profiling and inspecting generated code because compiler optimizations depend on context.

## Source excerpt

Declaring a value class is first and foremost a semantic decision. It tells our fellow programmers that its instances are defined entirely by their state and do not need identity. That clearer model is valuable in itself! The JVM's additional freedom to optimize how those values are represented is a welcome bonus. C2 can do amazing things with that freedom, but it cannot always recover information hidden behind abstraction boundaries. Profiling and inspecting the generated code remain the best ways to understand what is happening. To get the best results, we may still need to have a little sympathy for the compiler.