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