Navigation Menu

Skip to content

Commit

Permalink
8294564: IGV: IllegalArgumentException for "Difference to current graph"
Browse files Browse the repository at this point in the history
Reviewed-by: rcastanedalo, chagedorn
  • Loading branch information
tobiasholenstein committed Oct 4, 2022
1 parent ae79af2 commit f957ce9
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 80 deletions.
Expand Up @@ -40,7 +40,6 @@
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.Border;
import org.openide.ErrorManager;
Expand Down Expand Up @@ -228,48 +227,51 @@ protected boolean requestFocusInWindow(boolean temporary) {

@Override
public void changed(InputGraphProvider lastProvider) {
// Wait for LookupHistory to be updated with the last active graph
// before selecting it.
SwingUtilities.invokeLater(() -> {
for (GraphNode graphNode : selectedGraphs) {
graphNode.setSelected(false);
}
for (FolderNode folderNode : selectedFolders) {
folderNode.setSelected(false);
}
selectedGraphs = new GraphNode[0];
selectedFolders.clear();
if (lastProvider != null) {
// Try to fetch and select the latest active graph.
InputGraph graph = lastProvider.getGraph();
if (graph != null) {
if (graph.isDiffGraph()) {
EditorTopComponent editor = EditorTopComponent.getActive();
if (editor != null) {
InputGraph firstGraph = editor.getModel().getFirstGraph();
InputGraph secondGraph = editor.getModel().getSecondGraph();
selectedGraphs = new GraphNode[]{FolderNode.getGraphNode(firstGraph), FolderNode.getGraphNode(secondGraph)};
for (GraphNode graphNode : selectedGraphs) {
graphNode.setSelected(false);
}
for (FolderNode folderNode : selectedFolders) {
folderNode.setSelected(false);
}
selectedGraphs = new GraphNode[0];
selectedFolders.clear();
if (lastProvider != null) {
// Try to fetch and select the latest active graph.
InputGraph graph = lastProvider.getGraph();
if (graph != null) {
if (graph.isDiffGraph()) {
EditorTopComponent editor = EditorTopComponent.getActive();
if (editor != null) {
InputGraph firstGraph = editor.getModel().getFirstGraph();
GraphNode firstNode = FolderNode.getGraphNode(firstGraph);
InputGraph secondGraph = editor.getModel().getSecondGraph();
GraphNode secondNode = FolderNode.getGraphNode(secondGraph);
if (firstNode != null && secondNode != null) {
selectedGraphs = new GraphNode[]{firstNode, secondNode};
}
} else {
selectedGraphs = new GraphNode[]{FolderNode.getGraphNode(graph)};
}
} else {
GraphNode graphNode = FolderNode.getGraphNode(graph);
if (graphNode != null) {
selectedGraphs = new GraphNode[]{graphNode};
}
}
}
try {
for (GraphNode graphNode : selectedGraphs) {
Node parentNode = graphNode.getParentNode();
if (parentNode instanceof FolderNode) {
FolderNode folderNode = (FolderNode) graphNode.getParentNode();
folderNode.setSelected(true);
selectedFolders.add(folderNode);
}
graphNode.setSelected(true);
}
try {
for (GraphNode graphNode : selectedGraphs) {
Node parentNode = graphNode.getParentNode();
if (parentNode instanceof FolderNode) {
FolderNode folderNode = (FolderNode) graphNode.getParentNode();
folderNode.setSelected(true);
selectedFolders.add(folderNode);
}
manager.setSelectedNodes(selectedGraphs);
} catch (Exception e) {
Exceptions.printStackTrace(e);
graphNode.setSelected(true);
}
});
manager.setSelectedNodes(selectedGraphs);
} catch (Exception e) {
Exceptions.printStackTrace(e);
}
}

@Override
Expand Down
Expand Up @@ -28,6 +28,8 @@
import com.sun.hotspot.igv.data.services.InputGraphProvider;
import com.sun.hotspot.igv.difference.Difference;
import com.sun.hotspot.igv.util.LookupHistory;
import com.sun.hotspot.igv.view.EditorTopComponent;
import com.sun.hotspot.igv.view.GraphViewerImplementation;
import org.openide.nodes.Node;
import org.openide.util.Lookup;

Expand All @@ -37,7 +39,7 @@
*/
public class DiffGraphCookie implements Node.Cookie {

private InputGraph graph;
private final InputGraph graph;

public DiffGraphCookie(InputGraph graph) {
this.graph = graph;
Expand All @@ -52,15 +54,15 @@ private InputGraph getCurrentGraph() {
}

public boolean isPossible() {
return getCurrentGraph() != null;
InputGraph currentGraph = getCurrentGraph();
return currentGraph != null && !currentGraph.isDiffGraph() && currentGraph != graph;
}

public void openDiff() {
InputGraph other = getCurrentGraph();
final GraphViewer viewer = Lookup.getDefault().lookup(GraphViewer.class);
if (viewer != null) {
InputGraph diffGraph = Difference.createDiffGraph(other, graph);
viewer.view(diffGraph, true);
if (viewer != null && other != null) {
viewer.viewDifference(other, graph);
}
}
}
Expand Up @@ -39,10 +39,16 @@ public class InputGraph extends Properties.Entity implements FolderElement {
private List<InputBlockEdge> blockEdges;
private Map<Integer, InputBlock> nodeToBlock;
private boolean isDiffGraph;
private InputGraph firstGraph;
private InputGraph secondGraph;

public InputGraph(String name, boolean isDiffGraph) {
this(name);
this.isDiffGraph = isDiffGraph;

public InputGraph(InputGraph firstGraph, InputGraph secondGraph) {
this(firstGraph.getName() + " Δ " + secondGraph.getName());
assert !firstGraph.isDiffGraph() && !secondGraph.isDiffGraph();
this.firstGraph = firstGraph;
this.secondGraph = secondGraph;
isDiffGraph = true;
}

public InputGraph(String name) {
Expand All @@ -52,13 +58,23 @@ public InputGraph(String name) {
blocks = new LinkedHashMap<>();
blockEdges = new ArrayList<>();
nodeToBlock = new LinkedHashMap<>();
firstGraph = null;
secondGraph = null;
isDiffGraph = false;
}

public boolean isDiffGraph() {
return this.isDiffGraph;
}

public InputGraph getFirstGraph() {
return firstGraph;
}

public InputGraph getSecondGraph() {
return secondGraph;
}

@Override
public void setParent(Folder parent) {
this.parent = parent;
Expand Down
Expand Up @@ -31,5 +31,7 @@
*/
public interface GraphViewer {

public void view(InputGraph graph, boolean clone);
void view(InputGraph graph, boolean clone);

void viewDifference(InputGraph firstGraph, InputGraph secondGraph);
}
Expand Up @@ -105,7 +105,7 @@ private static InputGraph createDiff(InputGraph a, InputGraph b, Set<NodePair> p
}
}
g.getProperties().setProperty("name", "Difference");
InputGraph graph = new InputGraph(a.getName() + ", " + b.getName(), true);
InputGraph graph = new InputGraph(a, b);
g.addElement(graph);

Map<InputBlock, InputBlock> blocksMap = new HashMap<>();
Expand Down
Expand Up @@ -405,30 +405,59 @@ private void filterGraphs() {
}

public InputGraph getFirstGraph() {
InputGraph firstGraph;
if (getFirstPosition() < graphs.size()) {
return graphs.get(getFirstPosition());
firstGraph = graphs.get(getFirstPosition());
} else {
firstGraph = graphs.get(graphs.size() - 1);
}
return graphs.get(graphs.size() - 1);
if (firstGraph.isDiffGraph()) {
firstGraph = firstGraph.getFirstGraph();
}
return firstGraph;
}

public InputGraph getSecondGraph() {
InputGraph secondGraph;
if (getSecondPosition() < graphs.size()) {
return graphs.get(getSecondPosition());
secondGraph = graphs.get(getSecondPosition());
} else {
secondGraph = getFirstGraph();
}
if (secondGraph.isDiffGraph()) {
secondGraph = secondGraph.getSecondGraph();
}
return getFirstGraph();
return secondGraph;
}

public void selectGraph(InputGraph g) {
int index = graphs.indexOf(g);
public void selectGraph(InputGraph graph) {
int index = graphs.indexOf(graph);
if (index == -1 && hideDuplicates) {
// A graph was selected that's currently hidden, so unhide and select it.
setHideDuplicates(false);
index = graphs.indexOf(g);
index = graphs.indexOf(graph);
}
assert index != -1;
setPositions(index, index);
}

public void selectDiffGraph(InputGraph graph) {
int index = graphs.indexOf(graph);
if (index == -1 && hideDuplicates) {
// A graph was selected that's currently hidden, so unhide and select it.
setHideDuplicates(false);
index = graphs.indexOf(graph);
}
assert index != -1;
int firstIndex = getFirstPosition();
int secondIndex = getSecondPosition();
if (firstIndex <= index) {
setPositions(firstIndex, index);
} else {
setPositions(index, secondIndex);
}
}

private static ColorFilter.ColorRule stateColorRule(String state, Color color) {
return new ColorFilter.ColorRule(new MatcherSelector(new Properties.RegexpPropertyMatcher("state", state)), color);
}
Expand Down
Expand Up @@ -49,7 +49,7 @@ public EditorInputGraphProvider(EditorTopComponent editor) {

@Override
public InputGraph getGraph() {
if (editor != null) {
if (editor != null && EditorTopComponent.isOpen(editor)) {
return editor.getModel().getGraphToView();
} else {
return null;
Expand All @@ -58,14 +58,14 @@ public InputGraph getGraph() {

@Override
public void setSelectedNodes(Set<InputNode> nodes) {
if (editor != null) {
if (editor != null && EditorTopComponent.isOpen(editor)) {
editor.setSelectedNodes(nodes);
}
}

@Override
public Iterable<InputGraph> searchBackward() {
if (editor != null) {
if (editor != null && EditorTopComponent.isOpen(editor)) {
return editor.getModel().getGraphsBackward();
} else {
return null;
Expand All @@ -74,7 +74,7 @@ public Iterable<InputGraph> searchBackward() {

@Override
public Iterable<InputGraph> searchForward() {
if (editor != null) {
if (editor != null && EditorTopComponent.isOpen(editor)) {
return editor.getModel().getGraphsForward();
} else {
return null;
Expand Down
Expand Up @@ -54,7 +54,9 @@
import org.openide.util.lookup.AbstractLookup;
import org.openide.util.lookup.InstanceContent;
import org.openide.util.lookup.ProxyLookup;
import org.openide.windows.Mode;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;


/**
Expand Down Expand Up @@ -283,6 +285,10 @@ public void setZoomLevel(int percentage) {
scene.setZoomPercentage(percentage);
}

public static boolean isOpen(EditorTopComponent editor) {
return WindowManager.getDefault().isOpenedEditorTopComponent(editor);
}

public static EditorTopComponent getActive() {
TopComponent topComponent = getRegistry().getActivated();
if (topComponent instanceof EditorTopComponent) {
Expand All @@ -291,6 +297,24 @@ public static EditorTopComponent getActive() {
return null;
}

public static EditorTopComponent findEditorForGraph(InputGraph graph) {
WindowManager manager = WindowManager.getDefault();
for (Mode m : manager.getModes()) {
List<TopComponent> l = new ArrayList<>();
l.add(m.getSelectedTopComponent());
l.addAll(Arrays.asList(manager.getOpenedTopComponents(m)));
for (TopComponent t : l) {
if (t instanceof EditorTopComponent) {
EditorTopComponent etc = (EditorTopComponent) t;
if (etc.getModel().getGroup().getGraphs().contains(graph)) {
return etc;
}
}
}
}
return null;
}

@Override
public int getPersistenceType() {
return TopComponent.PERSISTENCE_NEVER;
Expand Down

1 comment on commit f957ce9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.