# HG changeset patch # User Peter Hofer # Date 1319039368 -7200 # Node ID 9fe4191f46af8d7dd27f99bec39f889c892495fb # Parent 78c94d5d23fb21c22aad08d6e67d4ff62cd31e42 IdealGraphVisualizer: Try to resolve UI concurrency issues by introducing locking for the list of graphs in Group and adding graphs to their group only after they have been fully read in. diff -r 78c94d5d23fb -r 9fe4191f46af src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java Wed Oct 19 15:11:33 2011 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java Wed Oct 19 17:49:28 2011 +0200 @@ -79,7 +79,7 @@ List curNodes = new ArrayList(); for (Group g : p.getRight()) { - for (InputGraph graph : g.getGraphs()) { + for (InputGraph graph : g.getGraphListCopy()) { curNodes.add(new GraphNode(graph)); } g.getChangedEvent().addListener(this); diff -r 78c94d5d23fb -r 9fe4191f46af src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphCountGroupOrganizer.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphCountGroupOrganizer.java Wed Oct 19 15:11:33 2011 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/GraphCountGroupOrganizer.java Wed Oct 19 17:49:28 2011 +0200 @@ -51,7 +51,7 @@ if (subFolders.size() == 0) { Map> map = new HashMap>(groups.size()); for (Group g : groups) { - Integer cur = g.getGraphs().size(); + Integer cur = g.getGraphsCount(); if (!map.containsKey(cur)) { map.put(cur, new ArrayList()); } diff -r 78c94d5d23fb -r 9fe4191f46af 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 Wed Oct 19 15:11:33 2011 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/Group.java Wed Oct 19 17:49:28 2011 +0200 @@ -35,14 +35,15 @@ */ public class Group extends Properties.Entity implements ChangedEventProvider { - private List graphs; + private final List graphs; + private InputMethod method; private String assembly; private transient ChangedEvent changedEvent; private transient boolean complete = true; public Group() { - graphs = new ArrayList(); + graphs = Collections.synchronizedList(new ArrayList()); changedEvent = new ChangedEvent(this); // Ensure that name and type are never null @@ -86,30 +87,50 @@ return Collections.unmodifiableList(graphs); } + public int getGraphsCount() { + return graphs.size(); + } + + public List getGraphListCopy() { + synchronized (graphs) { + return new ArrayList(graphs); + } + } + + public void addGraph(InputGraph graph) { + synchronized (graphs) { + graph.setParent(this, graphs.size()); + graphs.add(graph); + } + changedEvent.fire(); + } + public InputGraph addGraph(String name) { return addGraph(name, null); } public InputGraph addGraph(String name, Pair pair) { - InputGraph g = new InputGraph(graphs.size(), this, name, pair); - graphs.add(g); + InputGraph g; + synchronized (graphs) { + g = new InputGraph(graphs.size(), this, name, pair); + graphs.add(g); + } changedEvent.fire(); return g; } public void removeGraph(InputGraph g) { - int index = graphs.indexOf(g); - if (index != -1) { - graphs.remove(g); + if (graphs.remove(g)) { changedEvent.fire(); } } public Set getAllNodes() { Set result = new HashSet(); - for (InputGraph g : graphs) { - Set ids = g.getNodesAsSet(); - result.addAll(g.getNodesAsSet()); + synchronized (graphs) { + for (InputGraph g : graphs) { + result.addAll(g.getNodesAsSet()); + } } return result; } @@ -118,9 +139,11 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Group " + getProperties().toString() + "\n"); - for (InputGraph g : graphs) { - sb.append(g.toString()); - sb.append("\n"); + synchronized (graphs) { + for (InputGraph g : graphs) { + sb.append(g.toString()); + sb.append('\n'); + } } return sb.toString(); } diff -r 78c94d5d23fb -r 9fe4191f46af 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 Wed Oct 19 15:11:33 2011 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/InputGraph.java Wed Oct 19 17:49:28 2011 +0200 @@ -49,6 +49,10 @@ private Pair sourceGraphs; private int parentIndex; + public static InputGraph createWithoutGroup(String name, Pair sourceGraphs) { + return new InputGraph(-1, null, name, sourceGraphs); + } + InputGraph(int parentIndex, Group parent, String name, Pair sourceGraphs) { this.parentIndex = parentIndex; this.parent = parent; @@ -60,6 +64,14 @@ blockEdges = new LinkedHashSet(); nodeToBlock = new LinkedHashMap(); } + + public void setParent(Group parent, int parentIndex) { + assert (this.parent == null); + assert (this.parentIndex == -1); + + this.parent = parent; + this.parentIndex = parentIndex; + } public InputBlockEdge addBlockEdge(InputBlock left, InputBlock right) { InputBlockEdge edge = new InputBlockEdge(left, right); diff -r 78c94d5d23fb -r 9fe4191f46af src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java Wed Oct 19 15:11:33 2011 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Parser.java Wed Oct 19 17:49:28 2011 +0200 @@ -211,14 +211,12 @@ @Override protected InputGraph start() throws SAXException { - String name = readAttribute(GRAPH_NAME_PROPERTY); - InputGraph curGraph = getParentObject().addGraph(name); + InputGraph curGraph = InputGraph.createWithoutGroup(name, null); if (difference) { - List list = getParentObject().getGraphs(); - if (list.size() > 1) { - InputGraph previous = list.get(list.size() - 2); + if (list.size() > 0) { + InputGraph previous = list.get(list.size() - 1); for (InputNode n : previous.getNodes()) { curGraph.addNode(n); } @@ -279,6 +277,9 @@ graph.addBlockEdge(left, right); } blockConnections.clear(); + + // Add to group + getParentObject().addGraph(graph); } }; // diff -r 78c94d5d23fb -r 9fe4191f46af 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 Wed Oct 19 15:11:33 2011 +0200 +++ b/src/share/tools/IdealGraphVisualizer/Data/test/unit/src/com/sun/hotspot/igv/data/Util.java Wed Oct 19 17:49:28 2011 +0200 @@ -70,7 +70,7 @@ public static void assertGroupEquals(Group a, Group b) { - if (a.getGraphs().size() != b.getGraphs().size()) { + if (a.getGraphsCount() != b.getGraphsCount()) { fail(); } diff -r 78c94d5d23fb -r 9fe4191f46af src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java Wed Oct 19 15:11:33 2011 +0200 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java Wed Oct 19 17:49:28 2011 +0200 @@ -294,7 +294,7 @@ } }); - if (diagram.getGraph().getGroup().getGraphs().size() == 1) { + if (diagram.getGraph().getGroup().getGraphsCount() == 1) { rangeSlider.setVisible(false); }