();
+
+ if (previous != null) {
+ for (InputEdge e : previous.getEdges()) {
+ if (graph.getEdges().contains(e)) {
+ equalEdges.add(e);
+ } else {
+ removedEdges.add(e);
+ }
+ }
+ }
+
+ if (difference) {
+ for (InputEdge e : removedEdges) {
+ writer.simpleTag(Parser.REMOVE_EDGE_ELEMENT, createProperties(e));
+ }
+ }
+
+ for (InputEdge e : graph.getEdges()) {
+ if (!difference || !equalEdges.contains(e)) {
+ if (!equalEdges.contains(e)) {
+ writer.simpleTag(Parser.EDGE_ELEMENT, createProperties(e));
+ }
+ }
+ }
+
+ writer.endTag();
+
+ writer.startTag(Parser.CONTROL_FLOW_ELEMENT);
+ for (InputBlock b : graph.getBlocks()) {
+
+ writer.startTag(Parser.BLOCK_ELEMENT, new Properties(Parser.BLOCK_NAME_PROPERTY, b.getName()));
+
+ writer.startTag(Parser.SUCCESSORS_ELEMENT);
+ for (InputBlock s : b.getSuccessors()) {
+ writer.simpleTag(Parser.SUCCESSOR_ELEMENT, new Properties(Parser.BLOCK_NAME_PROPERTY, s.getName()));
+ }
+ writer.endTag();
+
+ writer.startTag(Parser.NODES_ELEMENT);
+ for (InputNode n : b.getNodes()) {
+ writer.simpleTag(Parser.NODE_ELEMENT, new Properties(Parser.NODE_ID_PROPERTY, n.getId() + ""));
+ }
+ writer.endTag();
+
+ writer.endTag();
+
+ }
+
+ writer.endTag();
+ writer.endTag();
+ }
+
+ private void export(XMLWriter w, InputMethod method) throws IOException {
+
+ w.startTag(Parser.METHOD_ELEMENT, new Properties(Parser.METHOD_BCI_PROPERTY, method.getBci() + "", Parser.METHOD_NAME_PROPERTY, method.getName(), Parser.METHOD_SHORT_NAME_PROPERTY, method.getShortName()));
+
+ w.writeProperties(method.getProperties());
+
+ if (method.getInlined().size() > 0) {
+ w.startTag(Parser.INLINE_ELEMENT);
+ for (InputMethod m : method.getInlined()) {
+ export(w, m);
+ }
+ w.endTag();
+ }
+
+ w.startTag(Parser.BYTECODES_ELEMENT);
+
+ StringBuilder b = new StringBuilder();
+ b.append("");
+ w.write(b.toString());
+ w.endTag();
+ w.endTag();
+ }
+
+ private Properties createProperties(InputEdge edge) {
+ Properties p = new Properties();
+ p.setProperty(Parser.TO_INDEX_PROPERTY, Integer.toString(edge.getToIndex()));
+ p.setProperty(Parser.TO_PROPERTY, Integer.toString(edge.getTo()));
+ p.setProperty(Parser.FROM_PROPERTY, Integer.toString(edge.getFrom()));
+ return p;
+ }
+}
diff --git a/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java b/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java
new file mode 100644
index 00000000000..1efcd06dec9
--- /dev/null
+++ b/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLParser.java
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ */
+package com.sun.hotspot.igv.data.serialization;
+
+import com.sun.hotspot.igv.data.Property;
+import com.sun.hotspot.igv.data.Properties;
+import java.util.Hashtable;
+import java.util.Stack;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+/**
+ *
+ * @author Thomas Wuerthinger
+ */
+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;
+
+ public MissingAttributeException(String name) {
+ super("Missing attribute \"" + name + "\"");
+ this.name = name;
+ }
+
+ public String getAttributeName() {
+ return this.getMessage();
+ }
+ }
+
+ public static class HandoverElementHandler extends ElementHandler
{
+
+ @Override
+ protected P start() throws SAXException {
+ return getParentObject();
+ }
+
+ public HandoverElementHandler(String name) {
+ super(name);
+ }
+
+ public HandoverElementHandler(String name, boolean needsText) {
+ super(name, needsText);
+ }
+ }
+
+ public static class TopElementHandler
extends ElementHandler
{
+
+ public TopElementHandler() {
+ super(null);
+ }
+ }
+
+ public static class ElementHandler {
+
+ private String name;
+ private T object;
+ private Attributes attr;
+ private StringBuilder currentText;
+ private ParseMonitor monitor;
+ private Hashtable> hashtable;
+ private boolean needsText;
+ private ElementHandler parentElement;
+
+ public ElementHandler(String name) {
+ this(name, false);
+ }
+
+ public ElementHandler
getParentElement() {
+ return parentElement;
+ }
+
+ public P getParentObject() {
+ return getParentElement().getObject();
+ }
+
+ protected boolean needsText() {
+ return needsText;
+ }
+
+ public ElementHandler(String name, boolean needsText) {
+ this.hashtable = new Hashtable>();
+ this.name = name;
+ this.needsText = needsText;
+ }
+
+ public ParseMonitor getMonitor() {
+ return monitor;
+ }
+
+ public ElementHandler, ? super T> getChild(String name) {
+ return hashtable.get(name);
+ }
+
+ public void addChild(ElementHandler, ? super T> handler) {
+ assert handler != null;
+ hashtable.put(handler.getName(), handler);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public T getObject() {
+ return object;
+ }
+
+ public String readAttribute(String name) {
+ return attr.getValue(name);
+ }
+
+ public String readRequiredAttribute(String name) throws SAXException {
+ String s = readAttribute(name);
+ if (s == null) {
+ throw new MissingAttributeException(name);
+ }
+ return s;
+ }
+
+ public void processAttributesAsProperties(Properties p) {
+ int length = attr.getLength();
+ for (int i = 0; i < length; i++) {
+ String val = attr.getValue(i).intern();
+ String localName = attr.getLocalName(i).intern();
+ p.add(new Property(val, localName));
+ }
+ }
+
+ public void startElement(ElementHandler parentElement, Attributes attr, ParseMonitor monitor) throws SAXException {
+ this.currentText = new StringBuilder();
+ this.attr = attr;
+ this.monitor = monitor;
+ this.parentElement = parentElement;
+ object = start();
+ }
+
+ protected T start() throws SAXException {
+ return null;
+ }
+
+ protected void end(String text) throws SAXException {
+
+ }
+
+ public void endElement() throws SAXException {
+ end(currentText.toString());
+ }
+
+ protected void text(char[] c, int start, int length) {
+ assert currentText != null;
+ currentText.append(c, start, length);
+ }
+ }
+ private Stack stack;
+ private ParseMonitor monitor;
+
+ public XMLParser(TopElementHandler rootHandler, ParseMonitor monitor) {
+ this.stack = new Stack();
+ this.monitor = monitor;
+ this.stack.push(rootHandler);
+ }
+
+ public void setDocumentLocator(Locator locator) {
+ if (monitor != null) {
+ monitor.setState("Starting parsing");
+ }
+ }
+
+ public void startDocument() throws SAXException {
+ }
+
+ public void endDocument() throws SAXException {
+ }
+
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException {
+ }
+
+ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
+
+ assert !stack.isEmpty();
+ ElementHandler parent = stack.peek();
+ if (parent != null) {
+ ElementHandler child = parent.getChild(qName);
+ if (child != null) {
+ child.startElement(parent, atts, monitor);
+ stack.push(child);
+ return;
+ }
+ }
+
+ stack.push(null);
+ }
+
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ ElementHandler handler = stack.pop();
+ if (handler != null) {
+ handler.endElement();
+ }
+ }
+
+ public void characters(char[] ch, int start, int length) throws SAXException {
+
+ assert !stack.isEmpty();
+
+
+ ElementHandler top = stack.peek();
+ if (top != null && top.needsText()) {
+ top.text(ch, start, length);
+ }
+ }
+
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
+ }
+
+ public void processingInstruction(String target, String data) throws SAXException {
+ }
+
+ public void skippedEntity(String name) throws SAXException {
+ }
+}
diff --git a/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLWriter.java b/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLWriter.java
new file mode 100644
index 00000000000..e112dbf4f07
--- /dev/null
+++ b/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/XMLWriter.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 1998-2007 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.hotspot.igv.data.serialization;
+
+import com.sun.hotspot.igv.data.Properties;
+import com.sun.hotspot.igv.data.Property;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Stack;
+
+/**
+ *
+ * @author Thomas Wuerthinger
+ */
+public class XMLWriter extends Writer {
+
+ private Writer inner;
+ private Stack elementStack;
+
+ public XMLWriter(Writer inner) {
+ this.inner = inner;
+ elementStack = new Stack();
+ }
+
+ @Override
+ public void write(char[] arr) throws IOException {
+ write(arr, 0, arr.length);
+ }
+
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ for (int i = off; i < off + len; i++) {
+ char c = cbuf[i];
+ if (c == '>') {
+ inner.write(">");
+ } else if (c == '<') {
+ inner.write("<");
+ } else if (c == '&') {
+ inner.write("&");
+ } else {
+ inner.write(c);
+ }
+ }
+ }
+
+ public void flush() throws IOException {
+ inner.flush();
+ }
+
+ public void close() throws IOException {
+ inner.close();
+ }
+
+ public void endTag() throws IOException {
+ inner.write("" + elementStack.pop() + ">\n");
+ }
+
+ public void startTag(String name) throws IOException {
+ inner.write("<" + name + ">\n");
+ elementStack.push(name);
+ }
+
+ public void simpleTag(String name) throws IOException {
+ inner.write("<" + name + "/>\n");
+ }
+
+ public void startTag(String name, Properties attributes) throws IOException {
+ inner.write("<" + name);
+ elementStack.push(name);
+
+ for (Property p : attributes.getProperties()) {
+ inner.write(" " + p.getName() + "=\"");
+ write(p.getValue().toCharArray());
+ inner.write("\"");
+ }
+
+ inner.write(">\n");
+ }
+
+ public void simpleTag(String name, Properties attributes) throws IOException {
+ inner.write("<" + name);
+
+ for (Property p : attributes.getProperties()) {
+ inner.write(" " + p.getName() + "=\"");
+ write(p.getValue().toCharArray());
+ inner.write("\"");
+ }
+
+ inner.write("/>\n");
+ }
+
+ public void writeProperties(Properties props) throws IOException {
+ if (props.getProperties().size() == 0) {
+ return;
+ }
+
+ startTag(Parser.PROPERTIES_ELEMENT);
+
+ for (Property p : props.getProperties()) {
+ startTag(Parser.PROPERTY_ELEMENT, new Properties(Parser.PROPERTY_NAME_PROPERTY, p.getName()));
+ this.write(p.getValue().toCharArray());
+ endTag();
+ }
+
+ endTag();
+ }
+}
diff --git a/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GraphViewer.java b/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GraphViewer.java
new file mode 100644
index 00000000000..153221d55e5
--- /dev/null
+++ b/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GraphViewer.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ */
+package com.sun.hotspot.igv.data.services;
+
+import com.sun.hotspot.igv.data.InputGraph;
+
+/**
+ *
+ * @author Thomas Wuerthinger
+ */
+public interface GraphViewer {
+
+ public void view(InputGraph graph);
+}
diff --git a/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupCallback.java b/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupCallback.java
new file mode 100644
index 00000000000..8b0115e84b1
--- /dev/null
+++ b/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupCallback.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 1998-2007 Sun Microsystems, Inc. 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. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.hotspot.igv.data.services;
+
+import com.sun.hotspot.igv.data.Group;
+
+/**
+ *
+ * @author Thomas Wuerthinger
+ */
+public interface GroupCallback {
+
+ public void started(Group g);
+}
diff --git a/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupOrganizer.java b/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupOrganizer.java
new file mode 100644
index 00000000000..90d61ebc10d
--- /dev/null
+++ b/hotspot/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/services/GroupOrganizer.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ */
+package com.sun.hotspot.igv.data.services;
+
+import com.sun.hotspot.igv.data.Group;
+import com.sun.hotspot.igv.data.Pair;
+import java.util.List;
+
+/**
+ *
+ * @author Thomas Wuerthinger
+ */
+public interface GroupOrganizer {
+
+ public String getName();
+
+ public List