changeset 4377:2fe2bb2e912b

Made inline tree work in IGV.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 27 Jan 2012 23:25:52 +0100
parents ff74bea7ff55
children 0c632ed89063
files graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/BasicIdealGraphPrinter.java graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterDumpHandler.java src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.java src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputMethod.java src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupReceiver.java src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java
diffstat 12 files changed, 86 insertions(+), 108 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java	Fri Jan 27 21:38:21 2012 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java	Fri Jan 27 23:25:52 2012 +0100
@@ -26,6 +26,7 @@
 import java.util.regex.*;
 
 import com.oracle.max.cri.ri.*;
+import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.printer.*;
@@ -46,7 +47,7 @@
         this.timerFilter = timerFilter;
         this.dumpFilter = dumpFilter;
         this.methodFilter = methodFilter;
-        dumpHandlers.add(new IdealGraphPrinterDumpHandler());
+        dumpHandlers.add(new IdealGraphPrinterDumpHandler(GraalOptions.PrintIdealGraphAddress, GraalOptions.PrintIdealGraphPort));
     }
 
     public boolean isLogEnabled() {
--- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/BasicIdealGraphPrinter.java	Fri Jan 27 21:38:21 2012 +0100
+++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/BasicIdealGraphPrinter.java	Fri Jan 27 23:25:52 2012 +0100
@@ -253,6 +253,12 @@
         flush();
     }
 
+
+    public boolean isValid() {
+        return !stream.checkError();
+    }
+
+
     private static String escape(String s) {
         StringBuilder str = null;
         for (int i = 0; i < s.length(); i++) {
--- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java	Fri Jan 27 21:38:21 2012 +0100
+++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java	Fri Jan 27 23:25:52 2012 +0100
@@ -273,5 +273,4 @@
             endBlock();
         }
     }
-
 }
--- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterDumpHandler.java	Fri Jan 27 21:38:21 2012 +0100
+++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterDumpHandler.java	Fri Jan 27 23:25:52 2012 +0100
@@ -28,6 +28,7 @@
 import java.util.regex.*;
 
 import com.oracle.max.cri.ri.*;
+import com.oracle.max.criutils.*;
 import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 
@@ -40,13 +41,14 @@
     private static final String DEFAULT_FILE_NAME = "output.igv.xml";
 
     private IdealGraphPrinter printer;
