Skip to content

Commit

Permalink
[GR-43927] Expose call tree roots from CallTreePrinter
Browse files Browse the repository at this point in the history
PullRequest: graal/18674
  • Loading branch information
rudsberg committed Sep 8, 2024
2 parents 07d876a + effcb4c commit a9fa562
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,29 @@ public AnalysisMethod getMethod(ResolvedJavaMethod resolvedJavaMethod) {
return methods.get(resolvedJavaMethod);
}

/**
* Returns the root {@link AnalysisMethod}s. Accessing the roots is useful when traversing the
* call graph.
*
* @param universe the universe from which the roots are derived from.
* @return the call tree roots.
*/
public static List<AnalysisMethod> getCallTreeRoots(AnalysisUniverse universe) {
List<AnalysisMethod> roots = new ArrayList<>();
for (AnalysisMethod m : universe.getMethods()) {
if (m.isDirectRootMethod() && m.isSimplyImplementationInvoked()) {
roots.add(m);
}
if (m.isVirtualRootMethod()) {
for (AnalysisMethod impl : m.collectMethodImplementations(false)) {
AnalysisError.guarantee(impl.isImplementationInvoked());
roots.add(impl);
}
}
}
return roots;
}

public Map<Constant, Object> getEmbeddedRoots() {
return embeddedRoots;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.meta.AnalysisMethod;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
import com.oracle.graal.pointsto.meta.InvokeInfo;
import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod;
import com.oracle.graal.pointsto.util.AnalysisError;
Expand Down Expand Up @@ -182,18 +183,7 @@ public CallTreePrinter(BigBang bb) {

public void buildCallTree() {
/* Add all the roots to the tree. */
List<AnalysisMethod> roots = new ArrayList<>();
for (AnalysisMethod m : bb.getUniverse().getMethods()) {
if (m.isDirectRootMethod() && m.isSimplyImplementationInvoked()) {
roots.add(m);
}
if (m.isVirtualRootMethod()) {
for (AnalysisMethod impl : m.collectMethodImplementations(false)) {
AnalysisError.guarantee(impl.isImplementationInvoked());
roots.add(impl);
}
}
}
List<AnalysisMethod> roots = AnalysisUniverse.getCallTreeRoots(bb.getUniverse());

roots.sort(methodComparator);
for (AnalysisMethod m : roots) {
Expand Down

0 comments on commit a9fa562

Please sign in to comment.