1 /* 2 * Copyright (c) 2000, 2023, 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 "precompiled.hpp" 26 #include "c1/c1_CodeStubs.hpp" 27 #include "c1/c1_InstructionPrinter.hpp" 28 #include "c1/c1_LIR.hpp" 29 #include "c1/c1_LIRAssembler.hpp" 30 #include "c1/c1_ValueStack.hpp" 31 #include "ci/ciInlineKlass.hpp" 32 #include "ci/ciInstance.hpp" 33 #include "runtime/safepointMechanism.inline.hpp" 34 #include "runtime/sharedRuntime.hpp" 35 #include "runtime/vm_version.hpp" 36 37 Register LIR_Opr::as_register() const { 38 return FrameMap::cpu_rnr2reg(cpu_regnr()); 39 } 40 41 Register LIR_Opr::as_register_lo() const { 42 return FrameMap::cpu_rnr2reg(cpu_regnrLo()); 43 } 44 45 Register LIR_Opr::as_register_hi() const { 46 return FrameMap::cpu_rnr2reg(cpu_regnrHi()); 47 } 48 49 LIR_Opr LIR_OprFact::illegalOpr = LIR_OprFact::illegal(); 50 LIR_Opr LIR_OprFact::nullOpr = LIR_Opr(); 51 52 LIR_Opr LIR_OprFact::value_type(ValueType* type) { 53 ValueTag tag = type->tag(); 54 switch (tag) { 55 case metaDataTag : { 56 ClassConstant* c = type->as_ClassConstant(); 57 if (c != nullptr && !c->value()->is_loaded()) { 58 return LIR_OprFact::metadataConst(nullptr); 59 } else if (c != nullptr) { 60 return LIR_OprFact::metadataConst(c->value()->constant_encoding()); 61 } else { 62 MethodConstant* m = type->as_MethodConstant(); 63 assert (m != nullptr, "not a class or a method?"); 64 return LIR_OprFact::metadataConst(m->value()->constant_encoding()); 65 } 66 } 67 case objectTag : { 68 return LIR_OprFact::oopConst(type->as_ObjectType()->encoding()); 69 } 70 case addressTag: return LIR_OprFact::addressConst(type->as_AddressConstant()->value()); 71 case intTag : return LIR_OprFact::intConst(type->as_IntConstant()->value()); 72 case floatTag : return LIR_OprFact::floatConst(type->as_FloatConstant()->value()); 73 case longTag : return LIR_OprFact::longConst(type->as_LongConstant()->value()); 74 case doubleTag : return LIR_OprFact::doubleConst(type->as_DoubleConstant()->value()); 75 default: ShouldNotReachHere(); return LIR_OprFact::intConst(-1); 76 } 77 } 78 79 80 //--------------------------------------------------- 81 82 83 LIR_Address::Scale LIR_Address::scale(BasicType type) { 84 int elem_size = type2aelembytes(type); 85 switch (elem_size) { 86 case 1: return LIR_Address::times_1; 87 case 2: return LIR_Address::times_2; 88 case 4: return LIR_Address::times_4; 89 case 8: return LIR_Address::times_8; 90 } 91 ShouldNotReachHere(); 92 return LIR_Address::times_1; 93 } 94 95 //--------------------------------------------------- 96 97 char LIR_Opr::type_char(BasicType t) { 98 switch (t) { 99 case T_ARRAY: 100 case T_PRIMITIVE_OBJECT: 101 t = T_OBJECT; 102 case T_BOOLEAN: 103 case T_CHAR: 104 case T_FLOAT: 105 case T_DOUBLE: 106 case T_BYTE: 107 case T_SHORT: 108 case T_INT: 109 case T_LONG: 110 case T_OBJECT: 111 case T_ADDRESS: 112 case T_VOID: 113 return ::type2char(t); 114 case T_METADATA: 115 return 'M'; 116 case T_ILLEGAL: 117 return '?'; 118 119 default: 120 ShouldNotReachHere(); 121 return '?'; 122 } 123 } 124 125 #ifndef PRODUCT 126 void LIR_Opr::validate_type() const { 127 128 #ifdef ASSERT 129 if (!is_pointer() && !is_illegal()) { 130 OprKind kindfield = kind_field(); // Factored out because of compiler bug, see 8002160 131 switch (as_BasicType(type_field())) { 132 case T_LONG: 133 assert((kindfield == cpu_register || kindfield == stack_value) && 134 size_field() == double_size, "must match"); 135 break; 136 case T_FLOAT: 137 // FP return values can be also in CPU registers on ARM (softfp ABI) 138 assert((kindfield == fpu_register || kindfield == stack_value 139 ARM_ONLY(|| kindfield == cpu_register) ) && 140 size_field() == single_size, "must match"); 141 break; 142 case T_DOUBLE: 143 // FP return values can be also in CPU registers on ARM (softfp ABI) 144 assert((kindfield == fpu_register || kindfield == stack_value 145 ARM_ONLY(|| kindfield == cpu_register) ) && 146 size_field() == double_size, "must match"); 147 break; 148 case T_BOOLEAN: 149 case T_CHAR: 150 case T_BYTE: 151 case T_SHORT: 152 case T_INT: 153 case T_ADDRESS: 154 case T_OBJECT: 155 case T_METADATA: 156 case T_ARRAY: 157 case T_PRIMITIVE_OBJECT: 158 assert((kindfield == cpu_register || kindfield == stack_value) && 159 size_field() == single_size, "must match"); 160 break; 161 162 case T_ILLEGAL: 163 // XXX TKR also means unknown right now 164 // assert(is_illegal(), "must match"); 165 break; 166 167 default: 168 ShouldNotReachHere(); 169 } 170 } 171 #endif 172 173 } 174 #endif // PRODUCT 175 176 177 bool LIR_Opr::is_oop() const { 178 if (is_pointer()) { 179 return pointer()->is_oop_pointer(); 180 } else { 181 OprType t= type_field(); 182 assert(t != unknown_type, "not set"); 183 return t == object_type; 184 } 185 } 186 187 188 189 void LIR_Op2::verify() const { 190 #ifdef ASSERT 191 switch (code()) { 192 case lir_xchg: 193 break; 194 195 default: 196 assert(!result_opr()->is_register() || !result_opr()->is_oop_register(), 197 "can't produce oops from arith"); 198 } 199 200 if (two_operand_lir_form) { 201 202 #ifdef ASSERT 203 bool threeOperandForm = false; 204 #ifdef S390 205 // There are 3 operand shifts on S390 (see LIR_Assembler::shift_op()). 206 threeOperandForm = 207 code() == lir_shl || 208 ((code() == lir_shr || code() == lir_ushr) && (result_opr()->is_double_cpu() || in_opr1()->type() == T_OBJECT)); 209 #endif 210 #endif 211 212 switch (code()) { 213 case lir_add: 214 case lir_sub: 215 case lir_mul: 216 case lir_div: 217 case lir_rem: 218 case lir_logic_and: 219 case lir_logic_or: 220 case lir_logic_xor: 221 case lir_shl: 222 case lir_shr: 223 assert(in_opr1() == result_opr() || threeOperandForm, "opr1 and result must match"); 224 assert(in_opr1()->is_valid() && in_opr2()->is_valid(), "must be valid"); 225 break; 226 227 // special handling for lir_ushr because of write barriers 228 case lir_ushr: 229 assert(in_opr1() == result_opr() || in_opr2()->is_constant() || threeOperandForm, "opr1 and result must match or shift count is constant"); 230 assert(in_opr1()->is_valid() && in_opr2()->is_valid(), "must be valid"); 231 break; 232 233 default: 234 break; 235 } 236 } 237 #endif 238 } 239 240 241 LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, BlockBegin* block) 242 : LIR_Op2(lir_branch, cond, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, (CodeEmitInfo*)nullptr) 243 , _label(block->label()) 244 , _block(block) 245 , _ublock(nullptr) 246 , _stub(nullptr) { 247 } 248 249 LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, CodeStub* stub) : 250 LIR_Op2(lir_branch, cond, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, (CodeEmitInfo*)nullptr) 251 , _label(stub->entry()) 252 , _block(nullptr) 253 , _ublock(nullptr) 254 , _stub(stub) { 255 } 256 257 LIR_OpBranch::LIR_OpBranch(LIR_Condition cond, BlockBegin* block, BlockBegin* ublock) 258 : LIR_Op2(lir_cond_float_branch, cond, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, (CodeEmitInfo*)nullptr) 259 , _label(block->label()) 260 , _block(block) 261 , _ublock(ublock) 262 , _stub(nullptr) 263 { 264 } 265 266 void LIR_OpBranch::change_block(BlockBegin* b) { 267 assert(_block != nullptr, "must have old block"); 268 assert(_block->label() == label(), "must be equal"); 269 270 _block = b; 271 _label = b->label(); 272 } 273 274 void LIR_OpBranch::change_ublock(BlockBegin* b) { 275 assert(_ublock != nullptr, "must have old block"); 276 _ublock = b; 277 } 278 279 void LIR_OpBranch::negate_cond() { 280 switch (cond()) { 281 case lir_cond_equal: set_cond(lir_cond_notEqual); break; 282 case lir_cond_notEqual: set_cond(lir_cond_equal); break; 283 case lir_cond_less: set_cond(lir_cond_greaterEqual); break; 284 case lir_cond_lessEqual: set_cond(lir_cond_greater); break; 285 case lir_cond_greaterEqual: set_cond(lir_cond_less); break; 286 case lir_cond_greater: set_cond(lir_cond_lessEqual); break; 287 default: ShouldNotReachHere(); 288 } 289 } 290 291 292 LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass, 293 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, 294 bool fast_check, CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, 295 CodeStub* stub, bool need_null_check) 296 297 : LIR_Op(code, result, nullptr) 298 , _object(object) 299 , _array(LIR_OprFact::illegalOpr) 300 , _klass(klass) 301 , _tmp1(tmp1) 302 , _tmp2(tmp2) 303 , _tmp3(tmp3) 304 , _fast_check(fast_check) 305 , _info_for_patch(info_for_patch) 306 , _info_for_exception(info_for_exception) 307 , _stub(stub) 308 , _profiled_method(nullptr) 309 , _profiled_bci(-1) 310 , _should_profile(false) 311 , _need_null_check(need_null_check) 312 { 313 if (code == lir_checkcast) { 314 assert(info_for_exception != nullptr, "checkcast throws exceptions"); 315 } else if (code == lir_instanceof) { 316 assert(info_for_exception == nullptr, "instanceof throws no exceptions"); 317 } else { 318 ShouldNotReachHere(); 319 } 320 } 321 322 323 324 LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception) 325 : LIR_Op(code, LIR_OprFact::illegalOpr, nullptr) 326 , _object(object) 327 , _array(array) 328 , _klass(nullptr) 329 , _tmp1(tmp1) 330 , _tmp2(tmp2) 331 , _tmp3(tmp3) 332 , _fast_check(false) 333 , _info_for_patch(nullptr) 334 , _info_for_exception(info_for_exception) 335 , _stub(nullptr) 336 , _profiled_method(nullptr) 337 , _profiled_bci(-1) 338 , _should_profile(false) 339 , _need_null_check(true) 340 { 341 if (code == lir_store_check) { 342 _stub = new ArrayStoreExceptionStub(object, info_for_exception); 343 assert(info_for_exception != nullptr, "store_check throws exceptions"); 344 } else { 345 ShouldNotReachHere(); 346 } 347 } 348 349 LIR_OpFlattenedArrayCheck::LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub) 350 : LIR_Op(lir_flat_array_check, LIR_OprFact::illegalOpr, nullptr) 351 , _array(array) 352 , _value(value) 353 , _tmp(tmp) 354 , _stub(stub) {} 355 356 357 LIR_OpNullFreeArrayCheck::LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp) 358 : LIR_Op(lir_null_free_array_check, LIR_OprFact::illegalOpr, nullptr) 359 , _array(array) 360 , _tmp(tmp) {} 361 362 363 LIR_OpSubstitutabilityCheck::LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result, 364 LIR_Opr tmp1, LIR_Opr tmp2, 365 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op, 366 CodeEmitInfo* info, CodeStub* stub) 367 : LIR_Op(lir_substitutability_check, result, info) 368 , _left(left) 369 , _right(right) 370 , _equal_result(equal_result) 371 , _not_equal_result(not_equal_result) 372 , _tmp1(tmp1) 373 , _tmp2(tmp2) 374 , _left_klass(left_klass) 375 , _right_klass(right_klass) 376 , _left_klass_op(left_klass_op) 377 , _right_klass_op(right_klass_op) 378 , _stub(stub) {} 379 380 381 LIR_OpArrayCopy::LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, 382 LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info) 383 : LIR_Op(lir_arraycopy, LIR_OprFact::illegalOpr, info) 384 , _src(src) 385 , _src_pos(src_pos) 386 , _dst(dst) 387 , _dst_pos(dst_pos) 388 , _length(length) 389 , _tmp(tmp) 390 , _expected_type(expected_type) 391 , _flags(flags) { 392 _stub = new ArrayCopyStub(this); 393 } 394 395 LIR_OpUpdateCRC32::LIR_OpUpdateCRC32(LIR_Opr crc, LIR_Opr val, LIR_Opr res) 396 : LIR_Op(lir_updatecrc32, res, nullptr) 397 , _crc(crc) 398 , _val(val) { 399 } 400 401 //-------------------verify-------------------------- 402 403 void LIR_Op1::verify() const { 404 switch(code()) { 405 case lir_move: 406 assert(in_opr()->is_valid() && result_opr()->is_valid(), "must be"); 407 break; 408 case lir_null_check: 409 assert(in_opr()->is_register(), "must be"); 410 break; 411 case lir_return: 412 assert(in_opr()->is_register() || in_opr()->is_illegal(), "must be"); 413 break; 414 default: 415 break; 416 } 417 } 418 419 void LIR_OpRTCall::verify() const { 420 assert(strcmp(Runtime1::name_for_address(addr()), "<unknown function>") != 0, "unknown function"); 421 } 422 423 //-------------------visits-------------------------- 424 425 // complete rework of LIR instruction visitor. 426 // The virtual call for each instruction type is replaced by a big 427 // switch that adds the operands for each instruction 428 429 void LIR_OpVisitState::visit(LIR_Op* op) { 430 // copy information from the LIR_Op 431 reset(); 432 set_op(op); 433 434 switch (op->code()) { 435 436 // LIR_Op0 437 case lir_fpop_raw: // result and info always invalid 438 case lir_breakpoint: // result and info always invalid 439 case lir_membar: // result and info always invalid 440 case lir_membar_acquire: // result and info always invalid 441 case lir_membar_release: // result and info always invalid 442 case lir_membar_loadload: // result and info always invalid 443 case lir_membar_storestore: // result and info always invalid 444 case lir_membar_loadstore: // result and info always invalid 445 case lir_membar_storeload: // result and info always invalid 446 case lir_check_orig_pc: // result and info always invalid 447 case lir_on_spin_wait: 448 { 449 assert(op->as_Op0() != nullptr, "must be"); 450 assert(op->_info == nullptr, "info not used by this instruction"); 451 assert(op->_result->is_illegal(), "not used"); 452 break; 453 } 454 455 case lir_nop: // may have info, result always invalid 456 case lir_std_entry: // may have result, info always invalid 457 case lir_osr_entry: // may have result, info always invalid 458 case lir_get_thread: // may have result, info always invalid 459 { 460 assert(op->as_Op0() != nullptr, "must be"); 461 if (op->_info != nullptr) do_info(op->_info); 462 if (op->_result->is_valid()) do_output(op->_result); 463 break; 464 } 465 466 467 // LIR_OpLabel 468 case lir_label: // result and info always invalid 469 { 470 assert(op->as_OpLabel() != nullptr, "must be"); 471 assert(op->_info == nullptr, "info not used by this instruction"); 472 assert(op->_result->is_illegal(), "not used"); 473 break; 474 } 475 476 477 // LIR_Op1 478 case lir_fxch: // input always valid, result and info always invalid 479 case lir_fld: // input always valid, result and info always invalid 480 case lir_push: // input always valid, result and info always invalid 481 case lir_pop: // input always valid, result and info always invalid 482 case lir_leal: // input and result always valid, info always invalid 483 case lir_monaddr: // input and result always valid, info always invalid 484 case lir_null_check: // input and info always valid, result always invalid 485 case lir_move: // input and result always valid, may have info 486 { 487 assert(op->as_Op1() != nullptr, "must be"); 488 LIR_Op1* op1 = (LIR_Op1*)op; 489 490 if (op1->_info) do_info(op1->_info); 491 if (op1->_opr->is_valid()) do_input(op1->_opr); 492 if (op1->_result->is_valid()) do_output(op1->_result); 493 494 break; 495 } 496 497 case lir_return: 498 { 499 assert(op->as_OpReturn() != nullptr, "must be"); 500 LIR_OpReturn* op_ret = (LIR_OpReturn*)op; 501 502 if (op_ret->_info) do_info(op_ret->_info); 503 if (op_ret->_opr->is_valid()) do_input(op_ret->_opr); 504 if (op_ret->_result->is_valid()) do_output(op_ret->_result); 505 if (op_ret->stub() != nullptr) do_stub(op_ret->stub()); 506 507 break; 508 } 509 510 case lir_safepoint: 511 { 512 assert(op->as_Op1() != nullptr, "must be"); 513 LIR_Op1* op1 = (LIR_Op1*)op; 514 515 assert(op1->_info != nullptr, ""); do_info(op1->_info); 516 if (op1->_opr->is_valid()) do_temp(op1->_opr); // safepoints on SPARC need temporary register 517 assert(op1->_result->is_illegal(), "safepoint does not produce value"); 518 519 break; 520 } 521 522 // LIR_OpConvert; 523 case lir_convert: // input and result always valid, info always invalid 524 { 525 assert(op->as_OpConvert() != nullptr, "must be"); 526 LIR_OpConvert* opConvert = (LIR_OpConvert*)op; 527 528 assert(opConvert->_info == nullptr, "must be"); 529 if (opConvert->_opr->is_valid()) do_input(opConvert->_opr); 530 if (opConvert->_result->is_valid()) do_output(opConvert->_result); 531 do_stub(opConvert->_stub); 532 533 break; 534 } 535 536 // LIR_OpBranch; 537 case lir_branch: // may have info, input and result register always invalid 538 case lir_cond_float_branch: // may have info, input and result register always invalid 539 { 540 assert(op->as_OpBranch() != nullptr, "must be"); 541 LIR_OpBranch* opBranch = (LIR_OpBranch*)op; 542 543 assert(opBranch->_tmp1->is_illegal() && opBranch->_tmp2->is_illegal() && 544 opBranch->_tmp3->is_illegal() && opBranch->_tmp4->is_illegal() && 545 opBranch->_tmp5->is_illegal(), "not used"); 546 547 if (opBranch->_opr1->is_valid()) do_input(opBranch->_opr1); 548 if (opBranch->_opr2->is_valid()) do_input(opBranch->_opr2); 549 550 if (opBranch->_info != nullptr) do_info(opBranch->_info); 551 assert(opBranch->_result->is_illegal(), "not used"); 552 if (opBranch->_stub != nullptr) opBranch->stub()->visit(this); 553 554 break; 555 } 556 557 558 // LIR_OpAllocObj 559 case lir_alloc_object: 560 { 561 assert(op->as_OpAllocObj() != nullptr, "must be"); 562 LIR_OpAllocObj* opAllocObj = (LIR_OpAllocObj*)op; 563 564 if (opAllocObj->_info) do_info(opAllocObj->_info); 565 if (opAllocObj->_opr->is_valid()) { do_input(opAllocObj->_opr); 566 do_temp(opAllocObj->_opr); 567 } 568 if (opAllocObj->_tmp1->is_valid()) do_temp(opAllocObj->_tmp1); 569 if (opAllocObj->_tmp2->is_valid()) do_temp(opAllocObj->_tmp2); 570 if (opAllocObj->_tmp3->is_valid()) do_temp(opAllocObj->_tmp3); 571 if (opAllocObj->_tmp4->is_valid()) do_temp(opAllocObj->_tmp4); 572 if (opAllocObj->_result->is_valid()) do_output(opAllocObj->_result); 573 if (opAllocObj->_stub != nullptr) do_stub(opAllocObj->_stub); 574 break; 575 } 576 577 578 // LIR_OpRoundFP; 579 case lir_roundfp: { 580 assert(op->as_OpRoundFP() != nullptr, "must be"); 581 LIR_OpRoundFP* opRoundFP = (LIR_OpRoundFP*)op; 582 583 assert(op->_info == nullptr, "info not used by this instruction"); 584 assert(opRoundFP->_tmp->is_illegal(), "not used"); 585 do_input(opRoundFP->_opr); 586 do_output(opRoundFP->_result); 587 588 break; 589 } 590 591 592 // LIR_Op2 593 case lir_cmp: 594 case lir_cmp_l2i: 595 case lir_ucmp_fd2i: 596 case lir_cmp_fd2i: 597 case lir_add: 598 case lir_sub: 599 case lir_rem: 600 case lir_sqrt: 601 case lir_abs: 602 case lir_neg: 603 case lir_f2hf: 604 case lir_hf2f: 605 case lir_logic_and: 606 case lir_logic_or: 607 case lir_logic_xor: 608 case lir_shl: 609 case lir_shr: 610 case lir_ushr: 611 case lir_xadd: 612 case lir_xchg: 613 case lir_assert: 614 { 615 assert(op->as_Op2() != nullptr, "must be"); 616 LIR_Op2* op2 = (LIR_Op2*)op; 617 assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() && 618 op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used"); 619 620 if (op2->_info) do_info(op2->_info); 621 if (op2->_opr1->is_valid()) do_input(op2->_opr1); 622 if (op2->_opr2->is_valid()) do_input(op2->_opr2); 623 if (op2->_tmp1->is_valid()) do_temp(op2->_tmp1); 624 if (op2->_result->is_valid()) do_output(op2->_result); 625 if (op->code() == lir_xchg || op->code() == lir_xadd) { 626 // on ARM and PPC, return value is loaded first so could 627 // destroy inputs. On other platforms that implement those 628 // (x86, sparc), the extra constrainsts are harmless. 629 if (op2->_opr1->is_valid()) do_temp(op2->_opr1); 630 if (op2->_opr2->is_valid()) do_temp(op2->_opr2); 631 } 632 633 break; 634 } 635 636 // special handling for cmove: right input operand must not be equal 637 // to the result operand, otherwise the backend fails 638 case lir_cmove: 639 { 640 assert(op->as_Op4() != nullptr, "must be"); 641 LIR_Op4* op4 = (LIR_Op4*)op; 642 643 assert(op4->_info == nullptr && op4->_tmp1->is_illegal() && op4->_tmp2->is_illegal() && 644 op4->_tmp3->is_illegal() && op4->_tmp4->is_illegal() && op4->_tmp5->is_illegal(), "not used"); 645 assert(op4->_opr1->is_valid() && op4->_opr2->is_valid() && op4->_result->is_valid(), "used"); 646 647 do_input(op4->_opr1); 648 do_input(op4->_opr2); 649 if (op4->_opr3->is_valid()) do_input(op4->_opr3); 650 if (op4->_opr4->is_valid()) do_input(op4->_opr4); 651 do_temp(op4->_opr2); 652 do_output(op4->_result); 653 654 break; 655 } 656 657 // vspecial handling for strict operations: register input operands 658 // as temp to guarantee that they do not overlap with other 659 // registers 660 case lir_mul: 661 case lir_div: 662 { 663 assert(op->as_Op2() != nullptr, "must be"); 664 LIR_Op2* op2 = (LIR_Op2*)op; 665 666 assert(op2->_info == nullptr, "not used"); 667 assert(op2->_opr1->is_valid(), "used"); 668 assert(op2->_opr2->is_valid(), "used"); 669 assert(op2->_result->is_valid(), "used"); 670 assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() && 671 op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used"); 672 673 do_input(op2->_opr1); do_temp(op2->_opr1); 674 do_input(op2->_opr2); do_temp(op2->_opr2); 675 if (op2->_tmp1->is_valid()) do_temp(op2->_tmp1); 676 do_output(op2->_result); 677 678 break; 679 } 680 681 case lir_throw: { 682 assert(op->as_Op2() != nullptr, "must be"); 683 LIR_Op2* op2 = (LIR_Op2*)op; 684 685 if (op2->_info) do_info(op2->_info); 686 if (op2->_opr1->is_valid()) do_temp(op2->_opr1); 687 if (op2->_opr2->is_valid()) do_input(op2->_opr2); // exception object is input parameter 688 assert(op2->_result->is_illegal(), "no result"); 689 assert(op2->_tmp2->is_illegal() && op2->_tmp3->is_illegal() && 690 op2->_tmp4->is_illegal() && op2->_tmp5->is_illegal(), "not used"); 691 692 break; 693 } 694 695 case lir_unwind: { 696 assert(op->as_Op1() != nullptr, "must be"); 697 LIR_Op1* op1 = (LIR_Op1*)op; 698 699 assert(op1->_info == nullptr, "no info"); 700 assert(op1->_opr->is_valid(), "exception oop"); do_input(op1->_opr); 701 assert(op1->_result->is_illegal(), "no result"); 702 703 break; 704 } 705 706 // LIR_Op3 707 case lir_idiv: 708 case lir_irem: { 709 assert(op->as_Op3() != nullptr, "must be"); 710 LIR_Op3* op3= (LIR_Op3*)op; 711 712 if (op3->_info) do_info(op3->_info); 713 if (op3->_opr1->is_valid()) do_input(op3->_opr1); 714 715 // second operand is input and temp, so ensure that second operand 716 // and third operand get not the same register 717 if (op3->_opr2->is_valid()) do_input(op3->_opr2); 718 if (op3->_opr2->is_valid()) do_temp(op3->_opr2); 719 if (op3->_opr3->is_valid()) do_temp(op3->_opr3); 720 721 if (op3->_result->is_valid()) do_output(op3->_result); 722 723 break; 724 } 725 726 case lir_fmad: 727 case lir_fmaf: { 728 assert(op->as_Op3() != nullptr, "must be"); 729 LIR_Op3* op3= (LIR_Op3*)op; 730 assert(op3->_info == nullptr, "no info"); 731 do_input(op3->_opr1); 732 do_input(op3->_opr2); 733 do_input(op3->_opr3); 734 do_output(op3->_result); 735 break; 736 } 737 738 // LIR_OpJavaCall 739 case lir_static_call: 740 case lir_optvirtual_call: 741 case lir_icvirtual_call: 742 case lir_dynamic_call: { 743 LIR_OpJavaCall* opJavaCall = op->as_OpJavaCall(); 744 assert(opJavaCall != nullptr, "must be"); 745 746 if (opJavaCall->_receiver->is_valid()) do_input(opJavaCall->_receiver); 747 748 // only visit register parameters 749 int n = opJavaCall->_arguments->length(); 750 for (int i = opJavaCall->_receiver->is_valid() ? 1 : 0; i < n; i++) { 751 if (!opJavaCall->_arguments->at(i)->is_pointer()) { 752 do_input(*opJavaCall->_arguments->adr_at(i)); 753 } 754 } 755 756 if (opJavaCall->_info) do_info(opJavaCall->_info); 757 if (FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr && 758 opJavaCall->is_method_handle_invoke()) { 759 opJavaCall->_method_handle_invoke_SP_save_opr = FrameMap::method_handle_invoke_SP_save_opr(); 760 do_temp(opJavaCall->_method_handle_invoke_SP_save_opr); 761 } 762 do_call(); 763 if (opJavaCall->_result->is_valid()) do_output(opJavaCall->_result); 764 765 break; 766 } 767 768 769 // LIR_OpRTCall 770 case lir_rtcall: { 771 assert(op->as_OpRTCall() != nullptr, "must be"); 772 LIR_OpRTCall* opRTCall = (LIR_OpRTCall*)op; 773 774 // only visit register parameters 775 int n = opRTCall->_arguments->length(); 776 for (int i = 0; i < n; i++) { 777 if (!opRTCall->_arguments->at(i)->is_pointer()) { 778 do_input(*opRTCall->_arguments->adr_at(i)); 779 } 780 } 781 if (opRTCall->_info) do_info(opRTCall->_info); 782 if (opRTCall->_tmp->is_valid()) do_temp(opRTCall->_tmp); 783 do_call(); 784 if (opRTCall->_result->is_valid()) do_output(opRTCall->_result); 785 786 break; 787 } 788 789 790 // LIR_OpArrayCopy 791 case lir_arraycopy: { 792 assert(op->as_OpArrayCopy() != nullptr, "must be"); 793 LIR_OpArrayCopy* opArrayCopy = (LIR_OpArrayCopy*)op; 794 795 assert(opArrayCopy->_result->is_illegal(), "unused"); 796 assert(opArrayCopy->_src->is_valid(), "used"); do_input(opArrayCopy->_src); do_temp(opArrayCopy->_src); 797 assert(opArrayCopy->_src_pos->is_valid(), "used"); do_input(opArrayCopy->_src_pos); do_temp(opArrayCopy->_src_pos); 798 assert(opArrayCopy->_dst->is_valid(), "used"); do_input(opArrayCopy->_dst); do_temp(opArrayCopy->_dst); 799 assert(opArrayCopy->_dst_pos->is_valid(), "used"); do_input(opArrayCopy->_dst_pos); do_temp(opArrayCopy->_dst_pos); 800 assert(opArrayCopy->_length->is_valid(), "used"); do_input(opArrayCopy->_length); do_temp(opArrayCopy->_length); 801 assert(opArrayCopy->_tmp->is_valid(), "used"); do_temp(opArrayCopy->_tmp); 802 if (opArrayCopy->_info) do_info(opArrayCopy->_info); 803 804 // the implementation of arraycopy always has a call into the runtime 805 do_call(); 806 807 break; 808 } 809 810 811 // LIR_OpUpdateCRC32 812 case lir_updatecrc32: { 813 assert(op->as_OpUpdateCRC32() != nullptr, "must be"); 814 LIR_OpUpdateCRC32* opUp = (LIR_OpUpdateCRC32*)op; 815 816 assert(opUp->_crc->is_valid(), "used"); do_input(opUp->_crc); do_temp(opUp->_crc); 817 assert(opUp->_val->is_valid(), "used"); do_input(opUp->_val); do_temp(opUp->_val); 818 assert(opUp->_result->is_valid(), "used"); do_output(opUp->_result); 819 assert(opUp->_info == nullptr, "no info for LIR_OpUpdateCRC32"); 820 821 break; 822 } 823 824 825 // LIR_OpLock 826 case lir_lock: 827 case lir_unlock: { 828 assert(op->as_OpLock() != nullptr, "must be"); 829 LIR_OpLock* opLock = (LIR_OpLock*)op; 830 831 if (opLock->_info) do_info(opLock->_info); 832 833 // TODO: check if these operands really have to be temp 834 // (or if input is sufficient). This may have influence on the oop map! 835 assert(opLock->_lock->is_valid(), "used"); do_temp(opLock->_lock); 836 assert(opLock->_hdr->is_valid(), "used"); do_temp(opLock->_hdr); 837 assert(opLock->_obj->is_valid(), "used"); do_temp(opLock->_obj); 838 839 if (opLock->_scratch->is_valid()) do_temp(opLock->_scratch); 840 assert(opLock->_result->is_illegal(), "unused"); 841 842 do_stub(opLock->_stub); 843 do_stub(opLock->_throw_imse_stub); 844 845 break; 846 } 847 848 849 // LIR_OpDelay 850 case lir_delay_slot: { 851 assert(op->as_OpDelay() != nullptr, "must be"); 852 LIR_OpDelay* opDelay = (LIR_OpDelay*)op; 853 854 visit(opDelay->delay_op()); 855 break; 856 } 857 858 // LIR_OpTypeCheck 859 case lir_instanceof: 860 case lir_checkcast: 861 case lir_store_check: { 862 assert(op->as_OpTypeCheck() != nullptr, "must be"); 863 LIR_OpTypeCheck* opTypeCheck = (LIR_OpTypeCheck*)op; 864 865 if (opTypeCheck->_info_for_exception) do_info(opTypeCheck->_info_for_exception); 866 if (opTypeCheck->_info_for_patch) do_info(opTypeCheck->_info_for_patch); 867 if (opTypeCheck->_object->is_valid()) do_input(opTypeCheck->_object); 868 if (op->code() == lir_store_check && opTypeCheck->_object->is_valid()) { 869 do_temp(opTypeCheck->_object); 870 } 871 if (opTypeCheck->_array->is_valid()) do_input(opTypeCheck->_array); 872 if (opTypeCheck->_tmp1->is_valid()) do_temp(opTypeCheck->_tmp1); 873 if (opTypeCheck->_tmp2->is_valid()) do_temp(opTypeCheck->_tmp2); 874 if (opTypeCheck->_tmp3->is_valid()) do_temp(opTypeCheck->_tmp3); 875 if (opTypeCheck->_result->is_valid()) do_output(opTypeCheck->_result); 876 if (opTypeCheck->_stub != nullptr) do_stub(opTypeCheck->_stub); 877 break; 878 } 879 880 // LIR_OpFlattenedArrayCheck 881 case lir_flat_array_check: { 882 assert(op->as_OpFlattenedArrayCheck() != nullptr, "must be"); 883 LIR_OpFlattenedArrayCheck* opFlattenedArrayCheck = (LIR_OpFlattenedArrayCheck*)op; 884 885 if (opFlattenedArrayCheck->_array->is_valid()) do_input(opFlattenedArrayCheck->_array); 886 if (opFlattenedArrayCheck->_value->is_valid()) do_input(opFlattenedArrayCheck->_value); 887 if (opFlattenedArrayCheck->_tmp->is_valid()) do_temp(opFlattenedArrayCheck->_tmp); 888 889 do_stub(opFlattenedArrayCheck->_stub); 890 891 break; 892 } 893 894 // LIR_OpNullFreeArrayCheck 895 case lir_null_free_array_check: { 896 assert(op->as_OpNullFreeArrayCheck() != nullptr, "must be"); 897 LIR_OpNullFreeArrayCheck* opNullFreeArrayCheck = (LIR_OpNullFreeArrayCheck*)op; 898 899 if (opNullFreeArrayCheck->_array->is_valid()) do_input(opNullFreeArrayCheck->_array); 900 if (opNullFreeArrayCheck->_tmp->is_valid()) do_temp(opNullFreeArrayCheck->_tmp); 901 break; 902 } 903 904 // LIR_OpSubstitutabilityCheck 905 case lir_substitutability_check: { 906 assert(op->as_OpSubstitutabilityCheck() != nullptr, "must be"); 907 LIR_OpSubstitutabilityCheck* opSubstitutabilityCheck = (LIR_OpSubstitutabilityCheck*)op; 908 do_input(opSubstitutabilityCheck->_left); 909 do_temp (opSubstitutabilityCheck->_left); 910 do_input(opSubstitutabilityCheck->_right); 911 do_temp (opSubstitutabilityCheck->_right); 912 do_input(opSubstitutabilityCheck->_equal_result); 913 do_temp (opSubstitutabilityCheck->_equal_result); 914 do_input(opSubstitutabilityCheck->_not_equal_result); 915 do_temp (opSubstitutabilityCheck->_not_equal_result); 916 if (opSubstitutabilityCheck->_tmp1->is_valid()) do_temp(opSubstitutabilityCheck->_tmp1); 917 if (opSubstitutabilityCheck->_tmp2->is_valid()) do_temp(opSubstitutabilityCheck->_tmp2); 918 if (opSubstitutabilityCheck->_left_klass_op->is_valid()) do_temp(opSubstitutabilityCheck->_left_klass_op); 919 if (opSubstitutabilityCheck->_right_klass_op->is_valid()) do_temp(opSubstitutabilityCheck->_right_klass_op); 920 if (opSubstitutabilityCheck->_result->is_valid()) do_output(opSubstitutabilityCheck->_result); 921 922 do_info(opSubstitutabilityCheck->_info); 923 do_stub(opSubstitutabilityCheck->_stub); 924 break; 925 } 926 927 // LIR_OpCompareAndSwap 928 case lir_cas_long: 929 case lir_cas_obj: 930 case lir_cas_int: { 931 assert(op->as_OpCompareAndSwap() != nullptr, "must be"); 932 LIR_OpCompareAndSwap* opCmpAndSwap = (LIR_OpCompareAndSwap*)op; 933 934 if (opCmpAndSwap->_info) do_info(opCmpAndSwap->_info); 935 assert(opCmpAndSwap->_addr->is_valid(), "used"); do_input(opCmpAndSwap->_addr); 936 do_temp(opCmpAndSwap->_addr); 937 assert(opCmpAndSwap->_cmp_value->is_valid(), "used"); do_input(opCmpAndSwap->_cmp_value); 938 do_temp(opCmpAndSwap->_cmp_value); 939 assert(opCmpAndSwap->_new_value->is_valid(), "used"); do_input(opCmpAndSwap->_new_value); 940 do_temp(opCmpAndSwap->_new_value); 941 if (opCmpAndSwap->_tmp1->is_valid()) do_temp(opCmpAndSwap->_tmp1); 942 if (opCmpAndSwap->_tmp2->is_valid()) do_temp(opCmpAndSwap->_tmp2); 943 if (opCmpAndSwap->_result->is_valid()) do_output(opCmpAndSwap->_result); 944 945 break; 946 } 947 948 949 // LIR_OpAllocArray; 950 case lir_alloc_array: { 951 assert(op->as_OpAllocArray() != nullptr, "must be"); 952 LIR_OpAllocArray* opAllocArray = (LIR_OpAllocArray*)op; 953 954 if (opAllocArray->_info) do_info(opAllocArray->_info); 955 if (opAllocArray->_klass->is_valid()) { do_input(opAllocArray->_klass); 956 do_temp(opAllocArray->_klass); 957 } 958 if (opAllocArray->_len->is_valid()) { do_input(opAllocArray->_len); 959 do_temp(opAllocArray->_len); 960 } 961 if (opAllocArray->_tmp1->is_valid()) do_temp(opAllocArray->_tmp1); 962 if (opAllocArray->_tmp2->is_valid()) do_temp(opAllocArray->_tmp2); 963 if (opAllocArray->_tmp3->is_valid()) do_temp(opAllocArray->_tmp3); 964 if (opAllocArray->_tmp4->is_valid()) do_temp(opAllocArray->_tmp4); 965 if (opAllocArray->_result->is_valid()) do_output(opAllocArray->_result); 966 if (opAllocArray->_stub != nullptr) do_stub(opAllocArray->_stub); 967 break; 968 } 969 970 // LIR_OpLoadKlass 971 case lir_load_klass: 972 { 973 LIR_OpLoadKlass* opLoadKlass = op->as_OpLoadKlass(); 974 assert(opLoadKlass != nullptr, "must be"); 975 976 do_input(opLoadKlass->_obj); 977 do_output(opLoadKlass->_result); 978 if (opLoadKlass->_info) do_info(opLoadKlass->_info); 979 break; 980 } 981 982 983 // LIR_OpProfileCall: 984 case lir_profile_call: { 985 assert(op->as_OpProfileCall() != nullptr, "must be"); 986 LIR_OpProfileCall* opProfileCall = (LIR_OpProfileCall*)op; 987 988 if (opProfileCall->_recv->is_valid()) do_temp(opProfileCall->_recv); 989 assert(opProfileCall->_mdo->is_valid(), "used"); do_temp(opProfileCall->_mdo); 990 assert(opProfileCall->_tmp1->is_valid(), "used"); do_temp(opProfileCall->_tmp1); 991 break; 992 } 993 994 // LIR_OpProfileType: 995 case lir_profile_type: { 996 assert(op->as_OpProfileType() != nullptr, "must be"); 997 LIR_OpProfileType* opProfileType = (LIR_OpProfileType*)op; 998 999 do_input(opProfileType->_mdp); do_temp(opProfileType->_mdp); 1000 do_input(opProfileType->_obj); 1001 do_temp(opProfileType->_tmp); 1002 break; 1003 } 1004 1005 // LIR_OpProfileInlineType: 1006 case lir_profile_inline_type: { 1007 assert(op->as_OpProfileInlineType() != nullptr, "must be"); 1008 LIR_OpProfileInlineType* opProfileInlineType = (LIR_OpProfileInlineType*)op; 1009 1010 do_input(opProfileInlineType->_mdp); do_temp(opProfileInlineType->_mdp); 1011 do_input(opProfileInlineType->_obj); 1012 do_temp(opProfileInlineType->_tmp); 1013 break; 1014 } 1015 default: 1016 op->visit(this); 1017 } 1018 } 1019 1020 void LIR_Op::visit(LIR_OpVisitState* state) { 1021 ShouldNotReachHere(); 1022 } 1023 1024 void LIR_OpVisitState::do_stub(CodeStub* stub) { 1025 if (stub != nullptr) { 1026 stub->visit(this); 1027 } 1028 } 1029 1030 XHandlers* LIR_OpVisitState::all_xhandler() { 1031 XHandlers* result = nullptr; 1032 1033 int i; 1034 for (i = 0; i < info_count(); i++) { 1035 if (info_at(i)->exception_handlers() != nullptr) { 1036 result = info_at(i)->exception_handlers(); 1037 break; 1038 } 1039 } 1040 1041 #ifdef ASSERT 1042 for (i = 0; i < info_count(); i++) { 1043 assert(info_at(i)->exception_handlers() == nullptr || 1044 info_at(i)->exception_handlers() == result, 1045 "only one xhandler list allowed per LIR-operation"); 1046 } 1047 #endif 1048 1049 if (result != nullptr) { 1050 return result; 1051 } else { 1052 return new XHandlers(); 1053 } 1054 1055 return result; 1056 } 1057 1058 1059 #ifdef ASSERT 1060 bool LIR_OpVisitState::no_operands(LIR_Op* op) { 1061 visit(op); 1062 1063 return opr_count(inputMode) == 0 && 1064 opr_count(outputMode) == 0 && 1065 opr_count(tempMode) == 0 && 1066 info_count() == 0 && 1067 !has_call() && 1068 !has_slow_case(); 1069 } 1070 #endif 1071 1072 // LIR_OpReturn 1073 LIR_OpReturn::LIR_OpReturn(LIR_Opr opr) : 1074 LIR_Op1(lir_return, opr, (CodeEmitInfo*)nullptr /* info */), 1075 _stub(nullptr) { 1076 if (VM_Version::supports_stack_watermark_barrier()) { 1077 _stub = new C1SafepointPollStub(); 1078 } 1079 } 1080 1081 //--------------------------------------------------- 1082 1083 1084 void LIR_OpJavaCall::emit_code(LIR_Assembler* masm) { 1085 masm->emit_call(this); 1086 } 1087 1088 bool LIR_OpJavaCall::maybe_return_as_fields(ciInlineKlass** vk_ret) const { 1089 ciType* return_type = method()->return_type(); 1090 if (InlineTypeReturnedAsFields) { 1091 if (return_type->is_inlinetype()) { 1092 ciInlineKlass* vk = return_type->as_inline_klass(); 1093 if (vk->can_be_returned_as_fields()) { 1094 if (vk_ret != nullptr) { 1095 *vk_ret = vk; 1096 } 1097 return true; 1098 } 1099 } else if (return_type->is_instance_klass() && 1100 (method()->is_method_handle_intrinsic() || !return_type->is_loaded() || 1101 StressCallingConvention)) { 1102 // An inline type might be returned from the call but we don't know its type. 1103 // This can happen with method handle intrinsics or when the return type is 1104 // not loaded (method holder is not loaded or preload attribute is missing). 1105 // If an inline type is returned, we either get an oop to a buffer and nothing 1106 // needs to be done or one of the values being returned is the klass of the 1107 // inline type (RAX on x64, with LSB set to 1) and we need to allocate an inline 1108 // type instance of that type and initialize it with the fields values being 1109 // returned in other registers. 1110 return true; 1111 } 1112 } 1113 return false; 1114 } 1115 1116 void LIR_OpRTCall::emit_code(LIR_Assembler* masm) { 1117 masm->emit_rtcall(this); 1118 } 1119 1120 void LIR_OpLabel::emit_code(LIR_Assembler* masm) { 1121 masm->emit_opLabel(this); 1122 } 1123 1124 void LIR_OpArrayCopy::emit_code(LIR_Assembler* masm) { 1125 masm->emit_arraycopy(this); 1126 masm->append_code_stub(stub()); 1127 } 1128 1129 void LIR_OpUpdateCRC32::emit_code(LIR_Assembler* masm) { 1130 masm->emit_updatecrc32(this); 1131 } 1132 1133 void LIR_Op0::emit_code(LIR_Assembler* masm) { 1134 masm->emit_op0(this); 1135 } 1136 1137 void LIR_Op1::emit_code(LIR_Assembler* masm) { 1138 masm->emit_op1(this); 1139 } 1140 1141 void LIR_OpAllocObj::emit_code(LIR_Assembler* masm) { 1142 masm->emit_alloc_obj(this); 1143 masm->append_code_stub(stub()); 1144 } 1145 1146 void LIR_OpBranch::emit_code(LIR_Assembler* masm) { 1147 masm->emit_opBranch(this); 1148 if (stub()) { 1149 masm->append_code_stub(stub()); 1150 } 1151 } 1152 1153 void LIR_OpConvert::emit_code(LIR_Assembler* masm) { 1154 masm->emit_opConvert(this); 1155 if (stub() != nullptr) { 1156 masm->append_code_stub(stub()); 1157 } 1158 } 1159 1160 void LIR_Op2::emit_code(LIR_Assembler* masm) { 1161 masm->emit_op2(this); 1162 } 1163 1164 void LIR_OpAllocArray::emit_code(LIR_Assembler* masm) { 1165 masm->emit_alloc_array(this); 1166 masm->append_code_stub(stub()); 1167 } 1168 1169 void LIR_OpTypeCheck::emit_code(LIR_Assembler* masm) { 1170 masm->emit_opTypeCheck(this); 1171 if (stub()) { 1172 masm->append_code_stub(stub()); 1173 } 1174 } 1175 1176 void LIR_OpFlattenedArrayCheck::emit_code(LIR_Assembler* masm) { 1177 masm->emit_opFlattenedArrayCheck(this); 1178 if (stub() != nullptr) { 1179 masm->append_code_stub(stub()); 1180 } 1181 } 1182 1183 void LIR_OpNullFreeArrayCheck::emit_code(LIR_Assembler* masm) { 1184 masm->emit_opNullFreeArrayCheck(this); 1185 } 1186 1187 void LIR_OpSubstitutabilityCheck::emit_code(LIR_Assembler* masm) { 1188 masm->emit_opSubstitutabilityCheck(this); 1189 if (stub() != nullptr) { 1190 masm->append_code_stub(stub()); 1191 } 1192 } 1193 1194 void LIR_OpCompareAndSwap::emit_code(LIR_Assembler* masm) { 1195 masm->emit_compare_and_swap(this); 1196 } 1197 1198 void LIR_Op3::emit_code(LIR_Assembler* masm) { 1199 masm->emit_op3(this); 1200 } 1201 1202 void LIR_Op4::emit_code(LIR_Assembler* masm) { 1203 masm->emit_op4(this); 1204 } 1205 1206 void LIR_OpLock::emit_code(LIR_Assembler* masm) { 1207 masm->emit_lock(this); 1208 if (stub()) { 1209 masm->append_code_stub(stub()); 1210 } 1211 if (throw_imse_stub()) { 1212 masm->append_code_stub(throw_imse_stub()); 1213 } 1214 } 1215 1216 void LIR_OpLoadKlass::emit_code(LIR_Assembler* masm) { 1217 masm->emit_load_klass(this); 1218 } 1219 1220 #ifdef ASSERT 1221 void LIR_OpAssert::emit_code(LIR_Assembler* masm) { 1222 masm->emit_assert(this); 1223 } 1224 #endif 1225 1226 void LIR_OpDelay::emit_code(LIR_Assembler* masm) { 1227 masm->emit_delay(this); 1228 } 1229 1230 void LIR_OpProfileCall::emit_code(LIR_Assembler* masm) { 1231 masm->emit_profile_call(this); 1232 } 1233 1234 void LIR_OpProfileType::emit_code(LIR_Assembler* masm) { 1235 masm->emit_profile_type(this); 1236 } 1237 1238 void LIR_OpProfileInlineType::emit_code(LIR_Assembler* masm) { 1239 masm->emit_profile_inline_type(this); 1240 } 1241 1242 // LIR_List 1243 LIR_List::LIR_List(Compilation* compilation, BlockBegin* block) 1244 : _operations(8) 1245 , _compilation(compilation) 1246 #ifndef PRODUCT 1247 , _block(block) 1248 #endif 1249 #ifdef ASSERT 1250 , _file(nullptr) 1251 , _line(0) 1252 #endif 1253 #ifdef RISCV 1254 , _cmp_opr1(LIR_OprFact::illegalOpr) 1255 , _cmp_opr2(LIR_OprFact::illegalOpr) 1256 #endif 1257 { } 1258 1259 1260 #ifdef ASSERT 1261 void LIR_List::set_file_and_line(const char * file, int line) { 1262 const char * f = strrchr(file, '/'); 1263 if (f == nullptr) f = strrchr(file, '\\'); 1264 if (f == nullptr) { 1265 f = file; 1266 } else { 1267 f++; 1268 } 1269 _file = f; 1270 _line = line; 1271 } 1272 #endif 1273 1274 #ifdef RISCV 1275 void LIR_List::set_cmp_oprs(LIR_Op* op) { 1276 switch (op->code()) { 1277 case lir_cmp: 1278 _cmp_opr1 = op->as_Op2()->in_opr1(); 1279 _cmp_opr2 = op->as_Op2()->in_opr2(); 1280 break; 1281 case lir_branch: // fall through 1282 case lir_cond_float_branch: 1283 assert(op->as_OpBranch()->cond() == lir_cond_always || 1284 (_cmp_opr1 != LIR_OprFact::illegalOpr && _cmp_opr2 != LIR_OprFact::illegalOpr), 1285 "conditional branches must have legal operands"); 1286 if (op->as_OpBranch()->cond() != lir_cond_always) { 1287 op->as_Op2()->set_in_opr1(_cmp_opr1); 1288 op->as_Op2()->set_in_opr2(_cmp_opr2); 1289 } 1290 break; 1291 case lir_cmove: 1292 op->as_Op4()->set_in_opr3(_cmp_opr1); 1293 op->as_Op4()->set_in_opr4(_cmp_opr2); 1294 break; 1295 case lir_cas_long: 1296 case lir_cas_obj: 1297 case lir_cas_int: 1298 _cmp_opr1 = op->as_OpCompareAndSwap()->result_opr(); 1299 _cmp_opr2 = LIR_OprFact::intConst(0); 1300 break; 1301 #if INCLUDE_ZGC 1302 case lir_xloadbarrier_test: 1303 _cmp_opr1 = FrameMap::as_opr(t1); 1304 _cmp_opr2 = LIR_OprFact::intConst(0); 1305 break; 1306 #endif 1307 default: 1308 break; 1309 } 1310 } 1311 #endif 1312 1313 void LIR_List::append(LIR_InsertionBuffer* buffer) { 1314 assert(this == buffer->lir_list(), "wrong lir list"); 1315 const int n = _operations.length(); 1316 1317 if (buffer->number_of_ops() > 0) { 1318 // increase size of instructions list 1319 _operations.at_grow(n + buffer->number_of_ops() - 1, nullptr); 1320 // insert ops from buffer into instructions list 1321 int op_index = buffer->number_of_ops() - 1; 1322 int ip_index = buffer->number_of_insertion_points() - 1; 1323 int from_index = n - 1; 1324 int to_index = _operations.length() - 1; 1325 for (; ip_index >= 0; ip_index --) { 1326 int index = buffer->index_at(ip_index); 1327 // make room after insertion point 1328 while (index < from_index) { 1329 _operations.at_put(to_index --, _operations.at(from_index --)); 1330 } 1331 // insert ops from buffer 1332 for (int i = buffer->count_at(ip_index); i > 0; i --) { 1333 _operations.at_put(to_index --, buffer->op_at(op_index --)); 1334 } 1335 } 1336 } 1337 1338 buffer->finish(); 1339 } 1340 1341 1342 void LIR_List::oop2reg_patch(jobject o, LIR_Opr reg, CodeEmitInfo* info) { 1343 assert(reg->type() == T_OBJECT, "bad reg"); 1344 append(new LIR_Op1(lir_move, LIR_OprFact::oopConst(o), reg, T_OBJECT, lir_patch_normal, info)); 1345 } 1346 1347 void LIR_List::klass2reg_patch(Metadata* o, LIR_Opr reg, CodeEmitInfo* info) { 1348 assert(reg->type() == T_METADATA, "bad reg"); 1349 append(new LIR_Op1(lir_move, LIR_OprFact::metadataConst(o), reg, T_METADATA, lir_patch_normal, info)); 1350 } 1351 1352 void LIR_List::load(LIR_Address* addr, LIR_Opr src, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1353 append(new LIR_Op1( 1354 lir_move, 1355 LIR_OprFact::address(addr), 1356 src, 1357 addr->type(), 1358 patch_code, 1359 info)); 1360 } 1361 1362 1363 void LIR_List::volatile_load_mem_reg(LIR_Address* address, LIR_Opr dst, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1364 append(new LIR_Op1( 1365 lir_move, 1366 LIR_OprFact::address(address), 1367 dst, 1368 address->type(), 1369 patch_code, 1370 info, lir_move_volatile)); 1371 } 1372 1373 void LIR_List::volatile_load_unsafe_reg(LIR_Opr base, LIR_Opr offset, LIR_Opr dst, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1374 append(new LIR_Op1( 1375 lir_move, 1376 LIR_OprFact::address(new LIR_Address(base, offset, type)), 1377 dst, 1378 type, 1379 patch_code, 1380 info, lir_move_volatile)); 1381 } 1382 1383 1384 void LIR_List::store_mem_int(jint v, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1385 append(new LIR_Op1( 1386 lir_move, 1387 LIR_OprFact::intConst(v), 1388 LIR_OprFact::address(new LIR_Address(base, offset_in_bytes, type)), 1389 type, 1390 patch_code, 1391 info)); 1392 } 1393 1394 1395 void LIR_List::store_mem_oop(jobject o, LIR_Opr base, int offset_in_bytes, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1396 append(new LIR_Op1( 1397 lir_move, 1398 LIR_OprFact::oopConst(o), 1399 LIR_OprFact::address(new LIR_Address(base, offset_in_bytes, type)), 1400 type, 1401 patch_code, 1402 info)); 1403 } 1404 1405 1406 void LIR_List::store(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1407 append(new LIR_Op1( 1408 lir_move, 1409 src, 1410 LIR_OprFact::address(addr), 1411 addr->type(), 1412 patch_code, 1413 info)); 1414 } 1415 1416 1417 void LIR_List::volatile_store_mem_reg(LIR_Opr src, LIR_Address* addr, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1418 append(new LIR_Op1( 1419 lir_move, 1420 src, 1421 LIR_OprFact::address(addr), 1422 addr->type(), 1423 patch_code, 1424 info, 1425 lir_move_volatile)); 1426 } 1427 1428 void LIR_List::volatile_store_unsafe_reg(LIR_Opr src, LIR_Opr base, LIR_Opr offset, BasicType type, CodeEmitInfo* info, LIR_PatchCode patch_code) { 1429 append(new LIR_Op1( 1430 lir_move, 1431 src, 1432 LIR_OprFact::address(new LIR_Address(base, offset, type)), 1433 type, 1434 patch_code, 1435 info, lir_move_volatile)); 1436 } 1437 1438 1439 void LIR_List::idiv(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) { 1440 append(new LIR_Op3( 1441 lir_idiv, 1442 left, 1443 right, 1444 tmp, 1445 res, 1446 info)); 1447 } 1448 1449 1450 void LIR_List::idiv(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) { 1451 append(new LIR_Op3( 1452 lir_idiv, 1453 left, 1454 LIR_OprFact::intConst(right), 1455 tmp, 1456 res, 1457 info)); 1458 } 1459 1460 1461 void LIR_List::irem(LIR_Opr left, LIR_Opr right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) { 1462 append(new LIR_Op3( 1463 lir_irem, 1464 left, 1465 right, 1466 tmp, 1467 res, 1468 info)); 1469 } 1470 1471 1472 void LIR_List::irem(LIR_Opr left, int right, LIR_Opr res, LIR_Opr tmp, CodeEmitInfo* info) { 1473 append(new LIR_Op3( 1474 lir_irem, 1475 left, 1476 LIR_OprFact::intConst(right), 1477 tmp, 1478 res, 1479 info)); 1480 } 1481 1482 1483 void LIR_List::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) { 1484 append(new LIR_Op2( 1485 lir_cmp, 1486 condition, 1487 LIR_OprFact::address(new LIR_Address(base, disp, T_INT)), 1488 LIR_OprFact::intConst(c), 1489 info)); 1490 } 1491 1492 1493 void LIR_List::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Address* addr, CodeEmitInfo* info) { 1494 append(new LIR_Op2( 1495 lir_cmp, 1496 condition, 1497 reg, 1498 LIR_OprFact::address(addr), 1499 info)); 1500 } 1501 1502 void LIR_List::allocate_object(LIR_Opr dst, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4, 1503 int header_size, int object_size, LIR_Opr klass, bool init_check, CodeStub* stub) { 1504 append(new LIR_OpAllocObj( 1505 klass, 1506 dst, 1507 t1, 1508 t2, 1509 t3, 1510 t4, 1511 header_size, 1512 object_size, 1513 init_check, 1514 stub)); 1515 } 1516 1517 void LIR_List::allocate_array(LIR_Opr dst, LIR_Opr len, LIR_Opr t1,LIR_Opr t2, LIR_Opr t3,LIR_Opr t4, BasicType type, LIR_Opr klass, CodeStub* stub) { 1518 append(new LIR_OpAllocArray( 1519 klass, 1520 len, 1521 dst, 1522 t1, 1523 t2, 1524 t3, 1525 t4, 1526 type, 1527 stub)); 1528 } 1529 1530 void LIR_List::shift_left(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) { 1531 append(new LIR_Op2( 1532 lir_shl, 1533 value, 1534 count, 1535 dst, 1536 tmp)); 1537 } 1538 1539 void LIR_List::shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) { 1540 append(new LIR_Op2( 1541 lir_shr, 1542 value, 1543 count, 1544 dst, 1545 tmp)); 1546 } 1547 1548 1549 void LIR_List::unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) { 1550 append(new LIR_Op2( 1551 lir_ushr, 1552 value, 1553 count, 1554 dst, 1555 tmp)); 1556 } 1557 1558 void LIR_List::fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less) { 1559 append(new LIR_Op2(is_unordered_less ? lir_ucmp_fd2i : lir_cmp_fd2i, 1560 left, 1561 right, 1562 dst)); 1563 } 1564 1565 void LIR_List::lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_imse_stub) { 1566 append(new LIR_OpLock( 1567 lir_lock, 1568 hdr, 1569 obj, 1570 lock, 1571 scratch, 1572 stub, 1573 info, 1574 throw_imse_stub)); 1575 } 1576 1577 void LIR_List::unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub) { 1578 append(new LIR_OpLock( 1579 lir_unlock, 1580 hdr, 1581 obj, 1582 lock, 1583 scratch, 1584 stub, 1585 nullptr)); 1586 } 1587 1588 1589 void check_LIR() { 1590 // cannot do the proper checking as PRODUCT and other modes return different results 1591 // guarantee(sizeof(LIR_Opr) == wordSize, "may not have a v-table"); 1592 } 1593 1594 1595 1596 void LIR_List::checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass, 1597 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, 1598 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub, 1599 ciMethod* profiled_method, int profiled_bci, bool is_null_free) { 1600 // If klass is non-nullable, LIRGenerator::do_CheckCast has already performed null-check 1601 // on the object. 1602 bool need_null_check = !is_null_free; 1603 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_checkcast, result, object, klass, 1604 tmp1, tmp2, tmp3, fast_check, info_for_exception, info_for_patch, stub, 1605 need_null_check); 1606 if (profiled_method != nullptr) { 1607 c->set_profiled_method(profiled_method); 1608 c->set_profiled_bci(profiled_bci); 1609 c->set_should_profile(true); 1610 } 1611 append(c); 1612 } 1613 1614 void LIR_List::instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci) { 1615 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_instanceof, result, object, klass, tmp1, tmp2, tmp3, fast_check, nullptr, info_for_patch, nullptr); 1616 if (profiled_method != nullptr) { 1617 c->set_profiled_method(profiled_method); 1618 c->set_profiled_bci(profiled_bci); 1619 c->set_should_profile(true); 1620 } 1621 append(c); 1622 } 1623 1624 1625 void LIR_List::store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, 1626 CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci) { 1627 // FIXME -- if the types of the array and/or the object are known statically, we can avoid loading the klass 1628 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_store_check, object, array, tmp1, tmp2, tmp3, info_for_exception); 1629 if (profiled_method != nullptr) { 1630 c->set_profiled_method(profiled_method); 1631 c->set_profiled_bci(profiled_bci); 1632 c->set_should_profile(true); 1633 } 1634 append(c); 1635 } 1636 1637 void LIR_List::null_check(LIR_Opr opr, CodeEmitInfo* info, bool deoptimize_on_null) { 1638 if (deoptimize_on_null) { 1639 // Emit an explicit null check and deoptimize if opr is null 1640 CodeStub* deopt = new DeoptimizeStub(info, Deoptimization::Reason_null_check, Deoptimization::Action_none); 1641 cmp(lir_cond_equal, opr, LIR_OprFact::oopConst(nullptr)); 1642 branch(lir_cond_equal, deopt); 1643 } else { 1644 // Emit an implicit null check 1645 append(new LIR_Op1(lir_null_check, opr, info)); 1646 } 1647 } 1648 1649 void LIR_List::check_flat_array(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub) { 1650 LIR_OpFlattenedArrayCheck* c = new LIR_OpFlattenedArrayCheck(array, value, tmp, stub); 1651 append(c); 1652 } 1653 1654 void LIR_List::check_null_free_array(LIR_Opr array, LIR_Opr tmp) { 1655 LIR_OpNullFreeArrayCheck* c = new LIR_OpNullFreeArrayCheck(array, tmp); 1656 append(c); 1657 } 1658 1659 void LIR_List::substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result, 1660 LIR_Opr tmp1, LIR_Opr tmp2, 1661 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op, 1662 CodeEmitInfo* info, CodeStub* stub) { 1663 LIR_OpSubstitutabilityCheck* c = new LIR_OpSubstitutabilityCheck(result, left, right, equal_result, not_equal_result, 1664 tmp1, tmp2, 1665 left_klass, right_klass, left_klass_op, right_klass_op, 1666 info, stub); 1667 append(c); 1668 } 1669 1670 void LIR_List::cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value, 1671 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) { 1672 append(new LIR_OpCompareAndSwap(lir_cas_long, addr, cmp_value, new_value, t1, t2, result)); 1673 } 1674 1675 void LIR_List::cas_obj(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value, 1676 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) { 1677 append(new LIR_OpCompareAndSwap(lir_cas_obj, addr, cmp_value, new_value, t1, t2, result)); 1678 } 1679 1680 void LIR_List::cas_int(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value, 1681 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) { 1682 append(new LIR_OpCompareAndSwap(lir_cas_int, addr, cmp_value, new_value, t1, t2, result)); 1683 } 1684 1685 1686 #ifdef PRODUCT 1687 1688 void print_LIR(BlockList* blocks) { 1689 } 1690 1691 #else 1692 // LIR_Opr 1693 void LIR_Opr::print() const { 1694 print(tty); 1695 } 1696 1697 void LIR_Opr::print(outputStream* out) const { 1698 if (is_illegal()) { 1699 return; 1700 } 1701 1702 out->print("["); 1703 if (is_pointer()) { 1704 pointer()->print_value_on(out); 1705 } else if (is_single_stack()) { 1706 out->print("stack:%d", single_stack_ix()); 1707 } else if (is_double_stack()) { 1708 out->print("dbl_stack:%d",double_stack_ix()); 1709 } else if (is_virtual()) { 1710 out->print("R%d", vreg_number()); 1711 } else if (is_single_cpu()) { 1712 out->print("%s", as_register()->name()); 1713 } else if (is_double_cpu()) { 1714 out->print("%s", as_register_hi()->name()); 1715 out->print("%s", as_register_lo()->name()); 1716 #if defined(X86) 1717 } else if (is_single_xmm()) { 1718 out->print("%s", as_xmm_float_reg()->name()); 1719 } else if (is_double_xmm()) { 1720 out->print("%s", as_xmm_double_reg()->name()); 1721 } else if (is_single_fpu()) { 1722 out->print("fpu%d", fpu_regnr()); 1723 } else if (is_double_fpu()) { 1724 out->print("fpu%d", fpu_regnrLo()); 1725 #elif defined(AARCH64) 1726 } else if (is_single_fpu()) { 1727 out->print("fpu%d", fpu_regnr()); 1728 } else if (is_double_fpu()) { 1729 out->print("fpu%d", fpu_regnrLo()); 1730 #elif defined(ARM) 1731 } else if (is_single_fpu()) { 1732 out->print("s%d", fpu_regnr()); 1733 } else if (is_double_fpu()) { 1734 out->print("d%d", fpu_regnrLo() >> 1); 1735 #else 1736 } else if (is_single_fpu()) { 1737 out->print("%s", as_float_reg()->name()); 1738 } else if (is_double_fpu()) { 1739 out->print("%s", as_double_reg()->name()); 1740 #endif 1741 1742 } else if (is_illegal()) { 1743 out->print("-"); 1744 } else { 1745 out->print("Unknown Operand"); 1746 } 1747 if (!is_illegal()) { 1748 out->print("|%c", type_char()); 1749 } 1750 if (is_register() && is_last_use()) { 1751 out->print("(last_use)"); 1752 } 1753 out->print("]"); 1754 } 1755 1756 1757 // LIR_Address 1758 void LIR_Const::print_value_on(outputStream* out) const { 1759 switch (type()) { 1760 case T_ADDRESS:out->print("address:%d",as_jint()); break; 1761 case T_INT: out->print("int:%d", as_jint()); break; 1762 case T_LONG: out->print("lng:" JLONG_FORMAT, as_jlong()); break; 1763 case T_FLOAT: out->print("flt:%f", as_jfloat()); break; 1764 case T_DOUBLE: out->print("dbl:%f", as_jdouble()); break; 1765 case T_OBJECT: out->print("obj:" INTPTR_FORMAT, p2i(as_jobject())); break; 1766 case T_METADATA: out->print("metadata:" INTPTR_FORMAT, p2i(as_metadata()));break; 1767 default: out->print("%3d:" UINT64_FORMAT_X, type(), (uint64_t)as_jlong()); break; 1768 } 1769 } 1770 1771 // LIR_Address 1772 void LIR_Address::print_value_on(outputStream* out) const { 1773 out->print("Base:"); _base->print(out); 1774 if (!_index->is_illegal()) { 1775 out->print(" Index:"); _index->print(out); 1776 switch (scale()) { 1777 case times_1: break; 1778 case times_2: out->print(" * 2"); break; 1779 case times_4: out->print(" * 4"); break; 1780 case times_8: out->print(" * 8"); break; 1781 } 1782 } 1783 out->print(" Disp: " INTX_FORMAT, _disp); 1784 } 1785 1786 // debug output of block header without InstructionPrinter 1787 // (because phi functions are not necessary for LIR) 1788 static void print_block(BlockBegin* x) { 1789 // print block id 1790 BlockEnd* end = x->end(); 1791 tty->print("B%d ", x->block_id()); 1792 1793 // print flags 1794 if (x->is_set(BlockBegin::std_entry_flag)) tty->print("std "); 1795 if (x->is_set(BlockBegin::osr_entry_flag)) tty->print("osr "); 1796 if (x->is_set(BlockBegin::exception_entry_flag)) tty->print("ex "); 1797 if (x->is_set(BlockBegin::subroutine_entry_flag)) tty->print("jsr "); 1798 if (x->is_set(BlockBegin::backward_branch_target_flag)) tty->print("bb "); 1799 if (x->is_set(BlockBegin::linear_scan_loop_header_flag)) tty->print("lh "); 1800 if (x->is_set(BlockBegin::linear_scan_loop_end_flag)) tty->print("le "); 1801 1802 // print block bci range 1803 tty->print("[%d, %d] ", x->bci(), (end == nullptr ? -1 : end->printable_bci())); 1804 1805 // print predecessors and successors 1806 if (x->number_of_preds() > 0) { 1807 tty->print("preds: "); 1808 for (int i = 0; i < x->number_of_preds(); i ++) { 1809 tty->print("B%d ", x->pred_at(i)->block_id()); 1810 } 1811 } 1812 1813 if (end != nullptr && x->number_of_sux() > 0) { 1814 tty->print("sux: "); 1815 for (int i = 0; i < x->number_of_sux(); i ++) { 1816 tty->print("B%d ", x->sux_at(i)->block_id()); 1817 } 1818 } 1819 1820 // print exception handlers 1821 if (x->number_of_exception_handlers() > 0) { 1822 tty->print("xhandler: "); 1823 for (int i = 0; i < x->number_of_exception_handlers(); i++) { 1824 tty->print("B%d ", x->exception_handler_at(i)->block_id()); 1825 } 1826 } 1827 1828 tty->cr(); 1829 } 1830 1831 void print_LIR(BlockList* blocks) { 1832 tty->print_cr("LIR:"); 1833 int i; 1834 for (i = 0; i < blocks->length(); i++) { 1835 BlockBegin* bb = blocks->at(i); 1836 print_block(bb); 1837 tty->print("__id_Instruction___________________________________________"); tty->cr(); 1838 bb->lir()->print_instructions(); 1839 } 1840 } 1841 1842 void LIR_List::print_instructions() { 1843 for (int i = 0; i < _operations.length(); i++) { 1844 _operations.at(i)->print(); tty->cr(); 1845 } 1846 tty->cr(); 1847 } 1848 1849 // LIR_Ops printing routines 1850 // LIR_Op 1851 void LIR_Op::print_on(outputStream* out) const { 1852 if (id() != -1 || PrintCFGToFile) { 1853 out->print("%4d ", id()); 1854 } else { 1855 out->print(" "); 1856 } 1857 out->print("%s ", name()); 1858 print_instr(out); 1859 if (info() != nullptr) out->print(" [bci:%d]", info()->stack()->bci()); 1860 #ifdef ASSERT 1861 if (Verbose && _file != nullptr) { 1862 out->print(" (%s:%d)", _file, _line); 1863 } 1864 #endif 1865 } 1866 1867 const char * LIR_Op::name() const { 1868 const char* s = nullptr; 1869 switch(code()) { 1870 // LIR_Op0 1871 case lir_membar: s = "membar"; break; 1872 case lir_membar_acquire: s = "membar_acquire"; break; 1873 case lir_membar_release: s = "membar_release"; break; 1874 case lir_membar_loadload: s = "membar_loadload"; break; 1875 case lir_membar_storestore: s = "membar_storestore"; break; 1876 case lir_membar_loadstore: s = "membar_loadstore"; break; 1877 case lir_membar_storeload: s = "membar_storeload"; break; 1878 case lir_label: s = "label"; break; 1879 case lir_nop: s = "nop"; break; 1880 case lir_on_spin_wait: s = "on_spin_wait"; break; 1881 case lir_std_entry: s = "std_entry"; break; 1882 case lir_osr_entry: s = "osr_entry"; break; 1883 case lir_fpop_raw: s = "fpop_raw"; break; 1884 case lir_breakpoint: s = "breakpoint"; break; 1885 case lir_get_thread: s = "get_thread"; break; 1886 case lir_check_orig_pc: s = "check_orig_pc"; break; 1887 // LIR_Op1 1888 case lir_fxch: s = "fxch"; break; 1889 case lir_fld: s = "fld"; break; 1890 case lir_push: s = "push"; break; 1891 case lir_pop: s = "pop"; break; 1892 case lir_null_check: s = "null_check"; break; 1893 case lir_return: s = "return"; break; 1894 case lir_safepoint: s = "safepoint"; break; 1895 case lir_leal: s = "leal"; break; 1896 case lir_branch: s = "branch"; break; 1897 case lir_cond_float_branch: s = "flt_cond_br"; break; 1898 case lir_move: s = "move"; break; 1899 case lir_roundfp: s = "roundfp"; break; 1900 case lir_rtcall: s = "rtcall"; break; 1901 case lir_throw: s = "throw"; break; 1902 case lir_unwind: s = "unwind"; break; 1903 case lir_convert: s = "convert"; break; 1904 case lir_alloc_object: s = "alloc_obj"; break; 1905 case lir_monaddr: s = "mon_addr"; break; 1906 // LIR_Op2 1907 case lir_cmp: s = "cmp"; break; 1908 case lir_cmp_l2i: s = "cmp_l2i"; break; 1909 case lir_ucmp_fd2i: s = "ucomp_fd2i"; break; 1910 case lir_cmp_fd2i: s = "comp_fd2i"; break; 1911 case lir_add: s = "add"; break; 1912 case lir_sub: s = "sub"; break; 1913 case lir_mul: s = "mul"; break; 1914 case lir_div: s = "div"; break; 1915 case lir_rem: s = "rem"; break; 1916 case lir_abs: s = "abs"; break; 1917 case lir_neg: s = "neg"; break; 1918 case lir_sqrt: s = "sqrt"; break; 1919 case lir_f2hf: s = "f2hf"; break; 1920 case lir_hf2f: s = "hf2f"; break; 1921 case lir_logic_and: s = "logic_and"; break; 1922 case lir_logic_or: s = "logic_or"; break; 1923 case lir_logic_xor: s = "logic_xor"; break; 1924 case lir_shl: s = "shift_left"; break; 1925 case lir_shr: s = "shift_right"; break; 1926 case lir_ushr: s = "ushift_right"; break; 1927 case lir_alloc_array: s = "alloc_array"; break; 1928 case lir_xadd: s = "xadd"; break; 1929 case lir_xchg: s = "xchg"; break; 1930 // LIR_Op3 1931 case lir_idiv: s = "idiv"; break; 1932 case lir_irem: s = "irem"; break; 1933 case lir_fmad: s = "fmad"; break; 1934 case lir_fmaf: s = "fmaf"; break; 1935 // LIR_Op4 1936 case lir_cmove: s = "cmove"; break; 1937 // LIR_OpJavaCall 1938 case lir_static_call: s = "static"; break; 1939 case lir_optvirtual_call: s = "optvirtual"; break; 1940 case lir_icvirtual_call: s = "icvirtual"; break; 1941 case lir_dynamic_call: s = "dynamic"; break; 1942 // LIR_OpArrayCopy 1943 case lir_arraycopy: s = "arraycopy"; break; 1944 // LIR_OpUpdateCRC32 1945 case lir_updatecrc32: s = "updatecrc32"; break; 1946 // LIR_OpLock 1947 case lir_lock: s = "lock"; break; 1948 case lir_unlock: s = "unlock"; break; 1949 // LIR_OpDelay 1950 case lir_delay_slot: s = "delay"; break; 1951 // LIR_OpTypeCheck 1952 case lir_instanceof: s = "instanceof"; break; 1953 case lir_checkcast: s = "checkcast"; break; 1954 case lir_store_check: s = "store_check"; break; 1955 // LIR_OpFlattenedArrayCheck 1956 case lir_flat_array_check: s = "flat_array_check"; break; 1957 // LIR_OpNullFreeArrayCheck 1958 case lir_null_free_array_check: s = "null_free_array_check"; break; 1959 // LIR_OpSubstitutabilityCheck 1960 case lir_substitutability_check: s = "substitutability_check"; break; 1961 // LIR_OpCompareAndSwap 1962 case lir_cas_long: s = "cas_long"; break; 1963 case lir_cas_obj: s = "cas_obj"; break; 1964 case lir_cas_int: s = "cas_int"; break; 1965 // LIR_OpProfileCall 1966 case lir_profile_call: s = "profile_call"; break; 1967 // LIR_OpProfileType 1968 case lir_profile_type: s = "profile_type"; break; 1969 // LIR_OpProfileInlineType 1970 case lir_profile_inline_type: s = "profile_inline_type"; break; 1971 // LIR_OpAssert 1972 #ifdef ASSERT 1973 case lir_assert: s = "assert"; break; 1974 #endif 1975 case lir_none: ShouldNotReachHere();break; 1976 default: s = "illegal_op"; break; 1977 } 1978 return s; 1979 } 1980 1981 // LIR_OpJavaCall 1982 void LIR_OpJavaCall::print_instr(outputStream* out) const { 1983 out->print("call: "); 1984 out->print("[addr: " INTPTR_FORMAT "]", p2i(address())); 1985 if (receiver()->is_valid()) { 1986 out->print(" [recv: "); receiver()->print(out); out->print("]"); 1987 } 1988 if (result_opr()->is_valid()) { 1989 out->print(" [result: "); result_opr()->print(out); out->print("]"); 1990 } 1991 } 1992 1993 // LIR_OpLabel 1994 void LIR_OpLabel::print_instr(outputStream* out) const { 1995 out->print("[label:" INTPTR_FORMAT "]", p2i(_label)); 1996 } 1997 1998 // LIR_OpArrayCopy 1999 void LIR_OpArrayCopy::print_instr(outputStream* out) const { 2000 src()->print(out); out->print(" "); 2001 src_pos()->print(out); out->print(" "); 2002 dst()->print(out); out->print(" "); 2003 dst_pos()->print(out); out->print(" "); 2004 length()->print(out); out->print(" "); 2005 tmp()->print(out); out->print(" "); 2006 } 2007 2008 // LIR_OpUpdateCRC32 2009 void LIR_OpUpdateCRC32::print_instr(outputStream* out) const { 2010 crc()->print(out); out->print(" "); 2011 val()->print(out); out->print(" "); 2012 result_opr()->print(out); out->print(" "); 2013 } 2014 2015 // LIR_OpCompareAndSwap 2016 void LIR_OpCompareAndSwap::print_instr(outputStream* out) const { 2017 addr()->print(out); out->print(" "); 2018 cmp_value()->print(out); out->print(" "); 2019 new_value()->print(out); out->print(" "); 2020 tmp1()->print(out); out->print(" "); 2021 tmp2()->print(out); out->print(" "); 2022 2023 } 2024 2025 // LIR_Op0 2026 void LIR_Op0::print_instr(outputStream* out) const { 2027 result_opr()->print(out); 2028 } 2029 2030 // LIR_Op1 2031 const char * LIR_Op1::name() const { 2032 if (code() == lir_move) { 2033 switch (move_kind()) { 2034 case lir_move_normal: 2035 return "move"; 2036 case lir_move_volatile: 2037 return "volatile_move"; 2038 case lir_move_wide: 2039 return "wide_move"; 2040 default: 2041 ShouldNotReachHere(); 2042 return "illegal_op"; 2043 } 2044 } else { 2045 return LIR_Op::name(); 2046 } 2047 } 2048 2049 2050 void LIR_Op1::print_instr(outputStream* out) const { 2051 _opr->print(out); out->print(" "); 2052 result_opr()->print(out); out->print(" "); 2053 print_patch_code(out, patch_code()); 2054 } 2055 2056 2057 // LIR_Op1 2058 void LIR_OpRTCall::print_instr(outputStream* out) const { 2059 intx a = (intx)addr(); 2060 out->print("%s", Runtime1::name_for_address(addr())); 2061 out->print(" "); 2062 tmp()->print(out); 2063 } 2064 2065 void LIR_Op1::print_patch_code(outputStream* out, LIR_PatchCode code) { 2066 switch(code) { 2067 case lir_patch_none: break; 2068 case lir_patch_low: out->print("[patch_low]"); break; 2069 case lir_patch_high: out->print("[patch_high]"); break; 2070 case lir_patch_normal: out->print("[patch_normal]"); break; 2071 default: ShouldNotReachHere(); 2072 } 2073 } 2074 2075 // LIR_OpBranch 2076 void LIR_OpBranch::print_instr(outputStream* out) const { 2077 print_condition(out, cond()); out->print(" "); 2078 in_opr1()->print(out); out->print(" "); 2079 in_opr2()->print(out); out->print(" "); 2080 if (block() != nullptr) { 2081 out->print("[B%d] ", block()->block_id()); 2082 } else if (stub() != nullptr) { 2083 out->print("["); 2084 stub()->print_name(out); 2085 out->print(": " INTPTR_FORMAT "]", p2i(stub())); 2086 if (stub()->info() != nullptr) out->print(" [bci:%d]", stub()->info()->stack()->bci()); 2087 } else { 2088 out->print("[label:" INTPTR_FORMAT "] ", p2i(label())); 2089 } 2090 if (ublock() != nullptr) { 2091 out->print("unordered: [B%d] ", ublock()->block_id()); 2092 } 2093 } 2094 2095 void LIR_Op::print_condition(outputStream* out, LIR_Condition cond) { 2096 switch(cond) { 2097 case lir_cond_equal: out->print("[EQ]"); break; 2098 case lir_cond_notEqual: out->print("[NE]"); break; 2099 case lir_cond_less: out->print("[LT]"); break; 2100 case lir_cond_lessEqual: out->print("[LE]"); break; 2101 case lir_cond_greaterEqual: out->print("[GE]"); break; 2102 case lir_cond_greater: out->print("[GT]"); break; 2103 case lir_cond_belowEqual: out->print("[BE]"); break; 2104 case lir_cond_aboveEqual: out->print("[AE]"); break; 2105 case lir_cond_always: out->print("[AL]"); break; 2106 default: out->print("[%d]",cond); break; 2107 } 2108 } 2109 2110 // LIR_OpConvert 2111 void LIR_OpConvert::print_instr(outputStream* out) const { 2112 print_bytecode(out, bytecode()); 2113 in_opr()->print(out); out->print(" "); 2114 result_opr()->print(out); out->print(" "); 2115 } 2116 2117 void LIR_OpConvert::print_bytecode(outputStream* out, Bytecodes::Code code) { 2118 switch(code) { 2119 case Bytecodes::_d2f: out->print("[d2f] "); break; 2120 case Bytecodes::_d2i: out->print("[d2i] "); break; 2121 case Bytecodes::_d2l: out->print("[d2l] "); break; 2122 case Bytecodes::_f2d: out->print("[f2d] "); break; 2123 case Bytecodes::_f2i: out->print("[f2i] "); break; 2124 case Bytecodes::_f2l: out->print("[f2l] "); break; 2125 case Bytecodes::_i2b: out->print("[i2b] "); break; 2126 case Bytecodes::_i2c: out->print("[i2c] "); break; 2127 case Bytecodes::_i2d: out->print("[i2d] "); break; 2128 case Bytecodes::_i2f: out->print("[i2f] "); break; 2129 case Bytecodes::_i2l: out->print("[i2l] "); break; 2130 case Bytecodes::_i2s: out->print("[i2s] "); break; 2131 case Bytecodes::_l2i: out->print("[l2i] "); break; 2132 case Bytecodes::_l2f: out->print("[l2f] "); break; 2133 case Bytecodes::_l2d: out->print("[l2d] "); break; 2134 default: 2135 out->print("[?%d]",code); 2136 break; 2137 } 2138 } 2139 2140 void LIR_OpAllocObj::print_instr(outputStream* out) const { 2141 klass()->print(out); out->print(" "); 2142 obj()->print(out); out->print(" "); 2143 tmp1()->print(out); out->print(" "); 2144 tmp2()->print(out); out->print(" "); 2145 tmp3()->print(out); out->print(" "); 2146 tmp4()->print(out); out->print(" "); 2147 out->print("[hdr:%d]", header_size()); out->print(" "); 2148 out->print("[obj:%d]", object_size()); out->print(" "); 2149 out->print("[lbl:" INTPTR_FORMAT "]", p2i(stub()->entry())); 2150 } 2151 2152 void LIR_OpRoundFP::print_instr(outputStream* out) const { 2153 _opr->print(out); out->print(" "); 2154 tmp()->print(out); out->print(" "); 2155 result_opr()->print(out); out->print(" "); 2156 } 2157 2158 // LIR_Op2 2159 void LIR_Op2::print_instr(outputStream* out) const { 2160 if (code() == lir_cmp || code() == lir_branch || code() == lir_cond_float_branch) { 2161 print_condition(out, condition()); out->print(" "); 2162 } 2163 in_opr1()->print(out); out->print(" "); 2164 in_opr2()->print(out); out->print(" "); 2165 if (tmp1_opr()->is_valid()) { tmp1_opr()->print(out); out->print(" "); } 2166 if (tmp2_opr()->is_valid()) { tmp2_opr()->print(out); out->print(" "); } 2167 if (tmp3_opr()->is_valid()) { tmp3_opr()->print(out); out->print(" "); } 2168 if (tmp4_opr()->is_valid()) { tmp4_opr()->print(out); out->print(" "); } 2169 if (tmp5_opr()->is_valid()) { tmp5_opr()->print(out); out->print(" "); } 2170 result_opr()->print(out); 2171 } 2172 2173 void LIR_OpAllocArray::print_instr(outputStream* out) const { 2174 klass()->print(out); out->print(" "); 2175 len()->print(out); out->print(" "); 2176 obj()->print(out); out->print(" "); 2177 tmp1()->print(out); out->print(" "); 2178 tmp2()->print(out); out->print(" "); 2179 tmp3()->print(out); out->print(" "); 2180 tmp4()->print(out); out->print(" "); 2181 out->print("[type:0x%x]", type()); out->print(" "); 2182 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry())); 2183 } 2184 2185 2186 void LIR_OpTypeCheck::print_instr(outputStream* out) const { 2187 object()->print(out); out->print(" "); 2188 if (code() == lir_store_check) { 2189 array()->print(out); out->print(" "); 2190 } 2191 if (code() != lir_store_check) { 2192 klass()->print_name_on(out); out->print(" "); 2193 if (fast_check()) out->print("fast_check "); 2194 } 2195 tmp1()->print(out); out->print(" "); 2196 tmp2()->print(out); out->print(" "); 2197 tmp3()->print(out); out->print(" "); 2198 result_opr()->print(out); out->print(" "); 2199 if (info_for_exception() != nullptr) out->print(" [bci:%d]", info_for_exception()->stack()->bci()); 2200 } 2201 2202 void LIR_OpFlattenedArrayCheck::print_instr(outputStream* out) const { 2203 array()->print(out); out->print(" "); 2204 value()->print(out); out->print(" "); 2205 tmp()->print(out); out->print(" "); 2206 if (stub() != nullptr) { 2207 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry())); 2208 } 2209 } 2210 2211 void LIR_OpNullFreeArrayCheck::print_instr(outputStream* out) const { 2212 array()->print(out); out->print(" "); 2213 tmp()->print(out); out->print(" "); 2214 } 2215 2216 void LIR_OpSubstitutabilityCheck::print_instr(outputStream* out) const { 2217 result_opr()->print(out); out->print(" "); 2218 left()->print(out); out->print(" "); 2219 right()->print(out); out->print(" "); 2220 equal_result()->print(out); out->print(" "); 2221 not_equal_result()->print(out); out->print(" "); 2222 tmp1()->print(out); out->print(" "); 2223 tmp2()->print(out); out->print(" "); 2224 if (left_klass() == nullptr) { 2225 out->print("unknown "); 2226 } else { 2227 left_klass()->print(out); out->print(" "); 2228 } 2229 if (right_klass() == nullptr) { 2230 out->print("unknown "); 2231 } else { 2232 right_klass()->print(out); out->print(" "); 2233 } 2234 left_klass_op()->print(out); out->print(" "); 2235 right_klass_op()->print(out); out->print(" "); 2236 if (stub() != nullptr) { 2237 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry())); 2238 } 2239 } 2240 2241 // LIR_Op3 2242 void LIR_Op3::print_instr(outputStream* out) const { 2243 in_opr1()->print(out); out->print(" "); 2244 in_opr2()->print(out); out->print(" "); 2245 in_opr3()->print(out); out->print(" "); 2246 result_opr()->print(out); 2247 } 2248 2249 // LIR_Op4 2250 void LIR_Op4::print_instr(outputStream* out) const { 2251 print_condition(out, condition()); out->print(" "); 2252 in_opr1()->print(out); out->print(" "); 2253 in_opr2()->print(out); out->print(" "); 2254 in_opr3()->print(out); out->print(" "); 2255 in_opr4()->print(out); out->print(" "); 2256 result_opr()->print(out); 2257 } 2258 2259 void LIR_OpLock::print_instr(outputStream* out) const { 2260 hdr_opr()->print(out); out->print(" "); 2261 obj_opr()->print(out); out->print(" "); 2262 lock_opr()->print(out); out->print(" "); 2263 if (_scratch->is_valid()) { 2264 _scratch->print(out); out->print(" "); 2265 } 2266 out->print("[lbl:" INTPTR_FORMAT "]", p2i(stub()->entry())); 2267 } 2268 2269 void LIR_OpLoadKlass::print_instr(outputStream* out) const { 2270 obj()->print(out); out->print(" "); 2271 result_opr()->print(out); out->print(" "); 2272 } 2273 2274 #ifdef ASSERT 2275 void LIR_OpAssert::print_instr(outputStream* out) const { 2276 print_condition(out, condition()); out->print(" "); 2277 in_opr1()->print(out); out->print(" "); 2278 in_opr2()->print(out); out->print(", \""); 2279 out->print("%s", msg()); out->print("\""); 2280 } 2281 #endif 2282 2283 2284 void LIR_OpDelay::print_instr(outputStream* out) const { 2285 _op->print_on(out); 2286 } 2287 2288 2289 // LIR_OpProfileCall 2290 void LIR_OpProfileCall::print_instr(outputStream* out) const { 2291 profiled_method()->name()->print_symbol_on(out); 2292 out->print("."); 2293 profiled_method()->holder()->name()->print_symbol_on(out); 2294 out->print(" @ %d ", profiled_bci()); 2295 mdo()->print(out); out->print(" "); 2296 recv()->print(out); out->print(" "); 2297 tmp1()->print(out); out->print(" "); 2298 } 2299 2300 // LIR_OpProfileType 2301 void LIR_OpProfileType::print_instr(outputStream* out) const { 2302 out->print("exact = "); 2303 if (exact_klass() == nullptr) { 2304 out->print("unknown"); 2305 } else { 2306 exact_klass()->print_name_on(out); 2307 } 2308 out->print(" current = "); ciTypeEntries::print_ciklass(out, current_klass()); 2309 out->print(" "); 2310 mdp()->print(out); out->print(" "); 2311 obj()->print(out); out->print(" "); 2312 tmp()->print(out); out->print(" "); 2313 } 2314 2315 // LIR_OpProfileInlineType 2316 void LIR_OpProfileInlineType::print_instr(outputStream* out) const { 2317 out->print(" flag = %x ", flag()); 2318 mdp()->print(out); out->print(" "); 2319 obj()->print(out); out->print(" "); 2320 tmp()->print(out); out->print(" "); 2321 } 2322 2323 #endif // PRODUCT 2324 2325 // Implementation of LIR_InsertionBuffer 2326 2327 void LIR_InsertionBuffer::append(int index, LIR_Op* op) { 2328 assert(_index_and_count.length() % 2 == 0, "must have a count for each index"); 2329 2330 int i = number_of_insertion_points() - 1; 2331 if (i < 0 || index_at(i) < index) { 2332 append_new(index, 1); 2333 } else { 2334 assert(index_at(i) == index, "can append LIR_Ops in ascending order only"); 2335 assert(count_at(i) > 0, "check"); 2336 set_count_at(i, count_at(i) + 1); 2337 } 2338 _ops.push(op); 2339 2340 DEBUG_ONLY(verify()); 2341 } 2342 2343 #ifdef ASSERT 2344 void LIR_InsertionBuffer::verify() { 2345 int sum = 0; 2346 int prev_idx = -1; 2347 2348 for (int i = 0; i < number_of_insertion_points(); i++) { 2349 assert(prev_idx < index_at(i), "index must be ordered ascending"); 2350 sum += count_at(i); 2351 } 2352 assert(sum == number_of_ops(), "wrong total sum"); 2353 } 2354 #endif