Skip to content

Commit e9df11e

Browse files
committed
Add jarPath retrieval
1 parent 23bb3af commit e9df11e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ public class AnalyzeMethodsRequiringMetadataUsagePhase extends BasePhase<CorePro
178178
protected void run(StructuredGraph graph, CoreProviders context) {
179179
List<MethodCallTargetNode> callTargetNodes = graph.getNodes(MethodCallTargetNode.TYPE).snapshot();
180180
for (MethodCallTargetNode callTarget : callTargetNodes) {
181+
AnalysisType callerClass = (AnalysisType) graph.method().getDeclaringClass();
182+
String jarPath = getJarPath(callerClass);
181183
Pair<String, String> methodDetails = getMethod(graph, callTarget);
182-
if (methodDetails != null) {
184+
if (methodDetails != null && jarPath != null) {
183185
String methodType = methodDetails.getLeft();
184186
String methodName = methodDetails.getRight();
185187

@@ -199,10 +201,6 @@ protected void run(StructuredGraph graph, CoreProviders context) {
199201
}
200202

201203
public Pair<String, String> getMethod(StructuredGraph graph, MethodCallTargetNode callTarget) {
202-
AnalysisType callerClass = (AnalysisType) graph.method().getDeclaringClass();
203-
if (!containedInJars(callerClass)) {
204-
return null;
205-
}
206204
String methodName = callTarget.targetMethod().getName();
207205
String declaringClass = callTarget.targetMethod().getDeclaringClass().toJavaName();
208206

@@ -218,19 +216,23 @@ public Pair<String, String> getMethod(StructuredGraph graph, MethodCallTargetNod
218216
return null;
219217
}
220218

221-
private boolean containedInJars(AnalysisType callerClass) {
219+
private String getJarPath(AnalysisType callerClass) {
222220
try {
223221
CodeSource jarPathSource = callerClass.getJavaClass().getProtectionDomain().getCodeSource();
224222
if (jarPathSource == null) {
225-
return false;
223+
return null;
226224
}
227225

228226
URL jarPathURL = jarPathSource.getLocation();
229227
if (jarPathURL == null) {
230-
return false;
228+
return null;
231229
}
232230

233-
return AnalyzeMethodsRequiringMetadataUsageFeature.instance().getJarPaths().contains(jarPathURL.toURI().getPath());
231+
String jarPath = jarPathURL.toURI().getPath();
232+
if (AnalyzeMethodsRequiringMetadataUsageFeature.instance().getJarPaths().contains(jarPath)) {
233+
return jarPath;
234+
}
235+
return null;
234236
} catch (URISyntaxException e) {
235237
throw new RuntimeException(e);
236238
}

0 commit comments

Comments
 (0)