Skip to content

Extend PrintAnalysisCallTree option #3227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ziyilin
Copy link
Collaborator

@ziyilin ziyilin commented Feb 19, 2021

Current -H:+PrintAnalysisCallTree option prints call trees for all entries. However, the resulting file is too large to look for the method that user is interested in.

This PR extends the option to -H:PrintAnalysisCallTree=<comma-separated method list>. Only the specified entry methods' call tree will be printed out. And -H:PrintAnalysisCallTree= prints call tree for all entry methods, just like previous -H:+PrintAnalysisCallTree does.

The method name is the qualified name including parameter types, such as sun.nio.fs.UnixNativeDispatcher.<clinit>().

@zakkak
Copy link
Collaborator

zakkak commented Apr 14, 2021

Hi @mcraj017, could you please assign this to someone for a review?

@munishchouhan
Copy link
Contributor

@zakkak thanks for the PR, I have assigned reviwers for this

@zakkak
Copy link
Collaborator

zakkak commented Apr 15, 2021

@zakkak thanks for the PR, I have assigned reviwers for this

Well, the thanks for the PR go to @ziyilin. I didn't put any effort in this, I would just like to see it merged :)
Thanks for pushing it forward.

@ziyilin ziyilin force-pushed the extendPrintCallTree branch from d03afb1 to 4f44eed Compare April 15, 2021 12:44
@zakkak
Copy link
Collaborator

zakkak commented May 13, 2021

@christianwimmer @vjovanov are there any updates on this?

@christianwimmer christianwimmer requested review from cstancu and removed request for vjovanov and christianwimmer June 22, 2021 05:41
@cstancu cstancu self-assigned this Jun 22, 2021
Copy link
Member

@cstancu cstancu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the new option format in /docs/reference-manual/native-image/Reports.md. Is this supposed to work only for entry points, or any method can be selected?

