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