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