[lworld] RFR: 8334484: [lworld] new translation strategy for instance field initializers [v5]
Maurizio Cimadamore
mcimadamore at openjdk.org
Tue Apr 1 15:15:25 UTC 2025
On Mon, 31 Mar 2025 21:17:48 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> Proxy locals are added as a new compiler phase which is executed just before code generation.
>>
>> Q - what it does?
>> A - basically for code like:
>>
>> abstract value class Super {
>> Super(String s) {}
>> }
>>
>> value class V extends Super {
>> int i;
>> V(String s) {
>> if (s != null) {
>> i = 100;
>> } else {
>> i = 200;
>> }
>> super("100" + s);
>> }
>> }
>>
>> javac will generate for V's constructor something in the lines of:
>>
>> V(String s) {
>> /*synthetic*/ int local$i;
>> if (s != null) {
>> local$i = 100;
>> } else {
>> local$i = 200;
>> }
>> {
>> /*synthetic*/ final String local$0 = "100" + s;
>> i = local$i;
>> super(local$0);
>> }
>> }
>>
>> so given a constructor for which any strict field is assigned to more than once, javac will generate synthetic local variables that will correspond to it and any read or write done to this strict field will be done on the synthetic local variable.
>>
>> Javac will also generate additional synthetic local variables to hold the arguments, if any, of the super constructor invocation and will assign the strict fields with the current value of the corresponding synthetic local just before invoking the super constructor.
>>
>> Q - does it interacts with other valhalla features?
>> A - yes it has a direct interaction with the new stackmap table as the new assert_unset_fields entry, in most cases, is not generated now
>> Q- is it on by default?
>> A- yes but there is a hidden option to tell javac not to generate local proxy variables: `noLocalProxyVars` this will allow us to continue using javac for test cases that check for the generation of the assert_unset_fields entry in the stackmap table attribute until we have time to migrate those tests
>>
>> TIA for any comments
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
>
> adding tests
Marked as reviewed by mcimadamore (Committer).
Overall, this should be good enough to be integrated
-------------
PR Review: https://git.openjdk.org/valhalla/pull/1403#pullrequestreview-2733055789
PR Comment: https://git.openjdk.org/valhalla/pull/1403#issuecomment-2769705753
More information about the valhalla-dev
mailing list