RFR: 8355442: Reference field lambda forms with type casts are not generated [v2]

Jorn Vernee jvernee at openjdk.org
Tue Apr 29 21:41:49 UTC 2025


On Sat, 26 Apr 2025 23:47:01 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Currently, we are not generating all possible field lambda forms.
>> 
>> Field lambda forms have these dimensions:
>> - get/set
>> - instance/static/static+class init barrier
>> - plain/volatile
>> - 8 primitive types, no-cast object, object with cast
>> 
>> Bringing to a total of 2 × 3 × 2 × 10 = 120 lambda forms.
>> 
>> Previously, the ones with init barrier or object with cast types were not generated due to spamming the Kind enum. In retrospect, I believe skipping the object with cast form is a poor choice - tons of Java fields are using non-interface types. Also seems the volatile accessors were omitted in InvokerBytecodeGenerator, which made their pregen useless.
>> 
>> I have utilized erased method types to distinguish forms - get/set, 5 basic types, and instance/static can be distinguished by the types, so the Kind enums now only represent init, volatile, and non-basic types (byte, char, short, boolean, casts), bringing the total constants to 24 down from 40 previously.
>> 
>> In the long run, we should investigate update `Kind` to allow flexible representations - an enum is too restrictive especially with the erased types.
>
> Chen Liang has updated the pull request incrementally with one additional commit since the last revision:
> 
>   use var

src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java line 626:

> 624:             FT_UNCHECKED_REF   = Wrapper.OBJECT.ordinal(),
> 625:             FT_CHECKED_REF     = Wrapper.VOID.ordinal(),
> 626:             FT_LIMIT           = Wrapper.COUNT;

I don't see why these changes are needed?

src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java line 440:

> 438:                     throw new InternalError(b + " non-volatile " + ftype);
> 439:                 forms.add(form);
> 440:                 names.add(form.kind.defaultLambdaName);

I suppose the fact that static/non-static variants have the same name is okay since they will have a different number of parameters?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24887#discussion_r2067451587
PR Review Comment: https://git.openjdk.org/jdk/pull/24887#discussion_r2067447230


More information about the core-libs-dev mailing list