Skip to content

Commit edb42d7

Browse files
robcaslozchhagedorn
andcommitted
8282547: IGV: add control-flow graph view
Co-authored-by: Christian Hagedorn <chagedorn@openjdk.org> Reviewed-by: chagedorn, xliu, thartmann
1 parent 7418373 commit edb42d7

File tree

70 files changed

+2091
-507
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2091
-507
lines changed

src/utils/IdealGraphVisualizer/ControlFlow/src/main/java/com/sun/hotspot/igv/controlflow/BlockConnectionWidget.java

+10-1
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, 2022, 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
@@ -26,6 +26,7 @@
2626
import com.sun.hotspot.igv.data.InputBlockEdge;
2727
import com.sun.hotspot.igv.layout.Link;
2828
import com.sun.hotspot.igv.layout.Port;
29+
import com.sun.hotspot.igv.layout.Cluster;
2930
import java.awt.BasicStroke;
3031
import java.awt.Point;
3132
import java.awt.Stroke;
@@ -76,6 +77,14 @@ public Port getFrom() {
7677
return outputSlot;
7778
}
7879

80+
public Cluster getFromCluster() {
81+
return null;
82+
}
83+
84+
public Cluster getToCluster() {
85+
return null;
86+
}
87+
7988
public void setBold(boolean bold) {
8089
this.isBold = bold;
8190
updateStroke();

src/utils/IdealGraphVisualizer/ControlFlow/src/main/java/com/sun/hotspot/igv/controlflow/HierarchicalGraphLayout.java

+9-1
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, 2022, 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
@@ -69,6 +69,14 @@ public Port getTo() {
6969
return to.getSlot();
7070
}
7171

72+
public Cluster getFromCluster() {
73+
return null;
74+
}
75+
76+
public Cluster getToCluster() {
77+
return null;
78+
}
79+
7280
public List<Point> getControlPoints() {
7381
return new ArrayList<Point>();
7482
}

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

+15-1
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, 2022, 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
@@ -35,6 +35,7 @@ public class InputBlock {
3535
private String name;
3636
private InputGraph graph;
3737
private Set<InputBlock> successors;
38+
private boolean artificial;
3839

3940
@Override
4041
public int hashCode() {
@@ -77,6 +78,7 @@ public boolean equals(Object o) {
7778
this.name = name;
7879
nodes = new ArrayList<>();
7980
successors = new LinkedHashSet<>(2);
81+
artificial = false;
8082
}
8183

8284
public String getName() {
@@ -101,6 +103,10 @@ public Set<InputBlock> getSuccessors() {
101103
return Collections.unmodifiableSet(successors);
102104
}
103105

106+
public void setNodes(List<InputNode> nodes) {
107+
this.nodes = nodes;
108+
}
109+
104110
@Override
105111
public String toString() {
106112
return "Block " + this.getName();
@@ -111,4 +117,12 @@ void addSuccessor(InputBlock b) {
111117
successors.add(b);
112118
}
113119
}
120+
121+
void setArtificial(boolean artificial) {
122+
this.artificial = artificial;
123+
}
124+
125+
public boolean isArtificial() {
126+
return artificial;
127+
}
114128
}

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

+8-2
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, 2022, 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
@@ -38,12 +38,14 @@ public enum State {
3838
private InputBlock from;
3939
private InputBlock to;
4040
private State state = State.SAME;
41+
private String label;
4142

42-
public InputBlockEdge(InputBlock from, InputBlock to) {
43+
public InputBlockEdge(InputBlock from, InputBlock to, String label) {
4344
assert from != null;
4445
assert to != null;
4546
this.from = from;
4647
this.to = to;
48+
this.label = label;
4749
}
4850

4951
public InputBlock getFrom() {
@@ -62,6 +64,10 @@ public void setState(State state) {
6264
this.state = state;
6365
}
6466

67+
public String getLabel() {
68+
return label;
69+
}
70+
6571
@Override
6672
public boolean equals(Object obj) {
6773
if (obj != null && obj instanceof InputBlockEdge) {

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

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2022, 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
@@ -58,7 +58,11 @@ public void setParent(Folder parent) {
5858
}
5959

6060
public InputBlockEdge addBlockEdge(InputBlock left, InputBlock right) {
61-
InputBlockEdge edge = new InputBlockEdge(left, right);
61+
return addBlockEdge(left, right, null);
62+
}
63+
64+
public InputBlockEdge addBlockEdge(InputBlock left, InputBlock right, String label) {
65+
InputBlockEdge edge = new InputBlockEdge(left, right, label);
6266
blockEdges.add(edge);
6367
left.addSuccessor(right);
6468
return edge;
@@ -140,6 +144,7 @@ public List<InputEdge> findOutgoingEdges(InputNode n) {
140144

141145
public void clearBlocks() {
142146
blocks.clear();
147+
blockEdges.clear();
143148
nodeToBlock.clear();
144149
}
145150

@@ -168,7 +173,7 @@ public void ensureNodesInBlocks() {
168173
assert nodes.get(n.getId()) == n;
169174
if (!scheduledNodes.contains(n)) {
170175
if (noBlock == null) {
171-
noBlock = this.addBlock("(no block)");
176+
noBlock = addArtificialBlock();
172177
}
173178
noBlock.addNode(n.getId());
174179
}
@@ -270,6 +275,12 @@ public String toString() {
270275
return sb.toString();
271276
}
272277

278+
public InputBlock addArtificialBlock() {
279+
InputBlock b = addBlock("(no block)");
280+
b.setArtificial(true);
281+
return b;
282+
}
283+
273284
public InputBlock addBlock(String name) {
274285
final InputBlock b = new InputBlock(this, name);
275286
blocks.put(b.getName(), b);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2022, 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
@@ -261,7 +261,7 @@ protected void end(String text) throws SAXException {
261261
for (InputNode n : graph.getNodes()) {
262262
if (graph.getBlock(n) == null) {
263263
if (noBlock == null) {
264-
noBlock = graph.addBlock("(no block)");
264+
noBlock = graph.addArtificialBlock();
265265
}
266266

267267
noBlock.addNode(n.getId());

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

+2-2
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, 2022, 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
@@ -78,7 +78,7 @@ private void applyRule(ColorRule rule, Figure f) {
7878
ConnectionStyle style = rule.getLineStyle();
7979

8080
for (OutputSlot s : f.getOutputSlots()) {
81-
for (Connection c : s.getConnections()) {
81+
for (FigureConnection c : s.getConnections()) {
8282
if (color != null) {
8383
c.setColor(color);
8484
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2022, 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
@@ -67,7 +67,7 @@ public void apply(Diagram diagram) {
6767
InputSlot slot = null;
6868

6969
for (InputSlot s : succ.getInputSlots()) {
70-
for (Connection c : s.getConnections()) {
70+
for (FigureConnection c : s.getConnections()) {
7171
if (c.getOutputSlot().getFigure() == f) {
7272
slot = s;
7373
}
@@ -97,8 +97,8 @@ public void apply(Diagram diagram) {
9797
}
9898

9999
for (InputSlot s : f.getInputSlots()) {
100-
for (Connection c : s.getConnections()) {
101-
Connection newConn = diagram.createConnection(slot, c.getOutputSlot(), c.getLabel(), c.getType());
100+
for (FigureConnection c : s.getConnections()) {
101+
FigureConnection newConn = diagram.createConnection(slot, c.getOutputSlot(), c.getLabel());
102102
newConn.setColor(c.getColor());
103103
newConn.setStyle(c.getStyle());
104104
}
@@ -115,7 +115,7 @@ public void apply(Diagram diagram) {
115115

116116
OutputSlot oldSlot = null;
117117
for (OutputSlot s : f.getOutputSlots()) {
118-
for (Connection c : s.getConnections()) {
118+
for (FigureConnection c : s.getConnections()) {
119119
if (c.getInputSlot().getFigure() == succ) {
120120
oldSlot = s;
121121
}
@@ -155,8 +155,8 @@ public void apply(Diagram diagram) {
155155
}
156156
}
157157
}
158-
for (Connection c : nextSlot.getConnections()) {
159-
Connection newConn = diagram.createConnection(c.getInputSlot(), slot, c.getLabel(), c.getType());
158+
for (FigureConnection c : nextSlot.getConnections()) {
159+
FigureConnection newConn = diagram.createConnection(c.getInputSlot(), slot, c.getLabel());
160160
newConn.setColor(c.getColor());
161161
newConn.setStyle(c.getStyle());
162162
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2022, 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
@@ -62,7 +62,7 @@ public void apply(Diagram diagram) {
6262

6363
for (Figure f : figures) {
6464
for (OutputSlot os : f.getOutputSlots()) {
65-
for (Connection c : os.getConnections()) {
65+
for (FigureConnection c : os.getConnections()) {
6666
c.setStyle(rule.getLineStyle());
6767
c.setColor(rule.getLineColor());
6868
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2022, 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
@@ -64,7 +64,7 @@ public void apply(Diagram d) {
6464
for (Slot slot : slots) {
6565
if (index < colors.length && colors[index] != null) {
6666
slot.setColor(colors[index]);
67-
for (Connection c : slot.getConnections()) {
67+
for (FigureConnection c : slot.getConnections()) {
6868

6969
c.setColor(colors[index]);
7070
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
package com.sun.hotspot.igv.filter;
25+
26+
import com.sun.hotspot.igv.graph.Diagram;
27+
import com.sun.hotspot.igv.graph.Block;
28+
import com.sun.hotspot.igv.graph.BlockSelector;
29+
import java.util.ArrayList;
30+
import java.util.HashSet;
31+
import java.util.List;
32+
import java.util.Set;
33+
34+
public class RemoveBlockFilter extends AbstractFilter {
35+
36+
private final List<RemoveBlockRule> rules;
37+
private final String name;
38+
39+
public RemoveBlockFilter(String name) {
40+
this.name = name;
41+
rules = new ArrayList<>();
42+
}
43+
44+
@Override
45+
public String getName() {
46+
return name;
47+
}
48+
49+
@Override
50+
public void apply(Diagram diagram) {
51+
for (RemoveBlockRule r : rules) {
52+
List<Block> selected = r.getBlockSelector().selected(diagram);
53+
Set<Block> toRemove = new HashSet<>(selected);
54+
diagram.removeAllBlocks(toRemove);
55+
}
56+
}
57+
58+
public void addRule(RemoveBlockRule rule) {
59+
rules.add(rule);
60+
}
61+
62+
public static class RemoveBlockRule {
63+
64+
private final BlockSelector selector;
65+
66+
public RemoveBlockRule(BlockSelector selector) {
67+
this.selector = selector;
68+
}
69+
70+
public BlockSelector getBlockSelector() {
71+
return selector;
72+
}
73+
}
74+
}

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

+3-3
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, 2022, 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
@@ -58,9 +58,9 @@ public void apply(Diagram diagram) {
5858
for (InputSlot is : f.getInputSlots()) {
5959
if (z >= r.getStartingIndex() && z <= r.getEndIndex() && is.getConnections().size() > 0) {
6060
StringBuilder sb = new StringBuilder();
61-
List<Connection> conns = is.getConnections();
61+
List<FigureConnection> conns = is.getConnections();
6262
for (int i = 0; i < conns.size(); i++) {
63-
Connection c = conns.get(i);
63+
FigureConnection c = conns.get(i);
6464
OutputSlot os = c.getOutputSlot();
6565
Figure pred = os.getFigure();
6666
if (i != 0) {

0 commit comments

Comments
 (0)