On Fri, 9 Dec 2022 18:02:53 GMT, Jorn Vernee <jver...@openjdk.org> wrote:

> Refactor LambdaForm constructors into static factories.
> 
> In the new code, there's only 1 constructor, which simply initializes all 
> fields. Multiple factory methods are built on top of this, which add various 
> argument validation/pre-processing and post processing of the constructed 
> lambda forms.
> 
> In the LambdaFrom class itself, it is easier to see which LF creation goes 
> through which checks due to names of factory, or if all checks are bypassed 
> by calling the constructor.
> 
> New factories can easily be added that bypass all the checks in the existing 
> factories and just call the root constructor if they so wish to (we likely 
> want to add several for lazy lambda form resolution 
> https://bugs.openjdk.org/browse/JDK-8288041).
> 
> Additionally: replaced some default values literals with named constants so 
> it's easy to see that it's just the default value for that arg at the call 
> site.

LGTM. Nice to get rid of the in-flight side-effect of mutating 
`LambdaForm::names` in `normalize`, which seemed suspect as `names` is marked 
as `@Stable`.

src/java.base/share/classes/java/lang/invoke/LambdaForm.java line 347:

> 345:     // root factory pre/post processing and calls simple cosntructor
> 346:     private static LambdaForm create(int arity, Name[] names, int 
> result, boolean forceInline, MethodHandle customized, Kind kind) {
> 347:         names = names.clone();

Probably not important - and not for this RFE - but looking through the calls 
it seems that for some uses of `create` cloning the input array is superfluous. 
Maybe there's a very slight efficiency gain to be had here by making cloning 
the responsibility of the caller.

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

Marked as reviewed by redestad (Reviewer).

PR: https://git.openjdk.org/jdk/pull/11612

Reply via email to