From 083f0cc2368162631cc8e7b58cf96634fbb4fe15 Mon Sep 17 00:00:00 2001 From: Teng Zhang Date: Wed, 3 Apr 2024 21:13:30 +0800 Subject: [PATCH] Optimize the performance of CHA algorithm --- .../analysis/graph/callgraph/CHABuilder.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/pascal/taie/analysis/graph/callgraph/CHABuilder.java b/src/main/java/pascal/taie/analysis/graph/callgraph/CHABuilder.java index cfcbca77a..6c021b644 100644 --- a/src/main/java/pascal/taie/analysis/graph/callgraph/CHABuilder.java +++ b/src/main/java/pascal/taie/analysis/graph/callgraph/CHABuilder.java @@ -70,17 +70,18 @@ private CallGraph buildCallGraph(JMethod entry) { workList.add(entry); while (!workList.isEmpty()) { JMethod method = workList.poll(); - callGraph.addReachableMethod(method); - callGraph.callSitesIn(method).forEach(invoke -> { - Set callees = resolveCalleesOf(invoke); - callees.forEach(callee -> { - if (!callGraph.contains(callee)) { - workList.add(callee); - } - callGraph.addEdge(new Edge<>( - CallGraphs.getCallKind(invoke), invoke, callee)); + if (callGraph.addReachableMethod(method)) { + callGraph.callSitesIn(method).forEach(invoke -> { + Set callees = resolveCalleesOf(invoke); + callees.forEach(callee -> { + if (!callGraph.contains(callee)) { + workList.add(callee); + } + callGraph.addEdge(new Edge<>( + CallGraphs.getCallKind(invoke), invoke, callee)); + }); }); - }); + } } return callGraph; }