Skip to content

Commit 0feed58

Browse files
committed
DebugInfo: Get correct file path for substituted methods
When computing the full file path for the source file of a method check to see if this is a substitution method and get the source file containing it instead of the source file containing the original method. So if we have Foo.java that defines Foo.m which substitutes Bar.n which is defined in Bar.java this patch will associate code segments of Bar.n with Foo.java instead of Bar.java.
1 parent 58d2bd0 commit 0feed58

File tree

2 files changed

+34
-49
lines changed

2 files changed

+34
-49
lines changed

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

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,19 @@
3434
import java.util.function.Consumer;
3535
import java.util.stream.Stream;
3636

37+
import com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod;
3738
import com.oracle.svm.core.SubstrateOptions;
39+
import com.oracle.svm.hosted.substitute.SubstitutionMethod;
3840
import org.graalvm.compiler.code.CompilationResult;
3941
import org.graalvm.compiler.code.SourceMapping;
4042
import org.graalvm.compiler.debug.DebugContext;
4143
import org.graalvm.compiler.graph.NodeSourcePosition;
4244
import org.graalvm.nativeimage.ImageSingletons;
4345

44-
import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider;
45-
import com.oracle.graal.pointsto.meta.AnalysisType;
4646
import com.oracle.objectfile.debuginfo.DebugInfoProvider;
4747
import com.oracle.svm.core.graal.code.SubstrateBackend;
4848
import com.oracle.svm.hosted.image.sources.SourceManager;
4949
import com.oracle.svm.hosted.meta.HostedMethod;
50-
import com.oracle.svm.hosted.meta.HostedType;
5150

5251
import jdk.vm.ci.meta.LineNumberTable;
5352
import jdk.vm.ci.meta.ResolvedJavaMethod;
@@ -84,36 +83,47 @@ public Stream<DebugDataInfo> dataInfoProvider() {
8483
return Stream.empty();
8584
}
8685

