[lworld] RFR: 8281166: [lworld] javac should generate BSM to invoke the static factory for value class

Rémi Forax forax at openjdk.java.net
Mon Feb 7 08:00:38 UTC 2022


On Mon, 7 Feb 2022 07:32:28 GMT, Srikanth Adayapalam <sadayapalam at openjdk.org> wrote:

>> When constructor reference expressions invole value classes, ensure that TransValues will see the constructor call in order for that call to be transformed into factory method invocation.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java line 2345:
> 
>> 2343:                           tree.kind != ReferenceKind.ARRAY_CTOR &&
>> 2344:                           (tree.sym.owner.isDirectlyOrIndirectlyLocal() || tree.sym.owner.isInner() || tree.sym.owner.isValueClass()));
>> 2345:             }
> 
> Notes for reviewer: Basically by forcing the constructor references to be converted into lambdas, we ensure that later pipeline stages will see the constructor invocation. For example, with the code change above, given a value class V, a constructor reference of the form V::new will be transformed into a lambda implementation method of the form 
> 
> 
> /*synthetic*/ private static X$V lambda$main$1() {
>     return new X$V();
> }
> 
> This lambda implementation method has the constructor invocation intact which can then be detected and transformed by *com.sun.tools.javac.jvm.TransValues#visitNewClass*
> 
> (It is possible to directly emit BSM entries without converting them to lambda but that would result in code duplication - we would have to look at DynamicMethod symbols, pick them apart and reencode static and dynamic arguments to indy so that value constructors (and primitive class constructors are reencoded to static factory)

I wonder if the transformation from a constructor call to a static method call when it's a value class should not be done before the lambda transformation ?

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

PR: https://git.openjdk.java.net/valhalla/pull/629



More information about the valhalla-dev mailing list