Skip to content

Commit 998dbaa

Browse files
committed
[GR-68616] Fix DynamicAccessDetectionPhase listing wrong source method when working with inlined callers and avoid duplicates
PullRequest: graal/21810
2 parents 9bba5fc + ed75ba6 commit 998dbaa

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/DynamicAccessDetectionFeature.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
import java.util.Set;
5656
import java.util.Map;
5757
import java.util.concurrent.ConcurrentHashMap;
58-
import java.util.concurrent.ConcurrentLinkedQueue;
5958
import java.util.concurrent.ConcurrentSkipListMap;
59+
import java.util.concurrent.ConcurrentSkipListSet;
6060
import java.util.stream.Collectors;
6161
import java.util.stream.Stream;
6262

@@ -71,6 +71,8 @@
7171
@AutomaticallyRegisteredFeature
7272
public final class DynamicAccessDetectionFeature implements InternalFeature {
7373

74+
// We use a ConcurrentSkipListMap, as opposed to a ConcurrentHashMap, to maintain
75+
// order of methods by access kind.
7476
public record MethodsByAccessKind(Map<DynamicAccessDetectionPhase.DynamicAccessKind, CallLocationsByMethod> methodsByAccessKind) {
7577
MethodsByAccessKind() {
7678
this(new ConcurrentSkipListMap<>());
@@ -85,7 +87,9 @@ public CallLocationsByMethod getCallLocationsByMethod(DynamicAccessDetectionPhas
8587
}
8688
}
8789

88-
public record CallLocationsByMethod(Map<String, ConcurrentLinkedQueue<String>> callLocationsByMethod) {
90+
// We use a ConcurrentSkipListSet, as opposed to a wrapped ConcurrentHashMap, to maintain
91+
// order of call locations by method.
92+
public record CallLocationsByMethod(Map<String, ConcurrentSkipListSet<String>> callLocationsByMethod) {
8993
CallLocationsByMethod() {
9094
this(new ConcurrentSkipListMap<>());
9195
}
@@ -94,8 +98,8 @@ public Set<String> getMethods() {
9498
return callLocationsByMethod.keySet();
9599
}
96100

97-
public ConcurrentLinkedQueue<String> getMethodCallLocations(String methodName) {
98-
return callLocationsByMethod.getOrDefault(methodName, new ConcurrentLinkedQueue<>());
101+
public ConcurrentSkipListSet<String> getMethodCallLocations(String methodName) {
102+
return callLocationsByMethod.getOrDefault(methodName, new ConcurrentSkipListSet<>());
99103
}
100104
}
101105

@@ -136,7 +140,7 @@ public static DynamicAccessDetectionFeature instance() {
136140
public void addCall(String entry, DynamicAccessDetectionPhase.DynamicAccessKind accessKind, String call, String callLocation) {
137141
MethodsByAccessKind entryContent = callsBySourceEntry.computeIfAbsent(entry, k -> new MethodsByAccessKind());
138142
CallLocationsByMethod methodCallLocations = entryContent.methodsByAccessKind().computeIfAbsent(accessKind, k -> new CallLocationsByMethod());
139-
ConcurrentLinkedQueue<String> callLocations = methodCallLocations.callLocationsByMethod().computeIfAbsent(call, k -> new ConcurrentLinkedQueue<>());
143+
ConcurrentSkipListSet<String> callLocations = methodCallLocations.callLocationsByMethod().computeIfAbsent(call, k -> new ConcurrentSkipListSet<>());
140144
callLocations.add(callLocation);
141145
}
142146

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/DynamicAccessDetectionPhase.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ protected void run(StructuredGraph graph, CoreProviders context) {
231231
MethodInfo methodInfo = getMethodInfo(callTarget.targetMethod());
232232

233233
if (methodInfo != null && sourceEntry != null) {
234-
NodeSourcePosition nspToShow = getRootSourcePosition(callTarget.getNodeSourcePosition());
234+
NodeSourcePosition nspToShow = callTarget.getNodeSourcePosition();
235235
if (nspToShow != null && !dynamicAccessDetectionFeature.containsFoldEntry(nspToShow.getBCI(), nspToShow.getMethod())) {
236236
String callLocation = nspToShow.getMethod().asStackTraceElement(nspToShow.getBCI()).toString();
237237
dynamicAccessDetectionFeature.addCall(sourceEntry, methodInfo.accessKind(), methodInfo.signature(), callLocation);
@@ -317,14 +317,6 @@ private static String getSourceEntry(AnalysisType callerClass) {
317317
}
318318
}
319319

320-
private static NodeSourcePosition getRootSourcePosition(NodeSourcePosition nodeSourcePosition) {
321-
NodeSourcePosition rootNodeSourcePosition = nodeSourcePosition;
322-
while (rootNodeSourcePosition != null && rootNodeSourcePosition.getCaller() != null) {
323-
rootNodeSourcePosition = rootNodeSourcePosition.getCaller();
324-
}
325-
return rootNodeSourcePosition;
326-
}
327-
328320
public static void clearMethodSignatures() {
329321
reflectionMethodSignatures.clear();
330322
resourceMethodSignatures.clear();

0 commit comments

Comments
 (0)