annotate agent/src/share/classes/sun/jvm/hotspot/bugspot/ThreadListPanel.java @ 1913:3b2dea75431e

6984311: JSR 292 needs optional bootstrap method parameters Summary: Allow CONSTANT_InvokeDynamic nodes to have any number of extra operands. Reviewed-by: twisti
author jrose
date Sat, 30 Oct 2010 13:08:23 -0700
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) 2001, 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.bugspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.awt.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.awt.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import javax.swing.table.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.debugger.cdbg.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.ui.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // NOTE: this class was not placed in sun.jvm.hotspot.ui to prevent
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // mixing components designed for C and C++ debugging with the ones
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // that work with the core serviceability agent functionality (which
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // does not require that the CDebugger interface be implemented).
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 /** The ThreadListPanel is used for C and C++ debugging and can
a61af66fc99e Initial load
duke
parents:
diff changeset
44 visualize all threads in the target process. The caller passes in
a61af66fc99e Initial load
duke
parents:
diff changeset
45 a CDebugger attached to the target process and can request that
a61af66fc99e Initial load
duke
parents:
diff changeset
46 JavaThreads' associations with these underlying threads be
a61af66fc99e Initial load
duke
parents:
diff changeset
47 displayed; this option is only valid when attached to a HotSpot
a61af66fc99e Initial load
duke
parents:
diff changeset
48 JVM and when the {@link sun.jvm.hotspot.runtime.VM} has been
a61af66fc99e Initial load
duke
parents:
diff changeset
49 initialized. */
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public class ThreadListPanel extends JPanel {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 /** Listener which can be added to receive "Set Focus" events */
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public static interface Listener {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 /** ThreadProxy will always be provided; JavaThread will only be
a61af66fc99e Initial load
duke
parents:
diff changeset
55 present if displayJavaThreads was specified in the constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
56 for the panel and the thread was a JavaThread. */
a61af66fc99e Initial load
duke
parents:
diff changeset
57 public void setFocus(ThreadProxy thread, JavaThread jthread);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 static class ThreadInfo {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private ThreadProxy thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // Distinguish between PC == null and no top frame
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private boolean gotPC;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 private Address pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 private String location;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 private JavaThread javaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 private String javaThreadName;
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 public ThreadInfo(ThreadProxy thread, CDebugger dbg, JavaThread jthread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 this.thread = thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 this.location = "<unknown>";
a61af66fc99e Initial load
duke
parents:
diff changeset
72 CFrame fr = dbg.topFrameForThread(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 if (fr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 gotPC = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 pc = fr.pc();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 PCFinder.Info info = PCFinder.findPC(pc, fr.loadObjectForPC(), dbg);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 if (info.getName() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 location = info.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 if (info.getConfidence() == PCFinder.LOW_CONFIDENCE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 location = location + " (?)";
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 if (info.getOffset() < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 location = location + " + 0x" + Long.toHexString(info.getOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 if (jthread != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 javaThread = jthread;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 javaThreadName = jthread.getThreadName();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 public ThreadProxy getThread() { return thread; }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 public boolean hasPC() { return gotPC; }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 public Address getPC() { return pc; }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public String getLocation() { return location; }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 public boolean isJavaThread() { return (javaThread != null); }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 public JavaThread getJavaThread() { return javaThread; }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 public String getJavaThreadName() { return javaThreadName; }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // List<ThreadInfo>
a61af66fc99e Initial load
duke
parents:
diff changeset
103 private java.util.List threadList;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 private JTable table;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 private AbstractTableModel dataModel;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // List<Listener>
a61af66fc99e Initial load
duke
parents:
diff changeset
107 private java.util.List listeners;
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 /** Takes a CDebugger from which the thread list is queried.
a61af66fc99e Initial load
duke
parents:
diff changeset
110 displayJavaThreads must only be set to true if the debugger is
a61af66fc99e Initial load
duke
parents:
diff changeset
111 attached to a HotSpot JVM and if the VM has already been
a61af66fc99e Initial load
duke
parents:
diff changeset
112 initialized. */
a61af66fc99e Initial load
duke
parents:
diff changeset
113 public ThreadListPanel(CDebugger dbg, final boolean displayJavaThreads) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 super();
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 Map threadToJavaThreadMap = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 if (displayJavaThreads) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // Collect Java threads from virtual machine and insert them in
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // table for later querying
a61af66fc99e Initial load
duke
parents:
diff changeset
120 threadToJavaThreadMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 Threads threads = VM.getVM().getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
122 for (JavaThread thr = threads.first(); thr != null; thr = thr.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 threadToJavaThreadMap.put(thr.getThreadProxy(), thr);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 java.util.List/*<ThreadProxy>*/ threads = dbg.getThreadList();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 threadList = new ArrayList(threads.size());
a61af66fc99e Initial load
duke
parents:
diff changeset
129 for (Iterator iter = threads.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 ThreadProxy thr = (ThreadProxy) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
131 JavaThread jthr = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 if (displayJavaThreads) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 jthr = (JavaThread) threadToJavaThreadMap.get(thr);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 threadList.add(new ThreadInfo(thr, dbg, jthr));
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // Thread ID, current PC, current symbol, Java Thread, [Java thread name]
a61af66fc99e Initial load
duke
parents:
diff changeset
139 dataModel = new AbstractTableModel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 public int getColumnCount() { return (displayJavaThreads ? 5 : 3); }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 public int getRowCount() { return threadList.size(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 public String getColumnName(int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 switch (col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 case 0:
a61af66fc99e Initial load
duke
parents:
diff changeset
145 return "Thread ID";
a61af66fc99e Initial load
duke
parents:
diff changeset
146 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
147 return "PC";
a61af66fc99e Initial load
duke
parents:
diff changeset
148 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
149 return "Location";
a61af66fc99e Initial load
duke
parents:
diff changeset
150 case 3:
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return "Java?";
a61af66fc99e Initial load
duke
parents:
diff changeset
152 case 4:
a61af66fc99e Initial load
duke
parents:
diff changeset
153 return "Java Thread Name";
a61af66fc99e Initial load
duke
parents:
diff changeset
154 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
155 throw new RuntimeException("Index " + col + " out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 public Object getValueAt(int row, int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 ThreadInfo info = (ThreadInfo) threadList.get(row);
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 switch (col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 case 0:
a61af66fc99e Initial load
duke
parents:
diff changeset
163 return info.getThread();
a61af66fc99e Initial load
duke
parents:
diff changeset
164 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
165 {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 if (info.hasPC()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 return info.getPC();
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169 return "<no frames on stack>";
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
172 return info.getLocation();
a61af66fc99e Initial load
duke
parents:
diff changeset
173 case 3:
a61af66fc99e Initial load
duke
parents:
diff changeset
174 if (info.isJavaThread()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 return "Yes";
a61af66fc99e Initial load
duke
parents:
diff changeset
176 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 return "";
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 case 4:
a61af66fc99e Initial load
duke
parents:
diff changeset
180 if (info.isJavaThread()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 return info.getJavaThreadName();
a61af66fc99e Initial load
duke
parents:
diff changeset
182 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 return "";
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
186 throw new RuntimeException("Index (" + col + ", " + row + ") out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189 };
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // Build user interface
a61af66fc99e Initial load
duke
parents:
diff changeset
192 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
193 table = new JTable(dataModel);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 JTableHeader header = table.getTableHeader();
a61af66fc99e Initial load
duke
parents:
diff changeset
196 header.setReorderingAllowed(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
197 table.setRowSelectionAllowed(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 table.setColumnSelectionAllowed(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 JScrollPane scrollPane = new JScrollPane(table);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 add(scrollPane, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 if (threadList.size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 table.setRowSelectionInterval(0, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 JButton button = new JButton("Set Focus");
a61af66fc99e Initial load
duke
parents:
diff changeset
206 button.addActionListener(new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 int i = table.getSelectedRow();
a61af66fc99e Initial load
duke
parents:
diff changeset
209 if (i < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212 ThreadInfo info = (ThreadInfo) threadList.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 for (Iterator iter = listeners.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 ((Listener) iter.next()).setFocus(info.getThread(), info.getJavaThread());
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 });
a61af66fc99e Initial load
duke
parents:
diff changeset
218 JPanel focusPanel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
219 focusPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
220 focusPanel.setLayout(new BoxLayout(focusPanel, BoxLayout.Y_AXIS));
a61af66fc99e Initial load
duke
parents:
diff changeset
221 focusPanel.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
222 focusPanel.add(button);
a61af66fc99e Initial load
duke
parents:
diff changeset
223 focusPanel.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
224 add(focusPanel, BorderLayout.EAST);
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // FIXME: make listener model for the debugger so if the user
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // specifies a mapfile for or path to a given DSO later we can
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // update our state
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 public void addListener(Listener l) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 if (listeners == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
233 listeners = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235 listeners.add(l);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }