# HG changeset patch # User Thomas Wuerthinger # Date 1327696701 -3600 # Node ID ff74bea7ff551c2ec9c4a9d3d5b52b55573f938b # Parent 0e7133d1991de7391bb6570921b7344bc99ddfde Removed receiver text box from igv. Clean up igv printer. diff -r 0e7133d1991d -r ff74bea7ff55 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:06:41 2012 +0100 +++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/BasicIdealGraphPrinter.java Fri Jan 27 21:38:21 2012 +0100 @@ -34,7 +34,7 @@ /** * Edge between two nodes. */ - public static class Edge { + protected static class Edge { final String from; final int fromIndex; final String to; @@ -83,37 +83,37 @@ /** * Creates a new {@link IdealGraphPrinter} that writes to the specified output stream. */ - public BasicIdealGraphPrinter(OutputStream stream) { + protected BasicIdealGraphPrinter(OutputStream stream) { this.stream = new PrintStream(stream); } /** * Flushes any buffered output. */ - public void flush() { + protected void flush() { stream.flush(); } /** * Starts a new graph document. */ - public void begin() { + protected void begin() { stream.println(""); } - public void beginGroup() { + protected void beginGroup() { stream.println(""); } - public void beginMethod(String name, String shortName, int bci) { + protected void beginMethod(String name, String shortName, int bci) { stream.printf(" %n", escape(name), escape(shortName), bci); } - public void beginBytecodes() { + protected void beginBytecodes() { stream.println(" \n"); } - public void endMethod() { + protected void endMethod() { stream.println(" "); } - public void beginGraph(String title) { + protected void beginGraph(String title) { stream.printf(" %n", escape(title)); } - public void beginProperties() { + protected void beginProperties() { stream.print(""); } - public void printProperty(String name, String value) { + protected void printProperty(String name, String value) { stream.printf("

%s

