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