src/share/vm/c1/c1_InstructionPrinter.cpp

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 2174
f02a8bbe6ed4
child 2486
403dc4c1d7f5
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

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

mercurial