src/share/vm/c1/c1_InstructionPrinter.cpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

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

mercurial