boolean isNative = invoke.targetMethod.wrapped.getClass().getName().equals("com.oracle.svm.jni.hosted.JNINativeCallWrapperMethod");
if (print) {
if (calleeNode instanceof MethodNodeReference && printedID.add(((MethodNodeReference) calleeNode).methodNode.id)) {
calleeNode = ((MethodNodeReference) calleeNode).methodNode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why expand the method reference only for the direct invokes but not for the virtual invokes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

if (calleeNode instanceof MethodNode) {
printCallTreeNode(out, prefix + (lastInvoke ? EMPTY_INDENT : CONNECTING_INDENT) + (lastCallee ? EMPTY_INDENT : CONNECTING_INDENT), (MethodNode) calleeNode);
printCallTreeNode(out, prefix + (lastInvoke ? EMPTY_INDENT : CONNECTING_INDENT) + (lastCallee ? EMPTY_INDENT : CONNECTING_INDENT), (MethodNode) calleeNode, print, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing null for the beginning parameter seems wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example testing this naively with mx helloworld -H:PrintAnalysisCallTree='java.lang.String.hashCode(),java.lang.String.toString() results in:

VM Entry Points
nullentry java.lang.String.hashCode():int id=1277 
nullentry java.lang.String.toString():java.lang.String id=1351 

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@ziyilin ziyilin force-pushed the extendPrintCallTree branch 2 times, most recently from d986983 to c73cd5a Compare July 13, 2021 04:23
@ziyilin
Copy link
Collaborator Author

ziyilin commented Jul 13, 2021

Please document the new option format in /docs/reference-manual/native-image/Reports.md. Is this supposed to work only for entry points, or any method can be selected?

Updated the reference file. It should report for any method selected.@cstancu please have a review. Thanks.

@zakkak
Copy link
Collaborator

zakkak commented Sep 21, 2021

Hi @ziyilin, it looks like now that #3128 got merged there are some conflicts in this PR, could you please have a look?

@ziyilin ziyilin force-pushed the extendPrintCallTree branch 2 times, most recently from d1f9510 to 7b21f5c Compare September 23, 2021 02:04
@ziyilin
Copy link
Collaborator Author

ziyilin commented Sep 23, 2021

Hi @ziyilin, it looks like now that #3128 got merged there are some conflicts in this PR, could you please have a look?

@zakkak I've fixed the conflicts

@galderz
Copy link
Contributor

galderz commented Oct 1, 2021

Please consider my comment #3843 (comment) before integrating this. I'd rather PrintAnalysisCallTree be set to either text or csv, and then have a complementary option for the filter itself.

@@ -17,7 +17,10 @@ the image heap, respectively.
The call tree is a a breadth-first tree reduction of the call graph as seen by the points-to analysis.
The points-to analysis eliminates calls to methods that it determines cannot be reachable at runtime, based on the analysed receiver types.
It also completely eliminates invocations in unreachable code blocks, e.g., blocks guarded by a type check that always fails.
The call tree report is enabled using the `-H:+PrintAnalysisCallTree` option.
The call tree report is enabled using the `-H:PrintAnalysisCallTree=<comma-separated method list>` option.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ziyilin , as discussed in #3843 (comment) this option would better be left as is and a new option -H:PrintAnalysisCallTreeFilter=<comma-separated method list> should be introduced instead. To avoid the need of passing both PrintAnalysisCallTreeFilter and PrintAnalysisCallTree, the former can implicitly set the latter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have modified as suggested.

@ziyilin ziyilin force-pushed the extendPrintCallTree branch from 7b21f5c to f8f93ae Compare October 8, 2021 05:01
Copy link
Collaborator

@zakkak zakkak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update @ziyilin .

I have added a couple of suggestion could you please have a look?

There seems to be a styling issue as well https://github.com/oracle/graal/pull/3227/checks?check_run_id=3834984765#step:9:1000

@@ -17,7 +17,11 @@ the image heap, respectively.
The call tree is a a breadth-first tree reduction of the call graph as seen by the points-to analysis.
The points-to analysis eliminates calls to methods that it determines cannot be reachable at runtime, based on the analysed receiver types.
It also completely eliminates invocations in unreachable code blocks, e.g., blocks guarded by a type check that always fails.
The call tree report is enabled using the `-H:+PrintAnalysisCallTree` option.
The call tree report is enabled using the `-H:PrintAnalysisCallTree` option.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The call tree report is enabled using the `-H:PrintAnalysisCallTree` option.
The call tree report is enabled using the `-H:+PrintAnalysisCallTree` option.

The call tree report is enabled using the `-H:+PrintAnalysisCallTree` option.
The call tree report is enabled using the `-H:PrintAnalysisCallTree` option.
Option `-H:PrintAnalysisCallTreeFilter=<comma-separated method list>` can be used to only print out the specified methods'
call tree, and it implicitly enables the `-H:PrintAnalysisCallTree`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
call tree, and it implicitly enables the `-H:PrintAnalysisCallTree`.
call tree, and it implicitly sets `-H:+PrintAnalysisCallTree`.

@@ -45,8 +45,12 @@ public static void printAnalysisReports(String imageName, OptionValues options,
StatisticsPrinter.print(bb, reportsPath, ReportUtils.extractImageName(imageName));
}

if (AnalysisReportsOptions.PrintAnalysisCallTree.getValue(options)) {
CallTreePrinter.print(bb, reportsPath, ReportUtils.extractImageName(imageName));
if (AnalysisReportsOptions.PrintAnalysisCallTree.hasBeenSet(options)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (AnalysisReportsOptions.PrintAnalysisCallTree.hasBeenSet(options)) {
if (AnalysisReportsOptions.PrintAnalysisCallTree.getValue(options)) {

This condition should check whether PrintAnalysisCallTree is true, right? Not if it's just been set (possibly to false).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, I didn't change it when PrintAnalysisCallTree is changed from String to Boolean.

-H:PrintAnalysisCallTreeFilter= option accept a list of methods to print
the call tree of them, the default value is  an empty string to print all call trees.
@ziyilin ziyilin force-pushed the extendPrintCallTree branch from f8f93ae to c64d8e6 Compare October 8, 2021 11:55
@zakkak
Copy link
Collaborator

zakkak commented Dec 3, 2021

Hello @cstancu, are there any updates on this?

@cstancu
Copy link
Member

cstancu commented Jun 7, 2024

This PR fell between cracks. If it's still relevant for you I have a few suggestions:

  • instead of using a custom filter format I would use the same method filter format as jdk.graal.MethodFilter, we used that recently also for AbortOnMethodReachable for example.
  • instead of using having -H:PrintAnalysisCallTreeFilter= set -H:+PrintAnalysisCallTree I would just make AnalysisCallTreeMethodFilter as a separate option, that's by default empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants