diff src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramScene.java @ 21146:33ff6b03fad1

add support for control flow window and basic block view on graphs Contributed-by: Michael Haupt <michael.haupt@oracle.com> Contributed-by: Peter Hofer <peter.hofer@jku.at> Contributed-by: Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
author Michael Haupt <michael.haupt@oracle.com>
date Wed, 29 Apr 2015 08:31:28 +0200
parents 3c78119de0cd
children
line wrap: on
line diff
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramScene.java	Tue Apr 28 12:58:40 2015 -0700
+++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramScene.java	Wed Apr 29 08:31:28 2015 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, 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
@@ -25,9 +25,13 @@
 
 import com.sun.hotspot.igv.data.ChangedListener;
 import com.sun.hotspot.igv.data.ControllableChangedListener;
+import com.sun.hotspot.igv.data.InputBlock;
+import com.sun.hotspot.igv.data.InputNode;
 import com.sun.hotspot.igv.data.Pair;
 import com.sun.hotspot.igv.data.Properties;
+import com.sun.hotspot.igv.data.services.Scheduler;
 import com.sun.hotspot.igv.graph.*;
+import com.sun.hotspot.igv.hierarchicallayout.HierarchicalClusterLayoutManager;
 import com.sun.hotspot.igv.hierarchicallayout.HierarchicalLayoutManager;
 import com.sun.hotspot.igv.layout.LayoutGraph;
 import com.sun.hotspot.igv.selectioncoordinator.SelectionCoordinator;
@@ -111,6 +115,7 @@
             return DiagramScene.this.createPopupMenu();
         }
     };
+
     private RectangularSelectDecorator rectangularSelectDecorator = new RectangularSelectDecorator() {
 
         @Override
@@ -462,8 +467,14 @@
 
         name += " (";
 
+        if (f.getCluster() != null) {
+            name += "B" + f.getCluster().toString();
+        }
         final boolean hidden = !this.getWidget(f, FigureWidget.class).isVisible();
         if (hidden) {
+            if (f.getCluster() != null) {
+                name += ", ";
+            }
             name += "hidden";
         }
         name += ")";
@@ -503,6 +514,14 @@
         }
 
         Diagram d = getModel().getDiagramToView();
+        
+        if (d.getGraph().getBlocks().isEmpty()) {
+            Scheduler s = Lookup.getDefault().lookup(Scheduler.class);
+            d.getGraph().clearBlocks();
+            s.schedule(d.getGraph());
+            d.getGraph().ensureNodesInBlocks();
+            d.updateBlocks();
+        }
 
         for (Figure f : d.getFigures()) {
             FigureWidget w = new FigureWidget(f, hoverAction, selectAction, this, mainLayer);
@@ -530,6 +549,15 @@
             }
         }
         
+        if (getModel().getShowBlocks()) {
+            for (InputBlock bn : d.getGraph().getBlocks()) {
+                BlockWidget w = new BlockWidget(this, d, bn);
+                w.setVisible(false);
+                this.addObject(bn, w);
+                blockLayer.addChild(w);
+            }
+        }
+        
         rebuilding = false;
         this.smallUpdate(true);
     }
@@ -577,9 +605,20 @@
             }
         }
 
-        HierarchicalLayoutManager manager = new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS);
-        manager.setMaxLayerLength(10);
-        manager.doLayout(new LayoutGraph(edges, figures));
+        if (getModel().getShowBlocks()) {
+            HierarchicalClusterLayoutManager m = new HierarchicalClusterLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS);
+            HierarchicalLayoutManager manager = new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS);
+            manager.setMaxLayerLength(9);
+            manager.setMinLayerDifference(3);
+            m.setManager(manager);
+            m.setSubManager(new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS));
+            m.doLayout(new LayoutGraph(edges, figures));
+        } else {
+            HierarchicalLayoutManager manager = new HierarchicalLayoutManager(HierarchicalLayoutManager.Combine.SAME_OUTPUTS);
+            manager.setMaxLayerLength(10);
+            manager.doLayout(new LayoutGraph(edges, figures));
+        }
+        
         relayoutWithoutLayout(oldVisibleWidgets);
     }
     private Set<Pair<Point, Point>> lineCache = new HashSet<>();
