Skip to content

Commit a9fa562

Browse files
committed
[GR-43927] Expose call tree roots from CallTreePrinter
PullRequest: graal/18674
2 parents 07d876a + effcb4c commit a9fa562

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisUniverse.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,29 @@ public AnalysisMethod getMethod(ResolvedJavaMethod resolvedJavaMethod) {
563563
return methods.get(resolvedJavaMethod);
564564
}
565565

566+
/**
567+
* Returns the root {@link AnalysisMethod}s. Accessing the roots is useful when traversing the
568+
* call graph.
569+
*
570+
* @param universe the universe from which the roots are derived from.
571+
* @return the call tree roots.
572+
*/
573+
public static List<AnalysisMethod> getCallTreeRoots(AnalysisUniverse universe) {
574+
List<AnalysisMethod> roots = new ArrayList<>();
575+
for (AnalysisMethod m : universe.getMethods()) {
576+
if (m.isDirectRootMethod() && m.isSimplyImplementationInvoked()) {
577+
roots.add(m);
578+
}
579+
if (m.isVirtualRootMethod()) {
580+
for (AnalysisMethod impl : m.collectMethodImplementations(false)) {
581+
AnalysisError.guarantee(impl.isImplementationInvoked());
582+
roots.add(impl);
583+
}
584+
}
585+
}
586+
return roots;
587+
}
588+
566589
public Map<Constant, Object> getEmbeddedRoots() {
567590
return embeddedRoots;
568591
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/CallTreePrinter.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.oracle.graal.pointsto.BigBang;
5858
import com.oracle.graal.pointsto.meta.AnalysisMethod;
5959
import com.oracle.graal.pointsto.meta.AnalysisType;
60+
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
6061
import com.oracle.graal.pointsto.meta.InvokeInfo;
6162
import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod;
6263
import com.oracle.graal.pointsto.util.AnalysisError;
@@ -182,18 +183,7 @@ public CallTreePrinter(BigBang bb) {
182183

183184
public void buildCallTree() {
184185
/* Add all the roots to the tree. */
185-
List<AnalysisMethod> roots = new ArrayList<>();
186-
for (AnalysisMethod m : bb.getUniverse().getMethods()) {
187-
if (m.isDirectRootMethod() && m.isSimplyImplementationInvoked()) {
188-
roots.add(m);
189-
}
190-
if (m.isVirtualRootMethod()) {
191-
for (AnalysisMethod impl : m.collectMethodImplementations(false)) {
192-
AnalysisError.guarantee(impl.isImplementationInvoked());
193-
roots.add(impl);
194-
}
195-
}
196-
}
186+
List<AnalysisMethod> roots = AnalysisUniverse.getCallTreeRoots(bb.getUniverse());
197187

198188
roots.sort(methodComparator);
199189
for (AnalysisMethod m : roots) {

0 commit comments

Comments
 (0)