RFR: 8281548: Add escape analysis tracing flag [v4]

Xin Liu xliu at openjdk.java.net
Wed Feb 16 01:58:08 UTC 2022


On Tue, 15 Feb 2022 21:18:16 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> src/hotspot/share/opto/escape.cpp line 882:
>> 
>>> 880:     PointsToNode* ptn = ptnode_adr(val->_idx);
>>> 881:     assert(ptn != NULL, "node should be registered");
>>> 882:     set_escape_state(ptn, PointsToNode::GlobalEscape NOT_PRODUCT(COMMA "stored at raw address"));
>> 
>> In a nutshell, this PR annotates a node why it escapes or is NSR.  I believe the code would be much cleaner if you just add a field of "reason" to `PointsToNode`.  One field is enough because scalar replacement candidates is subset of NoEscape Java nodes.  There's no overlap between escape reason and NSR reason.  extra bonus is that we can access the reason field in debugger later on.
>
> I can get the debugger argument, but I'm not sure I see how doing this would make the code cleaner...
> 
> Instead of printing out the reason message directly in set_(fields_)escape_state/set_not_scalar_replaceable we would set it in `PointsToNode.reason`, and then afterwards walk the graph to print out all messages?
> 
> One potential problem with that approach is that if a node is first updated to ArgEscape, and then later to GlobalEscape, the first state transition would not be visible. (i.e. the PR is not just annotating nodes, it's annotating state transitions, and there can be multiple state transitions per node)

C/C++ macro is very powerful. however, it may scramble code.  If we refrain abusing, I think C++ can achieve cleaner code like Java. 

> Instead of printing out the reason message directly in set_(fields_)escape_state/set_not_scalar_replaceable we would set it in PointsToNode.reason, and then afterwards walk the graph to print out all messages?

I mean we can do thing like this: 
```ptn->reason = "stored at raw address";```

and then 

void ConnectionGraph::trace_es_update_helper(PointsToNode* ptn, PointsToNode::EscapeState es, bool fields) const {
  if (_compile->directive()->TraceEscapeAnalysisOption) {
    assert(ptn != nullptr, "should not be null");
    assert(ptn->reason != nullptr, "should not be null");
    ptn->dump_header(true);
    PointsToNode::EscapeState new_es = fields ? ptn->escape_state() : es;
    PointsToNode::EscapeState new_fields_es = fields ? es : ptn->fields_escape_state();
    tty->print_cr("-> %s(%s) %s", esc_names[(int)new_es], esc_names[(int)new_fields_es], ptn->reason);
  }
}


PointsToNode::reason is just a global variable. it can prevent you from passing the argument under macro expansion. 
if inliner and scalar replacement of gcc is at work, this field can be removed. Since we only use PointsToNode::reason in debug build, it doesn't matter if gcc misses that.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7428


More information about the hotspot-compiler-dev mailing list