From c8af3abfd02d49704ab920c396003efbf29ad217 Mon Sep 17 00:00:00 2001 From: jovanstevanovic Date: Wed, 26 Jul 2023 09:37:53 +0200 Subject: [PATCH] Make unique stub names stable. --- .../com/oracle/svm/core/SubstrateUtil.java | 19 +++++++++++++++---- .../UniqueShortNameProviderDefaultImpl.java | 15 +-------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java index 1c606e57f13f..2f903676314b 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java @@ -322,11 +322,22 @@ public static String uniqueShortName(Member m) { * @return a unique stub name for the method */ public static String uniqueStubName(ResolvedJavaMethod m) { - String shortName = UniqueShortNameProvider.singleton().uniqueShortName(null, m.getDeclaringClass(), m.getName(), m.getSignature(), m.isConstructor()); - return stripPackage(m.getDeclaringClass().toJavaName()) + "_" + - (m.isConstructor() ? "constructor" : m.getName()) + "_" + - SubstrateUtil.digest(shortName); + return uniqueShortName("", m.getDeclaringClass(), m.getName(), m.getSignature(), m.isConstructor()); + } + + public static String uniqueShortName(String loaderNameAndId, ResolvedJavaType declaringClass, String methodName, Signature methodSignature, boolean isConstructor) { + StringBuilder sb = new StringBuilder(loaderNameAndId); + sb.append(declaringClass.toClassName()).append(".").append(methodName).append("("); + for (int i = 0; i < methodSignature.getParameterCount(false); i++) { + sb.append(methodSignature.getParameterType(i, null).toClassName()).append(","); + } + sb.append(')'); + if (!isConstructor) { + sb.append(methodSignature.getReturnType(null).toClassName()); + } + return stripPackage(declaringClass.toJavaName()) + "_" + + (isConstructor ? "constructor" : methodName) + "_" + digest(sb.toString()); } /** diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/UniqueShortNameProviderDefaultImpl.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/UniqueShortNameProviderDefaultImpl.java index e0f54073a420..7e3b86b65cf4 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/UniqueShortNameProviderDefaultImpl.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/UniqueShortNameProviderDefaultImpl.java @@ -45,20 +45,7 @@ public class UniqueShortNameProviderDefaultImpl implements UniqueShortNameProvider { @Override public String uniqueShortName(ClassLoader loader, ResolvedJavaType declaringClass, String methodName, Signature methodSignature, boolean isConstructor) { - String loaderName = SubstrateUtil.classLoaderNameAndId(loader); - StringBuilder sb = new StringBuilder(loaderName); - sb.append(declaringClass.toClassName()).append(".").append(methodName).append("("); - for (int i = 0; i < methodSignature.getParameterCount(false); i++) { - sb.append(methodSignature.getParameterType(i, null).toClassName()).append(","); - } - sb.append(')'); - if (!isConstructor) { - sb.append(methodSignature.getReturnType(null).toClassName()); - } - - return SubstrateUtil.stripPackage(declaringClass.toJavaName()) + "_" + - (isConstructor ? "constructor" : methodName) + "_" + - SubstrateUtil.digest(sb.toString()); + return SubstrateUtil.uniqueShortName(SubstrateUtil.classLoaderNameAndId(loader), declaringClass, methodName, methodSignature, isConstructor); } @Override