Skip to content

Commit 835ee7b

Browse files
committed
Use implemented interfaces in lambda name generation.
1 parent a8157fe commit 835ee7b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/java/LambdaUtils.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.regex.Pattern;
3838

3939
import jdk.graal.compiler.bytecode.BytecodeStream;
40+
import jdk.graal.compiler.debug.GraalError;
4041
import jdk.graal.compiler.util.Digest;
4142
import jdk.vm.ci.common.JVMCIError;
4243
import jdk.vm.ci.meta.ConstantPool;
@@ -141,18 +142,28 @@ public static boolean isLambdaName(String name) {
141142
return isLambdaClassName(name) && lambdaMatcher(name).find();
142143
}
143144

144-
private static String createStableLambdaName(ResolvedJavaType lambdaType, List<JavaMethod> targetMethods) {
145+
private static String createStableLambdaName(ResolvedJavaType lambdaType, List<JavaMethod> invokedMethods) {
145146
final String lambdaName = lambdaType.getName();
146147
assert lambdaMatcher(lambdaName).find() : "Stable name should be created for lambda types: " + lambdaName;
147148

148149
Matcher m = lambdaMatcher(lambdaName);
150+
/* Generate lambda signature by hashing its composing parts. */
149151
StringBuilder sb = new StringBuilder();
150-
targetMethods.forEach((targetMethod) -> sb.append(targetMethod.format("%H.%n(%P)%R")));
151-
// Take parameter types of constructor into consideration, see GR-52837
152+
/* Append invoked methods. */
153+
for (JavaMethod method : invokedMethods) {
154+
sb.append(method.format("%H.%n(%P)%R"));
155+
}
156+
/* Append constructor parameter types. */
152157
for (JavaMethod ctor : lambdaType.getDeclaredConstructors()) {
153158
sb.append(ctor.format("%P"));
154159
}
155-
return m.replaceFirst(Matcher.quoteReplacement(LAMBDA_CLASS_NAME_SUBSTRING + ADDRESS_PREFIX + Digest.digestAsHex(sb.toString()) + ";"));
160+
/* Append implemented interfaces. */
161+
for (ResolvedJavaType iface : lambdaType.getInterfaces()) {
162+
sb.append(iface.toJavaName());
163+
}
164+
String signature = Digest.digestAsHex(sb.toString());
165+
GraalError.guarantee(signature.length() == 32, "Expecting a 32 digits long hex value.");
166+
return m.replaceFirst(Matcher.quoteReplacement(LAMBDA_CLASS_NAME_SUBSTRING + ADDRESS_PREFIX + signature + ";"));
156167
}
157168

158169
private static Matcher lambdaMatcher(String value) {

0 commit comments

Comments
 (0)