|
34 | 34 | import java.util.function.Consumer; |
35 | 35 | import java.util.stream.Stream; |
36 | 36 |
|
| 37 | +import com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod; |
37 | 38 | import com.oracle.svm.core.SubstrateOptions; |
| 39 | +import com.oracle.svm.hosted.substitute.SubstitutionMethod; |
38 | 40 | import org.graalvm.compiler.code.CompilationResult; |
39 | 41 | import org.graalvm.compiler.code.SourceMapping; |
40 | 42 | import org.graalvm.compiler.debug.DebugContext; |
41 | 43 | import org.graalvm.compiler.graph.NodeSourcePosition; |
42 | 44 | import org.graalvm.nativeimage.ImageSingletons; |
43 | 45 |
|
44 | | -import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; |
45 | | -import com.oracle.graal.pointsto.meta.AnalysisType; |
46 | 46 | import com.oracle.objectfile.debuginfo.DebugInfoProvider; |
47 | 47 | import com.oracle.svm.core.graal.code.SubstrateBackend; |
48 | 48 | import com.oracle.svm.hosted.image.sources.SourceManager; |
49 | 49 | import com.oracle.svm.hosted.meta.HostedMethod; |
50 | | -import com.oracle.svm.hosted.meta.HostedType; |
51 | 50 |
|
52 | 51 | import jdk.vm.ci.meta.LineNumberTable; |
53 | 52 | import jdk.vm.ci.meta.ResolvedJavaMethod; |
@@ -84,36 +83,47 @@ public Stream<DebugDataInfo> dataInfoProvider() { |
84 | 83 | return Stream.empty(); |
85 | 84 | } |
86 | 85 |
|
| 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 | + |
87 | 111 | /** |
88 | 112 | * Implementation of the DebugCodeInfo API interface that allows code info to be passed to an |
89 | 113 | * ObjectFile when generation of debug info is enabled. |
90 | 114 | */ |
91 | 115 | private class NativeImageDebugCodeInfo implements DebugCodeInfo { |
92 | 116 | private final HostedMethod method; |
93 | | - private final ResolvedJavaType javaType; |
94 | 117 | private final CompilationResult compilation; |
95 | 118 | private Path fullFilePath; |
96 | 119 | private final Path cachePath; |
97 | 120 |
|
98 | 121 | @SuppressWarnings("try") |
99 | 122 | NativeImageDebugCodeInfo(HostedMethod method, CompilationResult compilation) { |
100 | 123 | 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(); |
109 | 124 | this.compilation = compilation; |
110 | 125 | 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); |
117 | 127 | } |
118 | 128 |
|
119 | 129 | @SuppressWarnings("try") |
@@ -157,7 +167,7 @@ public String className() { |
157 | 167 |
|
158 | 168 | @Override |
159 | 169 | public String originalClassName() { |
160 | | - return javaType.toClassName(); |
| 170 | + return method.getDeclaringClass().toClassName(); |
161 | 171 | } |
162 | 172 |
|
163 | 173 | @Override |
@@ -257,7 +267,7 @@ private class NativeImageDebugLineInfo implements DebugLineInfo { |
257 | 267 | this.lo = sourceMapping.getStartOffset(); |
258 | 268 | this.hi = sourceMapping.getEndOffset(); |
259 | 269 | this.cachePath = SubstrateOptions.getDebugInfoSourceCacheRoot(); |
260 | | - computeFullFilePath(); |
| 270 | + this.fullFilePath = computeFullFilePath(method); |
261 | 271 | } |
262 | 272 |
|
263 | 273 | @Override |
@@ -317,33 +327,6 @@ public int line() { |
317 | 327 | } |
318 | 328 | return -1; |
319 | 329 | } |
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 | | - |
347 | 330 | } |
348 | 331 |
|
349 | 332 | /** |
|
0 commit comments