1 /*
  2  * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/vmSymbols.hpp"
 27 #include "c1/c1_InstructionPrinter.hpp"
 28 #include "c1/c1_ValueStack.hpp"
 29 #include "ci/ciArray.hpp"
 30 #include "ci/ciInstance.hpp"
 31 #include "ci/ciObject.hpp"
 32 
 33 
 34 #ifndef PRODUCT
 35 
 36 const char* InstructionPrinter::basic_type_name(BasicType type) {
 37   const char* n = type2name(type);
 38   if (n == nullptr || type > T_VOID) {
 39     return "???";
 40   }
 41   return n;
 42 }
 43 
 44 
 45 const char* InstructionPrinter::cond_name(If::Condition cond) {
 46   switch (cond) {
 47     case If::eql: return "==";
 48     case If::neq: return "!=";
 49     case If::lss: return "<";
 50     case If::leq: return "<=";
 51     case If::gtr: return ">";
 52     case If::geq: return ">=";
 53     case If::aeq: return "|>=|";
 54     case If::beq: return "|<=|";
 55     default:
 56       ShouldNotReachHere();
 57       return nullptr;
 58   }
 59 }
 60 
 61 
 62 const char* InstructionPrinter::op_name(Bytecodes::Code op) {
 63   switch (op) {
 64     // arithmetic ops
 65     case Bytecodes::_iadd : // fall through
 66     case Bytecodes::_ladd : // fall through
 67     case Bytecodes::_fadd : // fall through
 68     case Bytecodes::_dadd : return "+";
 69     case Bytecodes::_isub : // fall through
 70     case Bytecodes::_lsub : // fall through
 71     case Bytecodes::_fsub : // fall through
 72     case Bytecodes::_dsub : return "-";
 73     case Bytecodes::_imul : // fall through
 74     case Bytecodes::_lmul : // fall through
 75     case Bytecodes::_fmul : // fall through
 76     case Bytecodes::_dmul : return "*";
 77     case Bytecodes::_idiv : // fall through
 78     case Bytecodes::_ldiv : // fall through
 79     case Bytecodes::_fdiv : // fall through
 80     case Bytecodes::_ddiv : return "/";
 81     case Bytecodes::_irem : // fall through
 82     case Bytecodes::_lrem : // fall through
 83     case Bytecodes::_frem : // fall through
 84     case Bytecodes::_drem : return "%";
 85     // shift ops
 86     case Bytecodes::_ishl : // fall through
 87     case Bytecodes::_lshl : return "<<";
 88     case Bytecodes::_ishr : // fall through
 89     case Bytecodes::_lshr : return ">>";
 90     case Bytecodes::_iushr: // fall through
 91     case Bytecodes::_lushr: return ">>>";
 92     // logic ops
 93     case Bytecodes::_iand : // fall through
 94     case Bytecodes::_land : return "&";
 95     case Bytecodes::_ior  : // fall through
 96     case Bytecodes::_lor  : return "|";
 97     case Bytecodes::_ixor : // fall through
 98     case Bytecodes::_lxor : return "^";
 99     default               : return Bytecodes::name(op);
100   }
101 }
102 
103 
104 bool InstructionPrinter::is_illegal_phi(Value v) {
105   Phi* phi = v ? v->as_Phi() : nullptr;
106   if (phi && phi->is_illegal()) {
107     return true;
108   }
109   return false;
110 }
111 
112 
113 bool InstructionPrinter::is_phi_of_block(Value v, BlockBegin* b) {
114   Phi* phi = v ? v->as_Phi() : nullptr;
115   return phi && phi->block() == b;
116 }
117 
118 
119 void InstructionPrinter::print_klass(ciKlass* klass) {
120   klass->name()->print_symbol_on(output());
121 }
122 
123 
124 void InstructionPrinter::print_object(Value obj) {
125   ValueType* type = obj->type();
126   if (type->as_ObjectConstant() != nullptr) {
127     ciObject* value = type->as_ObjectConstant()->value();
128     if (value->is_null_object()) {
129       output()->print("null");
130     } else if (!value->is_loaded()) {
131       output()->print("<unloaded object " INTPTR_FORMAT ">", p2i(value));
132     } else {
133       output()->print("<object " INTPTR_FORMAT " klass=", p2i(value->constant_encoding()));
134       print_klass(value->klass());
135       output()->print(">");
136     }
137   } else if (type->as_InstanceConstant() != nullptr) {
138     ciInstance* value = type->as_InstanceConstant()->value();
139     if (value->is_loaded()) {
140       output()->print("<instance " INTPTR_FORMAT " klass=", p2i(value->constant_encoding()));
141       print_klass(value->klass());
142       output()->print(">");
143     } else {
144       output()->print("<unloaded instance " INTPTR_FORMAT ">", p2i(value));
145     }
146   } else if (type->as_ArrayConstant() != nullptr) {
147     output()->print("<array " INTPTR_FORMAT ">", p2i(type->as_ArrayConstant()->value()->constant_encoding()));
148   } else if (type->as_ClassConstant() != nullptr) {
149     ciInstanceKlass* klass = type->as_ClassConstant()->value();
150     if (!klass->is_loaded()) {
151       output()->print("<unloaded> ");
152     }
153     output()->print("class ");
154     print_klass(klass);
155   } else if (type->as_MethodConstant() != nullptr) {
156     ciMethod* m = type->as_MethodConstant()->value();
157     output()->print("<method %s.%s>", m->holder()->name()->as_utf8(), m->name()->as_utf8());
158   } else {
159     output()->print("???");
160   }
161 }
162 
163 
164 void InstructionPrinter::print_temp(Value value) {
165   output()->print("%c%d", value->type()->tchar(), value->id());
166 }
167 
168 
169 void InstructionPrinter::print_field(AccessField* field) {
170   print_value(field->obj());
171   output()->print("._%d", field->offset());
172 }
173 
174 
175 void InstructionPrinter::print_indexed(AccessIndexed* indexed) {
176   print_value(indexed->array());
177   output()->put('[');
178   print_value(indexed->index());
179   output()->put(']');
180   if (indexed->length() != nullptr) {
181     output()->put('(');
182     print_value(indexed->length());
183     output()->put(')');
184   }
185 }
186 
187 
188 void InstructionPrinter::print_monitor(AccessMonitor* monitor) {
189   output()->print("monitor[%d](", monitor->monitor_no());
190   print_value(monitor->obj());
191   output()->put(')');
192 }
193 
194 
195 void InstructionPrinter::print_op2(Op2* instr) {
196   print_value(instr->x());
197   output()->print(" %s ", op_name(instr->op()));
198   print_value(instr->y());
199 }
200 
201 
202 void InstructionPrinter::print_value(Value value) {
203   if (value == nullptr) {
204     output()->print("null");
205   } else {
206     print_temp(value);
207   }
208 }
209 
210 
211 void InstructionPrinter::print_instr(Instruction* instr) {
212   instr->visit(this);
213 }
214 
215 
216 void InstructionPrinter::print_stack(ValueStack* stack) {
217   int start_position = output()->position();
218   if (stack->stack_is_empty()) {
219     output()->print("empty stack");
220   } else {
221     output()->print("stack [");
222     for (int i = 0; i < stack->stack_size();) {
223       if (i > 0) output()->print(", ");
224       output()->print("%d:", i);
225       Value value = stack->stack_at_inc(i);
226       print_value(value);
227       Phi* phi = value->as_Phi();
228       if (phi != nullptr) {
229         if (phi->operand()->is_valid()) {
230           output()->print(" ");
231           phi->operand()->print(output());
232         }
233       }
234     }
235     output()->put(']');
236   }
237   if (!stack->no_active_locks()) {
238     // print out the lines on the line below this
239     // one at the same indentation level.
240     output()->cr();
241     fill_to(start_position, ' ');
242     output()->print("locks [");
243     for (int i = 0; i < stack->locks_size(); i++) {
244       Value t = stack->lock_at(i);
245       if (i > 0) output()->print(", ");
246       output()->print("%d:", i);
247       if (t == nullptr) {
248         // synchronized methods push null on the lock stack
249         output()->print("this");
250       } else {
251         print_value(t);
252       }
253     }
254     output()->print("]");
255   }
256 }
257 
258 
259 void InstructionPrinter::print_inline_level(BlockBegin* block) {
260   output()->print_cr("inlining depth %d", block->scope()->level());
261 }
262 
263 
264 void InstructionPrinter::print_unsafe_op(UnsafeOp* op, const char* name) {
265   output()->print("%s(", name);
266   print_value(op->object());
267   output()->print(", ");
268   print_value(op->offset());
269 }
270 
271 
272 void InstructionPrinter::print_phi(int i, Value v, BlockBegin* b) {
273   Phi* phi = v->as_Phi();
274   output()->print("%2d  ", i);
275   print_value(v);
276   // print phi operands
277   if (phi && phi->block() == b) {
278     output()->print(" [");
279     for (int j = 0; j < phi->operand_count(); j ++) {
280       output()->print(" ");
281       Value opd = phi->operand_at(j);
282       if (opd) print_value(opd);
283       else output()->print("null");
284     }
285     output()->print("] ");
286   }
287   print_alias(v);
288 }
289 
290 
291 void InstructionPrinter::print_alias(Value v) {
292   if (v != v->subst()) {
293     output()->print("alias "); print_value(v->subst());
294   }
295 }
296 
297 
298 void InstructionPrinter::fill_to(int pos, char filler) {
299   while (output()->position() < pos) output()->put(filler);
300 }
301 
302 
303 void InstructionPrinter::print_head() {
304   const char filler = '_';
305   fill_to(bci_pos  , filler); output()->print("bci"  );
306   fill_to(use_pos  , filler); output()->print("use"  );
307   fill_to(temp_pos , filler); output()->print("tid"  );
308   fill_to(instr_pos, filler); output()->print("instr");
309   fill_to(end_pos  , filler);
310   output()->cr();
311 }
312 
313 
314 void InstructionPrinter::print_line(Instruction* instr) {
315   // print instruction data on one line
316   if (instr->is_pinned()) output()->put('.');
317   if (instr->has_printable_bci()) {
318     fill_to(bci_pos  ); output()->print("%d", instr->printable_bci());
319   }
320   fill_to(use_pos  ); output()->print("%d", instr->use_count());
321   fill_to(temp_pos ); print_temp(instr);
322   fill_to(instr_pos); print_instr(instr);
323   output()->cr();
324   // add a line for StateSplit instructions w/ non-empty stacks
325   // (make it robust so we can print incomplete instructions)
326   StateSplit* split = instr->as_StateSplit();
327   if (split != nullptr && split->state() != nullptr && !split->state()->stack_is_empty()) {
328     fill_to(instr_pos); print_stack(split->state());
329     output()->cr();
330   }
331 }
332 
333 
334 void InstructionPrinter::do_Phi(Phi* x) {
335   output()->print("phi function");  // make that more detailed later
336   if (x->is_illegal())
337     output()->print(" (illegal)");
338 }
339 
340 
341 void InstructionPrinter::do_Local(Local* x) {
342   output()->print("local[index %d]", x->java_index());
343 }
344 
345 
346 void InstructionPrinter::do_Constant(Constant* x) {
347   ValueType* t = x->type();
348   switch (t->tag()) {
349     case intTag    : output()->print("%d"  , t->as_IntConstant   ()->value());    break;
350     case longTag   : output()->print(JLONG_FORMAT, t->as_LongConstant()->value()); output()->print("L"); break;
351     case floatTag  : output()->print("%g"  , t->as_FloatConstant ()->value());    break;
352     case doubleTag : output()->print("%gD" , t->as_DoubleConstant()->value());    break;
353     case objectTag : print_object(x);                                        break;
354     case addressTag: output()->print("bci:%d", t->as_AddressConstant()->value()); break;
355     default        : output()->print("???");                                      break;
356   }
357 }
358 
359 
360 void InstructionPrinter::do_LoadField(LoadField* x) {
361   print_field(x);
362   output()->print(" (%c)", type2char(x->field()->type()->basic_type()));
363   output()->print(" %s", x->field()->name()->as_utf8());
364 }
365 
366 
367 void InstructionPrinter::do_StoreField(StoreField* x) {
368   print_field(x);
369   output()->print(" := ");
370   print_value(x->value());
371   output()->print(" (%c)", type2char(x->field()->type()->basic_type()));
372   output()->print(" %s", x->field()->name()->as_utf8());
373 }
374 
375 
376 void InstructionPrinter::do_ArrayLength(ArrayLength* x) {
377   print_value(x->array());
378   output()->print(".length");
379 }
380 
381 
382 void InstructionPrinter::do_LoadIndexed(LoadIndexed* x) {
383   print_indexed(x);
384   output()->print(" (%c)", type2char(x->elt_type()));
385   if (x->check_flag(Instruction::NeedsRangeCheckFlag)) {
386     output()->print(" [rc]");
387   }
388 }
389 
390 
391 void InstructionPrinter::do_StoreIndexed(StoreIndexed* x) {
392   print_indexed(x);
393   output()->print(" := ");
394   print_value(x->value());
395   output()->print(" (%c)", type2char(x->elt_type()));
396   if (x->check_flag(Instruction::NeedsRangeCheckFlag)) {
397     output()->print(" [rc]");
398   }
399 }
400 
401 void InstructionPrinter::do_NegateOp(NegateOp* x) {
402   output()->put('-');
403   print_value(x->x());
404 }
405 
406 
407 void InstructionPrinter::do_ArithmeticOp(ArithmeticOp* x) {
408   print_op2(x);
409 }
410 
411 
412 void InstructionPrinter::do_ShiftOp(ShiftOp* x) {
413   print_op2(x);
414 }
415 
416 
417 void InstructionPrinter::do_LogicOp(LogicOp* x) {
418   print_op2(x);
419 }
420 
421 
422 void InstructionPrinter::do_CompareOp(CompareOp* x) {
423   print_op2(x);
424 }
425 
426 
427 void InstructionPrinter::do_IfOp(IfOp* x) {
428   print_value(x->x());
429   output()->print(" %s ", cond_name(x->cond()));
430   print_value(x->y());
431   output()->print(" ? ");
432   print_value(x->tval());
433   output()->print(" : ");
434   print_value(x->fval());
435 }
436 
437 
438 void InstructionPrinter::do_Convert(Convert* x) {
439   output()->print("%s(", Bytecodes::name(x->op()));
440   print_value(x->value());
441   output()->put(')');
442 }
443 
444 
445 void InstructionPrinter::do_NullCheck(NullCheck* x) {
446   output()->print("null_check(");
447   print_value(x->obj());
448   output()->put(')');
449   if (!x->can_trap()) {
450     output()->print(" (eliminated)");
451   }
452 }
453 
454 
455 void InstructionPrinter::do_TypeCast(TypeCast* x) {
456   output()->print("type_cast(");
457   print_value(x->obj());
458   output()->print(") ");
459   if (x->declared_type()->is_klass())
460     print_klass(x->declared_type()->as_klass());
461   else
462     output()->print("%s", type2name(x->declared_type()->basic_type()));
463 }
464 
465 
466 void InstructionPrinter::do_Invoke(Invoke* x) {
467   if (x->receiver() != nullptr) {
468     print_value(x->receiver());
469     output()->print(".");
470   }
471 
472   output()->print("%s(", Bytecodes::name(x->code()));
473   for (int i = 0; i < x->number_of_arguments(); i++) {
474     if (i > 0) output()->print(", ");
475     print_value(x->argument_at(i));
476   }
477   output()->print_cr(")");
478   fill_to(instr_pos);
479   output()->print("%s.%s%s",
480              x->target()->holder()->name()->as_utf8(),
481              x->target()->name()->as_utf8(),
482              x->target()->signature()->as_symbol()->as_utf8());
483 }
484 
485 
486 void InstructionPrinter::do_NewInstance(NewInstance* x) {
487   output()->print("new instance ");
488   print_klass(x->klass());
489 }
490 
491 
492 void InstructionPrinter::do_NewTypeArray(NewTypeArray* x) {
493   output()->print("new %s array [", basic_type_name(x->elt_type()));
494   print_value(x->length());
495   output()->put(']');
496 }
497 
498 
499 void InstructionPrinter::do_NewObjectArray(NewObjectArray* x) {
500   output()->print("new object array [");
501   print_value(x->length());
502   output()->print("] ");
503   print_klass(x->klass());
504 }
505 
506 
507 void InstructionPrinter::do_NewMultiArray(NewMultiArray* x) {
508   output()->print("new multi array [");
509   Values* dims = x->dims();
510   for (int i = 0; i < dims->length(); i++) {
511     if (i > 0) output()->print(", ");
512     print_value(dims->at(i));
513   }
514   output()->print("] ");
515   print_klass(x->klass());
516 }
517 
518 
519 void InstructionPrinter::do_MonitorEnter(MonitorEnter* x) {
520   output()->print("enter ");
521   print_monitor(x);
522 }
523 
524 
525 void InstructionPrinter::do_MonitorExit(MonitorExit* x) {
526   output()->print("exit ");
527   print_monitor(x);
528 }
529 
530 
531 void InstructionPrinter::do_Intrinsic(Intrinsic* x) {
532   const char* name = vmIntrinsics::name_at(x->id());
533   if (name[0] == '_')  name++;  // strip leading bug from _hashCode, etc.
534   const char* kname = vmSymbols::name_for(vmIntrinsics::class_for(x->id()));
535   if (strchr(name, '_') == nullptr) {
536     kname = nullptr;
537   } else {
538     const char* kptr = strrchr(kname, '/');
539     if (kptr != nullptr)  kname = kptr + 1;
540   }
541   if (kname == nullptr)
542     output()->print("%s(", name);
543   else
544     output()->print("%s.%s(", kname, name);
545   for (int i = 0; i < x->number_of_arguments(); i++) {
546     if (i > 0) output()->print(", ");
547     print_value(x->argument_at(i));
548   }
549   output()->put(')');
550 }
551 
552 
553 void InstructionPrinter::do_BlockBegin(BlockBegin* x) {
554   // print block id
555   BlockEnd* end = x->end();
556   output()->print("B%d ", x->block_id());
557 
558   // print flags
559   bool printed_flag = false;
560   if (x->is_set(BlockBegin::std_entry_flag)) {
561     if (!printed_flag) output()->print("(");
562     output()->print("S"); printed_flag = true;
563   }
564   if (x->is_set(BlockBegin::osr_entry_flag)) {
565     if (!printed_flag) output()->print("(");
566     output()->print("O"); printed_flag = true;
567   }
568   if (x->is_set(BlockBegin::exception_entry_flag)) {
569     if (!printed_flag) output()->print("(");
570     output()->print("E"); printed_flag = true;
571   }
572   if (x->is_set(BlockBegin::subroutine_entry_flag)) {
573     if (!printed_flag) output()->print("(");
574     output()->print("s"); printed_flag = true;
575   }
576   if (x->is_set(BlockBegin::parser_loop_header_flag)) {
577     if (!printed_flag) output()->print("(");
578     output()->print("LH"); printed_flag = true;
579   }
580   if (x->is_set(BlockBegin::backward_branch_target_flag)) {
581     if (!printed_flag) output()->print("(");
582     output()->print("b"); printed_flag = true;
583   }
584   if (x->is_set(BlockBegin::was_visited_flag)) {
585     if (!printed_flag) output()->print("(");
586     output()->print("V"); printed_flag = true;
587   }
588   if (printed_flag) output()->print(") ");
589 
590   // print block bci range
591   output()->print("[%d, %d]", x->bci(), (end == nullptr ? -1 : end->printable_bci()));
592 
593   // print block successors
594   if (end != nullptr && end->number_of_sux() > 0) {
595     output()->print(" ->");
596     for (int i = 0; i < end->number_of_sux(); i++) {
597       output()->print(" B%d", end->sux_at(i)->block_id());
598     }
599   }
600   // print exception handlers
601   if (x->number_of_exception_handlers() > 0) {
602     output()->print(" (xhandlers ");
603     for (int i = 0; i < x->number_of_exception_handlers();  i++) {
604       if (i > 0) output()->print(" ");
605       output()->print("B%d", x->exception_handler_at(i)->block_id());
606     }
607     output()->put(')');
608   }
609 
610   // print dominator block
611   if (x->dominator() != nullptr) {
612     output()->print(" dom B%d", x->dominator()->block_id());
613   }
614 
615   // print predecessors
616   if (x->number_of_preds() > 0) {
617     output()->print(" pred:");
618     for (int i = 0; i < x->number_of_preds(); i ++) {
619       output()->print(" B%d", x->pred_at(i)->block_id());
620     }
621   }
622 
623   if (!_print_phis) {
624     return;
625   }
626 
627   // print phi functions
628   bool has_phis_in_locals = false;
629   bool has_phis_on_stack = false;
630 
631   if (x->end() && x->end()->state()) {
632     ValueStack* state = x->state();
633 
634     int i = 0;
635     while (!has_phis_on_stack && i < state->stack_size()) {
636       Value v = state->stack_at_inc(i);
637       has_phis_on_stack = is_phi_of_block(v, x);
638     }
639 
640     do {
641       for (i = 0; !has_phis_in_locals && i < state->locals_size();) {
642         Value v = state->local_at(i);
643         has_phis_in_locals = is_phi_of_block(v, x);
644         // also ignore illegal HiWords
645         if (v && !v->type()->is_illegal()) i += v->type()->size(); else i ++;
646       }
647       state = state->caller_state();
648     } while (state != nullptr);
649 
650   }
651 
652   // print values in locals
653   if (has_phis_in_locals) {
654     output()->cr(); output()->print_cr("Locals:");
655 
656     ValueStack* state = x->state();
657     do {
658       for (int i = 0; i < state->locals_size();) {
659         Value v = state->local_at(i);
660         if (v) {
661           print_phi(i, v, x); output()->cr();
662           // also ignore illegal HiWords
663           i += (v->type()->is_illegal() ? 1 : v->type()->size());
664         } else {
665           i ++;
666         }
667       }
668       output()->cr();
669       state = state->caller_state();
670     } while (state != nullptr);
671   }
672 
673   // print values on stack
674   if (has_phis_on_stack) {
675     output()->print_cr("Stack:");
676     int i = 0;
677     while (i < x->state()->stack_size()) {
678       int o = i;
679       Value v = x->state()->stack_at_inc(i);
680       if (v) {
681         print_phi(o, v, x); output()->cr();
682       }
683     }
684   }
685 }
686 
687 
688 void InstructionPrinter::do_CheckCast(CheckCast* x) {
689   output()->print("checkcast(");
690   print_value(x->obj());
691   output()->print(") ");
692   print_klass(x->klass());
693 }
694 
695 
696 void InstructionPrinter::do_InstanceOf(InstanceOf* x) {
697   output()->print("instanceof(");
698   print_value(x->obj());
699   output()->print(") ");
700   print_klass(x->klass());
701 }
702 
703 
704 void InstructionPrinter::do_Goto(Goto* x) {
705   output()->print("goto B%d", x->default_sux()->block_id());
706   if (x->is_safepoint()) output()->print(" (safepoint)");
707 }
708 
709 
710 void InstructionPrinter::do_If(If* x) {
711   output()->print("if ");
712   print_value(x->x());
713   output()->print(" %s ", cond_name(x->cond()));
714   print_value(x->y());
715   output()->print(" then B%d else B%d", x->sux_at(0)->block_id(), x->sux_at(1)->block_id());
716   if (x->is_safepoint()) output()->print(" (safepoint)");
717 }
718 
719 
720 void InstructionPrinter::do_TableSwitch(TableSwitch* x) {
721   output()->print("tableswitch ");
722   if (x->is_safepoint()) output()->print("(safepoint) ");
723   print_value(x->tag());
724   output()->cr();
725   int l = x->length();
726   for (int i = 0; i < l; i++) {
727     fill_to(instr_pos);
728     output()->print_cr("case %5d: B%d", x->lo_key() + i, x->sux_at(i)->block_id());
729   }
730   fill_to(instr_pos);
731   output()->print("default   : B%d", x->default_sux()->block_id());
732 }
733 
734 
735 void InstructionPrinter::do_LookupSwitch(LookupSwitch* x) {
736   output()->print("lookupswitch ");
737   if (x->is_safepoint()) output()->print("(safepoint) ");
738   print_value(x->tag());
739   output()->cr();
740   int l = x->length();
741   for (int i = 0; i < l; i++) {
742     fill_to(instr_pos);
743     output()->print_cr("case %5d: B%d", x->key_at(i), x->sux_at(i)->block_id());
744   }
745   fill_to(instr_pos);
746   output()->print("default   : B%d", x->default_sux()->block_id());
747 }
748 
749 
750 void InstructionPrinter::do_Return(Return* x) {
751   if (x->result() == nullptr) {
752     output()->print("return");
753   } else {
754     output()->print("%creturn ", x->type()->tchar());
755     print_value(x->result());
756   }
757 }
758 
759 
760 void InstructionPrinter::do_Throw(Throw* x) {
761   output()->print("throw ");
762   print_value(x->exception());
763 }
764 
765 
766 void InstructionPrinter::do_Base(Base* x) {
767   output()->print("std entry B%d", x->std_entry()->block_id());
768   if (x->number_of_sux() > 1) {
769     output()->print(" osr entry B%d", x->osr_entry()->block_id());
770   }
771 }
772 
773 
774 void InstructionPrinter::do_OsrEntry(OsrEntry* x) {
775   output()->print("osr entry");
776 }
777 
778 
779 void InstructionPrinter::do_ExceptionObject(ExceptionObject* x) {
780   output()->print("incoming exception");
781 }
782 
783 
784 void InstructionPrinter::do_RoundFP(RoundFP* x) {
785   output()->print("round_fp ");
786   print_value(x->input());
787 }
788 
789 void InstructionPrinter::do_UnsafeGet(UnsafeGet* x) {
790   print_unsafe_op(x, x->is_raw() ? "UnsafeGet (raw)" : "UnsafeGet");
791   output()->put(')');
792 }
793 
794 void InstructionPrinter::do_UnsafePut(UnsafePut* x) {
795   print_unsafe_op(x, "UnsafePut");
796   output()->print(", value ");
797   print_value(x->value());
798   output()->put(')');
799 }
800 
801 void InstructionPrinter::do_UnsafeGetAndSet(UnsafeGetAndSet* x) {
802   print_unsafe_op(x, x->is_add()?"UnsafeGetAndSet (add)":"UnsafeGetAndSet");
803   output()->print(", value ");
804   print_value(x->value());
805   output()->put(')');
806 }
807 
808 void InstructionPrinter::do_RangeCheckPredicate(RangeCheckPredicate* x) {
809 
810   if (x->x() != nullptr && x->y() != nullptr) {
811     output()->print("if ");
812     print_value(x->x());
813     output()->print(" %s ", cond_name(x->cond()));
814     print_value(x->y());
815     output()->print(" then deoptimize!");
816   } else {
817     output()->print("always deoptimize!");
818   }
819 }
820 
821 #ifdef ASSERT
822 void InstructionPrinter::do_Assert(Assert* x) {
823   output()->print("assert ");
824   print_value(x->x());
825   output()->print(" %s ", cond_name(x->cond()));
826   print_value(x->y());
827 }
828 #endif
829 
830 void InstructionPrinter::do_ProfileCall(ProfileCall* x) {
831   output()->print("profile ");
832   print_value(x->recv());
833   output()->print(" %s.%s", x->method()->holder()->name()->as_utf8(), x->method()->name()->as_utf8());
834   if (x->known_holder() != nullptr) {
835     output()->print(", ");
836     print_klass(x->known_holder());
837     output()->print(" ");
838   }
839   for (int i = 0; i < x->nb_profiled_args(); i++) {
840     if (i > 0) output()->print(", ");
841     print_value(x->profiled_arg_at(i));
842     if (x->arg_needs_null_check(i)) {
843       output()->print(" [NC]");
844     }
845   }
846   output()->put(')');
847 }
848 
849 void InstructionPrinter::do_ProfileReturnType(ProfileReturnType* x) {
850   output()->print("profile ret type ");
851   print_value(x->ret());
852   output()->print(" %s.%s", x->method()->holder()->name()->as_utf8(), x->method()->name()->as_utf8());
853   output()->put(')');
854 }
855 void InstructionPrinter::do_ProfileInvoke(ProfileInvoke* x) {
856   output()->print("profile_invoke ");
857   output()->print(" %s.%s", x->inlinee()->holder()->name()->as_utf8(), x->inlinee()->name()->as_utf8());
858   output()->put(')');
859 
860 }
861 
862 void InstructionPrinter::do_RuntimeCall(RuntimeCall* x) {
863   output()->print("call_rt %s(", x->entry_name());
864   for (int i = 0; i < x->number_of_arguments(); i++) {
865     if (i > 0) output()->print(", ");
866     print_value(x->argument_at(i));
867   }
868   output()->put(')');
869 }
870 
871 void InstructionPrinter::do_MemBar(MemBar* x) {
872   LIR_Code code = x->code();
873   switch (code) {
874   case lir_membar_acquire   : output()->print("membar_acquire"); break;
875   case lir_membar_release   : output()->print("membar_release"); break;
876   case lir_membar           : output()->print("membar"); break;
877   case lir_membar_loadload  : output()->print("membar_loadload"); break;
878   case lir_membar_storestore: output()->print("membar_storestore"); break;
879   case lir_membar_loadstore : output()->print("membar_loadstore"); break;
880   case lir_membar_storeload : output()->print("membar_storeload"); break;
881   default                   : ShouldNotReachHere(); break;
882   }
883 }
884 
885 #endif // PRODUCT