author | jrose |
Wed, 09 Jun 2010 18:50:45 -0700 | |
changeset 5882 | 6b2aecc4f7d8 |
parent 5547 | f4b087cbb361 |
child 6062 | bab93afe9df7 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5341
diff
changeset
|
2 |
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5341
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5341
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5341
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot.ui.classbrowser; |
|
26 |
||
27 |
import java.io.*; |
|
28 |
import java.util.*; |
|
29 |
import sun.jvm.hotspot.asm.*; |
|
30 |
import sun.jvm.hotspot.asm.sparc.*; |
|
31 |
import sun.jvm.hotspot.asm.x86.*; |
|
32 |
import sun.jvm.hotspot.asm.ia64.*; |
|
33 |
import sun.jvm.hotspot.code.*; |
|
34 |
import sun.jvm.hotspot.compiler.*; |
|
35 |
import sun.jvm.hotspot.debugger.*; |
|
36 |
import sun.jvm.hotspot.interpreter.*; |
|
37 |
import sun.jvm.hotspot.memory.*; |
|
38 |
import sun.jvm.hotspot.oops.*; |
|
39 |
import sun.jvm.hotspot.runtime.*; |
|
40 |
import sun.jvm.hotspot.tools.jcore.*; |
|
41 |
import sun.jvm.hotspot.types.*; |
|
42 |
import sun.jvm.hotspot.utilities.*; |
|
43 |
||
44 |
public class HTMLGenerator implements /* imports */ ClassConstants { |
|
45 |
static class Formatter { |
|
46 |
boolean html; |
|
47 |
StringBuffer buf = new StringBuffer(); |
|
48 |
||
49 |
Formatter(boolean h) { |
|
50 |
html = h; |
|
51 |
} |
|
52 |
||
53 |
void append(String s) { |
|
54 |
buf.append(s); |
|
55 |
} |
|
56 |
||
57 |
void append(int s) { |
|
58 |
buf.append(s); |
|
59 |
} |
|
60 |
||
61 |
void append(char s) { |
|
62 |
buf.append(s); |
|
63 |
} |
|
64 |
||
65 |
void append(StringBuffer s) { |
|
66 |
buf.append(s); |
|
67 |
} |
|
68 |
||
69 |
void append(Formatter s) { |
|
70 |
buf.append(s); |
|
71 |
} |
|
72 |
||
73 |
StringBuffer getBuffer() { |
|
74 |
return buf; |
|
75 |
} |
|
76 |
||
77 |
public String toString() { |
|
78 |
return buf.toString(); |
|
79 |
} |
|
80 |
||
81 |
void wrap(String tag, String text) { |
|
82 |
wrap(tag, tag, text); |
|
83 |
} |
|
84 |
void wrap(String before, String after, String text) { |
|
85 |
beginTag(before); |
|
86 |
append(text); |
|
87 |
endTag(after); |
|
88 |
} |
|
89 |
||
90 |
// header tags |
|
91 |
void h1(String s) { nl(); wrap("h1", s); nl(); } |
|
92 |
void h2(String s) { nl(); wrap("h2", s); nl(); } |
|
93 |
void h3(String s) { nl(); wrap("h3", s); nl(); } |
|
94 |
void h4(String s) { nl(); wrap("h4", s); nl(); } |
|
95 |
||
96 |
// list tags |
|
97 |
void beginList() { beginTag("ul"); nl(); } |
|
5341 | 98 |
void endList() { endTag("ul"); nl(); } |
99 |
void beginListItem() { beginTag("li"); } |
|
100 |
void endListItem() { endTag("li"); nl(); } |
|
1 | 101 |
void li(String s) { wrap("li", s); nl(); } |
102 |
||
103 |
// table tags |
|
104 |
void beginTable(int border) { |
|
105 |
beginTag("table border='" + border + "'"); |
|
106 |
} |
|
107 |
void cell(String s) { wrap("td", s); } |
|
108 |
void headerCell(String s) { wrap("th", s); } |
|
109 |
void endTable() { endTag("table"); } |
|
110 |
||
111 |
void link(String href, String text) { |
|
112 |
wrap("a href='" + href + "'", "a", text); |
|
113 |
} |
|
114 |
void beginTag(String s) { |
|
115 |
if (html) { append("<"); append(s); append(">"); } |
|
116 |
} |
|
117 |
void endTag(String s) { |
|
118 |
if (html) { |
|
119 |
append("</"); append(s); append(">"); |
|
120 |
} else { |
|
121 |
if (s.equals("table") || s.equals("tr")) { |
|
122 |
nl(); |
|
123 |
} |
|
124 |
if (s.equals("td") || s.equals("th")) { |
|
125 |
append(" "); |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
void bold(String s) { |
|
130 |
wrap("b", s); |
|
131 |
} |
|
132 |
||
133 |
void nl() { |
|
134 |
if (!html) buf.append("\n"); |
|
135 |
} |
|
136 |
||
137 |
void br() { |
|
138 |
if (html) append("<br>"); |
|
139 |
else append("\n"); |
|
140 |
} |
|
141 |
void genEmptyHTML() { |
|
142 |
if (html) append("<html></html>"); |
|
143 |
} |
|
144 |
||
145 |
void genHTMLPrologue() { |
|
146 |
if (html) append("<html><body>"); |
|
147 |
} |
|
148 |
||
149 |
void genHTMLPrologue(String title) { |
|
150 |
if (html) { |
|
151 |
append("<html><head><title>"); |
|
152 |
append(title); |
|
153 |
append("</title></head>"); |
|
154 |
append("<body>"); |
|
155 |
} |
|
156 |
h2(title); |
|
157 |
} |
|
158 |
void genHTMLEpilogue() { |
|
159 |
if (html) append("</body></html>"); |
|
160 |
} |
|
161 |
||
162 |
} |
|
163 |
||
164 |
private static final String DUMP_KLASS_OUTPUT_DIR = "."; |
|
165 |
private static final int NATIVE_CODE_SIZE = 200; |
|
166 |
private final String spaces; |
|
167 |
private final String tab; |
|
168 |
||
169 |
private boolean genHTML = true; |
|
170 |
||
171 |
public HTMLGenerator() { |
|
172 |
this(true); |
|
173 |
} |
|
174 |
||
175 |
public HTMLGenerator(boolean html) { |
|
176 |
genHTML = html; |
|
177 |
if (html) { |
|
178 |
spaces = " "; |
|
179 |
tab = " "; |
|
180 |
} else { |
|
181 |
spaces = " "; |
|
182 |
tab = " "; |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
private static CPUHelper cpuHelper; |
|
187 |
static { |
|
188 |
VM.registerVMInitializedObserver(new Observer() { |
|
189 |
public void update(Observable o, Object data) { |
|
190 |
initialize(); |
|
191 |
} |
|
192 |
}); |
|
193 |
} |
|
194 |
||
195 |
private static synchronized void initialize() { |
|
196 |
String cpu = VM.getVM().getCPU(); |
|
197 |
if (cpu.equals("sparc")) { |
|
198 |
cpuHelper = new SPARCHelper(); |
|
199 |
} else if (cpu.equals("x86")) { |
|
200 |
cpuHelper = new X86Helper(); |
|
201 |
} else if (cpu.equals("ia64")) { |
|
202 |
cpuHelper = new IA64Helper(); |
|
203 |
} else { |
|
204 |
throw new RuntimeException("cpu '" + cpu + "' is not yet supported!"); |
|
205 |
} |
|
206 |
} |
|
207 |
||
208 |
protected static synchronized CPUHelper getCPUHelper() { |
|
209 |
return cpuHelper; |
|
210 |
} |
|
211 |
||
212 |
protected String escapeHTMLSpecialChars(String value) { |
|
213 |
if (!genHTML) return value; |
|
214 |
||
215 |
Formatter buf = new Formatter(genHTML); |
|
216 |
int len = value.length(); |
|
217 |
for (int i=0; i < len; i++) { |
|
218 |
char c = value.charAt(i); |
|
219 |
switch (c) { |
|
220 |
case '<': |
|
221 |
buf.append("<"); |
|
222 |
break; |
|
223 |
case '>': |
|
224 |
buf.append(">"); |
|
225 |
break; |
|
226 |
case '&': |
|
227 |
buf.append("&"); |
|
228 |
break; |
|
229 |
default: |
|
230 |
buf.append(c); |
|
231 |
break; |
|
232 |
} |
|
233 |
} |
|
234 |
return buf.toString(); |
|
235 |
} |
|
236 |
||
237 |
public String genHTMLForMessage(String message) { |
|
238 |
Formatter buf = new Formatter(genHTML); |
|
239 |
buf.genHTMLPrologue(message); |
|
240 |
buf.genHTMLEpilogue(); |
|
241 |
return buf.toString(); |
|
242 |
} |
|
243 |
||
244 |
public String genHTMLErrorMessage(Exception exp) { |
|
245 |
exp.printStackTrace(); |
|
246 |
return genHTMLForMessage(exp.getClass().getName() + " : " + exp.getMessage()); |
|
247 |
} |
|
248 |
||
249 |
public String genHTMLForWait(String message) { |
|
250 |
Formatter buf = new Formatter(genHTML); |
|
251 |
buf.genHTMLPrologue("Please wait .."); |
|
252 |
buf.h2(message); |
|
253 |
return buf.toString(); |
|
254 |
} |
|
255 |
||
256 |
protected String genKlassTitle(InstanceKlass klass) { |
|
257 |
Formatter buf = new Formatter(genHTML); |
|
258 |
AccessFlags acc = klass.getAccessFlagsObj(); |
|
259 |
if (acc.isPublic()) { |
|
260 |
buf.append("public "); |
|
261 |
} else if (acc.isProtected()) { |
|
262 |
buf.append("protected "); |
|
263 |
} else if (acc.isPrivate()) { |
|
264 |
buf.append("private "); |
|
265 |
} |
|
266 |
||
267 |
if (acc.isStatic()) { |
|
268 |
buf.append("static "); |
|
269 |
} |
|
270 |
||
271 |
if (acc.isAbstract() ) { |
|
272 |
buf.append("abstract "); |
|
273 |
} else if (acc.isFinal()) { |
|
274 |
buf.append("final "); |
|
275 |
} |
|
276 |
||
277 |
if (acc.isStrict()) { |
|
278 |
buf.append("strict "); |
|
279 |
} |
|
280 |
||
281 |
// javac generated flags |
|
282 |
if (acc.isEnum()) { |
|
283 |
buf.append("[enum] "); |
|
284 |
} |
|
285 |
if (acc.isSynthetic()) { |
|
286 |
buf.append("[synthetic] "); |
|
287 |
} |
|
288 |
||
289 |
if (klass.isInterface()) { |
|
290 |
buf.append("interface"); |
|
291 |
} else { |
|
292 |
buf.append("class"); |
|
293 |
} |
|
294 |
||
295 |
buf.append(' '); |
|
296 |
buf.append(klass.getName().asString().replace('/', '.')); |
|
297 |
// is it generic? |
|
298 |
Symbol genSig = klass.getGenericSignature(); |
|
299 |
if (genSig != null) { |
|
300 |
buf.append(" [signature "); |
|
301 |
buf.append(escapeHTMLSpecialChars(genSig.asString())); |
|
302 |
buf.append("] "); |
|
303 |
} else { |
|
304 |
buf.append(' '); |
|
305 |
} |
|
306 |
buf.append('@'); |
|
307 |
buf.append(klass.getHandle().toString()); |
|
308 |
return buf.toString(); |
|
309 |
} |
|
310 |
||
311 |
protected String genBaseHref() { |
|
312 |
return ""; |
|
313 |
} |
|
314 |
||
315 |
protected String genKlassHref(InstanceKlass klass) { |
|
316 |
return genBaseHref() + "klass=" + klass.getHandle(); |
|
317 |
} |
|
318 |
||
319 |
protected String genKlassLink(InstanceKlass klass) { |
|
320 |
Formatter buf = new Formatter(genHTML); |
|
321 |
buf.link(genKlassHref(klass), genKlassTitle(klass)); |
|
322 |
return buf.toString(); |
|
323 |
} |
|
324 |
||
325 |
protected String genMethodModifierString(AccessFlags acc) { |
|
326 |
Formatter buf = new Formatter(genHTML); |
|
327 |
if (acc.isPrivate()) { |
|
328 |
buf.append("private "); |
|
329 |
} else if (acc.isProtected()) { |
|
330 |
buf.append("protected "); |
|
331 |
} else if (acc.isPublic()) { |
|
332 |
buf.append("public "); |
|
333 |
} |
|
334 |
||
335 |
if (acc.isStatic()) { |
|
336 |
buf.append("static "); |
|
337 |
} else if (acc.isAbstract() ) { |
|
338 |
buf.append("abstract "); |
|
339 |
} else if (acc.isFinal()) { |
|
340 |
buf.append("final "); |
|
341 |
} |
|
342 |
||
343 |
if (acc.isNative()) { |
|
344 |
buf.append("native "); |
|
345 |
} |
|
346 |
||
347 |
if (acc.isStrict()) { |
|
348 |
buf.append("strict "); |
|
349 |
} |
|
350 |
||
351 |
if (acc.isSynchronized()) { |
|
352 |
buf.append("synchronized "); |
|
353 |
} |
|
354 |
||
355 |
// javac generated flags |
|
356 |
if (acc.isBridge()) { |
|
357 |
buf.append("[bridge] "); |
|
358 |
} |
|
359 |
||
360 |
if (acc.isSynthetic()) { |
|
361 |
buf.append("[synthetic] "); |
|
362 |
} |
|
363 |
||
364 |
if (acc.isVarArgs()) { |
|
365 |
buf.append("[varargs] "); |
|
366 |
} |
|
367 |
||
368 |
return buf.toString(); |
|
369 |
} |
|
370 |
||
371 |
protected String genMethodNameAndSignature(Method method) { |
|
372 |
Formatter buf = new Formatter(genHTML); |
|
373 |
buf.append(genMethodModifierString(method.getAccessFlagsObj())); |
|
374 |
Symbol sig = method.getSignature(); |
|
375 |
new SignatureConverter(sig, buf.getBuffer()).iterateReturntype(); |
|
376 |
buf.append(" "); |
|
377 |
String methodName = method.getName().asString(); |
|
378 |
buf.append(escapeHTMLSpecialChars(methodName)); |
|
379 |
buf.append('('); |
|
380 |
new SignatureConverter(sig, buf.getBuffer()).iterateParameters(); |
|
381 |
buf.append(')'); |
|
382 |
// is it generic? |
|
383 |
Symbol genSig = method.getGenericSignature(); |
|
384 |
if (genSig != null) { |
|
385 |
buf.append(" [signature "); |
|
386 |
buf.append(escapeHTMLSpecialChars(genSig.asString())); |
|
387 |
buf.append("] "); |
|
388 |
} |
|
389 |
return buf.toString().replace('/', '.'); |
|
390 |
} |
|
391 |
||
392 |
protected String genMethodTitle(Method method) { |
|
393 |
Formatter buf = new Formatter(genHTML); |
|
394 |
buf.append(genMethodNameAndSignature(method)); |
|
395 |
buf.append(' '); |
|
396 |
buf.append('@'); |
|
397 |
buf.append(method.getHandle().toString()); |
|
398 |
return buf.toString(); |
|
399 |
} |
|
400 |
||
401 |
protected String genMethodHref(Method m) { |
|
402 |
return genBaseHref() + "method=" + m.getHandle(); |
|
403 |
} |
|
404 |
||
405 |
protected String genMethodLink(Method m) { |
|
406 |
Formatter buf = new Formatter(genHTML); |
|
407 |
buf.link(genMethodHref(m), genMethodTitle(m)); |
|
408 |
return buf.toString(); |
|
409 |
} |
|
410 |
||
411 |
protected String genMethodAndKlassLink(Method m) { |
|
412 |
Formatter buf = new Formatter(genHTML); |
|
413 |
buf.append(genMethodLink(m)); |
|
414 |
buf.append(" of "); |
|
415 |
buf.append(genKlassLink((InstanceKlass) m.getMethodHolder())); |
|
416 |
return buf.toString(); |
|
417 |
} |
|
418 |
||
419 |
protected String genNMethodHref(NMethod nm) { |
|
420 |
return genBaseHref() + "nmethod=" + nm.getAddress(); |
|
421 |
} |
|
422 |
||
423 |
public String genNMethodTitle(NMethod nmethod) { |
|
424 |
Formatter buf = new Formatter(genHTML); |
|
425 |
Method m = nmethod.getMethod(); |
|
426 |
||
427 |
buf.append("Disassembly for compiled method ["); |
|
428 |
buf.append(genMethodTitle(m)); |
|
429 |
buf.append(" ] "); |
|
430 |
buf.append('@'); |
|
431 |
buf.append(nmethod.getAddress().toString()); |
|
432 |
return buf.toString(); |
|
433 |
} |
|
434 |
||
435 |
protected String genNMethodLink(NMethod nm) { |
|
436 |
Formatter buf = new Formatter(genHTML); |
|
437 |
buf.link(genNMethodHref(nm), genNMethodTitle(nm)); |
|
438 |
return buf.toString(); |
|
439 |
} |
|
440 |
||
441 |
public String genCodeBlobTitle(CodeBlob blob) { |
|
442 |
Formatter buf = new Formatter(genHTML); |
|
443 |
buf.append("Disassembly for code blob " + blob.getName() + " ["); |
|
444 |
buf.append(blob.getClass().getName()); |
|
445 |
buf.append(" ] @"); |
|
446 |
buf.append(blob.getAddress().toString()); |
|
447 |
return buf.toString(); |
|
448 |
} |
|
449 |
||
450 |
protected BytecodeDisassembler createBytecodeDisassembler(Method m) { |
|
451 |
return new BytecodeDisassembler(m); |
|
452 |
} |
|
453 |
||
454 |
private String genLowHighShort(int val) { |
|
455 |
Formatter buf = new Formatter(genHTML); |
|
456 |
buf.append('#'); |
|
457 |
buf.append(Integer.toString(val & 0xFFFF)); |
|
458 |
buf.append(" #"); |
|
459 |
buf.append(Integer.toString((val >> 16) & 0xFFFF)); |
|
460 |
return buf.toString(); |
|
461 |
} |
|
462 |
||
463 |
protected String genHTMLTableForConstantPool(ConstantPool cpool) { |
|
464 |
Formatter buf = new Formatter(genHTML); |
|
465 |
buf.beginTable(1); |
|
466 |
||
467 |
buf.beginTag("tr"); |
|
468 |
buf.headerCell("Index"); |
|
469 |
buf.headerCell("Constant Type"); |
|
470 |
buf.headerCell("Constant Value"); |
|
471 |
buf.endTag("tr"); |
|
472 |
||
473 |
final int length = (int) cpool.getLength(); |
|
474 |
// zero'th pool entry is always invalid. ignore it. |
|
475 |
for (int index = 1; index < length; index++) { |
|
476 |
buf.beginTag("tr"); |
|
477 |
buf.cell(Integer.toString(index)); |
|
478 |
||
479 |
int ctag = (int) cpool.getTags().getByteAt((int) index); |
|
480 |
switch (ctag) { |
|
481 |
case JVM_CONSTANT_Integer: |
|
482 |
buf.cell("JVM_CONSTANT_Integer"); |
|
483 |
buf.cell(Integer.toString(cpool.getIntAt(index))); |
|
484 |
break; |
|
485 |
||
486 |
case JVM_CONSTANT_Float: |
|
487 |
buf.cell("JVM_CONSTANT_Float"); |
|
488 |
buf.cell(Float.toString(cpool.getFloatAt(index))); |
|
489 |
break; |
|
490 |
||
491 |
case JVM_CONSTANT_Long: |
|
492 |
buf.cell("JVM_CONSTANT_Long"); |
|
493 |
buf.cell(Long.toString(cpool.getLongAt(index))); |
|
494 |
// long entries occupy two slots |
|
495 |
index++; |
|
496 |
break; |
|
497 |
||
498 |
case JVM_CONSTANT_Double: |
|
499 |
buf.cell("JVM_CONSTANT_Double"); |
|
500 |
buf.cell(Double.toString(cpool.getDoubleAt(index))); |
|
501 |
// double entries occupy two slots |
|
502 |
index++; |
|
503 |
break; |
|
504 |
||
505 |
case JVM_CONSTANT_UnresolvedClass: |
|
506 |
buf.cell("JVM_CONSTANT_UnresolvedClass"); |
|
507 |
buf.cell(cpool.getSymbolAt(index).asString()); |
|
508 |
break; |
|
509 |
||
5341 | 510 |
case JVM_CONSTANT_UnresolvedClassInError: |
511 |
buf.cell("JVM_CONSTANT_UnresolvedClassInError"); |
|
512 |
buf.cell(cpool.getSymbolAt(index).asString()); |
|
513 |
break; |
|
514 |
||
1 | 515 |
case JVM_CONSTANT_Class: |
516 |
buf.cell("JVM_CONSTANT_Class"); |
|
517 |
Klass klass = (Klass) cpool.getObjAt(index); |
|
518 |
if (klass instanceof InstanceKlass) { |
|
519 |
buf.cell(genKlassLink((InstanceKlass) klass)); |
|
520 |
} else { |
|
521 |
buf.cell(klass.getName().asString().replace('/', '.')); |
|
522 |
} |
|
523 |
break; |
|
524 |
||
525 |
case JVM_CONSTANT_UnresolvedString: |
|
526 |
buf.cell("JVM_CONSTANT_UnresolvedString"); |
|
527 |
buf.cell("\"" + |
|
528 |
escapeHTMLSpecialChars(cpool.getSymbolAt(index).asString()) + |
|
529 |
"\""); |
|
530 |
break; |
|
531 |
||
532 |
case JVM_CONSTANT_Utf8: |
|
533 |
buf.cell("JVM_CONSTANT_Utf8"); |
|
534 |
buf.cell("\"" + |
|
535 |
escapeHTMLSpecialChars(cpool.getSymbolAt(index).asString()) + |
|
536 |
"\""); |
|
537 |
break; |
|
538 |
||
539 |
case JVM_CONSTANT_String: |
|
540 |
buf.cell("JVM_CONSTANT_String"); |
|
541 |
buf.cell("\"" + |
|
542 |
escapeHTMLSpecialChars(OopUtilities.stringOopToString(cpool.getObjAt(index))) + "\""); |
|
543 |
break; |
|
544 |
||
545 |
case JVM_CONSTANT_Fieldref: |
|
546 |
buf.cell("JVM_CONSTANT_Fieldref"); |
|
547 |
buf.cell(genLowHighShort(cpool.getIntAt(index))); |
|
548 |
break; |
|
549 |
||
550 |
case JVM_CONSTANT_Methodref: |
|
551 |
buf.cell("JVM_CONSTANT_Methodref"); |
|
552 |
buf.cell(genLowHighShort(cpool.getIntAt(index))); |
|
553 |
break; |
|
554 |
||
555 |
case JVM_CONSTANT_InterfaceMethodref: |
|
556 |
buf.cell("JVM_CONSTANT_InterfaceMethodref"); |
|
557 |
buf.cell(genLowHighShort(cpool.getIntAt(index))); |
|
558 |
break; |
|
559 |
||
560 |
case JVM_CONSTANT_NameAndType: |
|
561 |
buf.cell("JVM_CONSTANT_NameAndType"); |
|
562 |
buf.cell(genLowHighShort(cpool.getIntAt(index))); |
|
563 |
break; |
|
564 |
||
565 |
case JVM_CONSTANT_ClassIndex: |
|
566 |
buf.cell("JVM_CONSTANT_ClassIndex"); |
|
567 |
buf.cell(Integer.toString(cpool.getIntAt(index))); |
|
568 |
break; |
|
569 |
||
570 |
case JVM_CONSTANT_StringIndex: |
|
571 |
buf.cell("JVM_CONSTANT_StringIndex"); |
|
572 |
buf.cell(Integer.toString(cpool.getIntAt(index))); |
|
573 |
break; |
|
5341 | 574 |
|
5882 | 575 |
case JVM_CONSTANT_MethodHandle: |
576 |
buf.cell("JVM_CONSTANT_MethodHandle"); |
|
577 |
buf.cell(genLowHighShort(cpool.getIntAt(index))); |
|
578 |
break; |
|
579 |
||
580 |
case JVM_CONSTANT_MethodType: |
|
581 |
buf.cell("JVM_CONSTANT_MethodType"); |
|
582 |
buf.cell(Integer.toString(cpool.getIntAt(index))); |
|
583 |
break; |
|
584 |
||
5341 | 585 |
default: |
586 |
throw new InternalError("unknown tag: " + ctag); |
|
1 | 587 |
} |
588 |
||
589 |
buf.endTag("tr"); |
|
590 |
} |
|
591 |
||
592 |
buf.endTable(); |
|
593 |
return buf.toString(); |
|
594 |
} |
|
595 |
||
596 |
public String genHTML(ConstantPool cpool) { |
|
597 |
try { |
|
598 |
Formatter buf = new Formatter(genHTML); |
|
599 |
buf.genHTMLPrologue(genConstantPoolTitle(cpool)); |
|
600 |
buf.h3("Holder Class"); |
|
601 |
buf.append(genKlassLink((InstanceKlass) cpool.getPoolHolder())); |
|
602 |
buf.h3("Constants"); |
|
603 |
buf.append(genHTMLTableForConstantPool(cpool)); |
|
604 |
buf.genHTMLEpilogue(); |
|
605 |
return buf.toString(); |
|
606 |
} catch (Exception exp) { |
|
607 |
return genHTMLErrorMessage(exp); |
|
608 |
} |
|
609 |
} |
|
610 |
||
611 |
protected String genConstantPoolHref(ConstantPool cpool) { |
|
612 |
return genBaseHref() + "cpool=" + cpool.getHandle(); |
|
613 |
} |
|
614 |
||
615 |
protected String genConstantPoolTitle(ConstantPool cpool) { |
|
616 |
Formatter buf = new Formatter(genHTML); |
|
617 |
buf.append("Constant Pool of ["); |
|
618 |
buf.append(genKlassTitle((InstanceKlass) cpool.getPoolHolder())); |
|
619 |
buf.append("] @"); |
|
620 |
buf.append(cpool.getHandle().toString()); |
|
621 |
return buf.toString(); |
|
622 |
} |
|
623 |
||
624 |
protected String genConstantPoolLink(ConstantPool cpool) { |
|
625 |
Formatter buf = new Formatter(genHTML); |
|
626 |
buf.link(genConstantPoolHref(cpool), genConstantPoolTitle(cpool)); |
|
627 |
return buf.toString(); |
|
628 |
} |
|
629 |
||
630 |
public String genHTML(Method method) { |
|
631 |
try { |
|
632 |
final Formatter buf = new Formatter(genHTML); |
|
633 |
buf.genHTMLPrologue(genMethodTitle(method)); |
|
634 |
||
635 |
buf.h3("Holder Class"); |
|
636 |
buf.append(genKlassLink((InstanceKlass) method.getMethodHolder())); |
|
637 |
||
638 |
NMethod nmethod = method.getNativeMethod(); |
|
639 |
if (nmethod != null) { |
|
640 |
buf.h3("Compiled Code"); |
|
641 |
buf.append(genNMethodLink(nmethod)); |
|
642 |
} |
|
643 |
||
644 |
boolean hasThrows = method.hasCheckedExceptions(); |
|
645 |
ConstantPool cpool = ((InstanceKlass) method.getMethodHolder()).getConstants(); |
|
646 |
if (hasThrows) { |
|
647 |
buf.h3("Checked Exception(s)"); |
|
648 |
CheckedExceptionElement[] exceptions = method.getCheckedExceptions(); |
|
649 |
buf.beginTag("ul"); |
|
650 |
for (int exp = 0; exp < exceptions.length; exp++) { |
|
651 |
short cpIndex = (short) exceptions[exp].getClassCPIndex(); |
|
652 |
Oop obj = cpool.getObjAt(cpIndex); |
|
653 |
if (obj instanceof Symbol) { |
|
654 |
buf.li(((Symbol)obj).asString().replace('/', '.')); |
|
655 |
} else { |
|
656 |
buf.li(genKlassLink((InstanceKlass)obj)); |
|
657 |
} |
|
658 |
} |
|
659 |
buf.endTag("ul"); |
|
660 |
} |
|
661 |
||
662 |
if (method.isNative() || method.isAbstract()) { |
|
663 |
buf.genHTMLEpilogue(); |
|
664 |
return buf.toString(); |
|
665 |
} |
|
666 |
||
667 |
buf.h3("Bytecode"); |
|
668 |
BytecodeDisassembler disasm = createBytecodeDisassembler(method); |
|
669 |
final boolean hasLineNumbers = method.hasLineNumberTable(); |
|
670 |
disasm.decode(new BytecodeVisitor() { |
|
671 |
private Method method; |
|
672 |
public void prologue(Method m) { |
|
673 |
method = m; |
|
674 |
buf.beginTable(0); |
|
675 |
buf.beginTag("tr"); |
|
676 |
if (hasLineNumbers) { |
|
677 |
buf.headerCell("line"); |
|
678 |
} |
|
679 |
buf.headerCell("bci" + spaces); |
|
680 |
buf.headerCell("bytecode"); |
|
681 |
buf.endTag("tr"); |
|
682 |
} |
|
683 |
||
684 |
public void visit(Bytecode instr) { |
|
685 |
int curBci = instr.bci(); |
|
686 |
buf.beginTag("tr"); |
|
687 |
if (hasLineNumbers) { |
|
688 |
int lineNumber = method.getLineNumberFromBCI(curBci); |
|
689 |
buf.cell(Integer.toString(lineNumber) + spaces); |
|
690 |
} |
|
691 |
buf.cell(Integer.toString(curBci) + spaces); |
|
692 |
||
693 |
buf.beginTag("td"); |
|
5341 | 694 |
String instrStr = null; |
695 |
try { |
|
696 |
instrStr = escapeHTMLSpecialChars(instr.toString()); |
|
697 |
} catch (RuntimeException re) { |
|
698 |
buf.append("exception during bytecode processing"); |
|
699 |
buf.endTag("td"); |
|
700 |
buf.endTag("tr"); |
|
701 |
re.printStackTrace(); |
|
702 |
return; |
|
703 |
} |
|
1 | 704 |
|
705 |
if (instr instanceof BytecodeNew) { |
|
706 |
BytecodeNew newBytecode = (BytecodeNew) instr; |
|
707 |
InstanceKlass klass = newBytecode.getNewKlass(); |
|
708 |
if (klass != null) { |
|
709 |
buf.link(genKlassHref(klass), instrStr); |
|
710 |
} else { |
|
711 |
buf.append(instrStr); |
|
712 |
} |
|
713 |
} else if(instr instanceof BytecodeInvoke) { |
|
714 |
BytecodeInvoke invokeBytecode = (BytecodeInvoke) instr; |
|
715 |
Method m = invokeBytecode.getInvokedMethod(); |
|
716 |
if (m != null) { |
|
717 |
buf.link(genMethodHref(m), instrStr); |
|
718 |
buf.append(" of "); |
|
719 |
InstanceKlass klass = (InstanceKlass) m.getMethodHolder(); |
|
720 |
buf.link(genKlassHref(klass), genKlassTitle(klass)); |
|
721 |
} else { |
|
722 |
buf.append(instrStr); |
|
723 |
} |
|
724 |
} else if (instr instanceof BytecodeGetPut) { |
|
725 |
BytecodeGetPut getPut = (BytecodeGetPut) instr; |
|
726 |
sun.jvm.hotspot.oops.Field f = getPut.getField(); |
|
727 |
buf.append(instrStr); |
|
728 |
if (f != null) { |
|
729 |
InstanceKlass klass = f.getFieldHolder(); |
|
730 |
buf.append(" of "); |
|
731 |
buf.link(genKlassHref(klass), genKlassTitle(klass)); |
|
732 |
} |
|
733 |
} else if (instr instanceof BytecodeLoadConstant) { |
|
734 |
BytecodeLoadConstant ldc = (BytecodeLoadConstant) instr; |
|
735 |
if (ldc.isKlassConstant()) { |
|
736 |
Oop oop = ldc.getKlass(); |
|
737 |
if (oop instanceof Klass) { |
|
738 |
buf.append("<a href='"); |
|
739 |
buf.append(genKlassHref((InstanceKlass) oop)); |
|
740 |
buf.append("'>"); |
|
741 |
buf.append(instrStr); |
|
742 |
buf.append("</a>"); |
|
743 |
} else { |
|
744 |
// unresolved klass literal |
|
745 |
buf.append(instrStr); |
|
746 |
} |
|
747 |
} else { |
|
748 |
// not a klass literal |
|
749 |
buf.append(instrStr); |
|
750 |
} |
|
751 |
} else { |
|
752 |
buf.append(instrStr); |
|
753 |
} |
|
754 |
buf.endTag("td"); |
|
755 |
buf.endTag("tr"); |
|
756 |
} |
|
757 |
||
758 |
public void epilogue() { |
|
759 |
buf.endTable(); |
|
760 |
} |
|
761 |
}); |
|
762 |
||
763 |
// display exception table for this method |
|
764 |
TypeArray exceptionTable = method.getExceptionTable(); |
|
765 |
// exception table is 4 tuple array of shorts |
|
766 |
int numEntries = (int)exceptionTable.getLength() / 4; |
|
767 |
if (numEntries != 0) { |
|
768 |
buf.h4("Exception Table"); |
|
769 |
buf.beginTable(1); |
|
770 |
buf.beginTag("tr"); |
|
771 |
buf.headerCell("start bci"); |
|
772 |
buf.headerCell("end bci"); |
|
773 |
buf.headerCell("handler bci"); |
|
774 |
buf.headerCell("catch type"); |
|
775 |
buf.endTag("tr"); |
|
776 |
||
777 |
for (int e = 0; e < numEntries; e += 4) { |
|
778 |
buf.beginTag("tr"); |
|
779 |
buf.cell(Integer.toString(exceptionTable.getIntAt(e))); |
|
780 |
buf.cell(Integer.toString(exceptionTable.getIntAt(e + 1))); |
|
781 |
buf.cell(Integer.toString(exceptionTable.getIntAt(e + 2))); |
|
782 |
short cpIndex = (short) exceptionTable.getIntAt(e + 3); |
|
783 |
Oop obj = cpIndex == 0? null : cpool.getObjAt(cpIndex); |
|
784 |
if (obj == null) { |
|
785 |
buf.cell("Any"); |
|
786 |
} else if (obj instanceof Symbol) { |
|
787 |
buf.cell(((Symbol)obj).asString().replace('/', '.')); |
|
788 |
} else { |
|
789 |
buf.cell(genKlassLink((InstanceKlass)obj)); |
|
790 |
} |
|
791 |
buf.endTag("tr"); |
|
792 |
} |
|
793 |
||
794 |
buf.endTable(); |
|
795 |
} |
|
796 |
||
797 |
// display constant pool hyperlink |
|
798 |
buf.h3("Constant Pool"); |
|
799 |
buf.append(genConstantPoolLink(cpool)); |
|
800 |
buf.genHTMLEpilogue(); |
|
801 |
return buf.toString(); |
|
802 |
} catch (Exception exp) { |
|
803 |
return genHTMLErrorMessage(exp); |
|
804 |
} |
|
805 |
} |
|
806 |
||
807 |
protected Disassembler createDisassembler(long startPc, byte[] code) { |
|
808 |
return getCPUHelper().createDisassembler(startPc, code); |
|
809 |
} |
|
810 |
||
811 |
protected SymbolFinder createSymbolFinder() { |
|
812 |
return new DummySymbolFinder(); |
|
813 |
} |
|
814 |
||
815 |
// genHTML for a given address. Address may be a PC or |
|
816 |
// methodOop or klassOop. |
|
817 |
||
818 |
public String genHTMLForAddress(String addrStr) { |
|
819 |
return genHTML(parseAddress(addrStr)); |
|
820 |
} |
|
821 |
||
822 |
public String genHTML(sun.jvm.hotspot.debugger.Address pc) { |
|
823 |
CodeBlob blob = null; |
|
824 |
||
825 |
try { |
|
826 |
blob = (CodeBlob)VM.getVM().getCodeCache().findBlobUnsafe(pc); |
|
827 |
} catch (Exception exp) { |
|
828 |
// ignore |
|
829 |
} |
|
830 |
||
831 |
if (blob != null) { |
|
832 |
if (blob instanceof NMethod) { |
|
833 |
return genHTML((NMethod)blob); |
|
834 |
} else { |
|
835 |
// may be interpreter code. |
|
836 |
Interpreter interp = VM.getVM().getInterpreter(); |
|
837 |
if (interp.contains(pc)) { |
|
838 |
InterpreterCodelet codelet = interp.getCodeletContaining(pc); |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
839 |
if (codelet == null) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
840 |
return "Unknown location in the Interpreter: " + pc; |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
841 |
} |
1 | 842 |
return genHTML(codelet); |
843 |
} |
|
844 |
return genHTML(blob); |
|
845 |
} |
|
846 |
} else if (VM.getVM().getCodeCache().contains(pc)) { |
|
847 |
return "Unknown location in the CodeCache: " + pc; |
|
848 |
} |
|
849 |
||
850 |
// did not find nmethod. |
|
851 |
// try methodOop, klassOop and constantPoolOop. |
|
852 |
try { |
|
853 |
Oop obj = getOopAtAddress(pc); |
|
854 |
if (obj != null) { |
|
855 |
if (obj instanceof Method) { |
|
856 |
return genHTML((Method) obj); |
|
857 |
} else if (obj instanceof InstanceKlass) { |
|
858 |
return genHTML((InstanceKlass) obj); |
|
859 |
} else if (obj instanceof ConstantPool) { |
|
860 |
return genHTML((ConstantPool) obj); |
|
861 |
} |
|
862 |
} |
|
863 |
} catch (Exception exp) { |
|
864 |
// ignore |
|
865 |
} |
|
866 |
||
867 |
// didn't find any. do raw disassembly. |
|
868 |
return genHTMLForRawDisassembly(pc, null); |
|
869 |
} |
|
870 |
||
871 |
protected byte[] readBuffer(sun.jvm.hotspot.debugger.Address addr, int size) { |
|
872 |
byte[] buf = new byte[size]; |
|
873 |
for (int b = 0; b < size; b++) { |
|
874 |
buf[b] = (byte) addr.getJByteAt(b); |
|
875 |
} |
|
876 |
return buf; |
|
877 |
} |
|
878 |
||
879 |
public String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address startPc, int size) { |
|
880 |
try { |
|
881 |
return genHTMLForRawDisassembly(startPc, null, readBuffer(startPc, size)); |
|
882 |
} catch (Exception exp) { |
|
883 |
return genHTMLErrorMessage(exp); |
|
884 |
} |
|
885 |
} |
|
886 |
||
887 |
protected String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address startPc, |
|
888 |
String prevPCs) { |
|
889 |
try { |
|
890 |
return genHTMLForRawDisassembly(startPc, prevPCs, readBuffer(startPc, NATIVE_CODE_SIZE)); |
|
891 |
} catch (Exception exp) { |
|
892 |
return genHTMLErrorMessage(exp); |
|
893 |
} |
|
894 |
} |
|
895 |
||
896 |
protected String genPCHref(long targetPc) { |
|
897 |
return genBaseHref() + "pc=0x" + Long.toHexString(targetPc); |
|
898 |
} |
|
899 |
||
900 |
protected String genMultPCHref(String pcs) { |
|
901 |
StringBuffer buf = new StringBuffer(genBaseHref()); |
|
902 |
buf.append("pc_multiple="); |
|
903 |
buf.append(pcs); |
|
904 |
return buf.toString(); |
|
905 |
} |
|
906 |
||
907 |
protected String genPCHref(long currentPc, sun.jvm.hotspot.asm.Address addr) { |
|
908 |
String href = null; |
|
909 |
if (addr instanceof PCRelativeAddress) { |
|
910 |
PCRelativeAddress pcRelAddr = (PCRelativeAddress) addr; |
|
911 |
href = genPCHref(currentPc + pcRelAddr.getDisplacement()); |
|
912 |
} else if(addr instanceof DirectAddress) { |
|
913 |
href = genPCHref(((DirectAddress) addr).getValue()); |
|
914 |
} |
|
915 |
||
916 |
return href; |
|
917 |
} |
|
918 |
||
919 |
class RawCodeVisitor implements InstructionVisitor { |
|
920 |
private int instrSize = 0; |
|
921 |
private Formatter buf; |
|
922 |
private SymbolFinder symFinder = createSymbolFinder(); |
|
923 |
||
924 |
RawCodeVisitor(Formatter buf) { |
|
925 |
this.buf = buf; |
|
926 |
} |
|
927 |
||
928 |
public int getInstructionSize() { |
|
929 |
return instrSize; |
|
930 |
} |
|
931 |
||
932 |
public void prologue() { |
|
933 |
} |
|
934 |
||
935 |
public void visit(long currentPc, Instruction instr) { |
|
936 |
String href = null; |
|
937 |
if (instr.isCall()) { |
|
938 |
CallInstruction call = (CallInstruction) instr; |
|
939 |
sun.jvm.hotspot.asm.Address addr = call.getBranchDestination(); |
|
940 |
href = genPCHref(currentPc, addr); |
|
941 |
} |
|
942 |
||
943 |
instrSize += instr.getSize(); |
|
944 |
buf.append("0x"); |
|
945 |
buf.append(Long.toHexString(currentPc)); |
|
946 |
buf.append(':'); |
|
947 |
buf.append(tab); |
|
948 |
||
949 |
if (href != null) { |
|
950 |
buf.link(href, instr.asString(currentPc, symFinder)); |
|
951 |
} else { |
|
952 |
buf.append(instr.asString(currentPc, symFinder)); |
|
953 |
} |
|
954 |
buf.br(); |
|
955 |
} |
|
956 |
||
957 |
public void epilogue() { |
|
958 |
} |
|
959 |
}; |
|
960 |
||
961 |
protected String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address addr, |
|
962 |
String prevPCs, |
|
963 |
byte[] code) { |
|
964 |
try { |
|
965 |
long startPc = addressToLong(addr); |
|
966 |
Disassembler disasm = createDisassembler(startPc, code); |
|
967 |
final Formatter buf = new Formatter(genHTML); |
|
968 |
buf.genHTMLPrologue("Disassembly @0x" + Long.toHexString(startPc)); |
|
969 |
||
970 |
if (prevPCs != null && genHTML) { |
|
971 |
buf.beginTag("p"); |
|
972 |
buf.link(genMultPCHref(prevPCs), "show previous code .."); |
|
973 |
buf.endTag("p"); |
|
974 |
} |
|
975 |
||
976 |
||
977 |
buf.h3("Code"); |
|
978 |
RawCodeVisitor visitor = new RawCodeVisitor(buf); |
|
979 |
disasm.decode(visitor); |
|
980 |
||
981 |
if (genHTML) buf.beginTag("p"); |
|
982 |
Formatter tmpBuf = new Formatter(genHTML); |
|
983 |
tmpBuf.append("0x"); |
|
984 |
tmpBuf.append(Long.toHexString(startPc + visitor.getInstructionSize()).toString()); |
|
985 |
tmpBuf.append(",0x"); |
|
986 |
tmpBuf.append(Long.toHexString(startPc)); |
|
987 |
if (prevPCs != null) { |
|
988 |
tmpBuf.append(','); |
|
989 |
tmpBuf.append(prevPCs); |
|
990 |
} |
|
991 |
if (genHTML) { |
|
992 |
buf.link(genMultPCHref(tmpBuf.toString()), "show more code .."); |
|
993 |
buf.endTag("p"); |
|
994 |
} |
|
995 |
||
996 |
buf.genHTMLEpilogue(); |
|
997 |
return buf.toString(); |
|
998 |
} catch (Exception exp) { |
|
999 |
return genHTMLErrorMessage(exp); |
|
1000 |
} |
|
1001 |
} |
|
1002 |
||
1003 |
protected String genSafepointInfo(NMethod nm, PCDesc pcDesc) { |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1004 |
ScopeDesc sd = nm.getScopeDescAt(pcDesc.getRealPC(nm)); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1005 |
Formatter buf = new Formatter(genHTML); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1006 |
Formatter tabs = new Formatter(genHTML); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1007 |
tabs.append(tab + tab + tab); // Initial indent for debug info |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1008 |
|
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1009 |
buf.beginTag("pre"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1010 |
genScope(buf, tabs, sd); |
1 | 1011 |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1012 |
// Reset indent for scalar replaced objects |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1013 |
tabs = new Formatter(genHTML); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1014 |
tabs.append(tab + tab + tab); // Initial indent for debug info |
1 | 1015 |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1016 |
genScObjInfo(buf, tabs, sd); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1017 |
buf.endTag("pre"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1018 |
|
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1019 |
buf.append(genOopMapInfo(nm, pcDesc)); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1020 |
|
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1021 |
return buf.toString(); |
1 | 1022 |
} |
1023 |
||
1024 |
protected void genScope(Formatter buf, Formatter tabs, ScopeDesc sd) { |
|
1025 |
if (sd == null) { |
|
1026 |
return; |
|
1027 |
} |
|
1028 |
||
1029 |
genScope(buf, tabs, sd.sender()); |
|
1030 |
||
1031 |
buf.append(tabs); |
|
1032 |
Method m = sd.getMethod(); |
|
1033 |
buf.append(genMethodAndKlassLink(m)); |
|
1034 |
int bci = sd.getBCI(); |
|
1035 |
buf.append(" @ bci = "); |
|
1036 |
buf.append(Integer.toString(bci)); |
|
1037 |
||
1038 |
int line = m.getLineNumberFromBCI(bci); |
|
1039 |
if (line != -1) { |
|
1040 |
buf.append(", line = "); |
|
1041 |
buf.append(Integer.toString(line)); |
|
1042 |
} |
|
1043 |
||
1044 |
List locals = sd.getLocals(); |
|
1045 |
if (locals != null) { |
|
1046 |
buf.br(); |
|
1047 |
buf.append(tabs); |
|
1048 |
buf.append(genHTMLForLocals(sd, locals)); |
|
1049 |
} |
|
1050 |
||
1051 |
List expressions = sd.getExpressions(); |
|
1052 |
if (expressions != null) { |
|
1053 |
buf.br(); |
|
1054 |
buf.append(tabs); |
|
1055 |
buf.append(genHTMLForExpressions(sd, expressions)); |
|
1056 |
} |
|
1057 |
||
1058 |
List monitors = sd.getMonitors(); |
|
1059 |
if (monitors != null) { |
|
1060 |
buf.br(); |
|
1061 |
buf.append(tabs); |
|
1062 |
buf.append(genHTMLForMonitors(sd, monitors)); |
|
1063 |
} |
|
1064 |
||
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1065 |
buf.br(); |
1 | 1066 |
tabs.append(tab); |
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1067 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1068 |
|
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1069 |
protected void genScObjInfo(Formatter buf, Formatter tabs, ScopeDesc sd) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1070 |
if (sd == null) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1071 |
return; |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1072 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1073 |
|
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1074 |
List objects = sd.getObjects(); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1075 |
if (objects == null) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1076 |
return; |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1077 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1078 |
int length = objects.size(); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1079 |
for (int i = 0; i < length; i++) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1080 |
buf.append(tabs); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1081 |
ObjectValue ov = (ObjectValue)objects.get(i); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1082 |
buf.append("ScObj" + i); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1083 |
ScopeValue sv = ov.getKlass(); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1084 |
if (Assert.ASSERTS_ENABLED) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1085 |
Assert.that(sv.isConstantOop(), "scalar replaced object klass must be constant oop"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1086 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1087 |
ConstantOopReadValue klv = (ConstantOopReadValue)sv; |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1088 |
OopHandle klHandle = klv.getValue(); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1089 |
if (Assert.ASSERTS_ENABLED) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1090 |
Assert.that(klHandle != null, "scalar replaced object klass must be not NULL"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1091 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1092 |
Oop obj = VM.getVM().getObjectHeap().newOop(klHandle); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1093 |
if (obj instanceof InstanceKlass) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1094 |
InstanceKlass kls = (InstanceKlass) obj; |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1095 |
buf.append(" " + kls.getName().asString() + "={"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1096 |
int flen = ov.fieldsSize(); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1097 |
|
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1098 |
TypeArray klfields = kls.getFields(); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1099 |
int klen = (int) klfields.getLength(); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1100 |
|
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1101 |
ConstantPool cp = kls.getConstants(); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1102 |
int findex = 0; |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1103 |
for (int index = 0; index < klen; index += kls.NEXT_OFFSET) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1104 |
int accsFlags = klfields.getShortAt(index + kls.ACCESS_FLAGS_OFFSET); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1105 |
int nameIndex = klfields.getShortAt(index + kls.NAME_INDEX_OFFSET); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1106 |
AccessFlags access = new AccessFlags(accsFlags); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1107 |
if (!access.isStatic()) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1108 |
ScopeValue svf = ov.getFieldAt(findex++); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1109 |
String fstr = scopeValueAsString(sd, svf); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1110 |
Symbol f_name = cp.getSymbolAt(nameIndex); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1111 |
buf.append(" [" + f_name.asString() + " :"+ index + "]=(#" + fstr + ")"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1112 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1113 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1114 |
buf.append(" }"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1115 |
} else { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1116 |
buf.append(" "); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1117 |
int flen = ov.fieldsSize(); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1118 |
if (obj instanceof TypeArrayKlass) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1119 |
TypeArrayKlass kls = (TypeArrayKlass) obj; |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1120 |
buf.append(kls.getElementTypeName() + "[" + flen + "]"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1121 |
} else if (obj instanceof ObjArrayKlass) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1122 |
ObjArrayKlass kls = (ObjArrayKlass) obj; |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1123 |
Klass elobj = kls.getBottomKlass(); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1124 |
if (elobj instanceof InstanceKlass) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1125 |
buf.append(elobj.getName().asString()); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1126 |
} else if (elobj instanceof TypeArrayKlass) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1127 |
TypeArrayKlass elkls = (TypeArrayKlass) elobj; |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1128 |
buf.append(elkls.getElementTypeName()); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1129 |
} else { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1130 |
if (Assert.ASSERTS_ENABLED) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1131 |
Assert.that(false, "unknown scalar replaced object klass!"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1132 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1133 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1134 |
buf.append("[" + flen + "]"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1135 |
int ndim = (int) kls.getDimension(); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1136 |
while (--ndim > 0) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1137 |
buf.append("[]"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1138 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1139 |
} else { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1140 |
if (Assert.ASSERTS_ENABLED) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1141 |
Assert.that(false, "unknown scalar replaced object klass!"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1142 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1143 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1144 |
buf.append("={"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1145 |
for (int findex = 0; findex < flen; findex++) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1146 |
ScopeValue svf = ov.getFieldAt(findex); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1147 |
String fstr = scopeValueAsString(sd, svf); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1148 |
buf.append(" [" + findex + "]=(#" + fstr + ")"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1149 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1150 |
buf.append(" }"); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1151 |
} |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1152 |
buf.br(); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1153 |
} |
1 | 1154 |
} |
1155 |
||
1156 |
protected String genHTMLForOopMap(OopMap map) { |
|
1157 |
final int stack0 = VMRegImpl.getStack0().getValue(); |
|
1158 |
Formatter buf = new Formatter(genHTML); |
|
1159 |
||
1160 |
final class OopMapValueIterator { |
|
1161 |
final Formatter iterate(OopMapStream oms, String type, boolean printContentReg) { |
|
1162 |
Formatter tmpBuf = new Formatter(genHTML); |
|
1163 |
boolean found = false; |
|
1164 |
tmpBuf.beginTag("tr"); |
|
1165 |
tmpBuf.beginTag("td"); |
|
1166 |
tmpBuf.append(type); |
|
1167 |
for (; ! oms.isDone(); oms.next()) { |
|
1168 |
OopMapValue omv = oms.getCurrent(); |
|
1169 |
if (omv == null) { |
|
1170 |
continue; |
|
1171 |
} |
|
1172 |
found = true; |
|
1173 |
VMReg vmReg = omv.getReg(); |
|
1174 |
int reg = vmReg.getValue(); |
|
1175 |
if (reg < stack0) { |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1176 |
tmpBuf.append(VMRegImpl.getRegisterName(reg)); |
1 | 1177 |
} else { |
1178 |
tmpBuf.append('['); |
|
1179 |
tmpBuf.append(Integer.toString((reg - stack0) * 4)); |
|
1180 |
tmpBuf.append(']'); |
|
1181 |
} |
|
1182 |
if (printContentReg) { |
|
1183 |
tmpBuf.append(" = "); |
|
1184 |
VMReg vmContentReg = omv.getContentReg(); |
|
1185 |
int contentReg = vmContentReg.getValue(); |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1186 |
if (contentReg < stack0) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1187 |
tmpBuf.append(VMRegImpl.getRegisterName(contentReg)); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1188 |
} else { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1189 |
tmpBuf.append('['); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1190 |
tmpBuf.append(Integer.toString((contentReg - stack0) * 4)); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1191 |
tmpBuf.append(']'); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1192 |
} |
1 | 1193 |
} |
1194 |
tmpBuf.append(spaces); |
|
1195 |
} |
|
1196 |
tmpBuf.endTag("td"); |
|
1197 |
tmpBuf.endTag("tr"); |
|
1198 |
return found ? tmpBuf : new Formatter(genHTML); |
|
1199 |
} |
|
1200 |
} |
|
1201 |
||
1202 |
buf.beginTable(0); |
|
1203 |
||
1204 |
OopMapValueIterator omvIterator = new OopMapValueIterator(); |
|
1205 |
OopMapStream oms = new OopMapStream(map, OopMapValue.OopTypes.OOP_VALUE); |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1206 |
buf.append(omvIterator.iterate(oms, "Oops:", false)); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1207 |
|
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1208 |
oms = new OopMapStream(map, OopMapValue.OopTypes.NARROWOOP_VALUE); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1209 |
buf.append(omvIterator.iterate(oms, "narrowOops:", false)); |
1 | 1210 |
|
1211 |
oms = new OopMapStream(map, OopMapValue.OopTypes.VALUE_VALUE); |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1212 |
buf.append(omvIterator.iterate(oms, "Values:", false)); |
1 | 1213 |
|
1214 |
oms = new OopMapStream(map, OopMapValue.OopTypes.CALLEE_SAVED_VALUE); |
|
1215 |
buf.append(omvIterator.iterate(oms, "Callee saved:", true)); |
|
1216 |
||
1217 |
oms = new OopMapStream(map, OopMapValue.OopTypes.DERIVED_OOP_VALUE); |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1218 |
buf.append(omvIterator.iterate(oms, "Derived oops:", true)); |
1 | 1219 |
|
1220 |
buf.endTag("table"); |
|
1221 |
return buf.toString(); |
|
1222 |
} |
|
1223 |
||
1224 |
||
1225 |
protected String genOopMapInfo(NMethod nmethod, PCDesc pcDesc) { |
|
1226 |
OopMapSet mapSet = nmethod.getOopMaps(); |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1227 |
if (mapSet == null || (mapSet.getSize() <= 0)) |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1228 |
return ""; |
1 | 1229 |
int pcOffset = pcDesc.getPCOffset(); |
1230 |
OopMap map = mapSet.findMapAtOffset(pcOffset, VM.getVM().isDebugging()); |
|
1231 |
if (map == null) { |
|
1232 |
throw new IllegalArgumentException("no oopmap at safepoint!"); |
|
1233 |
} |
|
1234 |
||
1235 |
return genOopMapInfo(map); |
|
1236 |
} |
|
1237 |
||
1238 |
protected String genOopMapInfo(OopMap map) { |
|
1239 |
Formatter buf = new Formatter(genHTML); |
|
1240 |
buf.beginTag("pre"); |
|
1241 |
buf.append("OopMap: "); |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1242 |
buf.br(); |
1 | 1243 |
buf.append(genHTMLForOopMap(map)); |
1244 |
buf.endTag("pre"); |
|
1245 |
||
1246 |
return buf.toString(); |
|
1247 |
} |
|
1248 |
||
1249 |
protected String locationAsString(Location loc) { |
|
1250 |
Formatter buf = new Formatter(genHTML); |
|
1251 |
if (loc.isIllegal()) { |
|
1252 |
buf.append("illegal"); |
|
1253 |
} else { |
|
1254 |
Location.Where w = loc.getWhere(); |
|
1255 |
Location.Type type = loc.getType(); |
|
1256 |
||
1257 |
if (w == Location.Where.ON_STACK) { |
|
1258 |
buf.append("stack[" + loc.getStackOffset() + "]"); |
|
1259 |
} else if (w == Location.Where.IN_REGISTER) { |
|
1260 |
boolean isFloat = (type == Location.Type.FLOAT_IN_DBL || |
|
1261 |
type == Location.Type.DBL); |
|
1262 |
int regNum = loc.getRegisterNumber(); |
|
1263 |
VMReg vmReg = new VMReg(regNum); |
|
1264 |
buf.append(VMRegImpl.getRegisterName(vmReg.getValue())); |
|
1265 |
} |
|
1266 |
||
1267 |
buf.append(", "); |
|
1268 |
if (type == Location.Type.NORMAL) { |
|
1269 |
buf.append("normal"); |
|
1270 |
} else if (type == Location.Type.OOP) { |
|
1271 |
buf.append("oop"); |
|
1135
9487203e5789
6706829: Compressed Oops: add debug info for narrow oops
kvn
parents:
670
diff
changeset
|
1272 |
} else if (type == Location.Type.NARROWOOP) { |
9487203e5789
6706829: Compressed Oops: add debug info for narrow oops
kvn
parents:
670
diff
changeset
|
1273 |
buf.append("narrowoop"); |
1 | 1274 |
} else if (type == Location.Type.INT_IN_LONG) { |
1275 |
buf.append("int"); |
|
1276 |
} else if (type == Location.Type.LNG) { |
|
1277 |
buf.append("long"); |
|
1278 |
} else if (type == Location.Type.FLOAT_IN_DBL) { |
|
1279 |
buf.append("float"); |
|
1280 |
} else if (type == Location.Type.DBL) { |
|
1281 |
buf.append("double"); |
|
1282 |
} else if (type == Location.Type.ADDR) { |
|
1283 |
buf.append("address"); |
|
1284 |
} else if (type == Location.Type.INVALID) { |
|
1285 |
buf.append("invalid"); |
|
1286 |
} |
|
1287 |
} |
|
1288 |
return buf.toString(); |
|
1289 |
} |
|
1290 |
||
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1291 |
private String scopeValueAsString(ScopeDesc sd, ScopeValue sv) { |
1 | 1292 |
Formatter buf = new Formatter(genHTML); |
1293 |
if (sv.isConstantInt()) { |
|
1294 |
buf.append("int "); |
|
1295 |
ConstantIntValue intValue = (ConstantIntValue) sv; |
|
1296 |
buf.append(Integer.toString(intValue.getValue())); |
|
1297 |
} else if (sv.isConstantLong()) { |
|
1298 |
buf.append("long "); |
|
1299 |
ConstantLongValue longValue = (ConstantLongValue) sv; |
|
1300 |
buf.append(Long.toString(longValue.getValue())); |
|
1301 |
buf.append("L"); |
|
1302 |
} else if (sv.isConstantDouble()) { |
|
1303 |
buf.append("double "); |
|
1304 |
ConstantDoubleValue dblValue = (ConstantDoubleValue) sv; |
|
1305 |
buf.append(Double.toString(dblValue.getValue())); |
|
1306 |
buf.append("D"); |
|
1307 |
} else if (sv.isConstantOop()) { |
|
1308 |
buf.append("oop "); |
|
1309 |
ConstantOopReadValue oopValue = (ConstantOopReadValue) sv; |
|
1310 |
OopHandle oopHandle = oopValue.getValue(); |
|
1311 |
if (oopHandle != null) { |
|
1312 |
buf.append(oopHandle.toString()); |
|
1313 |
} else { |
|
1314 |
buf.append("null"); |
|
1315 |
} |
|
1316 |
} else if (sv.isLocation()) { |
|
1317 |
LocationValue lvalue = (LocationValue) sv; |
|
1318 |
Location loc = lvalue.getLocation(); |
|
1319 |
if (loc != null) { |
|
1320 |
buf.append(locationAsString(loc)); |
|
1321 |
} else { |
|
1322 |
buf.append("null"); |
|
1323 |
} |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1324 |
} else if (sv.isObject()) { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1325 |
ObjectValue ov = (ObjectValue)sv; |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1326 |
buf.append("#ScObj" + sd.getObjects().indexOf(ov)); |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1327 |
} else { |
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1328 |
buf.append("unknown scope value " + sv); |
1 | 1329 |
} |
1330 |
return buf.toString(); |
|
1331 |
} |
|
1332 |
||
1333 |
protected String genHTMLForScopeValues(ScopeDesc sd, boolean locals, List values) { |
|
1334 |
int length = values.size(); |
|
1335 |
Formatter buf = new Formatter(genHTML); |
|
1336 |
buf.append(locals? "locals " : "expressions "); |
|
1337 |
for (int i = 0; i < length; i++) { |
|
1338 |
ScopeValue sv = (ScopeValue) values.get(i); |
|
1339 |
if (sv == null) { |
|
1340 |
continue; |
|
1341 |
} |
|
1342 |
buf.append('('); |
|
1343 |
if (locals) { |
|
1344 |
Symbol name = sd.getMethod().getLocalVariableName(sd.getBCI(), i); |
|
1345 |
if (name != null) { |
|
1346 |
buf.append("'"); |
|
1347 |
buf.append(name.asString()); |
|
1348 |
buf.append('\''); |
|
1349 |
} else { |
|
1350 |
buf.append("["); |
|
1351 |
buf.append(Integer.toString(i)); |
|
1352 |
buf.append(']'); |
|
1353 |
} |
|
1354 |
} else { |
|
1355 |
buf.append("["); |
|
1356 |
buf.append(Integer.toString(i)); |
|
1357 |
buf.append(']'); |
|
1358 |
} |
|
1359 |
||
1360 |
buf.append(", "); |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1361 |
buf.append(scopeValueAsString(sd, sv)); |
1 | 1362 |
buf.append(") "); |
1363 |
} |
|
1364 |
||
1365 |
return buf.toString(); |
|
1366 |
} |
|
1367 |
||
1368 |
protected String genHTMLForLocals(ScopeDesc sd, List locals) { |
|
1369 |
return genHTMLForScopeValues(sd, true, locals); |
|
1370 |
} |
|
1371 |
||
1372 |
protected String genHTMLForExpressions(ScopeDesc sd, List expressions) { |
|
1373 |
return genHTMLForScopeValues(sd, false, expressions); |
|
1374 |
} |
|
1375 |
||
1376 |
protected String genHTMLForMonitors(ScopeDesc sd, List monitors) { |
|
1377 |
int length = monitors.size(); |
|
1378 |
Formatter buf = new Formatter(genHTML); |
|
1379 |
buf.append("monitors "); |
|
1380 |
for (int i = 0; i < length; i++) { |
|
1381 |
MonitorValue mv = (MonitorValue) monitors.get(i); |
|
1382 |
if (mv == null) { |
|
1383 |
continue; |
|
1384 |
} |
|
1385 |
buf.append("(owner = "); |
|
1386 |
ScopeValue owner = mv.owner(); |
|
1387 |
if (owner != null) { |
|
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1388 |
buf.append(scopeValueAsString(sd, owner)); |
1 | 1389 |
} else { |
1390 |
buf.append("null"); |
|
1391 |
} |
|
1392 |
buf.append(", lock = "); |
|
1393 |
||
1394 |
Location loc = mv.basicLock(); |
|
1395 |
if (loc != null) { |
|
1396 |
buf.append(locationAsString(loc)); |
|
1397 |
} else { |
|
1398 |
buf.append("null"); |
|
1399 |
} |
|
1400 |
buf.append(") "); |
|
1401 |
} |
|
1402 |
return buf.toString(); |
|
1403 |
} |
|
1404 |
||
1405 |
public String genHTML(final NMethod nmethod) { |
|
1406 |
try { |
|
1407 |
final Formatter buf = new Formatter(genHTML); |
|
1408 |
buf.genHTMLPrologue(genNMethodTitle(nmethod)); |
|
1409 |
buf.h3("Method"); |
|
1410 |
buf.append(genMethodAndKlassLink(nmethod.getMethod())); |
|
1411 |
||
1412 |
buf.h3("Compiled Code"); |
|
1413 |
sun.jvm.hotspot.debugger.Address codeBegin = nmethod.codeBegin(); |
|
1414 |
sun.jvm.hotspot.debugger.Address codeEnd = nmethod.codeEnd(); |
|
1415 |
final int codeSize = (int)codeEnd.minus(codeBegin); |
|
1416 |
final long startPc = addressToLong(codeBegin); |
|
1417 |
final byte[] code = new byte[codeSize]; |
|
1418 |
for (int i=0; i < code.length; i++) |
|
1419 |
code[i] = codeBegin.getJByteAt(i); |
|
1420 |
||
1421 |
final long verifiedEntryPoint = addressToLong(nmethod.getVerifiedEntryPoint()); |
|
1422 |
final long entryPoint = addressToLong(nmethod.getEntryPoint()); |
|
1423 |
final Map safepoints = nmethod.getSafepoints(); |
|
1424 |
||
1425 |
final SymbolFinder symFinder = createSymbolFinder(); |
|
1426 |
final Disassembler disasm = createDisassembler(startPc, code); |
|
1427 |
class NMethodVisitor implements InstructionVisitor { |
|
1428 |
public void prologue() { |
|
1429 |
} |
|
1430 |
||
1431 |
public void visit(long currentPc, Instruction instr) { |
|
1432 |
String href = null; |
|
1433 |
if (instr.isCall()) { |
|
1434 |
CallInstruction call = (CallInstruction) instr; |
|
1435 |
sun.jvm.hotspot.asm.Address addr = call.getBranchDestination(); |
|
1436 |
href = genPCHref(currentPc, addr); |
|
1437 |
} |
|
1438 |
||
1439 |
if (currentPc == verifiedEntryPoint) { |
|
1440 |
buf.bold("Verified Entry Point"); buf.br(); |
|
1441 |
} |
|
1442 |
if (currentPc == entryPoint) { |
|
1443 |
buf.bold(">Entry Point"); buf.br(); |
|
1444 |
} |
|
1445 |
||
1446 |
PCDesc pcDesc = (PCDesc) safepoints.get(longToAddress(currentPc)); |
|
1447 |
||
5341 | 1448 |
if (pcDesc != null) { |
1 | 1449 |
buf.append(genSafepointInfo(nmethod, pcDesc)); |
1450 |
} |
|
1451 |
||
1452 |
buf.append("0x"); |
|
1453 |
buf.append(Long.toHexString(currentPc)); |
|
1454 |
buf.append(':'); |
|
1455 |
buf.append(tab); |
|
1456 |
||
1457 |
if (href != null) { |
|
1458 |
buf.link(href, instr.asString(currentPc, symFinder)); |
|
1459 |
} else { |
|
1460 |
buf.append(instr.asString(currentPc, symFinder)); |
|
1461 |
} |
|
1462 |
||
4095
6e0acfda1d47
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
1135
diff
changeset
|
1463 |
buf.br(); |
1 | 1464 |
} |
1465 |
||
1466 |
public void epilogue() { |
|
1467 |
} |
|
1468 |
}; |
|
1469 |
||
1470 |
disasm.decode(new NMethodVisitor()); |
|
1471 |
||
1472 |
sun.jvm.hotspot.debugger.Address stubBegin = nmethod.stubBegin(); |
|
1473 |
if (stubBegin != null) { |
|
1474 |
sun.jvm.hotspot.debugger.Address stubEnd = nmethod.stubEnd(); |
|
1475 |
buf.h3("Stub"); |
|
1476 |
long stubStartPc = addressToLong(stubBegin); |
|
1477 |
long stubEndPc = addressToLong(stubEnd); |
|
1478 |
int range = (int) (stubEndPc - stubStartPc); |
|
1479 |
byte[] stubCode = readBuffer(stubBegin, range); |
|
1480 |
Disassembler disasm2 = createDisassembler(stubStartPc, stubCode); |
|
1481 |
disasm2.decode(new NMethodVisitor()); |
|
1482 |
} |
|
1483 |
buf.genHTMLEpilogue(); |
|
1484 |
return buf.toString(); |
|
1485 |
} catch (Exception exp) { |
|
1486 |
return genHTMLErrorMessage(exp); |
|
1487 |
} |
|
1488 |
} |
|
1489 |
||
1490 |
public String genHTML(final CodeBlob blob) { |
|
1491 |
try { |
|
1492 |
final Formatter buf = new Formatter(genHTML); |
|
1493 |
buf.genHTMLPrologue(genCodeBlobTitle(blob)); |
|
1494 |
buf.h3("CodeBlob"); |
|
1495 |
||
1496 |
buf.h3("Compiled Code"); |
|
1497 |
final sun.jvm.hotspot.debugger.Address codeBegin = blob.instructionsBegin(); |
|
1498 |
final int codeSize = blob.getInstructionsSize(); |
|
1499 |
final long startPc = addressToLong(codeBegin); |
|
1500 |
final byte[] code = new byte[codeSize]; |
|
1501 |
for (int i=0; i < code.length; i++) |
|
1502 |
code[i] = codeBegin.getJByteAt(i); |
|
1503 |
||
1504 |
final SymbolFinder symFinder = createSymbolFinder(); |
|
1505 |
final Disassembler disasm = createDisassembler(startPc, code); |
|
1506 |
class CodeBlobVisitor implements InstructionVisitor { |
|
1507 |
OopMapSet maps; |
|
1508 |
OopMap curMap; |
|
1509 |
int curMapIndex; |
|
1510 |
long curMapOffset; |
|
1511 |
public void prologue() { |
|
1512 |
maps = blob.getOopMaps(); |
|
1513 |
if (maps != null && (maps.getSize() > 0)) { |
|
1514 |
curMap = maps.getMapAt(0); |
|
1515 |
if (curMap != null) { |
|
1516 |
curMapOffset = curMap.getOffset(); |
|
1517 |
} |
|
1518 |
} |
|
1519 |
} |
|
1520 |
||
1521 |
public void visit(long currentPc, Instruction instr) { |
|
1522 |
String href = null; |
|
1523 |
if (instr.isCall()) { |
|
1524 |
CallInstruction call = (CallInstruction) instr; |
|
1525 |
sun.jvm.hotspot.asm.Address addr = call.getBranchDestination(); |
|
1526 |
href = genPCHref(currentPc, addr); |
|
1527 |
} |
|
1528 |
||
1529 |
buf.append("0x"); |
|
1530 |
buf.append(Long.toHexString(currentPc)); |
|
1531 |
buf.append(':'); |
|
1532 |
buf.append(tab); |
|
1533 |
||
1534 |
if (href != null) { |
|
1535 |
buf.link(href, instr.asString(currentPc, symFinder)); |
|
1536 |
} else { |
|
1537 |
buf.append(instr.asString(currentPc, symFinder)); |
|
1538 |
} |
|
1539 |
buf.br(); |
|
1540 |
||
1541 |
// See whether we have an oop map at this PC |
|
1542 |
if (curMap != null) { |
|
1543 |
long curOffset = currentPc - startPc; |
|
1544 |
if (curOffset == curMapOffset) { |
|
1545 |
buf.append(genOopMapInfo(curMap)); |
|
1546 |
if (++curMapIndex >= maps.getSize()) { |
|
1547 |
curMap = null; |
|
1548 |
} else { |
|
1549 |
curMap = maps.getMapAt(curMapIndex); |
|
1550 |
if (curMap != null) { |
|
1551 |
curMapOffset = curMap.getOffset(); |
|
1552 |
} |
|
1553 |
} |
|
1554 |
} |
|
1555 |
} |
|
1556 |
} |
|
1557 |
||
1558 |
public void epilogue() { |
|
1559 |
} |
|
1560 |
}; |
|
1561 |
||
1562 |
disasm.decode(new CodeBlobVisitor()); |
|
1563 |
||
1564 |
buf.genHTMLEpilogue(); |
|
1565 |
return buf.toString(); |
|
1566 |
} catch (Exception exp) { |
|
1567 |
return genHTMLErrorMessage(exp); |
|
1568 |
} |
|
1569 |
} |
|
1570 |
||
1571 |
protected String genInterpreterCodeletTitle(InterpreterCodelet codelet) { |
|
1572 |
Formatter buf = new Formatter(genHTML); |
|
1573 |
buf.append("Interpreter codelet ["); |
|
1574 |
buf.append(codelet.codeBegin().toString()); |
|
1575 |
buf.append(','); |
|
1576 |
buf.append(codelet.codeEnd().toString()); |
|
1577 |
buf.append(") - "); |
|
1578 |
buf.append(codelet.getDescription()); |
|
1579 |
return buf.toString(); |
|
1580 |
} |
|
1581 |
||
1582 |
protected String genInterpreterCodeletLinkPageHref(StubQueue stubq) { |
|
1583 |
return genBaseHref() + "interp_codelets"; |
|
1584 |
} |
|
1585 |
||
1586 |
public String genInterpreterCodeletLinksPage() { |
|
1587 |
Formatter buf = new Formatter(genHTML); |
|
1588 |
buf.genHTMLPrologue("Interpreter Codelets"); |
|
1589 |
buf.beginTag("ul"); |
|
1590 |
||
1591 |
Interpreter interp = VM.getVM().getInterpreter(); |
|
1592 |
StubQueue code = interp.getCode(); |
|
1593 |
InterpreterCodelet stub = (InterpreterCodelet) code.getFirst(); |
|
1594 |
while (stub != null) { |
|
1595 |
buf.beginTag("li"); |
|
1596 |
sun.jvm.hotspot.debugger.Address addr = stub.codeBegin(); |
|
1597 |
buf.link(genPCHref(addressToLong(addr)), stub.getDescription() + " @" + addr); |
|
1598 |
buf.endTag("li"); |
|
1599 |
stub = (InterpreterCodelet) code.getNext(stub); |
|
1600 |
} |
|
1601 |
||
1602 |
buf.endTag("ul"); |
|
1603 |
buf.genHTMLEpilogue(); |
|
1604 |
return buf.toString(); |
|
1605 |
} |
|
1606 |
||
1607 |
public String genHTML(InterpreterCodelet codelet) { |
|
1608 |
Formatter buf = new Formatter(genHTML); |
|
1609 |
buf.genHTMLPrologue(genInterpreterCodeletTitle(codelet)); |
|
1610 |
Interpreter interp = VM.getVM().getInterpreter(); |
|
1611 |
StubQueue stubq = interp.getCode(); |
|
1612 |
||
1613 |
if (genHTML) { |
|
1614 |
buf.beginTag("h3"); |
|
1615 |
buf.link(genInterpreterCodeletLinkPageHref(stubq), "View links for all codelets"); |
|
1616 |
buf.endTag("h3"); |
|
1617 |
buf.br(); |
|
1618 |
} |
|
1619 |
||
1620 |
Stub prev = stubq.getPrev(codelet); |
|
1621 |
if (prev != null) { |
|
1622 |
if (genHTML) { |
|
1623 |
buf.beginTag("h3"); |
|
1624 |
buf.link(genPCHref(addressToLong(prev.codeBegin())), "View Previous Codelet"); |
|
1625 |
buf.endTag("h3"); |
|
1626 |
buf.br(); |
|
1627 |
} else { |
|
1628 |
buf.h3("Previous Codelet = 0x" + Long.toHexString(addressToLong(prev.codeBegin()))); |
|
1629 |
} |
|
1630 |
} |
|
1631 |
||
1632 |
buf.h3("Code"); |
|
1633 |
long stubStartPc = addressToLong(codelet.codeBegin()); |
|
1634 |
long stubEndPc = addressToLong(codelet.codeEnd()); |
|
1635 |
int range = (int) (stubEndPc - stubStartPc); |
|
1636 |
byte[] stubCode = readBuffer(codelet.codeBegin(), range); |
|
1637 |
Disassembler disasm = createDisassembler(stubStartPc, stubCode); |
|
1638 |
disasm.decode(new RawCodeVisitor(buf)); |
|
1639 |
||
1640 |
||
1641 |
Stub next = stubq.getNext(codelet); |
|
1642 |
if (next != null) { |
|
1643 |
if (genHTML) { |
|
1644 |
buf.beginTag("h3"); |
|
1645 |
buf.link(genPCHref(addressToLong(next.codeBegin())), "View Next Codelet"); |
|
1646 |
buf.endTag("h3"); |
|
1647 |
} else { |
|
1648 |
buf.h3("Next Codelet = 0x" + Long.toHexString(addressToLong(next.codeBegin()))); |
|
1649 |
} |
|
1650 |
} |
|
1651 |
||
1652 |
buf.genHTMLEpilogue(); |
|
1653 |
return buf.toString(); |
|
1654 |
} |
|
1655 |
||
1656 |
protected String genDumpKlassesTitle(InstanceKlass[] klasses) { |
|
1657 |
return (klasses.length == 1) ? "Create .class for this class" |
|
1658 |
: "Create .class for all classes"; |
|
1659 |
} |
|
1660 |
||
1661 |
protected String genDumpKlassesHref(InstanceKlass[] klasses) { |
|
1662 |
StringBuffer buf = new StringBuffer(genBaseHref()); |
|
1663 |
buf.append("jcore_multiple="); |
|
1664 |
for (int k = 0; k < klasses.length; k++) { |
|
1665 |
buf.append(klasses[k].getHandle().toString()); |
|
1666 |
buf.append(','); |
|
1667 |
} |
|
1668 |
return buf.toString(); |
|
1669 |
} |
|
1670 |
||
1671 |
protected String genDumpKlassesLink(InstanceKlass[] klasses) { |
|
1672 |
if (!genHTML) return ""; |
|
1673 |
||
1674 |
Formatter buf = new Formatter(genHTML); |
|
1675 |
buf.link(genDumpKlassesHref(klasses), genDumpKlassesTitle(klasses)); |
|
1676 |
return buf.toString(); |
|
1677 |
} |
|
1678 |
||
1679 |
public String genHTMLForKlassNames(InstanceKlass[] klasses) { |
|
1680 |
try { |
|
1681 |
Formatter buf = new Formatter(genHTML); |
|
1682 |
buf.genHTMLPrologue(); |
|
1683 |
buf.h3(genDumpKlassesLink(klasses)); |
|
1684 |
||
1685 |
buf.append(genHTMLListForKlassNames(klasses)); |
|
1686 |
buf.genHTMLEpilogue(); |
|
1687 |
return buf.toString(); |
|
1688 |
} catch (Exception exp) { |
|
1689 |
return genHTMLErrorMessage(exp); |
|
1690 |
} |
|
1691 |
} |
|
1692 |
||
1693 |
protected String genHTMLListForKlassNames(InstanceKlass[] klasses) { |
|
1694 |
final Formatter buf = new Formatter(genHTML); |
|
1695 |
buf.beginTable(0); |
|
1696 |
for (int i = 0; i < klasses.length; i++) { |
|
1697 |
InstanceKlass ik = klasses[i]; |
|
1698 |
buf.beginTag("tr"); |
|
1699 |
buf.cell(genKlassLink(ik)); |
|
1700 |
buf.endTag("tr"); |
|
1701 |
} |
|
1702 |
||
1703 |
buf.endTable(); |
|
1704 |
return buf.toString(); |
|
1705 |
} |
|
1706 |
||
1707 |
public String genHTMLForMethodNames(InstanceKlass klass) { |
|
1708 |
try { |
|
1709 |
Formatter buf = new Formatter(genHTML); |
|
1710 |
buf.genHTMLPrologue(); |
|
1711 |
buf.append(genHTMLListForMethods(klass)); |
|
1712 |
buf.genHTMLEpilogue(); |
|
1713 |
return buf.toString(); |
|
1714 |
} catch (Exception exp) { |
|
1715 |
return genHTMLErrorMessage(exp); |
|
1716 |
} |
|
1717 |
} |
|
1718 |
||
1719 |
protected String genHTMLListForMethods(InstanceKlass klass) { |
|
1720 |
Formatter buf = new Formatter(genHTML); |
|
1721 |
ObjArray methods = klass.getMethods(); |
|
1722 |
int numMethods = (int) methods.getLength(); |
|
1723 |
if (numMethods != 0) { |
|
1724 |
buf.h3("Methods"); |
|
1725 |
buf.beginTag("ul"); |
|
1726 |
for (int m = 0; m < numMethods; m++) { |
|
1727 |
Method mtd = (Method) methods.getObjAt(m); |
|
1728 |
buf.li(genMethodLink(mtd) + ";"); |
|
1729 |
} |
|
1730 |
buf.endTag("ul"); |
|
1731 |
} |
|
1732 |
return buf.toString(); |
|
1733 |
} |
|
1734 |
||
1735 |
protected String genHTMLListForInterfaces(InstanceKlass klass) { |
|
1736 |
try { |
|
1737 |
Formatter buf = new Formatter(genHTML); |
|
1738 |
ObjArray interfaces = klass.getLocalInterfaces(); |
|
1739 |
int numInterfaces = (int) interfaces.getLength(); |
|
1740 |
if (numInterfaces != 0) { |
|
1741 |
buf.h3("Interfaces"); |
|
1742 |
buf.beginTag("ul"); |
|
1743 |
for (int i = 0; i < numInterfaces; i++) { |
|
1744 |
InstanceKlass inf = (InstanceKlass) interfaces.getObjAt(i); |
|
1745 |
buf.li(genKlassLink(inf)); |
|
1746 |
} |
|
1747 |
buf.endTag("ul"); |
|
1748 |
} |
|
1749 |
return buf.toString(); |
|
1750 |
} catch (Exception exp) { |
|
1751 |
return genHTMLErrorMessage(exp); |
|
1752 |
} |
|
1753 |
} |
|
1754 |
||
1755 |
protected String genFieldModifierString(AccessFlags acc) { |
|
1756 |
Formatter buf = new Formatter(genHTML); |
|
1757 |
if (acc.isPrivate()) { |
|
1758 |
buf.append("private "); |
|
1759 |
} else if (acc.isProtected()) { |
|
1760 |
buf.append("protected "); |
|
1761 |
} else if (acc.isPublic()) { |
|
1762 |
buf.append("public "); |
|
1763 |
} |
|
1764 |
||
1765 |
if (acc.isStatic()) { |
|
1766 |
buf.append("static "); |
|
1767 |
} |
|
1768 |
||
1769 |
if (acc.isFinal()) { |
|
1770 |
buf.append("final "); |
|
1771 |
} |
|
1772 |
if (acc.isVolatile()) { |
|
1773 |
buf.append("volatile "); |
|
1774 |
} |
|
1775 |
if (acc.isTransient()) { |
|
1776 |
buf.append("transient "); |
|
1777 |
} |
|
1778 |
||
1779 |
// javac generated flags |
|
1780 |
if (acc.isSynthetic()) { |
|
1781 |
buf.append("[synthetic] "); |
|
1782 |
} |
|
1783 |
return buf.toString(); |
|
1784 |
} |
|
1785 |
||
1786 |
public String genHTMLForFieldNames(InstanceKlass klass) { |
|
1787 |
try { |
|
1788 |
Formatter buf = new Formatter(genHTML); |
|
1789 |
buf.genHTMLPrologue(); |
|
1790 |
buf.append(genHTMLListForFields(klass)); |
|
1791 |
buf.genHTMLEpilogue(); |
|
1792 |
return buf.toString(); |
|
1793 |
} catch (Exception exp) { |
|
1794 |
return genHTMLErrorMessage(exp); |
|
1795 |
} |
|
1796 |
} |
|
1797 |
||
1798 |
protected String genHTMLListForFields(InstanceKlass klass) { |
|
1799 |
Formatter buf = new Formatter(genHTML); |
|
1800 |
TypeArray fields = klass.getFields(); |
|
1801 |
int numFields = (int) fields.getLength(); |
|
1802 |
ConstantPool cp = klass.getConstants(); |
|
1803 |
if (numFields != 0) { |
|
1804 |
buf.h3("Fields"); |
|
1805 |
buf.beginList(); |
|
1806 |
for (int f = 0; f < numFields; f += InstanceKlass.NEXT_OFFSET) { |
|
5341 | 1807 |
sun.jvm.hotspot.oops.Field field = klass.getFieldByIndex(f); |
1808 |
String f_name = ((NamedFieldIdentifier)field.getID()).getName(); |
|
1809 |
Symbol f_sig = field.getSignature(); |
|
1810 |
Symbol f_genSig = field.getGenericSignature(); |
|
1811 |
AccessFlags acc = field.getAccessFlagsObj(); |
|
1 | 1812 |
|
5341 | 1813 |
buf.beginListItem(); |
1 | 1814 |
buf.append(genFieldModifierString(acc)); |
1815 |
buf.append(' '); |
|
1816 |
Formatter sigBuf = new Formatter(genHTML); |
|
1817 |
new SignatureConverter(f_sig, sigBuf.getBuffer()).dispatchField(); |
|
1818 |
buf.append(sigBuf.toString().replace('/', '.')); |
|
1819 |
buf.append(' '); |
|
5341 | 1820 |
buf.append(f_name); |
1 | 1821 |
buf.append(';'); |
1822 |
// is it generic? |
|
1823 |
if (f_genSig != null) { |
|
1824 |
buf.append(" [signature "); |
|
1825 |
buf.append(escapeHTMLSpecialChars(f_genSig.asString())); |
|
1826 |
buf.append("] "); |
|
1827 |
} |
|
5341 | 1828 |
buf.append(" (offset = " + field.getOffset() + ")"); |
1829 |
buf.endListItem(); |
|
1 | 1830 |
} |
1831 |
buf.endList(); |
|
1832 |
} |
|
1833 |
return buf.toString(); |
|
1834 |
} |
|
1835 |
||
1836 |
protected String genKlassHierarchyHref(InstanceKlass klass) { |
|
1837 |
return genBaseHref() + "hierarchy=" + klass.getHandle(); |
|
1838 |
} |
|
1839 |
||
1840 |
protected String genKlassHierarchyTitle(InstanceKlass klass) { |
|
1841 |
Formatter buf = new Formatter(genHTML); |
|
1842 |
buf.append("Class Hierarchy of "); |
|
1843 |
buf.append(genKlassTitle(klass)); |
|
1844 |
return buf.toString(); |
|
1845 |
} |
|
1846 |
||
1847 |
protected String genKlassHierarchyLink(InstanceKlass klass) { |
|
1848 |
Formatter buf = new Formatter(genHTML); |
|
1849 |
buf.link(genKlassHierarchyHref(klass), genKlassHierarchyTitle(klass)); |
|
1850 |
return buf.toString(); |
|
1851 |
} |
|
1852 |
||
1853 |
protected String genHTMLListForSubKlasses(InstanceKlass klass) { |
|
1854 |
Formatter buf = new Formatter(genHTML); |
|
1855 |
Klass subklass = klass.getSubklassKlass(); |
|
1856 |
if (subklass != null) { |
|
1857 |
buf.beginList(); |
|
1858 |
while (subklass != null) { |
|
1859 |
if (subklass instanceof InstanceKlass) { |
|
1860 |
buf.li(genKlassLink((InstanceKlass)subklass)); |
|
1861 |
} |
|
1862 |
subklass = subklass.getNextSiblingKlass(); |
|
1863 |
} |
|
1864 |
buf.endList(); |
|
1865 |
} |
|
1866 |
return buf.toString(); |
|
1867 |
} |
|
1868 |
||
1869 |
public String genHTMLForKlassHierarchy(InstanceKlass klass) { |
|
1870 |
Formatter buf = new Formatter(genHTML); |
|
1871 |
buf.genHTMLPrologue(genKlassHierarchyTitle(klass)); |
|
1872 |
||
1873 |
||
1874 |
buf.beginTag("pre"); |
|
1875 |
buf.append(genKlassLink(klass)); |
|
1876 |
buf.br(); |
|
1877 |
StringBuffer tabs = new StringBuffer(tab); |
|
1878 |
InstanceKlass superKlass = klass; |
|
1879 |
while ( (superKlass = (InstanceKlass) superKlass.getSuper()) != null ) { |
|
1880 |
buf.append(tabs); |
|
1881 |
buf.append(genKlassLink(superKlass)); |
|
1882 |
tabs.append(tab); |
|
1883 |
buf.br(); |
|
1884 |
} |
|
1885 |
buf.endTag("pre"); |
|
1886 |
||
1887 |
// generate subklass list |
|
1888 |
Klass subklass = klass.getSubklassKlass(); |
|
1889 |
if (subklass != null) { |
|
1890 |
buf.h3("Direct Subclasses"); |
|
1891 |
buf.append(genHTMLListForSubKlasses(klass)); |
|
1892 |
} |
|
1893 |
||
1894 |
buf.genHTMLEpilogue(); |
|
1895 |
return buf.toString(); |
|
1896 |
} |
|
1897 |
||
1898 |
protected String genDumpKlassHref(InstanceKlass klass) { |
|
1899 |
return genBaseHref() + "jcore=" + klass.getHandle(); |
|
1900 |
} |
|
1901 |
||
1902 |
protected String genDumpKlassLink(InstanceKlass klass) { |
|
1903 |
if (!genHTML) return ""; |
|
1904 |
||
1905 |
Formatter buf = new Formatter(genHTML); |
|
1906 |
buf.link(genDumpKlassHref(klass), "Create .class File"); |
|
1907 |
return buf.toString(); |
|
1908 |
} |
|
1909 |
||
1910 |
public String genHTML(InstanceKlass klass) { |
|
1911 |
Formatter buf = new Formatter(genHTML); |
|
1912 |
buf.genHTMLPrologue(genKlassTitle(klass)); |
|
1913 |
InstanceKlass superKlass = (InstanceKlass) klass.getSuper(); |
|
1914 |
||
1915 |
if (genHTML) { |
|
1916 |
// super class tree and subclass list |
|
1917 |
buf.beginTag("h3"); |
|
1918 |
buf.link(genKlassHierarchyHref(klass), "View Class Hierarchy"); |
|
1919 |
buf.endTag("h3"); |
|
1920 |
} |
|
1921 |
||
1922 |
// jcore - create .class link |
|
1923 |
buf.h3(genDumpKlassLink(klass)); |
|
1924 |
||
1925 |
// super class |
|
1926 |
if (superKlass != null) { |
|
1927 |
buf.h3("Super Class"); |
|
1928 |
buf.append(genKlassLink(superKlass)); |
|
1929 |
} |
|
1930 |
||
1931 |
// interfaces |
|
1932 |
buf.append(genHTMLListForInterfaces(klass)); |
|
1933 |
||
1934 |
// fields |
|
1935 |
buf.append(genHTMLListForFields(klass)); |
|
1936 |
||
1937 |
// methods |
|
1938 |
buf.append(genHTMLListForMethods(klass)); |
|
1939 |
||
1940 |
// constant pool link |
|
1941 |
buf.h3("Constant Pool"); |
|
1942 |
buf.append(genConstantPoolLink(klass.getConstants())); |
|
1943 |
||
1944 |
buf.genHTMLEpilogue(); |
|
1945 |
return buf.toString(); |
|
1946 |
} |
|
1947 |
||
1948 |
protected sun.jvm.hotspot.debugger.Address parseAddress(String address) { |
|
1949 |
VM vm = VM.getVM(); |
|
1950 |
sun.jvm.hotspot.debugger.Address addr = vm.getDebugger().parseAddress(address); |
|
1951 |
return addr; |
|
1952 |
} |
|
1953 |
||
1954 |
protected long addressToLong(sun.jvm.hotspot.debugger.Address addr) { |
|
1955 |
return VM.getVM().getDebugger().getAddressValue(addr); |
|
1956 |
} |
|
1957 |
||
1958 |
protected sun.jvm.hotspot.debugger.Address longToAddress(long addr) { |
|
1959 |
return parseAddress("0x" + Long.toHexString(addr)); |
|
1960 |
} |
|
1961 |
||
1962 |
protected Oop getOopAtAddress(sun.jvm.hotspot.debugger.Address addr) { |
|
1963 |
OopHandle oopHandle = addr.addOffsetToAsOopHandle(0); |
|
1964 |
return VM.getVM().getObjectHeap().newOop(oopHandle); |
|
1965 |
} |
|
1966 |
||
1967 |
protected Oop getOopAtAddress(String address) { |
|
1968 |
sun.jvm.hotspot.debugger.Address addr = parseAddress(address); |
|
1969 |
return getOopAtAddress(addr); |
|
1970 |
} |
|
1971 |
||
1972 |
private void dumpKlass(InstanceKlass kls) throws IOException { |
|
1973 |
String klassName = kls.getName().asString(); |
|
1974 |
klassName = klassName.replace('/', File.separatorChar); |
|
1975 |
int index = klassName.lastIndexOf(File.separatorChar); |
|
1976 |
File dir = null; |
|
1977 |
if (index != -1) { |
|
1978 |
String dirName = klassName.substring(0, index); |
|
1979 |
dir = new File(DUMP_KLASS_OUTPUT_DIR, dirName); |
|
1980 |
} else { |
|
1981 |
dir = new File(DUMP_KLASS_OUTPUT_DIR); |
|
1982 |
} |
|
1983 |
||
1984 |
dir.mkdirs(); |
|
1985 |
File f = new File(dir, klassName.substring(klassName.lastIndexOf(File.separatorChar) + 1) |
|
1986 |
+ ".class"); |
|
1987 |
f.createNewFile(); |
|
1988 |
FileOutputStream fis = new FileOutputStream(f); |
|
1989 |
ClassWriter cw = new ClassWriter(kls, fis); |
|
1990 |
cw.write(); |
|
1991 |
} |
|
1992 |
||
1993 |
public String genDumpKlass(InstanceKlass kls) { |
|
1994 |
try { |
|
1995 |
dumpKlass(kls); |
|
1996 |
Formatter buf = new Formatter(genHTML); |
|
1997 |
buf.genHTMLPrologue(genKlassTitle(kls)); |
|
1998 |
buf.append(".class created for "); |
|
1999 |
buf.append(genKlassLink(kls)); |
|
2000 |
buf.genHTMLEpilogue(); |
|
2001 |
return buf.toString(); |
|
2002 |
} catch(IOException exp) { |
|
2003 |
return genHTMLErrorMessage(exp); |
|
2004 |
} |
|
2005 |
} |
|
2006 |
||
2007 |
protected String genJavaStackTraceTitle(JavaThread thread) { |
|
2008 |
Formatter buf = new Formatter(genHTML); |
|
2009 |
buf.append("Java Stack Trace for "); |
|
2010 |
buf.append(thread.getThreadName()); |
|
2011 |
return buf.toString(); |
|
2012 |
} |
|
2013 |
||
2014 |
public String genHTMLForJavaStackTrace(JavaThread thread) { |
|
2015 |
Formatter buf = new Formatter(genHTML); |
|
2016 |
buf.genHTMLPrologue(genJavaStackTraceTitle(thread)); |
|
2017 |
||
2018 |
buf.append("Thread state = "); |
|
2019 |
buf.append(thread.getThreadState().toString()); |
|
2020 |
buf.br(); |
|
2021 |
buf.beginTag("pre"); |
|
2022 |
for (JavaVFrame vf = thread.getLastJavaVFrameDbg(); vf != null; vf = vf.javaSender()) { |
|
2023 |
Method method = vf.getMethod(); |
|
2024 |
buf.append(" - "); |
|
2025 |
buf.append(genMethodLink(method)); |
|
2026 |
buf.append(" @bci = " + vf.getBCI()); |
|
2027 |
||
2028 |
int lineNumber = method.getLineNumberFromBCI(vf.getBCI()); |
|
2029 |
if (lineNumber != -1) { |
|
2030 |
buf.append(", line = "); |
|
2031 |
buf.append(lineNumber); |
|
2032 |
} |
|
2033 |
||
2034 |
sun.jvm.hotspot.debugger.Address pc = vf.getFrame().getPC(); |
|
2035 |
if (pc != null) { |
|
2036 |
buf.append(", pc = "); |
|
2037 |
buf.link(genPCHref(addressToLong(pc)), pc.toString()); |
|
2038 |
} |
|
2039 |
||
2040 |
if (vf.isCompiledFrame()) { |
|
2041 |
buf.append(" (Compiled"); |
|
2042 |
} |
|
2043 |
else if (vf.isInterpretedFrame()) { |
|
2044 |
buf.append(" (Interpreted"); |
|
2045 |
} |
|
2046 |
||
2047 |
if (vf.mayBeImpreciseDbg()) { |
|
2048 |
buf.append("; information may be imprecise"); |
|
2049 |
} |
|
2050 |
buf.append(")"); |
|
2051 |
buf.br(); |
|
2052 |
} |
|
2053 |
||
2054 |
buf.endTag("pre"); |
|
2055 |
buf.genHTMLEpilogue(); |
|
2056 |
return buf.toString(); |
|
2057 |
} |
|
2058 |
||
2059 |
public String genHTMLForHyperlink(String href) { |
|
2060 |
if (href.startsWith("klass=")) { |
|
2061 |
href = href.substring(href.indexOf('=') + 1); |
|
2062 |
Oop obj = getOopAtAddress(href); |
|
2063 |
if (Assert.ASSERTS_ENABLED) { |
|
2064 |
Assert.that(obj instanceof InstanceKlass, "class= href with improper InstanceKlass!"); |
|
2065 |
} |
|
2066 |
return genHTML((InstanceKlass) obj); |
|
2067 |
} else if (href.startsWith("method=")) { |
|
2068 |
href = href.substring(href.indexOf('=') + 1); |
|
2069 |
Oop obj = getOopAtAddress(href); |
|
2070 |
if (Assert.ASSERTS_ENABLED) { |
|
2071 |
Assert.that(obj instanceof Method, "method= href with improper Method!"); |
|
2072 |
} |
|
2073 |
return genHTML((Method) obj); |
|
2074 |
} else if (href.startsWith("nmethod=")) { |
|
2075 |
String addr = href.substring(href.indexOf('=') + 1); |
|
2076 |
Object obj = VMObjectFactory.newObject(NMethod.class, parseAddress(addr)); |
|
2077 |
if (Assert.ASSERTS_ENABLED) { |
|
2078 |
Assert.that(obj instanceof NMethod, "nmethod= href with improper NMethod!"); |
|
2079 |
} |
|
2080 |
return genHTML((NMethod) obj); |
|
2081 |
} else if (href.startsWith("pc=")) { |
|
2082 |
String address = href.substring(href.indexOf('=') + 1); |
|
2083 |
return genHTML(parseAddress(address)); |
|
2084 |
} else if (href.startsWith("pc_multiple=")) { |
|
2085 |
int indexOfComma = href.indexOf(','); |
|
2086 |
if (indexOfComma == -1) { |
|
2087 |
String firstPC = href.substring(href.indexOf('=') + 1); |
|
2088 |
return genHTMLForRawDisassembly(parseAddress(firstPC), null); |
|
2089 |
} else { |
|
2090 |
String firstPC = href.substring(href.indexOf('=') + 1, indexOfComma); |
|
2091 |
return genHTMLForRawDisassembly(parseAddress(firstPC), href.substring(indexOfComma + 1)); |
|
2092 |
} |
|
2093 |
} else if (href.startsWith("interp_codelets")) { |
|
2094 |
return genInterpreterCodeletLinksPage(); |
|
2095 |
} else if (href.startsWith("hierarchy=")) { |
|
2096 |
href = href.substring(href.indexOf('=') + 1); |
|
2097 |
Oop obj = getOopAtAddress(href); |
|
2098 |
if (Assert.ASSERTS_ENABLED) { |
|
2099 |
Assert.that(obj instanceof InstanceKlass, "class= href with improper InstanceKlass!"); |
|
2100 |
} |
|
2101 |
return genHTMLForKlassHierarchy((InstanceKlass) obj); |
|
2102 |
} else if (href.startsWith("cpool=")) { |
|
2103 |
href = href.substring(href.indexOf('=') + 1); |
|
2104 |
Oop obj = getOopAtAddress(href); |
|
2105 |
if (Assert.ASSERTS_ENABLED) { |
|
2106 |
Assert.that(obj instanceof ConstantPool, "cpool= href with improper ConstantPool!"); |
|
2107 |
} |
|
2108 |
return genHTML((ConstantPool) obj); |
|
2109 |
} else if (href.startsWith("jcore=")) { |
|
2110 |
href = href.substring(href.indexOf('=') + 1); |
|
2111 |
Oop obj = getOopAtAddress(href); |
|
2112 |
if (Assert.ASSERTS_ENABLED) { |
|
2113 |
Assert.that(obj instanceof InstanceKlass, "jcore= href with improper InstanceKlass!"); |
|
2114 |
} |
|
2115 |
return genDumpKlass((InstanceKlass) obj); |
|
2116 |
} else if (href.startsWith("jcore_multiple=")) { |
|
2117 |
href = href.substring(href.indexOf('=') + 1); |
|
2118 |
Formatter buf = new Formatter(genHTML); |
|
2119 |
buf.genHTMLPrologue(); |
|
2120 |
StringTokenizer st = new StringTokenizer(href, ","); |
|
2121 |
while (st.hasMoreTokens()) { |
|
2122 |
Oop obj = getOopAtAddress(st.nextToken()); |
|
2123 |
if (Assert.ASSERTS_ENABLED) { |
|
2124 |
Assert.that(obj instanceof InstanceKlass, "jcore_multiple= href with improper InstanceKlass!"); |
|
2125 |
} |
|
2126 |
||
2127 |
InstanceKlass kls = (InstanceKlass) obj; |
|
2128 |
try { |
|
2129 |
dumpKlass(kls); |
|
2130 |
buf.append(".class created for "); |
|
2131 |
buf.append(genKlassLink(kls)); |
|
2132 |
} catch(Exception exp) { |
|
2133 |
buf.bold("can't .class for " + |
|
2134 |
genKlassTitle(kls) + |
|
2135 |
" : " + |
|
2136 |
exp.getMessage()); |
|
2137 |
} |
|
2138 |
buf.br(); |
|
2139 |
} |
|
2140 |
||
2141 |
buf.genHTMLEpilogue(); |
|
2142 |
return buf.toString(); |
|
2143 |
} else { |
|
2144 |
if (Assert.ASSERTS_ENABLED) { |
|
2145 |
Assert.that(false, "unknown href link!"); |
|
2146 |
} |
|
2147 |
return null; |
|
2148 |
} |
|
2149 |
} |
|
2150 |
} |