changeset 5825:4c92e2b43789

Merge.
author Doug Simon <doug.simon@oracle.com>
date Fri, 13 Jul 2012 11:40:41 +0200
parents b1dc8fbebb48 (current diff) 547587296886 (diff)
children 0c1358dee8c7
files src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/BinaryClient.java src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/BinaryServer.java src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java
diffstat 33 files changed, 430 insertions(+), 351 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Jul 13 09:06:14 2012 +0200
+++ b/.hgignore	Fri Jul 13 11:40:41 2012 +0200
@@ -55,3 +55,5 @@
 ^.hgtip
 .DS_Store
 javadoc/
+syntax: glob
+*.bgv
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/ReadEliminationPhase.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/ReadEliminationPhase.java	Fri Jul 13 11:40:41 2012 +0200
@@ -22,26 +22,84 @@
  */
 package com.oracle.graal.compiler.phases;
 
+import java.util.*;
+
 import com.oracle.graal.debug.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.PhiNode.PhiType;
 import com.oracle.graal.nodes.extended.*;
 
 public class ReadEliminationPhase extends Phase {
+    private Queue<PhiNode> newPhis;
 
     @Override
     protected void run(StructuredGraph graph) {
+        newPhis = new LinkedList<>();
         for (FloatingReadNode n : graph.getNodes(FloatingReadNode.class)) {
-            if (n.lastLocationAccess() != null) {
-                Node memoryInput = n.lastLocationAccess();
-                if (memoryInput instanceof WriteNode) {
-                    WriteNode other = (WriteNode) memoryInput;
-                    if (other.object() == n.object() && other.location() == n.location()) {
-                        Debug.log("Eliminated memory read %1.1s and replaced with node %s", n, other.value());
-                        graph.replaceFloating(n, other.value());
-                    }
+            if (isReadEliminable(n)) {
+                NodeMap<ValueNode> nodeMap = n.graph().createNodeMap();
+                ValueNode value = getValue(n.lastLocationAccess(), nodeMap);
+                Debug.log("Eliminated memory read %1.1s and replaced with node %s", n, value);
+                graph.replaceFloating(n, value);
+            }
+        }
+        // get a proper stamp for the new phis
+        while (!newPhis.isEmpty()) {
+            PhiNode phi = newPhis.poll();
+            if (phi.inferStamp()) {
+                for (PhiNode usagePhi : phi.usages().filter(PhiNode.class)) {
+                    newPhis.add(usagePhi);
                 }
             }
         }
     }
+
+    private boolean isReadEliminable(FloatingReadNode n) {
+        return isWrites(n, n.lastLocationAccess(), n.graph().createNodeBitMap());
+    }
+
+    private boolean isWrites(FloatingReadNode n, Node lastLocationAccess, NodeBitMap visited) {
+        if (lastLocationAccess == null) {
+            return false;
+        }
+        if (visited.isMarked(lastLocationAccess)) {
+            return true; // dataflow loops must come from Phis assume them ok until proven wrong
+        }
+        if (lastLocationAccess instanceof WriteNode) {
+            WriteNode other = (WriteNode) lastLocationAccess;
+            return other.object() == n.object() && other.location() == n.location();
+        }
+        if (lastLocationAccess instanceof PhiNode) {
+            visited.mark(lastLocationAccess);
+            for (ValueNode value : ((PhiNode) lastLocationAccess).values()) {
+                if (!isWrites(n, value, visited)) {
+                    return false;
+                }
+            }
+            return true;
+        }
+        return false;
+    }
+
+    private ValueNode getValue(Node lastLocationAccess, NodeMap<ValueNode> nodeMap) {
+        ValueNode exisiting = nodeMap.get(lastLocationAccess);
+        if (exisiting != null) {
+            return exisiting;
+        }
+        if (lastLocationAccess instanceof WriteNode) {
+            return ((WriteNode) lastLocationAccess).value();
+        }
+        if (lastLocationAccess instanceof PhiNode) {
+            PhiNode phi = (PhiNode) lastLocationAccess;
+            PhiNode newPhi = phi.graph().add(new PhiNode(PhiType.Value, phi.merge()));
+            nodeMap.set(lastLocationAccess, newPhi);
+            for (ValueNode value : phi.values()) {
+                newPhi.addInput(getValue(value, nodeMap));
+            }
+            newPhis.add(newPhi);
+            return newPhi;
+        }
+        throw GraalInternalError.shouldNotReachHere();
+    }
 }
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpHandler.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpHandler.java	Fri Jul 13 11:40:41 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);
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerThread.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerThread.java	Fri Jul 13 11:40:41 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) {
+
+                    }
+                }
+            }
+        }
     }
 }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java	Fri Jul 13 11:40:41 2012 +0200
