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