mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8232806: Introduce a system property to disable eager lambda initialization
Reviewed-by: briangoetz, mr, psandoz, forax
This commit is contained in:
parent
4fcd28bf54
commit
29f2d74173
3 changed files with 88 additions and 27 deletions
|
@ -26,8 +26,11 @@
|
|||
* @bug 8003280
|
||||
* @summary Add lambda tests
|
||||
* Test bridge methods for certain SAM conversions
|
||||
* Tests that jdk.internal.lambda.disableEagerInitialization=true creates a
|
||||
* get$Lambda method for non-capturing lambdas
|
||||
* @compile LambdaTest6.java
|
||||
* @run main LambdaTest6
|
||||
* @run main/othervm -Djdk.internal.lambda.disableEagerInitialization=true LambdaTest6
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -60,18 +63,37 @@ public class LambdaTest6<T> {
|
|||
return s;
|
||||
}
|
||||
|
||||
private static Set<String> allowedMethods() {
|
||||
Set<String> s = new HashSet<>();
|
||||
s.add("m");
|
||||
if (Boolean.getBoolean("jdk.internal.lambda.disableEagerInitialization")) {
|
||||
s.add("get$Lambda");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private static boolean matchingMethodNames(Method[] methods) {
|
||||
Set<String> methodNames = new HashSet<>();
|
||||
for (Method m : methods) {
|
||||
methodNames.add(m.getName());
|
||||
}
|
||||
return methodNames.equals(allowedMethods());
|
||||
}
|
||||
|
||||
private void test1()
|
||||
{
|
||||
L la = s -> { };
|
||||
la.m("hi");
|
||||
Class<? extends L> c1 = la.getClass();
|
||||
Method[] methods = c1.getDeclaredMethods();
|
||||
assertTrue(matchingMethodNames(methods));
|
||||
Set<String> types = setOfStringObject();
|
||||
for(Method m : methods) {
|
||||
assertTrue(m.getName().equals("m"));
|
||||
Class[] parameterTypes = m.getParameterTypes();
|
||||
assertTrue(parameterTypes.length == 1);
|
||||
assertTrue(types.remove(parameterTypes[0].getName()));
|
||||
if ("m".equals(m.getName())) {
|
||||
Class[] parameterTypes = m.getParameterTypes();
|
||||
assertTrue(parameterTypes.length == 1);
|
||||
assertTrue(types.remove(parameterTypes[0].getName()));
|
||||
}
|
||||
}
|
||||
assertTrue(types.isEmpty() || (types.size() == 1 && types.contains("java.lang.String")));
|
||||
}
|
||||
|
@ -82,12 +104,14 @@ public class LambdaTest6<T> {
|
|||
//km.m("hi");
|
||||
Class<? extends KM> c2 = km.getClass();
|
||||
Method[] methods = c2.getDeclaredMethods();
|
||||
assertTrue(matchingMethodNames(methods));
|
||||
Set<String> types = setOfStringObject();
|
||||
for(Method m : methods) {
|
||||
assertTrue(m.getName().equals("m"));
|
||||
Class[] parameterTypes = m.getParameterTypes();
|
||||
assertTrue(parameterTypes.length == 1);
|
||||
assertTrue(types.remove(parameterTypes[0].getName()));
|
||||
if ("m".equals(m.getName())) {
|
||||
Class[] parameterTypes = m.getParameterTypes();
|
||||
assertTrue(parameterTypes.length == 1);
|
||||
assertTrue(types.remove(parameterTypes[0].getName()));
|
||||
}
|
||||
}
|
||||
assertTrue(types.isEmpty());
|
||||
}
|
||||
|
@ -99,11 +123,13 @@ public class LambdaTest6<T> {
|
|||
assertTrue( ((H)na).m().equals("hi") );
|
||||
Class<? extends N> c3 = na.getClass();
|
||||
Method[] methods = c3.getDeclaredMethods();
|
||||
assertTrue(matchingMethodNames(methods));
|
||||
Set<String> types = setOfStringObject();
|
||||
for(Method m : methods) {
|
||||
assertTrue(m.getName().equals("m"));
|
||||
Class returnType = m.getReturnType();
|
||||
assertTrue(types.remove(returnType.getName()));
|
||||
if ("m".equals(m.getName())) {
|
||||
Class returnType = m.getReturnType();
|
||||
assertTrue(types.remove(returnType.getName()));
|
||||
}
|
||||
}
|
||||
assertTrue(types.size() == 1); //there's a bridge
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue