annotate agent/src/share/classes/sun/jvm/hotspot/ui/FindInHeapPanel.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: 196
diff changeset
2 * Copyright (c) 2002, 2008, 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: 196
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
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: 196
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.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.awt.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.awt.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import javax.swing.text.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.runtime.*;
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 /** Finds a given (Address) value in the heap. Only intended for use
a61af66fc99e Initial load
duke
parents:
diff changeset
40 in a debugging system. */
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 public class FindInHeapPanel extends JPanel {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private RawHeapVisitor iterator;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private long addressSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private long usedSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 private long iterated;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private Address value;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private ProgressBarPanel progressBar;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private HistoryComboBox addressField;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private JButton findButton;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private JTextArea textArea;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private ArrayList updates;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 private double lastFrac;
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 static final double minUpdateFraction = 0.05;
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 public FindInHeapPanel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 super();
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 JPanel topPanel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 JPanel panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
a61af66fc99e Initial load
duke
parents:
diff changeset
67 panel.add(new JLabel("Address to search for:"));
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 addressField = new HistoryComboBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 panel.add(addressField);
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 addressSize = VM.getVM().getAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 iterator = new RawHeapVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 boolean error = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 public void prologue(long used) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 usedSize = used;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 iterated = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 lastFrac = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 error = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 updates = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 public void visitAddress(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (error) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 Address val = addr.getAddressAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 if (AddressOps.equal(val, value)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 error = reportResult(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 iterated += addressSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 updateProgressBar();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
95 public void visitCompOopAddress(Address addr) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
96 if (error) return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
97
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
98 Address val = addr.getCompOopAddressAt(0);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
99 if (AddressOps.equal(val, value)) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
100 error = reportResult(addr);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
101 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
102 iterated += addressSize;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
103 updateProgressBar();
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
104
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
105 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
106 public void epilogue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 iterated = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 updateProgressBar();
a61af66fc99e Initial load
duke
parents:
diff changeset
109 findButton.setEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 };
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 findButton = new JButton("Find");
a61af66fc99e Initial load
duke
parents:
diff changeset
114 ActionListener listener = new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 clearResultWindow();
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // Parse text
a61af66fc99e Initial load
duke
parents:
diff changeset
118 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 Address val = VM.getVM().getDebugger().parseAddress(addressField.getText());
a61af66fc99e Initial load
duke
parents:
diff changeset
120 value = val;
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 findButton.setEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 java.lang.Thread t = new java.lang.Thread(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 VM.getVM().getObjectHeap().iterateRaw(iterator);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 } finally {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 findButton.setEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 });
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 });
a61af66fc99e Initial load
duke
parents:
diff changeset
137 t.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
138 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 textArea.setText("Error parsing address");
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 };
a61af66fc99e Initial load
duke
parents:
diff changeset
143 panel.add(findButton);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 findButton.addActionListener(listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 addressField.addActionListener(listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 topPanel.add(panel);
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 progressBar = new ProgressBarPanel(ProgressBarPanel.HORIZONTAL, "Search progress:");
a61af66fc99e Initial load
duke
parents:
diff changeset
149 topPanel.add(progressBar);
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 add(topPanel, BorderLayout.NORTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 textArea = new JTextArea();
a61af66fc99e Initial load
duke
parents:
diff changeset
154 JScrollPane scroller = new JScrollPane(textArea);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 add(scroller, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 private boolean pendingUpdate = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 private boolean reportResult(final Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 synchronized (this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 updates.add("found at " + addr + "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
164 if (!pendingUpdate) {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 pendingUpdate = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 updateResultWindow();
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 });
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 } catch (Throwable t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 t.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
174 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 private void clearResultWindow() {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 Document d = textArea.getDocument();
a61af66fc99e Initial load
duke
parents:
diff changeset
186 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 d.remove(0, d.getLength());
a61af66fc99e Initial load
duke
parents:
diff changeset
188 } catch (BadLocationException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191 });
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 private synchronized void updateResultWindow() {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (updates.size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 Iterator i = updates.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 while (i.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 textArea.append((String)i.next());
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200 updates = new ArrayList();;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 pendingUpdate = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 private void invokeInDispatchThread(Runnable runnable) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 if (EventQueue.isDispatchThread()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 runnable.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 SwingUtilities.invokeLater(runnable);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 private void updateProgressBar() {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 final double frac = (double) iterated / (double) usedSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
215 if (frac == 0.0 || (frac - lastFrac > minUpdateFraction)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 lastFrac = frac;
a61af66fc99e Initial load
duke
parents:
diff changeset
217 if (iterated > usedSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 System.out.println("iterated " + iterated + " usedSize " + usedSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 progressBar.setValue(frac);
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 });
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }