JEP proposed to target JDK 16: 390: Warnings for Value-Based Classes
daniel.smith at oracle.com
Wed Dec 2 15:43:16 UTC 2020
> On Dec 2, 2020, at 2:32 AM, Florian Weimer <fweimer at redhat.com> wrote:
> The proposal does not discuss the concurrency impact of a switch to
> primitive types. I expect that lot of code has data races on fields
> whose type is a value-based class, and these races are largely
> recognized as benign today. I think the default choice for primitive
> types will be that data races can observe invalid states, and it would
> be nice to tell developers if that's going to happen for e.g. immutable
Details of how Valhalla will cope with data races and atomicity are still to be worked out. But it should not be a problem for migration.
Briefly, the model is that each primitive class has two types: a value type and a reference type. Reference types hold pointers, so reads/writes of variables of that type are atomic. For migrated primitive classes, the class name ('LocalDate') refers to the reference type. Thus, all legacy code will continue to operate safely on references. Data races only become a problem when the programmer opts in to flattened storage by using the value type (via something like 'LocalDate.val').
More information about the jdk-dev