annotate agent/src/share/classes/sun/jvm/hotspot/HSDB.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children ba764ed4b6f2 c70a245cad3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.awt.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.awt.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.math.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import javax.swing.tree.*;
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 sun.jvm.hotspot.code.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.compiler.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.gc_interface.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 import sun.jvm.hotspot.interpreter.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 import sun.jvm.hotspot.ui.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 import sun.jvm.hotspot.ui.tree.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 import sun.jvm.hotspot.ui.classbrowser.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 /** The top-level HotSpot Debugger. FIXME: make this an embeddable
a61af66fc99e Initial load
duke
parents:
diff changeset
50 component! (Among other things, figure out what to do with the
a61af66fc99e Initial load
duke
parents:
diff changeset
51 menu bar...) */
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public class HSDB implements ObjectHistogramPanel.Listener, SAListener {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 new HSDB(args).run();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
60 //
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private HotSpotAgent agent;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private JDesktopPane desktop;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private boolean attached;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 /** List <JMenuItem> */
a61af66fc99e Initial load
duke
parents:
diff changeset
65 private java.util.List attachMenuItems;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 /** List <JMenuItem> */
a61af66fc99e Initial load
duke
parents:
diff changeset
67 private java.util.List detachMenuItems;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 private JMenu toolsMenu;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 private JMenuItem showDbgConsoleMenuItem;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 private JMenuItem computeRevPtrsMenuItem;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 private JInternalFrame attachWaitDialog;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private JInternalFrame threadsFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private JInternalFrame consoleFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 private WorkerThread workerThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // These had to be made data members because they are referenced in inner classes.
a61af66fc99e Initial load
duke
parents:
diff changeset
76 private String pidText;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 private int pid;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 private String execPath;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 private String coreFilename;
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 private void doUsage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 System.out.println("Usage: java HSDB [[pid] | [path-to-java-executable [path-to-corefile]] | help ]");
a61af66fc99e Initial load
duke
parents:
diff changeset
83 System.out.println(" pid: attach to the process whose id is 'pid'");
a61af66fc99e Initial load
duke
parents:
diff changeset
84 System.out.println(" path-to-java-executable: Debug a core file produced by this program");
a61af66fc99e Initial load
duke
parents:
diff changeset
85 System.out.println(" path-to-corefile: Debug this corefile. The default is 'core'");
a61af66fc99e Initial load
duke
parents:
diff changeset
86 System.out.println(" If no arguments are specified, you can select what to do from the GUI.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
87 HotSpotAgent.showUsage();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 private HSDB(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 switch (args.length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 case (0):
a61af66fc99e Initial load
duke
parents:
diff changeset
93 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 case (1):
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (args[0].equals("help") || args[0].equals("-help")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 doUsage();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 System.exit(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // If all numbers, it is a PID to attach to
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // Else, it is a pathname to a .../bin/java for a core file.
a61af66fc99e Initial load
duke
parents:
diff changeset
102 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 int unused = Integer.parseInt(args[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // If we get here, we have a PID and not a core file name
a61af66fc99e Initial load
duke
parents:
diff changeset
105 pidText = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
106 } catch (NumberFormatException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 execPath = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
108 coreFilename = "core";
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 case (2):
a61af66fc99e Initial load
duke
parents:
diff changeset
113 execPath = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
114 coreFilename = args[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
115 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
118 System.out.println("HSDB Error: Too many options specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
119 doUsage();
a61af66fc99e Initial load
duke
parents:
diff changeset
120 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 private void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // At this point, if pidText != null we are supposed to attach to it.
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // Else, if execPath != null, it is the path of a jdk/bin/java
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // and coreFilename is the pathname of a core file we are
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // supposed to attach to.
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 agent = new HotSpotAgent();
a61af66fc99e Initial load
duke
parents:
diff changeset
131 workerThread = new WorkerThread();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 attachMenuItems = new java.util.ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
133 detachMenuItems = new java.util.ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 JFrame frame = new JFrame("HSDB - HotSpot Debugger");
a61af66fc99e Initial load
duke
parents:
diff changeset
136 frame.setSize(800, 600);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 JMenuBar menuBar = new JMenuBar();
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 //
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // File menu
a61af66fc99e Initial load
duke
parents:
diff changeset
143 //
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 JMenu menu = new JMenu("File");
a61af66fc99e Initial load
duke
parents:
diff changeset
146 menu.setMnemonic(KeyEvent.VK_F);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 JMenuItem item;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 item = createMenuItem("Attach to HotSpot process...",
a61af66fc99e Initial load
duke
parents:
diff changeset
149 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 showAttachDialog();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 });
a61af66fc99e Initial load
duke
parents:
diff changeset
154 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.ALT_MASK));
a61af66fc99e Initial load
duke
parents:
diff changeset
155 item.setMnemonic(KeyEvent.VK_A);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 menu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 attachMenuItems.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 item = createMenuItem("Open HotSpot core file...",
a61af66fc99e Initial load
duke
parents:
diff changeset
160 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 showOpenCoreFileDialog();
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 });
a61af66fc99e Initial load
duke
parents:
diff changeset
165 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.ALT_MASK));
a61af66fc99e Initial load
duke
parents:
diff changeset
166 item.setMnemonic(KeyEvent.VK_O);
a61af66fc99e Initial load
duke
parents:
diff changeset
167 menu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 attachMenuItems.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 item = createMenuItem("Connect to debug server...",
a61af66fc99e Initial load
duke
parents:
diff changeset
171 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 showConnectDialog();
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 });
a61af66fc99e Initial load
duke
parents:
diff changeset
176 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.ALT_MASK));
a61af66fc99e Initial load
duke
parents:
diff changeset
177 item.setMnemonic(KeyEvent.VK_S);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 menu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 attachMenuItems.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 item = createMenuItem("Detach",
a61af66fc99e Initial load
duke
parents:
diff changeset
182 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186 });
a61af66fc99e Initial load
duke
parents:
diff changeset
187 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.ALT_MASK));
a61af66fc99e Initial load
duke
parents:
diff changeset
188 item.setMnemonic(KeyEvent.VK_S);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 menu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
190 detachMenuItems.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // Disable detach menu items at first
a61af66fc99e Initial load
duke
parents:
diff changeset
193 setMenuItemsEnabled(detachMenuItems, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 menu.addSeparator();
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 item = createMenuItem("Exit",
a61af66fc99e Initial load
duke
parents:
diff changeset
198 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 System.exit(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 });
a61af66fc99e Initial load
duke
parents:
diff changeset
203 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.ALT_MASK));
a61af66fc99e Initial load
duke
parents:
diff changeset
204 item.setMnemonic(KeyEvent.VK_X);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 menu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 menuBar.add(menu);
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 //
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // Tools menu
a61af66fc99e Initial load
duke
parents:
diff changeset
210 //
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 toolsMenu = new JMenu("Tools");
a61af66fc99e Initial load
duke
parents:
diff changeset
213 toolsMenu.setMnemonic(KeyEvent.VK_T);
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 item = createMenuItem("Class Browser",
a61af66fc99e Initial load
duke
parents:
diff changeset
216 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 showClassBrowser();
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 });
a61af66fc99e Initial load
duke
parents:
diff changeset
221 item.setMnemonic(KeyEvent.VK_B);
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 item = createMenuItem("Code Viewer",
a61af66fc99e Initial load
duke
parents:
diff changeset
226 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 showCodeViewer();
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 });
a61af66fc99e Initial load
duke
parents:
diff changeset
231 item.setMnemonic(KeyEvent.VK_C);
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 item = createMenuItem("Compute Reverse Ptrs",
a61af66fc99e Initial load
duke
parents:
diff changeset
237 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 fireComputeReversePtrs();
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241 });
a61af66fc99e Initial load
duke
parents:
diff changeset
242 computeRevPtrsMenuItem = item;
a61af66fc99e Initial load
duke
parents:
diff changeset
243 item.setMnemonic(KeyEvent.VK_M);
a61af66fc99e Initial load
duke
parents:
diff changeset
244 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 item = createMenuItem("Deadlock Detection",
a61af66fc99e Initial load
duke
parents:
diff changeset
247 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 showDeadlockDetectionPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251 });
a61af66fc99e Initial load
duke
parents:
diff changeset
252 item.setMnemonic(KeyEvent.VK_D);
a61af66fc99e Initial load
duke
parents:
diff changeset
253 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 item = createMenuItem("Find Object by Query",
a61af66fc99e Initial load
duke
parents:
diff changeset
256 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 showFindByQueryPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 });
a61af66fc99e Initial load
duke
parents:
diff changeset
261 item.setMnemonic(KeyEvent.VK_Q);
a61af66fc99e Initial load
duke
parents:
diff changeset
262 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 item = createMenuItem("Find Pointer",
a61af66fc99e Initial load
duke
parents:
diff changeset
266 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 showFindPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270 });
a61af66fc99e Initial load
duke
parents:
diff changeset
271 item.setMnemonic(KeyEvent.VK_P);
a61af66fc99e Initial load
duke
parents:
diff changeset
272 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 item = createMenuItem("Find Value In Heap",
a61af66fc99e Initial load
duke
parents:
diff changeset
275 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 showFindInHeapPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279 });
a61af66fc99e Initial load
duke
parents:
diff changeset
280 item.setMnemonic(KeyEvent.VK_V);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 item = createMenuItem("Find Value In Code Cache",
a61af66fc99e Initial load
duke
parents:
diff changeset
284 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 showFindInCodeCachePanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288 });
a61af66fc99e Initial load
duke
parents:
diff changeset
289 item.setMnemonic(KeyEvent.VK_A);
a61af66fc99e Initial load
duke
parents:
diff changeset
290 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292 item = createMenuItem("Heap Parameters",
a61af66fc99e Initial load
duke
parents:
diff changeset
293 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
294 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 showHeapParametersPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297 });
a61af66fc99e Initial load
duke
parents:
diff changeset
298 item.setMnemonic(KeyEvent.VK_H);
a61af66fc99e Initial load
duke
parents:
diff changeset
299 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 item = createMenuItem("Inspector",
a61af66fc99e Initial load
duke
parents:
diff changeset
302 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 showInspector(null);
a61af66fc99e Initial load
duke
parents:
diff changeset
305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
306 });
a61af66fc99e Initial load
duke
parents:
diff changeset
307 item.setMnemonic(KeyEvent.VK_R);
a61af66fc99e Initial load
duke
parents:
diff changeset
308 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK));
a61af66fc99e Initial load
duke
parents:
diff changeset
309 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
310
a61af66fc99e Initial load
duke
parents:
diff changeset
311 item = createMenuItem("Memory Viewer",
a61af66fc99e Initial load
duke
parents:
diff changeset
312 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 showMemoryViewer();
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316 });
a61af66fc99e Initial load
duke
parents:
diff changeset
317 item.setMnemonic(KeyEvent.VK_M);
a61af66fc99e Initial load
duke
parents:
diff changeset
318 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 item = createMenuItem("Monitor Cache Dump",
a61af66fc99e Initial load
duke
parents:
diff changeset
321 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 showMonitorCacheDumpPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325 });
a61af66fc99e Initial load
duke
parents:
diff changeset
326 item.setMnemonic(KeyEvent.VK_D);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
328
a61af66fc99e Initial load
duke
parents:
diff changeset
329 item = createMenuItem("Object Histogram",
a61af66fc99e Initial load
duke
parents:
diff changeset
330 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
331 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
332 showObjectHistogram();
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334 });
a61af66fc99e Initial load
duke
parents:
diff changeset
335 item.setMnemonic(KeyEvent.VK_O);
a61af66fc99e Initial load
duke
parents:
diff changeset
336 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 item = createMenuItem("Show System Properties",
a61af66fc99e Initial load
duke
parents:
diff changeset
339 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 showSystemProperties();
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343 });
a61af66fc99e Initial load
duke
parents:
diff changeset
344 item.setMnemonic(KeyEvent.VK_S);
a61af66fc99e Initial load
duke
parents:
diff changeset
345 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 item = createMenuItem("Show VM Version",
a61af66fc99e Initial load
duke
parents:
diff changeset
348 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 showVMVersion();
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352 });
a61af66fc99e Initial load
duke
parents:
diff changeset
353 item.setMnemonic(KeyEvent.VK_M);
a61af66fc99e Initial load
duke
parents:
diff changeset
354 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 item = createMenuItem("Show -XX flags",
a61af66fc99e Initial load
duke
parents:
diff changeset
357 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 showCommandLineFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361 });
a61af66fc99e Initial load
duke
parents:
diff changeset
362 item.setMnemonic(KeyEvent.VK_X);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 toolsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 toolsMenu.setEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
366 menuBar.add(toolsMenu);
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 //
a61af66fc99e Initial load
duke
parents:
diff changeset
369 // Windows menu
a61af66fc99e Initial load
duke
parents:
diff changeset
370 //
a61af66fc99e Initial load
duke
parents:
diff changeset
371
a61af66fc99e Initial load
duke
parents:
diff changeset
372 JMenu windowsMenu = new JMenu("Windows");
a61af66fc99e Initial load
duke
parents:
diff changeset
373 windowsMenu.setMnemonic(KeyEvent.VK_W);
a61af66fc99e Initial load
duke
parents:
diff changeset
374 item = createMenuItem("Console",
a61af66fc99e Initial load
duke
parents:
diff changeset
375 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 showConsole();
a61af66fc99e Initial load
duke
parents:
diff changeset
378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
379 });
a61af66fc99e Initial load
duke
parents:
diff changeset
380 item.setMnemonic(KeyEvent.VK_C);
a61af66fc99e Initial load
duke
parents:
diff changeset
381 windowsMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
382 showDbgConsoleMenuItem = createMenuItem("Debugger Console",
a61af66fc99e Initial load
duke
parents:
diff changeset
383 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
385 showDebuggerConsole();
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387 });
a61af66fc99e Initial load
duke
parents:
diff changeset
388 showDbgConsoleMenuItem.setMnemonic(KeyEvent.VK_D);
a61af66fc99e Initial load
duke
parents:
diff changeset
389 windowsMenu.add(showDbgConsoleMenuItem);
a61af66fc99e Initial load
duke
parents:
diff changeset
390 showDbgConsoleMenuItem.setEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
391
a61af66fc99e Initial load
duke
parents:
diff changeset
392 menuBar.add(windowsMenu);
a61af66fc99e Initial load
duke
parents:
diff changeset
393
a61af66fc99e Initial load
duke
parents:
diff changeset
394
a61af66fc99e Initial load
duke
parents:
diff changeset
395 frame.setJMenuBar(menuBar);
a61af66fc99e Initial load
duke
parents:
diff changeset
396
a61af66fc99e Initial load
duke
parents:
diff changeset
397 desktop = new JDesktopPane();
a61af66fc99e Initial load
duke
parents:
diff changeset
398 frame.getContentPane().add(desktop);
a61af66fc99e Initial load
duke
parents:
diff changeset
399 GraphicsUtilities.reshapeToAspectRatio(frame, 4.0f/3.0f, 0.75f, Toolkit.getDefaultToolkit().getScreenSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
400 GraphicsUtilities.centerInContainer(frame, Toolkit.getDefaultToolkit().getScreenSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
401 frame.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403 Runtime.getRuntime().addShutdownHook(new java.lang.Thread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
404 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 detachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
407 });
a61af66fc99e Initial load
duke
parents:
diff changeset
408
a61af66fc99e Initial load
duke
parents:
diff changeset
409 if (pidText != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 attach(pidText);
a61af66fc99e Initial load
duke
parents:
diff changeset
411 } else if (execPath != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
412 attach(execPath, coreFilename);
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
415
a61af66fc99e Initial load
duke
parents:
diff changeset
416 // FIXME: merge showAttachDialog, showOpenCoreFileDialog, showConnectDialog
a61af66fc99e Initial load
duke
parents:
diff changeset
417 private void showAttachDialog() {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 // FIXME: create filtered text field which only accepts numbers
a61af66fc99e Initial load
duke
parents:
diff changeset
419 setMenuItemsEnabled(attachMenuItems, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
420 final JInternalFrame attachDialog = new JInternalFrame("Attach to HotSpot process");
a61af66fc99e Initial load
duke
parents:
diff changeset
421 attachDialog.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 JPanel panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
424 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
a61af66fc99e Initial load
duke
parents:
diff changeset
425 panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
a61af66fc99e Initial load
duke
parents:
diff changeset
426 attachDialog.setBackground(panel.getBackground());
a61af66fc99e Initial load
duke
parents:
diff changeset
427
a61af66fc99e Initial load
duke
parents:
diff changeset
428 panel.add(new JLabel("Enter process ID:"));
a61af66fc99e Initial load
duke
parents:
diff changeset
429 final JTextField pidTextField = new JTextField(10);
a61af66fc99e Initial load
duke
parents:
diff changeset
430 ActionListener attacher = new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
431 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 attachDialog.setVisible(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
433 desktop.remove(attachDialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
434 workerThread.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
435 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
436 attach(pidTextField.getText());
a61af66fc99e Initial load
duke
parents:
diff changeset
437 }
a61af66fc99e Initial load
duke
parents:
diff changeset
438 });
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440 };
a61af66fc99e Initial load
duke
parents:
diff changeset
441
a61af66fc99e Initial load
duke
parents:
diff changeset
442 pidTextField.addActionListener(attacher);
a61af66fc99e Initial load
duke
parents:
diff changeset
443 panel.add(pidTextField);
a61af66fc99e Initial load
duke
parents:
diff changeset
444 attachDialog.getContentPane().add(panel, BorderLayout.NORTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 Box vbox = Box.createVerticalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
447 panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
448 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
a61af66fc99e Initial load
duke
parents:
diff changeset
449 panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
a61af66fc99e Initial load
duke
parents:
diff changeset
450 JTextArea ta = new JTextArea(
a61af66fc99e Initial load
duke
parents:
diff changeset
451 "Enter the process ID of a currently-running HotSpot process. On " +
a61af66fc99e Initial load
duke
parents:
diff changeset
452 "Solaris and most Unix operating systems, this can be determined by " +
a61af66fc99e Initial load
duke
parents:
diff changeset
453 "typing \"ps -u <your username> | grep java\"; the process ID is the " +
a61af66fc99e Initial load
duke
parents:
diff changeset
454 "first number which appears on the resulting line. On Windows, the " +
a61af66fc99e Initial load
duke
parents:
diff changeset
455 "process ID is present in the Task Manager, which can be brought up " +
a61af66fc99e Initial load
duke
parents:
diff changeset
456 "while logged on to the desktop by pressing Ctrl-Alt-Delete.");
a61af66fc99e Initial load
duke
parents:
diff changeset
457 ta.setLineWrap(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
458 ta.setWrapStyleWord(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
459 ta.setEditable(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
460 ta.setBackground(panel.getBackground());
a61af66fc99e Initial load
duke
parents:
diff changeset
461 panel.add(ta);
a61af66fc99e Initial load
duke
parents:
diff changeset
462 vbox.add(panel);
a61af66fc99e Initial load
duke
parents:
diff changeset
463
a61af66fc99e Initial load
duke
parents:
diff changeset
464 Box hbox = Box.createHorizontalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
465 hbox.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
466 JButton button = new JButton("OK");
a61af66fc99e Initial load
duke
parents:
diff changeset
467 button.addActionListener(attacher);
a61af66fc99e Initial load
duke
parents:
diff changeset
468 hbox.add(button);
a61af66fc99e Initial load
duke
parents:
diff changeset
469 hbox.add(Box.createHorizontalStrut(20));
a61af66fc99e Initial load
duke
parents:
diff changeset
470 button = new JButton("Cancel");
a61af66fc99e Initial load
duke
parents:
diff changeset
471 button.addActionListener(new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
472 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
473 attachDialog.setVisible(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
474 desktop.remove(attachDialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
475 setMenuItemsEnabled(attachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
476 }
a61af66fc99e Initial load
duke
parents:
diff changeset
477 });
a61af66fc99e Initial load
duke
parents:
diff changeset
478 hbox.add(button);
a61af66fc99e Initial load
duke
parents:
diff changeset
479 hbox.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
480 panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
481 panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
a61af66fc99e Initial load
duke
parents:
diff changeset
482 panel.add(hbox);
a61af66fc99e Initial load
duke
parents:
diff changeset
483 vbox.add(panel);
a61af66fc99e Initial load
duke
parents:
diff changeset
484
a61af66fc99e Initial load
duke
parents:
diff changeset
485 attachDialog.getContentPane().add(vbox, BorderLayout.SOUTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
486
a61af66fc99e Initial load
duke
parents:
diff changeset
487 desktop.add(attachDialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
488 attachDialog.setSize(400, 300);
a61af66fc99e Initial load
duke
parents:
diff changeset
489 GraphicsUtilities.centerInContainer(attachDialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
490 attachDialog.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
491 pidTextField.requestFocus();
a61af66fc99e Initial load
duke
parents:
diff changeset
492 }
a61af66fc99e Initial load
duke
parents:
diff changeset
493
a61af66fc99e Initial load
duke
parents:
diff changeset
494 // FIXME: merge showAttachDialog, showOpenCoreFileDialog, showConnectDialog
a61af66fc99e Initial load
duke
parents:
diff changeset
495 private void showOpenCoreFileDialog() {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 setMenuItemsEnabled(attachMenuItems, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
497 final JInternalFrame dialog = new JInternalFrame("Open Core File");
a61af66fc99e Initial load
duke
parents:
diff changeset
498 dialog.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
499
a61af66fc99e Initial load
duke
parents:
diff changeset
500 JPanel panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
501 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
a61af66fc99e Initial load
duke
parents:
diff changeset
502 panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
a61af66fc99e Initial load
duke
parents:
diff changeset
503 dialog.setBackground(panel.getBackground());
a61af66fc99e Initial load
duke
parents:
diff changeset
504
a61af66fc99e Initial load
duke
parents:
diff changeset
505 Box hbox = Box.createHorizontalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
506 Box vbox = Box.createVerticalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
507 vbox.add(new JLabel("Path to core file:"));
a61af66fc99e Initial load
duke
parents:
diff changeset
508 vbox.add(new JLabel("Path to Java executable:"));
a61af66fc99e Initial load
duke
parents:
diff changeset
509 hbox.add(vbox);
a61af66fc99e Initial load
duke
parents:
diff changeset
510
a61af66fc99e Initial load
duke
parents:
diff changeset
511 vbox = Box.createVerticalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
512 final JTextField corePathField = new JTextField(40);
a61af66fc99e Initial load
duke
parents:
diff changeset
513 final JTextField execPathField = new JTextField(40);
a61af66fc99e Initial load
duke
parents:
diff changeset
514 vbox.add(corePathField);
a61af66fc99e Initial load
duke
parents:
diff changeset
515 vbox.add(execPathField);
a61af66fc99e Initial load
duke
parents:
diff changeset
516 hbox.add(vbox);
a61af66fc99e Initial load
duke
parents:
diff changeset
517
a61af66fc99e Initial load
duke
parents:
diff changeset
518 final JButton browseCorePath = new JButton("Browse ..");
a61af66fc99e Initial load
duke
parents:
diff changeset
519 final JButton browseExecPath = new JButton("Browse ..");
a61af66fc99e Initial load
duke
parents:
diff changeset
520 browseCorePath.addActionListener(new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
521 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
522 JFileChooser fileChooser = new JFileChooser(new File("."));
a61af66fc99e Initial load
duke
parents:
diff changeset
523 int retVal = fileChooser.showOpenDialog(dialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
524 if (retVal == JFileChooser.APPROVE_OPTION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
525 corePathField.setText(fileChooser.getSelectedFile().getPath());
a61af66fc99e Initial load
duke
parents:
diff changeset
526 }
a61af66fc99e Initial load
duke
parents:
diff changeset
527 }
a61af66fc99e Initial load
duke
parents:
diff changeset
528 });
a61af66fc99e Initial load
duke
parents:
diff changeset
529 browseExecPath.addActionListener(new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
530 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
531 JFileChooser fileChooser = new JFileChooser(new File("."));
a61af66fc99e Initial load
duke
parents:
diff changeset
532 int retVal = fileChooser.showOpenDialog(dialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
533 if (retVal == JFileChooser.APPROVE_OPTION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
534 execPathField.setText(fileChooser.getSelectedFile().getPath());
a61af66fc99e Initial load
duke
parents:
diff changeset
535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
536 }
a61af66fc99e Initial load
duke
parents:
diff changeset
537 });
a61af66fc99e Initial load
duke
parents:
diff changeset
538 vbox = Box.createVerticalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
539 vbox.add(browseCorePath);
a61af66fc99e Initial load
duke
parents:
diff changeset
540 vbox.add(browseExecPath);
a61af66fc99e Initial load
duke
parents:
diff changeset
541 hbox.add(vbox);
a61af66fc99e Initial load
duke
parents:
diff changeset
542
a61af66fc99e Initial load
duke
parents:
diff changeset
543 panel.add(hbox);
a61af66fc99e Initial load
duke
parents:
diff changeset
544 dialog.getContentPane().add(panel, BorderLayout.NORTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
545
a61af66fc99e Initial load
duke
parents:
diff changeset
546 ActionListener attacher = new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
547 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
548 dialog.setVisible(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
549 desktop.remove(dialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
550 workerThread.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
551 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
552 attach(execPathField.getText(), corePathField.getText());
a61af66fc99e Initial load
duke
parents:
diff changeset
553 }
a61af66fc99e Initial load
duke
parents:
diff changeset
554 });
a61af66fc99e Initial load
duke
parents:
diff changeset
555 }
a61af66fc99e Initial load
duke
parents:
diff changeset
556 };
a61af66fc99e Initial load
duke
parents:
diff changeset
557 corePathField.addActionListener(attacher);
a61af66fc99e Initial load
duke
parents:
diff changeset
558 execPathField.addActionListener(attacher);
a61af66fc99e Initial load
duke
parents:
diff changeset
559
a61af66fc99e Initial load
duke
parents:
diff changeset
560 vbox = Box.createVerticalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
561 panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
562 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
a61af66fc99e Initial load
duke
parents:
diff changeset
563 panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
a61af66fc99e Initial load
duke
parents:
diff changeset
564 JTextArea ta = new JTextArea(
a61af66fc99e Initial load
duke
parents:
diff changeset
565 "Enter the full path names to the core file from a HotSpot process " +
a61af66fc99e Initial load
duke
parents:
diff changeset
566 "and the Java executable from which it came. The latter is typically " +
a61af66fc99e Initial load
duke
parents:
diff changeset
567 "located in the JDK/JRE directory under the directory " +
a61af66fc99e Initial load
duke
parents:
diff changeset
568 "jre/bin/<arch>/native_threads.");
a61af66fc99e Initial load
duke
parents:
diff changeset
569 ta.setLineWrap(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
570 ta.setWrapStyleWord(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
571 ta.setEditable(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
572 ta.setBackground(panel.getBackground());
a61af66fc99e Initial load
duke
parents:
diff changeset
573 panel.add(ta);
a61af66fc99e Initial load
duke
parents:
diff changeset
574 vbox.add(panel);
a61af66fc99e Initial load
duke
parents:
diff changeset
575
a61af66fc99e Initial load
duke
parents:
diff changeset
576 hbox = Box.createHorizontalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
577 hbox.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
578 JButton button = new JButton("OK");
a61af66fc99e Initial load
duke
parents:
diff changeset
579 button.addActionListener(attacher);
a61af66fc99e Initial load
duke
parents:
diff changeset
580 hbox.add(button);
a61af66fc99e Initial load
duke
parents:
diff changeset
581 hbox.add(Box.createHorizontalStrut(20));
a61af66fc99e Initial load
duke
parents:
diff changeset
582 button = new JButton("Cancel");
a61af66fc99e Initial load
duke
parents:
diff changeset
583 button.addActionListener(new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
584 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
585 dialog.setVisible(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
586 desktop.remove(dialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
587 setMenuItemsEnabled(attachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
589 });
a61af66fc99e Initial load
duke
parents:
diff changeset
590 hbox.add(button);
a61af66fc99e Initial load
duke
parents:
diff changeset
591 hbox.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
592 panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
593 panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
a61af66fc99e Initial load
duke
parents:
diff changeset
594 panel.add(hbox);
a61af66fc99e Initial load
duke
parents:
diff changeset
595 vbox.add(panel);
a61af66fc99e Initial load
duke
parents:
diff changeset
596
a61af66fc99e Initial load
duke
parents:
diff changeset
597 dialog.getContentPane().add(vbox, BorderLayout.SOUTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
598
a61af66fc99e Initial load
duke
parents:
diff changeset
599 desktop.add(dialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
600 dialog.setSize(500, 300);
a61af66fc99e Initial load
duke
parents:
diff changeset
601 GraphicsUtilities.centerInContainer(dialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
602 dialog.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
603 corePathField.requestFocus();
a61af66fc99e Initial load
duke
parents:
diff changeset
604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
605
a61af66fc99e Initial load
duke
parents:
diff changeset
606 // FIXME: merge showAttachDialog, showOpenCoreFileDialog, showConnectDialog
a61af66fc99e Initial load
duke
parents:
diff changeset
607 private void showConnectDialog() {
a61af66fc99e Initial load
duke
parents:
diff changeset
608 // FIXME: create filtered text field which only accepts numbers
a61af66fc99e Initial load
duke
parents:
diff changeset
609 setMenuItemsEnabled(attachMenuItems, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
610 final JInternalFrame dialog = new JInternalFrame("Connect to HotSpot Debug Server");
a61af66fc99e Initial load
duke
parents:
diff changeset
611 dialog.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
612
a61af66fc99e Initial load
duke
parents:
diff changeset
613 JPanel panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
614 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
a61af66fc99e Initial load
duke
parents:
diff changeset
615 panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
a61af66fc99e Initial load
duke
parents:
diff changeset
616 dialog.setBackground(panel.getBackground());
a61af66fc99e Initial load
duke
parents:
diff changeset
617
a61af66fc99e Initial load
duke
parents:
diff changeset
618 panel.add(new JLabel("Enter machine name:"));
a61af66fc99e Initial load
duke
parents:
diff changeset
619 final JTextField pidTextField = new JTextField(40);
a61af66fc99e Initial load
duke
parents:
diff changeset
620 ActionListener attacher = new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
621 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
622 dialog.setVisible(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
623 desktop.remove(dialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
624 workerThread.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
625 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
626 connect(pidTextField.getText());
a61af66fc99e Initial load
duke
parents:
diff changeset
627 }
a61af66fc99e Initial load
duke
parents:
diff changeset
628 });
a61af66fc99e Initial load
duke
parents:
diff changeset
629 }
a61af66fc99e Initial load
duke
parents:
diff changeset
630 };
a61af66fc99e Initial load
duke
parents:
diff changeset
631
a61af66fc99e Initial load
duke
parents:
diff changeset
632 pidTextField.addActionListener(attacher);
a61af66fc99e Initial load
duke
parents:
diff changeset
633 panel.add(pidTextField);
a61af66fc99e Initial load
duke
parents:
diff changeset
634 dialog.getContentPane().add(panel, BorderLayout.NORTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
635
a61af66fc99e Initial load
duke
parents:
diff changeset
636 Box vbox = Box.createVerticalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
637 panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
638 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
a61af66fc99e Initial load
duke
parents:
diff changeset
639 panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
a61af66fc99e Initial load
duke
parents:
diff changeset
640 JTextArea ta = new JTextArea(
a61af66fc99e Initial load
duke
parents:
diff changeset
641 "Enter the name of a machine on which the HotSpot \"Debug Server\" is " +
a61af66fc99e Initial load
duke
parents:
diff changeset
642 "running and is attached to a process or core file.");
a61af66fc99e Initial load
duke
parents:
diff changeset
643 ta.setLineWrap(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
644 ta.setWrapStyleWord(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
645 ta.setEditable(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
646 ta.setBackground(panel.getBackground());
a61af66fc99e Initial load
duke
parents:
diff changeset
647 panel.add(ta);
a61af66fc99e Initial load
duke
parents:
diff changeset
648 vbox.add(panel);
a61af66fc99e Initial load
duke
parents:
diff changeset
649
a61af66fc99e Initial load
duke
parents:
diff changeset
650 Box hbox = Box.createHorizontalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
651 hbox.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
652 JButton button = new JButton("OK");
a61af66fc99e Initial load
duke
parents:
diff changeset
653 button.addActionListener(attacher);
a61af66fc99e Initial load
duke
parents:
diff changeset
654 hbox.add(button);
a61af66fc99e Initial load
duke
parents:
diff changeset
655 hbox.add(Box.createHorizontalStrut(20));
a61af66fc99e Initial load
duke
parents:
diff changeset
656 button = new JButton("Cancel");
a61af66fc99e Initial load
duke
parents:
diff changeset
657 button.addActionListener(new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
658 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
659 dialog.setVisible(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
660 desktop.remove(dialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
661 setMenuItemsEnabled(attachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
662 }
a61af66fc99e Initial load
duke
parents:
diff changeset
663 });
a61af66fc99e Initial load
duke
parents:
diff changeset
664 hbox.add(button);
a61af66fc99e Initial load
duke
parents:
diff changeset
665 hbox.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
666 panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
667 panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
a61af66fc99e Initial load
duke
parents:
diff changeset
668 panel.add(hbox);
a61af66fc99e Initial load
duke
parents:
diff changeset
669 vbox.add(panel);
a61af66fc99e Initial load
duke
parents:
diff changeset
670
a61af66fc99e Initial load
duke
parents:
diff changeset
671 dialog.getContentPane().add(vbox, BorderLayout.SOUTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
672
a61af66fc99e Initial load
duke
parents:
diff changeset
673 desktop.add(dialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
674 dialog.setSize(400, 300);
a61af66fc99e Initial load
duke
parents:
diff changeset
675 GraphicsUtilities.centerInContainer(dialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
676 dialog.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
677 pidTextField.requestFocus();
a61af66fc99e Initial load
duke
parents:
diff changeset
678 }
a61af66fc99e Initial load
duke
parents:
diff changeset
679
a61af66fc99e Initial load
duke
parents:
diff changeset
680 public void showThreadOopInspector(JavaThread thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 showInspector(new OopTreeNodeAdapter(thread.getThreadObj(), null));
a61af66fc99e Initial load
duke
parents:
diff changeset
682 }
a61af66fc99e Initial load
duke
parents:
diff changeset
683
a61af66fc99e Initial load
duke
parents:
diff changeset
684 public void showInspector(SimpleTreeNode adapter) {
a61af66fc99e Initial load
duke
parents:
diff changeset
685 showPanel("Inspector", new Inspector(adapter), 1.0f, 0.65f);
a61af66fc99e Initial load
duke
parents:
diff changeset
686 }
a61af66fc99e Initial load
duke
parents:
diff changeset
687
a61af66fc99e Initial load
duke
parents:
diff changeset
688 public void showLiveness(Oop oop, LivenessPathList liveness) {
a61af66fc99e Initial load
duke
parents:
diff changeset
689 ByteArrayOutputStream bos = new ByteArrayOutputStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
690 PrintStream tty = new PrintStream(bos);
a61af66fc99e Initial load
duke
parents:
diff changeset
691 int numPaths = liveness.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
692 for (int i = 0; i < numPaths; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
693 tty.println("Path " + (i + 1) + " of " + numPaths + ":");
a61af66fc99e Initial load
duke
parents:
diff changeset
694 liveness.get(i).printOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
695 }
a61af66fc99e Initial load
duke
parents:
diff changeset
696 JTextArea ta = new JTextArea(bos.toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
697 ta.setLineWrap(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
698 ta.setWrapStyleWord(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
699 ta.setEditable(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
700
a61af66fc99e Initial load
duke
parents:
diff changeset
701 JPanel panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
702 panel.setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
703
a61af66fc99e Initial load
duke
parents:
diff changeset
704 JScrollPane scroller = new JScrollPane();
a61af66fc99e Initial load
duke
parents:
diff changeset
705 scroller.getViewport().add(ta);
a61af66fc99e Initial load
duke
parents:
diff changeset
706
a61af66fc99e Initial load
duke
parents:
diff changeset
707 panel.add(scroller, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
708
a61af66fc99e Initial load
duke
parents:
diff changeset
709 bos = new ByteArrayOutputStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
710 tty = new PrintStream(bos);
a61af66fc99e Initial load
duke
parents:
diff changeset
711 tty.print("Liveness result for ");
a61af66fc99e Initial load
duke
parents:
diff changeset
712 Oop.printOopValueOn(oop, tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
713
a61af66fc99e Initial load
duke
parents:
diff changeset
714 JInternalFrame frame = new JInternalFrame(bos.toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
715 frame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
716 frame.setClosable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
717 frame.setIconifiable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
718 frame.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
719 frame.getContentPane().add(panel, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
720 frame.pack();
a61af66fc99e Initial load
duke
parents:
diff changeset
721 desktop.add(frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
722 GraphicsUtilities.reshapeToAspectRatio(frame, 0.5f / 0.2f, 0.5f, frame.getParent().getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
723 frame.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
724 }
a61af66fc99e Initial load
duke
parents:
diff changeset
725
a61af66fc99e Initial load
duke
parents:
diff changeset
726 private void fireComputeReversePtrs() {
a61af66fc99e Initial load
duke
parents:
diff changeset
727 // Possible this might have been computed elsewhere
a61af66fc99e Initial load
duke
parents:
diff changeset
728 if (VM.getVM().getRevPtrs() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
729 computeRevPtrsMenuItem.setEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
730 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
731 }
a61af66fc99e Initial load
duke
parents:
diff changeset
732
a61af66fc99e Initial load
duke
parents:
diff changeset
733 workerThread.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
734 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
735 HeapProgress progress = new HeapProgress("Reverse Pointers Analysis");
a61af66fc99e Initial load
duke
parents:
diff changeset
736 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
737 ReversePtrsAnalysis analysis = new ReversePtrsAnalysis();
a61af66fc99e Initial load
duke
parents:
diff changeset
738 analysis.setHeapProgressThunk(progress);
a61af66fc99e Initial load
duke
parents:
diff changeset
739 analysis.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
740 computeRevPtrsMenuItem.setEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
741 } catch (OutOfMemoryError e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
742 final String errMsg = formatMessage(e.toString(), 80);
a61af66fc99e Initial load
duke
parents:
diff changeset
743 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
744 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
745 JOptionPane.showInternalMessageDialog(desktop,
a61af66fc99e Initial load
duke
parents:
diff changeset
746 "Error computing reverse pointers:" + errMsg,
a61af66fc99e Initial load
duke
parents:
diff changeset
747 "Error",
a61af66fc99e Initial load
duke
parents:
diff changeset
748 JOptionPane.WARNING_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
749 }
a61af66fc99e Initial load
duke
parents:
diff changeset
750 });
a61af66fc99e Initial load
duke
parents:
diff changeset
751 } finally {
a61af66fc99e Initial load
duke
parents:
diff changeset
752 // make sure the progress bar goes away
a61af66fc99e Initial load
duke
parents:
diff changeset
753 progress.heapIterationComplete();
a61af66fc99e Initial load
duke
parents:
diff changeset
754 }
a61af66fc99e Initial load
duke
parents:
diff changeset
755 }
a61af66fc99e Initial load
duke
parents:
diff changeset
756 });
a61af66fc99e Initial load
duke
parents:
diff changeset
757 }
a61af66fc99e Initial load
duke
parents:
diff changeset
758
a61af66fc99e Initial load
duke
parents:
diff changeset
759 // Simple struct containing signal information
a61af66fc99e Initial load
duke
parents:
diff changeset
760 class SignalInfo {
a61af66fc99e Initial load
duke
parents:
diff changeset
761 public int sigNum;
a61af66fc99e Initial load
duke
parents:
diff changeset
762 public String sigName;
a61af66fc99e Initial load
duke
parents:
diff changeset
763 }
a61af66fc99e Initial load
duke
parents:
diff changeset
764
a61af66fc99e Initial load
duke
parents:
diff changeset
765 // Need to have mutable vframe as well as visible memory panel
a61af66fc99e Initial load
duke
parents:
diff changeset
766 abstract class StackWalker implements Runnable {
a61af66fc99e Initial load
duke
parents:
diff changeset
767 protected JavaVFrame vf;
a61af66fc99e Initial load
duke
parents:
diff changeset
768 protected AnnotatedMemoryPanel annoPanel;
a61af66fc99e Initial load
duke
parents:
diff changeset
769
a61af66fc99e Initial load
duke
parents:
diff changeset
770 StackWalker(JavaVFrame vf, AnnotatedMemoryPanel annoPanel) {
a61af66fc99e Initial load
duke
parents:
diff changeset
771 this.vf = vf;
a61af66fc99e Initial load
duke
parents:
diff changeset
772 this.annoPanel = annoPanel;
a61af66fc99e Initial load
duke
parents:
diff changeset
773 }
a61af66fc99e Initial load
duke
parents:
diff changeset
774 }
a61af66fc99e Initial load
duke
parents:
diff changeset
775
a61af66fc99e Initial load
duke
parents:
diff changeset
776 public void showThreadStackMemory(final JavaThread thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
777 // dumpStack(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
778 JavaVFrame vframe = getLastJavaVFrame(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
779 if (vframe == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
780 JOptionPane.showInternalMessageDialog(desktop,
a61af66fc99e Initial load
duke
parents:
diff changeset
781 "Thread \"" + thread.getThreadName() +
a61af66fc99e Initial load
duke
parents:
diff changeset
782 "\" has no Java frames on its stack",
a61af66fc99e Initial load
duke
parents:
diff changeset
783 "Show Stack Memory",
a61af66fc99e Initial load
duke
parents:
diff changeset
784 JOptionPane.INFORMATION_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
785 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
786 }
a61af66fc99e Initial load
duke
parents:
diff changeset
787
a61af66fc99e Initial load
duke
parents:
diff changeset
788 JInternalFrame stackFrame = new JInternalFrame("Stack Memory for " + thread.getThreadName());
a61af66fc99e Initial load
duke
parents:
diff changeset
789 stackFrame.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
790 stackFrame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
791 stackFrame.setClosable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
792 stackFrame.setIconifiable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
793 final long addressSize = agent.getTypeDataBase().getAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
794 boolean is64Bit = (addressSize == 8);
a61af66fc99e Initial load
duke
parents:
diff changeset
795 // This is somewhat of a hack to guess a thread's stack limits since the
a61af66fc99e Initial load
duke
parents:
diff changeset
796 // JavaThread doesn't support this functionality. However it is nice in that
a61af66fc99e Initial load
duke
parents:
diff changeset
797 // it locks us into the active region of the thread's stack and not its
a61af66fc99e Initial load
duke
parents:
diff changeset
798 // theoretical limits.
a61af66fc99e Initial load
duke
parents:
diff changeset
799 //
a61af66fc99e Initial load
duke
parents:
diff changeset
800 sun.jvm.hotspot.runtime.Frame tmpFrame = thread.getCurrentFrameGuess();
a61af66fc99e Initial load
duke
parents:
diff changeset
801 Address sp = tmpFrame.getSP();
a61af66fc99e Initial load
duke
parents:
diff changeset
802 Address starting = sp;
a61af66fc99e Initial load
duke
parents:
diff changeset
803 Address maxSP = starting;
a61af66fc99e Initial load
duke
parents:
diff changeset
804 Address minSP = starting;
a61af66fc99e Initial load
duke
parents:
diff changeset
805 RegisterMap tmpMap = thread.newRegisterMap(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
806 while ((tmpFrame != null) && (!tmpFrame.isFirstFrame())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
807 tmpFrame = tmpFrame.sender(tmpMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
808 if (tmpFrame != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
809 sp = tmpFrame.getSP();
a61af66fc99e Initial load
duke
parents:
diff changeset
810 if (sp != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
811 maxSP = AddressOps.max(maxSP, sp);
a61af66fc99e Initial load
duke
parents:
diff changeset
812 minSP = AddressOps.min(minSP, sp);
a61af66fc99e Initial load
duke
parents:
diff changeset
813 }
a61af66fc99e Initial load
duke
parents:
diff changeset
814 }
a61af66fc99e Initial load
duke
parents:
diff changeset
815
a61af66fc99e Initial load
duke
parents:
diff changeset
816 }
a61af66fc99e Initial load
duke
parents:
diff changeset
817 // It is useful to be able to see say +/- 8K on the current stack range
a61af66fc99e Initial load
duke
parents:
diff changeset
818 AnnotatedMemoryPanel annoMemPanel = new AnnotatedMemoryPanel(agent.getDebugger(), is64Bit, starting,
a61af66fc99e Initial load
duke
parents:
diff changeset
819 minSP.addOffsetTo(-8192),
a61af66fc99e Initial load
duke
parents:
diff changeset
820 maxSP.addOffsetTo( 8192));
a61af66fc99e Initial load
duke
parents:
diff changeset
821
a61af66fc99e Initial load
duke
parents:
diff changeset
822 stackFrame.getContentPane().add(annoMemPanel, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
823 desktop.add(stackFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
824 GraphicsUtilities.reshapeToAspectRatio(stackFrame, 4.0f / 3.0f, 0.85f, stackFrame.getParent().getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
825 stackFrame.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
826
a61af66fc99e Initial load
duke
parents:
diff changeset
827 // Stackmap computation for interpreted frames is expensive; do
a61af66fc99e Initial load
duke
parents:
diff changeset
828 // all stackwalking work in another thread for better GUI
a61af66fc99e Initial load
duke
parents:
diff changeset
829 // responsiveness
a61af66fc99e Initial load
duke
parents:
diff changeset
830 workerThread.invokeLater(new StackWalker(vframe, annoMemPanel) {
a61af66fc99e Initial load
duke
parents:
diff changeset
831 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
832 Address startAddr = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
833
a61af66fc99e Initial load
duke
parents:
diff changeset
834 // As this is a debugger, we want to provide potential crash
a61af66fc99e Initial load
duke
parents:
diff changeset
835 // information to the user, i.e., by marking signal handler frames
a61af66fc99e Initial load
duke
parents:
diff changeset
836 // on the stack. Since this system is currently targeted at
a61af66fc99e Initial load
duke
parents:
diff changeset
837 // annotating the Java frames (interpreted or compiled) on the
a61af66fc99e Initial load
duke
parents:
diff changeset
838 // stack and not, for example, "external" frames (note the current
a61af66fc99e Initial load
duke
parents:
diff changeset
839 // absence of a PC-to-symbol lookup mechanism at the Debugger
a61af66fc99e Initial load
duke
parents:
diff changeset
840 // level), we want to mark any Java frames which were interrupted
a61af66fc99e Initial load
duke
parents:
diff changeset
841 // by a signal. We do this by making two passes over the stack,
a61af66fc99e Initial load
duke
parents:
diff changeset
842 // one which finds signal handler frames and puts the parent
a61af66fc99e Initial load
duke
parents:
diff changeset
843 // frames in a table and one which finds Java frames and if they
a61af66fc99e Initial load
duke
parents:
diff changeset
844 // are in the table indicates that they were interrupted by a signal.
a61af66fc99e Initial load
duke
parents:
diff changeset
845
a61af66fc99e Initial load
duke
parents:
diff changeset
846 Map interruptedFrameMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
847 {
a61af66fc99e Initial load
duke
parents:
diff changeset
848 sun.jvm.hotspot.runtime.Frame tmpFrame = thread.getCurrentFrameGuess();
a61af66fc99e Initial load
duke
parents:
diff changeset
849 RegisterMap tmpMap = thread.newRegisterMap(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
850 while ((tmpFrame != null) && (!tmpFrame.isFirstFrame())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
851 if (tmpFrame.isSignalHandlerFrameDbg()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
852 // Add some information to the map that we can extract later
a61af66fc99e Initial load
duke
parents:
diff changeset
853 sun.jvm.hotspot.runtime.Frame interruptedFrame = tmpFrame.sender(tmpMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
854 SignalInfo info = new SignalInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
855 info.sigNum = tmpFrame.getSignalNumberDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
856 info.sigName = tmpFrame.getSignalNameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
857 interruptedFrameMap.put(interruptedFrame, info);
a61af66fc99e Initial load
duke
parents:
diff changeset
858 }
a61af66fc99e Initial load
duke
parents:
diff changeset
859 tmpFrame = tmpFrame.sender(tmpMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
860 }
a61af66fc99e Initial load
duke
parents:
diff changeset
861 }
a61af66fc99e Initial load
duke
parents:
diff changeset
862
a61af66fc99e Initial load
duke
parents:
diff changeset
863 while (vf != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
864 String anno = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
865 JavaVFrame curVFrame = vf;
a61af66fc99e Initial load
duke
parents:
diff changeset
866 sun.jvm.hotspot.runtime.Frame curFrame = curVFrame.getFrame();
a61af66fc99e Initial load
duke
parents:
diff changeset
867 Method interpreterFrameMethod = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
868
a61af66fc99e Initial load
duke
parents:
diff changeset
869 if (curVFrame.isInterpretedFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
870 anno = "Interpreted frame";
a61af66fc99e Initial load
duke
parents:
diff changeset
871 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
872 anno = "Compiled frame";
a61af66fc99e Initial load
duke
parents:
diff changeset
873 if (curVFrame.isDeoptimized()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
874 anno += " (deoptimized)";
a61af66fc99e Initial load
duke
parents:
diff changeset
875 }
a61af66fc99e Initial load
duke
parents:
diff changeset
876 }
a61af66fc99e Initial load
duke
parents:
diff changeset
877 if (curVFrame.mayBeImpreciseDbg()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
878 anno += "; information may be imprecise";
a61af66fc99e Initial load
duke
parents:
diff changeset
879 }
a61af66fc99e Initial load
duke
parents:
diff changeset
880
a61af66fc99e Initial load
duke
parents:
diff changeset
881 if (curVFrame.isInterpretedFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
882 // Find the codelet
a61af66fc99e Initial load
duke
parents:
diff changeset
883 InterpreterCodelet codelet = VM.getVM().getInterpreter().getCodeletContaining(curFrame.getPC());
a61af66fc99e Initial load
duke
parents:
diff changeset
884 String description = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
885 if (codelet != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
886 description = codelet.getDescription();
a61af66fc99e Initial load
duke
parents:
diff changeset
887 }
a61af66fc99e Initial load
duke
parents:
diff changeset
888 if (description == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
889 anno += "\n(Unknown interpreter codelet)";
a61af66fc99e Initial load
duke
parents:
diff changeset
890 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
891 anno += "\nExecuting in codelet \"" + description + "\" at PC = " + curFrame.getPC();
a61af66fc99e Initial load
duke
parents:
diff changeset
892 }
a61af66fc99e Initial load
duke
parents:
diff changeset
893 } else if (curVFrame.isCompiledFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
894 anno += "\nExecuting at PC = " + curFrame.getPC();
a61af66fc99e Initial load
duke
parents:
diff changeset
895 }
a61af66fc99e Initial load
duke
parents:
diff changeset
896
a61af66fc99e Initial load
duke
parents:
diff changeset
897 if (startAddr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
898 startAddr = curFrame.getSP();
a61af66fc99e Initial load
duke
parents:
diff changeset
899 }
a61af66fc99e Initial load
duke
parents:
diff changeset
900
a61af66fc99e Initial load
duke
parents:
diff changeset
901 // FIXME: some compiled frames with empty oop map sets have been
a61af66fc99e Initial load
duke
parents:
diff changeset
902 // found (for example, Vector's inner Enumeration class, method
a61af66fc99e Initial load
duke
parents:
diff changeset
903 // "hasMoreElements"). Not sure yet why these cases are showing
a61af66fc99e Initial load
duke
parents:
diff changeset
904 // up -- should be possible (though unlikely) for safepoint code
a61af66fc99e Initial load
duke
parents:
diff changeset
905 // to patch the return instruction of these methods and then
a61af66fc99e Initial load
duke
parents:
diff changeset
906 // later attempt to get an oop map for that instruction. For
a61af66fc99e Initial load
duke
parents:
diff changeset
907 // now, we warn if we find such a method.
a61af66fc99e Initial load
duke
parents:
diff changeset
908 boolean shouldSkipOopMaps = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
909 if (curVFrame.isCompiledFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
910 CodeBlob cb = VM.getVM().getCodeCache().findBlob(curFrame.getPC());
a61af66fc99e Initial load
duke
parents:
diff changeset
911 OopMapSet maps = cb.getOopMaps();
a61af66fc99e Initial load
duke
parents:
diff changeset
912 if ((maps == null) || (maps.getSize() == 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
913 shouldSkipOopMaps = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
914 }
a61af66fc99e Initial load
duke
parents:
diff changeset
915 }
a61af66fc99e Initial load
duke
parents:
diff changeset
916
a61af66fc99e Initial load
duke
parents:
diff changeset
917 // Add signal information to annotation if necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
918 SignalInfo sigInfo = (SignalInfo) interruptedFrameMap.get(curFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
919 if (sigInfo != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
920 // This frame took a signal and we need to report it.
a61af66fc99e Initial load
duke
parents:
diff changeset
921 anno = (anno + "\n*** INTERRUPTED BY SIGNAL " + Integer.toString(sigInfo.sigNum) +
a61af66fc99e Initial load
duke
parents:
diff changeset
922 " (" + sigInfo.sigName + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
923 }
a61af66fc99e Initial load
duke
parents:
diff changeset
924
a61af66fc99e Initial load
duke
parents:
diff changeset
925 JavaVFrame nextVFrame = curVFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
926 sun.jvm.hotspot.runtime.Frame nextFrame = curFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
927 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
928 curVFrame = nextVFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
929 curFrame = nextFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
930
a61af66fc99e Initial load
duke
parents:
diff changeset
931 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
932 Method method = curVFrame.getMethod();
a61af66fc99e Initial load
duke
parents:
diff changeset
933 if (interpreterFrameMethod == null && curVFrame.isInterpretedFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
934 interpreterFrameMethod = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
935 }
a61af66fc99e Initial load
duke
parents:
diff changeset
936 int bci = curVFrame.getBCI();
a61af66fc99e Initial load
duke
parents:
diff changeset
937 String lineNumberAnno = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
938 if (method.hasLineNumberTable()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
939 if ((bci == DebugInformationRecorder.SYNCHRONIZATION_ENTRY_BCI) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
940 (bci >= 0 && bci < method.getCodeSize())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
941 lineNumberAnno = ", line " + method.getLineNumberFromBCI(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
942 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
943 lineNumberAnno = " (INVALID BCI)";
a61af66fc99e Initial load
duke
parents:
diff changeset
944 }
a61af66fc99e Initial load
duke
parents:
diff changeset
945 }
a61af66fc99e Initial load
duke
parents:
diff changeset
946 anno += "\n" + method.getMethodHolder().getName().asString() + "." +
a61af66fc99e Initial load
duke
parents:
diff changeset
947 method.getName().asString() + method.getSignature().asString() +
a61af66fc99e Initial load
duke
parents:
diff changeset
948 "\n@bci " + bci + lineNumberAnno;
a61af66fc99e Initial load
duke
parents:
diff changeset
949 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
950 anno += "\n(ERROR while iterating vframes for frame " + curFrame + ")";
a61af66fc99e Initial load
duke
parents:
diff changeset
951 }
a61af66fc99e Initial load
duke
parents:
diff changeset
952
a61af66fc99e Initial load
duke
parents:
diff changeset
953 nextVFrame = curVFrame.javaSender();
a61af66fc99e Initial load
duke
parents:
diff changeset
954 if (nextVFrame != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
955 nextFrame = nextVFrame.getFrame();
a61af66fc99e Initial load
duke
parents:
diff changeset
956 }
a61af66fc99e Initial load
duke
parents:
diff changeset
957 } while (nextVFrame != null && nextFrame.equals(curFrame));
a61af66fc99e Initial load
duke
parents:
diff changeset
958
a61af66fc99e Initial load
duke
parents:
diff changeset
959 if (shouldSkipOopMaps) {
a61af66fc99e Initial load
duke
parents:
diff changeset
960 anno = anno + "\nNOTE: null or empty OopMapSet found for this CodeBlob";
a61af66fc99e Initial load
duke
parents:
diff changeset
961 }
a61af66fc99e Initial load
duke
parents:
diff changeset
962
a61af66fc99e Initial load
duke
parents:
diff changeset
963 if (curFrame.getFP() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
964 annoPanel.addAnnotation(new Annotation(curFrame.getSP(),
a61af66fc99e Initial load
duke
parents:
diff changeset
965 curFrame.getFP(),
a61af66fc99e Initial load
duke
parents:
diff changeset
966 anno));
a61af66fc99e Initial load
duke
parents:
diff changeset
967 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
968 if (VM.getVM().getCPU().equals("x86") || VM.getVM().getCPU().equals("amd64")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
969 // For C2, which has null frame pointers on x86/amd64
a61af66fc99e Initial load
duke
parents:
diff changeset
970 CodeBlob cb = VM.getVM().getCodeCache().findBlob(curFrame.getPC());
a61af66fc99e Initial load
duke
parents:
diff changeset
971 Address sp = curFrame.getSP();
a61af66fc99e Initial load
duke
parents:
diff changeset
972 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
973 Assert.that(cb.getFrameSize() > 0, "CodeBlob must have non-zero frame size");
a61af66fc99e Initial load
duke
parents:
diff changeset
974 }
a61af66fc99e Initial load
duke
parents:
diff changeset
975 annoPanel.addAnnotation(new Annotation(sp,
a61af66fc99e Initial load
duke
parents:
diff changeset
976 sp.addOffsetTo(cb.getFrameSize()),
a61af66fc99e Initial load
duke
parents:
diff changeset
977 anno));
a61af66fc99e Initial load
duke
parents:
diff changeset
978 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
979 Assert.that(VM.getVM().getCPU().equals("ia64"), "only ia64 should reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
980 }
a61af66fc99e Initial load
duke
parents:
diff changeset
981 }
a61af66fc99e Initial load
duke
parents:
diff changeset
982
a61af66fc99e Initial load
duke
parents:
diff changeset
983 // Add interpreter frame annotations
a61af66fc99e Initial load
duke
parents:
diff changeset
984 if (curFrame.isInterpretedFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
985 annoPanel.addAnnotation(new Annotation(curFrame.addressOfInterpreterFrameExpressionStack(),
a61af66fc99e Initial load
duke
parents:
diff changeset
986 curFrame.addressOfInterpreterFrameTOS(),
a61af66fc99e Initial load
duke
parents:
diff changeset
987 "Interpreter expression stack"));
a61af66fc99e Initial load
duke
parents:
diff changeset
988 if (interpreterFrameMethod != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
989 // The offset is just to get the right stack slots highlighted in the output
a61af66fc99e Initial load
duke
parents:
diff changeset
990 int offset = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
991 annoPanel.addAnnotation(new Annotation(curFrame.addressOfInterpreterFrameLocal(offset),
a61af66fc99e Initial load
duke
parents:
diff changeset
992 curFrame.addressOfInterpreterFrameLocal((int) interpreterFrameMethod.getMaxLocals() + offset),
a61af66fc99e Initial load
duke
parents:
diff changeset
993 "Interpreter locals area for frame with SP = " + curFrame.getSP()));
a61af66fc99e Initial load
duke
parents:
diff changeset
994 }
a61af66fc99e Initial load
duke
parents:
diff changeset
995 String methodAnno = "Interpreter frame methodOop";
a61af66fc99e Initial load
duke
parents:
diff changeset
996 if (interpreterFrameMethod == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
997 methodAnno += " (BAD OOP)";
a61af66fc99e Initial load
duke
parents:
diff changeset
998 }
a61af66fc99e Initial load
duke
parents:
diff changeset
999 Address a = curFrame.addressOfInterpreterFrameMethod();
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 annoPanel.addAnnotation(new Annotation(a, a.addOffsetTo(addressSize), methodAnno));
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 a = curFrame.addressOfInterpreterFrameCPCache();
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 annoPanel.addAnnotation(new Annotation(a, a.addOffsetTo(addressSize), "Interpreter constant pool cache"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1004
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 RegisterMap rm = (RegisterMap) vf.getRegisterMap().clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 if (!shouldSkipOopMaps) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 curFrame.oopsDo(new AddressVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 public void visitAddress(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 Assert.that(addr.andWithMask(VM.getVM().getAddressSize() - 1) == null,
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 "Address " + addr + "should have been aligned");
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 // Check contents
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 OopHandle handle = addr.getOopHandleAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 String anno = "null oop";
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 if (handle != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 // Find location
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 CollectedHeap collHeap = VM.getVM().getUniverse().heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 boolean bad = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 anno = "BAD OOP";
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 if (collHeap instanceof GenCollectedHeap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 GenCollectedHeap heap = (GenCollectedHeap) collHeap;
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 for (int i = 0; i < heap.nGens(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 if (heap.getGen(i).isIn(handle)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 if (i == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 anno = "NewGen ";
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 } else if (i == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 anno = "OldGen ";
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 anno = "Gen " + i + " ";
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 bad = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1037
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 if (bad) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 // Try perm gen
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 if (heap.permGen().isIn(handle)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 anno = "PermGen ";
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 bad = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 } else if (collHeap instanceof ParallelScavengeHeap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 ParallelScavengeHeap heap = (ParallelScavengeHeap) collHeap;
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 if (heap.youngGen().isIn(handle)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 anno = "PSYoungGen ";
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 bad = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 } else if (heap.oldGen().isIn(handle)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 anno = "PSOldGen ";
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 bad = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 } else if (heap.permGen().isIn(handle)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 anno = "PSPermGen ";
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 bad = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 // Optimistically assume the oop isn't bad
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 anno = "[Unknown generation] ";
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 bad = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1062
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 if (!bad) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 Oop oop = VM.getVM().getObjectHeap().newOop(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 if (oop instanceof Instance) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 // Java-level objects always have workable names
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 anno = anno + oop.getKlass().getName().asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 ByteArrayOutputStream bos = new ByteArrayOutputStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 Oop.printOopValueOn(oop, new PrintStream(bos));
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 anno = anno + bos.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 catch (AddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 anno += "CORRUPT OOP";
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 catch (NullPointerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 anno += "CORRUPT OOP (null pointer)";
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1083
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 annoPanel.addAnnotation(new Annotation(addr, addr.addOffsetTo(addressSize), anno));
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 }, rm);
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 System.err.println("Error while performing oopsDo for frame " + curFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1092
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 vf = nextVFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1095
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 // This used to paint as we walked the frames. This caused the display to be refreshed
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 // enough to be annoying on remote displays. It also would cause the annotations to
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 // be displayed in varying order which caused some annotations to overwrite others
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 // depending on the races between painting and adding annotations. This latter problem
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 // still exists to some degree but moving this code here definitely seems to reduce it
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 annoPanel.makeVisible(startAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 annoPanel.repaint();
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1106
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 /** NOTE we are in a different thread here than either the main
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 thread or the Swing/AWT event handler thread, so we must be very
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 careful when creating or removing widgets */
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 private void attach(String pidText) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 this.pidText = pidText;
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 pid = Integer.parseInt(pidText);
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 catch (NumberFormatException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 setMenuItemsEnabled(attachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 JOptionPane.showInternalMessageDialog(desktop,
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 "Unable to parse process ID \"" + HSDB.this.pidText + "\".\nPlease enter a number.",
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 "Parse error",
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 JOptionPane.WARNING_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1127
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 // Try to attach to this process
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 Runnable remover = new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 attachWaitDialog.setVisible(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 desktop.remove(attachWaitDialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 attachWaitDialog = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1136
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 JOptionPane pane = new JOptionPane("Attaching to process " + pid + ", please wait...", JOptionPane.INFORMATION_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 pane.setOptions(new Object[] {});
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 attachWaitDialog = pane.createInternalFrame(desktop, "Attaching to Process");
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 attachWaitDialog.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1146
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 // FIXME: display exec'd debugger's output messages during this
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 // lengthy call
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 agent.attach(pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 if (agent.getDebugger().hasConsole()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 showDbgConsoleMenuItem.setEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 attached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 SwingUtilities.invokeLater(remover);
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 catch (DebuggerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 SwingUtilities.invokeLater(remover);
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 final String errMsg = formatMessage(e.getMessage(), 80);
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 setMenuItemsEnabled(attachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 JOptionPane.showInternalMessageDialog(desktop,
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 "Unable to connect to process ID " + pid + ":\n\n" + errMsg,
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 "Unable to Connect",
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 JOptionPane.WARNING_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 agent.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1171
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 // OK, the VM should be available. Create the Threads dialog.
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 showThreadsDialog();
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1175
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 /** NOTE we are in a different thread here than either the main
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 thread or the Swing/AWT event handler thread, so we must be very
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 careful when creating or removing widgets */
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 private void attach(final String executablePath, final String corePath) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 // Try to open this core file
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 Runnable remover = new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 attachWaitDialog.setVisible(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 desktop.remove(attachWaitDialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 attachWaitDialog = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1188
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 JOptionPane pane = new JOptionPane("Opening core file, please wait...", JOptionPane.INFORMATION_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 pane.setOptions(new Object[] {});
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 attachWaitDialog = pane.createInternalFrame(desktop, "Opening Core File");
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 attachWaitDialog.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1198
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 // FIXME: display exec'd debugger's output messages during this
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 // lengthy call
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 agent.attach(executablePath, corePath);
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 if (agent.getDebugger().hasConsole()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 showDbgConsoleMenuItem.setEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 attached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 SwingUtilities.invokeLater(remover);
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 catch (DebuggerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 SwingUtilities.invokeLater(remover);
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 final String errMsg = formatMessage(e.getMessage(), 80);
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 setMenuItemsEnabled(attachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 JOptionPane.showInternalMessageDialog(desktop,
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 "Unable to open core file\n" + corePath + ":\n\n" + errMsg,
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 "Unable to Open Core File",
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 JOptionPane.WARNING_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 agent.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1223
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 // OK, the VM should be available. Create the Threads dialog.
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 showThreadsDialog();
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1227
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 /** NOTE we are in a different thread here than either the main
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 thread or the Swing/AWT event handler thread, so we must be very
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 careful when creating or removing widgets */
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 private void connect(final String remoteMachineName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 // Try to open this core file
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 Runnable remover = new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 attachWaitDialog.setVisible(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 desktop.remove(attachWaitDialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 attachWaitDialog = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1240
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 JOptionPane pane = new JOptionPane("Connecting to debug server, please wait...", JOptionPane.INFORMATION_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 pane.setOptions(new Object[] {});
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 attachWaitDialog = pane.createInternalFrame(desktop, "Connecting to Debug Server");
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 attachWaitDialog.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1250
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 agent.attach(remoteMachineName);
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 if (agent.getDebugger().hasConsole()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 showDbgConsoleMenuItem.setEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 attached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 SwingUtilities.invokeLater(remover);
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 catch (DebuggerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 SwingUtilities.invokeLater(remover);
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 final String errMsg = formatMessage(e.getMessage(), 80);
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 setMenuItemsEnabled(attachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 JOptionPane.showInternalMessageDialog(desktop,
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 "Unable to connect to machine \"" + remoteMachineName + "\":\n\n" + errMsg,
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 "Unable to Connect",
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 JOptionPane.WARNING_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 agent.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1273
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 // OK, the VM should be available. Create the Threads dialog.
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 showThreadsDialog();
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1277
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 private void detachDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 if (!attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 agent.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 attached = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1285
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 private void detach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 detachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 attachWaitDialog = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 threadsFrame = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 consoleFrame = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 setMenuItemsEnabled(attachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 setMenuItemsEnabled(detachMenuItems, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 toolsMenu.setEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 showDbgConsoleMenuItem.setEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 // FIXME: is this sufficient, or will I have to do anything else
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 // to the components to kill them off? What about WorkerThreads?
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 desktop.removeAll();
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 desktop.invalidate();
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 desktop.validate();
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 desktop.repaint();
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1302
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 /** NOTE that this is called from another thread than the main or
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 Swing thread and we have to be careful about synchronization */
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 private void showThreadsDialog() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 threadsFrame = new JInternalFrame("Java Threads");
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 threadsFrame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 threadsFrame.setIconifiable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 JavaThreadsPanel threadsPanel = new JavaThreadsPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 threadsPanel.addPanelListener(HSDB.this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 threadsFrame.getContentPane().add(threadsPanel);
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 threadsFrame.setSize(500, 300);
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 threadsFrame.pack();
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 desktop.add(threadsFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 GraphicsUtilities.moveToInContainer(threadsFrame, 0.75f, 0.25f, 0, 20);
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 threadsFrame.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 setMenuItemsEnabled(attachMenuItems, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 setMenuItemsEnabled(detachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 toolsMenu.setEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 computeRevPtrsMenuItem.setEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1330
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 private void showObjectHistogram() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 sun.jvm.hotspot.oops.ObjectHistogram histo = new sun.jvm.hotspot.oops.ObjectHistogram();
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 ObjectHistogramCleanupThunk cleanup =
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 new ObjectHistogramCleanupThunk(histo);
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 doHeapIteration("Object Histogram",
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 "Generating histogram...",
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 histo,
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 cleanup);
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1340
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 class ObjectHistogramCleanupThunk implements CleanupThunk {
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 sun.jvm.hotspot.oops.ObjectHistogram histo;
a61af66fc99e Initial load
duke
parents:
diff changeset
1343
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 ObjectHistogramCleanupThunk(sun.jvm.hotspot.oops.ObjectHistogram histo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 this.histo = histo;
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1347
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 public void heapIterationComplete() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 JInternalFrame histoFrame = new JInternalFrame("Object Histogram");
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 histoFrame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 histoFrame.setClosable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 histoFrame.setIconifiable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 histoFrame.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 ObjectHistogramPanel panel = new ObjectHistogramPanel(histo);
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 panel.addPanelListener(HSDB.this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 histoFrame.getContentPane().add(panel);
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 desktop.add(histoFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 GraphicsUtilities.reshapeToAspectRatio(histoFrame, 4.0f / 3.0f, 0.6f,
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 histoFrame.getParent().getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 GraphicsUtilities.centerInContainer(histoFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 histoFrame.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1368
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 public void showObjectsOfType(Klass type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 FindObjectByType finder = new FindObjectByType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 FindObjectByTypeCleanupThunk cleanup =
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 new FindObjectByTypeCleanupThunk(finder);
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 ByteArrayOutputStream bos = new ByteArrayOutputStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 type.printValueOn(new PrintStream(bos));
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 String typeName = bos.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 doHeapIteration("Show Objects Of Type",
a61af66fc99e Initial load
duke
parents:
diff changeset
1377 "Finding instances of \"" + typeName + "\"",
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 finder,
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 cleanup);
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1381
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 class FindObjectByTypeCleanupThunk implements CleanupThunk {
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 FindObjectByType finder;
a61af66fc99e Initial load
duke
parents:
diff changeset
1384
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 FindObjectByTypeCleanupThunk(FindObjectByType finder) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 this.finder = finder;
a61af66fc99e Initial load
duke
parents:
diff changeset
1387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1388
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 public void heapIterationComplete() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 JInternalFrame finderFrame = new JInternalFrame("Show Objects of Type");
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 finderFrame.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 finderFrame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 finderFrame.setClosable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 finderFrame.setIconifiable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1397 ObjectListPanel panel = new ObjectListPanel(finder.getResults(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1398 new HeapProgress("Reverse Pointers Analysis"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 panel.addPanelListener(HSDB.this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 finderFrame.getContentPane().add(panel);
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 desktop.add(finderFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1402 GraphicsUtilities.reshapeToAspectRatio(finderFrame, 4.0f / 3.0f, 0.6f,
a61af66fc99e Initial load
duke
parents:
diff changeset
1403 finderFrame.getParent().getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 GraphicsUtilities.centerInContainer(finderFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1405 finderFrame.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1407 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1410
a61af66fc99e Initial load
duke
parents:
diff changeset
1411 private void showDebuggerConsole() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 if (consoleFrame == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 consoleFrame = new JInternalFrame("Debugger Console");
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 consoleFrame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 consoleFrame.setClosable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1416 consoleFrame.setIconifiable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1417 consoleFrame.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 consoleFrame.getContentPane().add(new DebuggerConsolePanel(agent.getDebugger()), BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 GraphicsUtilities.reshapeToAspectRatio(consoleFrame, 5.0f, 0.9f, desktop.getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1421 if (consoleFrame.getParent() == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1422 desktop.add(consoleFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1424 consoleFrame.setVisible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 consoleFrame.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 consoleFrame.getContentPane().getComponent(0).requestFocus();
a61af66fc99e Initial load
duke
parents:
diff changeset
1427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1428
a61af66fc99e Initial load
duke
parents:
diff changeset
1429 private void showConsole() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 CommandProcessor.DebuggerInterface di = new CommandProcessor.DebuggerInterface() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 public HotSpotAgent getAgent() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 return agent;
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 public boolean isAttached() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 return attached;
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 public void attach(String pid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1438 attach(pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 public void attach(String java, String core) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 public void detach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 detachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 public void reattach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1446 if (attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1447 detachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1449 if (pidText != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1450 attach(pidText);
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 attach(execPath, coreFilename);
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1456
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 showPanel("Command Line", new CommandProcessorPanel(new CommandProcessor(di, null, null, null)));
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1459
a61af66fc99e Initial load
duke
parents:
diff changeset
1460 private void showFindByQueryPanel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 showPanel("Find Object by Query", new FindByQueryPanel());
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1463
a61af66fc99e Initial load
duke
parents:
diff changeset
1464 private void showFindPanel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1465 showPanel("Find Pointer", new FindPanel());
a61af66fc99e Initial load
duke
parents:
diff changeset
1466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1467
a61af66fc99e Initial load
duke
parents:
diff changeset
1468 private void showFindInHeapPanel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1469 showPanel("Find Address In Heap", new FindInHeapPanel());
a61af66fc99e Initial load
duke
parents:
diff changeset
1470 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1471
a61af66fc99e Initial load
duke
parents:
diff changeset
1472 private void showFindInCodeCachePanel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1473 showPanel("Find Address In Code Cache", new FindInCodeCachePanel());
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1475
a61af66fc99e Initial load
duke
parents:
diff changeset
1476 private void showHeapParametersPanel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1477 showPanel("Heap Parameters", new HeapParametersPanel());
a61af66fc99e Initial load
duke
parents:
diff changeset
1478 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1479
a61af66fc99e Initial load
duke
parents:
diff changeset
1480 public void showThreadInfo(final JavaThread thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1481 showPanel("Info for " + thread.getThreadName(), new ThreadInfoPanel(thread));
a61af66fc99e Initial load
duke
parents:
diff changeset
1482 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1483
a61af66fc99e Initial load
duke
parents:
diff changeset
1484 public void showJavaStackTrace(final JavaThread thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1485 JavaStackTracePanel jstp = new JavaStackTracePanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
1486 showPanel("Java stack trace for " + thread.getThreadName(), jstp);
a61af66fc99e Initial load
duke
parents:
diff changeset
1487 jstp.setJavaThread(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
1488 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1489
a61af66fc99e Initial load
duke
parents:
diff changeset
1490 private void showDeadlockDetectionPanel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1491 showPanel("Deadlock Detection", new DeadlockDetectionPanel());
a61af66fc99e Initial load
duke
parents:
diff changeset
1492 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1493
a61af66fc99e Initial load
duke
parents:
diff changeset
1494 private void showMonitorCacheDumpPanel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1495 showPanel("Monitor Cache Dump", new MonitorCacheDumpPanel());
a61af66fc99e Initial load
duke
parents:
diff changeset
1496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1497
a61af66fc99e Initial load
duke
parents:
diff changeset
1498 public void showClassBrowser() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1499 final JInternalFrame progressFrame = new JInternalFrame("Class Browser");
a61af66fc99e Initial load
duke
parents:
diff changeset
1500 progressFrame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 progressFrame.setClosable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1502 progressFrame.setIconifiable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 progressFrame.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
1504 final ProgressBarPanel bar = new ProgressBarPanel("Generating class list ..");
a61af66fc99e Initial load
duke
parents:
diff changeset
1505 bar.setIndeterminate(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1506 progressFrame.getContentPane().add(bar, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
1507 desktop.add(progressFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1508 progressFrame.pack();
a61af66fc99e Initial load
duke
parents:
diff changeset
1509 GraphicsUtilities.centerInContainer(progressFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1510 progressFrame.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
1511
a61af66fc99e Initial load
duke
parents:
diff changeset
1512 workerThread.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1513 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1514 HTMLGenerator htmlGen = new HTMLGenerator();
a61af66fc99e Initial load
duke
parents:
diff changeset
1515 InstanceKlass[] klasses = SystemDictionaryHelper.getAllInstanceKlasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
1516 final String htmlText = htmlGen.genHTMLForKlassNames(klasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
1517 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1518 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1519 JInternalFrame cbFrame = new JInternalFrame("Class Browser");
a61af66fc99e Initial load
duke
parents:
diff changeset
1520 cbFrame.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
1521 cbFrame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1522 cbFrame.setClosable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1523 cbFrame.setIconifiable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1524 ClassBrowserPanel cbPanel = new ClassBrowserPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
1525 cbFrame.getContentPane().add(cbPanel, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
1526 desktop.remove(progressFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1527 desktop.repaint();
a61af66fc99e Initial load
duke
parents:
diff changeset
1528 desktop.add(cbFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1529 GraphicsUtilities.reshapeToAspectRatio(cbFrame, 1.25f, 0.85f,
a61af66fc99e Initial load
duke
parents:
diff changeset
1530 cbFrame.getParent().getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
1531 cbFrame.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
1532 cbPanel.setClassesText(htmlText);
a61af66fc99e Initial load
duke
parents:
diff changeset
1533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1534 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1536 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1537 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1538
a61af66fc99e Initial load
duke
parents:
diff changeset
1539 public void showCodeViewer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1540 showPanel("Code Viewer", new CodeViewerPanel(), 1.25f, 0.85f);
a61af66fc99e Initial load
duke
parents:
diff changeset
1541 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1542
a61af66fc99e Initial load
duke
parents:
diff changeset
1543 public void showCodeViewer(final Address address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1544 final CodeViewerPanel panel = new CodeViewerPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
1545 showPanel("Code Viewer", panel, 1.25f, 0.85f);
a61af66fc99e Initial load
duke
parents:
diff changeset
1546 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1547 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1548 panel.viewAddress(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
1549 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1550 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1551
a61af66fc99e Initial load
duke
parents:
diff changeset
1552 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1553
a61af66fc99e Initial load
duke
parents:
diff changeset
1554 public void showMemoryViewer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1555 showPanel("Memory Viewer", new MemoryViewer(agent.getDebugger(), agent.getTypeDataBase().getAddressSize() == 8));
a61af66fc99e Initial load
duke
parents:
diff changeset
1556 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1557
a61af66fc99e Initial load
duke
parents:
diff changeset
1558 public void showCommandLineFlags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1559 showPanel("Command Line Flags", new VMFlagsPanel());
a61af66fc99e Initial load
duke
parents:
diff changeset
1560 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1561
a61af66fc99e Initial load
duke
parents:
diff changeset
1562 public void showVMVersion() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1563 showPanel("VM Version Info", new VMVersionInfoPanel());
a61af66fc99e Initial load
duke
parents:
diff changeset
1564 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1565
a61af66fc99e Initial load
duke
parents:
diff changeset
1566 public void showSystemProperties() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1567 showPanel("System Properties", new SysPropsPanel());
a61af66fc99e Initial load
duke
parents:
diff changeset
1568 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1569
a61af66fc99e Initial load
duke
parents:
diff changeset
1570 private void showPanel(String name, JPanel panel) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1571 showPanel(name, panel, 5.0f / 3.0f, 0.4f);
a61af66fc99e Initial load
duke
parents:
diff changeset
1572 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1573
a61af66fc99e Initial load
duke
parents:
diff changeset
1574 private void showPanel(String name, JPanel panel, float aspectRatio, float fillRatio) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1575 JInternalFrame frame = new JInternalFrame(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1576 frame.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
1577 frame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1578 frame.setClosable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1579 frame.setIconifiable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1580 frame.setMaximizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1581 frame.getContentPane().add(panel, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
1582 desktop.add(frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1583 GraphicsUtilities.reshapeToAspectRatio(frame, aspectRatio, fillRatio, frame.getParent().getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
1584 GraphicsUtilities.randomLocation(frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1585 frame.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
1586 if (panel instanceof SAPanel) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1587 ((SAPanel)panel).addPanelListener(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1590
a61af66fc99e Initial load
duke
parents:
diff changeset
1591 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1592 // Framework for heap iteration with progress bar
a61af66fc99e Initial load
duke
parents:
diff changeset
1593 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1594
a61af66fc99e Initial load
duke
parents:
diff changeset
1595 interface CleanupThunk {
a61af66fc99e Initial load
duke
parents:
diff changeset
1596 public void heapIterationComplete();
a61af66fc99e Initial load
duke
parents:
diff changeset
1597 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1598
a61af66fc99e Initial load
duke
parents:
diff changeset
1599 class HeapProgress implements HeapProgressThunk {
a61af66fc99e Initial load
duke
parents:
diff changeset
1600 private JInternalFrame frame;
a61af66fc99e Initial load
duke
parents:
diff changeset
1601 private ProgressBarPanel bar;
a61af66fc99e Initial load
duke
parents:
diff changeset
1602 private String windowTitle;
a61af66fc99e Initial load
duke
parents:
diff changeset
1603 private String progressBarTitle;
a61af66fc99e Initial load
duke
parents:
diff changeset
1604 private CleanupThunk cleanup;
a61af66fc99e Initial load
duke
parents:
diff changeset
1605
a61af66fc99e Initial load
duke
parents:
diff changeset
1606 HeapProgress(String windowTitle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1607 this(windowTitle, "Percentage of heap visited", null);
a61af66fc99e Initial load
duke
parents:
diff changeset
1608 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1609
a61af66fc99e Initial load
duke
parents:
diff changeset
1610 HeapProgress(String windowTitle, String progressBarTitle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1611 this(windowTitle, progressBarTitle, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
1612 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1613
a61af66fc99e Initial load
duke
parents:
diff changeset
1614 HeapProgress(String windowTitle, String progressBarTitle, CleanupThunk cleanup) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1615 this.windowTitle = windowTitle;
a61af66fc99e Initial load
duke
parents:
diff changeset
1616 this.progressBarTitle = progressBarTitle;
a61af66fc99e Initial load
duke
parents:
diff changeset
1617 this.cleanup = cleanup;
a61af66fc99e Initial load
duke
parents:
diff changeset
1618 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1619
a61af66fc99e Initial load
duke
parents:
diff changeset
1620 public void heapIterationFractionUpdate(final double fractionOfHeapVisited) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1621 if (frame == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1622 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1623 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1624 frame = new JInternalFrame(windowTitle);
a61af66fc99e Initial load
duke
parents:
diff changeset
1625 frame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1626 frame.setIconifiable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1627 frame.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
1628 bar = new ProgressBarPanel(progressBarTitle);
a61af66fc99e Initial load
duke
parents:
diff changeset
1629 frame.getContentPane().add(bar, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
1630 desktop.add(frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1631 frame.pack();
a61af66fc99e Initial load
duke
parents:
diff changeset
1632 GraphicsUtilities.constrainToSize(frame, frame.getParent().getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
1633 GraphicsUtilities.centerInContainer(frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1634 frame.show();
a61af66fc99e Initial load
duke
parents:
diff changeset
1635 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1636 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1637 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1638
a61af66fc99e Initial load
duke
parents:
diff changeset
1639 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1640 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1641 bar.setValue(fractionOfHeapVisited);
a61af66fc99e Initial load
duke
parents:
diff changeset
1642 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1643 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1644 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1645
a61af66fc99e Initial load
duke
parents:
diff changeset
1646 public void heapIterationComplete() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1647 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1648 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1649 desktop.remove(frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1650 desktop.repaint();
a61af66fc99e Initial load
duke
parents:
diff changeset
1651 if (VM.getVM().getRevPtrs() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1652 // Ended up computing reverse pointers as a side-effect
a61af66fc99e Initial load
duke
parents:
diff changeset
1653 computeRevPtrsMenuItem.setEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1654 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1655 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1656 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1657
a61af66fc99e Initial load
duke
parents:
diff changeset
1658 if (cleanup != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1659 cleanup.heapIterationComplete();
a61af66fc99e Initial load
duke
parents:
diff changeset
1660 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1661 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1662 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1663
a61af66fc99e Initial load
duke
parents:
diff changeset
1664 class VisitHeap implements Runnable {
a61af66fc99e Initial load
duke
parents:
diff changeset
1665 HeapVisitor visitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
1666
a61af66fc99e Initial load
duke
parents:
diff changeset
1667 VisitHeap(HeapVisitor visitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1668 this.visitor = visitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
1669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1670
a61af66fc99e Initial load
duke
parents:
diff changeset
1671 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1672 VM.getVM().getObjectHeap().iterate(visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
1673 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1674 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1675
a61af66fc99e Initial load
duke
parents:
diff changeset
1676 private void doHeapIteration(String frameTitle,
a61af66fc99e Initial load
duke
parents:
diff changeset
1677 String progressBarText,
a61af66fc99e Initial load
duke
parents:
diff changeset
1678 HeapVisitor visitor,
a61af66fc99e Initial load
duke
parents:
diff changeset
1679 CleanupThunk cleanup) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1680 sun.jvm.hotspot.oops.ObjectHistogram histo = new sun.jvm.hotspot.oops.ObjectHistogram();
a61af66fc99e Initial load
duke
parents:
diff changeset
1681 HeapProgress progress = new HeapProgress(frameTitle,
a61af66fc99e Initial load
duke
parents:
diff changeset
1682 progressBarText,
a61af66fc99e Initial load
duke
parents:
diff changeset
1683 cleanup);
a61af66fc99e Initial load
duke
parents:
diff changeset
1684 HeapVisitor progVisitor = new ProgressiveHeapVisitor(visitor, progress);
a61af66fc99e Initial load
duke
parents:
diff changeset
1685 workerThread.invokeLater(new VisitHeap(progVisitor));
a61af66fc99e Initial load
duke
parents:
diff changeset
1686 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1687
a61af66fc99e Initial load
duke
parents:
diff changeset
1688 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1689 // Stack trace helper
a61af66fc99e Initial load
duke
parents:
diff changeset
1690 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1691
a61af66fc99e Initial load
duke
parents:
diff changeset
1692 private static JavaVFrame getLastJavaVFrame(JavaThread cur) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1693 RegisterMap regMap = cur.newRegisterMap(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1694 sun.jvm.hotspot.runtime.Frame f = cur.getCurrentFrameGuess();
a61af66fc99e Initial load
duke
parents:
diff changeset
1695 if (f == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1696 boolean imprecise = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1697 if (f.isInterpretedFrame() && !f.isInterpretedFrameValid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1698 System.err.println("Correcting for invalid interpreter frame");
a61af66fc99e Initial load
duke
parents:
diff changeset
1699 f = f.sender(regMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
1700 imprecise = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1701 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1702 VFrame vf = VFrame.newVFrame(f, regMap, cur, true, imprecise);
a61af66fc99e Initial load
duke
parents:
diff changeset
1703 if (vf == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1704 System.err.println(" (Unable to create vframe for topmost frame guess)");
a61af66fc99e Initial load
duke
parents:
diff changeset
1705 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1706 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1707 if (vf.isJavaFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1708 return (JavaVFrame) vf;
a61af66fc99e Initial load
duke
parents:
diff changeset
1709 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1710 return (JavaVFrame) vf.javaSender();
a61af66fc99e Initial load
duke
parents:
diff changeset
1711 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1712
a61af66fc99e Initial load
duke
parents:
diff changeset
1713 // Internal routine for debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
1714 private static void dumpStack(JavaThread cur) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1715 RegisterMap regMap = cur.newRegisterMap(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1716 sun.jvm.hotspot.runtime.Frame f = cur.getCurrentFrameGuess();
a61af66fc99e Initial load
duke
parents:
diff changeset
1717 PrintStream tty = System.err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1718 while (f != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1719 tty.print("Found ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1720 if (f.isInterpretedFrame()) { tty.print("interpreted"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
1721 else if (f.isCompiledFrame()) { tty.print("compiled"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
1722 else if (f.isEntryFrame()) { tty.print("entry"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
1723 else if (f.isNativeFrame()) { tty.print("native"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
1724 else if (f.isGlueFrame()) { tty.print("glue"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
1725 else { tty.print("external"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
1726 tty.print(" frame with PC = " + f.getPC() + ", SP = " + f.getSP() + ", FP = " + f.getFP());
a61af66fc99e Initial load
duke
parents:
diff changeset
1727 if (f.isSignalHandlerFrameDbg()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1728 tty.print(" (SIGNAL HANDLER)");
a61af66fc99e Initial load
duke
parents:
diff changeset
1729 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1730 tty.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
1731
a61af66fc99e Initial load
duke
parents:
diff changeset
1732 if (!f.isFirstFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1733 f = f.sender(regMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
1734 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1735 f = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1736 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1737 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1738 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1739
a61af66fc99e Initial load
duke
parents:
diff changeset
1740 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1741 // Component utilities
a61af66fc99e Initial load
duke
parents:
diff changeset
1742 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1743
a61af66fc99e Initial load
duke
parents:
diff changeset
1744 private static JMenuItem createMenuItem(String name, ActionListener l) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1745 JMenuItem item = new JMenuItem(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1746 item.addActionListener(l);
a61af66fc99e Initial load
duke
parents:
diff changeset
1747 return item;
a61af66fc99e Initial load
duke
parents:
diff changeset
1748 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1749
a61af66fc99e Initial load
duke
parents:
diff changeset
1750 /** Punctuates the given string with \n's where necessary to not
a61af66fc99e Initial load
duke
parents:
diff changeset
1751 exceed the given number of characters per line. Strips
a61af66fc99e Initial load
duke
parents:
diff changeset
1752 extraneous whitespace. */
a61af66fc99e Initial load
duke
parents:
diff changeset
1753 private String formatMessage(String message, int charsPerLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1754 StringBuffer buf = new StringBuffer(message.length());
a61af66fc99e Initial load
duke
parents:
diff changeset
1755 StringTokenizer tokenizer = new StringTokenizer(message);
a61af66fc99e Initial load
duke
parents:
diff changeset
1756 int curLineLength = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1757 while (tokenizer.hasMoreTokens()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1758 String tok = tokenizer.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
1759 if (curLineLength + tok.length() > charsPerLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1760 buf.append('\n');
a61af66fc99e Initial load
duke
parents:
diff changeset
1761 curLineLength = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1762 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1763 if (curLineLength != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1764 buf.append(' ');
a61af66fc99e Initial load
duke
parents:
diff changeset
1765 ++curLineLength;
a61af66fc99e Initial load
duke
parents:
diff changeset
1766 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1767 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1768 buf.append(tok);
a61af66fc99e Initial load
duke
parents:
diff changeset
1769 curLineLength += tok.length();
a61af66fc99e Initial load
duke
parents:
diff changeset
1770 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1771 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
1772 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1773
a61af66fc99e Initial load
duke
parents:
diff changeset
1774 private void setMenuItemsEnabled(java.util.List items, boolean enabled) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1775 for (Iterator iter = items.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1776 ((JMenuItem) iter.next()).setEnabled(enabled);
a61af66fc99e Initial load
duke
parents:
diff changeset
1777 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1778 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1779 }