Print this page
rev 1083 : [mq]: indy.compiler.inline.patch
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/interpreter/bytecodeTracer.cpp
+++ new/src/share/vm/interpreter/bytecodeTracer.cpp
1 1 /*
2 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 21 * have any questions.
22 22 *
23 23 */
24 24
25 25 #include "incls/_precompiled.incl"
26 26 #include "incls/_bytecodeTracer.cpp.incl"
27 27
28 28
29 29 #ifndef PRODUCT
30 30
31 31 // Standard closure for BytecodeTracer: prints the current bytecode
32 32 // and its attributes using bytecode-specific information.
33 33
34 34 class BytecodePrinter: public BytecodeClosure {
35 35 private:
36 36 // %%% This field is not GC-ed, and so can contain garbage
37 37 // between critical sections. Use only pointer-comparison
38 38 // operations on the pointer, except within a critical section.
39 39 // (Also, ensure that occasional false positives are benign.)
40 40 methodOop _current_method;
41 41 bool _is_wide;
42 42 address _next_pc; // current decoding position
43 43
44 44 void align() { _next_pc = (address)round_to((intptr_t)_next_pc, sizeof(jint)); }
45 45 int get_byte() { return *(jbyte*) _next_pc++; } // signed
46 46 short get_short() { short i=Bytes::get_Java_u2(_next_pc); _next_pc+=2; return i; }
47 47 int get_int() { int i=Bytes::get_Java_u4(_next_pc); _next_pc+=4; return i; }
48 48
49 49 int get_index() { return *(address)_next_pc++; }
50 50 int get_big_index() { int i=Bytes::get_Java_u2(_next_pc); _next_pc+=2; return i; }
51 51 int get_giant_index() { int i=Bytes::get_native_u4(_next_pc); _next_pc+=4; return i; }
52 52 int get_index_special() { return (is_wide()) ? get_big_index() : get_index(); }
53 53 methodOop method() { return _current_method; }
54 54 bool is_wide() { return _is_wide; }
55 55
56 56
57 57 bool check_index(int i, bool in_cp_cache, int& cp_index, outputStream* st = tty);
58 58 void print_constant(int i, outputStream* st = tty);
59 59 void print_field_or_method(int i, outputStream* st = tty);
60 60 void print_attributes(Bytecodes::Code code, int bci, outputStream* st = tty);
61 61 void bytecode_epilog(int bci, outputStream* st = tty);
62 62
63 63 public:
64 64 BytecodePrinter() {
65 65 _is_wide = false;
66 66 }
67 67
68 68 // This method is called while executing the raw bytecodes, so none of
69 69 // the adjustments that BytecodeStream performs applies.
70 70 void trace(methodHandle method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) {
71 71 ResourceMark rm;
72 72 if (_current_method != method()) {
73 73 // Note 1: This code will not work as expected with true MT/MP.
74 74 // Need an explicit lock or a different solution.
75 75 // It is possible for this block to be skipped, if a garbage
76 76 // _current_method pointer happens to have the same bits as
77 77 // the incoming method. We could lose a line of trace output.
78 78 // This is acceptable in a debug-only feature.
79 79 st->cr();
80 80 st->print("[%d] ", (int) Thread::current()->osthread()->thread_id());
81 81 method->print_name(st);
82 82 st->cr();
83 83 _current_method = method();
84 84 }
85 85 Bytecodes::Code code;
86 86 if (is_wide()) {
87 87 // bcp wasn't advanced if previous bytecode was _wide.
88 88 code = Bytecodes::code_at(bcp+1);
89 89 } else {
90 90 code = Bytecodes::code_at(bcp);
91 91 }
92 92 int bci = bcp - method->code_base();
93 93 st->print("[%d] ", (int) Thread::current()->osthread()->thread_id());
94 94 if (Verbose) {
95 95 st->print("%8d %4d " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
96 96 BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
97 97 } else {
98 98 st->print("%8d %4d %s",
99 99 BytecodeCounter::counter_value(), bci, Bytecodes::name(code));
100 100 }
101 101 _next_pc = is_wide() ? bcp+2 : bcp+1;
102 102 print_attributes(code, bci);
103 103 // Set is_wide for the next one, since the caller of this doesn't skip
104 104 // the next bytecode.
105 105 _is_wide = (code == Bytecodes::_wide);
106 106 }
107 107
108 108 // Used for methodOop::print_codes(). The input bcp comes from
109 109 // BytecodeStream, which will skip wide bytecodes.
110 110 void trace(methodHandle method, address bcp, outputStream* st) {
111 111 _current_method = method();
112 112 ResourceMark rm;
113 113 Bytecodes::Code code = Bytecodes::code_at(bcp);
114 114 // Set is_wide
115 115 _is_wide = (code == Bytecodes::_wide);
116 116 if (is_wide()) {
117 117 code = Bytecodes::code_at(bcp+1);
118 118 }
119 119 int bci = bcp - method->code_base();
120 120 // Print bytecode index and name
121 121 if (is_wide()) {
122 122 st->print("%d %s_w", bci, Bytecodes::name(code));
123 123 } else {
124 124 st->print("%d %s", bci, Bytecodes::name(code));
125 125 }
126 126 _next_pc = is_wide() ? bcp+2 : bcp+1;
127 127 print_attributes(code, bci, st);
128 128 bytecode_epilog(bci, st);
129 129 }
130 130 };
131 131
132 132
133 133 // Implementation of BytecodeTracer
134 134
135 135 // %%% This set_closure thing seems overly general, given that
136 136 // nobody uses it. Also, if BytecodePrinter weren't hidden
137 137 // then methodOop could use instances of it directly and it
138 138 // would be easier to remove races on _current_method and bcp.
139 139 // Since this is not product functionality, we can defer cleanup.
140 140
141 141 BytecodeClosure* BytecodeTracer::_closure = NULL;
142 142
143 143 static BytecodePrinter std_closure;
144 144 BytecodeClosure* BytecodeTracer::std_closure() {
145 145 return &::std_closure;
146 146 }
147 147
148 148
149 149 void BytecodeTracer::trace(methodHandle method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) {
150 150 if (TraceBytecodes && BytecodeCounter::counter_value() >= TraceBytecodesAt) {
151 151 ttyLocker ttyl; // 5065316: keep the following output coherent
152 152 // The ttyLocker also prevents races between two threads
153 153 // trying to use the single instance of BytecodePrinter.
154 154 // Using the ttyLocker prevents the system from coming to
155 155 // a safepoint within this code, which is sensitive to methodOop
156 156 // movement.
157 157 //
158 158 // There used to be a leaf mutex here, but the ttyLocker will
159 159 // work just as well, as long as the printing operations never block.
160 160 //
161 161 // We put the locker on the static trace method, not the
162 162 // virtual one, because the clients of this module go through
163 163 // the static method.
164 164 _closure->trace(method, bcp, tos, tos2, st);
165 165 }
166 166 }
167 167
168 168 void BytecodeTracer::trace(methodHandle method, address bcp, outputStream* st) {
169 169 ttyLocker ttyl; // 5065316: keep the following output coherent
170 170 _closure->trace(method, bcp, st);
171 171 }
172 172
173 173 void print_oop(oop value, outputStream* st) {
174 174 if (value == NULL) {
175 175 st->print_cr(" NULL");
176 176 } else {
177 177 EXCEPTION_MARK;
178 178 Handle h_value (THREAD, value);
179 179 symbolHandle sym = java_lang_String::as_symbol(h_value, CATCH);
180 180 if (sym->utf8_length() > 32) {
181 181 st->print_cr(" ....");
182 182 } else {
183 183 sym->print_on(st); st->cr();
184 184 }
185 185 }
186 186 }
187 187
188 188 bool BytecodePrinter::check_index(int i, bool in_cp_cache, int& cp_index, outputStream* st) {
189 189 constantPoolOop constants = method()->constants();
190 190 int ilimit = constants->length(), climit = 0;
191 191
192 192 constantPoolCacheOop cache = NULL;
193 193 if (in_cp_cache) {
194 194 cache = constants->cache();
195 195 if (cache != NULL) {
196 196 //climit = cache->length(); // %%% private!
197 197 size_t size = cache->size() * HeapWordSize;
198 198 size -= sizeof(constantPoolCacheOopDesc);
199 199 size /= sizeof(ConstantPoolCacheEntry);
200 200 climit = (int) size;
201 201 }
202 202 }
203 203
204 204 if (in_cp_cache && constantPoolCacheOopDesc::is_secondary_index(i)) {
205 205 i = constantPoolCacheOopDesc::decode_secondary_index(i);
206 206 st->print(" secondary cache[%d] of", i);
207 207 if (i >= 0 && i < climit) {
208 208 if (!cache->entry_at(i)->is_secondary_entry()) {
209 209 st->print_cr(" not secondary entry?", i);
210 210 return false;
211 211 }
212 212 i = cache->entry_at(i)->main_entry_index();
213 213 goto check_cache_index;
214 214 } else {
215 215 st->print_cr(" not in cache[*]?", i);
216 216 return false;
217 217 }
218 218 }
219 219
220 220 if (cache != NULL) {
221 221 i = Bytes::swap_u2(i);
222 222 if (WizardMode) st->print(" (swap=%d)", i);
223 223 goto check_cache_index;
224 224 }
225 225
226 226 check_cp_index:
227 227 if (i >= 0 && i < ilimit) {
228 228 if (WizardMode) st->print(" cp[%d]", i);
229 229 cp_index = i;
230 230 return true;
231 231 }
232 232
233 233 st->print_cr(" CP[%d] not in CP", i);
234 234 return false;
235 235
236 236 check_cache_index:
237 237 if (i >= 0 && i < climit) {
238 238 if (cache->entry_at(i)->is_secondary_entry()) {
239 239 st->print_cr(" secondary entry?");
240 240 return false;
241 241 }
242 242 i = cache->entry_at(i)->constant_pool_index();
243 243 goto check_cp_index;
244 244 }
245 245 st->print_cr(" not in CP[*]?", i);
246 246 return false;
247 247 }
248 248
249 249 void BytecodePrinter::print_constant(int i, outputStream* st) {
250 250 int orig_i = i;
251 251 if (!check_index(orig_i, false, i, st)) return;
252 252
253 253 constantPoolOop constants = method()->constants();
254 254 constantTag tag = constants->tag_at(i);
255 255
256 256 if (tag.is_int()) {
257 257 st->print_cr(" " INT32_FORMAT, constants->int_at(i));
258 258 } else if (tag.is_long()) {
259 259 st->print_cr(" " INT64_FORMAT, constants->long_at(i));
260 260 } else if (tag.is_float()) {
261 261 st->print_cr(" %f", constants->float_at(i));
262 262 } else if (tag.is_double()) {
↓ open down ↓ |
262 lines elided |
↑ open up ↑ |
263 263 st->print_cr(" %f", constants->double_at(i));
264 264 } else if (tag.is_string()) {
265 265 oop string = constants->resolved_string_at(i);
266 266 print_oop(string, st);
267 267 } else if (tag.is_unresolved_string()) {
268 268 st->print_cr(" <unresolved string at %d>", i);
269 269 } else if (tag.is_klass()) {
270 270 st->print_cr(" %s", constants->resolved_klass_at(i)->klass_part()->external_name());
271 271 } else if (tag.is_unresolved_klass()) {
272 272 st->print_cr(" <unresolved klass at %d>", i);
273 + } else if (tag.is_object()) {
274 + st->print_cr(" " PTR_FORMAT, constants->object_at(i));
273 275 } else {
274 276 st->print_cr(" bad tag=%d at %d", tag.value(), i);
275 277 }
276 278 }
277 279
278 280 void BytecodePrinter::print_field_or_method(int i, outputStream* st) {
279 281 int orig_i = i;
280 282 if (!check_index(orig_i, true, i, st)) return;
281 283
282 284 constantPoolOop constants = method()->constants();
283 285 constantTag tag = constants->tag_at(i);
284 286
285 287 int nt_index = -1;
286 288
287 289 switch (tag.value()) {
288 290 case JVM_CONSTANT_InterfaceMethodref:
289 291 case JVM_CONSTANT_Methodref:
290 292 case JVM_CONSTANT_Fieldref:
291 293 case JVM_CONSTANT_NameAndType:
292 294 break;
293 295 default:
294 296 st->print_cr(" bad tag=%d at %d", tag.value(), i);
295 297 return;
296 298 }
297 299
298 300 symbolOop name = constants->uncached_name_ref_at(i);
299 301 symbolOop signature = constants->uncached_signature_ref_at(i);
300 302 st->print_cr(" %d <%s> <%s> ", i, name->as_C_string(), signature->as_C_string());
301 303 }
302 304
303 305
304 306 void BytecodePrinter::print_attributes(Bytecodes::Code code, int bci, outputStream* st) {
305 307 // Show attributes of pre-rewritten codes
306 308 code = Bytecodes::java_code(code);
307 309 // If the code doesn't have any fields there's nothing to print.
308 310 // note this is ==1 because the tableswitch and lookupswitch are
309 311 // zero size (for some reason) and we want to print stuff out for them.
310 312 if (Bytecodes::length_for(code) == 1) {
311 313 st->cr();
312 314 return;
313 315 }
314 316
315 317 switch(code) {
316 318 // Java specific bytecodes only matter.
317 319 case Bytecodes::_bipush:
318 320 st->print_cr(" " INT32_FORMAT, get_byte());
319 321 break;
320 322 case Bytecodes::_sipush:
321 323 st->print_cr(" " INT32_FORMAT, get_short());
322 324 break;
323 325 case Bytecodes::_ldc:
324 326 print_constant(get_index(), st);
325 327 break;
326 328
327 329 case Bytecodes::_ldc_w:
328 330 case Bytecodes::_ldc2_w:
329 331 print_constant(get_big_index(), st);
330 332 break;
331 333
332 334 case Bytecodes::_iload:
333 335 case Bytecodes::_lload:
334 336 case Bytecodes::_fload:
335 337 case Bytecodes::_dload:
336 338 case Bytecodes::_aload:
337 339 case Bytecodes::_istore:
338 340 case Bytecodes::_lstore:
339 341 case Bytecodes::_fstore:
340 342 case Bytecodes::_dstore:
341 343 case Bytecodes::_astore:
342 344 st->print_cr(" #%d", get_index_special());
343 345 break;
344 346
345 347 case Bytecodes::_iinc:
346 348 { int index = get_index_special();
347 349 jint offset = is_wide() ? get_short(): get_byte();
348 350 st->print_cr(" #%d " INT32_FORMAT, index, offset);
349 351 }
350 352 break;
351 353
352 354 case Bytecodes::_newarray: {
353 355 BasicType atype = (BasicType)get_index();
354 356 const char* str = type2name(atype);
355 357 if (str == NULL || atype == T_OBJECT || atype == T_ARRAY) {
356 358 assert(false, "Unidentified basic type");
357 359 }
358 360 st->print_cr(" %s", str);
359 361 }
360 362 break;
361 363 case Bytecodes::_anewarray: {
362 364 int klass_index = get_big_index();
363 365 constantPoolOop constants = method()->constants();
364 366 symbolOop name = constants->klass_name_at(klass_index);
365 367 st->print_cr(" %s ", name->as_C_string());
366 368 }
367 369 break;
368 370 case Bytecodes::_multianewarray: {
369 371 int klass_index = get_big_index();
370 372 int nof_dims = get_index();
371 373 constantPoolOop constants = method()->constants();
372 374 symbolOop name = constants->klass_name_at(klass_index);
373 375 st->print_cr(" %s %d", name->as_C_string(), nof_dims);
374 376 }
375 377 break;
376 378
377 379 case Bytecodes::_ifeq:
378 380 case Bytecodes::_ifnull:
379 381 case Bytecodes::_iflt:
380 382 case Bytecodes::_ifle:
381 383 case Bytecodes::_ifne:
382 384 case Bytecodes::_ifnonnull:
383 385 case Bytecodes::_ifgt:
384 386 case Bytecodes::_ifge:
385 387 case Bytecodes::_if_icmpeq:
386 388 case Bytecodes::_if_icmpne:
387 389 case Bytecodes::_if_icmplt:
388 390 case Bytecodes::_if_icmpgt:
389 391 case Bytecodes::_if_icmple:
390 392 case Bytecodes::_if_icmpge:
391 393 case Bytecodes::_if_acmpeq:
392 394 case Bytecodes::_if_acmpne:
393 395 case Bytecodes::_goto:
394 396 case Bytecodes::_jsr:
395 397 st->print_cr(" %d", bci + get_short());
396 398 break;
397 399
398 400 case Bytecodes::_goto_w:
399 401 case Bytecodes::_jsr_w:
400 402 st->print_cr(" %d", bci + get_int());
401 403 break;
402 404
403 405 case Bytecodes::_ret: st->print_cr(" %d", get_index_special()); break;
404 406
405 407 case Bytecodes::_tableswitch:
406 408 { align();
407 409 int default_dest = bci + get_int();
408 410 int lo = get_int();
409 411 int hi = get_int();
410 412 int len = hi - lo + 1;
411 413 jint* dest = NEW_RESOURCE_ARRAY(jint, len);
412 414 for (int i = 0; i < len; i++) {
413 415 dest[i] = bci + get_int();
414 416 }
415 417 st->print(" %d " INT32_FORMAT " " INT32_FORMAT " ",
416 418 default_dest, lo, hi);
417 419 int first = true;
418 420 for (int ll = lo; ll <= hi; ll++, first = false) {
419 421 int idx = ll - lo;
420 422 const char *format = first ? " %d:" INT32_FORMAT " (delta: %d)" :
421 423 ", %d:" INT32_FORMAT " (delta: %d)";
422 424 st->print(format, ll, dest[idx], dest[idx]-bci);
423 425 }
424 426 st->cr();
425 427 }
426 428 break;
427 429 case Bytecodes::_lookupswitch:
428 430 { align();
429 431 int default_dest = bci + get_int();
430 432 int len = get_int();
431 433 jint* key = NEW_RESOURCE_ARRAY(jint, len);
432 434 jint* dest = NEW_RESOURCE_ARRAY(jint, len);
433 435 for (int i = 0; i < len; i++) {
434 436 key [i] = get_int();
435 437 dest[i] = bci + get_int();
436 438 };
437 439 st->print(" %d %d ", default_dest, len);
438 440 bool first = true;
439 441 for (int ll = 0; ll < len; ll++, first = false) {
440 442 const char *format = first ? " " INT32_FORMAT ":" INT32_FORMAT :
441 443 ", " INT32_FORMAT ":" INT32_FORMAT ;
442 444 st->print(format, key[ll], dest[ll]);
443 445 }
444 446 st->cr();
445 447 }
446 448 break;
447 449
448 450 case Bytecodes::_putstatic:
449 451 case Bytecodes::_getstatic:
450 452 case Bytecodes::_putfield:
451 453 case Bytecodes::_getfield:
452 454 print_field_or_method(get_big_index(), st);
453 455 break;
454 456
455 457 case Bytecodes::_invokevirtual:
456 458 case Bytecodes::_invokespecial:
457 459 case Bytecodes::_invokestatic:
458 460 print_field_or_method(get_big_index(), st);
459 461 break;
460 462
461 463 case Bytecodes::_invokeinterface:
462 464 { int i = get_big_index();
463 465 int n = get_index();
464 466 get_index(); // ignore zero byte
465 467 print_field_or_method(i, st);
466 468 }
467 469 break;
468 470
469 471 case Bytecodes::_invokedynamic:
470 472 print_field_or_method(get_giant_index(), st);
471 473 break;
472 474
473 475 case Bytecodes::_new:
474 476 case Bytecodes::_checkcast:
475 477 case Bytecodes::_instanceof:
476 478 { int i = get_big_index();
477 479 constantPoolOop constants = method()->constants();
478 480 symbolOop name = constants->klass_name_at(i);
479 481 st->print_cr(" %d <%s>", i, name->as_C_string());
480 482 }
481 483 break;
482 484
483 485 case Bytecodes::_wide:
484 486 // length is zero not one, but printed with no more info.
485 487 break;
486 488
487 489 default:
488 490 ShouldNotReachHere();
489 491 break;
490 492 }
491 493 }
492 494
493 495
494 496 void BytecodePrinter::bytecode_epilog(int bci, outputStream* st) {
495 497 methodDataOop mdo = method()->method_data();
496 498 if (mdo != NULL) {
497 499 ProfileData* data = mdo->bci_to_data(bci);
498 500 if (data != NULL) {
499 501 st->print(" %d", mdo->dp_to_di(data->dp()));
500 502 st->fill_to(6);
501 503 data->print_data_on(st);
502 504 }
503 505 }
504 506 }
505 507 #endif // PRODUCT
↓ open down ↓ |
223 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX