annotate agent/src/share/classes/sun/jvm/hotspot/ui/Inspector.java @ 6972:bd7a7ce2e264

6830717: replay of compilations would help with debugging Summary: When java process crashed in compiler thread, repeat the compilation process will help finding root cause. This is done with using SA dump application class data and replay data from core dump, then use debug version of jvm to recompile the problematic java method. Reviewed-by: kvn, twisti, sspitsyn Contributed-by: yumin.qi@oracle.com
author minqi
date Mon, 12 Nov 2012 14:03:53 -0800
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.ui;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.awt.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.awt.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import javax.swing.tree.TreePath;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.ui.tree.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 /** This class implements tree-browsing functionality of a particular
a61af66fc99e Initial load
duke
parents:
diff changeset
40 SimpleTreeNode, and is only designed to be used in a debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
41 system. It uses a SimpleTreeModel internally. It can inspect both
a61af66fc99e Initial load
duke
parents:
diff changeset
42 oops as well as C++ objects described by the VMStructs database in
a61af66fc99e Initial load
duke
parents:
diff changeset
43 the target VM. */
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 public class Inspector extends SAPanel {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 private JTree tree;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private SimpleTreeModel model;
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // UI widgets we need permanent handles to
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private HistoryComboBox addressField;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private JLabel statusLabel;
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 private JButton livenessButton;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private ActionListener livenessButtonListener;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 private ActionListener showLivenessListener;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 private static final String computeLivenessText = "Compute Liveness";
a61af66fc99e Initial load
duke
parents:
diff changeset
57 private static final String showLivenessText = "Show Liveness";
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private JLabel liveStatus;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 private LivenessPathList list = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private Oop currentOop = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 public Inspector() {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 model = new SimpleTreeModel();
a61af66fc99e Initial load
duke
parents:
diff changeset
64 tree = new JTree(model);
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
67 Box hbox = Box.createHorizontalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 JButton button = new JButton("Previous Oop");
a61af66fc99e Initial load
duke
parents:
diff changeset
69 button.addActionListener(new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 String text = addressField.getText();
a61af66fc99e Initial load
duke
parents:
diff changeset
72 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 VM vm = VM.getVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 Address a = vm.getDebugger().parseAddress(text);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 OopHandle handle = a.addOffsetToAsOopHandle(-vm.getAddressSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
76 addressField.setText(handle.toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
77 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 });
a61af66fc99e Initial load
duke
parents:
diff changeset
81 hbox.add(button);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 hbox.add(new JLabel("Address / C++ Expression: "));
a61af66fc99e Initial load
duke
parents:
diff changeset
83 addressField = new HistoryComboBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 hbox.add(addressField);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 statusLabel = new JLabel();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 hbox.add(statusLabel);
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 Box hboxDown = Box.createHorizontalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
89 hboxDown.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 livenessButton = new JButton(computeLivenessText);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 livenessButtonListener = new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if (currentOop != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 fireComputeLiveness();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 };
a61af66fc99e Initial load
duke
parents:
diff changeset
100 showLivenessListener = new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 fireShowLiveness();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 };
a61af66fc99e Initial load
duke
parents:
diff changeset
105 livenessButton.addActionListener(livenessButtonListener);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 hboxDown.add(livenessButton);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 hboxDown.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 liveStatus = new JLabel();
a61af66fc99e Initial load
duke
parents:
diff changeset
110 hboxDown.add(liveStatus);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 hboxDown.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 add(hbox, BorderLayout.NORTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 add(hboxDown, BorderLayout.SOUTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 addressField.addActionListener(new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 String text = addressField.getText();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 Address a = VM.getVM().getDebugger().parseAddress(text);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 int max_searches = 1000;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 int searches = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 int offset = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 Oop oop = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 if (a != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 OopHandle handle = a.addOffsetToAsOopHandle(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 while (searches < max_searches) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 searches++;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 if (RobustOopDeterminator.oopLooksValid(handle)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 oop = VM.getVM().getObjectHeap().newOop(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 addressField.setText(handle.toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
133 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 } catch (UnknownOopException ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // ok
a61af66fc99e Initial load
duke
parents:
diff changeset
136 } catch (RuntimeException ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 ex.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 offset -= 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 handle = a.addOffsetToAsOopHandle(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 if (oop != currentOop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 currentOop = oop;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 liveStatus.setText("");
a61af66fc99e Initial load
duke
parents:
diff changeset
147 list = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 if (livenessButton.getText().equals(showLivenessText)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 livenessButton.setText(computeLivenessText);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 livenessButton.removeActionListener(showLivenessListener);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 livenessButton.addActionListener(livenessButtonListener);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 if (oop != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 statusLabel.setText("");
a61af66fc99e Initial load
duke
parents:
diff changeset
157 setRoot(new OopTreeNodeAdapter(oop, null));
a61af66fc99e Initial load
duke
parents:
diff changeset
158 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // Try to treat this address as a C++ object and deduce its type
a61af66fc99e Initial load
duke
parents:
diff changeset
162 Type t = VM.getVM().getTypeDataBase().guessTypeForAddress(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 if (t != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 statusLabel.setText("");
a61af66fc99e Initial load
duke
parents:
diff changeset
165 setRoot(new CTypeTreeNodeAdapter(a, t, null));
a61af66fc99e Initial load
duke
parents:
diff changeset
166 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 statusLabel.setText("<bad oop or unknown C++ object " + text + ">");
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 catch (NumberFormatException ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 currentOop = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 liveStatus.setText("");
a61af66fc99e Initial load
duke
parents:
diff changeset
174 list = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 if (livenessButton.getText().equals(showLivenessText)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 livenessButton.setText(computeLivenessText);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 livenessButton.removeActionListener(showLivenessListener);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 livenessButton.addActionListener(livenessButtonListener);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // Try to treat this as a C++ expression
a61af66fc99e Initial load
duke
parents:
diff changeset
181 CPPExpressions.CastExpr cast = CPPExpressions.parseCast(text);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 if (cast != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 TypeDataBase db = VM.getVM().getTypeDataBase();
a61af66fc99e Initial load
duke
parents:
diff changeset
184 Type t = db.lookupType(cast.getType());
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (t == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 statusLabel.setText("<unknown C++ type \"" + cast.getType() + "\">");
a61af66fc99e Initial load
duke
parents:
diff changeset
187 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 Address a = VM.getVM().getDebugger().parseAddress(cast.getAddress());
a61af66fc99e Initial load
duke
parents:
diff changeset
190 statusLabel.setText("");
a61af66fc99e Initial load
duke
parents:
diff changeset
191 setRoot(new CTypeTreeNodeAdapter(a, t, null));
a61af66fc99e Initial load
duke
parents:
diff changeset
192 } catch (NumberFormatException ex2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 statusLabel.setText("<bad address " + cast.getAddress() + ">");
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 CPPExpressions.StaticFieldExpr stat = CPPExpressions.parseStaticField(text);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 if (stat != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 TypeDataBase db = VM.getVM().getTypeDataBase();
a61af66fc99e Initial load
duke
parents:
diff changeset
201 Type t = db.lookupType(stat.getContainingType());
a61af66fc99e Initial load
duke
parents:
diff changeset
202 if (t == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 statusLabel.setText("<unknown C++ type \"" + stat.getContainingType() + "\">");
a61af66fc99e Initial load
duke
parents:
diff changeset
204 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 sun.jvm.hotspot.types.Field f = t.getField(stat.getFieldName(), true, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 if (f == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 statusLabel.setText("<unknown field \"" + stat.getFieldName() + "\" in type \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
208 stat.getContainingType() + "\">");
a61af66fc99e Initial load
duke
parents:
diff changeset
209 } else if (!f.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 statusLabel.setText("<field \"" + stat.getContainingType() + "::" +
a61af66fc99e Initial load
duke
parents:
diff changeset
211 stat.getFieldName() + "\" was not static>");
a61af66fc99e Initial load
duke
parents:
diff changeset
212 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 Type fieldType = f.getType();
a61af66fc99e Initial load
duke
parents:
diff changeset
214 if (fieldType.isPointerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 fieldType = ((PointerType) fieldType).getTargetType();
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // Try to get a more derived type
a61af66fc99e Initial load
duke
parents:
diff changeset
218 Type typeGuess = db.guessTypeForAddress(f.getAddress());
a61af66fc99e Initial load
duke
parents:
diff changeset
219 if (typeGuess != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 fieldType = typeGuess;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 statusLabel.setText("");
a61af66fc99e Initial load
duke
parents:
diff changeset
224 setRoot(new CTypeTreeNodeAdapter(f.getAddress(),
a61af66fc99e Initial load
duke
parents:
diff changeset
225 fieldType,
a61af66fc99e Initial load
duke
parents:
diff changeset
226 new NamedFieldIdentifier(text)));
a61af66fc99e Initial load
duke
parents:
diff changeset
227 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 statusLabel.setText("");
a61af66fc99e Initial load
duke
parents:
diff changeset
229 setRoot(new CTypeTreeNodeAdapter(f.getStaticFieldAddress(),
a61af66fc99e Initial load
duke
parents:
diff changeset
230 f.getType(),
a61af66fc99e Initial load
duke
parents:
diff changeset
231 new NamedFieldIdentifier(text)));
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 statusLabel.setText("<parse error>");
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240 catch (AddressException ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 ex.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
242 currentOop = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
243 liveStatus.setText("");
a61af66fc99e Initial load
duke
parents:
diff changeset
244 list = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
245 if (livenessButton.getText().equals(showLivenessText)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 livenessButton.setText(computeLivenessText);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 livenessButton.removeActionListener(showLivenessListener);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 livenessButton.addActionListener(livenessButtonListener);
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250 statusLabel.setText("<bad address>");
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 ex.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
254 currentOop = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
255 liveStatus.setText("");
a61af66fc99e Initial load
duke
parents:
diff changeset
256 list = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
257 if (livenessButton.getText().equals(showLivenessText)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 livenessButton.setText(computeLivenessText);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 livenessButton.removeActionListener(showLivenessListener);
a61af66fc99e Initial load
duke
parents:
diff changeset
260 livenessButton.addActionListener(livenessButtonListener);
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 statusLabel.setText("<error constructing oop>");
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 });
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 MouseListener ml = new MouseAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 public void mousePressed(MouseEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 int selRow = tree.getRowForLocation(e.getX(), e.getY());
a61af66fc99e Initial load
duke
parents:
diff changeset
270 TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
a61af66fc99e Initial load
duke
parents:
diff changeset
271 if(selRow != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 if (e.getClickCount() == 1 && (e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 Object node = tree.getLastSelectedPathComponent();
a61af66fc99e Initial load
duke
parents:
diff changeset
274 if (node != null && node instanceof SimpleTreeNode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 showInspector((SimpleTreeNode)node);
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
280 };
a61af66fc99e Initial load
duke
parents:
diff changeset
281 tree.addMouseListener(ml);
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 JScrollPane scrollPane = new JScrollPane(tree);
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // Let's see what happens if we let the parent deal with resizing the panel
a61af66fc99e Initial load
duke
parents:
diff changeset
286 add(scrollPane, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 public Inspector(final SimpleTreeNode root) {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 this();
a61af66fc99e Initial load
duke
parents:
diff changeset
291 SwingUtilities.invokeLater( new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 if (root instanceof OopTreeNodeAdapter) {
a61af66fc99e Initial load
duke
parents:
diff changeset
294 final Oop oop = ((OopTreeNodeAdapter)root).getOop();
a61af66fc99e Initial load
duke
parents:
diff changeset
295 addressField.setText(oop.getHandle().toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297 setRoot(root);
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299 });
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 private void setRoot(SimpleTreeNode root) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 model.setRoot(root);
a61af66fc99e Initial load
duke
parents:
diff changeset
304
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // tree.invalidate();
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // tree.validate();
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // repaint();
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // FIXME: invalidate? How to get to redraw? Will I have to make
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // tree listeners work?
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312 private void fireComputeLiveness() {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 final Runnable cutoverButtonRunnable = new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
315 list = LivenessAnalysis.computeAllLivenessPaths(currentOop);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 if (list == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 liveStatus.setText("Oop is Dead");
a61af66fc99e Initial load
duke
parents:
diff changeset
318 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 liveStatus.setText("Oop is Alive");
a61af66fc99e Initial load
duke
parents:
diff changeset
320 livenessButton.removeActionListener(livenessButtonListener);
a61af66fc99e Initial load
duke
parents:
diff changeset
321 livenessButton.addActionListener(showLivenessListener);
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 livenessButton.setEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
324 livenessButton.setText(showLivenessText);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327 };
a61af66fc99e Initial load
duke
parents:
diff changeset
328
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 if (VM.getVM().getRevPtrs() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
331 cutoverButtonRunnable.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
332 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 final WorkerThread worker = new WorkerThread();
a61af66fc99e Initial load
duke
parents:
diff changeset
334 worker.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 ReversePtrsAnalysis rev = new ReversePtrsAnalysis();
a61af66fc99e Initial load
duke
parents:
diff changeset
338 rev.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
339 cutoverButtonRunnable.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
340 } finally {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 worker.shutdown();
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
344 });
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347
a61af66fc99e Initial load
duke
parents:
diff changeset
348 private void fireShowLiveness() {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 if (list == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 return; // dead object
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 for (Iterator iter = listeners.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 SAListener listener = (SAListener) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
355 listener.showLiveness(currentOop, list);
a61af66fc99e Initial load
duke
parents:
diff changeset
356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }