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