changeset 11678:89e9476040de

Support for sub-graphs in IGV.
author Roland Schatz <roland.schatz@oracle.com>
date Tue, 17 Sep 2013 10:34:26 +0200
parents 9d341b6e47e5
children f7a09339e29b
files graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputNode.java src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Diagram.java src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Figure.java src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java
diffstat 6 files changed, 83 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Tue Sep 17 02:35:52 2013 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Tue Sep 17 10:34:26 2013 +0200
@@ -66,6 +66,7 @@
     private static final int PROPERTY_TRUE = 0x05;
     private static final int PROPERTY_FALSE = 0x06;
     private static final int PROPERTY_ARRAY = 0x07;
+    private static final int PROPERTY_SUBGRAPH = 0x08;
 
     private static final int KLASS = 0x00;
     private static final int ENUM_KLASS = 0x01;
@@ -115,6 +116,17 @@
     }
 
     public void print(Graph graph, String title, SchedulePhase predefinedSchedule) throws IOException {
+        writeByte(BEGIN_GRAPH);
+        writePoolObject(title);
+        writeGraph(graph, predefinedSchedule);
+        flush();
+    }
+
+    private void writeGraph(Graph graph) throws IOException {
+        writeGraph(graph, null);
+    }
+
+    private void writeGraph(Graph graph, SchedulePhase predefinedSchedule) throws IOException {
         SchedulePhase schedule = predefinedSchedule;
         if (schedule == null) {
             try {
@@ -126,11 +138,8 @@
         ControlFlowGraph cfg = schedule == null ? null : schedule.getCFG();
         BlockMap<List<ScheduledNode>> blockToNodes = schedule == null ? null : schedule.getBlockToNodesMap();
         Block[] blocks = cfg == null ? null : cfg.getBlocks();
-        writeByte(BEGIN_GRAPH);
-        writePoolObject(title);
         writeNodes(graph);
         writeBlocks(blocks, blockToNodes);
-        flush();
     }
 
     private void flush() throws IOException {
@@ -343,6 +352,9 @@
             } else {
                 writeByte(PROPERTY_FALSE);
             }
+        } else if (obj instanceof Graph) {
+            writeByte(PROPERTY_SUBGRAPH);
+            writeGraph((Graph) obj);
         } else if (obj != null && obj.getClass().isArray()) {
             Class<?> componentType = obj.getClass().getComponentType();
             if (componentType.isPrimitive()) {
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputNode.java	Tue Sep 17 02:35:52 2013 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputNode.java	Tue Sep 17 10:34:26 2013 +0200
@@ -23,7 +23,9 @@
  */
 package com.sun.hotspot.igv.data;
 
+import java.util.ArrayList;
 import java.util.Comparator;
+import java.util.List;
 
 /**
  *
@@ -32,6 +34,7 @@
 public class InputNode extends Properties.Entity {
 
     private int id;
+    private List<InputGraph> subgraphs;
 
     public static final Comparator<InputNode> COMPARATOR = new Comparator<InputNode>() {
         @Override
@@ -81,6 +84,17 @@
         return id;
     }
 
+    public void addSubgraph(InputGraph graph) {
+        if (subgraphs == null) {
+            subgraphs = new ArrayList<>();
+        }
+        subgraphs.add(graph);
+    }
+
+    public List<InputGraph> getSubgraphs() {
+        return subgraphs;
+    }
+
     @Override
     public boolean equals(Object o) {
         if (!(o instanceof InputNode)) {
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java	Tue Sep 17 02:35:52 2013 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java	Tue Sep 17 10:34:26 2013 +0200
@@ -62,6 +62,7 @@
     private static final int PROPERTY_TRUE = 0x05;
     private static final int PROPERTY_FALSE = 0x06;
     private static final int PROPERTY_ARRAY = 0x07;
+    private static final int PROPERTY_SUBGRAPH = 0x08;
     
     private static final String NO_BLOCK = "noBlock";
     
@@ -522,6 +523,10 @@
                     default:
                         throw new IOException("Unknown type");
                 }
+            case PROPERTY_SUBGRAPH:
+                InputGraph graph = parseGraph(null);
+                new Group(null).addElement(graph);
+                return graph;
             default:
                 throw new IOException("Unknown type");
         }
@@ -612,6 +617,10 @@
             monitor.updateProgress();
         }
         String title = readPoolObject(String.class);
+        return parseGraph(title);
+    }
+
+    private InputGraph parseGraph(String title) throws IOException {
         InputGraph graph = new InputGraph(title);
         parseNodes(graph);
         parseBlocks(graph);
@@ -666,8 +675,14 @@
                     key = "!data." + key;
                 }
                 Object value = readPropertyObject();
-                properties.setProperty(key, value != null ? value.toString() : "null");
-                props.put(key, value);
+                if (value instanceof InputGraph) {
+                    InputGraph subgraph = (InputGraph) value;
+                    subgraph.getProperties().setProperty("name", node.getId() + ":" + key);
+                    node.addSubgraph((InputGraph) value);
+                } else {
+                    properties.setProperty(key, value != null ? value.toString() : "null");
+                    props.put(key, value);
+                }
             }
             int edgesStart = edges.size();
             int suxCount = readShort();
--- a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Diagram.java	Tue Sep 17 02:35:52 2013 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Diagram.java	Tue Sep 17 10:34:26 2013 +0200
@@ -119,6 +119,7 @@
             Figure f = d.createFigure();
             f.getSource().addSourceNode(n);
             f.getProperties().add(n.getProperties());
+            f.setSubgraphs(n.getSubgraphs());
             figureHash.put(n.getId(), f);
         }
 
--- a/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Figure.java	Tue Sep 17 02:35:52 2013 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Graph/src/com/sun/hotspot/igv/graph/Figure.java	Tue Sep 17 10:34:26 2013 +0200
@@ -23,6 +23,7 @@
  */
 package com.sun.hotspot.igv.graph;
 
+import com.sun.hotspot.igv.data.InputGraph;
 import com.sun.hotspot.igv.data.InputNode;
 import com.sun.hotspot.igv.data.Properties;
 import com.sun.hotspot.igv.data.Source;
@@ -51,6 +52,7 @@
     private Point position;
     private List<Figure> predecessors;
     private List<Figure> successors;
+    private List<InputGraph> subgraphs;
     private Color color;
     private int id;
     private String idString;
@@ -177,6 +179,14 @@
         successors.remove(f);
     }
 
+    public List<InputGraph> getSubgraphs() {
+        return subgraphs;
+    }
+
+    public void setSubgraphs(List<InputGraph> subgraphs) {
+        this.subgraphs = subgraphs;
+    }
+
     @Override
     public void setPosition(Point p) {
         this.position = p;
--- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java	Tue Sep 17 02:35:52 2013 +0200
+++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/widgets/FigureWidget.java	Tue Sep 17 10:34:26 2013 +0200
@@ -23,16 +23,20 @@
  */
 package com.sun.hotspot.igv.view.widgets;
 
+import com.sun.hotspot.igv.data.InputGraph;
 import com.sun.hotspot.igv.data.Properties;
+import com.sun.hotspot.igv.data.services.GraphViewer;
 import com.sun.hotspot.igv.graph.Figure;
 import com.sun.hotspot.igv.util.DoubleClickAction;
 import com.sun.hotspot.igv.util.DoubleClickHandler;
 import com.sun.hotspot.igv.util.PropertiesSheet;
 import com.sun.hotspot.igv.view.DiagramScene;
 import java.awt.*;
+import java.awt.event.ActionEvent;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Set;
+import javax.swing.AbstractAction;
 import javax.swing.Action;
 import javax.swing.BorderFactory;
 import javax.swing.JMenu;
@@ -49,6 +53,7 @@
 import org.openide.nodes.Children;
 import org.openide.nodes.Node;
 import org.openide.nodes.Sheet;
+import org.openide.util.Lookup;
 
 /**
  *
@@ -272,6 +277,27 @@
         successors.addMenuListener(new NeighborMenuListener(successors, getFigure(), true));
         menu.add(successors);
 
+        if (getFigure().getSubgraphs() != null) {
+            menu.addSeparator();
+            JMenu subgraphs = new JMenu("Subgraphs");
+            menu.add(subgraphs);
+
+            final GraphViewer viewer = Lookup.getDefault().lookup(GraphViewer.class);
+            for(final InputGraph subgraph : getFigure().getSubgraphs()) {
+                Action a = new AbstractAction() {
+
+                    @Override
+                    public void actionPerformed(ActionEvent e) {
+                        viewer.view(subgraph, true);
+                    }
+                };
+
+                a.setEnabled(true);
+                a.putValue(Action.NAME, subgraph.getName());
+                subgraphs.add(a);
+            }
+        }
+
         return menu;
     }