From e95f4285819d5b189ba1ed6a2d266abcd4a50b83 Mon Sep 17 00:00:00 2001 From: Sergey Kuksenko Date: Tue, 29 Oct 2013 12:45:18 -0400 Subject: [PATCH] 8024633: Lambda linkage performance - initialize generated class earlier Reviewed-by: briangoetz, rfield --- .../invoke/InnerClassLambdaMetafactory.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/jdk/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java b/jdk/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java index a989ddf0bd4..a85c505c0f8 100644 --- a/jdk/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java +++ b/jdk/src/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java @@ -197,22 +197,20 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; new PrivilegedAction() { @Override public Constructor[] run() { - return innerClass.getDeclaredConstructors(); + Constructor[] ctrs = innerClass.getDeclaredConstructors(); + if (ctrs.length == 1) { + // The lambda implementing inner class constructor is private, set + // it accessible (by us) before creating the constant sole instance + ctrs[0].setAccessible(true); + } + return ctrs; } - }); + }); if (ctrs.length != 1) { throw new LambdaConversionException("Expected one lambda constructor for " + innerClass.getCanonicalName() + ", got " + ctrs.length); } - // The lambda implementing inner class constructor is private, set - // it accessible (by us) before creating the constant sole instance - AccessController.doPrivileged(new PrivilegedAction() { - @Override - public Void run() { - ctrs[0].setAccessible(true); - return null; - } - }); + try { Object inst = ctrs[0].newInstance(); return new ConstantCallSite(MethodHandles.constant(samBase, inst)); @@ -222,6 +220,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; } } else { try { + UNSAFE.ensureClassInitialized(innerClass); return new ConstantCallSite( MethodHandles.Lookup.IMPL_LOOKUP .findStatic(innerClass, NAME_FACTORY, invokedType));