LANGUAGES Signal 142
JDK 28 previews value classes where flattening depends on field mutability and size
Illustration only Photo by Kristian Strand on Unsplash
JEP 401 value classes are a preview feature in JDK 28, but their performance benefit from flattening depends on immutability and size constraints that not all code will satisfy.
Engineers adopting value classes cannot assume they always improve performance over ordinary classes. The JVM must sometimes convert between flattened and reference representations when methods with different preferences interact, and mutable fields containing large values force reference layouts to prevent torn reads during data races.
Written by elseif from the cluster below · every claim links back to a sourceThe three things worth knowing
JEP 401 value classes are a preview feature in JDK 28 that give up identity to enable flattening and scalarization optimizations.
JEP 539 strict field initialization allows the JVM to use non-atomic flattened layouts for final fields, since they cannot be updated after initialization.
Mutable fields containing values too large for atomic flattened updates force the JVM to use reference layouts to guarantee tear-free assignment under the Java Memory Model.
THE CLUSTER