1 /*
  2  * Copyright (c) 1999, 2019, 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 == NULL || 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 NULL;
 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() : NULL;
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() : NULL;
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() != NULL) {
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() != NULL) {
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() != NULL) {
147     output()->print("<array " INTPTR_FORMAT ">", p2i(type->as_ArrayConstant()->value()->constant_encoding()));
148   } else if (type->as_ClassConstant() != NULL) {
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() != NULL) {
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() != NULL) {
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 == NULL) {
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 != NULL) {
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 == NULL) {
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 != NULL && split->state() != NULL && !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() != NULL) {
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, '_') == NULL) {
536     kname = NULL;
537   } else {
538     const char* kptr = strrchr(kname, '/');
539     if (kptr != NULL)  kname = kptr + 1;
540   }
541   if (kname == NULL)
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 == NULL ? -1 : end->printable_bci()));
592 
593   // print block successors
594   if (end != NULL && 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() != NULL) {
612     output()->print(" dom B%d", x->dominator()->block_id());
613   }
614 
615   // print predecessors and successors
616   if (x->successors()->length() > 0) {
617     output()->print(" sux:");
618     for (int i = 0; i < x->successors()->length(); i ++) {
619       output()->print(" B%d", x->successors()->at(i)->block_id());
620     }
621   }
622 
623   if (x->number_of_preds() > 0) {
624     output()->print(" pred:");
625     for (int i = 0; i < x->number_of_preds(); i ++) {
626       output()->print(" B%d", x->pred_at(i)->block_id());
627     }
628   }
629 
630   if (!_print_phis) {
631     return;
632   }
633 
634   // print phi functions
635   bool has_phis_in_locals = false;
636   bool has_phis_on_stack = false;
637 
638   if (x->end() && x->end()->state()) {
639     ValueStack* state = x->state();
640 
641     int i = 0;
642     while (!has_phis_on_stack && i < state->stack_size()) {
643       Value v = state->stack_at_inc(i);
644       has_phis_on_stack = is_phi_of_block(v, x);
645     }
646 
647     do {
648       for (i = 0; !has_phis_in_locals && i < state->locals_size();) {
649         Value v = state->local_at(i);
650         has_phis_in_locals = is_phi_of_block(v, x);
651         // also ignore illegal HiWords
652         if (v && !v->type()->is_illegal()) i += v->type()->size(); else i ++;
653       }
654       state = state->caller_state();
655     } while (state != NULL);
656 
657   }
658 
659   // print values in locals
660   if (has_phis_in_locals) {
661     output()->cr(); output()->print_cr("Locals:");
662 
663     ValueStack* state = x->state();
664     do {
665       for (int i = 0; i < state->locals_size();) {
666         Value v = state->local_at(i);
667         if (v) {
668           print_phi(i, v, x); output()->cr();
669           // also ignore illegal HiWords
670           i += (v->type()->is_illegal() ? 1 : v->type()->size());
671         } else {
672           i ++;
673         }
674       }
675       output()->cr();
676       state = state->caller_state();
677     } while (state != NULL);
678   }
679 
680   // print values on stack
681   if (has_phis_on_stack) {
682     output()->print_cr("Stack:");
683     int i = 0;
684     while (i < x->state()->stack_size()) {
685       int o = i;
686       Value v = x->state()->stack_at_inc(i);
687       if (v) {
688         print_phi(o, v, x); output()->cr();
689       }
690     }
691   }
692 }
693 
694 
695 void InstructionPrinter::do_CheckCast(CheckCast* x) {
696   output()->print("checkcast(");
697   print_value(x->obj());
698   output()->print(") ");
699   print_klass(x->klass());
700 }
701 
702 
703 void InstructionPrinter::do_InstanceOf(InstanceOf* x) {
704   output()->print("instanceof(");
705   print_value(x->obj());
706   output()->print(") ");
707   print_klass(x->klass());
708 }
709 
710 
711 void InstructionPrinter::do_Goto(Goto* x) {
712   output()->print("goto B%d", x->default_sux()->block_id());
713   if (x->is_safepoint()) output()->print(" (safepoint)");
714 }
715 
716 
717 void InstructionPrinter::do_If(If* x) {
718   output()->print("if ");
719   print_value(x->x());
720   output()->print(" %s ", cond_name(x->cond()));
721   print_value(x->y());
722   output()->print(" then B%d else B%d", x->sux_at(0)->block_id(), x->sux_at(1)->block_id());
723   if (x->is_safepoint()) output()->print(" (safepoint)");
724 }
725 
726 
727 void InstructionPrinter::do_TableSwitch(TableSwitch* x) {
728   output()->print("tableswitch ");
729   if (x->is_safepoint()) output()->print("(safepoint) ");
730   print_value(x->tag());
731   output()->cr();
732   int l = x->length();
733   for (int i = 0; i < l; i++) {
734     fill_to(instr_pos);
735     output()->print_cr("case %5d: B%d", x->lo_key() + i, x->sux_at(i)->block_id());
736   }
737   fill_to(instr_pos);
738   output()->print("default   : B%d", x->default_sux()->block_id());
739 }
740 
741 
742 void InstructionPrinter::do_LookupSwitch(LookupSwitch* x) {
743   output()->print("lookupswitch ");
744   if (x->is_safepoint()) output()->print("(safepoint) ");
745   print_value(x->tag());
746   output()->cr();
747   int l = x->length();
748   for (int i = 0; i < l; i++) {
749     fill_to(instr_pos);
750     output()->print_cr("case %5d: B%d", x->key_at(i), x->sux_at(i)->block_id());
751   }
752   fill_to(instr_pos);
753   output()->print("default   : B%d", x->default_sux()->block_id());
754 }
755 
756 
757 void InstructionPrinter::do_Return(Return* x) {
758   if (x->result() == NULL) {
759     output()->print("return");
760   } else {
761     output()->print("%creturn ", x->type()->tchar());
762     print_value(x->result());
763   }
764 }
765 
766 
767 void InstructionPrinter::do_Throw(Throw* x) {
768   output()->print("throw ");
769   print_value(x->exception());
770 }
771 
772 
773 void InstructionPrinter::do_Base(Base* x) {
774   output()->print("std entry B%d", x->std_entry()->block_id());
775   if (x->number_of_sux() > 1) {
776     output()->print(" osr entry B%d", x->osr_entry()->block_id());
777   }
778 }
779 
780 
781 void InstructionPrinter::do_OsrEntry(OsrEntry* x) {
782   output()->print("osr entry");
783 }
784 
785 
786 void InstructionPrinter::do_ExceptionObject(ExceptionObject* x) {
787   output()->print("incoming exception");
788 }
789 
790 
791 void InstructionPrinter::do_RoundFP(RoundFP* x) {
792   output()->print("round_fp ");
793   print_value(x->input());
794 }
795 
796 void InstructionPrinter::do_UnsafeGet(UnsafeGet* x) {
797   print_unsafe_op(x, x->is_raw() ? "UnsafeGet (raw)" : "UnsafeGet");
798   output()->put(')');
799 }
800 
801 void InstructionPrinter::do_UnsafePut(UnsafePut* x) {
802   print_unsafe_op(x, "UnsafePut");
803   output()->print(", value ");
804   print_value(x->value());
805   output()->put(')');
806 }
807 
808 void InstructionPrinter::do_UnsafeGetAndSet(UnsafeGetAndSet* x) {
809   print_unsafe_op(x, x->is_add()?"UnsafeGetAndSet (add)":"UnsafeGetAndSet");
810   output()->print(", value ");
811   print_value(x->value());
812   output()->put(')');
813 }
814 
815 void InstructionPrinter::do_RangeCheckPredicate(RangeCheckPredicate* x) {
816 
817   if (x->x() != NULL && x->y() != NULL) {
818     output()->print("if ");
819     print_value(x->x());
820     output()->print(" %s ", cond_name(x->cond()));
821     print_value(x->y());
822     output()->print(" then deoptimize!");
823   } else {
824     output()->print("always deoptimize!");
825   }
826 }
827 
828 #ifdef ASSERT
829 void InstructionPrinter::do_Assert(Assert* x) {
830   output()->print("assert ");
831   print_value(x->x());
832   output()->print(" %s ", cond_name(x->cond()));
833   print_value(x->y());
834 }
835 #endif
836 
837 void InstructionPrinter::do_ProfileCall(ProfileCall* x) {
838   output()->print("profile ");
839   print_value(x->recv());
840   output()->print(" %s.%s", x->method()->holder()->name()->as_utf8(), x->method()->name()->as_utf8());
841   if (x->known_holder() != NULL) {
842     output()->print(", ");
843     print_klass(x->known_holder());
844     output()->print(" ");
845   }
846   for (int i = 0; i < x->nb_profiled_args(); i++) {
847     if (i > 0) output()->print(", ");
848     print_value(x->profiled_arg_at(i));
849     if (x->arg_needs_null_check(i)) {
850       output()->print(" [NC]");
851     }
852   }
853   output()->put(')');
854 }
855 
856 void InstructionPrinter::do_ProfileReturnType(ProfileReturnType* x) {
857   output()->print("profile ret type ");
858   print_value(x->ret());
859   output()->print(" %s.%s", x->method()->holder()->name()->as_utf8(), x->method()->name()->as_utf8());
860   output()->put(')');
861 }
862 void InstructionPrinter::do_ProfileInvoke(ProfileInvoke* x) {
863   output()->print("profile_invoke ");
864   output()->print(" %s.%s", x->inlinee()->holder()->name()->as_utf8(), x->inlinee()->name()->as_utf8());
865   output()->put(')');
866 
867 }
868 
869 void InstructionPrinter::do_RuntimeCall(RuntimeCall* x) {
870   output()->print("call_rt %s(", x->entry_name());
871   for (int i = 0; i < x->number_of_arguments(); i++) {
872     if (i > 0) output()->print(", ");
873     print_value(x->argument_at(i));
874   }
875   output()->put(')');
876 }
877 
878 void InstructionPrinter::do_MemBar(MemBar* x) {
879   LIR_Code code = x->code();
880   switch (code) {
881   case lir_membar_acquire   : output()->print("membar_acquire"); break;
882   case lir_membar_release   : output()->print("membar_release"); break;
883   case lir_membar           : output()->print("membar"); break;
884   case lir_membar_loadload  : output()->print("membar_loadload"); break;
885   case lir_membar_storestore: output()->print("membar_storestore"); break;
886   case lir_membar_loadstore : output()->print("membar_loadstore"); break;
887   case lir_membar_storeload : output()->print("membar_storeload"); break;
888   default                   : ShouldNotReachHere(); break;
889   }
890 }
891 
892 #endif // PRODUCT