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