86+
private ResolvedJavaType getDeclaringClass(ResolvedJavaMethod method) {
87+
ResolvedJavaMethod wrappedMethod = method;
88+
while (wrappedMethod instanceof WrappedJavaMethod) {
89+
wrappedMethod = ((WrappedJavaMethod) wrappedMethod).getWrapped();
90+
}
91+
ResolvedJavaType declaringClass;
92+
if (wrappedMethod instanceof SubstitutionMethod) {
93+
declaringClass = ((SubstitutionMethod) wrappedMethod).getAnnotated().getDeclaringClass();
94+
} else {
95+
declaringClass = wrappedMethod.getDeclaringClass();
96+
}
97+
return declaringClass;
98+
}
99+
100+
@SuppressWarnings("try")
101+
private Path computeFullFilePath(ResolvedJavaMethod method) {
102+
ResolvedJavaType declaringClass = getDeclaringClass(method);
103+
SourceManager sourceManager = ImageSingletons.lookup(SourceManager.class);
104+
try (DebugContext.Scope s = debugContext.scope("DebugCodeInfo", declaringClass)) {
105+
return sourceManager.findAndCacheSource(declaringClass, debugContext);
106+
} catch (Throwable e) {
107+
throw debugContext.handle(e);
108+
}
109+
}
110+
87111
/**
88112
* Implementation of the DebugCodeInfo API interface that allows code info to be passed to an
89113
* ObjectFile when generation of debug info is enabled.
90114
*/
91115
private class NativeImageDebugCodeInfo implements DebugCodeInfo {
92116
private final HostedMethod method;
93-
private final ResolvedJavaType javaType;
94117
private final CompilationResult compilation;
95118
private Path fullFilePath;
96119
private final Path cachePath;
97120

98121
@SuppressWarnings("try")
99122
NativeImageDebugCodeInfo(HostedMethod method, CompilationResult compilation) {
100123
this.method = method;
101-
HostedType declaringClass = method.getDeclaringClass();
102-
Class<?> clazz = declaringClass.getJavaClass();
103-
/*
104-
* HostedType wraps an AnalysisType and both HostedType and AnalysisType punt calls to
105-
* getSourceFilename to the wrapped class so for consistency we need to do the path
106-
* lookup relative to the doubly unwrapped HostedType.
107-
*/
108-
this.javaType = declaringClass.getWrapped().getWrapped();
109124
this.compilation = compilation;
110125
this.cachePath = SubstrateOptions.getDebugInfoSourceCacheRoot();
111-
SourceManager sourceManager = ImageSingletons.lookup(SourceManager.class);
112-
try (DebugContext.Scope s = debugContext.scope("DebugCodeInfo", declaringClass)) {
113-
fullFilePath = sourceManager.findAndCacheSource(javaType, clazz, debugContext);
114-
} catch (Throwable e) {
115-
throw debugContext.handle(e);
116-
}
126+
this.fullFilePath = computeFullFilePath(method);
117127
}
118128

119129
@SuppressWarnings("try")
@@ -157,7 +167,7 @@ public String className() {
157167

158168
@Override
159169
public String originalClassName() {
160-
return javaType.toClassName();
170+
return method.getDeclaringClass().toClassName();
161171
}
162172

163173
@Override
@@ -257,7 +267,7 @@ private class NativeImageDebugLineInfo implements DebugLineInfo {
257267
this.lo = sourceMapping.getStartOffset();
258268
this.hi = sourceMapping.getEndOffset();
259269
this.cachePath = SubstrateOptions.getDebugInfoSourceCacheRoot();
260-
computeFullFilePath();
270+
this.fullFilePath = computeFullFilePath(method);
261271
}
262272

263273
@Override
@@ -317,33 +327,6 @@ public int line() {
317327
}
318328
return -1;
319329
}
320-
321-
@SuppressWarnings("try")
322-
private void computeFullFilePath() {
323-
ResolvedJavaType declaringClass = method.getDeclaringClass();
324-
Class<?> clazz = null;
325-
if (declaringClass instanceof OriginalClassProvider) {
326-
clazz = ((OriginalClassProvider) declaringClass).getJavaClass();
327-
}
328-
/*
329-
* HostedType wraps an AnalysisType and both HostedType and AnalysisType punt calls to
330-
* getSourceFilename to the wrapped class so for consistency we need to do the path
331-
* lookup relative to the doubly unwrapped HostedType or singly unwrapped AnalysisType.
332-
*/
333-
if (declaringClass instanceof HostedType) {
334-
declaringClass = ((HostedType) declaringClass).getWrapped();
335-
}
336-
if (declaringClass instanceof AnalysisType) {
337-
declaringClass = ((AnalysisType) declaringClass).getWrapped();
338-
}
339-
SourceManager sourceManager = ImageSingletons.lookup(SourceManager.class);
340-
try (DebugContext.Scope s = debugContext.scope("DebugCodeInfo", declaringClass)) {
341-
fullFilePath = sourceManager.findAndCacheSource(declaringClass, clazz, debugContext);
342-
} catch (Throwable e) {
343-
throw debugContext.handle(e);
344-
}
345-
}
346-
347330
}
348331

349332
/**

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
package com.oracle.svm.hosted.image.sources;
2828

29+
import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider;
30+
import com.oracle.svm.hosted.c.GraalAccess;
2931
import jdk.vm.ci.meta.ResolvedJavaType;
3032
import org.graalvm.compiler.debug.DebugContext;
3133

@@ -46,12 +48,11 @@ public class SourceManager {
4648
* the source.
4749
*
4850
* @param resolvedType the Java type whose source file should be located and cached
49-
* @param clazz the Java class associated with the resolved type
5051
* @param debugContext context for logging details of any lookup failure
5152
* @return a path identifying the location of a successfully cached file for inclusion in the
5253
* generated debug info or null if a source file cannot be found or cached.
5354
*/
54-
public Path findAndCacheSource(ResolvedJavaType resolvedType, Class<?> clazz, DebugContext debugContext) {
55+
public Path findAndCacheSource(ResolvedJavaType resolvedType, DebugContext debugContext) {
5556
/* short circuit if we have already seen this type */
5657
Path path = verifiedPaths.get(resolvedType);
5758
if (path != null) {
@@ -68,6 +69,7 @@ public Path findAndCacheSource(ResolvedJavaType resolvedType, Class<?> clazz, De
6869
*/
6970
if (resolvedType.isInstanceClass() || resolvedType.isInterface()) {
7071
String packageName = computePackageName(resolvedType);
72+
Class<?> clazz = OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), resolvedType);
7173
path = locateSource(fileName, packageName, clazz);
7274
if (path == null) {
7375
// as a last ditch effort derive path from the Java class name

0 commit comments

Comments
 (0)