1 /* 2 * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. 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 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "cds/heapShared.hpp" 26 #include "classfile/classPrinter.hpp" 27 #include "classfile/javaClasses.inline.hpp" 28 #include "interpreter/bytecodeHistogram.hpp" 29 #include "interpreter/bytecodeStream.hpp" 30 #include "interpreter/bytecodeTracer.hpp" 31 #include "interpreter/bytecodes.hpp" 32 #include "interpreter/interpreter.hpp" 33 #include "interpreter/interpreterRuntime.hpp" 34 #include "memory/resourceArea.hpp" 35 #include "oops/constantPool.inline.hpp" 36 #include "oops/methodData.hpp" 37 #include "oops/method.hpp" 38 #include "oops/resolvedFieldEntry.hpp" 39 #include "oops/resolvedIndyEntry.hpp" 40 #include "oops/resolvedMethodEntry.hpp" 41 #include "runtime/handles.inline.hpp" 42 #include "runtime/mutexLocker.hpp" 43 #include "runtime/osThread.hpp" 44 #include "runtime/timer.hpp" 45 #include "utilities/align.hpp" 46 47 // Prints the current bytecode and its attributes using bytecode-specific information. 48 49 class BytecodePrinter { 50 private: 51 // %%% This field is not GC-ed, and so can contain garbage 52 // between critical sections. Use only pointer-comparison 53 // operations on the pointer, except within a critical section. 54 // (Also, ensure that occasional false positives are benign.) 55 Method* _current_method; 56 bool _is_wide; 57 Bytecodes::Code _code; 58 address _next_pc; // current decoding position 59 int _flags; 60 bool _is_linked; 61 62 bool is_linked() const { return _is_linked; } 63 void align() { _next_pc = align_up(_next_pc, sizeof(jint)); } 64 int get_byte() { return *(jbyte*) _next_pc++; } // signed 65 int get_index_u1() { return *(address)_next_pc++; } // returns 0x00 - 0xff as an int 66 short get_short() { short i = Bytes::get_Java_u2 (_next_pc); _next_pc += 2; return i; } 67 int get_int() { int i = Bytes::get_Java_u4 (_next_pc); _next_pc += 4; return i; } 68 int get_native_index_u2() { int i = Bytes::get_native_u2(_next_pc); _next_pc += 2; return i; } 69 int get_native_index_u4() { int i = Bytes::get_native_u4(_next_pc); _next_pc += 4; return i; } 70 int get_Java_index_u2() { int i = Bytes::get_Java_u2 (_next_pc); _next_pc += 2; return i; } 71 int get_Java_index_u4() { int i = Bytes::get_Java_u4 (_next_pc); _next_pc += 4; return i; } 72 int get_index_special() { return (is_wide()) ? get_Java_index_u2() : get_index_u1(); } 73 Method* method() const { return _current_method; } 74 bool is_wide() const { return _is_wide; } 75 Bytecodes::Code raw_code() const { return Bytecodes::Code(_code); } 76 ConstantPool* constants() const { return method()->constants(); } 77 ConstantPoolCache* cpcache() const { assert(is_linked(), "must be"); return constants()->cache(); } 78 79 void print_constant(int i, outputStream* st); 80 void print_cpcache_entry(int cpc_index, outputStream* st); 81 void print_invokedynamic(int indy_index, int cp_index, outputStream* st); 82 void print_bsm(int cp_index, outputStream* st); 83 void print_field_or_method(int cp_index, outputStream* st); 84 void print_dynamic(int cp_index, outputStream* st); 85 void print_attributes(int bci, outputStream* st); 86 void bytecode_epilog(int bci, outputStream* st); 87 88 public: 89 BytecodePrinter(int flags = 0) { 90 _is_wide = false; 91 _code = Bytecodes::_illegal; 92 _flags = flags; 93 } 94 95 // This method is called while executing the raw bytecodes, so none of 96 // the adjustments that BytecodeStream performs applies. 97 void trace(const methodHandle& method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) { 98 ResourceMark rm; 99 bool method_changed = _current_method != method(); 100 if (method_changed) { 101 // Note 1: This code will not work as expected with true MT/MP. 102 // Need an explicit lock or a different solution. 103 // It is possible for this block to be skipped, if a garbage 104 // _current_method pointer happens to have the same bits as 105 // the incoming method. We could lose a line of trace output. 106 // This is acceptable in a debug-only feature. 107 st->cr(); 108 st->print("[%zu] ", Thread::current()->osthread()->thread_id_for_printing()); 109 method->print_name(st); 110 st->cr(); 111 _current_method = method(); 112 _is_linked = method->method_holder()->is_linked(); 113 assert(_is_linked, "this function must be called on methods that are already executing"); 114 } 115 Bytecodes::Code code; 116 if (is_wide()) { 117 // bcp wasn't advanced if previous bytecode was _wide. 118 code = Bytecodes::code_at(method(), bcp+1); 119 } else { 120 code = Bytecodes::code_at(method(), bcp); 121 } 122 _code = code; 123 _next_pc = is_wide() ? bcp+2 : bcp+1; 124 // Trace each bytecode unless we're truncating the tracing output, then only print the first 125 // bytecode in every method as well as returns/throws that pop control flow 126 if (!TraceBytecodesTruncated || method_changed || 127 code == Bytecodes::_athrow || 128 code == Bytecodes::_return_register_finalizer || 129 (code >= Bytecodes::_ireturn && code <= Bytecodes::_return)) { 130 int bci = (int)(bcp - method->code_base()); 131 st->print("[%zu] ", Thread::current()->osthread()->thread_id_for_printing()); 132 if (Verbose) { 133 st->print("%8zu %4d " INTPTR_FORMAT " " INTPTR_FORMAT " %s", 134 BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code)); 135 } else { 136 st->print("%8zu %4d %s", 137 BytecodeCounter::counter_value(), bci, Bytecodes::name(code)); 138 } 139 print_attributes(bci, st); 140 } 141 // Set is_wide for the next one, since the caller of this doesn't skip 142 // the next bytecode. 143 _is_wide = (code == Bytecodes::_wide); 144 _code = Bytecodes::_illegal; 145 146 #ifndef PRODUCT 147 if (TraceBytecodesStopAt != 0 && BytecodeCounter::counter_value() >= TraceBytecodesStopAt) { 148 TraceBytecodes = false; 149 } 150 #endif 151 } 152 153 // Used for Method*::print_codes(). The input bcp comes from 154 // BytecodeStream, which will skip wide bytecodes. 155 void trace(const methodHandle& method, address bcp, outputStream* st) { 156 _current_method = method(); 157 _is_linked = method->method_holder()->is_linked(); 158 ResourceMark rm; 159 Bytecodes::Code code = Bytecodes::code_at(method(), bcp); 160 // Set is_wide 161 _is_wide = (code == Bytecodes::_wide); 162 if (is_wide()) { 163 code = Bytecodes::code_at(method(), bcp+1); 164 } 165 _code = code; 166 int bci = (int)(bcp - method->code_base()); 167 // Print bytecode index and name 168 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_BYTECODE_ADDR)) { 169 st->print(INTPTR_FORMAT " ", p2i(bcp)); 170 } 171 if (is_wide()) { 172 st->print("%4d %s_w", bci, Bytecodes::name(code)); 173 } else { 174 st->print("%4d %s", bci, Bytecodes::name(code)); 175 } 176 _next_pc = is_wide() ? bcp+2 : bcp+1; 177 print_attributes(bci, st); 178 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_PROFILE)) { 179 bytecode_epilog(bci, st); 180 } 181 } 182 }; 183 184 #ifndef PRODUCT 185 // We need a global instance to keep track of the states when the bytecodes 186 // are executed. Access by multiple threads are controlled by ttyLocker. 187 static BytecodePrinter _interpreter_printer; 188 189 void BytecodeTracer::trace_interpreter(const methodHandle& method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) { 190 if (TraceBytecodes && BytecodeCounter::counter_value() >= TraceBytecodesAt) { 191 ttyLocker ttyl; // 5065316: keep the following output coherent 192 // The ttyLocker also prevents races between two threads 193 // trying to use the single instance of BytecodePrinter. 194 // 195 // There used to be a leaf mutex here, but the ttyLocker will 196 // work just as well, as long as the printing operations never block. 197 _interpreter_printer.trace(method, bcp, tos, tos2, st); 198 } 199 } 200 #endif 201 202 void BytecodeTracer::print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags) { 203 BytecodePrinter method_printer(flags); 204 BytecodeStream s(method); 205 s.set_interval(from, to); 206 207 // Keep output to st coherent: collect all lines and print at once. 208 ResourceMark rm; 209 stringStream ss; 210 while (s.next() >= 0) { 211 method_printer.trace(method, s.bcp(), &ss); 212 } 213 st->print("%s", ss.as_string()); 214 } 215 216 void BytecodePrinter::print_constant(int cp_index, outputStream* st) { 217 ConstantPool* constants = method()->constants(); 218 constantTag tag = constants->tag_at(cp_index); 219 220 if (tag.is_int()) { 221 st->print_cr(" " INT32_FORMAT, constants->int_at(cp_index)); 222 } else if (tag.is_long()) { 223 st->print_cr(" " INT64_FORMAT, (int64_t)(constants->long_at(cp_index))); 224 } else if (tag.is_float()) { 225 st->print_cr(" %f", constants->float_at(cp_index)); 226 } else if (tag.is_double()) { 227 st->print_cr(" %f", constants->double_at(cp_index)); 228 } else if (tag.is_string()) { 229 const char* string = constants->unresolved_string_at(cp_index)->as_quoted_ascii(); 230 st->print_cr(" \"%s\"", string); 231 } else if (tag.is_klass()) { 232 st->print_cr(" %s", constants->resolved_klass_at(cp_index)->external_name()); 233 } else if (tag.is_unresolved_klass()) { 234 st->print_cr(" %s", constants->klass_at_noresolve(cp_index)->as_quoted_ascii()); 235 } else if (tag.is_method_type()) { 236 int i2 = constants->method_type_index_at(cp_index); 237 st->print(" <MethodType> %d", i2); 238 st->print_cr(" %s", constants->symbol_at(i2)->as_quoted_ascii()); 239 } else if (tag.is_method_handle()) { 240 int kind = constants->method_handle_ref_kind_at(cp_index); 241 int i2 = constants->method_handle_index_at(cp_index); 242 st->print(" <MethodHandle of kind %d index at %d>", kind, i2); 243 print_field_or_method(i2, st); 244 } else if (tag.is_dynamic_constant()) { 245 print_dynamic(cp_index, st); 246 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_DYNAMIC)) { 247 print_bsm(cp_index, st); 248 } 249 } else { 250 st->print_cr(" bad tag=%d at %d", tag.value(), cp_index); 251 } 252 } 253 254 // Fieldref, Methodref, or InterfaceMethodref 255 void BytecodePrinter::print_field_or_method(int cp_index, outputStream* st) { 256 ConstantPool* constants = method()->constants(); 257 constantTag tag = constants->tag_at(cp_index); 258 259 switch (tag.value()) { 260 case JVM_CONSTANT_Fieldref: 261 case JVM_CONSTANT_Methodref: 262 case JVM_CONSTANT_InterfaceMethodref: 263 break; 264 default: 265 st->print_cr(" bad tag=%d at %d", tag.value(), cp_index); 266 return; 267 } 268 269 Symbol* name = constants->uncached_name_ref_at(cp_index); 270 Symbol* signature = constants->uncached_signature_ref_at(cp_index); 271 Symbol* klass = constants->klass_name_at(constants->uncached_klass_ref_index_at(cp_index)); 272 const char* sep = (tag.is_field() ? ":" : ""); 273 st->print_cr(" %d <%s.%s%s%s> ", cp_index, klass->as_C_string(), name->as_C_string(), sep, signature->as_C_string()); 274 } 275 276 // JVM_CONSTANT_Dynamic or JVM_CONSTANT_InvokeDynamic 277 void BytecodePrinter::print_dynamic(int cp_index, outputStream* st) { 278 ConstantPool* constants = method()->constants(); 279 constantTag tag = constants->tag_at(cp_index); 280 281 switch (tag.value()) { 282 case JVM_CONSTANT_Dynamic: 283 case JVM_CONSTANT_InvokeDynamic: 284 break; 285 default: 286 st->print_cr(" bad tag=%d at %d", tag.value(), cp_index); 287 return; 288 } 289 290 int bsm = constants->bootstrap_method_ref_index_at(cp_index); 291 st->print(" bsm=%d", bsm); 292 293 Symbol* name = constants->uncached_name_ref_at(cp_index); 294 Symbol* signature = constants->uncached_signature_ref_at(cp_index); 295 const char* sep = tag.is_dynamic_constant() ? ":" : ""; 296 st->print_cr(" %d <%s%s%s>", cp_index, name->as_C_string(), sep, signature->as_C_string()); 297 } 298 299 void BytecodePrinter::print_invokedynamic(int indy_index, int cp_index, outputStream* st) { 300 print_dynamic(cp_index, st); 301 302 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_DYNAMIC)) { 303 print_bsm(cp_index, st); 304 305 if (is_linked()) { 306 ResolvedIndyEntry* indy_entry = constants()->resolved_indy_entry_at(indy_index); 307 st->print(" ResolvedIndyEntry: "); 308 indy_entry->print_on(st); 309 if (indy_entry->has_appendix()) { 310 oop apx = constants()->resolved_reference_from_indy(indy_index); 311 st->print_cr(" - appendix = " INTPTR_FORMAT, p2i(apx)); 312 } 313 } 314 } 315 } 316 317 // cp_index: must be the cp_index of a JVM_CONSTANT_{Dynamic, DynamicInError, InvokeDynamic} 318 void BytecodePrinter::print_bsm(int cp_index, outputStream* st) { 319 assert(constants()->tag_at(cp_index).has_bootstrap(), "must be"); 320 int bsm = constants()->bootstrap_method_ref_index_at(cp_index); 321 const char* ref_kind = ""; 322 switch (constants()->method_handle_ref_kind_at(bsm)) { 323 case JVM_REF_getField : ref_kind = "REF_getField"; break; 324 case JVM_REF_getStatic : ref_kind = "REF_getStatic"; break; 325 case JVM_REF_putField : ref_kind = "REF_putField"; break; 326 case JVM_REF_putStatic : ref_kind = "REF_putStatic"; break; 327 case JVM_REF_invokeVirtual : ref_kind = "REF_invokeVirtual"; break; 328 case JVM_REF_invokeStatic : ref_kind = "REF_invokeStatic"; break; 329 case JVM_REF_invokeSpecial : ref_kind = "REF_invokeSpecial"; break; 330 case JVM_REF_newInvokeSpecial : ref_kind = "REF_newInvokeSpecial"; break; 331 case JVM_REF_invokeInterface : ref_kind = "REF_invokeInterface"; break; 332 default : ShouldNotReachHere(); 333 } 334 st->print(" BSM: %s", ref_kind); 335 print_field_or_method(constants()->method_handle_index_at(bsm), st); 336 int argc = constants()->bootstrap_argument_count_at(cp_index); 337 st->print(" arguments[%d] = {", argc); 338 if (argc > 0) { 339 st->cr(); 340 for (int arg_i = 0; arg_i < argc; arg_i++) { 341 int arg = constants()->bootstrap_argument_index_at(cp_index, arg_i); 342 st->print(" "); 343 print_constant(arg, st); 344 } 345 } 346 st->print_cr(" }"); 347 } 348 349 void BytecodePrinter::print_attributes(int bci, outputStream* st) { 350 // Show attributes of pre-rewritten codes 351 Bytecodes::Code code = Bytecodes::java_code(raw_code()); 352 // If the code doesn't have any fields there's nothing to print. 353 // note this is ==1 because the tableswitch and lookupswitch are 354 // zero size (for some reason) and we want to print stuff out for them. 355 // Also skip this if we're truncating bytecode output 356 if (TraceBytecodesTruncated || Bytecodes::length_for(code) == 1) { 357 st->cr(); 358 return; 359 } 360 361 switch(code) { 362 // Java specific bytecodes only matter. 363 case Bytecodes::_bipush: 364 st->print_cr(" " INT32_FORMAT, get_byte()); 365 break; 366 case Bytecodes::_sipush: 367 st->print_cr(" " INT32_FORMAT, get_short()); 368 break; 369 case Bytecodes::_ldc: 370 { 371 int cp_index; 372 if (Bytecodes::uses_cp_cache(raw_code())) { 373 assert(is_linked(), "fast ldc bytecode must be in linked classes"); 374 int obj_index = get_index_u1(); 375 cp_index = constants()->object_to_cp_index(obj_index); 376 } else { 377 cp_index = get_index_u1(); 378 } 379 print_constant(cp_index, st); 380 } 381 break; 382 383 case Bytecodes::_ldc_w: 384 case Bytecodes::_ldc2_w: 385 { 386 int cp_index; 387 if (Bytecodes::uses_cp_cache(raw_code())) { 388 assert(is_linked(), "fast ldc bytecode must be in linked classes"); 389 int obj_index = get_native_index_u2(); 390 cp_index = constants()->object_to_cp_index(obj_index); 391 } else { 392 cp_index = get_Java_index_u2(); 393 } 394 print_constant(cp_index, st); 395 } 396 break; 397 398 case Bytecodes::_iload: 399 case Bytecodes::_lload: 400 case Bytecodes::_fload: 401 case Bytecodes::_dload: 402 case Bytecodes::_aload: 403 case Bytecodes::_istore: 404 case Bytecodes::_lstore: 405 case Bytecodes::_fstore: 406 case Bytecodes::_dstore: 407 case Bytecodes::_astore: 408 st->print_cr(" #%d", get_index_special()); 409 break; 410 411 case Bytecodes::_iinc: 412 { int index = get_index_special(); 413 jint offset = is_wide() ? get_short(): get_byte(); 414 st->print_cr(" #%d " INT32_FORMAT, index, offset); 415 } 416 break; 417 418 case Bytecodes::_newarray: { 419 BasicType atype = (BasicType)get_index_u1(); 420 const char* str = type2name(atype); 421 if (str == nullptr || is_reference_type(atype)) { 422 assert(false, "Unidentified basic type"); 423 } 424 st->print_cr(" %s", str); 425 } 426 break; 427 case Bytecodes::_anewarray: { 428 int klass_index = get_Java_index_u2(); 429 ConstantPool* constants = method()->constants(); 430 Symbol* name = constants->klass_name_at(klass_index); 431 st->print_cr(" %s ", name->as_C_string()); 432 } 433 break; 434 case Bytecodes::_multianewarray: { 435 int klass_index = get_Java_index_u2(); 436 int nof_dims = get_index_u1(); 437 ConstantPool* constants = method()->constants(); 438 Symbol* name = constants->klass_name_at(klass_index); 439 st->print_cr(" %s %d", name->as_C_string(), nof_dims); 440 } 441 break; 442 443 case Bytecodes::_ifeq: 444 case Bytecodes::_ifnull: 445 case Bytecodes::_iflt: 446 case Bytecodes::_ifle: 447 case Bytecodes::_ifne: 448 case Bytecodes::_ifnonnull: 449 case Bytecodes::_ifgt: 450 case Bytecodes::_ifge: 451 case Bytecodes::_if_icmpeq: 452 case Bytecodes::_if_icmpne: 453 case Bytecodes::_if_icmplt: 454 case Bytecodes::_if_icmpgt: 455 case Bytecodes::_if_icmple: 456 case Bytecodes::_if_icmpge: 457 case Bytecodes::_if_acmpeq: 458 case Bytecodes::_if_acmpne: 459 case Bytecodes::_goto: 460 case Bytecodes::_jsr: 461 st->print_cr(" %d", bci + get_short()); 462 break; 463 464 case Bytecodes::_goto_w: 465 case Bytecodes::_jsr_w: 466 st->print_cr(" %d", bci + get_int()); 467 break; 468 469 case Bytecodes::_ret: st->print_cr(" %d", get_index_special()); break; 470 471 case Bytecodes::_tableswitch: 472 { align(); 473 int default_dest = bci + get_int(); 474 int lo = get_int(); 475 int hi = get_int(); 476 int len = hi - lo + 1; 477 jint* dest = NEW_RESOURCE_ARRAY(jint, len); 478 for (int i = 0; i < len; i++) { 479 dest[i] = bci + get_int(); 480 } 481 st->print(" %d " INT32_FORMAT " " INT32_FORMAT " ", 482 default_dest, lo, hi); 483 const char *comma = ""; 484 for (int ll = lo; ll <= hi; ll++) { 485 int idx = ll - lo; 486 st->print("%s %d:" INT32_FORMAT " (delta: %d)", comma, ll, dest[idx], dest[idx]-bci); 487 comma = ","; 488 } 489 st->cr(); 490 } 491 break; 492 case Bytecodes::_lookupswitch: 493 { align(); 494 int default_dest = bci + get_int(); 495 int len = get_int(); 496 jint* key = NEW_RESOURCE_ARRAY(jint, len); 497 jint* dest = NEW_RESOURCE_ARRAY(jint, len); 498 for (int i = 0; i < len; i++) { 499 key [i] = get_int(); 500 dest[i] = bci + get_int(); 501 }; 502 st->print(" %d %d ", default_dest, len); 503 const char *comma = ""; 504 for (int ll = 0; ll < len; ll++) { 505 st->print("%s " INT32_FORMAT ":" INT32_FORMAT, comma, key[ll], dest[ll]); 506 comma = ","; 507 } 508 st->cr(); 509 } 510 break; 511 512 case Bytecodes::_putstatic: 513 case Bytecodes::_getstatic: 514 case Bytecodes::_putfield: 515 case Bytecodes::_getfield: 516 { 517 int cp_index; 518 if (is_linked()) { 519 int field_index = get_native_index_u2(); 520 cp_index = cpcache()->resolved_field_entry_at(field_index)->constant_pool_index(); 521 } else { 522 cp_index = get_Java_index_u2(); 523 } 524 print_field_or_method(cp_index, st); 525 } 526 break; 527 528 case Bytecodes::_invokevirtual: 529 case Bytecodes::_invokespecial: 530 case Bytecodes::_invokestatic: 531 { 532 int cp_index; 533 if (is_linked()) { 534 int method_index = get_native_index_u2(); 535 ResolvedMethodEntry* method_entry = cpcache()->resolved_method_entry_at(method_index); 536 cp_index = method_entry->constant_pool_index(); 537 print_field_or_method(cp_index, st); 538 539 if (raw_code() == Bytecodes::_invokehandle && 540 ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_METHOD_HANDLE)) { 541 assert(is_linked(), "invokehandle is only in rewritten methods"); 542 method_entry->print_on(st); 543 if (method_entry->has_appendix()) { 544 st->print(" appendix: "); 545 constants()->resolved_reference_from_method(method_index)->print_on(st); 546 } 547 } 548 } else { 549 cp_index = get_Java_index_u2(); 550 print_field_or_method(cp_index, st); 551 } 552 } 553 break; 554 555 case Bytecodes::_invokeinterface: 556 { 557 int cp_index; 558 if (is_linked()) { 559 int method_index = get_native_index_u2(); 560 cp_index = cpcache()->resolved_method_entry_at(method_index)->constant_pool_index(); 561 } else { 562 cp_index = get_Java_index_u2(); 563 } 564 int count = get_index_u1(); // TODO: this is not printed. 565 get_byte(); // ignore zero byte 566 print_field_or_method(cp_index, st); 567 } 568 break; 569 570 case Bytecodes::_invokedynamic: 571 { 572 int indy_index; 573 int cp_index; 574 if (is_linked()) { 575 indy_index = get_native_index_u4(); 576 cp_index = constants()->resolved_indy_entry_at(indy_index)->constant_pool_index(); 577 } else { 578 indy_index = -1; 579 cp_index = get_Java_index_u2(); 580 get_byte(); // ignore zero byte 581 get_byte(); // ignore zero byte 582 } 583 print_invokedynamic(indy_index, cp_index, st); 584 } 585 break; 586 587 case Bytecodes::_new: 588 case Bytecodes::_checkcast: 589 case Bytecodes::_instanceof: 590 { int i = get_Java_index_u2(); 591 ConstantPool* constants = method()->constants(); 592 Symbol* name = constants->klass_name_at(i); 593 st->print_cr(" %d <%s>", i, name->as_C_string()); 594 } 595 break; 596 597 case Bytecodes::_wide: 598 // length is zero not one, but printed with no more info. 599 break; 600 601 default: 602 ShouldNotReachHere(); 603 break; 604 } 605 } 606 607 608 void BytecodePrinter::bytecode_epilog(int bci, outputStream* st) { 609 MethodData* mdo = method()->method_data(); 610 if (mdo != nullptr) { 611 612 // Lock to read ProfileData, and ensure lock is not broken by a safepoint 613 MutexLocker ml(mdo->extra_data_lock(), Mutex::_no_safepoint_check_flag); 614 615 ProfileData* data = mdo->bci_to_data(bci); 616 if (data != nullptr) { 617 st->print(" %d ", mdo->dp_to_di(data->dp())); 618 st->fill_to(7); 619 data->print_data_on(st, mdo); 620 } 621 } 622 }