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