Skip to content

Commit 9fbd75d

Browse files
committed
[GR-58055] Track fallback methods created within fallbackResolveConcreteMethod.
PullRequest: graal/19426
2 parents 2b69a66 + dc1aeb4 commit 9fbd75d

File tree

3 files changed

+18
-50
lines changed

3 files changed

+18
-50
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java

+3-48
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ public abstract class AnalysisType extends AnalysisElement implements WrappedJav
161161
* implement a method.
162162
*/
163163
private static final Object NULL_METHOD = new Object();
164-
private static final Object COMPUTING_FALLBACK_RESOLUTION = new Object();
165164

166165
private final AnalysisType componentType;
167166
private final AnalysisType elementalType;
@@ -1118,7 +1117,6 @@ public AnalysisMethod resolveConcreteMethod(ResolvedJavaMethod method, ResolvedJ
11181117
if (resolvedMethod == null) {
11191118
ResolvedJavaMethod originalMethod = OriginalMethodProvider.getOriginalMethod(method);
11201119
Object newResolvedMethod = null;
1121-
boolean computingFallback = false;
11221120
if (originalMethod != null) {
11231121
/*
11241122
* We do not want any access checks to be performed, so we use the method's
@@ -1130,27 +1128,7 @@ public AnalysisMethod resolveConcreteMethod(ResolvedJavaMethod method, ResolvedJ
11301128
var concreteMethod = originalMethod instanceof BaseLayerMethod ? originalMethod : wrapped.resolveConcreteMethod(originalMethod, originalCallerType);
11311129
newResolvedMethod = universe.lookup(concreteMethod);
11321130
if (newResolvedMethod == null) {
1133-
/*
1134-
* Note we cannot directly use computeIfAbsent; calling
1135-
* fallbackResolveConcreteMethod will potentially cause other entries to be
1136-
* added to resolvedMethods, resulting in illegal recursive updates.
1137-
*/
1138-
Object oldResolvedMethod = resolvedMethods.putIfAbsent(method, COMPUTING_FALLBACK_RESOLUTION);
1139-
if (oldResolvedMethod == null) {
1140-
computingFallback = true;
1141-
try {
1142-
newResolvedMethod = getUniverse().getBigbang().fallbackResolveConcreteMethod(this, (AnalysisMethod) method);
1143-
} catch (Throwable t) {
1144-
/* Finalize result if an error occurs. */
1145-
resolvedMethods.compute(method, (k, v) -> {
1146-
assert v == COMPUTING_FALLBACK_RESOLUTION : v;
1147-
return NULL_METHOD;
1148-
});
1149-
computingFallback = false;
1150-
1151-
throw t;
1152-
}
1153-
}
1131+
newResolvedMethod = getUniverse().getBigbang().fallbackResolveConcreteMethod(this, (AnalysisMethod) method);
11541132
}
11551133

11561134
} catch (UnsupportedFeatureException e) {
@@ -1162,32 +1140,9 @@ public AnalysisMethod resolveConcreteMethod(ResolvedJavaMethod method, ResolvedJ
11621140
if (newResolvedMethod == null) {
11631141
newResolvedMethod = NULL_METHOD;
11641142
}
1165-
1166-
if (computingFallback) {
1167-
/*
1168-
* If computingFallback is set, it is this thread's responsibility to install the
1169-
* result and override the placeholder put in the map.
1170-
*/
1171-
var finalResolvedMethod = newResolvedMethod;
1172-
resolvedMethods.compute(method, (k, v) -> {
1173-
assert v == COMPUTING_FALLBACK_RESOLUTION : v;
1174-
return finalResolvedMethod;
1175-
});
1176-
resolvedMethod = newResolvedMethod;
1177-
} else {
1178-
Object oldResolvedMethod = resolvedMethods.putIfAbsent(method, newResolvedMethod);
1179-
resolvedMethod = oldResolvedMethod != null ? oldResolvedMethod : newResolvedMethod;
1180-
}
1181-
}
1182-
1183-
/*
1184-
* Wait for fallback resolution computation to complete on another thread (if needed).
1185-
*/
1186-
while (resolvedMethod == COMPUTING_FALLBACK_RESOLUTION) {
1187-
Thread.onSpinWait();
1188-
resolvedMethod = resolvedMethods.get(method);
1143+
Object oldResolvedMethod = resolvedMethods.putIfAbsent(method, newResolvedMethod);
1144+
resolvedMethod = oldResolvedMethod != null ? oldResolvedMethod : newResolvedMethod;
11891145
}
1190-
assert resolvedMethod != null;
11911146
return resolvedMethod == NULL_METHOD ? null : (AnalysisMethod) resolvedMethod;
11921147
}
11931148

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/analysis/NativeImagePointsToAnalysis.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.lang.reflect.Modifier;
3030
import java.util.Arrays;
3131
import java.util.List;
32+
import java.util.concurrent.ConcurrentHashMap;
3233
import java.util.stream.Stream;
3334

3435
import com.oracle.graal.pointsto.ClassInclusionPolicy;
@@ -60,6 +61,7 @@
6061
import jdk.vm.ci.code.BytecodePosition;
6162
import jdk.vm.ci.meta.ConstantReflectionProvider;
6263
import jdk.vm.ci.meta.ResolvedJavaType;
64+
import jdk.vm.ci.meta.Signature;
6365

6466
public class NativeImagePointsToAnalysis extends PointsToAnalysis implements Inflation {
6567

@@ -68,6 +70,14 @@ public class NativeImagePointsToAnalysis extends PointsToAnalysis implements Inf
6870
private final CustomTypeFieldHandler customTypeFieldHandler;
6971
private final CallChecker callChecker;
7072

73+
/**
74+
* Track the fallback methods created so that they are unique.
75+
*/
76+
private final ConcurrentHashMap<FallbackDescriptor, IncompatibleClassChangeFallbackMethod> fallbackMethods = new ConcurrentHashMap<>();
77+
78+
record FallbackDescriptor(AnalysisType resolvingType, String name, Signature signature) {
79+
}
80+
7181
@SuppressWarnings("this-escape")
7282
public NativeImagePointsToAnalysis(OptionValues options, AnalysisUniverse universe,
7383
AnalysisMetaAccess metaAccess, SnippetReflectionProvider snippetReflectionProvider,
@@ -206,7 +216,10 @@ public AnalysisMethod fallbackResolveConcreteMethod(AnalysisType resolvingType,
206216
*/
207217
return method;
208218
}
209-
return getUniverse().lookup(new IncompatibleClassChangeFallbackMethod(resolvingType.getWrapped(), method.getWrapped(), findResolutionError(resolvingType, method.getJavaMethod())));
219+
220+
var uniqueFallbackMethod = fallbackMethods.computeIfAbsent(new FallbackDescriptor(resolvingType, method.getName(), method.getSignature()),
221+
(k) -> new IncompatibleClassChangeFallbackMethod(resolvingType.getWrapped(), method.getWrapped(), findResolutionError(resolvingType, method.getJavaMethod())));
222+
return getUniverse().lookup(uniqueFallbackMethod);
210223
}
211224
return super.fallbackResolveConcreteMethod(resolvingType, method);
212225
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ private static class BinutilsCCLinkerInvocation extends CCLinkerInvocation {
273273
additionalPreOptions.add("-Wl,--gc-sections");
274274
}
275275

276-
if (!imageKind.isExecutable) {
276+
if (imageKind.isImageLayer) {
277277
/*
278278
* We do not want interposition to affect the resolution of symbols we define and
279279
* reference within this library.

0 commit comments

Comments
 (0)