Skip to content

Commit 6028181

Browse files
committed
8283930: IGV: add toggle button to show/hide empty blocks in CFG view
Reviewed-by: kvn, chagedorn
1 parent a445ecd commit 6028181

File tree

9 files changed

+118
-33
lines changed

9 files changed

+118
-33
lines changed

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

-5
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ public void setControlPoints(List<Point> list) {
100100
controlPoints = list;
101101
}
102102

103-
@Override
104-
public boolean isAlwaysVisible() {
105-
return true;
106-
}
107-
108103
@Override
109104
public boolean hasSlots() {
110105
return false;

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

-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public enum ConnectionStyle {
4141

4242
public String getToolTipText();
4343

44-
public boolean isAlwaysVisible();
45-
4644
public boolean hasSlots();
4745

4846
}

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

-5
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ public void setControlPoints(List<Point> list) {
148148
controlPoints = list;
149149
}
150150

151-
@Override
152-
public boolean isAlwaysVisible() {
153-
return false;
154-
}
155-
156151
@Override
157152
public boolean hasSlots() {
158153
return true;

src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java

+39-21
Original file line numberDiff line numberDiff line change
@@ -605,17 +605,22 @@ private void smallUpdate(boolean relayout) {
605605
}
606606

607607
private boolean isVisible(Connection c) {
608-
if (getModel().getShowCFG()) {
609-
return c.isAlwaysVisible();
610-
}
611-
FigureWidget w1 = getWidget(c.getFrom().getVertex());
612-
FigureWidget w2 = getWidget(c.getTo().getVertex());
613-
614-
if (w1.isVisible() && w2.isVisible()) {
615-
return true;
608+
// Generally, a connection is visible if its source and destination
609+
// widgets are visible. An exception is Figure connections in the CFG
610+
// view, which are never shown.
611+
if (getModel().getShowCFG() && c instanceof FigureConnection) {
612+
return false;
613+
}
614+
Widget w1, w2;
615+
if (c instanceof BlockConnection) {
616+
w1 = getWidget(((Block)c.getFromCluster()).getInputBlock());
617+
w2 = getWidget(((Block)c.getToCluster()).getInputBlock());
618+
} else {
619+
assert (c instanceof FigureConnection);
620+
w1 = getWidget(c.getFrom().getVertex());
621+
w2 = getWidget(c.getTo().getVertex());
616622
}
617-
618-
return false;
623+
return w1.isVisible() && w2.isVisible();
619624
}
620625

621626
private void relayout(Set<Widget> oldVisibleWidgets) {
@@ -697,10 +702,21 @@ private void doCFGLayout(HashSet<Figure> figures, HashSet<Connection> edges) {
697702
}
698703
}
699704
}
700-
// Add connections for CFG edges.
701-
edges.addAll(diagram.getBlockConnections());
705+
// Add visible connections for CFG edges.
706+
for (BlockConnection c : diagram.getBlockConnections()) {
707+
if (isVisible(c)) {
708+
edges.add(c);
709+
}
710+
}
702711
m.setSubManager(new LinearLayoutManager(figureRank));
703-
m.setClusters(new HashSet<>(diagram.getBlocks()));
712+
Set<Block> visibleBlocks = new HashSet<>();
713+
for (Block b : diagram.getBlocks()) {
714+
BlockWidget w = getWidget(b.getInputBlock());
715+
if (w.isVisible()) {
716+
visibleBlocks.add(b);
717+
}
718+
}
719+
m.setClusters(new HashSet<>(visibleBlocks));
704720
m.doLayout(new LayoutGraph(edges, figures));
705721
}
706722

@@ -795,8 +811,9 @@ private void relayoutWithoutLayout(Set<Widget> oldVisibleWidgets) {
795811

796812
if (getModel().getShowCFG()) {
797813
for (BlockConnection c : diagram.getBlockConnections()) {
798-
SceneAnimator anim = animator;
799-
processOutputSlot(lastLineCache, null, Collections.singletonList(c), 0, null, null, offx2, offy2, anim);
814+
if (isVisible(c)) {
815+
processOutputSlot(lastLineCache, null, Collections.singletonList(c), 0, null, null, offx2, offy2, animator);
816+
}
800817
}
801818
}
802819

@@ -1211,18 +1228,19 @@ private void updateHiddenNodes(Set<Integer> newHiddenNodes, boolean doRelayout)
12111228
w.setVisible(false);
12121229
}
12131230
}
1214-
visibleBlocks.clear();
1215-
for (InputBlock b : diagram.getGraph().getBlocks()) {
1216-
if (!b.isArtificial()) {
1217-
visibleBlocks.add(b);
1218-
}
1231+
if (getModel().getShowEmptyBlocks()) {
1232+
// Add remaining blocks.
1233+
visibleBlocks.addAll(diagram.getGraph().getBlocks());
12191234
}
12201235
}
12211236

