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