src/share/vm/c1/c1_InstructionPrinter.cpp

Thu, 20 Sep 2012 16:49:17 +0200

author
roland
date
Thu, 20 Sep 2012 16:49:17 +0200
changeset 4106
7eca5de9e0b6
parent 4037
da91efe96a93
child 4465
203f64878aab
permissions
-rw-r--r--

7023898: Intrinsify AtomicLongFieldUpdater.getAndIncrement()
Summary: use shorter instruction sequences for atomic add and atomic exchange when possible.
Reviewed-by: kvn, jrose

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

mercurial