", escape(name), escape(value)); } - public void endProperties() { + protected void endProperties() { stream.print("
"); } - public void printProperties(Map properties) { + protected void printProperties(Map properties) { beginProperties(); for (Entry entry : properties.entrySet()) { printProperty(entry.getKey(), entry.getValue()); @@ -158,19 +158,19 @@ endProperties(); } - public void beginNodes() { + protected void beginNodes() { stream.println(" "); } - public void beginNode(String id) { + protected void beginNode(String id) { stream.printf(" ", escape(id)); } - public void endNode() { + protected void endNode() { stream.println(" "); } - public void printNode(String id, Map properties) { + protected void printNode(String id, Map properties) { beginNode(id); if (properties != null) { printProperties(properties); @@ -178,77 +178,77 @@ endNode(); } - public void endNodes() { + protected void endNodes() { stream.println(" "); } - public void beginEdges() { + protected void beginEdges() { stream.println(" "); } - public void printEdge(Edge edge) { + protected void printEdge(Edge edge) { stream.printf(" %n", escape(edge.from), edge.fromIndex, escape(edge.to), edge.toIndex, escape(edge.label)); } - public void endEdges() { + protected void endEdges() { stream.println(" "); } - public void beginControlFlow() { + protected void beginControlFlow() { stream.println(" "); } - public void beginBlock(String name) { + protected void beginBlock(String name) { stream.printf(" %n", escape(name)); } - public void beginSuccessors() { + protected void beginSuccessors() { stream.println(" "); } - public void printSuccessor(String name) { + protected void printSuccessor(String name) { stream.printf(" %n", escape(name)); } - public void endSuccessors() { + protected void endSuccessors() { stream.println(" "); } - public void beginBlockNodes() { + protected void beginBlockNodes() { stream.println(" "); } - public void printBlockNode(String nodeId) { + protected void printBlockNode(String nodeId) { stream.printf(" %n", escape(nodeId)); } - public void endBlockNodes() { + protected void endBlockNodes() { stream.println(" "); } - public void endBlock() { + protected void endBlock() { stream.println(" "); } - public void endControlFlow() { + protected void endControlFlow() { stream.println(" "); } - public void endGraph() { + protected void endGraph() { stream.println("
"); } /** * Ends the current group. */ - public void endGroup() { + protected void endGroup() { stream.println("
"); } /** * Finishes the graph document and flushes the output stream. */ - public void end() { + protected void end() { stream.println("
"); flush(); } diff -r 0e7133d1991d -r ff74bea7ff55 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:06:41 2012 +0100 +++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java Fri Jan 27 21:38:21 2012 +0100 @@ -50,11 +50,10 @@ /** * Starts a new group of graphs with the given name, short name and method byte code index (BCI) as properties. */ - public void beginGroup(String name, String shortName, RiResolvedMethod method, int bci, String origin) { + public void beginGroup(String name, String shortName, RiResolvedMethod method, int bci) { beginGroup(); beginProperties(); printProperty("name", name); - printProperty("origin", origin); endProperties(); beginMethod(name, shortName, bci); if (method != null) { diff -r 0e7133d1991d -r ff74bea7ff55 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:06:41 2012 +0100 +++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinterDumpHandler.java Fri Jan 27 21:38:21 2012 +0100 @@ -37,152 +37,42 @@ */ public class IdealGraphPrinterDumpHandler implements DebugDumpHandler { - private static final Pattern INVALID_CHAR = Pattern.compile("[^A-Za-z0-9_.-]"); + private static final String DEFAULT_FILE_NAME = "output.igv.xml"; - private final String host; - private final int port; - - public IdealGraphPrinter printer; - private OutputStream stream; - private Socket socket; + private IdealGraphPrinter printer; private List previousInlineContext = new ArrayList(); /** * Creates a new {@link IdealGraphPrinterDumpHandler} that writes output to a file named after the compiled method. */ public IdealGraphPrinterDumpHandler() { - this(null, -1); + initializeFilePrinter(DEFAULT_FILE_NAME); } /** * Creates a new {@link IdealGraphPrinterDumpHandler} that sends output to a remote IdealGraphVisualizer instance. */ public IdealGraphPrinterDumpHandler(String host, int port) { - this.host = host; - this.port = port; - } - - private IdealGraphPrinter printer() { - return printer; - } - - private Socket socket() { - return socket; - } - - private void openPrinter(RiResolvedMethod method) { - assert stream == null && printer() == null; - String name; - if (method != null) { - name = method.holder().name(); - name = name.substring(1, name.length() - 1).replace('/', '.'); - name = name + "." + method.name(); - } else { - name = "null"; - } - - openPrinter(name, method); + initializeNetworkPrinter(host, port); } - private void openPrinter(String title, RiResolvedMethod method) { - assert stream == null && printer() == null; - if (host != null) { - openNetworkPrinter(title, method); - } else { - openFilePrinter(title, method); - } - } - - private void openFilePrinter(String title, RiResolvedMethod method) { - String filename = title + ".igv.xml"; - filename = INVALID_CHAR.matcher(filename).replaceAll("_"); - - try { - stream = new FileOutputStream(filename); + private void initializeFilePrinter(String fileName) { + try (FileOutputStream stream = new FileOutputStream(fileName)) { printer = new IdealGraphPrinter(stream); - printer().begin(); - printer().beginGroup(title, title, method, -1, "Graal"); } catch (IOException e) { - e.printStackTrace(); - } - } - - public boolean networkAvailable() { - try { - Socket s = new Socket(host, port); - s.setSoTimeout(10); - s.close(); - return true; - } catch (IOException e) { - return false; + throw new RuntimeException(e); } } - private void openNetworkPrinter(String title, RiResolvedMethod method) { - try { - socket = new Socket(host, port); - if (socket().getInputStream().read() == 'y') { - stream = new BufferedOutputStream(socket().getOutputStream(), 0x4000); - } else { - // server currently does not accept any input - socket().close(); - socket = null; - return; - } - - + private void initializeNetworkPrinter(String host, int port) { + try (Socket socket = new Socket(host, port)) { + BufferedOutputStream stream = new BufferedOutputStream(socket.getOutputStream(), 0x4000); printer = new IdealGraphPrinter(stream); - printer().begin(); - printer().beginGroup(title, title, method, -1, "Graal"); - printer().flush(); - if (socket().getInputStream().read() != 'y') { - // server declines input for this method - socket().close(); - socket = null; - stream = null; - printer = null; - } } catch (IOException e) { - System.err.println("Error opening connection to " + host + ":" + port + ": " + e); - - if (socket() != null) { - try { - socket().close(); - } catch (IOException ioe) { - } - socket = null; - } - stream = null; - printer = null; + throw new RuntimeException(e); } } - private void closePrinter() { - assert (printer() != null); - - try { - printer().endGroup(); - printer().end(); - - if (socket() != null) { - socket().close(); // also closes stream - } else { - stream.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - printer = null; - stream = null; - socket = null; - } - } - - public void compilationStarted(String groupTitle) { - openPrinter(groupTitle, null); - } - - @Override public void dump(Object object, String message) { if (object instanceof Graph) { @@ -212,17 +102,31 @@ } } + // Save inline context for next dump. previousInlineContext = inlineContext; + + // Finally, output the graph. + printer.print(graph, message); } } private void openMethodScope(RiResolvedMethod method) { System.out.println("OPEN " + method); + printer.beginGroup(getName(method), getShortName(method), method, -1); } + private static String getShortName(RiResolvedMethod method) { + return method.toString(); + } + + private static String getName(RiResolvedMethod method) { + return method.toString(); + } + private void closeMethodScope(RiResolvedMethod method) { System.out.println("CLOSE " + method); + printer.endGroup(); } } diff -r 0e7133d1991d -r ff74bea7ff55 src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/project.xml --- a/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/project.xml Fri Jan 27 21:06:41 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/nbproject/project.xml Fri Jan 27 21:38:21 2012 +0100 @@ -1,134 +1,142 @@ - - - org.netbeans.modules.apisupport.project - - - com.sun.hotspot.igv.coordinator - - - - com.sun.hotspot.igv.data - - - - 1.0 - - - - com.sun.hotspot.igv.difference - - - - 1.0 - - - - com.sun.hotspot.igv.settings - - - - 1.0 - - - - com.sun.hotspot.igv.util - - - - 1.0 - - - - org.netbeans.api.progress - - - - 1 - 1.23.1 - - - - org.openide.actions - - - - 6.21.1 - - - - org.openide.awt - - - - 7.30.1 - - - - org.openide.dialogs - - - - 7.18.1 - - - - org.openide.explorer - - - - 6.34.1 - - - - org.openide.filesystems - - - - 7.46.1 - - - - org.openide.loaders - - - - 7.20.1 - - - - org.openide.nodes - - - - 7.20.1 - - - - org.openide.util - - - - 8.14.1 - - - - org.openide.util.lookup - - - - 8.6.1 - - - - org.openide.windows - - - - 6.39.1 - - - - - - - + + + org.netbeans.modules.apisupport.project + + + com.sun.hotspot.igv.coordinator + + + + com.sun.hotspot.igv.connection + + + + 1.0 + + + + com.sun.hotspot.igv.data + + + + 1.0 + + + + com.sun.hotspot.igv.difference + + + + 1.0 + + + + com.sun.hotspot.igv.settings + + + + 1.0 + + + + com.sun.hotspot.igv.util + + + + 1.0 + + + + org.netbeans.api.progress + + + + 1 + 1.23.1 + + + + org.openide.actions + + + + 6.21.1 + + + + org.openide.awt + + + + 7.30.1 + + + + org.openide.dialogs + + + + 7.18.1 + + + + org.openide.explorer + + + + 6.34.1 + + + + org.openide.filesystems + + + + 7.46.1 + + + + org.openide.loaders + + + + 7.20.1 + + + + org.openide.nodes + + + + 7.20.1 + + + + org.openide.util + + + + 8.14.1 + + + + org.openide.util.lookup + + + + 8.6.1 + + + + org.openide.windows + + + + 6.39.1 + + + + + + + diff -r 0e7133d1991d -r ff74bea7ff55 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.form --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.form Fri Jan 27 21:06:41 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.form Fri Jan 27 21:38:21 2012 +0100 @@ -16,28 +16,17 @@ - + + + + - - - - - - - - - - - - - - - + diff -r 0e7133d1991d -r ff74bea7ff55 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:06:41 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.java Fri Jan 27 21:38:21 2012 +0100 @@ -23,6 +23,7 @@ */ 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; @@ -70,6 +71,7 @@ private ExplorerManager manager; private GraphDocument document; private FolderNode root; + private Server server; private OutlineTopComponent() { initComponents(); @@ -116,29 +118,20 @@ final GroupCallback callback = new GroupCallback() { + @Override public void started(Group g) { getDocument().addElement(g); } }; - - Collection receivers = Lookup.getDefault().lookupAll(GroupReceiver.class); - if (receivers.size() > 0) { - JPanel panel = new JPanel(); - panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - - for (GroupReceiver r : receivers) { - Component c = r.init(callback); - panel.add(c); - } - - jPanel2.add(panel, BorderLayout.PAGE_START); - } + + server = new Server(callback); } public void clear() { document.clear(); } + @Override public ExplorerManager getExplorerManager() { return manager; } @@ -212,6 +205,7 @@ return super.requestFocusInWindow(temporary); } + @Override public void resultChanged(LookupEvent lookupEvent) { } @@ -244,19 +238,13 @@ // //GEN-BEGIN:initComponents private void initComponents() { - jPanel2 = new javax.swing.JPanel(); treeView = new BeanTreeView(); setLayout(new java.awt.BorderLayout()); - - jPanel2.setLayout(new java.awt.BorderLayout()); - jPanel2.add(treeView, java.awt.BorderLayout.CENTER); - - add(jPanel2, java.awt.BorderLayout.CENTER); + add(treeView, java.awt.BorderLayout.CENTER); }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane treeView; // End of variables declaration//GEN-END:variables } diff -r 0e7133d1991d -r ff74bea7ff55 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:06:41 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java Fri Jan 27 21:38:21 2012 +0100 @@ -144,7 +144,7 @@ protected void end(String text) throws SAXException { final Group group = getObject(); final Folder parent = getParentObject(); - if (groupCallback == null) { + if (groupCallback == null || parent instanceof Group) { SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { @@ -434,8 +434,14 @@ @Override public void end(String text) throws SAXException { - if (groupCallback != null) { - groupCallback.started(getParentObject()); + if (groupCallback != null && getParentObject().getParent() instanceof GraphDocument) { + final Group group = getParentObject(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + groupCallback.started(group); + } + }); } } }; diff -r 0e7133d1991d -r ff74bea7ff55 src/share/tools/IdealGraphVisualizer/NetworkConnection/src/META-INF/services/com.sun.hotspot.igv.data.services.GroupReceiver --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/META-INF/services/com.sun.hotspot.igv.data.services.GroupReceiver Fri Jan 27 21:06:41 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.sun.hotspot.igv.connection.Server \ No newline at end of file diff -r 0e7133d1991d -r ff74bea7ff55 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:06:41 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java Fri Jan 27 21:38:21 2012 +0100 @@ -40,54 +40,36 @@ * * @author Thomas Wuerthinger */ -public class Client implements Runnable, GroupCallback { +public class Client implements Runnable { private Socket socket; - private JTextField networkTextField; private GroupCallback callback; - public Client(Socket socket, JTextField networkTextField, GroupCallback callback) { + public Client(Socket socket, GroupCallback callback) { this.callback = callback; this.socket = socket; - this.networkTextField = networkTextField; } public void run() { try { InputStream inputStream = socket.getInputStream(); - - if (networkTextField.isEnabled()) { - - socket.getOutputStream().write('y'); - InputSource is = new InputSource(inputStream); + InputSource is = new InputSource(inputStream); - try { - Parser parser = new Parser(this); - parser.parse(is, null); - } catch (SAXException ex) { - ex.printStackTrace(); - } - } else { - socket.getOutputStream().write('n'); + try { + Parser parser = new Parser(callback); + parser.parse(is, null); + } catch (SAXException ex) { + ex.printStackTrace(); } - - socket.close(); } catch (IOException ex) { Exceptions.printStackTrace(ex); + } finally { + try { + socket.close(); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } } } - - public void started(final Group g) { - try { - RegexpPropertyMatcher matcher = new RegexpPropertyMatcher("name", ".*" + networkTextField.getText() + ".*"); - if (g.getProperties().selectSingle(matcher) != null && networkTextField.isEnabled()) { - socket.getOutputStream().write('y'); - callback.started(g); - } else { - socket.getOutputStream().write('n'); - } - } catch (IOException e) { - } - } -} +} \ No newline at end of file diff -r 0e7133d1991d -r ff74bea7ff55 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:06:41 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java Fri Jan 27 21:38:21 2012 +0100 @@ -43,49 +43,18 @@ * * @author Thomas Wuerthinger */ -public class Server implements GroupCallback, GroupReceiver, PreferenceChangeListener { +public class Server implements PreferenceChangeListener { - private javax.swing.JPanel jPanel1; - private javax.swing.JCheckBox networkCheckBox; - private javax.swing.JTextField networkTextField; private ServerSocket serverSocket; private GroupCallback callback; private int port; private Runnable serverRunnable; - public Component init(GroupCallback callback) { + public Server(GroupCallback callback) { this.callback = callback; - - jPanel1 = new javax.swing.JPanel(); - networkTextField = new javax.swing.JTextField(); - networkCheckBox = new javax.swing.JCheckBox(); - - - jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); - jPanel1.setLayout(new java.awt.BorderLayout(10, 10)); - jPanel1.add(networkTextField, java.awt.BorderLayout.CENTER); - - networkCheckBox.setSelected(true); - org.openide.awt.Mnemonics.setLocalizedText(networkCheckBox, "Receive when name contains"); - networkCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); - networkCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0)); - networkCheckBox.addChangeListener(new javax.swing.event.ChangeListener() { - - public void stateChanged(javax.swing.event.ChangeEvent evt) { - networkCheckBoxChanged(evt); - } - }); - jPanel1.add(networkCheckBox, java.awt.BorderLayout.WEST); - networkCheckBox.getAccessibleContext().setAccessibleName("Read from network when name contains"); - initializeNetwork(); Settings.get().addPreferenceChangeListener(this); - return jPanel1; - } - - private void networkCheckBoxChanged(javax.swing.event.ChangeEvent evt) { - networkTextField.setEnabled(networkCheckBox.isSelected()); } public void preferenceChange(PreferenceChangeEvent e) { @@ -118,7 +87,7 @@ clientSocket.close(); return; } - RequestProcessor.getDefault().post(new Client(clientSocket, networkTextField, Server.this), 0, Thread.MAX_PRIORITY); + RequestProcessor.getDefault().post(new Client(clientSocket, callback), 0, Thread.MAX_PRIORITY); } catch (IOException ex) { serverSocket = null; NotifyDescriptor message = new NotifyDescriptor.Message("Error during listening for incoming connections. Listening for incoming data is disabled.", NotifyDescriptor.ERROR_MESSAGE);