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