Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -181,14 +180,6 @@ protected PhaseSuite<HighTierContext> 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) {
}

Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class HostedDynamicLayerInfo extends DynamicImageLayerInfo implements Lay
private final Map<Integer, Integer> methodIdToOffsetMap;
private final ConcurrentHashMap<Integer, MethodNameInfo> methodIdToNameInfoMap;
private final CGlobalData<PointerBase> cGlobalData;
private final Set<HostedMethod> priorLayerHostedMethods = new HashSet<>();
private final Set<String> priorLayerMethodSymbols = new HashSet<>();
private boolean persisted = false;

HostedDynamicLayerInfo() {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,32 @@ public static HostedMethodNameFactory singleton() {

MethodNameInfo createNames(Function<Integer, MethodNameInfo> 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());

Expand Down