From 97a8d12e56a6257812486bae40e9ad6bb410b4dd Mon Sep 17 00:00:00 2001 From: Rangeet Pan Date: Thu, 23 May 2024 10:31:33 -0400 Subject: [PATCH] update call graph --- .../ibm/northstar/SystemDependencyGraph.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/main/java/com/ibm/northstar/SystemDependencyGraph.java b/src/main/java/com/ibm/northstar/SystemDependencyGraph.java index 48c99adb..ac22e1f1 100644 --- a/src/main/java/com/ibm/northstar/SystemDependencyGraph.java +++ b/src/main/java/com/ibm/northstar/SystemDependencyGraph.java @@ -76,6 +76,7 @@ private static JSONExporter, AbstractGraphEdge> getGraphE return gson.toJson(vertex); } ); +// exporter.setVertexAttributeProvider(v -> v.getRight().getAttributes()); exporter.setEdgeAttributeProvider(AbstractGraphEdge::getAttributes); return exporter; } @@ -151,6 +152,41 @@ private static org.jgrapht.Graph, AbstractGraphEdge> buil } } })); + + callGraph.getEntrypointNodes() + .forEach(p -> { + // Get call statements that may execute in a given method + Iterator outGoingCalls = p.iterateCallSites(); + outGoingCalls.forEachRemaining(n -> { + callGraph.getPossibleTargets(p, n).stream() + .filter(o -> AnalysisUtils.isApplicationClass(o.getMethod().getDeclaringClass())) + .forEach(o -> { + + // Add the source nodes to the graph as vertices + Pair source = Optional.ofNullable(getCallableFromSymbolTable(p.getMethod())).orElseGet(() -> createAndPutNewCallableInSymbolTable(p.getMethod())); + graph.addVertex(source); + + // Add the target nodes to the graph as vertices + Pair target = Optional.ofNullable(getCallableFromSymbolTable(o.getMethod())).orElseGet(() -> createAndPutNewCallableInSymbolTable(o.getMethod())); + graph.addVertex(target); + + if (!source.equals(target) && source.getRight() != null && target.getRight() != null) { + + // Get the edge between the source and the target + AbstractGraphEdge cgEdge = graph.getEdge(source, target); + + if (cgEdge == null) { + graph.addEdge(source, target, new CallEdge()); + } + // If edge exists, then increment the weight + else { + cgEdge.incrementWeight(); + } + } + }); + }); + }); + return graph; }