Mercurial > hg > graal-compiler
annotate agent/src/share/classes/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java @ 1552:c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair
author | trims |
---|---|
date | Thu, 27 May 2010 19:08:38 -0700 |
parents | bc32f286fae0 |
children | 136b78722a08 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
diff
changeset
|
2 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1385
diff
changeset
|
21 * questions. |
0 | 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(); } | |
1385 | 98 void endList() { endTag("ul"); nl(); } |
99 void beginListItem() { beginTag("li"); } | |
100 void endListItem() { endTag("li"); nl(); } | |
0 | 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 | |
1385 | 510 case JVM_CONSTANT_UnresolvedClassInError: |
511 buf.cell("JVM_CONSTANT_UnresolvedClassInError"); | |
512 buf.cell(cpool.getSymbolAt(index).asString()); | |
513 break; | |
514 | |
0 | 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; | |
1385 | 574 |
575 default: | |
576 throw new InternalError("unknown tag: " + ctag); | |
0 | 577 } |
578 | |
579 buf.endTag("tr"); | |
580 } | |
581 | |
582 buf.endTable(); | |
583 return buf.toString(); | |
584 } | |
585 | |
586 public String genHTML(ConstantPool cpool) { | |
587 try { | |
588 Formatter buf = new Formatter(genHTML); | |
589 buf.genHTMLPrologue(genConstantPoolTitle(cpool)); | |
590 buf.h3("Holder Class"); | |
591 buf.append(genKlassLink((InstanceKlass) cpool.getPoolHolder())); | |
592 buf.h3("Constants"); | |
593 buf.append(genHTMLTableForConstantPool(cpool)); | |
594 buf.genHTMLEpilogue(); | |
595 return buf.toString(); | |
596 } catch (Exception exp) { | |
597 return genHTMLErrorMessage(exp); | |
598 } | |
599 } | |
600 | |
601 protected String genConstantPoolHref(ConstantPool cpool) { | |
602 return genBaseHref() + "cpool=" + cpool.getHandle(); | |
603 } | |
604 | |
605 protected String genConstantPoolTitle(ConstantPool cpool) { | |
606 Formatter buf = new Formatter(genHTML); | |
607 buf.append("Constant Pool of ["); | |
608 buf.append(genKlassTitle((InstanceKlass) cpool.getPoolHolder())); | |
609 buf.append("] @"); | |
610 buf.append(cpool.getHandle().toString()); | |
611 return buf.toString(); | |
612 } | |
613 | |
614 protected String genConstantPoolLink(ConstantPool cpool) { | |
615 Formatter buf = new Formatter(genHTML); | |
616 buf.link(genConstantPoolHref(cpool), genConstantPoolTitle(cpool)); | |
617 return buf.toString(); | |
618 } | |
619 | |
620 public String genHTML(Method method) { | |
621 try { | |
622 final Formatter buf = new Formatter(genHTML); | |
623 buf.genHTMLPrologue(genMethodTitle(method)); | |
624 | |
625 buf.h3("Holder Class"); | |
626 buf.append(genKlassLink((InstanceKlass) method.getMethodHolder())); | |
627 | |
628 NMethod nmethod = method.getNativeMethod(); | |
629 if (nmethod != null) { | |
630 buf.h3("Compiled Code"); | |
631 buf.append(genNMethodLink(nmethod)); | |
632 } | |
633 | |
634 boolean hasThrows = method.hasCheckedExceptions(); | |
635 ConstantPool cpool = ((InstanceKlass) method.getMethodHolder()).getConstants(); | |
636 if (hasThrows) { | |
637 buf.h3("Checked Exception(s)"); | |
638 CheckedExceptionElement[] exceptions = method.getCheckedExceptions(); | |
639 buf.beginTag("ul"); | |
640 for (int exp = 0; exp < exceptions.length; exp++) { | |
641 short cpIndex = (short) exceptions[exp].getClassCPIndex(); | |
642 Oop obj = cpool.getObjAt(cpIndex); | |
643 if (obj instanceof Symbol) { | |
644 buf.li(((Symbol)obj).asString().replace('/', '.')); | |
645 } else { | |
646 buf.li(genKlassLink((InstanceKlass)obj)); | |
647 } | |
648 } | |
649 buf.endTag("ul"); | |
650 } | |
651 | |
652 if (method.isNative() || method.isAbstract()) { | |
653 buf.genHTMLEpilogue(); | |
654 return buf.toString(); | |
655 } | |
656 | |
657 buf.h3("Bytecode"); | |
658 BytecodeDisassembler disasm = createBytecodeDisassembler(method); | |
659 final boolean hasLineNumbers = method.hasLineNumberTable(); | |
660 disasm.decode(new BytecodeVisitor() { | |
661 private Method method; | |
662 public void prologue(Method m) { | |
663 method = m; | |
664 buf.beginTable(0); | |
665 buf.beginTag("tr"); | |
666 if (hasLineNumbers) { | |
667 buf.headerCell("line"); | |
668 } | |
669 buf.headerCell("bci" + spaces); | |
670 buf.headerCell("bytecode"); | |
671 buf.endTag("tr"); | |
672 } | |
673 | |
674 public void visit(Bytecode instr) { | |
675 int curBci = instr.bci(); | |
676 buf.beginTag("tr"); | |
677 if (hasLineNumbers) { | |
678 int lineNumber = method.getLineNumberFromBCI(curBci); | |
679 buf.cell(Integer.toString(lineNumber) + spaces); | |
680 } | |
681 buf.cell(Integer.toString(curBci) + spaces); | |
682 | |
683 buf.beginTag("td"); | |
1385 | 684 String instrStr = null; |
685 try { | |
686 instrStr = escapeHTMLSpecialChars(instr.toString()); | |
687 } catch (RuntimeException re) { | |
688 buf.append("exception during bytecode processing"); | |
689 buf.endTag("td"); | |
690 buf.endTag("tr"); | |
691 re.printStackTrace(); | |
692 return; | |
693 } | |
0 | 694 |
695 if (instr instanceof BytecodeNew) { | |
696 BytecodeNew newBytecode = (BytecodeNew) instr; | |
697 InstanceKlass klass = newBytecode.getNewKlass(); | |
698 if (klass != null) { | |
699 buf.link(genKlassHref(klass), instrStr); | |
700 } else { | |
701 buf.append(instrStr); | |
702 } | |
703 } else if(instr instanceof BytecodeInvoke) { | |
704 BytecodeInvoke invokeBytecode = (BytecodeInvoke) instr; | |
705 Method m = invokeBytecode.getInvokedMethod(); | |
706 if (m != null) { | |
707 buf.link(genMethodHref(m), instrStr); | |
708 buf.append(" of "); | |
709 InstanceKlass klass = (InstanceKlass) m.getMethodHolder(); | |
710 buf.link(genKlassHref(klass), genKlassTitle(klass)); | |
711 } else { | |
712 buf.append(instrStr); | |
713 } | |
714 } else if (instr instanceof BytecodeGetPut) { | |
715 BytecodeGetPut getPut = (BytecodeGetPut) instr; | |
716 sun.jvm.hotspot.oops.Field f = getPut.getField(); | |
717 buf.append(instrStr); | |
718 if (f != null) { | |
719 InstanceKlass klass = f.getFieldHolder(); | |
720 buf.append(" of "); | |
721 buf.link(genKlassHref(klass), genKlassTitle(klass)); | |
722 } | |
723 } else if (instr instanceof BytecodeLoadConstant) { | |
724 BytecodeLoadConstant ldc = (BytecodeLoadConstant) instr; | |
725 if (ldc.isKlassConstant()) { | |
726 Oop oop = ldc.getKlass(); | |
727 if (oop instanceof Klass) { | |
728 buf.append("<a href='"); | |
729 buf.append(genKlassHref((InstanceKlass) oop)); | |
730 buf.append("'>"); | |
731 buf.append(instrStr); | |
732 buf.append("</a>"); | |
733 } else { | |
734 // unresolved klass literal | |
735 buf.append(instrStr); | |
736 } | |
737 } else { | |
738 // not a klass literal | |
739 buf.append(instrStr); | |
740 } | |
741 } else { | |
742 buf.append(instrStr); | |
743 } | |
744 buf.endTag("td"); | |
745 buf.endTag("tr"); | |
746 } | |
747 | |
748 public void epilogue() { | |
749 buf.endTable(); | |
750 } | |
751 }); | |
752 | |
753 // display exception table for this method | |
754 TypeArray exceptionTable = method.getExceptionTable(); | |
755 // exception table is 4 tuple array of shorts | |
756 int numEntries = (int)exceptionTable.getLength() / 4; | |
757 if (numEntries != 0) { | |
758 buf.h4("Exception Table"); | |
759 buf.beginTable(1); | |
760 buf.beginTag("tr"); | |
761 buf.headerCell("start bci"); | |
762 buf.headerCell("end bci"); | |
763 buf.headerCell("handler bci"); | |
764 buf.headerCell("catch type"); | |
765 buf.endTag("tr"); | |
766 | |
767 for (int e = 0; e < numEntries; e += 4) { | |
768 buf.beginTag("tr"); | |
769 buf.cell(Integer.toString(exceptionTable.getIntAt(e))); | |
770 buf.cell(Integer.toString(exceptionTable.getIntAt(e + 1))); | |
771 buf.cell(Integer.toString(exceptionTable.getIntAt(e + 2))); | |
772 short cpIndex = (short) exceptionTable.getIntAt(e + 3); | |
773 Oop obj = cpIndex == 0? null : cpool.getObjAt(cpIndex); | |
774 if (obj == null) { | |
775 buf.cell("Any"); | |
776 } else if (obj instanceof Symbol) { | |
777 buf.cell(((Symbol)obj).asString().replace('/', '.')); | |
778 } else { | |
779 buf.cell(genKlassLink((InstanceKlass)obj)); | |
780 } | |
781 buf.endTag("tr"); | |
782 } | |
783 | |
784 buf.endTable(); | |
785 } | |
786 | |
787 // display constant pool hyperlink | |
788 buf.h3("Constant Pool"); | |
789 buf.append(genConstantPoolLink(cpool)); | |
790 buf.genHTMLEpilogue(); | |
791 return buf.toString(); | |
792 } catch (Exception exp) { | |
793 return genHTMLErrorMessage(exp); | |
794 } | |
795 } | |
796 | |
797 protected Disassembler createDisassembler(long startPc, byte[] code) { | |
798 return getCPUHelper().createDisassembler(startPc, code); | |
799 } | |
800 | |
801 protected SymbolFinder createSymbolFinder() { | |
802 return new DummySymbolFinder(); | |
803 } | |
804 | |
805 // genHTML for a given address. Address may be a PC or | |
806 // methodOop or klassOop. | |
807 | |
808 public String genHTMLForAddress(String addrStr) { | |
809 return genHTML(parseAddress(addrStr)); | |
810 } | |
811 | |
812 public String genHTML(sun.jvm.hotspot.debugger.Address pc) { | |
813 CodeBlob blob = null; | |
814 | |
815 try { | |
816 blob = (CodeBlob)VM.getVM().getCodeCache().findBlobUnsafe(pc); | |
817 } catch (Exception exp) { | |
818 // ignore | |
819 } | |
820 | |
821 if (blob != null) { | |
822 if (blob instanceof NMethod) { | |
823 return genHTML((NMethod)blob); | |
824 } else { | |
825 // may be interpreter code. | |
826 Interpreter interp = VM.getVM().getInterpreter(); | |
827 if (interp.contains(pc)) { | |
828 InterpreterCodelet codelet = interp.getCodeletContaining(pc); | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
829 if (codelet == null) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
830 return "Unknown location in the Interpreter: " + pc; |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
831 } |
0 | 832 return genHTML(codelet); |
833 } | |
834 return genHTML(blob); | |
835 } | |
836 } else if (VM.getVM().getCodeCache().contains(pc)) { | |
837 return "Unknown location in the CodeCache: " + pc; | |
838 } | |
839 | |
840 // did not find nmethod. | |
841 // try methodOop, klassOop and constantPoolOop. | |
842 try { | |
843 Oop obj = getOopAtAddress(pc); | |
844 if (obj != null) { | |
845 if (obj instanceof Method) { | |
846 return genHTML((Method) obj); | |
847 } else if (obj instanceof InstanceKlass) { | |
848 return genHTML((InstanceKlass) obj); | |
849 } else if (obj instanceof ConstantPool) { | |
850 return genHTML((ConstantPool) obj); | |
851 } | |
852 } | |
853 } catch (Exception exp) { | |
854 // ignore | |
855 } | |
856 | |
857 // didn't find any. do raw disassembly. | |
858 return genHTMLForRawDisassembly(pc, null); | |
859 } | |
860 | |
861 protected byte[] readBuffer(sun.jvm.hotspot.debugger.Address addr, int size) { | |
862 byte[] buf = new byte[size]; | |
863 for (int b = 0; b < size; b++) { | |
864 buf[b] = (byte) addr.getJByteAt(b); | |
865 } | |
866 return buf; | |
867 } | |
868 | |
869 public String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address startPc, int size) { | |
870 try { | |
871 return genHTMLForRawDisassembly(startPc, null, readBuffer(startPc, size)); | |
872 } catch (Exception exp) { | |
873 return genHTMLErrorMessage(exp); | |
874 } | |
875 } | |
876 | |
877 protected String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address startPc, | |
878 String prevPCs) { | |
879 try { | |
880 return genHTMLForRawDisassembly(startPc, prevPCs, readBuffer(startPc, NATIVE_CODE_SIZE)); | |
881 } catch (Exception exp) { | |
882 return genHTMLErrorMessage(exp); | |
883 } | |
884 } | |
885 | |
886 protected String genPCHref(long targetPc) { | |
887 return genBaseHref() + "pc=0x" + Long.toHexString(targetPc); | |
888 } | |
889 | |
890 protected String genMultPCHref(String pcs) { | |
891 StringBuffer buf = new StringBuffer(genBaseHref()); | |
892 buf.append("pc_multiple="); | |
893 buf.append(pcs); | |
894 return buf.toString(); | |
895 } | |
896 | |
897 protected String genPCHref(long currentPc, sun.jvm.hotspot.asm.Address addr) { | |
898 String href = null; | |
899 if (addr instanceof PCRelativeAddress) { | |
900 PCRelativeAddress pcRelAddr = (PCRelativeAddress) addr; | |
901 href = genPCHref(currentPc + pcRelAddr.getDisplacement()); | |
902 } else if(addr instanceof DirectAddress) { | |
903 href = genPCHref(((DirectAddress) addr).getValue()); | |
904 } | |
905 | |
906 return href; | |
907 } | |
908 | |
909 class RawCodeVisitor implements InstructionVisitor { | |
910 private int instrSize = 0; | |
911 private Formatter buf; | |
912 private SymbolFinder symFinder = createSymbolFinder(); | |
913 | |
914 RawCodeVisitor(Formatter buf) { | |
915 this.buf = buf; | |
916 } | |
917 | |
918 public int getInstructionSize() { | |
919 return instrSize; | |
920 } | |
921 | |
922 public void prologue() { | |
923 } | |
924 | |
925 public void visit(long currentPc, Instruction instr) { | |
926 String href = null; | |
927 if (instr.isCall()) { | |
928 CallInstruction call = (CallInstruction) instr; | |
929 sun.jvm.hotspot.asm.Address addr = call.getBranchDestination(); | |
930 href = genPCHref(currentPc, addr); | |
931 } | |
932 | |
933 instrSize += instr.getSize(); | |
934 buf.append("0x"); | |
935 buf.append(Long.toHexString(currentPc)); | |
936 buf.append(':'); | |
937 buf.append(tab); | |
938 | |
939 if (href != null) { | |
940 buf.link(href, instr.asString(currentPc, symFinder)); | |
941 } else { | |
942 buf.append(instr.asString(currentPc, symFinder)); | |
943 } | |
944 buf.br(); | |
945 } | |
946 | |
947 public void epilogue() { | |
948 } | |
949 }; | |
950 | |
951 protected String genHTMLForRawDisassembly(sun.jvm.hotspot.debugger.Address addr, | |
952 String prevPCs, | |
953 byte[] code) { | |
954 try { | |
955 long startPc = addressToLong(addr); | |
956 Disassembler disasm = createDisassembler(startPc, code); | |
957 final Formatter buf = new Formatter(genHTML); | |
958 buf.genHTMLPrologue("Disassembly @0x" + Long.toHexString(startPc)); | |
959 | |
960 if (prevPCs != null && genHTML) { | |
961 buf.beginTag("p"); | |
962 buf.link(genMultPCHref(prevPCs), "show previous code .."); | |
963 buf.endTag("p"); | |
964 } | |
965 | |
966 | |
967 buf.h3("Code"); | |
968 RawCodeVisitor visitor = new RawCodeVisitor(buf); | |
969 disasm.decode(visitor); | |
970 | |
971 if (genHTML) buf.beginTag("p"); | |
972 Formatter tmpBuf = new Formatter(genHTML); | |
973 tmpBuf.append("0x"); | |
974 tmpBuf.append(Long.toHexString(startPc + visitor.getInstructionSize()).toString()); | |
975 tmpBuf.append(",0x"); | |
976 tmpBuf.append(Long.toHexString(startPc)); | |
977 if (prevPCs != null) { | |
978 tmpBuf.append(','); | |
979 tmpBuf.append(prevPCs); | |
980 } | |
981 if (genHTML) { | |
982 buf.link(genMultPCHref(tmpBuf.toString()), "show more code .."); | |
983 buf.endTag("p"); | |
984 } | |
985 | |
986 buf.genHTMLEpilogue(); | |
987 return buf.toString(); | |
988 } catch (Exception exp) { | |
989 return genHTMLErrorMessage(exp); | |
990 } | |
991 } | |
992 | |
993 protected String genSafepointInfo(NMethod nm, PCDesc pcDesc) { | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
994 ScopeDesc sd = nm.getScopeDescAt(pcDesc.getRealPC(nm)); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
995 Formatter buf = new Formatter(genHTML); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
996 Formatter tabs = new Formatter(genHTML); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
997 tabs.append(tab + tab + tab); // Initial indent for debug info |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
998 |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
999 buf.beginTag("pre"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1000 genScope(buf, tabs, sd); |
0 | 1001 |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1002 // Reset indent for scalar replaced objects |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1003 tabs = new Formatter(genHTML); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1004 tabs.append(tab + tab + tab); // Initial indent for debug info |
0 | 1005 |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1006 genScObjInfo(buf, tabs, sd); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1007 buf.endTag("pre"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1008 |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1009 buf.append(genOopMapInfo(nm, pcDesc)); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1010 |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1011 return buf.toString(); |
0 | 1012 } |
1013 | |
1014 protected void genScope(Formatter buf, Formatter tabs, ScopeDesc sd) { | |
1015 if (sd == null) { | |
1016 return; | |
1017 } | |
1018 | |
1019 genScope(buf, tabs, sd.sender()); | |
1020 | |
1021 buf.append(tabs); | |
1022 Method m = sd.getMethod(); | |
1023 buf.append(genMethodAndKlassLink(m)); | |
1024 int bci = sd.getBCI(); | |
1025 buf.append(" @ bci = "); | |
1026 buf.append(Integer.toString(bci)); | |
1027 | |
1028 int line = m.getLineNumberFromBCI(bci); | |
1029 if (line != -1) { | |
1030 buf.append(", line = "); | |
1031 buf.append(Integer.toString(line)); | |
1032 } | |
1033 | |
1034 List locals = sd.getLocals(); | |
1035 if (locals != null) { | |
1036 buf.br(); | |
1037 buf.append(tabs); | |
1038 buf.append(genHTMLForLocals(sd, locals)); | |
1039 } | |
1040 | |
1041 List expressions = sd.getExpressions(); | |
1042 if (expressions != null) { | |
1043 buf.br(); | |
1044 buf.append(tabs); | |
1045 buf.append(genHTMLForExpressions(sd, expressions)); | |
1046 } | |
1047 | |
1048 List monitors = sd.getMonitors(); | |
1049 if (monitors != null) { | |
1050 buf.br(); | |
1051 buf.append(tabs); | |
1052 buf.append(genHTMLForMonitors(sd, monitors)); | |
1053 } | |
1054 | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1055 buf.br(); |
0 | 1056 tabs.append(tab); |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1057 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1058 |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1059 protected void genScObjInfo(Formatter buf, Formatter tabs, ScopeDesc sd) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1060 if (sd == null) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1061 return; |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1062 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1063 |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1064 List objects = sd.getObjects(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1065 if (objects == null) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1066 return; |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1067 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1068 int length = objects.size(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1069 for (int i = 0; i < length; i++) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1070 buf.append(tabs); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1071 ObjectValue ov = (ObjectValue)objects.get(i); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1072 buf.append("ScObj" + i); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1073 ScopeValue sv = ov.getKlass(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1074 if (Assert.ASSERTS_ENABLED) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1075 Assert.that(sv.isConstantOop(), "scalar replaced object klass must be constant oop"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1076 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1077 ConstantOopReadValue klv = (ConstantOopReadValue)sv; |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1078 OopHandle klHandle = klv.getValue(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1079 if (Assert.ASSERTS_ENABLED) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1080 Assert.that(klHandle != null, "scalar replaced object klass must be not NULL"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1081 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1082 Oop obj = VM.getVM().getObjectHeap().newOop(klHandle); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1083 if (obj instanceof InstanceKlass) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1084 InstanceKlass kls = (InstanceKlass) obj; |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1085 buf.append(" " + kls.getName().asString() + "={"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1086 int flen = ov.fieldsSize(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1087 |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1088 TypeArray klfields = kls.getFields(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1089 int klen = (int) klfields.getLength(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1090 |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1091 ConstantPool cp = kls.getConstants(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1092 int findex = 0; |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1093 for (int index = 0; index < klen; index += kls.NEXT_OFFSET) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1094 int accsFlags = klfields.getShortAt(index + kls.ACCESS_FLAGS_OFFSET); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1095 int nameIndex = klfields.getShortAt(index + kls.NAME_INDEX_OFFSET); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1096 AccessFlags access = new AccessFlags(accsFlags); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1097 if (!access.isStatic()) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1098 ScopeValue svf = ov.getFieldAt(findex++); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1099 String fstr = scopeValueAsString(sd, svf); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1100 Symbol f_name = cp.getSymbolAt(nameIndex); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1101 buf.append(" [" + f_name.asString() + " :"+ index + "]=(#" + fstr + ")"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1102 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1103 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1104 buf.append(" }"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1105 } else { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1106 buf.append(" "); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1107 int flen = ov.fieldsSize(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1108 if (obj instanceof TypeArrayKlass) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1109 TypeArrayKlass kls = (TypeArrayKlass) obj; |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1110 buf.append(kls.getElementTypeName() + "[" + flen + "]"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1111 } else if (obj instanceof ObjArrayKlass) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1112 ObjArrayKlass kls = (ObjArrayKlass) obj; |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1113 Klass elobj = kls.getBottomKlass(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1114 if (elobj instanceof InstanceKlass) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1115 buf.append(elobj.getName().asString()); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1116 } else if (elobj instanceof TypeArrayKlass) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1117 TypeArrayKlass elkls = (TypeArrayKlass) elobj; |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1118 buf.append(elkls.getElementTypeName()); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1119 } else { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1120 if (Assert.ASSERTS_ENABLED) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1121 Assert.that(false, "unknown scalar replaced object klass!"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1122 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1123 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1124 buf.append("[" + flen + "]"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1125 int ndim = (int) kls.getDimension(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1126 while (--ndim > 0) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1127 buf.append("[]"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1128 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1129 } else { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1130 if (Assert.ASSERTS_ENABLED) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1131 Assert.that(false, "unknown scalar replaced object klass!"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1132 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1133 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1134 buf.append("={"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1135 for (int findex = 0; findex < flen; findex++) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1136 ScopeValue svf = ov.getFieldAt(findex); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1137 String fstr = scopeValueAsString(sd, svf); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1138 buf.append(" [" + findex + "]=(#" + fstr + ")"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1139 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1140 buf.append(" }"); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1141 } |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1142 buf.br(); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1143 } |
0 | 1144 } |
1145 | |
1146 protected String genHTMLForOopMap(OopMap map) { | |
1147 final int stack0 = VMRegImpl.getStack0().getValue(); | |
1148 Formatter buf = new Formatter(genHTML); | |
1149 | |
1150 final class OopMapValueIterator { | |
1151 final Formatter iterate(OopMapStream oms, String type, boolean printContentReg) { | |
1152 Formatter tmpBuf = new Formatter(genHTML); | |
1153 boolean found = false; | |
1154 tmpBuf.beginTag("tr"); | |
1155 tmpBuf.beginTag("td"); | |
1156 tmpBuf.append(type); | |
1157 for (; ! oms.isDone(); oms.next()) { | |
1158 OopMapValue omv = oms.getCurrent(); | |
1159 if (omv == null) { | |
1160 continue; | |
1161 } | |
1162 found = true; | |
1163 VMReg vmReg = omv.getReg(); | |
1164 int reg = vmReg.getValue(); | |
1165 if (reg < stack0) { | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1166 tmpBuf.append(VMRegImpl.getRegisterName(reg)); |
0 | 1167 } else { |
1168 tmpBuf.append('['); | |
1169 tmpBuf.append(Integer.toString((reg - stack0) * 4)); | |
1170 tmpBuf.append(']'); | |
1171 } | |
1172 if (printContentReg) { | |
1173 tmpBuf.append(" = "); | |
1174 VMReg vmContentReg = omv.getContentReg(); | |
1175 int contentReg = vmContentReg.getValue(); | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1176 if (contentReg < stack0) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1177 tmpBuf.append(VMRegImpl.getRegisterName(contentReg)); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1178 } else { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1179 tmpBuf.append('['); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1180 tmpBuf.append(Integer.toString((contentReg - stack0) * 4)); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1181 tmpBuf.append(']'); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1182 } |
0 | 1183 } |
1184 tmpBuf.append(spaces); | |
1185 } | |
1186 tmpBuf.endTag("td"); | |
1187 tmpBuf.endTag("tr"); | |
1188 return found ? tmpBuf : new Formatter(genHTML); | |
1189 } | |
1190 } | |
1191 | |
1192 buf.beginTable(0); | |
1193 | |
1194 OopMapValueIterator omvIterator = new OopMapValueIterator(); | |
1195 OopMapStream oms = new OopMapStream(map, OopMapValue.OopTypes.OOP_VALUE); | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1196 buf.append(omvIterator.iterate(oms, "Oops:", false)); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1197 |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1198 oms = new OopMapStream(map, OopMapValue.OopTypes.NARROWOOP_VALUE); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1199 buf.append(omvIterator.iterate(oms, "narrowOops:", false)); |
0 | 1200 |
1201 oms = new OopMapStream(map, OopMapValue.OopTypes.VALUE_VALUE); | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1202 buf.append(omvIterator.iterate(oms, "Values:", false)); |
0 | 1203 |
1204 oms = new OopMapStream(map, OopMapValue.OopTypes.CALLEE_SAVED_VALUE); | |
1205 buf.append(omvIterator.iterate(oms, "Callee saved:", true)); | |
1206 | |
1207 oms = new OopMapStream(map, OopMapValue.OopTypes.DERIVED_OOP_VALUE); | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1208 buf.append(omvIterator.iterate(oms, "Derived oops:", true)); |
0 | 1209 |
1210 buf.endTag("table"); | |
1211 return buf.toString(); | |
1212 } | |
1213 | |
1214 | |
1215 protected String genOopMapInfo(NMethod nmethod, PCDesc pcDesc) { | |
1216 OopMapSet mapSet = nmethod.getOopMaps(); | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1217 if (mapSet == null || (mapSet.getSize() <= 0)) |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1218 return ""; |
0 | 1219 int pcOffset = pcDesc.getPCOffset(); |
1220 OopMap map = mapSet.findMapAtOffset(pcOffset, VM.getVM().isDebugging()); | |
1221 if (map == null) { | |
1222 throw new IllegalArgumentException("no oopmap at safepoint!"); | |
1223 } | |
1224 | |
1225 return genOopMapInfo(map); | |
1226 } | |
1227 | |
1228 protected String genOopMapInfo(OopMap map) { | |
1229 Formatter buf = new Formatter(genHTML); | |
1230 buf.beginTag("pre"); | |
1231 buf.append("OopMap: "); | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1232 buf.br(); |
0 | 1233 buf.append(genHTMLForOopMap(map)); |
1234 buf.endTag("pre"); | |
1235 | |
1236 return buf.toString(); | |
1237 } | |
1238 | |
1239 protected String locationAsString(Location loc) { | |
1240 Formatter buf = new Formatter(genHTML); | |
1241 if (loc.isIllegal()) { | |
1242 buf.append("illegal"); | |
1243 } else { | |
1244 Location.Where w = loc.getWhere(); | |
1245 Location.Type type = loc.getType(); | |
1246 | |
1247 if (w == Location.Where.ON_STACK) { | |
1248 buf.append("stack[" + loc.getStackOffset() + "]"); | |
1249 } else if (w == Location.Where.IN_REGISTER) { | |
1250 boolean isFloat = (type == Location.Type.FLOAT_IN_DBL || | |
1251 type == Location.Type.DBL); | |
1252 int regNum = loc.getRegisterNumber(); | |
1253 VMReg vmReg = new VMReg(regNum); | |
1254 buf.append(VMRegImpl.getRegisterName(vmReg.getValue())); | |
1255 } | |
1256 | |
1257 buf.append(", "); | |
1258 if (type == Location.Type.NORMAL) { | |
1259 buf.append("normal"); | |
1260 } else if (type == Location.Type.OOP) { | |
1261 buf.append("oop"); | |
331
cecd8eb4e0ca
6706829: Compressed Oops: add debug info for narrow oops
kvn
parents:
196
diff
changeset
|
1262 } else if (type == Location.Type.NARROWOOP) { |
cecd8eb4e0ca
6706829: Compressed Oops: add debug info for narrow oops
kvn
parents:
196
diff
changeset
|
1263 buf.append("narrowoop"); |
0 | 1264 } else if (type == Location.Type.INT_IN_LONG) { |
1265 buf.append("int"); | |
1266 } else if (type == Location.Type.LNG) { | |
1267 buf.append("long"); | |
1268 } else if (type == Location.Type.FLOAT_IN_DBL) { | |
1269 buf.append("float"); | |
1270 } else if (type == Location.Type.DBL) { | |
1271 buf.append("double"); | |
1272 } else if (type == Location.Type.ADDR) { | |
1273 buf.append("address"); | |
1274 } else if (type == Location.Type.INVALID) { | |
1275 buf.append("invalid"); | |
1276 } | |
1277 } | |
1278 return buf.toString(); | |
1279 } | |
1280 | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1281 private String scopeValueAsString(ScopeDesc sd, ScopeValue sv) { |
0 | 1282 Formatter buf = new Formatter(genHTML); |
1283 if (sv.isConstantInt()) { | |
1284 buf.append("int "); | |
1285 ConstantIntValue intValue = (ConstantIntValue) sv; | |
1286 buf.append(Integer.toString(intValue.getValue())); | |
1287 } else if (sv.isConstantLong()) { | |
1288 buf.append("long "); | |
1289 ConstantLongValue longValue = (ConstantLongValue) sv; | |
1290 buf.append(Long.toString(longValue.getValue())); | |
1291 buf.append("L"); | |
1292 } else if (sv.isConstantDouble()) { | |
1293 buf.append("double "); | |
1294 ConstantDoubleValue dblValue = (ConstantDoubleValue) sv; | |
1295 buf.append(Double.toString(dblValue.getValue())); | |
1296 buf.append("D"); | |
1297 } else if (sv.isConstantOop()) { | |
1298 buf.append("oop "); | |
1299 ConstantOopReadValue oopValue = (ConstantOopReadValue) sv; | |
1300 OopHandle oopHandle = oopValue.getValue(); | |
1301 if (oopHandle != null) { | |
1302 buf.append(oopHandle.toString()); | |
1303 } else { | |
1304 buf.append("null"); | |
1305 } | |
1306 } else if (sv.isLocation()) { | |
1307 LocationValue lvalue = (LocationValue) sv; | |
1308 Location loc = lvalue.getLocation(); | |
1309 if (loc != null) { | |
1310 buf.append(locationAsString(loc)); | |
1311 } else { | |
1312 buf.append("null"); | |
1313 } | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1314 } else if (sv.isObject()) { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1315 ObjectValue ov = (ObjectValue)sv; |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1316 buf.append("#ScObj" + sd.getObjects().indexOf(ov)); |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1317 } else { |
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1318 buf.append("unknown scope value " + sv); |
0 | 1319 } |
1320 return buf.toString(); | |
1321 } | |
1322 | |
1323 protected String genHTMLForScopeValues(ScopeDesc sd, boolean locals, List values) { | |
1324 int length = values.size(); | |
1325 Formatter buf = new Formatter(genHTML); | |
1326 buf.append(locals? "locals " : "expressions "); | |
1327 for (int i = 0; i < length; i++) { | |
1328 ScopeValue sv = (ScopeValue) values.get(i); | |
1329 if (sv == null) { | |
1330 continue; | |
1331 } | |
1332 buf.append('('); | |
1333 if (locals) { | |
1334 Symbol name = sd.getMethod().getLocalVariableName(sd.getBCI(), i); | |
1335 if (name != null) { | |
1336 buf.append("'"); | |
1337 buf.append(name.asString()); | |
1338 buf.append('\''); | |
1339 } else { | |
1340 buf.append("["); | |
1341 buf.append(Integer.toString(i)); | |
1342 buf.append(']'); | |
1343 } | |
1344 } else { | |
1345 buf.append("["); | |
1346 buf.append(Integer.toString(i)); | |
1347 buf.append(']'); | |
1348 } | |
1349 | |
1350 buf.append(", "); | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1351 buf.append(scopeValueAsString(sd, sv)); |
0 | 1352 buf.append(") "); |
1353 } | |
1354 | |
1355 return buf.toString(); | |
1356 } | |
1357 | |
1358 protected String genHTMLForLocals(ScopeDesc sd, List locals) { | |
1359 return genHTMLForScopeValues(sd, true, locals); | |
1360 } | |
1361 | |
1362 protected String genHTMLForExpressions(ScopeDesc sd, List expressions) { | |
1363 return genHTMLForScopeValues(sd, false, expressions); | |
1364 } | |
1365 | |
1366 protected String genHTMLForMonitors(ScopeDesc sd, List monitors) { | |
1367 int length = monitors.size(); | |
1368 Formatter buf = new Formatter(genHTML); | |
1369 buf.append("monitors "); | |
1370 for (int i = 0; i < length; i++) { | |
1371 MonitorValue mv = (MonitorValue) monitors.get(i); | |
1372 if (mv == null) { | |
1373 continue; | |
1374 } | |
1375 buf.append("(owner = "); | |
1376 ScopeValue owner = mv.owner(); | |
1377 if (owner != null) { | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1378 buf.append(scopeValueAsString(sd, owner)); |
0 | 1379 } else { |
1380 buf.append("null"); | |
1381 } | |
1382 buf.append(", lock = "); | |
1383 | |
1384 Location loc = mv.basicLock(); | |
1385 if (loc != null) { | |
1386 buf.append(locationAsString(loc)); | |
1387 } else { | |
1388 buf.append("null"); | |
1389 } | |
1390 buf.append(") "); | |
1391 } | |
1392 return buf.toString(); | |
1393 } | |
1394 | |
1395 public String genHTML(final NMethod nmethod) { | |
1396 try { | |
1397 final Formatter buf = new Formatter(genHTML); | |
1398 buf.genHTMLPrologue(genNMethodTitle(nmethod)); | |
1399 buf.h3("Method"); | |
1400 buf.append(genMethodAndKlassLink(nmethod.getMethod())); | |
1401 | |
1402 buf.h3("Compiled Code"); | |
1403 sun.jvm.hotspot.debugger.Address codeBegin = nmethod.codeBegin(); | |
1404 sun.jvm.hotspot.debugger.Address codeEnd = nmethod.codeEnd(); | |
1405 final int codeSize = (int)codeEnd.minus(codeBegin); | |
1406 final long startPc = addressToLong(codeBegin); | |
1407 final byte[] code = new byte[codeSize]; | |
1408 for (int i=0; i < code.length; i++) | |
1409 code[i] = codeBegin.getJByteAt(i); | |
1410 | |
1411 final long verifiedEntryPoint = addressToLong(nmethod.getVerifiedEntryPoint()); | |
1412 final long entryPoint = addressToLong(nmethod.getEntryPoint()); | |
1413 final Map safepoints = nmethod.getSafepoints(); | |
1414 | |
1415 final SymbolFinder symFinder = createSymbolFinder(); | |
1416 final Disassembler disasm = createDisassembler(startPc, code); | |
1417 class NMethodVisitor implements InstructionVisitor { | |
1418 public void prologue() { | |
1419 } | |
1420 | |
1421 public void visit(long currentPc, Instruction instr) { | |
1422 String href = null; | |
1423 if (instr.isCall()) { | |
1424 CallInstruction call = (CallInstruction) instr; | |
1425 sun.jvm.hotspot.asm.Address addr = call.getBranchDestination(); | |
1426 href = genPCHref(currentPc, addr); | |
1427 } | |
1428 | |
1429 if (currentPc == verifiedEntryPoint) { | |
1430 buf.bold("Verified Entry Point"); buf.br(); | |
1431 } | |
1432 if (currentPc == entryPoint) { | |
1433 buf.bold(">Entry Point"); buf.br(); | |
1434 } | |
1435 | |
1436 PCDesc pcDesc = (PCDesc) safepoints.get(longToAddress(currentPc)); | |
1437 | |
1385 | 1438 if (pcDesc != null) { |
0 | 1439 buf.append(genSafepointInfo(nmethod, pcDesc)); |
1440 } | |
1441 | |
1442 buf.append("0x"); | |
1443 buf.append(Long.toHexString(currentPc)); | |
1444 buf.append(':'); | |
1445 buf.append(tab); | |
1446 | |
1447 if (href != null) { | |
1448 buf.link(href, instr.asString(currentPc, symFinder)); | |
1449 } else { | |
1450 buf.append(instr.asString(currentPc, symFinder)); | |
1451 } | |
1452 | |
1040
873ec3787992
6892186: SA does not dump debug info for scalar replaced objects
kvn
parents:
331
diff
changeset
|
1453 buf.br(); |
0 | 1454 } |
1455 | |
1456 public void epilogue() { | |
1457 } | |
1458 }; | |
1459 | |
1460 disasm.decode(new NMethodVisitor()); | |
1461 | |
1462 sun.jvm.hotspot.debugger.Address stubBegin = nmethod.stubBegin(); | |
1463 if (stubBegin != null) { | |
1464 sun.jvm.hotspot.debugger.Address stubEnd = nmethod.stubEnd(); | |
1465 buf.h3("Stub"); | |
1466 long stubStartPc = addressToLong(stubBegin); | |
1467 long stubEndPc = addressToLong(stubEnd); | |
1468 int range = (int) (stubEndPc - stubStartPc); | |
1469 byte[] stubCode = readBuffer(stubBegin, range); | |
1470 Disassembler disasm2 = createDisassembler(stubStartPc, stubCode); | |
1471 disasm2.decode(new NMethodVisitor()); | |
1472 } | |
1473 buf.genHTMLEpilogue(); | |
1474 return buf.toString(); | |
1475 } catch (Exception exp) { | |
1476 return genHTMLErrorMessage(exp); | |
1477 } | |
1478 } | |
1479 | |
1480 public String genHTML(final CodeBlob blob) { | |
1481 try { | |
1482 final Formatter buf = new Formatter(genHTML); | |
1483 buf.genHTMLPrologue(genCodeBlobTitle(blob)); | |
1484 buf.h3("CodeBlob"); | |
1485 | |
1486 buf.h3("Compiled Code"); | |
1487 final sun.jvm.hotspot.debugger.Address codeBegin = blob.instructionsBegin(); | |
1488 final int codeSize = blob.getInstructionsSize(); | |
1489 final long startPc = addressToLong(codeBegin); | |
1490 final byte[] code = new byte[codeSize]; | |
1491 for (int i=0; i < code.length; i++) | |
1492 code[i] = codeBegin.getJByteAt(i); | |
1493 | |
1494 final SymbolFinder symFinder = createSymbolFinder(); | |
1495 final Disassembler disasm = createDisassembler(startPc, code); | |
1496 class CodeBlobVisitor implements InstructionVisitor { | |
1497 OopMapSet maps; | |
1498 OopMap curMap; | |
1499 int curMapIndex; | |
1500 long curMapOffset; | |
1501 public void prologue() { | |
1502 maps = blob.getOopMaps(); | |
1503 if (maps != null && (maps.getSize() > 0)) { | |
1504 curMap = maps.getMapAt(0); | |
1505 if (curMap != null) { | |
1506 curMapOffset = curMap.getOffset(); | |
1507 } | |
1508 } | |
1509 } | |
1510 | |
1511 public void visit(long currentPc, Instruction instr) { | |
1512 String href = null; | |
1513 if (instr.isCall()) { | |
1514 CallInstruction call = (CallInstruction) instr; | |
1515 sun.jvm.hotspot.asm.Address addr = call.getBranchDestination(); | |
1516 href = genPCHref(currentPc, addr); | |
1517 } | |
1518 | |
1519 buf.append("0x"); | |
1520 buf.append(Long.toHexString(currentPc)); | |
1521 buf.append(':'); | |
1522 buf.append(tab); | |
1523 | |
1524 if (href != null) { | |
1525 buf.link(href, instr.asString(currentPc, symFinder)); | |
1526 } else { | |
1527 buf.append(instr.asString(currentPc, symFinder)); | |
1528 } | |
1529 buf.br(); | |
1530 | |
1531 // See whether we have an oop map at this PC | |
1532 if (curMap != null) { | |
1533 long curOffset = currentPc - startPc; | |
1534 if (curOffset == curMapOffset) { | |
1535 buf.append(genOopMapInfo(curMap)); | |
1536 if (++curMapIndex >= maps.getSize()) { | |
1537 curMap = null; | |
1538 } else { | |
1539 curMap = maps.getMapAt(curMapIndex); | |
1540 if (curMap != null) { | |
1541 curMapOffset = curMap.getOffset(); | |
1542 } | |
1543 } | |
1544 } | |
1545 } | |
1546 } | |
1547 | |
1548 public void epilogue() { | |
1549 } | |
1550 }; | |
1551 | |
1552 disasm.decode(new CodeBlobVisitor()); | |
1553 | |
1554 buf.genHTMLEpilogue(); | |
1555 return buf.toString(); | |
1556 } catch (Exception exp) { | |
1557 return genHTMLErrorMessage(exp); | |
1558 } | |
1559 } | |
1560 | |
1561 protected String genInterpreterCodeletTitle(InterpreterCodelet codelet) { | |
1562 Formatter buf = new Formatter(genHTML); | |
1563 buf.append("Interpreter codelet ["); | |
1564 buf.append(codelet.codeBegin().toString()); | |
1565 buf.append(','); | |
1566 buf.append(codelet.codeEnd().toString()); | |
1567 buf.append(") - "); | |
1568 buf.append(codelet.getDescription()); | |
1569 return buf.toString(); | |
1570 } | |
1571 | |
1572 protected String genInterpreterCodeletLinkPageHref(StubQueue stubq) { | |
1573 return genBaseHref() + "interp_codelets"; | |
1574 } | |
1575 | |
1576 public String genInterpreterCodeletLinksPage() { | |
1577 Formatter buf = new Formatter(genHTML); | |
1578 buf.genHTMLPrologue("Interpreter Codelets"); | |
1579 buf.beginTag("ul"); | |
1580 | |
1581 Interpreter interp = VM.getVM().getInterpreter(); | |
1582 StubQueue code = interp.getCode(); | |
1583 InterpreterCodelet stub = (InterpreterCodelet) code.getFirst(); | |
1584 while (stub != null) { | |
1585 buf.beginTag("li"); | |
1586 sun.jvm.hotspot.debugger.Address addr = stub.codeBegin(); | |
1587 buf.link(genPCHref(addressToLong(addr)), stub.getDescription() + " @" + addr); | |
1588 buf.endTag("li"); | |
1589 stub = (InterpreterCodelet) code.getNext(stub); | |
1590 } | |
1591 | |
1592 buf.endTag("ul"); | |
1593 buf.genHTMLEpilogue(); | |
1594 return buf.toString(); | |
1595 } | |
1596 | |
1597 public String genHTML(InterpreterCodelet codelet) { | |
1598 Formatter buf = new Formatter(genHTML); | |
1599 buf.genHTMLPrologue(genInterpreterCodeletTitle(codelet)); | |
1600 Interpreter interp = VM.getVM().getInterpreter(); | |
1601 StubQueue stubq = interp.getCode(); | |
1602 | |
1603 if (genHTML) { | |
1604 buf.beginTag("h3"); | |
1605 buf.link(genInterpreterCodeletLinkPageHref(stubq), "View links for all codelets"); | |
1606 buf.endTag("h3"); | |
1607 buf.br(); | |
1608 } | |
1609 | |
1610 Stub prev = stubq.getPrev(codelet); | |
1611 if (prev != null) { | |
1612 if (genHTML) { | |
1613 buf.beginTag("h3"); | |
1614 buf.link(genPCHref(addressToLong(prev.codeBegin())), "View Previous Codelet"); | |
1615 buf.endTag("h3"); | |
1616 buf.br(); | |
1617 } else { | |
1618 buf.h3("Previous Codelet = 0x" + Long.toHexString(addressToLong(prev.codeBegin()))); | |
1619 } | |
1620 } | |
1621 | |
1622 buf.h3("Code"); | |
1623 long stubStartPc = addressToLong(codelet.codeBegin()); | |
1624 long stubEndPc = addressToLong(codelet.codeEnd()); | |
1625 int range = (int) (stubEndPc - stubStartPc); | |
1626 byte[] stubCode = readBuffer(codelet.codeBegin(), range); | |
1627 Disassembler disasm = createDisassembler(stubStartPc, stubCode); | |
1628 disasm.decode(new RawCodeVisitor(buf)); | |
1629 | |
1630 | |
1631 Stub next = stubq.getNext(codelet); | |
1632 if (next != null) { | |
1633 if (genHTML) { | |
1634 buf.beginTag("h3"); | |
1635 buf.link(genPCHref(addressToLong(next.codeBegin())), "View Next Codelet"); | |
1636 buf.endTag("h3"); | |
1637 } else { | |
1638 buf.h3("Next Codelet = 0x" + Long.toHexString(addressToLong(next.codeBegin()))); | |
1639 } | |
1640 } | |
1641 | |
1642 buf.genHTMLEpilogue(); | |
1643 return buf.toString(); | |
1644 } | |
1645 | |
1646 protected String genDumpKlassesTitle(InstanceKlass[] klasses) { | |
1647 return (klasses.length == 1) ? "Create .class for this class" | |
1648 : "Create .class for all classes"; | |
1649 } | |
1650 | |
1651 protected String genDumpKlassesHref(InstanceKlass[] klasses) { | |
1652 StringBuffer buf = new StringBuffer(genBaseHref()); | |
1653 buf.append("jcore_multiple="); | |
1654 for (int k = 0; k < klasses.length; k++) { | |
1655 buf.append(klasses[k].getHandle().toString()); | |
1656 buf.append(','); | |
1657 } | |
1658 return buf.toString(); | |
1659 } | |
1660 | |
1661 protected String genDumpKlassesLink(InstanceKlass[] klasses) { | |
1662 if (!genHTML) return ""; | |
1663 | |
1664 Formatter buf = new Formatter(genHTML); | |
1665 buf.link(genDumpKlassesHref(klasses), genDumpKlassesTitle(klasses)); | |
1666 return buf.toString(); | |
1667 } | |
1668 | |
1669 public String genHTMLForKlassNames(InstanceKlass[] klasses) { | |
1670 try { | |
1671 Formatter buf = new Formatter(genHTML); | |
1672 buf.genHTMLPrologue(); | |
1673 buf.h3(genDumpKlassesLink(klasses)); | |
1674 | |
1675 buf.append(genHTMLListForKlassNames(klasses)); | |
1676 buf.genHTMLEpilogue(); | |
1677 return buf.toString(); | |
1678 } catch (Exception exp) { | |
1679 return genHTMLErrorMessage(exp); | |
1680 } | |
1681 } | |
1682 | |
1683 protected String genHTMLListForKlassNames(InstanceKlass[] klasses) { | |
1684 final Formatter buf = new Formatter(genHTML); | |
1685 buf.beginTable(0); | |
1686 for (int i = 0; i < klasses.length; i++) { | |
1687 InstanceKlass ik = klasses[i]; | |
1688 buf.beginTag("tr"); | |
1689 buf.cell(genKlassLink(ik)); | |
1690 buf.endTag("tr"); | |
1691 } | |
1692 | |
1693 buf.endTable(); | |
1694 return buf.toString(); | |
1695 } | |
1696 | |
1697 public String genHTMLForMethodNames(InstanceKlass klass) { | |
1698 try { | |
1699 Formatter buf = new Formatter(genHTML); | |
1700 buf.genHTMLPrologue(); | |
1701 buf.append(genHTMLListForMethods(klass)); | |
1702 buf.genHTMLEpilogue(); | |
1703 return buf.toString(); | |
1704 } catch (Exception exp) { | |
1705 return genHTMLErrorMessage(exp); | |
1706 } | |
1707 } | |
1708 | |
1709 protected String genHTMLListForMethods(InstanceKlass klass) { | |
1710 Formatter buf = new Formatter(genHTML); | |
1711 ObjArray methods = klass.getMethods(); | |
1712 int numMethods = (int) methods.getLength(); | |
1713 if (numMethods != 0) { | |
1714 buf.h3("Methods"); | |
1715 buf.beginTag("ul"); | |
1716 for (int m = 0; m < numMethods; m++) { | |
1717 Method mtd = (Method) methods.getObjAt(m); | |
1718 buf.li(genMethodLink(mtd) + ";"); | |
1719 } | |
1720 buf.endTag("ul"); | |
1721 } | |
1722 return buf.toString(); | |
1723 } | |
1724 | |
1725 protected String genHTMLListForInterfaces(InstanceKlass klass) { | |
1726 try { | |
1727 Formatter buf = new Formatter(genHTML); | |
1728 ObjArray interfaces = klass.getLocalInterfaces(); | |
1729 int numInterfaces = (int) interfaces.getLength(); | |
1730 if (numInterfaces != 0) { | |
1731 buf.h3("Interfaces"); | |
1732 buf.beginTag("ul"); | |
1733 for (int i = 0; i < numInterfaces; i++) { | |
1734 InstanceKlass inf = (InstanceKlass) interfaces.getObjAt(i); | |
1735 buf.li(genKlassLink(inf)); | |
1736 } | |
1737 buf.endTag("ul"); | |
1738 } | |
1739 return buf.toString(); | |
1740 } catch (Exception exp) { | |
1741 return genHTMLErrorMessage(exp); | |
1742 } | |
1743 } | |
1744 | |
1745 protected String genFieldModifierString(AccessFlags acc) { | |
1746 Formatter buf = new Formatter(genHTML); | |
1747 if (acc.isPrivate()) { | |
1748 buf.append("private "); | |
1749 } else if (acc.isProtected()) { | |
1750 buf.append("protected "); | |
1751 } else if (acc.isPublic()) { | |
1752 buf.append("public "); | |
1753 } | |
1754 | |
1755 if (acc.isStatic()) { | |
1756 buf.append("static "); | |
1757 } | |
1758 | |
1759 if (acc.isFinal()) { | |
1760 buf.append("final "); | |
1761 } | |
1762 if (acc.isVolatile()) { | |
1763 buf.append("volatile "); | |
1764 } | |
1765 if (acc.isTransient()) { | |
1766 buf.append("transient "); | |
1767 } | |
1768 | |
1769 // javac generated flags | |
1770 if (acc.isSynthetic()) { | |
1771 buf.append("[synthetic] "); | |
1772 } | |
1773 return buf.toString(); | |
1774 } | |
1775 | |
1776 public String genHTMLForFieldNames(InstanceKlass klass) { | |
1777 try { | |
1778 Formatter buf = new Formatter(genHTML); | |
1779 buf.genHTMLPrologue(); | |
1780 buf.append(genHTMLListForFields(klass)); | |
1781 buf.genHTMLEpilogue(); | |
1782 return buf.toString(); | |
1783 } catch (Exception exp) { | |
1784 return genHTMLErrorMessage(exp); | |
1785 } | |
1786 } | |
1787 | |
1788 protected String genHTMLListForFields(InstanceKlass klass) { | |
1789 Formatter buf = new Formatter(genHTML); | |
1790 TypeArray fields = klass.getFields(); | |
1791 int numFields = (int) fields.getLength(); | |
1792 ConstantPool cp = klass.getConstants(); | |
1793 if (numFields != 0) { | |
1794 buf.h3("Fields"); | |
1795 buf.beginList(); | |
1796 for (int f = 0; f < numFields; f += InstanceKlass.NEXT_OFFSET) { | |
1385 | 1797 sun.jvm.hotspot.oops.Field field = klass.getFieldByIndex(f); |
1798 String f_name = ((NamedFieldIdentifier)field.getID()).getName(); | |
1799 Symbol f_sig = field.getSignature(); | |
1800 Symbol f_genSig = field.getGenericSignature(); | |
1801 AccessFlags acc = field.getAccessFlagsObj(); | |
0 | 1802 |
1385 | 1803 buf.beginListItem(); |
0 | 1804 buf.append(genFieldModifierString(acc)); |
1805 buf.append(' '); | |
1806 Formatter sigBuf = new Formatter(genHTML); | |
1807 new SignatureConverter(f_sig, sigBuf.getBuffer()).dispatchField(); | |
1808 buf.append(sigBuf.toString().replace('/', '.')); | |
1809 buf.append(' '); | |
1385 | 1810 buf.append(f_name); |
0 | 1811 buf.append(';'); |
1812 // is it generic? | |
1813 if (f_genSig != null) { | |
1814 buf.append(" [signature "); | |
1815 buf.append(escapeHTMLSpecialChars(f_genSig.asString())); | |
1816 buf.append("] "); | |
1817 } | |
1385 | 1818 buf.append(" (offset = " + field.getOffset() + ")"); |
1819 buf.endListItem(); | |
0 | 1820 } |
1821 buf.endList(); | |
1822 } | |
1823 return buf.toString(); | |
1824 } | |
1825 | |
1826 protected String genKlassHierarchyHref(InstanceKlass klass) { | |
1827 return genBaseHref() + "hierarchy=" + klass.getHandle(); | |
1828 } | |
1829 | |
1830 protected String genKlassHierarchyTitle(InstanceKlass klass) { | |
1831 Formatter buf = new Formatter(genHTML); | |
1832 buf.append("Class Hierarchy of "); | |
1833 buf.append(genKlassTitle(klass)); | |
1834 return buf.toString(); | |
1835 } | |
1836 | |
1837 protected String genKlassHierarchyLink(InstanceKlass klass) { | |
1838 Formatter buf = new Formatter(genHTML); | |
1839 buf.link(genKlassHierarchyHref(klass), genKlassHierarchyTitle(klass)); | |
1840 return buf.toString(); | |
1841 } | |
1842 | |
1843 protected String genHTMLListForSubKlasses(InstanceKlass klass) { | |
1844 Formatter buf = new Formatter(genHTML); | |
1845 Klass subklass = klass.getSubklassKlass(); | |
1846 if (subklass != null) { | |
1847 buf.beginList(); | |
1848 while (subklass != null) { | |
1849 if (subklass instanceof InstanceKlass) { | |
1850 buf.li(genKlassLink((InstanceKlass)subklass)); | |
1851 } | |
1852 subklass = subklass.getNextSiblingKlass(); | |
1853 } | |
1854 buf.endList(); | |
1855 } | |
1856 return buf.toString(); | |
1857 } | |
1858 | |
1859 public String genHTMLForKlassHierarchy(InstanceKlass klass) { | |
1860 Formatter buf = new Formatter(genHTML); | |
1861 buf.genHTMLPrologue(genKlassHierarchyTitle(klass)); | |
1862 | |
1863 | |
1864 buf.beginTag("pre"); | |
1865 buf.append(genKlassLink(klass)); | |
1866 buf.br(); | |
1867 StringBuffer tabs = new StringBuffer(tab); | |
1868 InstanceKlass superKlass = klass; | |
1869 while ( (superKlass = (InstanceKlass) superKlass.getSuper()) != null ) { | |
1870 buf.append(tabs); | |
1871 buf.append(genKlassLink(superKlass)); | |
1872 tabs.append(tab); | |
1873 buf.br(); | |
1874 } | |
1875 buf.endTag("pre"); | |
1876 | |
1877 // generate subklass list | |
1878 Klass subklass = klass.getSubklassKlass(); | |
1879 if (subklass != null) { | |
1880 buf.h3("Direct Subclasses"); | |
1881 buf.append(genHTMLListForSubKlasses(klass)); | |
1882 } | |
1883 | |
1884 buf.genHTMLEpilogue(); | |
1885 return buf.toString(); | |
1886 } | |
1887 | |
1888 protected String genDumpKlassHref(InstanceKlass klass) { | |
1889 return genBaseHref() + "jcore=" + klass.getHandle(); | |
1890 } | |
1891 | |
1892 protected String genDumpKlassLink(InstanceKlass klass) { | |
1893 if (!genHTML) return ""; | |
1894 | |
1895 Formatter buf = new Formatter(genHTML); | |
1896 buf.link(genDumpKlassHref(klass), "Create .class File"); | |
1897 return buf.toString(); | |
1898 } | |
1899 | |
1900 public String genHTML(InstanceKlass klass) { | |
1901 Formatter buf = new Formatter(genHTML); | |
1902 buf.genHTMLPrologue(genKlassTitle(klass)); | |
1903 InstanceKlass superKlass = (InstanceKlass) klass.getSuper(); | |
1904 | |
1905 if (genHTML) { | |
1906 // super class tree and subclass list | |
1907 buf.beginTag("h3"); | |
1908 buf.link(genKlassHierarchyHref(klass), "View Class Hierarchy"); | |
1909 buf.endTag("h3"); | |
1910 } | |
1911 | |
1912 // jcore - create .class link | |
1913 buf.h3(genDumpKlassLink(klass)); | |
1914 | |
1915 // super class | |
1916 if (superKlass != null) { | |
1917 buf.h3("Super Class"); | |
1918 buf.append(genKlassLink(superKlass)); | |
1919 } | |
1920 | |
1921 // interfaces | |
1922 buf.append(genHTMLListForInterfaces(klass)); | |
1923 | |
1924 // fields | |
1925 buf.append(genHTMLListForFields(klass)); | |
1926 | |
1927 // methods | |
1928 buf.append(genHTMLListForMethods(klass)); | |
1929 | |
1930 // constant pool link | |
1931 buf.h3("Constant Pool"); | |
1932 buf.append(genConstantPoolLink(klass.getConstants())); | |
1933 | |
1934 buf.genHTMLEpilogue(); | |
1935 return buf.toString(); | |
1936 } | |
1937 | |
1938 protected sun.jvm.hotspot.debugger.Address parseAddress(String address) { | |
1939 VM vm = VM.getVM(); | |
1940 sun.jvm.hotspot.debugger.Address addr = vm.getDebugger().parseAddress(address); | |
1941 return addr; | |
1942 } | |
1943 | |
1944 protected long addressToLong(sun.jvm.hotspot.debugger.Address addr) { | |
1945 return VM.getVM().getDebugger().getAddressValue(addr); | |
1946 } | |
1947 | |
1948 protected sun.jvm.hotspot.debugger.Address longToAddress(long addr) { | |
1949 return parseAddress("0x" + Long.toHexString(addr)); | |
1950 } | |
1951 | |
1952 protected Oop getOopAtAddress(sun.jvm.hotspot.debugger.Address addr) { | |
1953 OopHandle oopHandle = addr.addOffsetToAsOopHandle(0); | |
1954 return VM.getVM().getObjectHeap().newOop(oopHandle); | |
1955 } | |
1956 | |
1957 protected Oop getOopAtAddress(String address) { | |
1958 sun.jvm.hotspot.debugger.Address addr = parseAddress(address); | |
1959 return getOopAtAddress(addr); | |
1960 } | |
1961 | |
1962 private void dumpKlass(InstanceKlass kls) throws IOException { | |
1963 String klassName = kls.getName().asString(); | |
1964 klassName = klassName.replace('/', File.separatorChar); | |
1965 int index = klassName.lastIndexOf(File.separatorChar); | |
1966 File dir = null; | |
1967 if (index != -1) { | |
1968 String dirName = klassName.substring(0, index); | |
1969 dir = new File(DUMP_KLASS_OUTPUT_DIR, dirName); | |
1970 } else { | |
1971 dir = new File(DUMP_KLASS_OUTPUT_DIR); | |
1972 } | |
1973 | |
1974 dir.mkdirs(); | |
1975 File f = new File(dir, klassName.substring(klassName.lastIndexOf(File.separatorChar) + 1) | |
1976 + ".class"); | |
1977 f.createNewFile(); | |
1978 FileOutputStream fis = new FileOutputStream(f); | |
1979 ClassWriter cw = new ClassWriter(kls, fis); | |
1980 cw.write(); | |
1981 } | |
1982 | |
1983 public String genDumpKlass(InstanceKlass kls) { | |
1984 try { | |
1985 dumpKlass(kls); | |
1986 Formatter buf = new Formatter(genHTML); | |
1987 buf.genHTMLPrologue(genKlassTitle(kls)); | |
1988 buf.append(".class created for "); | |
1989 buf.append(genKlassLink(kls)); | |
1990 buf.genHTMLEpilogue(); | |
1991 return buf.toString(); | |
1992 } catch(IOException exp) { | |
1993 return genHTMLErrorMessage(exp); | |
1994 } | |
1995 } | |
1996 | |
1997 protected String genJavaStackTraceTitle(JavaThread thread) { | |
1998 Formatter buf = new Formatter(genHTML); | |
1999 buf.append("Java Stack Trace for "); | |
2000 buf.append(thread.getThreadName()); | |
2001 return buf.toString(); | |
2002 } | |
2003 | |
2004 public String genHTMLForJavaStackTrace(JavaThread thread) { | |
2005 Formatter buf = new Formatter(genHTML); | |
2006 buf.genHTMLPrologue(genJavaStackTraceTitle(thread)); | |
2007 | |
2008 buf.append("Thread state = "); | |
2009 buf.append(thread.getThreadState().toString()); | |
2010 buf.br(); | |
2011 buf.beginTag("pre"); | |
2012 for (JavaVFrame vf = thread.getLastJavaVFrameDbg(); vf != null; vf = vf.javaSender()) { | |
2013 Method method = vf.getMethod(); | |
2014 buf.append(" - "); | |
2015 buf.append(genMethodLink(method)); | |
2016 buf.append(" @bci = " + vf.getBCI()); | |
2017 | |
2018 int lineNumber = method.getLineNumberFromBCI(vf.getBCI()); | |
2019 if (lineNumber != -1) { | |
2020 buf.append(", line = "); | |
2021 buf.append(lineNumber); | |
2022 } | |
2023 | |
2024 sun.jvm.hotspot.debugger.Address pc = vf.getFrame().getPC(); | |
2025 if (pc != null) { | |
2026 buf.append(", pc = "); | |
2027 buf.link(genPCHref(addressToLong(pc)), pc.toString()); | |
2028 } | |
2029 | |
2030 if (vf.isCompiledFrame()) { | |
2031 buf.append(" (Compiled"); | |
2032 } | |
2033 else if (vf.isInterpretedFrame()) { | |
2034 buf.append(" (Interpreted"); | |
2035 } | |
2036 | |
2037 if (vf.mayBeImpreciseDbg()) { | |
2038 buf.append("; information may be imprecise"); | |
2039 } | |
2040 buf.append(")"); | |
2041 buf.br(); | |
2042 } | |
2043 | |
2044 buf.endTag("pre"); | |
2045 buf.genHTMLEpilogue(); | |
2046 return buf.toString(); | |
2047 } | |
2048 | |
2049 public String genHTMLForHyperlink(String href) { | |
2050 if (href.startsWith("klass=")) { | |
2051 href = href.substring(href.indexOf('=') + 1); | |
2052 Oop obj = getOopAtAddress(href); | |
2053 if (Assert.ASSERTS_ENABLED) { | |
2054 Assert.that(obj instanceof InstanceKlass, "class= href with improper InstanceKlass!"); | |
2055 } | |
2056 return genHTML((InstanceKlass) obj); | |
2057 } else if (href.startsWith("method=")) { | |
2058 href = href.substring(href.indexOf('=') + 1); | |
2059 Oop obj = getOopAtAddress(href); | |
2060 if (Assert.ASSERTS_ENABLED) { | |
2061 Assert.that(obj instanceof Method, "method= href with improper Method!"); | |
2062 } | |
2063 return genHTML((Method) obj); | |
2064 } else if (href.startsWith("nmethod=")) { | |
2065 String addr = href.substring(href.indexOf('=') + 1); | |
2066 Object obj = VMObjectFactory.newObject(NMethod.class, parseAddress(addr)); | |
2067 if (Assert.ASSERTS_ENABLED) { | |
2068 Assert.that(obj instanceof NMethod, "nmethod= href with improper NMethod!"); | |
2069 } | |
2070 return genHTML((NMethod) obj); | |
2071 } else if (href.startsWith("pc=")) { | |
2072 String address = href.substring(href.indexOf('=') + 1); | |
2073 return genHTML(parseAddress(address)); | |
2074 } else if (href.startsWith("pc_multiple=")) { | |
2075 int indexOfComma = href.indexOf(','); | |
2076 if (indexOfComma == -1) { | |
2077 String firstPC = href.substring(href.indexOf('=') + 1); | |
2078 return genHTMLForRawDisassembly(parseAddress(firstPC), null); | |
2079 } else { | |
2080 String firstPC = href.substring(href.indexOf('=') + 1, indexOfComma); | |
2081 return genHTMLForRawDisassembly(parseAddress(firstPC), href.substring(indexOfComma + 1)); | |
2082 } | |
2083 } else if (href.startsWith("interp_codelets")) { | |
2084 return genInterpreterCodeletLinksPage(); | |
2085 } else if (href.startsWith("hierarchy=")) { | |
2086 href = href.substring(href.indexOf('=') + 1); | |
2087 Oop obj = getOopAtAddress(href); | |
2088 if (Assert.ASSERTS_ENABLED) { | |
2089 Assert.that(obj instanceof InstanceKlass, "class= href with improper InstanceKlass!"); | |
2090 } | |
2091 return genHTMLForKlassHierarchy((InstanceKlass) obj); | |
2092 } else if (href.startsWith("cpool=")) { | |
2093 href = href.substring(href.indexOf('=') + 1); | |
2094 Oop obj = getOopAtAddress(href); | |
2095 if (Assert.ASSERTS_ENABLED) { | |
2096 Assert.that(obj instanceof ConstantPool, "cpool= href with improper ConstantPool!"); | |
2097 } | |
2098 return genHTML((ConstantPool) obj); | |
2099 } else if (href.startsWith("jcore=")) { | |
2100 href = href.substring(href.indexOf('=') + 1); | |
2101 Oop obj = getOopAtAddress(href); | |
2102 if (Assert.ASSERTS_ENABLED) { | |
2103 Assert.that(obj instanceof InstanceKlass, "jcore= href with improper InstanceKlass!"); | |
2104 } | |
2105 return genDumpKlass((InstanceKlass) obj); | |
2106 } else if (href.startsWith("jcore_multiple=")) { | |
2107 href = href.substring(href.indexOf('=') + 1); | |
2108 Formatter buf = new Formatter(genHTML); | |
2109 buf.genHTMLPrologue(); | |
2110 StringTokenizer st = new StringTokenizer(href, ","); | |
2111 while (st.hasMoreTokens()) { | |
2112 Oop obj = getOopAtAddress(st.nextToken()); | |
2113 if (Assert.ASSERTS_ENABLED) { | |
2114 Assert.that(obj instanceof InstanceKlass, "jcore_multiple= href with improper InstanceKlass!"); | |
2115 } | |
2116 | |
2117 InstanceKlass kls = (InstanceKlass) obj; | |
2118 try { | |
2119 dumpKlass(kls); | |
2120 buf.append(".class created for "); | |
2121 buf.append(genKlassLink(kls)); | |
2122 } catch(Exception exp) { | |
2123 buf.bold("can't .class for " + | |
2124 genKlassTitle(kls) + | |
2125 " : " + | |
2126 exp.getMessage()); | |
2127 } | |
2128 buf.br(); | |
2129 } | |
2130 | |
2131 buf.genHTMLEpilogue(); | |
2132 return buf.toString(); | |
2133 } else { | |
2134 if (Assert.ASSERTS_ENABLED) { | |
2135 Assert.that(false, "unknown href link!"); | |
2136 } | |
2137 return null; | |
2138 } | |
2139 } | |
2140 } |