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