-    private List<RiResolvedMethod> previousInlineContext = new ArrayList<RiResolvedMethod>();
+    private List<RiResolvedMethod> previousInlineContext = new ArrayList<>();
 
     /**
      * Creates a new {@link IdealGraphPrinterDumpHandler} that writes output to a file named after the compiled method.
      */
     public IdealGraphPrinterDumpHandler() {
         initializeFilePrinter(DEFAULT_FILE_NAME);
+        begin();
     }
 
     /**
@@ -54,10 +56,16 @@
      */
     public IdealGraphPrinterDumpHandler(String host, int port) {
         initializeNetworkPrinter(host, port);
+        begin();
+    }
+
+    private void begin() {
+        printer.begin();
     }
 
     private void initializeFilePrinter(String fileName) {
-        try (FileOutputStream stream = new FileOutputStream(fileName)) {
+        try {
+            FileOutputStream stream = new FileOutputStream(fileName);
             printer = new IdealGraphPrinter(stream);
         } catch (IOException e) {
             throw new RuntimeException(e);
@@ -65,48 +73,62 @@
     }
 
     private void initializeNetworkPrinter(String host, int port) {
-        try (Socket socket = new Socket(host, port)) {
+        try  {
+            Socket socket = new Socket(host, port);
             BufferedOutputStream stream = new BufferedOutputStream(socket.getOutputStream(), 0x4000);
             printer = new IdealGraphPrinter(stream);
+            TTY.println("Connected to the IGV on port %d", port);
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
     }
 
     @Override
-    public void dump(Object object, String message) {
+    public void dump(Object object, final String message) {
         if (object instanceof Graph) {
-            Graph graph = (Graph) object;
+            final Graph graph = (Graph) object;
 
-            // Get all current RiResolvedMethod instances in the context.
-            List<RiResolvedMethod> inlineContext = Debug.contextSnapshot(RiResolvedMethod.class);
+            if (printer.isValid()) {
+                // Get all current RiResolvedMethod instances in the context.
+                List<RiResolvedMethod> inlineContext = Debug.contextSnapshot(RiResolvedMethod.class);
 
-            // Reverse list such that inner method comes after outer method.
-            Collections.reverse(inlineContext);
+                // Reverse list such that inner method comes after outer method.
+                Collections.reverse(inlineContext);
 
-            // Check for method scopes that must be closed since the previous dump.
-            for (int i = 0; i < previousInlineContext.size(); ++i) {
-                if (i >= inlineContext.size() || inlineContext.get(i) != previousInlineContext.get(i)) {
-                    for (int j = previousInlineContext.size() - 1; j >= i; --j) {
-                        closeMethodScope(previousInlineContext.get(j));
+                // Check for method scopes that must be closed since the previous dump.
+                for (int i = 0; i < previousInlineContext.size(); ++i) {
+                    if (i >= inlineContext.size() || inlineContext.get(i) != previousInlineContext.get(i)) {
+                        for (int j = previousInlineContext.size() - 1; j >= i; --j) {
+                            closeMethodScope(previousInlineContext.get(j));
+                        }
                     }
                 }
-            }
 
-            // Check for method scopes that must be opened since the previous dump.
-            for (int i = 0; i < inlineContext.size(); ++i) {
-                if (i >= previousInlineContext.size() || inlineContext.get(i) != previousInlineContext.get(i)) {
-                    for (int j = i; j < inlineContext.size(); ++j) {
-                        openMethodScope(inlineContext.get(j));
+                // Check for method scopes that must be opened since the previous dump.
+                for (int i = 0; i < inlineContext.size(); ++i) {
+                    if (i >= previousInlineContext.size() || inlineContext.get(i) != previousInlineContext.get(i)) {
+                        for (int j = i; j < inlineContext.size(); ++j) {
+                            openMethodScope(inlineContext.get(j));
+                        }
                     }
                 }
-            }
+
+                // Save inline context for next dump.
+                previousInlineContext = inlineContext;
+
+                Debug.sandbox("PrintingGraph", new Runnable() {
 
-            // Save inline context for next dump.
-            previousInlineContext = inlineContext;
+                    @Override
+                    public void run() {
+                        // Finally, output the graph.
+                        printer.print(graph, message);
 
-            // Finally, output the graph.
-            printer.print(graph, message);
+                    }
+                });
+            } else {
+                TTY.println("Printer invalid!");
+                System.exit(-1);
+            }
         }
     }
 
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.java	Fri Jan 27 21:38:21 2012 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.java	Fri Jan 27 23:25:52 2012 +0100
@@ -24,26 +24,15 @@
 package com.sun.hotspot.igv.coordinator;
 
 import com.sun.hotspot.igv.connection.Server;
-import com.sun.hotspot.igv.coordinator.actions.ImportAction;
-import com.sun.hotspot.igv.coordinator.actions.RemoveAction;
-import com.sun.hotspot.igv.coordinator.actions.RemoveAllAction;
-import com.sun.hotspot.igv.coordinator.actions.SaveAllAction;
-import com.sun.hotspot.igv.coordinator.actions.SaveAsAction;
+import com.sun.hotspot.igv.coordinator.actions.*;
 import com.sun.hotspot.igv.data.GraphDocument;
-import com.sun.hotspot.igv.data.ChangedListener;
 import com.sun.hotspot.igv.data.Group;
 import com.sun.hotspot.igv.data.services.GroupCallback;
-import com.sun.hotspot.igv.data.services.GroupReceiver;
 import java.awt.BorderLayout;
-import java.awt.Component;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import javax.swing.BoxLayout;
-import javax.swing.JPanel;
 import javax.swing.UIManager;
 import javax.swing.border.Border;
 import org.openide.ErrorManager;
@@ -52,7 +41,6 @@
 import org.openide.explorer.ExplorerManager;
 import org.openide.explorer.ExplorerUtils;
 import org.openide.explorer.view.BeanTreeView;
-import org.openide.util.Lookup;
 import org.openide.util.LookupEvent;
 import org.openide.util.LookupListener;
 import org.openide.util.NbBundle;
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java	Fri Jan 27 21:38:21 2012 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java	Fri Jan 27 23:25:52 2012 +0100
@@ -77,8 +77,10 @@
         elements.add(element);
         if (element instanceof InputGraph) {
             graphs.add((InputGraph) element);
-            ((InputGraph) element).setParent(this);
+        } else {
+            
         }
+        element.setParent(this);
         changedEvent.fire();
     }
 
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputMethod.java	Fri Jan 27 21:38:21 2012 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputMethod.java	Fri Jan 27 23:25:52 2012 +0100
@@ -70,8 +70,8 @@
         this.name = name;
         this.bci = bci;
         this.shortName = shortName;
-        inlined = new ArrayList<InputMethod>();
-        bytecodes = new ArrayList<InputBytecode>();
+        inlined = new ArrayList<>();
+        bytecodes = new ArrayList<>();
     }
 
     public List<InputBytecode> getBytecodes() {
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java	Fri Jan 27 21:38:21 2012 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java	Fri Jan 27 23:25:52 2012 +0100
@@ -92,12 +92,12 @@
     public static final String SUCCESSOR_ELEMENT = "successor";
     public static final String ASSEMBLY_ELEMENT = "assembly";
     public static final String DIFFERENCE_PROPERTY = "difference";
-    private TopElementHandler<GraphDocument> xmlDocument = new TopElementHandler<GraphDocument>();
+    private TopElementHandler<GraphDocument> xmlDocument = new TopElementHandler<>();
     private Map<Group, Boolean> differenceEncoding = new HashMap<>();
     private Map<Group, InputGraph> lastParsedGraph = new HashMap<>();
     private GroupCallback groupCallback;
-    private HashMap<String, Integer> idCache = new HashMap<String, Integer>();
-    private ArrayList<Pair<String, String>> blockConnections = new ArrayList<Pair<String, String>>();
+    private HashMap<String, Integer> idCache = new HashMap<>();
+    private ArrayList<Pair<String, String>> blockConnections = new ArrayList<>();
     private int maxId = 0;
 
     private int lookupID(String i) {
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java	Fri Jan 27 21:38:21 2012 +0100
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java	Fri Jan 27 23:25:52 2012 +0100
@@ -84,24 +84,25 @@
     public static class ElementHandler<T, P> {
 
         private String name;
-        private T object;
+        private Stack<T> object = new Stack<>();
         private Attributes attr;
         private StringBuilder currentText;
         private ParseMonitor monitor;
         private HashMap<String, ElementHandler<?, ? super T>> hashtable;
         private boolean needsText;
-        private ElementHandler<P, ?> parentElement;
+        private Stack<ElementHandler<P, ?>> parentElement = new Stack<>();
+        private Stack<P> parentObject = new Stack<>();
 
         public ElementHandler(String name) {
             this(name, false);
         }
 
         public ElementHandler<P, ?> getParentElement() {
-            return parentElement;
+            return parentElement.peek();
         }
 
         public P getParentObject() {
-            return getParentElement().getObject();
+            return parentObject.peek();
         }
 
         protected boolean needsText() {
@@ -109,7 +110,7 @@
         }
 
         public ElementHandler(String name, boolean needsText) {
-            this.hashtable = new HashMap<String, ElementHandler<?, ? super T>>();
+            this.hashtable = new HashMap<>();
             this.name = name;
             this.needsText = needsText;
         }
@@ -132,7 +133,7 @@
         }
 
         public T getObject() {
-            return object;
+            return object.size() == 0 ? null : object.peek();
         }
 
         public String readAttribute(String name) {
@@ -160,8 +161,9 @@
             this.currentText = new StringBuilder();
             this.attr = attr;
             this.monitor = monitor;
-            this.parentElement = parentElement;
-            object = start();
+            this.parentElement.push(parentElement);
+            parentObject.push(parentElement.getObject());
+            object.push(start());
         }
 
         protected T start() throws SAXException {
@@ -174,6 +176,9 @@
 
         public void endElement() throws SAXException {
             end(currentText.toString());
+            object.pop();
+            parentElement.pop();
+            parentObject.pop();
         }
 
         protected void text(char[] c, int start, int length) {
@@ -185,7 +190,7 @@
     private ParseMonitor monitor;
 
     public XMLParser(TopElementHandler rootHandler, ParseMonitor monitor) {
-        this.stack = new Stack<ElementHandler>();
+        this.stack = new Stack<>();
         this.monitor = monitor;
         this.stack.push(rootHandler);
     }
@@ -196,19 +201,24 @@
         }
     }
 
+    @Override
     public void startDocument() throws SAXException {
     }
 
+    @Override
     public void endDocument() throws SAXException {
     }
 
+    @Override
     public void startPrefixMapping(String prefix, String uri) throws SAXException {
     }
 
+    @Override
     public void endPrefixMapping(String prefix) throws SAXException {
     }
 
     @SuppressWarnings("unchecked")
+    @Override
     public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
         assert !stack.isEmpty();
 
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupReceiver.java	Fri Jan 27 21:38:21 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2008, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-package com.sun.hotspot.igv.data.services;
-
-import java.awt.Component;
-
-/**
- *
- * @author Thomas Wuerthinger
- */
-public interface GroupReceiver {
-
-    public Component init(GroupCallback callback);
-}
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java	Fri Jan 27 21:38:21 2012 +0100
+++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java	Fri Jan 27 23:25:52 2012 +0100
@@ -24,14 +24,12 @@
  */
 package com.sun.hotspot.igv.connection;
 
-import com.sun.hotspot.igv.data.Group;
+import com.sun.hotspot.igv.data.serialization.Parser;
 import com.sun.hotspot.igv.data.services.GroupCallback;
-import com.sun.hotspot.igv.data.serialization.Parser;
-import com.sun.hotspot.igv.data.Properties.RegexpPropertyMatcher;
+import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.Socket;
-import javax.swing.JTextField;
 import org.openide.util.Exceptions;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -53,7 +51,7 @@
     public void run() {
 
         try {
-            InputStream inputStream = socket.getInputStream();
+            InputStream inputStream = new BufferedInputStream(socket.getInputStream());
             InputSource is = new InputSource(inputStream);
 
             try {
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java	Fri Jan 27 21:38:21 2012 +0100
+++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java	Fri Jan 27 23:25:52 2012 +0100
@@ -24,17 +24,13 @@
  */
 package com.sun.hotspot.igv.connection;
 
-import com.sun.hotspot.igv.data.Group;
 import com.sun.hotspot.igv.data.services.GroupCallback;
-import com.sun.hotspot.igv.data.services.GroupReceiver;
 import com.sun.hotspot.igv.settings.Settings;
-import java.awt.Component;
 import java.io.IOException;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.util.prefs.PreferenceChangeEvent;
 import java.util.prefs.PreferenceChangeListener;
-import javax.swing.SwingUtilities;
 import org.openide.DialogDisplayer;
 import org.openide.NotifyDescriptor;
 import org.openide.util.RequestProcessor;
@@ -102,13 +98,4 @@
 
         RequestProcessor.getDefault().post(runnable, 0, Thread.MAX_PRIORITY);
     }
-
-    public void started(final Group g) {
-        SwingUtilities.invokeLater(new Runnable() {
-
-            public void run() {
-                callback.started(g);
-            }
-        });
-    }
 }