[lworld] RFR: 8334484: [lworld] new translation strategy for instance field initializers [v3]

Vicente Romero vromero at openjdk.org
Sat Mar 29 01:06:05 UTC 2025


> 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:

  addressing review comments

-------------

Changes:
  - all: https://git.openjdk.org/valhalla/pull/1403/files
  - new: https://git.openjdk.org/valhalla/pull/1403/files/de6020a6..dae0fc32

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=valhalla&pr=1403&range=02
 - incr: https://webrevs.openjdk.org/?repo=valhalla&pr=1403&range=01-02

  Stats: 116 lines in 7 files changed: 35 ins; 59 del; 22 mod
  Patch: https://git.openjdk.org/valhalla/pull/1403.diff
  Fetch: git fetch https://git.openjdk.org/valhalla.git pull/1403/head:pull/1403

PR: https://git.openjdk.org/valhalla/pull/1403


More information about the valhalla-dev mailing list