RFR: [performance] Early class initialization from LambdaMetafactory improves lambda linkage performance

Remi Forax forax at univ-mlv.fr
Wed Sep 11 10:43:17 PDT 2013


On 09/11/2013 07:14 PM, Aleksey Shipilev wrote:
> On 09/11/2013 08:23 PM, Sergey Kuksenko wrote:
>> http://cr.openjdk.java.net/~skuksenko/jsr335/8024633/webrev.00/
> Looks good. (Not the Reviewer).
>
> -Aleksey.
>
>

you can simplify the code a little, you don't need to check the length 
of the array twice,
and the privileged action can return only the constructor instead of the 
array
avoiding to access the first element twice.

if (invokedType.parameterCount() == 0) {
     final Constructor constructor = AccessController.doPrivileged(
         new PrivilegedAction<Constructor[]>() {
             @Override
             public Constructor[] run() {
                 Constructor<?>[] constructors = innerClass.getDeclaredConstructors();
                 if (constructors.length != 1) {
                     throw new ReflectiveOperationException("Expected one lambda constructor for "
                          + innerClass.getCanonicalName() + ", got " +constructors.length);
                 }
                 Constructor constructor = ctrs[0];
                 // The lambda implementing inner class constructor is private, set
                 // it accessible (by us) before creating the constant sole instance
                 constructor.setAccessible(true);
                 return constructor;
             }
         });
     Object instance = constructor.newInstance();
     return new ConstantCallSite(MethodHandles.constant(samBase, instance));

I've let the 'final' in front of of the declaration constructor (line 2) 
even final is not used
for the declaration of other local variables and add in my opinion only 
noise.

Rémi



More information about the lambda-dev mailing list