Skip to content

Commit

Permalink
8251464: make Node::dump(int depth) support indent
Browse files Browse the repository at this point in the history
Reviewed-by: thartmann
  • Loading branch information
Xin Liu authored and Paul Hohensee committed Oct 2, 2020
1 parent fff8c8d commit ea5a2b1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/hotspot/share/opto/c2_globals.hpp
Expand Up @@ -105,6 +105,10 @@
notproduct(bool, PrintIdeal, false, \
"Print ideal graph before code generation") \
\
notproduct(uintx, PrintIdealIndentThreshold, 0, \
"A depth threshold of ideal graph. Indentation is disabled " \
"when users attempt to dump an ideal graph deeper than it.") \
\
notproduct(bool, PrintOpto, false, \
"Print compiler2 attempts") \
\
Expand Down
50 changes: 33 additions & 17 deletions src/hotspot/share/opto/node.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -329,6 +329,7 @@ Node::Node(uint req)
: _idx(Init(req))
#ifdef ASSERT
, _parse_idx(_idx)
, _indent(0)
#endif
{
assert( req < Compile::current()->max_node_limit() - NodeLimitFudgeFactor, "Input limit exceeded" );
Expand All @@ -349,6 +350,7 @@ Node::Node(Node *n0)
: _idx(Init(1))
#ifdef ASSERT
, _parse_idx(_idx)
, _indent(0)
#endif
{
debug_only( verify_construction() );
Expand All @@ -362,6 +364,7 @@ Node::Node(Node *n0, Node *n1)
: _idx(Init(2))
#ifdef ASSERT
, _parse_idx(_idx)
, _indent(0)
#endif
{
debug_only( verify_construction() );
Expand All @@ -377,6 +380,7 @@ Node::Node(Node *n0, Node *n1, Node *n2)
: _idx(Init(3))
#ifdef ASSERT
, _parse_idx(_idx)
, _indent(0)
#endif
{
debug_only( verify_construction() );
Expand All @@ -394,6 +398,7 @@ Node::Node(Node *n0, Node *n1, Node *n2, Node *n3)
: _idx(Init(4))
#ifdef ASSERT
, _parse_idx(_idx)
, _indent(0)
#endif
{
debug_only( verify_construction() );
Expand All @@ -413,6 +418,7 @@ Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, Node *n4)
: _idx(Init(5))
#ifdef ASSERT
, _parse_idx(_idx)
, _indent(0)
#endif
{
debug_only( verify_construction() );
Expand All @@ -435,6 +441,7 @@ Node::Node(Node *n0, Node *n1, Node *n2, Node *n3,
: _idx(Init(6))
#ifdef ASSERT
, _parse_idx(_idx)
, _indent(0)
#endif
{
debug_only( verify_construction() );
Expand All @@ -459,6 +466,7 @@ Node::Node(Node *n0, Node *n1, Node *n2, Node *n3,
: _idx(Init(7))
#ifdef ASSERT
, _parse_idx(_idx)
, _indent(0)
#endif
{
debug_only( verify_construction() );
Expand Down Expand Up @@ -1718,7 +1726,12 @@ void Node::dump(const char* suffix, bool mark, outputStream *st) const {
Compile* C = Compile::current();
bool is_new = C->node_arena()->contains(this);
C->_in_dump_cnt++;
st->print("%c%d%s\t%s\t=== ", is_new ? ' ' : 'o', _idx, mark ? " >" : "", Name());

if (_indent > 0) {
st->print("%*s", (_indent << 1), " ");
}

st->print("%c%d%s%s === ", is_new ? ' ' : 'o', _idx, mark ? " >" : " ", Name());

// Dump the required and precedence inputs
dump_req(st);
Expand Down Expand Up @@ -1843,23 +1856,26 @@ void Node::dump_out(outputStream *st) const {
// moving in a given direction until a certain depth (distance from the start
// node) is reached. Duplicates are ignored.
// Arguments:
// nstack: the nodes are collected into this array.
// queue: the nodes are collected into this array.
// start: the node at which to start collecting.
// direction: if this is a positive number, collect input nodes; if it is
// a negative number, collect output nodes.
// depth: collect nodes up to this distance from the start node.
// include_start: whether to include the start node in the result collection.
// only_ctrl: whether to regard control edges only during traversal.
// only_data: whether to regard data edges only during traversal.
static void collect_nodes_i(GrowableArray<Node*> *nstack, const Node* start, int direction, uint depth, bool include_start, bool only_ctrl, bool only_data) {
static void collect_nodes_i(GrowableArray<Node*>* queue, const Node* start, int direction, uint depth, bool include_start, bool only_ctrl, bool only_data) {
bool indent = depth <= PrintIdealIndentThreshold;
Node* s = (Node*) start; // remove const
nstack->append(s);
queue->append(s);
int begin = 0;
int end = 0;

s->set_indent(0);
for(uint i = 0; i < depth; i++) {
end = nstack->length();
end = queue->length();
for(int j = begin; j < end; j++) {
Node* tp = nstack->at(j);
Node* tp = queue->at(j);
uint limit = direction > 0 ? tp->len() : tp->outcnt();
for(uint k = 0; k < limit; k++) {
Node* n = direction > 0 ? tp->in(k) : tp->raw_out(k);
Expand All @@ -1869,35 +1885,35 @@ static void collect_nodes_i(GrowableArray<Node*> *nstack, const Node* start, int
if (n->is_Root() || n->is_top()) continue;
if (only_ctrl && !n->is_CFG()) continue;
if (only_data && n->is_CFG()) continue;

bool on_stack = nstack->contains(n);
if (!on_stack) {
nstack->append(n);
bool in_queue = queue->contains(n);
if (!in_queue) {
queue->append(n);
n->set_indent(indent ? (i + 1) : 0);
}
}
}
begin = end;
}
if (!include_start) {
nstack->remove(s);
queue->remove(s);
}
}

//------------------------------dump_nodes-------------------------------------
static void dump_nodes(const Node* start, int d, bool only_ctrl) {
if (NotANode(start)) return;

GrowableArray <Node *> nstack(Compile::current()->live_nodes());
collect_nodes_i(&nstack, start, d, (uint) ABS(d), true, only_ctrl, false);
GrowableArray <Node *> queue(Compile::current()->live_nodes());
collect_nodes_i(&queue, start, d, (uint) ABS(d), true, only_ctrl, false);

int end = nstack.length();
int end = queue.length();
if (d > 0) {
for(int j = end-1; j >= 0; j--) {
nstack.at(j)->dump();
queue.at(j)->dump();
}
} else {
for(int j = 0; j < end; j++) {
nstack.at(j)->dump();
queue.at(j)->dump();
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/share/opto/node.hpp
Expand Up @@ -1119,6 +1119,12 @@ class Node {

//----------------- Printing, etc
#ifndef PRODUCT
int _indent;

public:
void set_indent(int indent) { _indent = indent; }

private:
static bool add_to_worklist(Node* n, Node_List* worklist, Arena* old_arena, VectorSet* old_space, VectorSet* new_space);
public:
Node* find(int idx, bool only_ctrl = false); // Search the graph for the given idx.
Expand Down
4 changes: 2 additions & 2 deletions test/hotspot/jtreg/compiler/c2/cr7200264/TestDriver.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -56,7 +56,7 @@ private List<String> executeApplication() throws Throwable {

private void verifyVectorizationNumber(List<String> vectorizationLog) {
for (Map.Entry<String, Long> entry : expectedVectorizationNumbers.entrySet()) {
String v = "\t" + entry.getKey();
String v = entry.getKey();
long actualNum = vectorizationLog.stream()
.filter(s -> s.contains(v)).count();
long expectedNum = entry.getValue();
Expand Down
Expand Up @@ -73,12 +73,12 @@ private static void check(boolean enabled) {
List<Node> safePoints = new ArrayList<>();
List<Node> loopEnds = new ArrayList<>();
for (String line : oa.getOutput().split("\\n")) {
int separatorIndex = line.indexOf("\t===");
int separatorIndex = line.indexOf(" ===");
if (separatorIndex > -1) {
String header = line.substring(0, separatorIndex);
if (header.endsWith("\tSafePoint")) {
if (header.endsWith("SafePoint")) {
safePoints.add(new Node("SafePoint", line));
} else if (header.endsWith("\tCountedLoopEnd")) {
} else if (header.endsWith("CountedLoopEnd")) {
loopEnds.add(new Node("CountedLoopEnd", line));
}
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public Node(String name, String str) {
List<Integer> tmpFrom = new ArrayList<>();
List<Integer> tmpTo = new ArrayList<>();
// parse string like: " $id $name === $to1 $to2 ... [[ $from1 $from2 ... ]] $anything"
// example: 318 SafePoint === 317 1 304 1 1 10 308 [[ 97 74 ]] ...
// example: 318 SafePoint === 317 1 304 1 1 10 308 [[ 97 74 ]] ...
id = Integer.parseInt(str.substring(1, str.indexOf(name)).trim());
Arrays.stream(str.substring(str.indexOf("===") + 4, str.indexOf("[[")).trim().split("\\s+"))
.map(Integer::parseInt)
Expand Down

1 comment on commit ea5a2b1

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on ea5a2b1 Oct 2, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.