diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java index a1322a197ae6..b2bd6c67e655 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java @@ -60,7 +60,6 @@ import com.oracle.svm.core.graal.phases.OptimizeExceptionPathsPhase; import com.oracle.svm.core.heap.RestrictHeapAccess; import com.oracle.svm.core.heap.RestrictHeapAccessCallees; -import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport; import com.oracle.svm.core.meta.MethodPointer; import com.oracle.svm.core.meta.SubstrateMethodPointerConstant; import com.oracle.svm.core.util.InterruptImageBuilding; @@ -181,14 +180,6 @@ protected PhaseSuite getAfterParseSuite() { private final boolean printMethodHistogram = NativeImageOptions.PrintMethodHistogram.getValue(); private final boolean optionAOTTrivialInline = SubstrateOptions.AOTTrivialInline.getValue(); - /** - * Indicates we need to force compilation of all possible methods so that all calls to the prior - * layers have a target. - * - * The criteria for this will become more nuanced as part of GR-57021. - */ - private final boolean layeredForceCompilation = ImageLayerBuildingSupport.buildingSharedLayer() && !SubstrateOptions.UseSharedLayerGraphs.getValue(); - public record UnpublishedTrivialMethods(CompilationGraph unpublishedGraph, boolean newlyTrivial) { } @@ -637,8 +628,8 @@ private void parseAheadOfTimeCompiledMethods() { */ continue; } - if (layeredForceCompilation || layeredForceCompilation(hMethod)) { - // when layered force compilation is enabled we try to parse all graphs + if (layeredForceCompilation(hMethod)) { + // when layered force compilation is triggered we try to parse all graphs if (method.wrapped.getAnalyzedGraph() != null) { ensureParsed(method, null, new EntryPointReason()); } @@ -935,9 +926,9 @@ public void scheduleEntryPoints() { continue; } - if (layeredForceCompilation || layeredForceCompilation(hMethod)) { + if (layeredForceCompilation(hMethod)) { /* - * when layeredForceCompilation is enabled we try to parse all graphs. + * when layeredForceCompilation is triggered we try to parse all graphs. */ if (method.compilationInfo.getCompilationGraph() != null) { ensureCompiled(hMethod, new EntryPointReason()); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java index 24d1f2ebc3cb..13472f39cb72 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java @@ -757,6 +757,22 @@ private void markDataRelocationSiteFromText(RelocatableBuffer buffer, final Prog } } + private static String getUniqueShortName(ResolvedJavaMethod sm) { + String name; + if (sm instanceof HostedMethod hMethod) { + if (hMethod.isCompiledInPriorLayer()) { + // ensure we use a consistent symbol name across layers + name = HostedDynamicLayerInfo.singleton().loadMethodNameInfo(hMethod.getWrapped()).uniqueShortName(); + } else { + name = hMethod.getUniqueShortName(); + } + } else { + name = SubstrateUtil.uniqueShortName(sm); + } + + return name; + } + /** * Given a {@link ResolvedJavaMethod}, compute what symbol name of its start address (if any) in * the image. The symbol name returned is the one that would be used for local references (e.g. @@ -768,7 +784,7 @@ private void markDataRelocationSiteFromText(RelocatableBuffer buffer, final Prog * does) */ public static String localSymbolNameForMethod(ResolvedJavaMethod sm) { - return SubstrateOptions.ImageSymbolsPrefix.getValue() + (sm instanceof HostedMethod ? ((HostedMethod) sm).getUniqueShortName() : SubstrateUtil.uniqueShortName(sm)); + return SubstrateOptions.ImageSymbolsPrefix.getValue() + getUniqueShortName(sm); } /** @@ -798,7 +814,7 @@ public static String globalSymbolNameForMethod(java.lang.reflect.Method m) { * does) */ public static String globalSymbolNameForMethod(ResolvedJavaMethod sm) { - return mangleName((sm instanceof HostedMethod ? ((HostedMethod) sm).getUniqueShortName() : SubstrateUtil.uniqueShortName(sm))); + return mangleName(getUniqueShortName(sm)); } @Override diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/HostedDynamicLayerInfo.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/HostedDynamicLayerInfo.java index 2ab347f624e1..5fccabf435e0 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/HostedDynamicLayerInfo.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/HostedDynamicLayerInfo.java @@ -67,7 +67,7 @@ public class HostedDynamicLayerInfo extends DynamicImageLayerInfo implements Lay private final Map methodIdToOffsetMap; private final ConcurrentHashMap methodIdToNameInfoMap; private final CGlobalData cGlobalData; - private final Set priorLayerHostedMethods = new HashSet<>(); + private final Set priorLayerMethodSymbols = new HashSet<>(); private boolean persisted = false; HostedDynamicLayerInfo() { @@ -131,14 +131,14 @@ public void registerHostedMethod(HostedMethod hMethod) { AnalysisMethod aMethod = hMethod.getWrapped(); if (compiledInPriorLayer(aMethod)) { assert aMethod.isInBaseLayer() : hMethod; - priorLayerHostedMethods.add(hMethod); + priorLayerMethodSymbols.add(localSymbolNameForMethod(hMethod)); hMethod.setCompiledInPriorLayer(); } } public void defineSymbolsForPriorLayerMethods(ObjectFile objectFile) { assert BuildPhaseProvider.isHeapLayoutFinished(); - priorLayerHostedMethods.forEach(m -> objectFile.createUndefinedSymbol(localSymbolNameForMethod(m), 0, true)); + priorLayerMethodSymbols.forEach(symbol -> objectFile.createUndefinedSymbol(symbol, 0, true)); } @Override diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedMethodNameFactory.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedMethodNameFactory.java index 2468bc8d8f83..9ca4a1169ad0 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedMethodNameFactory.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedMethodNameFactory.java @@ -54,23 +54,32 @@ public static HostedMethodNameFactory singleton() { MethodNameInfo createNames(Function nameGenerator, AnalysisMethod aMethod) { MethodNameInfo result = buildingExtensionLayer ? HostedDynamicLayerInfo.singleton().loadMethodNameInfo(aMethod) : null; - if (result == null) { - MethodNameInfo initialName = nameGenerator.apply(0); - result = initialName; + if (result != null) { + assert reservedUniqueShortNames.contains(result.uniqueShortName()) : result; - do { - int collisionCount = methodNameCount.merge(initialName.uniqueShortName(), 0, (oldValue, value) -> oldValue + 1); - if (collisionCount != 0) { - result = nameGenerator.apply(collisionCount); - } + boolean added = uniqueShortNames.add(result.uniqueShortName()); + if (added) { /* - * Redo if the short name is reserved. + * Currently it is possible for the same method id to be assigned to multiple + * AnalysisMethods. However, only one is assigned this name. */ - } while (buildingExtensionLayer && reservedUniqueShortNames.contains(result.uniqueShortName())); - } else { - assert reservedUniqueShortNames.contains(result.uniqueShortName()) : result; + return result; + } } + MethodNameInfo initialName = nameGenerator.apply(0); + result = initialName; + + do { + int collisionCount = methodNameCount.merge(initialName.uniqueShortName(), 0, (oldValue, value) -> oldValue + 1); + if (collisionCount != 0) { + result = nameGenerator.apply(collisionCount); + } + /* + * Redo if the short name is reserved. + */ + } while (buildingExtensionLayer && reservedUniqueShortNames.contains(result.uniqueShortName())); + boolean added = uniqueShortNames.add(result.uniqueShortName()); VMError.guarantee(added, "failed to generate uniqueShortName for HostedMethod: %s", result.uniqueShortName());