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