Skip to content

Commit 4e7cb15

Browse files
8293480: IGV: Update Bytecode and ControlFlow Component immediately when opening a new graph
Reviewed-by: rcastanedalo, chagedorn
1 parent 8ecdaa6 commit 4e7cb15

File tree

11 files changed

+200
-267
lines changed

11 files changed

+200
-267
lines changed

src/utils/IdealGraphVisualizer/Bytecodes/src/main/java/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.java

+40-50
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
*/
2424
package com.sun.hotspot.igv.bytecodes;
2525

26+
import com.sun.hotspot.igv.data.ChangedListener;
2627
import com.sun.hotspot.igv.data.Group;
2728
import com.sun.hotspot.igv.data.InputGraph;
2829
import com.sun.hotspot.igv.data.services.InputGraphProvider;
2930
import com.sun.hotspot.igv.util.LookupHistory;
3031
import java.awt.BorderLayout;
3132
import java.io.Serializable;
32-
import javax.swing.SwingUtilities;
3333
import org.openide.ErrorManager;
3434
import org.openide.explorer.ExplorerManager;
3535
import org.openide.explorer.ExplorerUtils;
@@ -41,13 +41,12 @@
4141
/**
4242
* @author Thomas Wuerthinger
4343
*/
44-
final class BytecodeViewTopComponent extends TopComponent implements ExplorerManager.Provider, LookupListener {
44+
final class BytecodeViewTopComponent extends TopComponent implements ExplorerManager.Provider, ChangedListener<InputGraphProvider> {
4545

4646
private static BytecodeViewTopComponent instance;
4747
private static final String PREFERRED_ID = "BytecodeViewTopComponent";
48-
private ExplorerManager manager;
49-
private BeanTreeView treeView;
50-
private Lookup.Result result = null;
48+
private final ExplorerManager manager;
49+
private final BeanTreeView treeView;
5150
private MethodNode rootNode;
5251

5352
private BytecodeViewTopComponent() {
@@ -67,32 +66,10 @@ private BytecodeViewTopComponent() {
6766
associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
6867
}
6968

70-
/** This method is called from within the constructor to
71-
* initialize the form.
72-
* WARNING: Do NOT modify this code. The content of this method is
73-
* always regenerated by the Form Editor.
74-
*/
75-
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
76-
private void initComponents() {
77-
78-
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
79-
this.setLayout(layout);
80-
layout.setHorizontalGroup(
81-
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
82-
.add(0, 400, Short.MAX_VALUE)
83-
);
84-
layout.setVerticalGroup(
85-
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
86-
.add(0, 300, Short.MAX_VALUE)
87-
);
88-
}// </editor-fold>//GEN-END:initComponents
89-
// Variables declaration - do not modify//GEN-BEGIN:variables
90-
// End of variables declaration//GEN-END:variables
91-
9269
/**
9370
* Gets default instance. Do not use directly: reserved for *.settings files only,
9471
* i.e. deserialization routines; otherwise you could get a non-deserialized instance.
95-
* To obtain the singleton instance, use {@link findInstance}.
72+
* To obtain the singleton instance, use {@link #findInstance()}.
9673
*/
9774
public static synchronized BytecodeViewTopComponent getDefault() {
9875
if (instance == null) {
@@ -124,15 +101,12 @@ public int getPersistenceType() {
124101

125102
@Override
126103
public void componentOpened() {
127-
Lookup.Template<InputGraphProvider> tpl = new Lookup.Template<>(InputGraphProvider.class);
128-
result = Utilities.actionsGlobalContext().lookup(tpl);
129-
result.addLookupListener(this);
104+
LookupHistory.addListener(InputGraphProvider.class, this);
130105
}
131106

132107
@Override
133108
public void componentClosed() {
134-
result.removeLookupListener(this);
135-
result = null;
109+
LookupHistory.removeListener(InputGraphProvider.class, this);
136110
}
137111

138112
@Override
@@ -169,23 +143,17 @@ protected boolean requestFocusInWindow(boolean temporary) {
169143
}
170144

171145
@Override
172-
public void resultChanged(LookupEvent lookupEvent) {
173-
final InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);//)Utilities.actionsGlobalContext().lookup(InputGraphProvider.class);
174-
SwingUtilities.invokeLater(new Runnable() {
175-
@Override
176-
public void run() {
177-
if (p != null) {
178-
InputGraph graph = p.getGraph();
179-
if (graph != null) {
180-
Group g = graph.getGroup();
181-
rootNode.update(graph, g.getMethod());
182-
return;
183-
}
184-
}
185-
rootNode.update(null, null);
186-
}
187-
});
188-
146+
public void changed(InputGraphProvider lastProvider) {
147+
if (lastProvider != null) {
148+
InputGraph graph = lastProvider.getGraph();
149+
if (graph != null) {
150+
Group g = graph.getGroup();
151+
rootNode.update(graph, g.getMethod());
152+
return;
153+
}
154+
}
155+
rootNode = new MethodNode(null, null, "");
156+
manager.setRootContext(rootNode);
189157
}
190158

191159
static final class ResolvableHelper implements Serializable {
@@ -196,4 +164,26 @@ public Object readResolve() {
196164
return BytecodeViewTopComponent.getDefault();
197165
}
198166
}
167+
168+
/** This method is called from within the constructor to
169+
* initialize the form.
170+
* WARNING: Do NOT modify this code. The content of this method is
171+
* always regenerated by the Form Editor.
172+
*/
173+
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
174+
private void initComponents() {
175+
176+
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
177+
this.setLayout(layout);
178+
layout.setHorizontalGroup(
179+
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
180+
.add(0, 400, Short.MAX_VALUE)
181+
);
182+
layout.setVerticalGroup(
183+
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
184+
.add(0, 300, Short.MAX_VALUE)
185+
);
186+
}// </editor-fold>//GEN-END:initComponents
187+
// Variables declaration - do not modify//GEN-BEGIN:variables
188+
// End of variables declaration//GEN-END:variables
199189
}

src/utils/IdealGraphVisualizer/Bytecodes/src/main/java/com/sun/hotspot/igv/bytecodes/SelectBytecodesAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public final class SelectBytecodesAction extends CookieAction {
3939
@Override
4040
protected void performAction(Node[] activatedNodes) {
4141
SelectBytecodesCookie c = activatedNodes[0].getCookie(SelectBytecodesCookie.class);
42-
InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);//Utilities.actionsGlobalContext().lookup(InputGraphProvider.class);
42+
InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);
4343
if (p != null) {
4444
p.setSelectedNodes(c.getNodes());
4545
}

src/utils/IdealGraphVisualizer/ControlFlow/src/main/java/com/sun/hotspot/igv/controlflow/ControlFlowScene.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void clearSelection() {
133133
}
134134

135135
public void selectionChanged() {
136-
InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);//)Utilities.actionsGlobalContext().lookup(InputGraphProvider.class);
136+
InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);
137137
if (p != null) {
138138
Set<InputNode> inputNodes = new HashSet<InputNode>();
139139
for (BlockWidget w : selection) {

src/utils/IdealGraphVisualizer/ControlFlow/src/main/java/com/sun/hotspot/igv/controlflow/ControlFlowTopComponent.java

+38-51
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2022, 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
@@ -23,32 +23,27 @@
2323
*/
2424
package com.sun.hotspot.igv.controlflow;
2525

26+
import com.sun.hotspot.igv.data.ChangedListener;
2627
import com.sun.hotspot.igv.data.InputGraph;
2728
import com.sun.hotspot.igv.data.services.InputGraphProvider;
2829
import com.sun.hotspot.igv.util.LookupHistory;
2930
import java.awt.BorderLayout;
3031
import java.io.Serializable;
3132
import javax.swing.JScrollPane;
32-
import javax.swing.SwingUtilities;
3333
import org.openide.ErrorManager;
34-
import org.openide.util.Lookup;
35-
import org.openide.util.LookupEvent;
36-
import org.openide.util.LookupListener;
3734
import org.openide.util.NbBundle;
38-
import org.openide.util.Utilities;
3935
import org.openide.windows.TopComponent;
4036
import org.openide.windows.WindowManager;
4137

4238
/**
4339
*
4440
* @author Thomas Wuerthinger
4541
*/
46-
final class ControlFlowTopComponent extends TopComponent implements LookupListener {
42+
final class ControlFlowTopComponent extends TopComponent implements ChangedListener<InputGraphProvider> {
4743

4844
private static ControlFlowTopComponent instance;
49-
private Lookup.Result result = null;
5045
private static final String PREFERRED_ID = "ControlFlowTopComponent";
51-
private ControlFlowScene scene;
46+
private final ControlFlowScene scene;
5247

5348
private ControlFlowTopComponent() {
5449
initComponents();
@@ -64,34 +59,10 @@ private ControlFlowTopComponent() {
6459
this.add(panel, BorderLayout.CENTER);
6560
}
6661

67-
68-
69-
/** This method is called from within the constructor to
70-
* initialize the form.
71-
* WARNING: Do NOT modify this code. The content of this method is
72-
* always regenerated by the Form Editor.
73-
*/
74-
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
75-
private void initComponents() {
76-
77-
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
78-
this.setLayout(layout);
79-
layout.setHorizontalGroup(
80-
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
81-
.add(0, 400, Short.MAX_VALUE)
82-
);
83-
layout.setVerticalGroup(
84-
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
85-
.add(0, 300, Short.MAX_VALUE)
86-
);
87-
}// </editor-fold>//GEN-END:initComponents
88-
// Variables declaration - do not modify//GEN-BEGIN:variables
89-
// End of variables declaration//GEN-END:variables
90-
9162
/**
9263
* Gets default instance. Do not use directly: reserved for *.settings files only,
9364
* i.e. deserialization routines; otherwise you could get a non-deserialized instance.
94-
* To obtain the singleton instance, use {@link findInstance}.
65+
* To obtain the singleton instance, use {@link #findInstance()}.
9566
*/
9667
public static synchronized ControlFlowTopComponent getDefault() {
9768
if (instance == null) {
@@ -123,30 +94,24 @@ public int getPersistenceType() {
12394

12495
@Override
12596
public void componentOpened() {
126-
Lookup.Template<InputGraphProvider> tpl = new Lookup.Template<InputGraphProvider>(InputGraphProvider.class);
127-
result = Utilities.actionsGlobalContext().lookup(tpl);
128-
result.addLookupListener(this);
97+
LookupHistory.addListener(InputGraphProvider.class, this);
12998
}
13099

131100
@Override
132101
public void componentClosed() {
133-
result.removeLookupListener(this);
134-
result = null;
102+
LookupHistory.removeListener(InputGraphProvider.class, this);
135103
}
136104

137-
public void resultChanged(LookupEvent lookupEvent) {
138-
final InputGraphProvider p = LookupHistory.getLast(InputGraphProvider.class);//Utilities.actionsGlobalContext().lookup(InputGraphProvider.class);
139-
if (p != null) {
140-
SwingUtilities.invokeLater(new Runnable() {
141-
142-
public void run() {
143-
InputGraph g = p.getGraph();
144-
if (g != null) {
145-
scene.setGraph(g);
146-
}
147-
}
148-
});
105+
@Override
106+
public void changed(InputGraphProvider lastProvider) {
107+
if (lastProvider != null) {
108+
InputGraph graph = lastProvider.getGraph();
109+
if (graph != null) {
110+
scene.setGraph(graph);
111+
return;
112+
}
149113
}
114+
scene.setGraph(new InputGraph(""));
150115
}
151116

152117
@Override
@@ -173,4 +138,26 @@ public Object readResolve() {
173138
return ControlFlowTopComponent.getDefault();
174139
}
175140
}
141+
142+
/** This method is called from within the constructor to
143+
* initialize the form.
144+
* WARNING: Do NOT modify this code. The content of this method is
145+
* always regenerated by the Form Editor.
146+
*/
147+
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
148+
private void initComponents() {
149+
150+
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
151+
this.setLayout(layout);
152+
layout.setHorizontalGroup(
153+
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
154+
.add(0, 400, Short.MAX_VALUE)
155+
);
156+
layout.setVerticalGroup(
157+
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
158+
.add(0, 300, Short.MAX_VALUE)
159+
);
160+
}// </editor-fold>//GEN-END:initComponents
161+
// Variables declaration - do not modify//GEN-BEGIN:variables
162+
// End of variables declaration//GEN-END:variables
176163
}

0 commit comments

Comments
 (0)