JVMS changes for JEP 401

John Rose john.r.rose at oracle.com
Tue Feb 6 15:56:32 UTC 2024


On 29 Jan 2024, at 10:22, Dan Smith wrote:

>>
>> As I understand the current design intent, a constructor that calls
>> 'this' is forbidden from assigning to a strict field, because that
>> will lead to a duplicate assignment in a constructor that calls
>> 'super'.
>>
>> This language appears to say the opposite. It seems to state that only
>> the first constructor of the current class can assign the class's
>> strict instance fields. If that is the case, then further constructors
>> (including the one that calls 'super') are forbidden from assigning to
>> strict instance fields.
>
> Hello,
> the problem is not duplicate assignment, as you said that part of the spec allows that,
> the problem is assignment of final fields after a call to super() or this() because when the assignment occurs, 'this' may have already leaked to another context.
>
> Right.
>
> There is a *language* rule that final fields must not be assigned more than once. (Specifically, they must be definitely unassigned before their assignment; we'll add a rule that final fields must be definitely assigned before a 'this()' call.)
>
> In the *JVM*, the only new thing we're guarding against is assignments after the constructor call. All assignments before a constructor call, duplicate or not, are allowed.

This might be worth a non-normative note, to the effect of, “One may notice that the VM may assign strict fields before this-calls in the VM.  Java compilers do not issue putfield instructions at such points, and we do not expect them to do so in the future.  A special restriction on such assignments would add no value.”


More information about the valhalla-spec-observers mailing list