Skip to content

Commit 6ae8b0f

Browse files
committed
Update LambdaStableNameTest based on new interface rule.
1 parent cf86e02 commit 6ae8b0f

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/LambdaStableNameTest.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
package jdk.graal.compiler.hotspot.test;
2727

2828
import static org.junit.Assert.assertEquals;
29+
import static org.junit.Assert.assertNotEquals;
2930
import static org.junit.Assert.assertNotNull;
3031
import static org.junit.Assert.assertTrue;
3132
import static org.junit.Assert.fail;
3233

3334
import java.math.BigInteger;
35+
import java.util.function.Function;
3436

3537
import org.junit.Test;
3638
import org.objectweb.asm.Type;
@@ -40,22 +42,43 @@
4042
import jdk.vm.ci.runtime.JVMCI;
4143

4244
public class LambdaStableNameTest {
45+
4346
@Test
4447
public void checkStableLamdaNameForRunnableAndAutoCloseable() {
4548
String s = "a string";
46-
Runnable r = s::hashCode;
47-
ResolvedJavaType rType = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaType(r.getClass());
49+
Runnable r0 = s::hashCode;
50+
String r0Name = getLambdaName(r0.getClass());
4851

49-
String name = LambdaUtils.findStableLambdaName(rType);
50-
assertLambdaName(name);
52+
Runnable r1 = s::hashCode;
53+
String r1Name = getLambdaName(r1.getClass());
54+
55+
assertEquals("The two stable lambda names should the same as they reference the same method and implement the same interface", r0Name, r1Name);
5156

5257
AutoCloseable ac = s::hashCode;
53-
ResolvedJavaType acType = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaType(ac.getClass());
54-
String acName = LambdaUtils.findStableLambdaName(acType);
55-
assertEquals("Both stable lambda names are the same as they reference the same method", name, acName);
58+
String acName = getLambdaName(ac.getClass());
59+
60+
assertNotEquals("The two stable lambda names should not be the same as they reference the same method but implement different interfaces", r0Name, acName);
5661

5762
String myName = Type.getInternalName(getClass());
58-
assertEquals("The name known in 24.0 version is computed", "L" + myName + "$$Lambda.0x605511206480068bfd9e0bafd4f79e22;", name);
63+
assertEquals("The name known in 24.0 version is computed", "L" + myName + "$$Lambda.0x59cf38d78b5471f8ea57f1c28b37039c;", r0Name);
64+
65+
Function<String, Integer> f0 = (str) -> str.hashCode();
66+
String f0Name = getLambdaName(f0.getClass());
67+
68+
interface ValueTransformer<L, R> extends Function<L, R> {
69+
}
70+
71+
ValueTransformer<String, Integer> f1 = (str) -> str.hashCode();
72+
String f1Name = getLambdaName(f1.getClass());
73+
74+
assertNotEquals("The two stable lambda names should not be the same as they reference the same method but implement different interfaces", f0Name, f1Name);
75+
}
76+
77+
private static String getLambdaName(Class<?> clazz) {
78+
ResolvedJavaType type = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaType(clazz);
79+
String name = LambdaUtils.findStableLambdaName(type);
80+
assertLambdaName(name);
81+
return name;
5982
}
6083

6184
private static void assertLambdaName(String name) {

0 commit comments

Comments
 (0)