12221237
if (getModel().getShowBlocks() || getModel().getShowCFG()) {
12231238
for (InputBlock b : diagram.getGraph().getBlocks()) {
12241239

1225-
boolean visibleAfter = visibleBlocks.contains(b);
1240+
// A block is visible if it is marked as such, except for
1241+
// artificial or null blocks in the CFG view.
1242+
boolean visibleAfter = visibleBlocks.contains(b) &&
1243+
!(getModel().getShowCFG() && (b.isArtificial() || b.getNodes().isEmpty()));
12261244

12271245
BlockWidget w = getWidget(b);
12281246
if (visibleAfter) {

src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramViewModel.java

+11
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public class DiagramViewModel extends RangeSliderModel implements ChangedListene
6262
private boolean showBlocks;
6363
private boolean showCFG;
6464
private boolean showNodeHull;
65+
private boolean showEmptyBlocks;
6566
private boolean hideDuplicates;
6667
private ChangedListener<FilterChain> filterChainChangedListener = new ChangedListener<FilterChain>() {
6768

@@ -166,6 +167,15 @@ public void setShowNodeHull(boolean b) {
166167
viewPropertiesChangedEvent.fire();
167168
}
168169

170+
public boolean getShowEmptyBlocks() {
171+
return showEmptyBlocks;
172+
}
173+
174+
public void setShowEmptyBlocks(boolean b) {
175+
showEmptyBlocks = b;
176+
viewPropertiesChangedEvent.fire();
177+
}
178+
169179
public boolean getHideDuplicates() {
170180
return hideDuplicates;
171181
}
@@ -194,6 +204,7 @@ public DiagramViewModel(Group g, FilterChain filterChain, FilterChain sequenceFi
194204
this.showBlocks = Settings.get().getInt(Settings.DEFAULT_VIEW, Settings.DEFAULT_VIEW_DEFAULT) == Settings.DefaultView.CLUSTERED_SEA_OF_NODES;
195205
this.showCFG = Settings.get().getInt(Settings.DEFAULT_VIEW, Settings.DEFAULT_VIEW_DEFAULT) == Settings.DefaultView.CONTROL_FLOW_GRAPH;
196206
this.showNodeHull = true;
207+
this.showEmptyBlocks = true;
197208
this.group = g;
198209
filterGraphs();
199210
assert filterChain != null;

src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/EditorTopComponent.java

+14
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public final class EditorTopComponent extends TopComponent implements PropertyCh
9999
private OverviewAction overviewAction;
100100
private HideDuplicatesAction hideDuplicatesAction;
101101
private PredSuccAction predSuccAction;
102+
private ShowEmptyBlocksAction showEmptyBlocksAction;
102103
private SelectionModeAction selectionModeAction;
103104
private PanModeAction panModeAction;
104105
private boolean notFirstTime;
@@ -279,6 +280,13 @@ public void changed(DiagramViewModel source) {
279280
toolBar.add(button);
280281
predSuccAction.addPropertyChangeListener(this);
281282

283+
showEmptyBlocksAction = new ShowEmptyBlocksAction();
284+
button = new JToggleButton(showEmptyBlocksAction);
285+
button.setSelected(true);
286+
button.setEnabled(Settings.get().getInt(Settings.DEFAULT_VIEW, Settings.DEFAULT_VIEW_DEFAULT) == Settings.DefaultView.CONTROL_FLOW_GRAPH);
287+
toolBar.add(button);
288+
showEmptyBlocksAction.addPropertyChangeListener(this);
289+
282290
hideDuplicatesAction = new HideDuplicatesAction();
283291
hideDuplicatesButton = new JToggleButton(hideDuplicatesAction);
284292
hideDuplicatesButton.setSelected(false);
@@ -546,6 +554,9 @@ public void propertyChange(PropertyChangeEvent evt) {
546554
if (evt.getSource() == this.predSuccAction) {
547555
boolean b = (Boolean) predSuccAction.getValue(PredSuccAction.STATE);
548556
this.getModel().setShowNodeHull(b);
557+
} else if (evt.getSource() == this.showEmptyBlocksAction) {
558+
boolean b = (Boolean) showEmptyBlocksAction.getValue(ShowEmptyBlocksAction.STATE);
559+
this.getModel().setShowEmptyBlocks(b);
549560
} else if (evt.getSource() == this.overviewAction) {
550561
boolean b = (Boolean) overviewAction.getValue(OverviewAction.STATE);
551562
if (b) {
@@ -556,12 +567,15 @@ public void propertyChange(PropertyChangeEvent evt) {
556567
} else if (evt.getSource() == this.seaLayoutAction) {
557568
boolean b = seaLayoutAction.isSelected();
558569
this.getModel().setShowSea(b);
570+
this.showEmptyBlocksAction.setEnabled(false);
559571
} else if (evt.getSource() == this.blockLayoutAction) {
560572
boolean b = blockLayoutAction.isSelected();
561573
this.getModel().setShowBlocks(b);
574+
this.showEmptyBlocksAction.setEnabled(false);
562575
} else if (evt.getSource() == this.cfgLayoutAction) {
563576
boolean b = cfgLayoutAction.isSelected();
564577
this.getModel().setShowCFG(b);
578+
this.showEmptyBlocksAction.setEnabled(true);
565579
} else if (evt.getSource() == this.hideDuplicatesAction) {
566580
boolean b = (Boolean) hideDuplicatesAction.getValue(HideDuplicatesAction.STATE);
567581
this.getModel().setHideDuplicates(b);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.view.actions;
25+
26+
import java.awt.event.ActionEvent;
27+
import javax.swing.AbstractAction;
28+
import javax.swing.Action;
29+
import javax.swing.ImageIcon;
30+
import org.openide.util.ImageUtilities;
31+
32+
public class ShowEmptyBlocksAction extends AbstractAction {
33+
34+
private boolean state;
35+
public static final String STATE = "state";
36+
37+
public ShowEmptyBlocksAction() {
38+
state = true;
39+
putValue(AbstractAction.SMALL_ICON, new ImageIcon(ImageUtilities.loadImage(iconResource())));
40+
putValue(STATE, true);
41+
putValue(Action.SHORT_DESCRIPTION, "Show empty blocks in control-flow graph view");
42+
}
43+
44+
@Override
45+
public void actionPerformed(ActionEvent ev) {
46+
this.state = !state;
47+
this.putValue(STATE, state);
48+
}
49+
50+
protected String iconResource() {
51+
return "com/sun/hotspot/igv/view/images/showEmptyBlocks.png";
52+
}
53+
}

src/utils/IdealGraphVisualizer/View/src/main/resources/com/sun/hotspot/igv/view/layer.xml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<file name="com-sun-hotspot-igv-view-actions-ZoomOutAction.instance"><attr name="position" intvalue="2001"/></file>
1818
<file name="com-sun-hotspot-igv-view-actions-OverviewAction.instance"><attr name="position" intvalue="2001"/></file>
1919
<file name="com-sun-hotspot-igv-view-actions-PredSuccAction.instance"><attr name="position" intvalue="2001"/></file>
20+
<file name="com-sun-hotspot-igv-view-actions-ShowEmptyBlocksAction.instance"><attr name="position" intvalue="2001"/></file>
2021
<file name="com-sun-hotspot-igv-view-actions-EnableSeaLayoutAction.instance"><attr name="position" intvalue="2001"/></file>
2122
<file name="com-sun-hotspot-igv-view-actions-EnableBlockLayoutAction.instance"><attr name="position" intvalue="2001"/></file>
2223
<file name="com-sun-hotspot-igv-view-actions-EnableCFGLayoutAction.instance"><attr name="position" intvalue="2001"/></file>

0 commit comments

Comments
 (0)