Skip to content

Commit 95c0e03

Browse files
committed
ensure uniqueness of short names for constructors
1 parent b62e37c commit 95c0e03

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageBFDNameProvider.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,14 @@ public String mangle(String loaderName, ResolvedJavaType declaringClass, String
365365
String selector = memberName;
366366
if (isConstructor) {
367367
assert methodSignature != null;
368-
assert selector.equals("<init>");
369-
int index = fqn.lastIndexOf('.');
368+
// replace <init> with the class name n.b. it may include a disambiguating suffix
369+
assert selector.startsWith("<init>");
370+
String replacement = fqn;
371+
int index = replacement.lastIndexOf('.');
370372
if (index >= 0) {
371-
selector = fqn.substring(index);
372-
} else {
373-
selector = fqn;
373+
replacement = fqn.substring(index + 1);
374374
}
375+
selector = selector.replace("<init>", replacement);
375376
}
376377
mangleClassAndMemberName(loaderName, fqn, selector);
377378
if (methodSignature != null) {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedMethod.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ public static HostedMethod create(HostedUniverse universe, AnalysisMethod wrappe
108108
int collisionCount = universe.uniqueHostedMethodNames.merge(uniqueShortName, 0, (oldValue, value) -> oldValue + 1);
109109
if (collisionCount > 0) {
110110
name = name + METHOD_NAME_COLLISION_SUFFIX + collisionCount;
111-
uniqueShortName = SubstrateUtil.uniqueShortName(holder.getJavaClass().getClassLoader(), holder, name, signature, wrapped.isConstructor());
111+
String fixedUniqueShortName = SubstrateUtil.uniqueShortName(holder.getJavaClass().getClassLoader(), holder, name, signature, wrapped.isConstructor());
112+
VMError.guarantee(!fixedUniqueShortName.equals(uniqueShortName), "failed to generate uniqueShortName for HostedMethod created for " + wrapped);
113+
uniqueShortName = fixedUniqueShortName;
112114
}
113115
return new HostedMethod(wrapped, holder, signature, constantPool, handlers, deoptOrigin, name, uniqueShortName, localVariableTable);
114116
}

0 commit comments

Comments
 (0)