@@ -613,6 +652,17 @@
                 }
             }
         }
+        
+        if (getModel().getShowBlocks()) {
+            for (Block b : diagram.getBlocks()) {
+                BlockWidget w = getWidget(b.getInputBlock());
+                if (w != null && w.isVisible()) {
+                    Rectangle r = b.getBounds();
+                    maxX = Math.max(maxX, r.x + r.width);
+                    maxY = Math.max(maxY, r.y + r.height);
+                }
+            }
+        }
 
         bottomRight.setPreferredLocation(new Point(maxX + BORDER_SIZE, maxY + BORDER_SIZE));
         int offx = 0;
@@ -669,6 +719,23 @@
                 }
             }
         }
+        
+        if (getModel().getShowBlocks()) {
+            for (Block b : diagram.getBlocks()) {
+                BlockWidget w = getWidget(b.getInputBlock());
+                if (w != null && w.isVisible()) {
+                    Point location = new Point(b.getBounds().x + offx2, b.getBounds().y + offy2);
+                    Rectangle r = new Rectangle(location.x, location.y, b.getBounds().width, b.getBounds().height);
+                    
+                    if ((visibleFigureCount <= ANIMATION_LIMIT && oldVisibleWidgets != null && oldVisibleWidgets.contains(w))) {
+                        animator.animatePreferredBounds(w, r);
+                    } else {
+                        w.setPreferredBounds(r);
+                        animator.animatePreferredBounds(w, r);
+                    }
+                }
+            }
+        }
 
         this.validate();
     }
@@ -956,6 +1023,7 @@
         Diagram diagram = getModel().getDiagramToView();
         assert diagram != null;
 
+        Set<InputBlock> visibleBlocks = new HashSet<InputBlock>();
         Set<Widget> oldVisibleWidgets = new HashSet<>();
 
         for (Figure f : diagram.getFigures()) {
@@ -964,6 +1032,15 @@
                 oldVisibleWidgets.add(w);
             }
         }
+        
+        if (getModel().getShowBlocks()) {
+            for (InputBlock b : diagram.getGraph().getBlocks()) {
+                BlockWidget w = getWidget(b);
+                if (w.isVisible()) {
+                    oldVisibleWidgets.add(w);
+                }
+            }
+        }
 
         for (Figure f : diagram.getFigures()) {
             boolean hiddenAfter = doesIntersect(f.getSource().getSourceNodesAsSet(), newHiddenNodes);
@@ -973,6 +1050,9 @@
             if (!hiddenAfter) {
                 // Figure is shown
                 w.setVisible(true);
+                for (InputNode n : f.getSource().getSourceNodes()) {
+                    visibleBlocks.add(diagram.getGraph().getBlock(n));
+                }
             } else {
                 // Figure is hidden
                 w.setVisible(false);
@@ -998,6 +1078,9 @@
 
                     if (b) {
                         w.setBoundary(true);
+                        for (InputNode n : f.getSource().getSourceNodes()) {
+                            visibleBlocks.add(diagram.getGraph().getBlock(n));
+                        }
                         boundaries.add(w);
                     }
                 }
@@ -1009,6 +1092,22 @@
                 }
             }
         }
+        
+        if (getModel().getShowBlocks()) {
+            for (InputBlock b : diagram.getGraph().getBlocks()) {
+
+                boolean visibleAfter = visibleBlocks.contains(b);
+
+                BlockWidget w = getWidget(b);
+                if (visibleAfter) {
+                    // Block must be shown
+                    w.setVisible(true);
+                } else {
+                    // Block must be hidden
+                    w.setVisible(false);
+                }
+            }
+        }
 
         if (doRelayout) {
             relayout(oldVisibleWidgets);