# HG changeset patch # User Thomas Wuerthinger # Date 1327703152 -3600 # Node ID 2fe2bb2e912b63dc059b497391949b248d7df8aa # Parent ff74bea7ff551c2ec9c4a9d3d5b52b55573f938b Made inline tree work in IGV. diff -r ff74bea7ff55 -r 2fe2bb2e912b graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotDebugConfig.java --- 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() { diff -r ff74bea7ff55 -r 2fe2bb2e912b graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/BasicIdealGraphPrinter.java --- 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++) { diff -r ff74bea7ff55 -r 2fe2bb2e912b graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java --- 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(); } } - } diff -r ff74bea7ff55 -r 2fe2bb2e912b graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterDumpHandler.java --- 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 previousInlineContext = new ArrayList(); + private List 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 inlineContext = Debug.contextSnapshot(RiResolvedMethod.class); + if (printer.isValid()) { + // Get all current RiResolvedMethod instances in the context. + List 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); + } } } diff -r ff74bea7ff55 -r 2fe2bb2e912b src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.java --- 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; diff -r ff74bea7ff55 -r 2fe2bb2e912b src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java --- 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(); } diff -r ff74bea7ff55 -r 2fe2bb2e912b src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputMethod.java --- 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(); - bytecodes = new ArrayList(); + inlined = new ArrayList<>(); + bytecodes = new ArrayList<>(); } public List getBytecodes() { diff -r ff74bea7ff55 -r 2fe2bb2e912b src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java --- 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 xmlDocument = new TopElementHandler(); + private TopElementHandler xmlDocument = new TopElementHandler<>(); private Map differenceEncoding = new HashMap<>(); private Map lastParsedGraph = new HashMap<>(); private GroupCallback groupCallback; - private HashMap idCache = new HashMap(); - private ArrayList> blockConnections = new ArrayList>(); + private HashMap idCache = new HashMap<>(); + private ArrayList> blockConnections = new ArrayList<>(); private int maxId = 0; private int lookupID(String i) { diff -r ff74bea7ff55 -r 2fe2bb2e912b src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java --- 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 { private String name; - private T object; + private Stack object = new Stack<>(); private Attributes attr; private StringBuilder currentText; private ParseMonitor monitor; private HashMap> hashtable; private boolean needsText; - private ElementHandler parentElement; + private Stack> parentElement = new Stack<>(); + private Stack

parentObject = new Stack<>(); public ElementHandler(String name) { this(name, false); } public ElementHandler 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>(); + 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(); + 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(); diff -r ff74bea7ff55 -r 2fe2bb2e912b src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupReceiver.java --- 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); -} diff -r ff74bea7ff55 -r 2fe2bb2e912b src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java --- 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 { diff -r ff74bea7ff55 -r 2fe2bb2e912b src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java --- 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); - } - }); - } }