Skip to content

Commit

Permalink
Ensure uniqueness of short names for constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
adinn committed Oct 6, 2022
1 parent bd9803f commit 3d15b72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,14 @@ public String mangle(String loaderName, ResolvedJavaType declaringClass, String
String selector = memberName;
if (isConstructor) {
assert methodSignature != null;
assert selector.equals("<init>");
int index = fqn.lastIndexOf('.');
// replace <init> with the class name n.b. it may include a disambiguating suffix
assert selector.startsWith("<init>");
String replacement = fqn;
int index = replacement.lastIndexOf('.');
if (index >= 0) {
selector = fqn.substring(index);
} else {
selector = fqn;
replacement = fqn.substring(index + 1);
}
selector = selector.replace("<init>", replacement);
}
mangleClassAndMemberName(loaderName, fqn, selector);
if (methodSignature != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public static HostedMethod create(HostedUniverse universe, AnalysisMethod wrappe
int collisionCount = universe.uniqueHostedMethodNames.merge(uniqueShortName, 0, (oldValue, value) -> oldValue + 1);
if (collisionCount > 0) {
name = name + METHOD_NAME_COLLISION_SUFFIX + collisionCount;
uniqueShortName = SubstrateUtil.uniqueShortName(holder.getJavaClass().getClassLoader(), holder, name, signature, wrapped.isConstructor());
String fixedUniqueShortName = SubstrateUtil.uniqueShortName(holder.getJavaClass().getClassLoader(), holder, name, signature, wrapped.isConstructor());
VMError.guarantee(!fixedUniqueShortName.equals(uniqueShortName), "failed to generate uniqueShortName for HostedMethod created for " + wrapped);
uniqueShortName = fixedUniqueShortName;
}
return new HostedMethod(wrapped, holder, signature, constantPool, handlers, deoptOrigin, name, uniqueShortName, localVariableTable);
}
Expand Down

0 comments on commit 3d15b72

Please sign in to comment.