equal
deleted
inserted
replaced
27 |
27 |
28 import jdk.internal.org.objectweb.asm.*; |
28 import jdk.internal.org.objectweb.asm.*; |
29 import sun.invoke.util.BytecodeDescriptor; |
29 import sun.invoke.util.BytecodeDescriptor; |
30 import jdk.internal.misc.Unsafe; |
30 import jdk.internal.misc.Unsafe; |
31 import sun.security.action.GetPropertyAction; |
31 import sun.security.action.GetPropertyAction; |
|
32 import sun.security.action.GetBooleanAction; |
32 |
33 |
33 import java.io.FilePermission; |
34 import java.io.FilePermission; |
34 import java.io.Serializable; |
35 import java.io.Serializable; |
35 import java.lang.reflect.Constructor; |
36 import java.lang.reflect.Constructor; |
36 import java.security.AccessController; |
37 import java.security.AccessController; |
85 private static final AtomicInteger counter = new AtomicInteger(0); |
86 private static final AtomicInteger counter = new AtomicInteger(0); |
86 |
87 |
87 // For dumping generated classes to disk, for debugging purposes |
88 // For dumping generated classes to disk, for debugging purposes |
88 private static final ProxyClassesDumper dumper; |
89 private static final ProxyClassesDumper dumper; |
89 |
90 |
|
91 private static final boolean disableEagerInitialization; |
|
92 |
90 static { |
93 static { |
91 final String key = "jdk.internal.lambda.dumpProxyClasses"; |
94 final String dumpProxyClassesKey = "jdk.internal.lambda.dumpProxyClasses"; |
92 String path = GetPropertyAction.privilegedGetProperty(key); |
95 String dumpPath = GetPropertyAction.privilegedGetProperty(dumpProxyClassesKey); |
93 dumper = (null == path) ? null : ProxyClassesDumper.getInstance(path); |
96 dumper = (null == dumpPath) ? null : ProxyClassesDumper.getInstance(dumpPath); |
|
97 |
|
98 final String disableEagerInitializationKey = "jdk.internal.lambda.disableEagerInitialization"; |
|
99 disableEagerInitialization = GetBooleanAction.privilegedGetProperty(disableEagerInitializationKey); |
94 } |
100 } |
95 |
101 |
96 // See context values in AbstractValidatingLambdaMetafactory |
102 // See context values in AbstractValidatingLambdaMetafactory |
97 private final String implMethodClassName; // Name of type containing implementation "CC" |
103 private final String implMethodClassName; // Name of type containing implementation "CC" |
98 private final String implMethodName; // Name of implementation method "impl" |
104 private final String implMethodName; // Name of implementation method "impl" |
185 * is not found |
191 * is not found |
186 */ |
192 */ |
187 @Override |
193 @Override |
188 CallSite buildCallSite() throws LambdaConversionException { |
194 CallSite buildCallSite() throws LambdaConversionException { |
189 final Class<?> innerClass = spinInnerClass(); |
195 final Class<?> innerClass = spinInnerClass(); |
190 if (invokedType.parameterCount() == 0) { |
196 if (invokedType.parameterCount() == 0 && !disableEagerInitialization) { |
|
197 // In the case of a non-capturing lambda, we optimize linkage by pre-computing a single instance, |
|
198 // unless we've suppressed eager initialization |
191 final Constructor<?>[] ctrs = AccessController.doPrivileged( |
199 final Constructor<?>[] ctrs = AccessController.doPrivileged( |
192 new PrivilegedAction<>() { |
200 new PrivilegedAction<>() { |
193 @Override |
201 @Override |
194 public Constructor<?>[] run() { |
202 public Constructor<?>[] run() { |
195 Constructor<?>[] ctrs = innerClass.getDeclaredConstructors(); |
203 Constructor<?>[] ctrs = innerClass.getDeclaredConstructors(); |
213 catch (ReflectiveOperationException e) { |
221 catch (ReflectiveOperationException e) { |
214 throw new LambdaConversionException("Exception instantiating lambda object", e); |
222 throw new LambdaConversionException("Exception instantiating lambda object", e); |
215 } |
223 } |
216 } else { |
224 } else { |
217 try { |
225 try { |
218 UNSAFE.ensureClassInitialized(innerClass); |
226 if (!disableEagerInitialization) { |
|
227 UNSAFE.ensureClassInitialized(innerClass); |
|
228 } |
219 return new ConstantCallSite( |
229 return new ConstantCallSite( |
220 MethodHandles.Lookup.IMPL_LOOKUP |
230 MethodHandles.Lookup.IMPL_LOOKUP |
221 .findStatic(innerClass, NAME_FACTORY, invokedType)); |
231 .findStatic(innerClass, NAME_FACTORY, invokedType)); |
222 } |
232 } |
223 catch (ReflectiveOperationException e) { |
233 catch (ReflectiveOperationException e) { |
271 fv.visitEnd(); |
281 fv.visitEnd(); |
272 } |
282 } |
273 |
283 |
274 generateConstructor(); |
284 generateConstructor(); |
275 |
285 |
276 if (invokedType.parameterCount() != 0) { |
286 if (invokedType.parameterCount() != 0 || disableEagerInitialization) { |
277 generateFactory(); |
287 generateFactory(); |
278 } |
288 } |
279 |
289 |
280 // Forward the SAM method |
290 // Forward the SAM method |
281 MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, samMethodName, |
291 MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, samMethodName, |