# HG changeset patch # User Thomas Wuerthinger # Date 1327693014 -3600 # Node ID e5cc2440f034eb0e78791a276316ebd36893c918 # Parent 2e66f6fd4bc9d88dcbb2af550af18e7691a88341 Fixed multi-threading issue when changing the model. Fixed regression in folder node deletion. diff -r 2e66f6fd4bc9 -r e5cc2440f034 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 Fri Jan 27 19:39:29 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/actions/ImportAction.java Fri Jan 27 20:36:54 2012 +0100 @@ -38,6 +38,7 @@ import javax.swing.Action; import javax.swing.JFileChooser; import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; import javax.swing.filechooser.FileFilter; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; @@ -69,6 +70,7 @@ }; } + @Override public void performAction() { JFileChooser fc = new JFileChooser(); @@ -96,6 +98,7 @@ final XMLParser.ParseMonitor parseMonitor = new XMLParser.ParseMonitor() { + @Override public void setProgress(double d) { try { int curAvailable = inputStream.available(); @@ -105,6 +108,7 @@ } } + @Override public void setState(String state) { setProgress(0.0); handle.progress(state); @@ -117,12 +121,18 @@ RequestProcessor.getDefault().post(new Runnable() { + @Override public void run() { - GraphDocument document = null; try { - document = parser.parse(is, parseMonitor); + final GraphDocument document = parser.parse(is, parseMonitor); parseMonitor.setState("Finishing"); - component.getDocument().addGraphDocument(document); + 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) { @@ -159,6 +169,7 @@ return "com/sun/hotspot/igv/coordinator/images/import.png"; } + @Override public HelpCtx getHelpCtx() { return HelpCtx.DEFAULT_HELP; } diff -r 2e66f6fd4bc9 -r e5cc2440f034 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/FolderElement.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/FolderElement.java Fri Jan 27 19:39:29 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/FolderElement.java Fri Jan 27 20:36:54 2012 +0100 @@ -27,4 +27,5 @@ Folder getParent(); String getName(); + void setParent(Folder parent); } diff -r 2e66f6fd4bc9 -r e5cc2440f034 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java Fri Jan 27 19:39:29 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/GraphDocument.java Fri Jan 27 20:36:54 2012 +0100 @@ -37,8 +37,8 @@ private ChangedEvent changedEvent; public GraphDocument() { - elements = new ArrayList(); - changedEvent = new ChangedEvent(this); + elements = new ArrayList<>(); + changedEvent = new ChangedEvent<>(this); } public void clear() { @@ -52,6 +52,7 @@ public void addGraphDocument(GraphDocument document) { for (FolderElement e : document.elements) { + e.setParent(this); this.addElement(e); } document.clear(); @@ -62,7 +63,7 @@ public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("GraphDocument: " + getProperties().toString() + " \n\n"); + sb.append("GraphDocument: ").append(getProperties().toString()).append(" \n\n"); for (FolderElement g : getElements()) { sb.append(g.toString()); sb.append("\n\n"); diff -r 2e66f6fd4bc9 -r e5cc2440f034 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java Fri Jan 27 19:39:29 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java Fri Jan 27 20:36:54 2012 +0100 @@ -36,7 +36,7 @@ private InputMethod method; private transient ChangedEvent changedEvent; - private final Folder parent; + private Folder parent; public Group(Folder parent) { elements = new ArrayList<>(); @@ -166,4 +166,9 @@ public List getGraphs() { return graphs; } + + @Override + public void setParent(Folder parent) { + this.parent = parent; + } } diff -r 2e66f6fd4bc9 -r e5cc2440f034 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java Fri Jan 27 19:39:29 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java Fri Jan 27 20:36:54 2012 +0100 @@ -42,29 +42,27 @@ private Map nodes; private Set edges; - private Group parent; + private Folder parent; + private Group parentGroup; private Map blocks; private Set blockEdges; private Map nodeToBlock; public InputGraph(String name) { - this(null, name); - } - - InputGraph(Group parent, String name) { - this.parent = parent; setName(name); - nodes = new LinkedHashMap(); - edges = new LinkedHashSet(); - blocks = new LinkedHashMap(); - blockEdges = new LinkedHashSet(); - nodeToBlock = new LinkedHashMap(); + nodes = new LinkedHashMap<>(); + edges = new LinkedHashSet<>(); + blocks = new LinkedHashMap<>(); + blockEdges = new LinkedHashSet<>(); + nodeToBlock = new LinkedHashMap<>(); } - public void setParent(Group parent) { - assert (this.parent == null); - + public void setParent(Folder parent) { this.parent = parent; + if (parent instanceof Group) { + assert this.parentGroup == null; + this.parentGroup = (Group) parent; + } } public InputBlockEdge addBlockEdge(InputBlock left, InputBlock right) { @@ -75,8 +73,8 @@ } public List findRootNodes() { - List result = new ArrayList(); - Set nonRoot = new HashSet(); + List result = new ArrayList<>(); + Set nonRoot = new HashSet<>(); for(InputEdge curEdges : getEdges()) { nonRoot.add(curEdges.getTo()); } @@ -203,11 +201,11 @@ } public InputGraph getNext() { - return parent.getNext(this); + return parentGroup.getNext(this); } public InputGraph getPrev() { - return parent.getPrev(this); + return parentGroup.getPrev(this); } private void setName(String name) { @@ -259,13 +257,13 @@ } public Group getGroup() { - return parent; + return parentGroup; } @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("Graph " + getName() + " " + getProperties().toString() + "\n"); + sb.append("Graph ").append(getName()).append(" ").append(getProperties().toString()).append("\n"); for (InputNode n : nodes.values()) { sb.append(n.toString()); sb.append("\n"); diff -r 2e66f6fd4bc9 -r e5cc2440f034 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java Fri Jan 27 19:39:29 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java Fri Jan 27 20:36:54 2012 +0100 @@ -34,6 +34,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; +import javax.swing.SwingUtilities; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.Source; @@ -91,7 +93,8 @@ public static final String ASSEMBLY_ELEMENT = "assembly"; public static final String DIFFERENCE_PROPERTY = "difference"; private TopElementHandler xmlDocument = new TopElementHandler(); - private boolean difference; + private Map differenceEncoding = new HashMap<>(); + private Map lastParsedGraph = new HashMap<>(); private GroupCallback groupCallback; private HashMap idCache = new HashMap(); private ArrayList> blockConnections = new ArrayList>(); @@ -127,7 +130,7 @@ Group group = new Group(this.getParentObject()); String differenceProperty = this.readAttribute(DIFFERENCE_PROPERTY); - Parser.this.difference = (differenceProperty != null && (differenceProperty.equals("1") || differenceProperty.equals("true"))); + Parser.this.differenceEncoding.put(group, (differenceProperty != null && (differenceProperty.equals("1") || differenceProperty.equals("true")))); ParseMonitor monitor = getMonitor(); if (monitor != null) { @@ -139,9 +142,15 @@ @Override protected void end(String text) throws SAXException { - Group group = getObject(); + final Group group = getObject(); + final Folder parent = getParentObject(); if (groupCallback == null) { - getParentObject().addElement(group); + SwingUtilities.invokeLater(new Runnable(){ + @Override + public void run() { + parent.addElement(group); + } + }); } } }; @@ -191,14 +200,13 @@ // private ElementHandler graphHandler = new XMLParser.ElementHandler(GRAPH_ELEMENT) { - private InputGraph graph; - @Override protected InputGraph start() throws SAXException { String name = readAttribute(GRAPH_NAME_PROPERTY); InputGraph curGraph = new InputGraph(name); - if (difference) { - InputGraph previous = getParentObject().getLastGraph(); + if (differenceEncoding.get(getParentObject())) { + InputGraph previous = lastParsedGraph.get(getParentObject()); + lastParsedGraph.put(getParentObject(), curGraph); if (previous != null) { for (InputNode n : previous.getNodes()) { curGraph.addNode(n); @@ -208,7 +216,6 @@ } } } - this.graph = curGraph; return curGraph; } @@ -221,6 +228,8 @@ // block to some artificial block below unless blocks are // defined and nodes are assigned to them. + final InputGraph graph = getObject(); + final Group parent = getParentObject(); if (graph.getBlocks().size() > 0) { boolean blocksContainNodes = false; for (InputBlock b : graph.getBlocks()) { @@ -261,8 +270,14 @@ } blockConnections.clear(); - // Add to group - getParentObject().addElement(graph); + SwingUtilities.invokeLater(new Runnable(){ + + @Override + public void run() { + // Add to group + parent.addElement(graph); + } + }); } }; // diff -r 2e66f6fd4bc9 -r e5cc2440f034 src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/GroupTest.java --- a/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/GroupTest.java Fri Jan 27 19:39:29 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/GroupTest.java Fri Jan 27 20:36:54 2012 +0100 @@ -64,9 +64,11 @@ */ @Test public void testGetAllNodes() { - final Group g = new Group(); - final InputGraph graph1 = g.addGraph("1"); - final InputGraph graph2 = g.addGraph("2"); + final Group g = new Group(null); + final InputGraph graph1 = new InputGraph("1"); + final InputGraph graph2 = new InputGraph("2"); + g.addElement(graph1); + g.addElement(graph2); graph1.addNode(new InputNode(1)); graph1.addNode(new InputNode(2)); graph2.addNode(new InputNode(2)); diff -r 2e66f6fd4bc9 -r e5cc2440f034 src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/InputGraphTest.java --- a/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/InputGraphTest.java Fri Jan 27 19:39:29 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/InputGraphTest.java Fri Jan 27 20:36:54 2012 +0100 @@ -68,11 +68,13 @@ @BeforeClass public static void setUpClass() throws Exception { - Group group = new Group(); + Group group = new Group(null); - emptyGraph = group.addGraph("emptyGraph"); - - referenceGraph = group.addGraph("referenceGraph"); + emptyGraph = new InputGraph("emptyGraph"); + group.addElement(emptyGraph); + + referenceGraph = new InputGraph("referenceGraph"); + group.addElement(referenceGraph); referenceGraph.addNode(N1); referenceGraph.addNode(N2); referenceGraph.addNode(N3); @@ -104,13 +106,16 @@ @Test public void testEquals() { - Group parentA = new Group(); - InputGraph a = parentA.addGraph("graph"); + Group parentA = new Group(null); + InputGraph a = new InputGraph("graph"); + parentA.addElement(a); - Group parentB = new Group(); - InputGraph b = parentB.addGraph("graph"); + Group parentB = new Group(null); + InputGraph b = new InputGraph("graph"); + parentB.addElement(b); - InputGraph c = parentB.addGraph("graph"); + InputGraph c = new InputGraph("graph"); + parentB.addElement(b); Util.assertGraphEquals(a, b); Util.assertGraphEquals(b, c); @@ -127,7 +132,7 @@ */ @Test public void testFindRootNodes() { - assertTrue(emptyGraph.findRootNodes().size() == 0); + assertTrue(emptyGraph.findRootNodes().isEmpty()); List result = referenceGraph.findRootNodes(); assertTrue(result.size() == 2); @@ -140,7 +145,7 @@ */ @Test public void testFindAllOutgoingEdges() { - assertTrue(emptyGraph.findAllOutgoingEdges().size() == 0); + assertTrue(emptyGraph.findAllOutgoingEdges().isEmpty()); Map> result = referenceGraph.findAllOutgoingEdges(); assertTrue(result.size() == 5); @@ -156,7 +161,7 @@ */ @Test public void testFindAllIngoingEdges() { - assertTrue(emptyGraph.findAllIngoingEdges().size() == 0); + assertTrue(emptyGraph.findAllIngoingEdges().isEmpty()); Map> result = referenceGraph.findAllIngoingEdges(); assertTrue(result.size() == 5); @@ -172,7 +177,7 @@ */ @Test public void testFindOutgoingEdges() { - assertTrue(emptyGraph.findOutgoingEdges(new InputNode(1)).size() == 0); + assertTrue(emptyGraph.findOutgoingEdges(new InputNode(1)).isEmpty()); assertEquals(referenceGraph.findOutgoingEdges(N1), Arrays.asList(E12, E13)); assertEquals(referenceGraph.findOutgoingEdges(N2), Arrays.asList(E24)); @@ -186,13 +191,16 @@ */ @Test public void testGetNextPrev() { - final Group group = new Group(); + final Group group = new Group(null); - final InputGraph a = group.addGraph("a"); + final InputGraph a = new InputGraph("a"); - final InputGraph b = group.addGraph("b"); + final InputGraph b = new InputGraph("b"); - final InputGraph c = group.addGraph("c"); + final InputGraph c = new InputGraph("c"); + group.addElement(a); + group.addElement(b); + group.addElement(c); assertEquals(null, a.getPrev()); assertEquals(b, a.getNext()); diff -r 2e66f6fd4bc9 -r e5cc2440f034 src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/InputMethodTest.java --- a/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/InputMethodTest.java Fri Jan 27 19:39:29 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/InputMethodTest.java Fri Jan 27 20:36:54 2012 +0100 @@ -72,7 +72,7 @@ "7 iconst_0\n" + "8 ireturn"; - final Group g = new Group(); + final Group g = new Group(null); InputMethod m = new InputMethod(g, "name", "shortName", -1); m.setBytecodes(input); diff -r 2e66f6fd4bc9 -r e5cc2440f034 src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/Util.java --- a/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/Util.java Fri Jan 27 19:39:29 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/Util.java Fri Jan 27 20:36:54 2012 +0100 @@ -45,16 +45,19 @@ public static void assertGraphDocumentEquals(GraphDocument a, GraphDocument b) { - if (a.getGroups().size() != b.getGroups().size()) { + if (a.getElements().size() != b.getElements().size()) { fail(); } int z = 0; - for (Group g : b.getGroups()) { + for (FolderElement e : b.getElements()) { - Group thisG = a.getGroups().get(z); - assertGroupEquals(thisG, g); + if (e instanceof Group) { + Group g = (Group) e; + Group thisG = (Group) a.getElements().get(z); + assertGroupEquals(thisG, g); z++; + } } } diff -r 2e66f6fd4bc9 -r e5cc2440f034 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 Fri Jan 27 19:39:29 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/serialization/ParserTest.java Fri Jan 27 20:36:54 2012 +0100 @@ -104,15 +104,16 @@ test(doc); - final Group group1 = new Group(); - doc.addGroup(group1); + final Group group1 = new Group(doc); + doc.addElement(group1); test(doc); - final Group group2 = new Group(); - doc.addGroup(group2); + final Group group2 = new Group(doc); + doc.addElement(group2); test(doc); - final InputGraph graph = group1.addGraph(""); + final InputGraph graph = new InputGraph(""); + group1.addElement(graph); test(doc); graph.addNode(new InputNode(0)); @@ -154,13 +155,13 @@ final GraphDocument document2 = new GraphDocument(); doc.addGraphDocument(document2); test(doc); - assertTrue(doc.getGroups().size() == 2); + assertTrue(doc.getElements().size() == 2); - final Group group3 = new Group(); - document2.addGroup(group3); + final Group group3 = new Group(document2); + document2.addElement(group3); doc.addGraphDocument(document2); - assertTrue(doc.getGroups().size() == 3); - assertTrue(document2.getGroups().size() == 0); + assertTrue(doc.getElements().size() == 3); + assertTrue(document2.getElements().size() == 0); doc.clear(); test(doc); @@ -170,10 +171,11 @@ @Test public void testSimpleExport() { GraphDocument document = new GraphDocument(); - Group g = new Group(); - document.addGroup(g); + Group g = new Group(document); + document.addElement(g); - InputGraph graph = g.addGraph("TestGraph"); + InputGraph graph = new InputGraph("TestGraph"); + g.addElement(graph); graph.getProperties().setProperty("testName", "testValue"); InputNode n1 = new InputNode(0); @@ -192,10 +194,11 @@ public void testComplexExport() { GraphDocument document = new GraphDocument(); - Group g = new Group(); - document.addGroup(g); + Group g = new Group(document); + document.addElement(g); - InputGraph graph = g.addGraph("TestGraph"); + InputGraph graph = new InputGraph("TestGraph"); + g.addElement(graph); graph.getProperties().setProperty("testName", "testValue"); InputNode n1 = new InputNode(0); @@ -207,7 +210,8 @@ graph.addEdge(e1); graph.addEdge(e2); - InputGraph graph2 = g.addGraph("TestGraph2"); + InputGraph graph2 = new InputGraph("TestGraph2"); + g.addElement(graph2); graph2.addNode(n1); InputNode n3 = new InputNode(2); graph2.addNode(n3);