Skip to content

Commit ea5a2b1

Browse files
Xin LiuPaul Hohensee
Xin Liu
authored and
Paul Hohensee
committedOct 2, 2020
8251464: make Node::dump(int depth) support indent
Reviewed-by: thartmann
1 parent fff8c8d commit ea5a2b1

File tree

5 files changed

+49
-23
lines changed

5 files changed

+49
-23
lines changed
 

‎src/hotspot/share/opto/c2_globals.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@
105105
notproduct(bool, PrintIdeal, false, \
106106
"Print ideal graph before code generation") \
107107
\
108+
notproduct(uintx, PrintIdealIndentThreshold, 0, \
109+
"A depth threshold of ideal graph. Indentation is disabled " \
110+
"when users attempt to dump an ideal graph deeper than it.") \
111+
\
108112
notproduct(bool, PrintOpto, false, \
109113
"Print compiler2 attempts") \
110114
\

‎src/hotspot/share/opto/node.cpp

+33-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -329,6 +329,7 @@ Node::Node(uint req)
329329
: _idx(Init(req))
330330
#ifdef ASSERT
331331
, _parse_idx(_idx)
332+
, _indent(0)
332333
#endif
333334
{
334335
assert( req < Compile::current()->max_node_limit() - NodeLimitFudgeFactor, "Input limit exceeded" );
@@ -349,6 +350,7 @@ Node::Node(Node *n0)
349350
: _idx(Init(1))
350351
#ifdef ASSERT
351352
, _parse_idx(_idx)
353+
, _indent(0)
352354
#endif
353355
{
354356
debug_only( verify_construction() );
@@ -362,6 +364,7 @@ Node::Node(Node *n0, Node *n1)
362364
: _idx(Init(2))
363365
#ifdef ASSERT
364366
, _parse_idx(_idx)
367+
, _indent(0)
365368
#endif
366369
{
367370
debug_only( verify_construction() );
@@ -377,6 +380,7 @@ Node::Node(Node *n0, Node *n1, Node *n2)
377380
: _idx(Init(3))
378381
#ifdef ASSERT
379382
, _parse_idx(_idx)
383+
, _indent(0)
380384
#endif
381385
{
382386
debug_only( verify_construction() );
@@ -394,6 +398,7 @@ Node::Node(Node *n0, Node *n1, Node *n2, Node *n3)
394398
: _idx(Init(4))
395399
#ifdef ASSERT
396400
, _parse_idx(_idx)
401+
, _indent(0)
397402
#endif
398403
{
399404
debug_only( verify_construction() );
@@ -413,6 +418,7 @@ Node::Node(Node *n0, Node *n1, Node *n2, Node *n3, Node *n4)
413418
: _idx(Init(5))
414419
#ifdef ASSERT
415420
, _parse_idx(_idx)
421+
, _indent(0)
416422
#endif
417423
{
418424
debug_only( verify_construction() );
@@ -435,6 +441,7 @@ Node::Node(Node *n0, Node *n1, Node *n2, Node *n3,
435441
: _idx(Init(6))
436442
#ifdef ASSERT
437443
, _parse_idx(_idx)
444+
, _indent(0)
438445
#endif
439446
{
440447
debug_only( verify_construction() );
@@ -459,6 +466,7 @@ Node::Node(Node *n0, Node *n1, Node *n2, Node *n3,
459466
: _idx(Init(7))
460467
#ifdef ASSERT
461468
, _parse_idx(_idx)
469+
, _indent(0)
462470
#endif
463471
{
464472
debug_only( verify_construction() );
@@ -1718,7 +1726,12 @@ void Node::dump(const char* suffix, bool mark, outputStream *st) const {
17181726
Compile* C = Compile::current();
17191727
bool is_new = C->node_arena()->contains(this);
17201728
C->_in_dump_cnt++;
1721-
st->print("%c%d%s\t%s\t=== ", is_new ? ' ' : 'o', _idx, mark ? " >" : "", Name());
1729+
1730+
if (_indent > 0) {
1731+
st->print("%*s", (_indent << 1), " ");
1732+
}
1733+
1734+
st->print("%c%d%s%s === ", is_new ? ' ' : 'o', _idx, mark ? " >" : " ", Name());
17221735

17231736
// Dump the required and precedence inputs
17241737
dump_req(st);
@@ -1843,23 +1856,26 @@ void Node::dump_out(outputStream *st) const {
18431856
// moving in a given direction until a certain depth (distance from the start
18441857
// node) is reached. Duplicates are ignored.
18451858
// Arguments:
1846-
// nstack: the nodes are collected into this array.
1859+
// queue: the nodes are collected into this array.
18471860
// start: the node at which to start collecting.
18481861
// direction: if this is a positive number, collect input nodes; if it is
18491862
// a negative number, collect output nodes.
18501863
// depth: collect nodes up to this distance from the start node.
18511864
// include_start: whether to include the start node in the result collection.
18521865
// only_ctrl: whether to regard control edges only during traversal.
18531866
// only_data: whether to regard data edges only during traversal.
1854-
static void collect_nodes_i(GrowableArray<Node*> *nstack, const Node* start, int direction, uint depth, bool include_start, bool only_ctrl, bool only_data) {
1867+
static void collect_nodes_i(GrowableArray<Node*>* queue, const Node* start, int direction, uint depth, bool include_start, bool only_ctrl, bool only_data) {
1868+
bool indent = depth <= PrintIdealIndentThreshold;
18551869
Node* s = (Node*) start; // remove const
1856-
nstack->append(s);
1870+
queue->append(s);
18571871
int begin = 0;
18581872
int end = 0;
1873+
1874+
s->set_indent(0);
18591875
for(uint i = 0; i < depth; i++) {
1860-
end = nstack->length();
1876+
end = queue->length();
18611877
for(int j = begin; j < end; j++) {
1862-
Node* tp = nstack->at(j);
1878+
Node* tp = queue->at(j);
18631879
uint limit = direction > 0 ? tp->len() : tp->outcnt();
18641880
for(uint k = 0; k < limit; k++) {
18651881
Node* n = direction > 0 ? tp->in(k) : tp->raw_out(k);
@@ -1869,35 +1885,35 @@ static void collect_nodes_i(GrowableArray<Node*> *nstack, const Node* start, int
18691885
if (n->is_Root() || n->is_top()) continue;
18701886
if (only_ctrl && !n->is_CFG()) continue;
18711887
if (only_data && n->is_CFG()) continue;
1872-
1873-
bool on_stack = nstack->contains(n);
1874-
if (!on_stack) {
1875-
nstack->append(n);
1888+
bool in_queue = queue->contains(n);
1889+
if (!in_queue) {
1890+
queue->append(n);
1891+
n->set_indent(indent ? (i + 1) : 0);
18761892
}
18771893
}
18781894
}
18791895
begin = end;
18801896
}
18811897
if (!include_start) {
1882-
nstack->remove(s);
1898+
queue->remove(s);
18831899
}
18841900
}
18851901

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

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

1893-
int end = nstack.length();
1909+
int end = queue.length();
18941910
if (d > 0) {
18951911
for(int j = end-1; j >= 0; j--) {
1896-
nstack.at(j)->dump();
1912+
queue.at(j)->dump();
18971913
}
18981914
} else {
18991915
for(int j = 0; j < end; j++) {
1900-
nstack.at(j)->dump();
1916+
queue.at(j)->dump();
19011917
}
19021918
}
19031919
}

‎src/hotspot/share/opto/node.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,12 @@ class Node {
11191119

11201120
//----------------- Printing, etc
11211121
#ifndef PRODUCT
1122+
int _indent;
1123+
1124+
public:
1125+
void set_indent(int indent) { _indent = indent; }
1126+
1127+
private:
11221128
static bool add_to_worklist(Node* n, Node_List* worklist, Arena* old_arena, VectorSet* old_space, VectorSet* new_space);
11231129
public:
11241130
Node* find(int idx, bool only_ctrl = false); // Search the graph for the given idx.

‎test/hotspot/jtreg/compiler/c2/cr7200264/TestDriver.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -56,7 +56,7 @@ private List<String> executeApplication() throws Throwable {
5656

5757
private void verifyVectorizationNumber(List<String> vectorizationLog) {
5858
for (Map.Entry<String, Long> entry : expectedVectorizationNumbers.entrySet()) {
59-
String v = "\t" + entry.getKey();
59+
String v = entry.getKey();
6060
long actualNum = vectorizationLog.stream()
6161
.filter(s -> s.contains(v)).count();
6262
long expectedNum = entry.getValue();

‎test/hotspot/jtreg/compiler/loopopts/UseCountedLoopSafepointsTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ private static void check(boolean enabled) {
7373
List<Node> safePoints = new ArrayList<>();
7474
List<Node> loopEnds = new ArrayList<>();
7575
for (String line : oa.getOutput().split("\\n")) {
76-
int separatorIndex = line.indexOf("\t===");
76+
int separatorIndex = line.indexOf(" ===");
7777
if (separatorIndex > -1) {
7878
String header = line.substring(0, separatorIndex);
79-
if (header.endsWith("\tSafePoint")) {
79+
if (header.endsWith("SafePoint")) {
8080
safePoints.add(new Node("SafePoint", line));
81-
} else if (header.endsWith("\tCountedLoopEnd")) {
81+
} else if (header.endsWith("CountedLoopEnd")) {
8282
loopEnds.add(new Node("CountedLoopEnd", line));
8383
}
8484
}
@@ -110,7 +110,7 @@ public Node(String name, String str) {
110110
List<Integer> tmpFrom = new ArrayList<>();
111111
List<Integer> tmpTo = new ArrayList<>();
112112
// parse string like: " $id $name === $to1 $to2 ... [[ $from1 $from2 ... ]] $anything"
113-
// example: 318 SafePoint === 317 1 304 1 1 10 308 [[ 97 74 ]] ...
113+
// example: 318 SafePoint === 317 1 304 1 1 10 308 [[ 97 74 ]] ...
114114
id = Integer.parseInt(str.substring(1, str.indexOf(name)).trim());
115115
Arrays.stream(str.substring(str.indexOf("===") + 4, str.indexOf("[[")).trim().split("\\s+"))
116116
.map(Integer::parseInt)

0 commit comments

Comments
 (0)
Please sign in to comment.