@@ -36,7 +36,7 @@
 public final class PhiNode extends FloatingNode implements Canonicalizable, Node.IterableNodeType {
 
     public static enum PhiType {
-        Value(null), // normal value phis
+        Value(StampFactory.top()), // normal value phis
         Memory(StampFactory.dependency());
 
         public final Stamp stamp;
@@ -62,7 +62,9 @@
     }
 
     /**
-     * Create a non-value phi ({@link PhiType#Memory} with the specified kind.
+     * Create a phi with the specified {@link PhiType}.
+     * If you use this to create a {@link PhiType#Value value} phi, its {@link Kind kind} will originally be {@link Kind#Void void} ;
+     * use {@link PhiNode#inferStamp()} to update it when it has valid inputs.
      * @param type the type of the new phi
      * @param merge the merge that the new phi belongs to
      */
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ValueNode.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ValueNode.java	Fri Jul 13 11:40:41 2012 +0200
@@ -55,19 +55,16 @@
     public ValueNode(Stamp stamp) {
         this.stamp = stamp;
         this.dependencies = new NodeInputList<>(this);
-        assert kind() != null && kind() == kind().stackKind() : kind() + " != " + kind().stackKind();
     }
 
     public ValueNode(Stamp stamp, ValueNode... dependencies) {
         this.stamp = stamp;
         this.dependencies = new NodeInputList<>(this, dependencies);
-        assert kind() != null && kind() == kind().stackKind() : kind() + " != " + kind().stackKind();
     }
 
     public ValueNode(Stamp stamp, List<ValueNode> dependencies) {
         this.stamp = stamp;
         this.dependencies = new NodeInputList<>(this, dependencies);
-        assert kind() != null && kind() == kind().stackKind() : kind() + " != " + kind().stackKind();
     }
 
     public Stamp stamp() {
@@ -176,6 +173,8 @@
         for (ValueNode v : dependencies().nonNull()) {
             assertTrue(!(v.stamp() instanceof GenericStamp) || ((GenericStamp) v.stamp()).type() == GenericStampType.Dependency, "cannot depend on node with stamp %s", v.stamp());
         }
+        assertTrue(kind() != null, "Should have a valid kind");
+        assertTrue(kind() == kind().stackKind(), "Should have a stack kind : %s", kind());
         return super.verify();
     }
 
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/FloatStamp.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/FloatStamp.java	Fri Jul 13 11:40:41 2012 +0200
@@ -91,6 +91,9 @@
 
     @Override
     public Stamp meet(Stamp otherStamp) {
+        if (otherStamp == StampFactory.top()) {
+            return this;
+        }
         FloatStamp other = (FloatStamp) otherStamp;
         assert kind() == other.kind();
         double meetUpperBound = Math.max(upperBound, other.upperBound);
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/GenericStamp.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/GenericStamp.java	Fri Jul 13 11:40:41 2012 +0200
@@ -53,6 +53,9 @@
 
     @Override
     public Stamp meet(Stamp other) {
+        if (other == StampFactory.top()) {
+            return this;
+        }
         assert ((GenericStamp) other).type == type;
         return this;
     }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/IntegerStamp.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/IntegerStamp.java	Fri Jul 13 11:40:41 2012 +0200
@@ -104,6 +104,9 @@
 
     @Override
     public Stamp meet(Stamp otherStamp) {
+        if (otherStamp == StampFactory.top()) {
+            return this;
+        }
         IntegerStamp other = (IntegerStamp) otherStamp;
         assert kind() == other.kind();
         long meetUpperBound = Math.max(upperBound, other.upperBound);
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/ObjectStamp.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/ObjectStamp.java	Fri Jul 13 11:40:41 2012 +0200
@@ -75,6 +75,9 @@
 
     @Override
     public Stamp meet(Stamp otherStamp) {
+        if (otherStamp == StampFactory.top()) {
+            return this;
+        }
         ObjectStamp other = (ObjectStamp) otherStamp;
         ResolvedJavaType orType = meetTypes(type(), other.type());
         boolean meetExactType = orType == type && orType == other.type && exactType && other.exactType;
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampFactory.java	Fri Jul 13 11:40:41 2012 +0200
@@ -28,7 +28,7 @@
 
 
 public class StampFactory {
-
+    private static final TopStamp top = new TopStamp();
     private static final Stamp[] stampCache = new Stamp[Kind.values().length];
     private static final Stamp objectStamp = new ObjectStamp(null, false, false);
     private static final Stamp objectNonNullStamp = new ObjectStamp(null, false, true);
@@ -98,6 +98,10 @@
         return positiveInt;
     }
 
+    public static Stamp top() {
+        return top;
+    }
+
     public static Stamp forInteger(Kind kind, long lowerBound, long upperBound, long mask) {
         return new IntegerStamp(kind, lowerBound, upperBound, mask);
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/TopStamp.java	Fri Jul 13 11:40:41 2012 +0200
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 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.
+ *
+ * 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.oracle.graal.nodes.type;
+
+
+public final class TopStamp extends Stamp {
+
+    TopStamp() {
+        super(null);
+    }
+
+    @Override
+    public boolean alwaysDistinct(Stamp other) {
+        return false;
+    }
+
+    @Override
+    public Stamp meet(Stamp other) {
+        return other;
+    }
+
+}
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/WordStamp.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/WordStamp.java	Fri Jul 13 11:40:41 2012 +0200
@@ -56,6 +56,9 @@
 
     @Override
     public Stamp meet(Stamp otherStamp) {
+        if (otherStamp == StampFactory.top()) {
+            return this;
+        }
         WordStamp other = (WordStamp) otherStamp;
         if (other.nonNull == nonNull) {
             return this;
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BasicIdealGraphPrinter.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BasicIdealGraphPrinter.java	Fri Jul 13 11:40:41 2012 +0200
@@ -269,6 +269,10 @@
         flush();
     }
 
+    public void close() {
+        end();
+        stream.close();
+    }
 
     public boolean isValid() {
         return !stream.checkError();
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Fri Jul 13 11:40:41 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();
+    }
 }
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java	Fri Jul 13 11:40:41 2012 +0200
@@ -192,4 +192,11 @@
         }
         return false;
     }
+
+    @Override
+    public void close() throws IOException {
+        if (cfgPrinter != null) {
+            cfgPrinter.close();
+        }
+    }
 }
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CompilationPrinter.java	Fri Jul 13 11:40:41 2012 +0200
@@ -36,7 +36,7 @@
  * The output format is such that it can then be fed to the
  * <a href="https://c1visualizer.dev.java.net/">C1 Visualizer</a>.
  */
-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);
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinter.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinter.java	Fri Jul 13 11:40:41 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.
      */
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java	Fri Jul 13 11:40:41 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();
+    }
 }
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/IdealGraphPrinter.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/IdealGraphPrinter.java	Fri Jul 13 11:40:41 2012 +0200
@@ -46,6 +46,7 @@
      */
     public IdealGraphPrinter(OutputStream stream) {
         super(stream);
+        this.begin();
     }
 
     /**
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/OutlineTopComponent.java	Fri Jul 13 11:40:41 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() {
--- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/ImportAction.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/ImportAction.java	Fri Jul 13 11:40:41 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);
             }
         }
     }
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java	Fri Jul 13 11:40:41 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<Object> constantPool;
+    private final GroupCallback callback;
+    private final List<Object> constantPool;
     private final ByteBuffer buffer;
     private final ReadableByteChannel channel;
-    private Deque<Folder> folderStack;
+    private final Deque<Folder> 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);
--- /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	Fri Jul 13 11:40:41 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;
+}
--- /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	Fri Jul 13 11:40:41 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);
+    
+}
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java	Fri Jul 13 11:40:41 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<Pair<String, String>> 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;
     }
 
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java	Fri Jul 13 11:40:41 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
--- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/graphdocument.xsd	Fri Jul 13 09:06:14 2012 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/graphdocument.xsd	Fri Jul 13 11:40:41 2012 +0200
@@ -15,7 +15,10 @@
             <xsd:element name="properties" type="propertiesType" minOccurs="0" maxOccurs="1" />
             <xsd:element name="assembly" type="assemblyType" minOccurs="0" maxOccurs="1" />
             <xsd:element name="method" type="methodType" minOccurs="0" maxOccurs="1" />
-            <xsd:element name="graph" type="graphType" minOccurs="0" maxOccurs="unbounded" />
+            <xsd:choice minOccurs="0" maxOccurs="unbounded" >
+                <xsd:element name="graph" type="graphType" />
+                <xsd:element name="group" type="groupType" />
+            </xsd:choice>
         </xsd:sequence>
         <xsd:attribute name="difference" use="optional" />
     </xsd:complexType>
--- a/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/serialization/ParserTest.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/serialization/ParserTest.java	Fri Jul 13 11:40:41 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);
         }
     }
 
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/BinaryClient.java	Fri Jul 13 09:06:14 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
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/BinaryServer.java	Fri Jul 13 09:06:14 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);
-    }
-}
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Client.java	Fri Jul 13 11:40:41 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);
--- a/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java	Fri Jul 13 09:06:14 2012 +0200
+++ b/src/share/tools/IdealGraphVisualizer/NetworkConnection/src/com/sun/hotspot/igv/connection/Server.java	Fri Jul 13 11:40:41 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;
                     }