# HG changeset patch # User Gilles Duboscq # Date 1342105149 -7200 # Node ID 8fd81d0e3acf3519048eb487fd9a309b1f70be21 # Parent ade4014aa89589fd630804806307190ff3cb8dbc Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish Remove debug code from binary dumper Allow openning of binary graphs in IGV Present Xml and binary parsers under a common interface in IGV Factor binary/xml Server/Client classes in IGV diff -r ade4014aa895 -r 8fd81d0e3acf graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpHandler.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpHandler.java Wed Jul 11 15:38:28 2012 +0200 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpHandler.java Thu Jul 12 16:59:09 2012 +0200 @@ -22,6 +22,8 @@ */ package com.oracle.graal.debug; -public interface DebugDumpHandler { +import java.io.*; + +public interface DebugDumpHandler extends Closeable { void dump(Object object, String message); } diff -r ade4014aa895 -r 8fd81d0e3acf graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerThread.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerThread.java Wed Jul 11 15:38:28 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerThread.java Thu Jul 12 16:59:09 2012 +0200 @@ -56,12 +56,25 @@ @Override public void run() { + HotSpotDebugConfig hotspotDebugConfig = null; if (GraalOptions.Debug) { Debug.enable(); PrintStream log = HotSpotGraalRuntime.getInstance().getVMToCompiler().log(); - HotSpotDebugConfig hotspotDebugConfig = new HotSpotDebugConfig(GraalOptions.Log, GraalOptions.Meter, GraalOptions.Time, GraalOptions.Dump, GraalOptions.MethodFilter, log); + hotspotDebugConfig = new HotSpotDebugConfig(GraalOptions.Log, GraalOptions.Meter, GraalOptions.Time, GraalOptions.Dump, GraalOptions.MethodFilter, log); Debug.setConfig(hotspotDebugConfig); } - super.run(); + try { + super.run(); + } finally { + if (hotspotDebugConfig != null) { + for (DebugDumpHandler dumpHandler : hotspotDebugConfig.dumpHandlers()) { + try { + dumpHandler.close(); + } catch (Throwable t) { + + } + } + } + } } } diff -r ade4014aa895 -r 8fd81d0e3acf graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BasicIdealGraphPrinter.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BasicIdealGraphPrinter.java Wed Jul 11 15:38:28 2012 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BasicIdealGraphPrinter.java Thu Jul 12 16:59:09 2012 +0200 @@ -269,6 +269,10 @@ flush(); } + public void close() { + end(); + stream.close(); + } public boolean isValid() { return !stream.checkError(); diff -r ade4014aa895 -r 8fd81d0e3acf graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java Wed Jul 11 15:38:28 2012 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java Thu Jul 12 16:59:09 2012 +0200 @@ -99,8 +99,6 @@ private final ConstantPool constantPool; private final ByteBuffer buffer; private final WritableByteChannel channel; - private long bytes; - private long newPoolEntry; public BinaryGraphPrinter(WritableByteChannel channel) { constantPool = new ConstantPool(); @@ -109,9 +107,6 @@ } public void print(Graph graph, String title, SchedulePhase predefinedSchedule) throws IOException { - long startBytes = bytes; - long startTime = System.currentTimeMillis(); - long startPool = newPoolEntry; SchedulePhase schedule = predefinedSchedule; if (schedule == null) { try { @@ -128,15 +123,11 @@ writeNodes(graph); writeBlocks(blocks, blockToNodes); flush(); - long t = System.currentTimeMillis() - startTime; - long b = bytes - startBytes; - long pool = newPoolEntry - startPool; - System.out.println("Graph printed in " + t + " ms and " + b + " bytes, " + pool + " pool entries created (" + graph.getNodeCount() + " nodes)"); } private void flush() throws IOException { buffer.flip(); - bytes += channel.write(buffer); + channel.write(buffer); buffer.compact(); } @@ -251,7 +242,6 @@ } private void addPoolEntry(Object object) throws IOException { - newPoolEntry++; int index = constantPool.add(object); writeByte(POOL_NEW); writeInt(index); @@ -439,4 +429,10 @@ public void endGroup() throws IOException { writeByte(CLOSE_GROUP); } + + @Override + public void close() throws IOException { + flush(); + channel.close(); + } } diff -r ade4014aa895 -r 8fd81d0e3acf graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Wed Jul 11 15:38:28 2012 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Thu Jul 12 16:59:09 2012 +0200 @@ -192,4 +192,11 @@ } return false; } + + @Override + public void close() throws IOException { + if (cfgPrinter != null) { + cfgPrinter.close(); + } + } } diff -r ade4014aa895 -r 8fd81d0e3acf graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java Wed Jul 11 15:38:28 2012 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java Thu Jul 12 16:59:09 2012 +0200 @@ -36,7 +36,7 @@ * The output format is such that it can then be fed to the * C1 Visualizer. */ -public class CompilationPrinter { +public class CompilationPrinter implements Closeable { public static final String COLUMN_END = " <|@"; public static final String HOVER_START = "<@"; public static final String HOVER_SEP = "|@"; @@ -81,6 +81,11 @@ out.flush(); } + @Override + public void close() throws IOException { + out.out().close(); + } + protected void begin(String string) { out.println("begin_" + string); out.adjustIndentation(2); diff -r ade4014aa895 -r 8fd81d0e3acf graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinter.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinter.java Wed Jul 11 15:38:28 2012 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinter.java Thu Jul 12 16:59:09 2012 +0200 @@ -28,7 +28,7 @@ import com.oracle.graal.compiler.schedule.*; import com.oracle.graal.graph.*; -interface GraphPrinter { +interface GraphPrinter extends Closeable { /** * Starts a new group of graphs with the given name, short name and method byte code index (BCI) as properties. */ diff -r ade4014aa895 -r 8fd81d0e3acf graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java Wed Jul 11 15:38:28 2012 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java Thu Jul 12 16:59:09 2012 +0200 @@ -25,6 +25,7 @@ import java.io.*; import java.net.*; import java.nio.channels.*; +import java.nio.file.*; import java.text.*; import java.util.*; @@ -58,7 +59,7 @@ return; } previousInlineContext.clear(); - if (GraalOptions.PrintIdealGraphAddress == null) { + if (GraalOptions.PrintIdealGraphFile) { initializeFilePrinter(); } else { initializeNetworkPrinter(); @@ -67,21 +68,22 @@ } private void initializeFilePrinter() { + String ext; + if (GraalOptions.PrintBinaryGraphs) { + ext = ".bgv"; + } else { + ext = ".gv.xml"; + } + String fileName = "Graphs-" + Thread.currentThread().getName() + "-" + sdf.format(new Date()) + ext; try { - String ext; if (GraalOptions.PrintBinaryGraphs) { - ext = ".bgv"; - } else { - ext = ".gv.xml"; - } - String fileName = "Graphs-" + Thread.currentThread().getName() + "-" + sdf.format(new Date()) + ext; - if (GraalOptions.PrintBinaryGraphs) { - printer = new BinaryGraphPrinter(FileChannel.open(new File(fileName).toPath())); + printer = new BinaryGraphPrinter(FileChannel.open(new File(fileName).toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW)); } else { printer = new IdealGraphPrinter(new FileOutputStream(fileName)); } TTY.println("Dumping IGV graphs to %s", fileName); } catch (IOException e) { + TTY.println("Faild to open %s to dump IGV graphs : %s", fileName, e); failuresCount++; printer = null; } @@ -95,12 +97,11 @@ printer = new BinaryGraphPrinter(SocketChannel.open(new InetSocketAddress(host, port))); } else { IdealGraphPrinter xmlPrinter = new IdealGraphPrinter(new Socket(host, port).getOutputStream()); - xmlPrinter.begin(); printer = xmlPrinter; } TTY.println("Connected to the IGV on %s:%d", host, port); } catch (IOException e) { - TTY.println("Could not connect to the IGV on %s:%d: %s", host, port, e); + TTY.println("Could not connect to the IGV on %s:%d : %s", host, port, e); failuresCount++; printer = null; } @@ -198,4 +199,12 @@ printer = null; } } + + @Override + public void close() throws IOException { + for (int i = 0; i < previousInlineContext.size(); i++) { + closeScope(); + } + printer.close(); + } } diff -r ade4014aa895 -r 8fd81d0e3acf graal/com.oracle.graal.printer/src/com/oracle/graal/printer/IdealGraphPrinter.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/IdealGraphPrinter.java Wed Jul 11 15:38:28 2012 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/IdealGraphPrinter.java Thu Jul 12 16:59:09 2012 +0200 @@ -46,6 +46,7 @@ */ public IdealGraphPrinter(OutputStream stream) { super(stream); + this.begin(); } /** diff -r ade4014aa895 -r 8fd81d0e3acf 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 Wed Jul 11 15:38:28 2012 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.java Thu Jul 12 16:59:09 2012 +0200 @@ -23,7 +23,6 @@ */ package com.sun.hotspot.igv.coordinator; -import com.sun.hotspot.igv.connection.BinaryServer; import com.sun.hotspot.igv.connection.Server; import com.sun.hotspot.igv.coordinator.actions.*; import com.sun.hotspot.igv.data.GraphDocument; @@ -62,7 +61,7 @@ private GraphDocument document; private FolderNode root; private Server server; - private BinaryServer binaryServer; + private Server binaryServer; private OutlineTopComponent() { initComponents(); @@ -117,8 +116,8 @@ } }; - server = new Server(callback); - binaryServer = new BinaryServer(callback); + server = new Server(callback, false); + binaryServer = new Server(callback, true); } public void clear() { diff -r ade4014aa895 -r 8fd81d0e3acf src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/ImportAction.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/ImportAction.java Wed Jul 11 15:38:28 2012 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/ImportAction.java Thu Jul 12 16:59:09 2012 +0200 @@ -26,15 +26,18 @@ import com.sun.hotspot.igv.coordinator.OutlineTopComponent; import com.sun.hotspot.igv.data.GraphDocument; +import com.sun.hotspot.igv.data.serialization.BinaryParser; +import com.sun.hotspot.igv.data.serialization.GraphParser; +import com.sun.hotspot.igv.data.serialization.ParseMonitor; import com.sun.hotspot.igv.data.serialization.Parser; -import com.sun.hotspot.igv.data.serialization.XMLParser; import com.sun.hotspot.igv.settings.Settings; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.channels.FileChannel; +import java.nio.file.StandardOpenOption; import javax.swing.Action; import javax.swing.JFileChooser; import javax.swing.KeyStroke; @@ -42,32 +45,30 @@ import javax.swing.filechooser.FileFilter; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; +import org.openide.util.Exceptions; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; import org.openide.util.actions.CallableSystemAction; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; /** * * @author Thomas Wuerthinger */ public final class ImportAction extends CallableSystemAction { + private static final int WORKUNITS = 10000; public static FileFilter getFileFilter() { return new FileFilter() { @Override public boolean accept(File f) { - return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory(); + return f.getName().toLowerCase().endsWith(".xml") || f.getName().toLowerCase().endsWith(".bgv") || f.isDirectory(); } @Override public String getDescription() { - return "XML files (*.xml)"; + return "Graph files (*.xml, *.bgv)"; } }; } @@ -88,71 +89,59 @@ } Settings.get().put(Settings.DIRECTORY, dir.getAbsolutePath()); - try { - final FileInputStream inputStream = new FileInputStream(file); - final InputSource is = new InputSource(inputStream); - + final FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.READ); final ProgressHandle handle = ProgressHandleFactory.createHandle("Opening file " + file.getName()); - final int basis = 1000; - handle.start(basis); - final int start = inputStream.available(); - - final XMLParser.ParseMonitor parseMonitor = new XMLParser.ParseMonitor() { - + handle.start(WORKUNITS); + final long start = channel.size(); + ParseMonitor monitor = new ParseMonitor() { @Override - public void setProgress(double d) { + public void updateProgress() { try { - int curAvailable = inputStream.available(); - int prog = (int) (basis * (double) (start - curAvailable) / (double) start); + int prog = (int) (WORKUNITS * (double) channel.position() / (double) start); handle.progress(prog); } catch (IOException ex) { } } - @Override public void setState(String state) { - setProgress(0.0); + updateProgress(); handle.progress(state); } }; - final Parser parser = new Parser(); + final GraphParser parser; + if (file.getName().endsWith(".xml")) { + parser = new Parser(channel, monitor, null); + } else if (file.getName().endsWith(".bgv")) { + parser = new BinaryParser(channel, monitor, null); + } else { + parser = null; + } final OutlineTopComponent component = OutlineTopComponent.findInstance(); - - component.requestActive(); - RequestProcessor.getDefault().post(new Runnable() { - @Override public void run() { try { - final GraphDocument document = parser.parse(is, parseMonitor); - parseMonitor.setState("Finishing"); - SwingUtilities.invokeLater(new Runnable(){ - - @Override - public void run() { - component.getDocument().addGraphDocument(document); - } - }); - } catch (SAXException ex) { - String s = "Exception during parsing the XML file, could not load document!"; - if (ex instanceof XMLParser.MissingAttributeException) { - XMLParser.MissingAttributeException e = (XMLParser.MissingAttributeException) ex; - s += "\nMissing attribute \"" + e.getAttributeName() + "\""; + final GraphDocument document = parser.parse(); + if (document != null) { + SwingUtilities.invokeLater(new Runnable(){ + @Override + public void run() { + component.requestActive(); + component.getDocument().addGraphDocument(document); + } + }); } - ex.printStackTrace(); - NotifyDescriptor d = new NotifyDescriptor.Message(s, NotifyDescriptor.ERROR_MESSAGE); - DialogDisplayer.getDefault().notify(d); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); } handle.finish(); } }); - } catch (FileNotFoundException ex) { - ex.printStackTrace(); + Exceptions.printStackTrace(ex); } catch (IOException ex) { - ex.printStackTrace(); + Exceptions.printStackTrace(ex); } } } diff -r ade4014aa895 -r 8fd81d0e3acf src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java Wed Jul 11 15:38:28 2012 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java Thu Jul 12 16:59:09 2012 +0200 @@ -1,6 +1,26 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (c) 2012, 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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.serialization; @@ -16,11 +36,7 @@ import java.util.regex.Pattern; import javax.swing.SwingUtilities; -/** - * - * @author gd - */ -public class BinaryParser { +public class BinaryParser implements GraphParser { private static final int BEGIN_GROUP = 0x00; private static final int BEGIN_GRAPH = 0x01; private static final int CLOSE_GROUP = 0x02; @@ -49,11 +65,12 @@ private static final String NO_BLOCK = "noBlock"; - private GroupCallback callback; - private List constantPool; + private final GroupCallback callback; + private final List constantPool; private final ByteBuffer buffer; private final ReadableByteChannel channel; - private Deque folderStack; + private final Deque folderStack; + private final ParseMonitor monitor; private enum Length { S, @@ -223,13 +240,14 @@ } } - public BinaryParser(GroupCallback callback, ReadableByteChannel channel) { + public BinaryParser(ReadableByteChannel channel, ParseMonitor monitor, GroupCallback callback) { this.callback = callback; constantPool = new ArrayList<>(); buffer = ByteBuffer.allocateDirect(256 * 1024); buffer.flip(); this.channel = channel; folderStack = new LinkedList<>(); + this.monitor = monitor; } private void fill() throws IOException { @@ -507,8 +525,12 @@ } } - public void parse() throws IOException { - folderStack.push(new GraphDocument()); + public GraphDocument parse() throws IOException { + GraphDocument doc = new GraphDocument(); + folderStack.push(doc); + if (monitor != null) { + monitor.setState("Starting parsing"); + } try { while(true) { parseRoot(); @@ -516,6 +538,10 @@ } catch (EOFException e) { } + if (monitor != null) { + monitor.setState("Finished parsing"); + } + return doc; } private void parseRoot() throws IOException { @@ -564,6 +590,9 @@ private Group parseGroup(Folder parent) throws IOException { String name = readPoolObject(String.class); String shortName = readPoolObject(String.class); + if (monitor != null) { + monitor.setState(shortName); + } Method method = readPoolObject(Method.class); int bci = readInt(); Group group = new Group(parent); @@ -577,6 +606,9 @@ } private InputGraph parseGraph() throws IOException { + if (monitor != null) { + monitor.updateProgress(); + } String title = readPoolObject(String.class); InputGraph graph = new InputGraph(title); parseNodes(graph); diff -r ade4014aa895 -r 8fd81d0e3acf src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/GraphParser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/GraphParser.java Thu Jul 12 16:59:09 2012 +0200 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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.serialization; + +import com.sun.hotspot.igv.data.GraphDocument; +import java.io.IOException; + +public interface GraphParser { + public GraphDocument parse() throws IOException; +} diff -r ade4014aa895 -r 8fd81d0e3acf src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/ParseMonitor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/ParseMonitor.java Thu Jul 12 16:59:09 2012 +0200 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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.serialization; + +public interface ParseMonitor { + + public void updateProgress(); + + public void setState(String state); + +} diff -r ade4014aa895 -r 8fd81d0e3acf 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 Wed Jul 11 15:38:28 2012 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java Thu Jul 12 16:59:09 2012 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2012, 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 @@ -26,11 +26,12 @@ import com.sun.hotspot.igv.data.*; import com.sun.hotspot.igv.data.serialization.XMLParser.ElementHandler; import com.sun.hotspot.igv.data.serialization.XMLParser.HandoverElementHandler; -import com.sun.hotspot.igv.data.serialization.XMLParser.ParseMonitor; import com.sun.hotspot.igv.data.serialization.XMLParser.TopElementHandler; import com.sun.hotspot.igv.data.services.GroupCallback; import java.io.IOException; import java.io.InputStream; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -42,13 +43,14 @@ import javax.xml.validation.SchemaFactory; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; /** * * @author Thomas Wuerthinger */ -public class Parser { +public class Parser implements GraphParser { public static final String INDENT = " "; public static final String TOP_ELEMENT = "graphDocument"; @@ -99,6 +101,8 @@ private ArrayList> blockConnections = new ArrayList<>(); private int maxId = 0; private GraphDocument graphDocument; + private final ParseMonitor monitor; + private final ReadableByteChannel channel; private int lookupID(String i) { try { @@ -217,6 +221,10 @@ } } } + ParseMonitor monitor = getMonitor(); + if (monitor != null) { + monitor.updateProgress(); + } return curGraph; } @@ -460,13 +468,15 @@ } }; - public Parser() { - this(null); + public Parser(ReadableByteChannel channel) { + this(channel, null, null); } - public Parser(GroupCallback groupCallback) { + public Parser(ReadableByteChannel channel, ParseMonitor monitor, GroupCallback groupCallback) { this.groupCallback = groupCallback; + this.monitor = monitor; + this.channel = channel; // Initialize dependencies xmlDocument.addChild(topHandler); @@ -510,16 +520,23 @@ } // Returns a new GraphDocument object deserialized from an XML input source. - public GraphDocument parse(InputSource source, XMLParser.ParseMonitor monitor) throws SAXException { - XMLReader reader = createReader(); - - reader.setContentHandler(new XMLParser(xmlDocument, monitor)); + @Override + public GraphDocument parse() throws IOException { + if (monitor != null) { + monitor.setState("Starting parsing"); + } try { - reader.parse(source); - } catch (IOException ex) { - throw new SAXException(ex); + XMLReader reader = createReader(); + reader.setContentHandler(new XMLParser(xmlDocument, monitor)); + reader.parse(new InputSource(Channels.newInputStream(channel))); + } catch (SAXException ex) { + if (!(ex instanceof SAXParseException) || !"XML document structures must start and end within the same entity.".equals(ex.getMessage())) { + throw new IOException(ex); + } } - + if (monitor != null) { + monitor.setState("Finished parsing"); + } return graphDocument; } diff -r ade4014aa895 -r 8fd81d0e3acf 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 Wed Jul 11 15:38:28 2012 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java Thu Jul 12 16:59:09 2012 +0200 @@ -37,13 +37,6 @@ */ public class XMLParser implements ContentHandler { - public static interface ParseMonitor { - - public void setProgress(double d); - - public void setState(String state); - } - public static class MissingAttributeException extends SAXException { private String name; @@ -197,9 +190,7 @@ @Override public void setDocumentLocator(Locator locator) { - if (monitor != null) { - monitor.setState("Starting parsing"); - } + } @Override diff -r ade4014aa895 -r 8fd81d0e3acf src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/graphdocument.xsd --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/graphdocument.xsd Wed Jul 11 15:38:28 2012 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/graphdocument.xsd Thu Jul 12 16:59:09 2012 +0200 @@ -15,7 +15,10 @@ - + + + + diff -r ade4014aa895 -r 8fd81d0e3acf src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/serialization/ParserTest.java --- a/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/serialization/ParserTest.java Wed Jul 11 15:38:28 2012 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/serialization/ParserTest.java Thu Jul 12 16:59:09 2012 +0200 @@ -26,11 +26,12 @@ package com.sun.hotspot.igv.data.serialization; import com.sun.hotspot.igv.data.*; -import java.io.CharArrayWriter; -import java.io.StringReader; +import java.io.*; +import java.nio.channels.Channels; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.*; +import org.openide.util.Exceptions; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -67,16 +68,17 @@ } private void test(GraphDocument document, String xmlString) { - - StringReader sr = new StringReader(xmlString); - InputSource is = new InputSource(sr); - try { - Parser parser = new Parser(); - final GraphDocument parsedDocument = parser.parse(is, null); - Util.assertGraphDocumentEquals(document, parsedDocument); - } catch (SAXException ex) { - fail(ex.toString()); + InputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8")); + try { + Parser parser = new Parser(Channels.newChannel(in)); + final GraphDocument parsedDocument = parser.parse(); + Util.assertGraphDocumentEquals(document, parsedDocument); + } catch (SAXException ex) { + fail(ex.toString()); + } + } catch (UnsupportedEncodingException ex) { + Exceptions.printStackTrace(ex); } } diff -r ade4014aa895 -r 8fd81d0e3acf src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/BinaryClient.java --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/BinaryClient.java Wed Jul 11 15:38:28 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Copyright (c) 1998, 2007, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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.connection; - -import com.sun.hotspot.igv.data.serialization.BinaryParser; -import com.sun.hotspot.igv.data.services.GroupCallback; -import java.io.IOException; -import java.nio.channels.SocketChannel; -import org.openide.util.Exceptions; - -/** - * - * @author Thomas Wuerthinger - */ -public class BinaryClient implements Runnable { - - private SocketChannel socket; - private GroupCallback callback; - - public BinaryClient(SocketChannel socket, GroupCallback callback) { - this.callback = callback; - this.socket = socket; - } - - @Override - public void run() { - - try { - final SocketChannel channel = socket; - channel.configureBlocking(true); - new BinaryParser(callback, channel).parse(); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } finally { - try { - socket.close(); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - } - } -} \ No newline at end of file diff -r ade4014aa895 -r 8fd81d0e3acf src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/BinaryServer.java --- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/BinaryServer.java Wed Jul 11 15:38:28 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -/* - * Copyright (c) 1998, 2007, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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.connection; - -import com.sun.hotspot.igv.data.services.GroupCallback; -import com.sun.hotspot.igv.settings.Settings; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketAddress; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.SocketChannel; -import java.util.prefs.PreferenceChangeEvent; -import java.util.prefs.PreferenceChangeListener; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; -import org.openide.util.RequestProcessor; - -/** - * - * @author Thomas Wuerthinger - */ -public class BinaryServer implements PreferenceChangeListener { - - private ServerSocketChannel serverSocket; - private GroupCallback callback; - private int port; - private Runnable serverRunnable; - - public BinaryServer(GroupCallback callback) { - - this.callback = callback; - initializeNetwork(); - Settings.get().addPreferenceChangeListener(this); - } - - @Override - public void preferenceChange(PreferenceChangeEvent e) { - - int curPort = Integer.parseInt(Settings.get().get(Settings.PORT_BINARY, Settings.PORT_BINARY_DEFAULT)); - if (curPort != port) { - initializeNetwork(); - } - } - - private void initializeNetwork() { - - int curPort = Integer.parseInt(Settings.get().get(Settings.PORT_BINARY, Settings.PORT_BINARY_DEFAULT)); - this.port = curPort; - try { - serverSocket = ServerSocketChannel.open(); - serverSocket.bind(new InetSocketAddress(curPort)); - } catch (IOException ex) { - NotifyDescriptor message = new NotifyDescriptor.Message("Could not create server. Listening for incoming binary data is disabled.", NotifyDescriptor.ERROR_MESSAGE); - DialogDisplayer.getDefault().notifyLater(message); - return; - } - - Runnable runnable = new Runnable() { - - @Override - public void run() { - while (true) { - try { - SocketChannel clientSocket = serverSocket.accept(); - if (serverRunnable != this) { - clientSocket.close(); - return; - } - RequestProcessor.getDefault().post(new BinaryClient(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 binary data is disabled.", NotifyDescriptor.ERROR_MESSAGE); - DialogDisplayer.getDefault().notifyLater(message); - return; - } - } - } - }; - - serverRunnable = runnable; - - RequestProcessor.getDefault().post(runnable, 0, Thread.MAX_PRIORITY); - } -} diff -r ade4014aa895 -r 8fd81d0e3acf 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 Wed Jul 11 15:38:28 2012 +0200 +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java Thu Jul 12 16:59:09 2012 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2012, 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 @@ -24,42 +24,34 @@ */ package com.sun.hotspot.igv.connection; +import com.sun.hotspot.igv.data.serialization.BinaryParser; import com.sun.hotspot.igv.data.serialization.Parser; import com.sun.hotspot.igv.data.services.GroupCallback; -import java.io.BufferedInputStream; import java.io.IOException; -import java.io.InputStream; -import java.net.Socket; +import java.nio.channels.SocketChannel; import org.openide.util.Exceptions; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -/** - * - * @author Thomas Wuerthinger - */ public class Client implements Runnable { + private final boolean binary; + private final SocketChannel socket; + private final GroupCallback callback; - private Socket socket; - private GroupCallback callback; - - public Client(Socket socket, GroupCallback callback) { + public Client(SocketChannel socket, GroupCallback callback, boolean binary) { this.callback = callback; this.socket = socket; + this.binary = binary; } @Override public void run() { try { - InputStream inputStream = new BufferedInputStream(socket.getInputStream()); - InputSource is = new InputSource(inputStream); - - try { - Parser parser = new Parser(callback); - parser.parse(is, null); - } catch (SAXException ex) { - ex.printStackTrace(); + final SocketChannel channel = socket; + channel.configureBlocking(true); + if (binary) { + new BinaryParser(channel, null, callback).parse(); + } else { + new Parser(channel, null, callback).parse(); } } catch (IOException ex) { Exceptions.printStackTrace(ex); diff -r ade4014aa895 -r 8fd81d0e3acf 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 Wed Jul 11 15:38:28 2012 +0200 +++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java Thu Jul 12 16:59:09 2012 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2012, 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 @@ -27,8 +27,9 @@ import com.sun.hotspot.igv.data.services.GroupCallback; import com.sun.hotspot.igv.settings.Settings; import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; +import java.net.InetSocketAddress; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; import java.util.prefs.PreferenceChangeEvent; import java.util.prefs.PreferenceChangeListener; import org.openide.DialogDisplayer; @@ -40,14 +41,14 @@ * @author Thomas Wuerthinger */ public class Server implements PreferenceChangeListener { - - private ServerSocket serverSocket; - private GroupCallback callback; + private final boolean binary; + private ServerSocketChannel serverSocket; + private final GroupCallback callback; private int port; private Runnable serverRunnable; - public Server(GroupCallback callback) { - + public Server(GroupCallback callback, boolean binary) { + this.binary = binary; this.callback = callback; initializeNetwork(); Settings.get().addPreferenceChangeListener(this); @@ -56,7 +57,7 @@ @Override public void preferenceChange(PreferenceChangeEvent e) { - int curPort = Integer.parseInt(Settings.get().get(Settings.PORT, Settings.PORT_DEFAULT)); + int curPort = Integer.parseInt(Settings.get().get(binary ? Settings.PORT_BINARY : Settings.PORT, binary ? Settings.PORT_BINARY_DEFAULT : Settings.PORT_DEFAULT)); if (curPort != port) { initializeNetwork(); } @@ -64,12 +65,13 @@ private void initializeNetwork() { - int curPort = Integer.parseInt(Settings.get().get(Settings.PORT, Settings.PORT_DEFAULT)); + int curPort = Integer.parseInt(Settings.get().get(binary ? Settings.PORT_BINARY : Settings.PORT, binary ? Settings.PORT_BINARY_DEFAULT : Settings.PORT_DEFAULT)); this.port = curPort; try { - serverSocket = new java.net.ServerSocket(curPort); + serverSocket = ServerSocketChannel.open(); + serverSocket.bind(new InetSocketAddress(curPort)); } catch (IOException ex) { - NotifyDescriptor message = new NotifyDescriptor.Message("Could not create server. Listening for incoming data is disabled.", NotifyDescriptor.ERROR_MESSAGE); + NotifyDescriptor message = new NotifyDescriptor.Message("Could not create server. Listening for incoming binary data is disabled.", NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notifyLater(message); return; } @@ -80,15 +82,15 @@ public void run() { while (true) { try { - Socket clientSocket = serverSocket.accept(); + SocketChannel clientSocket = serverSocket.accept(); if (serverRunnable != this) { clientSocket.close(); return; } - RequestProcessor.getDefault().post(new Client(clientSocket, callback), 0, Thread.MAX_PRIORITY); + RequestProcessor.getDefault().post(new Client(clientSocket, callback, binary), 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); + NotifyDescriptor message = new NotifyDescriptor.Message("Error during listening for incoming connections. Listening for incoming binary data is disabled.", NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notifyLater(message); return; }