<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;color:#073763">
<div style="font-family:verdana,sans-serif;color:rgb(7,55,99)" class="gmail_default"></div><div dir="auto"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif">Hello,</span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"></span></span></span><div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span><br></span></span></div><div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">I </span>would like to bring to your consideration the following set of observations and user-model suggestions<span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">, in the hope that</span> they will <span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">bring some useful</span> <span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">ideas to</span> the <span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">development</span> of the Valhalla project.<span class="gmail_default"></span><b><br></b></span></span></div><div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><b><br></b></span></span></div><div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><b><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></b><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><br><b>Definition<br></b><br></span></span></span></div><div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><u>shared-mutable</u>
- a variable that is mutable (non-final) and can be shared between
threads; shared-mutables are the non-final subset of the
shared-variables (<a href="https://docs.oracle.com/javase/specs/jls/se18/html/jls-17.html#jls-17.4.1" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">§17.4.1.</a>)<br><br><br><b>Observations<br></b><br>Shared-mutables are the only variables that have these two apparently independent properties:<br></span></span></span><ol><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">lack definite-assignment (<a href="https://docs.oracle.com/javase/specs/jls/se18/html/jls-16.html" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">§16.</a>) - the variable is initialized with a default-value if not definitely-assigned (<a href="https://docs.oracle.com/javase/specs/jls/se18/html/jls-4.html#jls-4.12.5" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">§4.12.5.</a>)</span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">allow
data-races - the variable may be read/written while being written by
another thread, with both events happening in an unpredictable order (<a href="https://docs.oracle.com/javase/specs/jls/se18/html/jls-17.html#jls-17.4.5" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">§17.4.5.</a>)</span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><br></span></span></span></li></ol><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span></span></span></span></div><div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">Via properties 1 and 2, <span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">nullability and encoding-mode, <span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">respectively, </span></span></span></span></span></span></span></span></span>affect <span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">the semantics<span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"> of variables </span></span></span></span><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span></span></span></span>in a way that is unique to shared-mutables:</span></span></span></span></span></span><ol><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">if not definitely-assigned, the variable is initialized with:</span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span></li><ul><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">if nullable: the null value, regardless of type</span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">if not nullable: the zero-value of the type</span></span></span></li></ul><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">in a data-race, the value read/written:</span></span></span></li><ul><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">if reference: has unpredictable origin in <u>one</u> of the various writes</span></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">if inline, either:</span></span></span></li><ul><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">has unpredictable origin in one of the various writes</span></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">is torn i.e. has distinct internal parts with separate unpredictable origins in <u>more than one</u> of the various writes (<a href="https://docs.oracle.com/javase/specs/jls/se18/html/jls-17.html#jls-17.7" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">§17.7.</a>)</span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span></li></ul></ul></ol><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span><br><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">These are the 3 kinds of shared-mutable variables (<a href="https://docs.oracle.com/javase/specs/jls/se18/html/jls-4.html#jls-4.12.3" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">§4.12.3.</a>):</span></span></span></div><div><ul><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">non-final class variables</span></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">non-final instance variables</span></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">array components</span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><br></span></span></span></li></ul><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">The remaining kinds of variables don't have any of the above properties:<br></span></span></span><ul><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">final class variables</span></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">final instance variables</span></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">method parameters</span></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">constructor parameters</span></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">lambda parameters</span></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">exception parameters</span></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">local variables</span></span></span><br><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span></li></ul><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><br><br><b>User-model</b></span></span></span></div></div><div dir="auto"><div dir="auto"><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif">For class-authors:</span></span></div><div dir="auto"><ul><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><u>value-knob</u> to reject identity - Applicable on class declarations, if used by a class-author to indicate that the class instances don't require identity (a value-class), the runtime will be free to copy these values and choose between reference or inline encoding everywhere except in shared-mutables, as doing so does not introduce any semantic changes to the program. In shared-mutables, however, value-instances can only be inlined if atomicity is guaranteed, which will depend on the hardware and the variable bit-size (value plus nullability).</span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><u>tearable-knob</u> to allow tearing - Applicable on value-class declarations, may be used by the class-author to hand the class-user the responsibility of how to avoid tearing, freeing the runtime to always inline instances in shared-mutables (bikeshedding: when dealing with tearable value-classes, the "terrible" sound can work as a warning for the dangers of neglecting this responsibility). Conversely, if this knob is not used, instances will be kept atomic, which allows the class-author to guarantee constructor invariants, which may be useful for the class implementation and class-users to rely upon.</span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><u>zero-knob</u> to allow using the zero-value as a default - by omission, the class-author will force shared-mutables of this type to either be definitely-assigned or nullable.</span></span></li></ul></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif">For class-users:</span></span></div><div dir="auto"><ul><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><u>not-nullable-knob</u> to exclude null from a variable's value-set - Applicable on any variable declaration. Since identity-types lack a zero-value, any non-nullable shared-mutable with an identity-type must be definitely-assigned. For nullable variables, in either encoding-mode, the runtime is free to choose the encoding for the extra bit of information required to represent null. In shared-mutables that are not definitely-assigned, this knob controls the default-value: either null or the zero-value of the type. <br></span></span></li><li><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"></span></span><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><u>atomic-knob</u> to avoid tearing - Applicable on shared-mutable declarations, may be used by the class-user to reverse the effect of the tearable-knob, thereby restoring atomicity.</span></span></li></ul></div></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"></span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><b>Nullable types</b></span></span></span></div><div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><b><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></b></span></span></div><div><ul><li><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">For compatibility, we cannot have a nullable-knob in the new user-model since unadorned type</span><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">s must remain nullable as they are now</span><br><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></li><li><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">(!) as a non-nullable-knob is pretty concise although not very readable<br></span></li><li><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">In method bodies, var will mitigate the majority of the noise of (!)</span></li><li><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">In method signatures, the proliferation of (!) in arguments and return types will look ugly</span></li><li><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">The compiler will be able to help us avoid the majority of NullPointerExceptions</span></li><li><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">Old APIs can compatibly update return types to be non-nullable where appropriate, which is more convenient for new client code. Also, <span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">removing the nullability overhead</span>
and may increase performance. Ex: <span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">Stream::findAny can be updated to return Optional!<T></span></span></span></span></span></span></span></li></ul></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><b>Zero-knob vs no-zero-knob<br></b></span></span></span></div><div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span><br></span></span></div><div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">I am going with the zero-knob because I feel it gives us the safest and most common default:</span></span></span></div><div><ul><li><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">Allows
a more cautious API introduction - A late addition of the zero-default to a
class doesn't break client code, but a late removal does.</span></li><li><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">Definite-assignment is safe - Without a zero-default, class-users are forced to definitely-assign their shared-mutables, preventing missed-initialization-bugs.</span></li><li><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">It's
the right default for value Records - The vast majority of Records are semantically value classes, since using any
identity operations on them would be a bug (locking or identity
comparison). Making these Records value-classes will prevent such bugs.
So I am predicting that the vast majority of value-classes written by
average developers will be Records, which mostly don't have a sensible
zero-value.</span></li></ul></div><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span><br></span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div dir="auto"><b><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span>Migration of value-based classes</span></span></b></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif">For compatibility with existing code, no value-based class can be tearable, and somewhat amazingly, not even Double or Long. The reason is that where <span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">in the current model we have</span> a field declaration such as:</span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">ValueBasedClass v = someValue;</span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif">v <span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">is</span> <span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">always</span><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span> reference encoded and, therefore, atomic. In the new model, the encoding-mode is fully encapsulated<span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span>, so the only way for v to remain atomic is all the migrated value-based classes not being declared tearable.</span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif">For Double and Long, this is a bit awkward, because it means that for these two primitives, and for them alone, <span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">each of these</span> pair of field declarations will not be<span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"> semantically</span> equivalent:</span></span></div><div dir="auto"><font size="2"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></font></div><div dir="auto"><span style="font-family:monospace"><font size="2"><span style="color:rgb(7,55,99)">long v; // tearable </span></font></span></div><div dir="auto"><span style="font-family:monospace"><font size="2"><span style="color:rgb(7,55,99)">Long! v; // atomic</span></font></span></div><div dir="auto"><span style="font-family:monospace"><font size="2"><span style="color:rgb(7,55,99)">double d; <span class="gmail_default" style="color:rgb(7,55,99)"> </span>// tearable</span></font></span></div><div dir="auto"><span style="font-family:monospace"><font size="2"><span style="color:rgb(7,55,99)">Double! d; // atomic</span></font></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif">Regardless of this peculiarity, the major downside <span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">of </span><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">being forced to make</span> <span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">all </span>value-based classes atomic is that, depending on<span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">:</span> <span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">target</span> architecture, primitive bit-size and nullability, we may not get inline encoding where we otherwise could. So, even though in the new model we can still achieve the same inlining as before<span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"> (</span>as the old primitives are still available<span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">)</span>, in a few situations<span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">,</span><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span>
the runtime may</span> have to resort to reference<span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"> encoding to ensure atomicity<span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">, <span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">even if atomicity is not needed</span></span></span></span></span></span>.</span> <span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)">I think this is a relatively small </span>price to pay for compatibility.<span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span></span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div dir="auto"><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><br></span></span></div><div dir="auto"><b><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span>Sample code</span></span></b></div><div dir="auto"><b><span style="color:rgb(7,55,99)"><span style="font-family:verdana,sans-serif"><span class="gmail_default" style="font-family:verdana,sans-serif;color:rgb(7,55,99)"></span><br></span></span></b></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)">//</span></span><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"> For brevity,</span></span></span><span class="gmail_default" style="color:rgb(7,55,99)"></span></span><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"> imports and the modifiers public, <span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)">final, extends and implements </span></span>are omitted.</span></span><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span></span><br><span style="color:rgb(7,55,99)"></span><span style="color:rgb(7,55,99)"></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">// Declaration of the primitive wrappers<span class="gmail_default" style="color:rgb(7,55,99)">.</span><span class="gmail_default" style="color:rgb(7,55,99)"></span></span></span></div><span style="font-family:monospace"><span style="color:rgb(7,55,99)">zero value class Boolean {...}<br></span></span><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">zero value class Char {...}<br></span></span></div><div dir="auto"><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">zero value class Byte {...}<br></span></span></div><div dir="auto"><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">zero value class Short {...}<br></span></span></div><span style="font-family:monospace"><span style="color:rgb(7,55,99)">zero value class Integer {...}<br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">zero value class Float {...}<br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">zero value class Long {...}<br></span></span><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">zero value class Double {...}</span></span></div></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">// declaration of some value-based classes</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">zero value class Optional {...}</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">value class Instant {...}</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">value class LocalDate {...}</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><br></span></span></div><div><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)">// declaration of some value classes</span><br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">tearable value class Rational {...}</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">tearable zero value class Complex {...}</span></span></div><span style="font-family:monospace"><br></span><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">// Fields</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">class C {<br></span></span></div><div><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"> double _tearable_0d;</span><span class="gmail_default" style="color:rgb(7,55,99)"></span><span class="gmail_default" style="color:rgb(7,55,99)"></span><span class="gmail_default" style="color:rgb(7,55,99)"></span><br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"> Double! <span class="gmail_default" style="color:rgb(7,55,99)"></span>_<span class="gmail_default" style="color:rgb(7,55,99)">atomic_</span>0d;<span class="gmail_default" style="color:rgb(7,55,99)"></span><span class="gmail_default" style="color:rgb(7,55,99)"></span><span class="gmail_default" style="color:rgb(7,55,99)"></span><span class="gmail_default" style="color:rgb(7,55,99)"></span><span class="gmail_default" style="color:rgb(7,55,99)"></span></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"> <span class="gmail_default" style="color:rgb(7,55,99)"></span><span class="gmail_default" style="color:rgb(7,55,99)"></span>Integer! _<span class="gmail_default" style="color:rgb(7,55,99)">atomic_2i</span><span class="gmail_default" style="color:rgb(7,55,99)"></span> = <span class="gmail_default" style="color:rgb(7,55,99)">2</span>;<span class="gmail_default" style="color:rgb(7,55,99)">
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
// <span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span><span class="gmail_default" style="color:rgb(7,55,99)"></span>Integer! <==> int</span><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"></span></span></span></span></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"> In<span class="gmail_default" style="color:rgb(7,55,99)">s</span>tant t_null;</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"> Intant! t_error; <span class="gmail_default" style="color:rgb(7,55,99)">
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
</span><span class="gmail_default" style="color:rgb(7,55,99)"></span>// <span class="gmail_default" style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span>error:<span class="gmail_default" style="color:rgb(7,55,99)"> <span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span><span class="gmail_default" style="color:rgb(7,55,99)">Blank field not initialized</span></span></span></span></span></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"> Instant! t = Instant.now();</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"> LocalDate! ld; <span class="gmail_default" style="color:rgb(7,55,99)">
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
</span>// <span class="gmail_default" style="color:rgb(7,55,99)"></span>error:<span class="gmail_default" style="color:rgb(7,55,99)"> <span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span><span class="gmail_default" style="color:rgb(7,55,99)">Blank field not initialized</span></span></span></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"> <span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span>atomic Rational! r = new Rational(2, 3)<span class="gmail_default" style="color:rgb(7,55,99)"></span>;</span></span></span></span></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"> final
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span>atomic Rational r2<span class="gmail_default" style="color:rgb(7,55,99)"></span>;
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span>
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
// error: Final fields are already atomic</span></span></span></span></span></span></span></span></span></span></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)"><span style="color:rgb(7,55,99)">
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span>Rational r<span class="gmail_default" style="color:rgb(7,55,99)">_null</span><span class="gmail_default" style="color:rgb(7,55,99)"></span>;</span>
<span class="gmail_default" style="color:rgb(7,55,99)"></span></span>
</span></span></span></span></span>
</span></span></span></span></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"> <span class="gmail_default" style="color:rgb(7,55,99)"></span>Rational<span class="gmail_default" style="color:rgb(7,55,99)">!</span> r<span class="gmail_default" style="color:rgb(7,55,99)">3</span><span class="gmail_default" style="color:rgb(7,55,99)"></span>; <span class="gmail_default" style="color:rgb(7,55,99)">
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
</span><span class="gmail_default" style="color:rgb(7,55,99)"></span>// error: <span class="gmail_default" style="color:rgb(7,55,99)"></span><span class="gmail_default" style="color:rgb(7,55,99)">Blank field not initialized</span></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">}</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">// <span class="gmail_default" style="color:rgb(7,55,99)">Local Variables and </span>Arrays</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">var _2zeros_d = new Double![2];<br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">var _3zeros_L= new atomic Long![3];</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">var ints = new atomic Integer![3];<span class="gmail_default" style="color:rgb(7,55,99)"> </span><span class="gmail_default" style="color:rgb(7,55,99)"></span><span class="gmail_default" style="color:rgb(7,55,99)">
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
</span>// <span class="gmail_default" style="color:rgb(7,55,99)">error: </span>Integer is <span class="gmail_default" style="color:rgb(7,55,99)"></span>already atomic<br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">atomic <span class="gmail_default" style="color:rgb(7,55,99)">Complex</span> nullable<span class="gmail_default" style="color:rgb(7,55,99)">Complex</span>;<span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)">
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
</span><span class="gmail_default" style="color:rgb(7,55,99)"></span>// error: local variables are already atomic</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">var s_nulls = new String[3];</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">var s_error = new String![3]; <span class="gmail_default" style="color:rgb(7,55,99)"> </span><span class="gmail_default" style="color:rgb(7,55,99)">
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
</span>// <span class="gmail_default" style="color:rgb(7,55,99)">error: array components not initialized</span><br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">var letters = new String![]{"a", "b"};<span class="gmail_default" style="color:rgb(7,55,99)"></span><br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">String nullable_letter_a = letters[0];</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">var nonNullable_letter_b = letters[1];<br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">letters[0] = "z";</span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">letters[1] = null; <span class="gmail_default" style="color:rgb(7,55,99)"> </span><span class="gmail_default" style="color:rgb(7,55,99)">
<span style="color:rgb(7,55,99)"><span class="gmail_default" style="color:rgb(7,55,99)"></span> <span class="gmail_default" style="color:rgb(7,55,99)"> </span></span>
</span>// error: <span class="gmail_default" style="color:rgb(7,55,99)">cannot convert from null to String!</span><span class="gmail_default" style="color:rgb(7,55,99)"></span><br></span></span></div><div dir="auto"><span style="font-family:monospace"><span style="color:rgb(7,55,99)">var _3emptyOpts = Optional!<span class="gmail_default" style="color:rgb(7,55,99)"><String></span>[3];</span></span></div><div><span style="font-family:monospace"><span style="color:rgb(7,55,99)"><br></span></span></div><div dir="auto"><div style="font-family:verdana,sans-serif;color:rgb(7,55,99)" class="gmail_default"><br></div><div style="font-family:verdana,sans-serif;color:rgb(7,55,99)" class="gmail_default">Kind regards,<br></div></div><div dir="auto"><div style="font-family:verdana,sans-serif;color:rgb(7,55,99)" class="gmail_default">João Menodnça
</div><br></div></div></div>
</div></div>