bool InstructionPrinter::is_illegal_phi(Value v) {
  Phi* phi = v ? v->as_Phi() : NULL;
  if (phi && phi->is_illegal()) {
    return true;
  }
  return false;
}
void InstructionPrinter::print_phi(int i, Value v, BlockBegin* b) {
  Phi* phi = v->as_Phi();
  output()->print("%2d  ", i);
  print_value(v);
  // print phi operands
  if (phi && phi->block() == b) {
    output()->print(" [");
    for (int j = 0; j < phi->operand_count(); j ++) {
      output()->print(" ");
      Value opd = phi->operand_at(j);
      if (opd) print_value(opd);
      else output()->print("NULL");
    }
    output()->print("] ");
  }
  print_alias(v);
}
void InstructionPrinter::print_stack(ValueStack* stack) {
  int start_position = output()->position();
if(!stack||stack->stack_is_empty()){
    output()->print("empty stack");
  } else {
    output()->print("stack [");
    for (int i = 0; i < stack->stack_size();) {
      if (i > 0) output()->print(", ");
      output()->print("%d:", i);
      Value value = stack->stack_at_inc(i);
      print_value(value);
      Phi* phi = value->as_Phi();
      if (phi != NULL) {
        if (phi->operand()->is_valid()) {
          output()->print(" ");
          phi->operand()->print(output());
        }
      }
    }
    output()->put(']');
  }
if(stack&&!stack->no_active_locks()){
    // print out the lines on the line below this
    // one at the same indentation level.
    output()->cr();
    fill_to(start_position, ' ');
    output()->print("locks [");
for(int i=0;i<stack->locks_size();i++){
      Value t = stack->lock_at(i);
      if (i > 0) output()->print(", ");
      output()->print("%d:", i);
      if (t == NULL) {
        // synchronized methods push null on the lock stack
        output()->print("this");
      } else {
        print_value(t);
      }
    }
    output()->print("]");
  }
}
void Canonicalizer::set_canonical(Value x) {
  assert(x != NULL, "value must exist");
  // Note: we can not currently substitute root nodes which show up in
  // the instruction stream (because the instruction list is embedded
  // in the instructions). Phis always show up as roots. It is fatal
  // to embed a phi into the instruction stream as block merging will
  // not be able to substitute the old phi.
  if (x->as_Phi() != NULL) {
    if (PrintCanonicalization) {
      tty->print_cr("canonicalization produced a phi node; rejected");
    }
    return;
  }
  if (canonical() != x) {
    if (PrintCanonicalization) {
      canonical()->print(); tty->cr();
      tty->print_cr("canonicalized to:");
      x->print(); tty->cr();
      tty->cr();
    }
    _canonical = x;
  }
}
bool InstructionPrinter::is_phi_of_block(Value v, BlockBegin* b) {
  Phi* phi = v ? v->as_Phi() : NULL;
  return phi && phi->block() == b;
}