Skip to content

Commit 5136643

Browse files
committed
8262725: IGV: crash when removing all graphs in a group
Make IGV close graph views when their groups are either removed or emptied, and avoid faulty graph view computation for empty groups. Reviewed-by: chagedorn, rrich
1 parent 79798c6 commit 5136643

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramViewModel.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -206,6 +206,11 @@ public void changed(DiagramViewModel source) {
206206
@Override
207207
public void changed(Group source) {
208208
assert source == group;
209+
if (group.getGraphs().isEmpty()) {
210+
// If the group has been emptied, all corresponding graph views
211+
// will be closed, so do nothing.
212+
return;
213+
}
209214
filterGraphs();
210215
setSelectedNodes(selectedNodes);
211216
}

src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/EditorTopComponent.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525

2626
import com.sun.hotspot.igv.data.ChangedEvent;
2727
import com.sun.hotspot.igv.data.ChangedListener;
28+
import com.sun.hotspot.igv.data.GraphDocument;
29+
import com.sun.hotspot.igv.data.Group;
2830
import com.sun.hotspot.igv.data.InputNode;
2931
import com.sun.hotspot.igv.data.Properties;
3032
import com.sun.hotspot.igv.data.Properties.PropertyMatcher;
@@ -225,6 +227,12 @@ public void changed(DiagramViewModel source) {
225227
}
226228
});
227229

230+
Group group = getDiagram().getGraph().getGroup();
231+
group.getChangedEvent().addListener(g -> closeOnRemovedOrEmptyGroup());
232+
if (group.getParent() instanceof GraphDocument) {
233+
final GraphDocument doc = (GraphDocument) group.getParent();
234+
doc.getChangedEvent().addListener(d -> closeOnRemovedOrEmptyGroup());
235+
}
228236

229237
toolBar.add(NextDiagramAction.get(NextDiagramAction.class));
230238
toolBar.add(PrevDiagramAction.get(PrevDiagramAction.class));
@@ -449,6 +457,14 @@ protected String preferredID() {
449457
return PREFERRED_ID;
450458
}
451459

460+
private void closeOnRemovedOrEmptyGroup() {
461+
Group group = getDiagram().getGraph().getGroup();
462+
if (!group.getParent().getElements().contains(group) ||
463+
group.getGraphs().isEmpty()) {
464+
close();
465+
}
466+
}
467+
452468
private ChangedListener<DiagramViewModel> diagramChangedListener = new ChangedListener<DiagramViewModel>() {
453469

454470
@Override

0 commit comments

Comments
 (0)