annotate agent/src/share/classes/sun/jvm/hotspot/ui/JavaThreadsPanel.java @ 12226:7944aba7ba41

8015107: NPG: Use consistent naming for metaspace concepts Reviewed-by: coleenp, mgerdin, hseigel
author ehelin
date Mon, 12 Aug 2013 17:37:02 +0200
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.ui;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.awt.BorderLayout;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.awt.Dimension;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.awt.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import javax.swing.event.ListSelectionEvent;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import javax.swing.event.ListSelectionListener;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import javax.swing.table.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 import sun.jvm.hotspot.ui.action.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 import com.sun.java.swing.ui.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 import com.sun.java.swing.action.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
49 * This panel contains a JTable which displays the list of Java
a61af66fc99e Initial load
duke
parents:
diff changeset
50 * threads as their native thread identifiers combined with their
a61af66fc99e Initial load
duke
parents:
diff changeset
51 * Java names. It allows selection and examination of any of the
a61af66fc99e Initial load
duke
parents:
diff changeset
52 * threads.
a61af66fc99e Initial load
duke
parents:
diff changeset
53 */
a61af66fc99e Initial load
duke
parents:
diff changeset
54 public class JavaThreadsPanel extends SAPanel implements ActionListener {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 private JavaThreadsTableModel dataModel;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 private StatusBar statusBar;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 private JTable threadTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private java.util.List cachedThreads = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 /** Constructor assumes the threads panel is created while the VM is
a61af66fc99e Initial load
duke
parents:
diff changeset
62 suspended. Subsequent resume and suspend operations of the VM
a61af66fc99e Initial load
duke
parents:
diff changeset
63 will cause the threads panel to clear and fill itself back in,
a61af66fc99e Initial load
duke
parents:
diff changeset
64 respectively. */
a61af66fc99e Initial load
duke
parents:
diff changeset
65 public JavaThreadsPanel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 VM.getVM().registerVMResumedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 decache();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 });
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 VM.getVM().registerVMSuspendedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 cache();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 });
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 cache();
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 dataModel = new JavaThreadsTableModel(cachedThreads);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 statusBar = new StatusBar();
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 threadTable = new JTable(dataModel, new JavaThreadsColumnModel());
a61af66fc99e Initial load
duke
parents:
diff changeset
86 threadTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 threadTable.addMouseListener(new MouseAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 public void mouseClicked(MouseEvent evt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 if (evt.getClickCount() == 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // double clicking will display the oop inspector.
a61af66fc99e Initial load
duke
parents:
diff changeset
91 fireShowThreadOopInspector();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 });
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 add(new JavaThreadsToolBar(statusBar), BorderLayout.NORTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 add(new ThreadPanel(threadTable), BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 add(statusBar, BorderLayout.SOUTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 registerActions();
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
104 * A splitpane panel which contains the thread table and the Thread Info.
a61af66fc99e Initial load
duke
parents:
diff changeset
105 * the thread info is toggleable
a61af66fc99e Initial load
duke
parents:
diff changeset
106 */
a61af66fc99e Initial load
duke
parents:
diff changeset
107 private class ThreadPanel extends JPanel {
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 private JSplitPane splitPane;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 private JTable threadTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 private ThreadInfoPanel threadInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 private int dividerSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 private int dividerLocation = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 private boolean actionsEnabled = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public ThreadPanel(JTable table) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
118 this.threadInfo = new ThreadInfoPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 this.threadTable = table;
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 splitPane.setOneTouchExpandable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 splitPane.setTopComponent(new JScrollPane(table));
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // Set the size of the divider to 0 but save it so it can be restored
a61af66fc99e Initial load
duke
parents:
diff changeset
126 dividerSize = splitPane.getDividerSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 splitPane.setDividerSize(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 add(splitPane, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // Register an ItemListener on the LogViewerAction which toggles
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // the apearance of the ThreadInfoPanel
a61af66fc99e Initial load
duke
parents:
diff changeset
133 ActionManager manager = HSDBActionManager.getInstance();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 StateChangeAction action = manager.getStateChangeAction(ThreadInfoAction.VALUE_COMMAND);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 if (action != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 action.setItemListener(new ItemListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 public void itemStateChanged(ItemEvent evt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (evt.getStateChange() == ItemEvent.SELECTED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 showOutputPane();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 hideOutputPane();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 });
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // A listener is added to listen to changes in row selection
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // and changes the contents of the ThreadInfoPanel.
a61af66fc99e Initial load
duke
parents:
diff changeset
149 ListSelectionModel selModel = table.getSelectionModel();
a61af66fc99e Initial load
duke
parents:
diff changeset
150 selModel.addListSelectionListener(new ListSelectionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 public void valueChanged(ListSelectionEvent evt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (evt.getValueIsAdjusting() == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 setActionsEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (isInfoVisible()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 showCurrentThreadInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 });
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
163 * Returns a flag to indicate if the thread info is visible
a61af66fc99e Initial load
duke
parents:
diff changeset
164 */
a61af66fc99e Initial load
duke
parents:
diff changeset
165 private boolean isInfoVisible() {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 return (splitPane.getBottomComponent() != null);
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 private void showOutputPane() {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 if (splitPane.getBottomComponent() == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 splitPane.setBottomComponent(threadInfo);
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 if (dividerLocation == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // Calculate the divider location from the pref size.
a61af66fc99e Initial load
duke
parents:
diff changeset
175 Dimension pSize = this.getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 dividerLocation = pSize.height / 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 splitPane.setDividerSize(dividerSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 splitPane.setDividerLocation(dividerLocation);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 showCurrentThreadInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 private void hideOutputPane() {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 dividerLocation = splitPane.getDividerLocation();
a61af66fc99e Initial load
duke
parents:
diff changeset
187 splitPane.remove(threadInfo);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 splitPane.setDividerSize(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 private void showCurrentThreadInfo() {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 int row = threadTable.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
193 if (row >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 threadInfo.setJavaThread(dataModel.getJavaThread(row));
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 private void setActionsEnabled(boolean enabled) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 if (actionsEnabled != enabled) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 ActionManager manager = ActionManager.getInstance();
a61af66fc99e Initial load
duke
parents:
diff changeset
201 manager.setActionEnabled(InspectAction.VALUE_COMMAND, enabled);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 manager.setActionEnabled(MemoryAction.VALUE_COMMAND, enabled);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 manager.setActionEnabled(JavaStackTraceAction.VALUE_COMMAND, enabled);
a61af66fc99e Initial load
duke
parents:
diff changeset
204 actionsEnabled = enabled;
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 } // end ThreadPanel
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 private class JavaThreadsToolBar extends CommonToolBar {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 public JavaThreadsToolBar(StatusBar status) {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 super(HSDBActionManager.getInstance(), status);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 protected void addComponents() {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 addButton(manager.getAction(InspectAction.VALUE_COMMAND));
a61af66fc99e Initial load
duke
parents:
diff changeset
217 addButton(manager.getAction(MemoryAction.VALUE_COMMAND));
a61af66fc99e Initial load
duke
parents:
diff changeset
218 addButton(manager.getAction(JavaStackTraceAction.VALUE_COMMAND));
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 addToggleButton(manager.getStateChangeAction(ThreadInfoAction.VALUE_COMMAND));
a61af66fc99e Initial load
duke
parents:
diff changeset
221 addButton(manager.getAction(FindCrashesAction.VALUE_COMMAND));
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 private class JavaThreadsColumnModel extends DefaultTableColumnModel {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 private String[] columnNames = { "OS Thread ID", "Java Thread Name" };
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 public JavaThreadsColumnModel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // Should actually get the line metrics for
a61af66fc99e Initial load
duke
parents:
diff changeset
230 int PREF_WIDTH = 80;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 int MAX_WIDTH = 100;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 int HUGE_WIDTH = 140;
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 TableColumn column;
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // Thread ID
a61af66fc99e Initial load
duke
parents:
diff changeset
237 column = new TableColumn(0, MAX_WIDTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
238 column.setHeaderValue(columnNames[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
239 column.setMaxWidth(MAX_WIDTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
240 column.setResizable(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
241 addColumn(column);
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // Thread name
a61af66fc99e Initial load
duke
parents:
diff changeset
244 column = new TableColumn(1, HUGE_WIDTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
245 column.setHeaderValue(columnNames[1]);
a61af66fc99e Initial load
duke
parents:
diff changeset
246 column.setResizable(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 addColumn(column);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 } // end class JavaThreadsColumnModel
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
252 * Encapsulates the set of threads in a table model
a61af66fc99e Initial load
duke
parents:
diff changeset
253 */
a61af66fc99e Initial load
duke
parents:
diff changeset
254 private class JavaThreadsTableModel extends AbstractTableModel {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 private String[] columnNames = { "OS Thread ID", "Java Thread Name" };
a61af66fc99e Initial load
duke
parents:
diff changeset
256
a61af66fc99e Initial load
duke
parents:
diff changeset
257 private java.util.List elements;
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 public JavaThreadsTableModel(java.util.List threads) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 this.elements = threads;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263 public int getColumnCount() {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 return columnNames.length;
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 public int getRowCount() {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 return elements.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 public String getColumnName(int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 return columnNames[col];
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 public Object getValueAt(int row, int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 CachedThread thread = getRow(row);
a61af66fc99e Initial load
duke
parents:
diff changeset
277 switch (col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 case 0:
a61af66fc99e Initial load
duke
parents:
diff changeset
279 return thread.getThreadID();
a61af66fc99e Initial load
duke
parents:
diff changeset
280 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
281 return thread.getThreadName();
a61af66fc99e Initial load
duke
parents:
diff changeset
282 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
283 throw new RuntimeException("Index (" + col + ", " + row + ") out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
288 * Returns the selected Java Thread indexed by the row or null.
a61af66fc99e Initial load
duke
parents:
diff changeset
289 */
a61af66fc99e Initial load
duke
parents:
diff changeset
290 public JavaThread getJavaThread(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 return getRow(index).getThread();
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 private CachedThread getRow(int row) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 return (CachedThread)elements.get(row);
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298 private String threadIDAt(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 return ((CachedThread) cachedThreads.get(index)).getThreadID();
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 private String threadNameAt(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 return ((CachedThread) cachedThreads.get(index)).getThreadName();
a61af66fc99e Initial load
duke
parents:
diff changeset
305 } catch (AddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 return "<Error: AddressException>";
a61af66fc99e Initial load
duke
parents:
diff changeset
307 } catch (NullPointerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 return "<Error: NullPointerException>";
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311 } // end class JavaThreadsTableModel
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 public void actionPerformed(ActionEvent evt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 String command = evt.getActionCommand();
a61af66fc99e Initial load
duke
parents:
diff changeset
315
a61af66fc99e Initial load
duke
parents:
diff changeset
316 if (command.equals(InspectAction.VALUE_COMMAND)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 fireShowThreadOopInspector();
a61af66fc99e Initial load
duke
parents:
diff changeset
318 } else if (command.equals(MemoryAction.VALUE_COMMAND)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 fireShowThreadStackMemory();
a61af66fc99e Initial load
duke
parents:
diff changeset
320 } else if (command.equals(ThreadInfoAction.VALUE_COMMAND)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 fireShowThreadInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
322 } else if (command.equals(FindCrashesAction.VALUE_COMMAND)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if (fireShowThreadCrashes()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 statusBar.setMessage("Some thread crashes were encountered");
a61af66fc99e Initial load
duke
parents:
diff changeset
325 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 statusBar.setMessage("No thread crashes encountered");
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328 } else if (command.equals(JavaStackTraceAction.VALUE_COMMAND)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 fireShowJavaStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 // Cached data for a thread
a61af66fc99e Initial load
duke
parents:
diff changeset
334 private class CachedThread {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 private JavaThread thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
336 private String threadID;
a61af66fc99e Initial load
duke
parents:
diff changeset
337 private String threadName;
a61af66fc99e Initial load
duke
parents:
diff changeset
338 private boolean computed;
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 public CachedThread(JavaThread thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 this.thread = thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 public JavaThread getThread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 return thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347
a61af66fc99e Initial load
duke
parents:
diff changeset
348 public String getThreadID() {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 if (!computed) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 compute();
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 return threadID;
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 public String getThreadName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (!computed) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 compute();
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360
a61af66fc99e Initial load
duke
parents:
diff changeset
361 return threadName;
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363
a61af66fc99e Initial load
duke
parents:
diff changeset
364 private void compute() {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 ByteArrayOutputStream bos = new ByteArrayOutputStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
366 thread.printThreadIDOn(new PrintStream(bos));
a61af66fc99e Initial load
duke
parents:
diff changeset
367 threadID = bos.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
368 threadName = thread.getThreadName();
a61af66fc99e Initial load
duke
parents:
diff changeset
369
a61af66fc99e Initial load
duke
parents:
diff changeset
370 computed = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
375 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
376 //
a61af66fc99e Initial load
duke
parents:
diff changeset
377
a61af66fc99e Initial load
duke
parents:
diff changeset
378 protected void registerActions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
379 registerAction(InspectAction.VALUE_COMMAND);
a61af66fc99e Initial load
duke
parents:
diff changeset
380 registerAction(MemoryAction.VALUE_COMMAND);
a61af66fc99e Initial load
duke
parents:
diff changeset
381 registerAction(FindCrashesAction.VALUE_COMMAND);
a61af66fc99e Initial load
duke
parents:
diff changeset
382 registerAction(JavaStackTraceAction.VALUE_COMMAND);
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // disable Inspector, Memory and Java Stack trace action until a thread is selected
a61af66fc99e Initial load
duke
parents:
diff changeset
385 ActionManager manager = ActionManager.getInstance();
a61af66fc99e Initial load
duke
parents:
diff changeset
386 manager.setActionEnabled(InspectAction.VALUE_COMMAND, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
387 manager.setActionEnabled(MemoryAction.VALUE_COMMAND, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
388 manager.setActionEnabled(JavaStackTraceAction.VALUE_COMMAND, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390
a61af66fc99e Initial load
duke
parents:
diff changeset
391 private void registerAction(String actionName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
392 ActionManager manager = ActionManager.getInstance();
a61af66fc99e Initial load
duke
parents:
diff changeset
393 DelegateAction action = manager.getDelegateAction(actionName);
a61af66fc99e Initial load
duke
parents:
diff changeset
394 action.addActionListener(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398
a61af66fc99e Initial load
duke
parents:
diff changeset
399 private void fireShowThreadOopInspector() {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 int i = threadTable.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
401 if (i < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
402 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404
a61af66fc99e Initial load
duke
parents:
diff changeset
405 JavaThread t = dataModel.getJavaThread(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
406 showThreadOopInspector(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408
a61af66fc99e Initial load
duke
parents:
diff changeset
409 private void fireShowThreadStackMemory() {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 int i = threadTable.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
411 if (i < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
412 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414 showThreadStackMemory(dataModel.getJavaThread(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
416
a61af66fc99e Initial load
duke
parents:
diff changeset
417 private void fireShowJavaStackTrace() {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 int i = threadTable.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
419 if (i < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
420 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
422 showJavaStackTrace(dataModel.getJavaThread(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
424
a61af66fc99e Initial load
duke
parents:
diff changeset
425 private void fireShowThreadInfo() {
a61af66fc99e Initial load
duke
parents:
diff changeset
426 int i = threadTable.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
427 if (i < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
428 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 }
a61af66fc99e Initial load
duke
parents:
diff changeset
430 showThreadInfo(dataModel.getJavaThread(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
431 }
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
434 * Shows stack memory for threads which have crashed (defined as
a61af66fc99e Initial load
duke
parents:
diff changeset
435 * having taken a signal above a Java frame)
a61af66fc99e Initial load
duke
parents:
diff changeset
436 *
a61af66fc99e Initial load
duke
parents:
diff changeset
437 * @return a flag which indicates if crashes were encountered.
a61af66fc99e Initial load
duke
parents:
diff changeset
438 */
a61af66fc99e Initial load
duke
parents:
diff changeset
439 private boolean fireShowThreadCrashes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 boolean crash = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
441 for (Iterator iter = cachedThreads.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 JavaThread t = (JavaThread) ((CachedThread) iter.next()).getThread();
a61af66fc99e Initial load
duke
parents:
diff changeset
443 sun.jvm.hotspot.runtime.Frame tmpFrame = t.getCurrentFrameGuess();
a61af66fc99e Initial load
duke
parents:
diff changeset
444 RegisterMap tmpMap = t.newRegisterMap(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
445 while ((tmpFrame != null) && (!tmpFrame.isFirstFrame())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
446 if (tmpFrame.isSignalHandlerFrameDbg()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
447 showThreadStackMemory(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 crash = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
449 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451 tmpFrame = tmpFrame.sender(tmpMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
454 return crash;
a61af66fc99e Initial load
duke
parents:
diff changeset
455 }
a61af66fc99e Initial load
duke
parents:
diff changeset
456
a61af66fc99e Initial load
duke
parents:
diff changeset
457 private void cache() {
a61af66fc99e Initial load
duke
parents:
diff changeset
458 Threads threads = VM.getVM().getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
459 for (JavaThread t = threads.first(); t != null; t = t.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
460 if (t.isJavaThread()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
461 cachedThreads.add(new CachedThread(t));
a61af66fc99e Initial load
duke
parents:
diff changeset
462 }
a61af66fc99e Initial load
duke
parents:
diff changeset
463 }
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465
a61af66fc99e Initial load
duke
parents:
diff changeset
466 private void decache() {
a61af66fc99e Initial load
duke
parents:
diff changeset
467 cachedThreads.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
468 }
a61af66fc99e Initial load
duke
parents:
diff changeset
469
a61af66fc99e Initial load
duke
parents:
diff changeset
470 }