atomicity for value types

Tobi Ajila Tobi_Ajila at
Mon Jan 13 21:44:22 UTC 2020

Hi John

Given that inline types can be flattened there is a possibility that data
races will occur in places where users were not expecting it before. So
your `__AlwaysAtomic` modifier is a necessary tool as the existing spec
will only enforce atomicity for 32bit primitives and references. I just
want to confirm if the intention of the __AlwaysAtomic bit on an inline
class is only to ensure atomic reads and writes of inline types and that
there are no happens-before ordering expectations as there are with the
existing volatile modifier on fields.

For example:

__AlwaysAtomic inline class Long256 { long v1, v2, v3 ,v4;  … }

class Example {
	Long256 bigLong;
	int x;
	int y;

	void method() {
		Long256 newLong = new Long256(1, 2, 3, 4);

            x = 1;

		//compiler is still free to re-order write to bigLong with
		//to writes to x and y, but the write to bigLong must be done
		bigLong = newLong;

		y = 2;

Does this match your expectations?

The reason I ask is because of the "Protection is “as if” each field were
volatile" wording in your previous note. Does this only speak to the
atomicity properties of the volatile modifier? Or do you intend further


"valhalla-spec-experts" <valhalla-spec-experts-bounces at>
wrote on 2019/12/18 08:46:42 PM:

> From: John Rose <john.r.rose at>
> To: valhalla-spec-experts <valhalla-spec-experts at>
> Date: 2019/12/18 08:47 PM
> Subject: [EXTERNAL] atomicity for value types
> Sent by: "valhalla-spec-experts" <valhalla-spec-experts-
> bounces at>
> In a nutshell, here’s a proposal for value type atomicity:
> - Define a contextual keyword “alwaysatomic" (working title
> - It can only occur with “inline” in class declaration.
> - All instances of the given inline class are protected against races.
> - Protection is “as if” each field were volatile, “and the same” for
> array elements.
> - In the class file the ACC_VOLATILE bit is used (0x0040) to record
> the keyword.
> - This bit does not necessarily disable flattening; if the JVM can
> get away with flattening it should.
> - The JVM can get away with flattening such values on stack, in
> registers, and perhaps in final heap variables.
> - The JVM can get away with flattening such values if they are
> “naturally atomic”, meaning they can be wholly loaded or stored in
> one (atomic) hardware instruction.
> More details to follow.  Here’s a backgrounder I wrote a while ago:


> aS4ug04&s=dhRZz0Da6RYg45c_b-x6gFBP0sqXC1VtTWP--BDHMS4&e=
> — John

More information about the valhalla-spec-observers mailing list