Skip to content

Commit b3a319c

Browse files
committed
8264842: IGV: different nodes sharing idx are treated as equal
Introduce IGV-specific node identifier and encapsulate it in IGV by showing a configurable 'short node text' string instead. Reviewed-by: iveresov, kvn
1 parent 95f0fd6 commit b3a319c

File tree

19 files changed

+182
-107
lines changed

19 files changed

+182
-107
lines changed

src/hotspot/share/opto/compile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ Compile::Compile( ciEnv* ci_env, ciMethod* target, int osr_bci,
553553
_do_cleanup(false),
554554
_has_reserved_stack_access(target->has_reserved_stack_access()),
555555
#ifndef PRODUCT
556+
_igv_idx(0),
556557
_trace_opto_output(directive->TraceOptoOutputOption),
557558
_print_ideal(directive->PrintIdealOption),
558559
#endif
@@ -859,6 +860,7 @@ Compile::Compile( ciEnv* ci_env,
859860
_inlining_incrementally(false),
860861
_has_reserved_stack_access(false),
861862
#ifndef PRODUCT
863+
_igv_idx(0),
862864
_trace_opto_output(directive->TraceOptoOutputOption),
863865
_print_ideal(directive->PrintIdealOption),
864866
#endif

src/hotspot/share/opto/compile.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ class Compile : public Phase {
293293
bool _print_inlining; // True if we should print inlining for this compilation
294294
bool _print_intrinsics; // True if we should print intrinsics for this compilation
295295
#ifndef PRODUCT
296+
uint _igv_idx; // Counter for IGV node identifiers
296297
bool _trace_opto_output;
297298
bool _print_ideal;
298299
bool _parsed_irreducible_loop; // True if ciTypeFlow detected irreducible loops during parsing
@@ -601,6 +602,7 @@ class Compile : public Phase {
601602
}
602603

603604
#ifndef PRODUCT
605+
uint next_igv_idx() { return _igv_idx++; }
604606
bool trace_opto_output() const { return _trace_opto_output; }
605607
bool print_ideal() const { return _print_ideal; }
606608
bool parsed_irreducible_loop() const { return _parsed_irreducible_loop; }

src/hotspot/share/opto/idealGraphPrinter.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,12 @@ void IdealGraphPrinter::visit_node(Node *n, bool edges, VectorSet* temp_set) {
340340

341341
if (edges) {
342342

343-
// Output edge
344-
node_idx_t dest_id = n->_idx;
345-
for ( uint i = 0; i < n->len(); i++ ) {
346-
if ( n->in(i) ) {
343+
for (uint i = 0; i < n->len(); i++) {
344+
if (n->in(i)) {
347345
Node *source = n->in(i);
348346
begin_elem(EDGE_ELEMENT);
349-
print_attr(FROM_PROPERTY, source->_idx);
350-
print_attr(TO_PROPERTY, dest_id);
347+
print_attr(FROM_PROPERTY, source->_igv_idx);
348+
print_attr(TO_PROPERTY, n->_igv_idx);
351349
print_attr(INDEX_PROPERTY, i);
352350
end_elem();
353351
}
@@ -357,7 +355,7 @@ void IdealGraphPrinter::visit_node(Node *n, bool edges, VectorSet* temp_set) {
357355

358356
// Output node
359357
begin_head(NODE_ELEMENT);
360-
print_attr(NODE_ID_PROPERTY, n->_idx);
358+
print_attr(NODE_ID_PROPERTY, n->_igv_idx);
361359
end_head();
362360

363361
head(PROPERTIES_ELEMENT);
@@ -715,7 +713,7 @@ void IdealGraphPrinter::print(const char *name, Node *node) {
715713
head(NODES_ELEMENT);
716714
for (uint s = 0; s < block->number_of_nodes(); s++) {
717715
begin_elem(NODE_ELEMENT);
718-
print_attr(NODE_ID_PROPERTY, block->get_node(s)->_idx);
716+
print_attr(NODE_ID_PROPERTY, block->get_node(s)->_igv_idx);
719717
end_elem();
720718
}
721719
tail(NODES_ELEMENT);

src/hotspot/share/opto/node.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, 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
@@ -303,6 +303,7 @@ static void init_node_notes(Compile* C, int idx, Node_Notes* nn) {
303303
inline int Node::Init(int req) {
304304
Compile* C = Compile::current();
305305
int idx = C->next_unique();
306+
NOT_PRODUCT(_igv_idx = C->next_igv_idx());
306307

307308
// Allocate memory for the necessary number of edges.
308309
if (req > 0) {
@@ -531,6 +532,7 @@ Node *Node::clone() const {
531532
bs->register_potential_barrier_node(n);
532533

533534
n->set_idx(C->next_unique()); // Get new unique index as well
535+
NOT_PRODUCT(n->_igv_idx = C->next_igv_idx());
534536
debug_only( n->verify_construction() );
535537
NOT_PRODUCT(nodes_created++);
536538
// Do not patch over the debug_idx of a clone, because it makes it

src/hotspot/share/opto/node.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ class Node {
323323
// preserved in _parse_idx.
324324
const node_idx_t _idx;
325325
DEBUG_ONLY(const node_idx_t _parse_idx;)
326+
// IGV node identifier. It is similar to Node::_debug_idx in that it is unique
327+
// across all compilation phases, but different in that it is initialized in
328+
// each compilation, for stability.
329+
NOT_PRODUCT(node_idx_t _igv_idx;)
326330

327331
// Get the (read-only) number of input edges
328332
uint req() const { return _cnt; }

src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2021, 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
@@ -77,7 +77,6 @@ public InputNode(int id) {
7777

7878
public void setId(int id) {
7979
this.id = id;
80-
getProperties().setProperty("id", "" + id);
8180
}
8281

8382
public int getId() {

src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/Properties.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2021, 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
@@ -451,4 +451,36 @@ public void remove() {
451451
public Iterator<Property> iterator() {
452452
return new PropertiesIterator();
453453
}
454+
455+
public final String resolveString(String string) {
456+
457+
StringBuilder sb = new StringBuilder();
458+
boolean inBrackets = false;
459+
StringBuilder curIdent = new StringBuilder();
460+
461+
for (int i = 0; i < string.length(); i++) {
462+
char c = string.charAt(i);
463+
if (inBrackets) {
464+
if (c == ']') {
465+
String value = get(curIdent.toString());
466+
if (value == null) {
467+
value = "";
468+
}
469+
sb.append(value);
470+
inBrackets = false;
471+
} else {
472+
curIdent.append(c);
473+
}
474+
} else {
475+
if (c == '[') {
476+
inBrackets = true;
477+
curIdent = new StringBuilder();
478+
} else {
479+
sb.append(c);
480+
}
481+
}
482+
}
483+
484+
return sb.toString();
485+
}
454486
}

src/utils/IdealGraphVisualizer/Filter/src/main/java/com/sun/hotspot/igv/filter/SplitFilter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2021, 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
@@ -63,7 +63,7 @@ public void apply(Diagram d) {
6363
}
6464

6565

66-
String s = Figure.resolveString(propertyName, f.getProperties());
66+
String s = f.getProperties().resolveString(propertyName);
6767
if (s != null) {
6868
os.setShortName(s);
6969
}
@@ -79,7 +79,7 @@ public void apply(Diagram d) {
7979
is.setColor(f.getColor());
8080
}
8181

82-
String s = Figure.resolveString(propertyName, f.getProperties());
82+
String s = f.getProperties().resolveString(propertyName);
8383
if (s != null) {
8484
is.setShortName(s);
8585
}

src/utils/IdealGraphVisualizer/Graph/src/main/java/com/sun/hotspot/igv/graph/Connection.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ public String getToolTipText() {
128128
if (type != null) {
129129
builder.append(type).append(" ");
130130
}
131-
builder.append("from ");
132-
builder.append(getOutputSlot().getFigure().getSource().getSourceNodes().get(0).getId());
133-
builder.append(" to ");
134-
builder.append(getInputSlot().getFigure().getSource().getSourceNodes().get(0).getId());
131+
// Resolve strings lazily every time the tooltip is shown, instead of
132+
// eagerly as for node labels, for efficiency.
133+
String shortNodeText = getInputSlot().getFigure().getDiagram().getShortNodeText();
134+
builder.append(getOutputSlot().getFigure().getProperties().resolveString(shortNodeText));
135+
builder.append(" → ");
136+
builder.append(getInputSlot().getFigure().getProperties().resolveString(shortNodeText));
135137
return builder.toString();
136138
}
137139

src/utils/IdealGraphVisualizer/Graph/src/main/java/com/sun/hotspot/igv/graph/Diagram.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2021, 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
@@ -43,6 +43,7 @@ public class Diagram {
4343
private InputGraph graph;
4444
private int curId;
4545
private String nodeText;
46+
private String shortNodeText;
4647
private final Font font;
4748
private final Font slotFont;
4849
private final Font boldFont;
@@ -63,6 +64,7 @@ private Diagram() {
6364
figures = new ArrayList<>();
6465
blocks = new LinkedHashMap<>(8);
6566
this.nodeText = "";
67+
this.shortNodeText = "";
6668
this.font = new Font("Arial", Font.PLAIN, 12);
6769
this.slotFont = new Font("Arial", Font.PLAIN, 10);
6870
this.boldFont = this.font.deriveFont(Font.BOLD);
@@ -77,6 +79,10 @@ public String getNodeText() {
7779
return nodeText;
7880
}
7981

82+
public String getShortNodeText() {
83+
return shortNodeText;
84+
}
85+
8086
public void updateBlocks() {
8187
blocks.clear();
8288
for (InputBlock b : graph.getBlocks()) {
@@ -86,15 +92,15 @@ public void updateBlocks() {
8692
}
8793

8894
public Diagram getNext() {
89-
return Diagram.createDiagram(graph.getNext(), nodeText);
95+
return Diagram.createDiagram(graph.getNext(), nodeText, shortNodeText);
9096
}
9197

9298
public Collection<Block> getBlocks() {
9399
return Collections.unmodifiableCollection(blocks.values());
94100
}
95101

96102
public Diagram getPrev() {
97-
return Diagram.createDiagram(graph.getPrev(), nodeText);
103+
return Diagram.createDiagram(graph.getPrev(), nodeText, shortNodeText);
98104
}
99105

100106
public List<Figure> getFigures() {
@@ -130,14 +136,16 @@ public Map<InputNode, Set<Figure>> calcSourceToFigureRelation() {
130136
return map;
131137
}
132138

133-
public static Diagram createDiagram(InputGraph graph, String nodeText) {
139+
public static Diagram createDiagram(InputGraph graph, String nodeText,
140+
String shortNodeText) {
134141
if (graph == null) {
135142
return null;
136143
}
137144

138145
Diagram d = new Diagram();
139146
d.graph = graph;
140147
d.nodeText = nodeText;
148+
d.shortNodeText = shortNodeText;
141149

142150
d.updateBlocks();
143151

src/utils/IdealGraphVisualizer/Graph/src/main/java/com/sun/hotspot/igv/graph/Figure.java

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public String[] getLines() {
278278
// search is done on the node label (without line breaks). See also
279279
// class NodeQuickSearch in the View module.
280280
for (InputNode n : getSource().getSourceNodes()) {
281-
String label = resolveString(diagram.getNodeText(), n.getProperties());
281+
String label = n.getProperties().resolveString(diagram.getNodeText());
282282
n.getProperties().setProperty("label", label.replaceAll("\\R", " "));
283283
}
284284
}
@@ -290,44 +290,12 @@ public void updateLines() {
290290
String[] result = new String[strings.length];
291291

292292
for (int i = 0; i < strings.length; i++) {
293-
result[i] = resolveString(strings[i], getProperties());
293+
result[i] = getProperties().resolveString(strings[i]);
294294
}
295295

296296
lines = result;
297297
}
298298

299-
public static final String resolveString(String string, Properties properties) {
300-
301-
StringBuilder sb = new StringBuilder();
302-
boolean inBrackets = false;
303-
StringBuilder curIdent = new StringBuilder();
304-
305-
for (int i = 0; i < string.length(); i++) {
306-
char c = string.charAt(i);
307-
if (inBrackets) {
308-
if (c == ']') {
309-
String value = properties.get(curIdent.toString());
310-
if (value == null) {
311-
value = "";
312-
}
313-
sb.append(value);
314-
inBrackets = false;
315-
} else {
316-
curIdent.append(c);
317-
}
318-
} else {
319-
if (c == '[') {
320-
inBrackets = true;
321-
curIdent = new StringBuilder();
322-
} else {
323-
sb.append(c);
324-
}
325-
}
326-
}
327-
328-
return sb.toString();
329-
}
330-
331299
@Override
332300
public Dimension getSize() {
333301
if (VERTICAL_LAYOUT) {

src/utils/IdealGraphVisualizer/Graph/src/main/java/com/sun/hotspot/igv/graph/Slot.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2021, 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
@@ -139,11 +139,16 @@ public String getShortName() {
139139

140140
public String getToolTipText() {
141141
StringBuilder sb = new StringBuilder();
142-
sb.append(text);
142+
String shortNodeText = figure.getDiagram().getShortNodeText();
143+
if (!text.isEmpty()) {
144+
sb.append(text);
145+
if (!shortNodeText.isEmpty()) {
146+
sb.append(": ");
147+
}
148+
}
143149

144150
for (InputNode n : getSource().getSourceNodes()) {
145-
sb.append(StringUtils.escapeHTML("Node (ID=" + n.getId() + "): " + n.getProperties().get("name")));
146-
sb.append("<br>");
151+
sb.append(StringUtils.escapeHTML(n.getProperties().resolveString(shortNodeText)));
147152
}
148153

149154
return sb.toString();

src/utils/IdealGraphVisualizer/Settings/src/main/java/com/sun/hotspot/igv/settings/Settings.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, 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
@@ -34,6 +34,8 @@ public class Settings {
3434

3535
public final static String NODE_TEXT = "nodeText";
3636
public final static String NODE_TEXT_DEFAULT = "[idx] [name]";
37+
public final static String NODE_SHORT_TEXT = "nodeShortText";
38+
public final static String NODE_SHORT_TEXT_DEFAULT = "[idx] [name]";
3739
public final static String NODE_WIDTH = "nodeWidth";
3840
public final static String NODE_WIDTH_DEFAULT = "100";
3941
public final static String PORT = "port";

0 commit comments

Comments
 (0)