annotate agent/src/share/classes/sun/jvm/hotspot/ui/FindInCodeCachePanel.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children 3e8fbc61cee8
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) 2004, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.ui;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.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 javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import javax.swing.event.*;
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 import sun.jvm.hotspot.code.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.ui.classbrowser.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 /** Finds a given (Address) value in the code cache. Only intended for use
a61af66fc99e Initial load
duke
parents:
diff changeset
42 in a debugging system. */
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 public class FindInCodeCachePanel extends SAPanel {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private Visitor iterator;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 private long usedSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private long iterated;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private Address value;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private ProgressBarPanel progressBar;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private HistoryComboBox addressField;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private JButton findButton;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private SAEditorPane contentEditor;
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 class Visitor implements CodeCacheVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 Address base;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 StringBuffer result;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 boolean searching;
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public void prologue(Address start, Address end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 searching = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 base = start;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 usedSize = end.minus(start);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 iterated = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 result = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
65 clearResultWindow();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 public void visit(CodeBlob blob) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 Address begin = blob.headerBegin();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 Address end = begin.addOffsetTo(blob.getSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
71 long addressSize = VM.getVM().getAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 boolean found = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 while (!found && begin.lessThan(end)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 Address val = begin.getAddressAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 if (AddressOps.equal(val, value)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 reportResult(result, blob);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 found = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 begin = begin.addOffsetTo(addressSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 iterated = end.minus(base);;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 updateProgressBar(null);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 public void epilogue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 public void cleanup() {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 iterated = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 updateProgressBar(result);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 searching = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 result = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 private void search() {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // Parse text
a61af66fc99e Initial load
duke
parents:
diff changeset
98 Address val = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 val = VM.getVM().getDebugger().parseAddress(addressField.getText());
a61af66fc99e Initial load
duke
parents:
diff changeset
101 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 contentEditor.setText("<b>Error parsing address</b>");
a61af66fc99e Initial load
duke
parents:
diff changeset
103 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // make sure we don't start up multiple search threads in parallel
a61af66fc99e Initial load
duke
parents:
diff changeset
107 synchronized (iterator) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if (searching && value.equals(val)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 value = val;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 contentEditor.setText("");
a61af66fc99e Initial load
duke
parents:
diff changeset
114 findButton.setEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 System.out.println("Searching " + value);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 java.lang.Thread t = new java.lang.Thread(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 synchronized (iterator) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 VM.getVM().getCodeCache().iterate(iterator);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 } finally {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 iterator.cleanup();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 });
a61af66fc99e Initial load
duke
parents:
diff changeset
128 t.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 public FindInCodeCachePanel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 super();
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 JPanel topPanel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
140 topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 JPanel panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
143 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
a61af66fc99e Initial load
duke
parents:
diff changeset
144 panel.add(new JLabel("Address to search for:"));
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 addressField = new HistoryComboBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 panel.add(addressField);
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 iterator = new Visitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 findButton = new JButton("Find");
a61af66fc99e Initial load
duke
parents:
diff changeset
152 ActionListener listener = new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 iterator.search();
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 };
a61af66fc99e Initial load
duke
parents:
diff changeset
157 panel.add(findButton);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 findButton.addActionListener(listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 addressField.addActionListener(listener);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 topPanel.add(panel);
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 progressBar = new ProgressBarPanel(ProgressBarPanel.HORIZONTAL, "Search progress:");
a61af66fc99e Initial load
duke
parents:
diff changeset
163 topPanel.add(progressBar);
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 add(topPanel, BorderLayout.NORTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 contentEditor = new SAEditorPane();
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 HyperlinkListener hyperListener = new HyperlinkListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 public void hyperlinkUpdate(HyperlinkEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 String description = e.getDescription();
a61af66fc99e Initial load
duke
parents:
diff changeset
173 int index = description.indexOf(':');
a61af66fc99e Initial load
duke
parents:
diff changeset
174 if (index != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 String item = description.substring(0, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (item.equals("blob")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 Address blob = VM.getVM().getDebugger().parseAddress(description.substring(index + 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
178 showCodeViewer(blob);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183 };
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 contentEditor.addHyperlinkListener(hyperListener);
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 JScrollPane scroller = new JScrollPane(contentEditor);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 add(scroller, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 private void reportResult(StringBuffer result, CodeBlob blob) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 result.append("<a href='blob:");
a61af66fc99e Initial load
duke
parents:
diff changeset
193 result.append(blob.instructionsBegin().toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
194 result.append("'>");
a61af66fc99e Initial load
duke
parents:
diff changeset
195 result.append(blob.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
196 result.append("@");
a61af66fc99e Initial load
duke
parents:
diff changeset
197 result.append(blob.instructionsBegin());
a61af66fc99e Initial load
duke
parents:
diff changeset
198 result.append("</a><br>");
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 private void clearResultWindow() {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 contentEditor.setText("");
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206 });
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 private void updateProgressBar(final StringBuffer result) {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 progressBar.setValue((double) iterated / (double) usedSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 if (result != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 String s = "<html> <head> </head> <body>\n" + result + " </body> </html>";
a61af66fc99e Initial load
duke
parents:
diff changeset
215 contentEditor.setText(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
216 findButton.setEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 });
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }