RFR: [performance] Early class initialization from LambdaMetafactory improves lambda linkage performance
Sergey Kuksenko
sergey.kuksenko at oracle.com
Thu Sep 26 08:02:51 PDT 2013
Hi Remi,
ReflectiveOperationException is checked exception. Moving it into
PrivilegedAction requires to use PrivilegedExceptionAction, catching
PrivilegedActionException and rethrowing the exception. I don't think
that such code will be simpler than existing.
I am returning array of constructors because of I want don't change a
source of exception and do constructors check outside PrivilegedAction.
On 09/11/2013 09:43 PM, Remi Forax wrote:
> 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
>
>
--
Best regards,
Sergey Kuksenko
More information about the lambda-dev
mailing list