1 /* 2 * Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "c1/c1_Compilation.hpp" 26 #include "c1/c1_Defs.hpp" 27 #include "c1/c1_FrameMap.hpp" 28 #include "c1/c1_Instruction.hpp" 29 #include "c1/c1_LIRAssembler.hpp" 30 #include "c1/c1_LIRGenerator.hpp" 31 #include "c1/c1_ValueStack.hpp" 32 #include "ci/ciArrayKlass.hpp" 33 #include "ci/ciInstance.hpp" 34 #include "ci/ciObjArray.hpp" 35 #include "ci/ciUtilities.hpp" 36 #include "code/aotCodeCache.hpp" 37 #include "compiler/compilerDefinitions.inline.hpp" 38 #include "compiler/compilerOracle.hpp" 39 #include "gc/shared/barrierSet.hpp" 40 #include "gc/shared/c1/barrierSetC1.hpp" 41 #include "oops/klass.inline.hpp" 42 #include "oops/methodCounters.hpp" 43 #include "runtime/runtimeUpcalls.hpp" 44 #include "runtime/sharedRuntime.hpp" 45 #include "runtime/stubRoutines.hpp" 46 #include "runtime/vm_version.hpp" 47 #include "utilities/bitMap.inline.hpp" 48 #include "utilities/macros.hpp" 49 #include "utilities/powerOfTwo.hpp" 50 51 #ifdef ASSERT 52 #define __ gen()->lir(__FILE__, __LINE__)-> 53 #else 54 #define __ gen()->lir()-> 55 #endif 56 57 #ifndef PATCHED_ADDR 58 #define PATCHED_ADDR (max_jint) 59 #endif 60 61 void PhiResolverState::reset() { 62 _virtual_operands.clear(); 63 _other_operands.clear(); 64 _vreg_table.clear(); 65 } 66 67 68 //-------------------------------------------------------------- 69 // PhiResolver 70 71 // Resolves cycles: 72 // 73 // r1 := r2 becomes temp := r1 74 // r2 := r1 r1 := r2 75 // r2 := temp 76 // and orders moves: 77 // 78 // r2 := r3 becomes r1 := r2 79 // r1 := r2 r2 := r3 80 81 PhiResolver::PhiResolver(LIRGenerator* gen) 82 : _gen(gen) 83 , _state(gen->resolver_state()) 84 , _loop(nullptr) 85 , _temp(LIR_OprFact::illegalOpr) 86 { 87 // reinitialize the shared state arrays 88 _state.reset(); 89 } 90 91 92 void PhiResolver::emit_move(LIR_Opr src, LIR_Opr dest) { 93 assert(src->is_valid(), ""); 94 assert(dest->is_valid(), ""); 95 __ move(src, dest); 96 } 97 98 99 void PhiResolver::move_temp_to(LIR_Opr dest) { 100 assert(_temp->is_valid(), ""); 101 emit_move(_temp, dest); 102 NOT_PRODUCT(_temp = LIR_OprFact::illegalOpr); 103 } 104 105 106 void PhiResolver::move_to_temp(LIR_Opr src) { 107 assert(_temp->is_illegal(), ""); 108 _temp = _gen->new_register(src->type()); 109 emit_move(src, _temp); 110 } 111 112 113 // Traverse assignment graph in depth first order and generate moves in post order 114 // ie. two assignments: b := c, a := b start with node c: 115 // Call graph: move(null, c) -> move(c, b) -> move(b, a) 116 // Generates moves in this order: move b to a and move c to b 117 // ie. cycle a := b, b := a start with node a 118 // Call graph: move(null, a) -> move(a, b) -> move(b, a) 119 // Generates moves in this order: move b to temp, move a to b, move temp to a 120 void PhiResolver::move(ResolveNode* src, ResolveNode* dest) { 121 if (!dest->visited()) { 122 dest->set_visited(); 123 for (int i = dest->no_of_destinations()-1; i >= 0; i --) { 124 move(dest, dest->destination_at(i)); 125 } 126 } else if (!dest->start_node()) { 127 // cylce in graph detected 128 assert(_loop == nullptr, "only one loop valid!"); 129 _loop = dest; 130 move_to_temp(src->operand()); 131 return; 132 } // else dest is a start node 133 134 if (!dest->assigned()) { 135 if (_loop == dest) { 136 move_temp_to(dest->operand()); 137 dest->set_assigned(); 138 } else if (src != nullptr) { 139 emit_move(src->operand(), dest->operand()); 140 dest->set_assigned(); 141 } 142 } 143 } 144 145 146 PhiResolver::~PhiResolver() { 147 int i; 148 // resolve any cycles in moves from and to virtual registers 149 for (i = virtual_operands().length() - 1; i >= 0; i --) { 150 ResolveNode* node = virtual_operands().at(i); 151 if (!node->visited()) { 152 _loop = nullptr; 153 move(nullptr, node); 154 node->set_start_node(); 155 assert(_temp->is_illegal(), "move_temp_to() call missing"); 156 } 157 } 158 159 // generate move for move from non virtual register to abitrary destination 160 for (i = other_operands().length() - 1; i >= 0; i --) { 161 ResolveNode* node = other_operands().at(i); 162 for (int j = node->no_of_destinations() - 1; j >= 0; j --) { 163 emit_move(node->operand(), node->destination_at(j)->operand()); 164 } 165 } 166 } 167 168 169 ResolveNode* PhiResolver::create_node(LIR_Opr opr, bool source) { 170 ResolveNode* node; 171 if (opr->is_virtual()) { 172 int vreg_num = opr->vreg_number(); 173 node = vreg_table().at_grow(vreg_num, nullptr); 174 assert(node == nullptr || node->operand() == opr, ""); 175 if (node == nullptr) { 176 node = new ResolveNode(opr); 177 vreg_table().at_put(vreg_num, node); 178 } 179 // Make sure that all virtual operands show up in the list when 180 // they are used as the source of a move. 181 if (source && !virtual_operands().contains(node)) { 182 virtual_operands().append(node); 183 } 184 } else { 185 assert(source, ""); 186 node = new ResolveNode(opr); 187 other_operands().append(node); 188 } 189 return node; 190 } 191 192 193 void PhiResolver::move(LIR_Opr src, LIR_Opr dest) { 194 assert(dest->is_virtual(), ""); 195 // tty->print("move "); src->print(); tty->print(" to "); dest->print(); tty->cr(); 196 assert(src->is_valid(), ""); 197 assert(dest->is_valid(), ""); 198 ResolveNode* source = source_node(src); 199 source->append(destination_node(dest)); 200 } 201 202 203 //-------------------------------------------------------------- 204 // LIRItem 205 206 void LIRItem::set_result(LIR_Opr opr) { 207 assert(value()->operand()->is_illegal() || value()->operand()->is_constant(), "operand should never change"); 208 value()->set_operand(opr); 209 210 #ifdef ASSERT 211 if (opr->is_virtual()) { 212 _gen->_instruction_for_operand.at_put_grow(opr->vreg_number(), value(), nullptr); 213 } 214 #endif 215 216 _result = opr; 217 } 218 219 void LIRItem::load_item() { 220 if (result()->is_illegal()) { 221 // update the items result 222 _result = value()->operand(); 223 } 224 if (!result()->is_register()) { 225 LIR_Opr reg = _gen->new_register(value()->type()); 226 __ move(result(), reg); 227 if (result()->is_constant()) { 228 _result = reg; 229 } else { 230 set_result(reg); 231 } 232 } 233 } 234 235 236 void LIRItem::load_for_store(BasicType type) { 237 if (_gen->can_store_as_constant(value(), type)) { 238 _result = value()->operand(); 239 if (!_result->is_constant()) { 240 _result = LIR_OprFact::value_type(value()->type()); 241 } 242 } else if (type == T_BYTE || type == T_BOOLEAN) { 243 load_byte_item(); 244 } else { 245 load_item(); 246 } 247 } 248 249 void LIRItem::load_item_force(LIR_Opr reg) { 250 LIR_Opr r = result(); 251 if (r != reg) { 252 #if !defined(ARM) && !defined(E500V2) 253 if (r->type() != reg->type()) { 254 // moves between different types need an intervening spill slot 255 r = _gen->force_to_spill(r, reg->type()); 256 } 257 #endif 258 __ move(r, reg); 259 _result = reg; 260 } 261 } 262 263 ciObject* LIRItem::get_jobject_constant() const { 264 ObjectType* oc = type()->as_ObjectType(); 265 if (oc) { 266 return oc->constant_value(); 267 } 268 return nullptr; 269 } 270 271 272 jint LIRItem::get_jint_constant() const { 273 assert(is_constant() && value() != nullptr, ""); 274 assert(type()->as_IntConstant() != nullptr, "type check"); 275 return type()->as_IntConstant()->value(); 276 } 277 278 279 jint LIRItem::get_address_constant() const { 280 assert(is_constant() && value() != nullptr, ""); 281 assert(type()->as_AddressConstant() != nullptr, "type check"); 282 return type()->as_AddressConstant()->value(); 283 } 284 285 286 jfloat LIRItem::get_jfloat_constant() const { 287 assert(is_constant() && value() != nullptr, ""); 288 assert(type()->as_FloatConstant() != nullptr, "type check"); 289 return type()->as_FloatConstant()->value(); 290 } 291 292 293 jdouble LIRItem::get_jdouble_constant() const { 294 assert(is_constant() && value() != nullptr, ""); 295 assert(type()->as_DoubleConstant() != nullptr, "type check"); 296 return type()->as_DoubleConstant()->value(); 297 } 298 299 300 jlong LIRItem::get_jlong_constant() const { 301 assert(is_constant() && value() != nullptr, ""); 302 assert(type()->as_LongConstant() != nullptr, "type check"); 303 return type()->as_LongConstant()->value(); 304 } 305 306 307 308 //-------------------------------------------------------------- 309 310 311 void LIRGenerator::block_do_prolog(BlockBegin* block) { 312 #ifndef PRODUCT 313 if (PrintIRWithLIR) { 314 block->print(); 315 } 316 #endif 317 318 // set up the list of LIR instructions 319 assert(block->lir() == nullptr, "LIR list already computed for this block"); 320 _lir = new LIR_List(compilation(), block); 321 block->set_lir(_lir); 322 323 __ branch_destination(block->label()); 324 325 if (LIRTraceExecution && 326 Compilation::current()->hir()->start()->block_id() != block->block_id() && 327 !block->is_set(BlockBegin::exception_entry_flag)) { 328 assert(block->lir()->instructions_list()->length() == 1, "should come right after br_dst"); 329 trace_block_entry(block); 330 } 331 } 332 333 334 void LIRGenerator::block_do_epilog(BlockBegin* block) { 335 #ifndef PRODUCT 336 if (PrintIRWithLIR) { 337 tty->cr(); 338 } 339 #endif 340 341 // LIR_Opr for unpinned constants shouldn't be referenced by other 342 // blocks so clear them out after processing the block. 343 for (int i = 0; i < _unpinned_constants.length(); i++) { 344 _unpinned_constants.at(i)->clear_operand(); 345 } 346 _unpinned_constants.trunc_to(0); 347 348 // clear our any registers for other local constants 349 _constants.trunc_to(0); 350 _reg_for_constants.trunc_to(0); 351 } 352 353 354 void LIRGenerator::block_do(BlockBegin* block) { 355 CHECK_BAILOUT(); 356 357 block_do_prolog(block); 358 set_block(block); 359 360 for (Instruction* instr = block; instr != nullptr; instr = instr->next()) { 361 if (instr->is_pinned()) do_root(instr); 362 } 363 364 set_block(nullptr); 365 block_do_epilog(block); 366 } 367 368 369 //-------------------------LIRGenerator----------------------------- 370 371 // This is where the tree-walk starts; instr must be root; 372 void LIRGenerator::do_root(Value instr) { 373 CHECK_BAILOUT(); 374 375 InstructionMark im(compilation(), instr); 376 377 assert(instr->is_pinned(), "use only with roots"); 378 assert(instr->subst() == instr, "shouldn't have missed substitution"); 379 380 instr->visit(this); 381 382 assert(!instr->has_uses() || instr->operand()->is_valid() || 383 instr->as_Constant() != nullptr || bailed_out(), "invalid item set"); 384 } 385 386 387 // This is called for each node in tree; the walk stops if a root is reached 388 void LIRGenerator::walk(Value instr) { 389 InstructionMark im(compilation(), instr); 390 //stop walk when encounter a root 391 if ((instr->is_pinned() && instr->as_Phi() == nullptr) || instr->operand()->is_valid()) { 392 assert(instr->operand() != LIR_OprFact::illegalOpr || instr->as_Constant() != nullptr, "this root has not yet been visited"); 393 } else { 394 assert(instr->subst() == instr, "shouldn't have missed substitution"); 395 instr->visit(this); 396 // assert(instr->use_count() > 0 || instr->as_Phi() != nullptr, "leaf instruction must have a use"); 397 } 398 } 399 400 401 CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ignore_xhandler) { 402 assert(state != nullptr, "state must be defined"); 403 404 #ifndef PRODUCT 405 state->verify(); 406 #endif 407 408 ValueStack* s = state; 409 for_each_state(s) { 410 if (s->kind() == ValueStack::EmptyExceptionState || 411 s->kind() == ValueStack::CallerEmptyExceptionState) 412 { 413 #ifdef ASSERT 414 int index; 415 Value value; 416 for_each_stack_value(s, index, value) { 417 fatal("state must be empty"); 418 } 419 for_each_local_value(s, index, value) { 420 fatal("state must be empty"); 421 } 422 #endif 423 assert(s->locks_size() == 0 || s->locks_size() == 1, "state must be empty"); 424 continue; 425 } 426 427 int index; 428 Value value; 429 for_each_stack_value(s, index, value) { 430 assert(value->subst() == value, "missed substitution"); 431 if (!value->is_pinned() && value->as_Constant() == nullptr && value->as_Local() == nullptr) { 432 walk(value); 433 assert(value->operand()->is_valid(), "must be evaluated now"); 434 } 435 } 436 437 int bci = s->bci(); 438 IRScope* scope = s->scope(); 439 ciMethod* method = scope->method(); 440 441 MethodLivenessResult liveness = method->liveness_at_bci(bci); 442 if (bci == SynchronizationEntryBCI) { 443 if (x->as_ExceptionObject() || x->as_Throw()) { 444 // all locals are dead on exit from the synthetic unlocker 445 liveness.clear(); 446 } else { 447 assert(x->as_MonitorEnter() || x->as_ProfileInvoke(), "only other cases are MonitorEnter and ProfileInvoke"); 448 } 449 } 450 if (!liveness.is_valid()) { 451 // Degenerate or breakpointed method. 452 bailout("Degenerate or breakpointed method"); 453 } else { 454 assert((int)liveness.size() == s->locals_size(), "error in use of liveness"); 455 for_each_local_value(s, index, value) { 456 assert(value->subst() == value, "missed substitution"); 457 if (liveness.at(index) && !value->type()->is_illegal()) { 458 if (!value->is_pinned() && value->as_Constant() == nullptr && value->as_Local() == nullptr) { 459 walk(value); 460 assert(value->operand()->is_valid(), "must be evaluated now"); 461 } 462 } else { 463 // null out this local so that linear scan can assume that all non-null values are live. 464 s->invalidate_local(index); 465 } 466 } 467 } 468 } 469 470 return new CodeEmitInfo(state, ignore_xhandler ? nullptr : x->exception_handlers(), x->check_flag(Instruction::DeoptimizeOnException)); 471 } 472 473 474 CodeEmitInfo* LIRGenerator::state_for(Instruction* x) { 475 return state_for(x, x->exception_state()); 476 } 477 478 479 void LIRGenerator::klass2reg_with_patching(LIR_Opr r, ciMetadata* obj, CodeEmitInfo* info, bool need_resolve) { 480 /* C2 relies on constant pool entries being resolved (ciTypeFlow), so if tiered compilation 481 * is active and the class hasn't yet been resolved we need to emit a patch that resolves 482 * the class. */ 483 if ((!CompilerConfig::is_c1_only_no_jvmci() && need_resolve) || !obj->is_loaded() || PatchALot) { 484 assert(info != nullptr, "info must be set if class is not loaded"); 485 __ klass2reg_patch(nullptr, r, info); 486 } else { 487 // no patching needed 488 __ metadata2reg(obj->constant_encoding(), r); 489 } 490 } 491 492 493 void LIRGenerator::array_range_check(LIR_Opr array, LIR_Opr index, 494 CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info) { 495 CodeStub* stub = new RangeCheckStub(range_check_info, index, array); 496 if (index->is_constant()) { 497 cmp_mem_int(lir_cond_belowEqual, array, arrayOopDesc::length_offset_in_bytes(), 498 index->as_jint(), null_check_info); 499 __ branch(lir_cond_belowEqual, stub); // forward branch 500 } else { 501 cmp_reg_mem(lir_cond_aboveEqual, index, array, 502 arrayOopDesc::length_offset_in_bytes(), T_INT, null_check_info); 503 __ branch(lir_cond_aboveEqual, stub); // forward branch 504 } 505 } 506 507 void LIRGenerator::arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp_op, CodeEmitInfo* info) { 508 LIR_Opr result_op = result; 509 LIR_Opr left_op = left; 510 LIR_Opr right_op = right; 511 512 if (two_operand_lir_form && left_op != result_op) { 513 assert(right_op != result_op, "malformed"); 514 __ move(left_op, result_op); 515 left_op = result_op; 516 } 517 518 switch(code) { 519 case Bytecodes::_dadd: 520 case Bytecodes::_fadd: 521 case Bytecodes::_ladd: 522 case Bytecodes::_iadd: __ add(left_op, right_op, result_op); break; 523 case Bytecodes::_fmul: 524 case Bytecodes::_lmul: __ mul(left_op, right_op, result_op); break; 525 526 case Bytecodes::_dmul: __ mul(left_op, right_op, result_op, tmp_op); break; 527 528 case Bytecodes::_imul: 529 { 530 bool did_strength_reduce = false; 531 532 if (right->is_constant()) { 533 jint c = right->as_jint(); 534 if (c > 0 && is_power_of_2(c)) { 535 // do not need tmp here 536 __ shift_left(left_op, exact_log2(c), result_op); 537 did_strength_reduce = true; 538 } else { 539 did_strength_reduce = strength_reduce_multiply(left_op, c, result_op, tmp_op); 540 } 541 } 542 // we couldn't strength reduce so just emit the multiply 543 if (!did_strength_reduce) { 544 __ mul(left_op, right_op, result_op); 545 } 546 } 547 break; 548 549 case Bytecodes::_dsub: 550 case Bytecodes::_fsub: 551 case Bytecodes::_lsub: 552 case Bytecodes::_isub: __ sub(left_op, right_op, result_op); break; 553 554 case Bytecodes::_fdiv: __ div (left_op, right_op, result_op); break; 555 // ldiv and lrem are implemented with a direct runtime call 556 557 case Bytecodes::_ddiv: __ div(left_op, right_op, result_op, tmp_op); break; 558 559 case Bytecodes::_drem: 560 case Bytecodes::_frem: __ rem (left_op, right_op, result_op); break; 561 562 default: ShouldNotReachHere(); 563 } 564 } 565 566 567 void LIRGenerator::arithmetic_op_int(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp) { 568 arithmetic_op(code, result, left, right, tmp); 569 } 570 571 572 void LIRGenerator::arithmetic_op_long(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info) { 573 arithmetic_op(code, result, left, right, LIR_OprFact::illegalOpr, info); 574 } 575 576 577 void LIRGenerator::arithmetic_op_fpu(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp) { 578 arithmetic_op(code, result, left, right, tmp); 579 } 580 581 582 void LIRGenerator::shift_op(Bytecodes::Code code, LIR_Opr result_op, LIR_Opr value, LIR_Opr count, LIR_Opr tmp) { 583 584 if (two_operand_lir_form && value != result_op 585 // Only 32bit right shifts require two operand form on S390. 586 S390_ONLY(&& (code == Bytecodes::_ishr || code == Bytecodes::_iushr))) { 587 assert(count != result_op, "malformed"); 588 __ move(value, result_op); 589 value = result_op; 590 } 591 592 assert(count->is_constant() || count->is_register(), "must be"); 593 switch(code) { 594 case Bytecodes::_ishl: 595 case Bytecodes::_lshl: __ shift_left(value, count, result_op, tmp); break; 596 case Bytecodes::_ishr: 597 case Bytecodes::_lshr: __ shift_right(value, count, result_op, tmp); break; 598 case Bytecodes::_iushr: 599 case Bytecodes::_lushr: __ unsigned_shift_right(value, count, result_op, tmp); break; 600 default: ShouldNotReachHere(); 601 } 602 } 603 604 605 void LIRGenerator::logic_op (Bytecodes::Code code, LIR_Opr result_op, LIR_Opr left_op, LIR_Opr right_op) { 606 if (two_operand_lir_form && left_op != result_op) { 607 assert(right_op != result_op, "malformed"); 608 __ move(left_op, result_op); 609 left_op = result_op; 610 } 611 612 switch(code) { 613 case Bytecodes::_iand: 614 case Bytecodes::_land: __ logical_and(left_op, right_op, result_op); break; 615 616 case Bytecodes::_ior: 617 case Bytecodes::_lor: __ logical_or(left_op, right_op, result_op); break; 618 619 case Bytecodes::_ixor: 620 case Bytecodes::_lxor: __ logical_xor(left_op, right_op, result_op); break; 621 622 default: ShouldNotReachHere(); 623 } 624 } 625 626 627 void LIRGenerator::monitor_enter(LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info) { 628 if (!GenerateSynchronizationCode) return; 629 // for slow path, use debug info for state after successful locking 630 CodeStub* slow_path = new MonitorEnterStub(object, lock, info); 631 __ load_stack_address_monitor(monitor_no, lock); 632 // for handling NullPointerException, use debug info representing just the lock stack before this monitorenter 633 __ lock_object(hdr, object, lock, scratch, slow_path, info_for_exception); 634 } 635 636 637 void LIRGenerator::monitor_exit(LIR_Opr object, LIR_Opr lock, LIR_Opr new_hdr, LIR_Opr scratch, int monitor_no) { 638 if (!GenerateSynchronizationCode) return; 639 // setup registers 640 LIR_Opr hdr = lock; 641 lock = new_hdr; 642 CodeStub* slow_path = new MonitorExitStub(lock, LockingMode != LM_MONITOR, monitor_no); 643 __ load_stack_address_monitor(monitor_no, lock); 644 __ unlock_object(hdr, object, lock, scratch, slow_path); 645 } 646 647 #ifndef PRODUCT 648 void LIRGenerator::print_if_not_loaded(const NewInstance* new_instance) { 649 if (PrintNotLoaded && !new_instance->klass()->is_loaded()) { 650 tty->print_cr(" ###class not loaded at new bci %d", new_instance->printable_bci()); 651 } else if (PrintNotLoaded && (!CompilerConfig::is_c1_only_no_jvmci() && new_instance->is_unresolved())) { 652 tty->print_cr(" ###class not resolved at new bci %d", new_instance->printable_bci()); 653 } 654 } 655 #endif 656 657 void LIRGenerator::new_instance(LIR_Opr dst, ciInstanceKlass* klass, bool is_unresolved, LIR_Opr scratch1, LIR_Opr scratch2, LIR_Opr scratch3, LIR_Opr scratch4, LIR_Opr klass_reg, CodeEmitInfo* info) { 658 klass2reg_with_patching(klass_reg, klass, info, is_unresolved); 659 // If klass is not loaded we do not know if the klass has finalizers: 660 if (UseFastNewInstance && klass->is_loaded() 661 && !Klass::layout_helper_needs_slow_path(klass->layout_helper())) { 662 663 bool known_initialized = klass->is_initialized() && !compilation()->env()->is_precompile(); 664 C1StubId stub_id = known_initialized ? C1StubId::fast_new_instance_id : C1StubId::fast_new_instance_init_check_id; 665 666 CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, stub_id); 667 668 assert(klass->is_loaded(), "must be loaded"); 669 // allocate space for instance 670 assert(klass->size_helper() > 0, "illegal instance size"); 671 const int instance_size = align_object_size(klass->size_helper()); 672 __ allocate_object(dst, scratch1, scratch2, scratch3, scratch4, 673 oopDesc::header_size(), instance_size, klass_reg, !known_initialized, slow_path); 674 } else { 675 CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, C1StubId::new_instance_id); 676 __ branch(lir_cond_always, slow_path); 677 __ branch_destination(slow_path->continuation()); 678 } 679 } 680 681 682 static bool is_constant_zero(Instruction* inst) { 683 IntConstant* c = inst->type()->as_IntConstant(); 684 if (c) { 685 return (c->value() == 0); 686 } 687 return false; 688 } 689 690 691 static bool positive_constant(Instruction* inst) { 692 IntConstant* c = inst->type()->as_IntConstant(); 693 if (c) { 694 return (c->value() >= 0); 695 } 696 return false; 697 } 698 699 700 static ciArrayKlass* as_array_klass(ciType* type) { 701 if (type != nullptr && type->is_array_klass() && type->is_loaded()) { 702 return (ciArrayKlass*)type; 703 } else { 704 return nullptr; 705 } 706 } 707 708 static ciType* phi_declared_type(Phi* phi) { 709 ciType* t = phi->operand_at(0)->declared_type(); 710 if (t == nullptr) { 711 return nullptr; 712 } 713 for(int i = 1; i < phi->operand_count(); i++) { 714 if (t != phi->operand_at(i)->declared_type()) { 715 return nullptr; 716 } 717 } 718 return t; 719 } 720 721 void LIRGenerator::arraycopy_helper(Intrinsic* x, int* flagsp, ciArrayKlass** expected_typep) { 722 Instruction* src = x->argument_at(0); 723 Instruction* src_pos = x->argument_at(1); 724 Instruction* dst = x->argument_at(2); 725 Instruction* dst_pos = x->argument_at(3); 726 Instruction* length = x->argument_at(4); 727 728 // first try to identify the likely type of the arrays involved 729 ciArrayKlass* expected_type = nullptr; 730 bool is_exact = false, src_objarray = false, dst_objarray = false; 731 { 732 ciArrayKlass* src_exact_type = as_array_klass(src->exact_type()); 733 ciArrayKlass* src_declared_type = as_array_klass(src->declared_type()); 734 Phi* phi; 735 if (src_declared_type == nullptr && (phi = src->as_Phi()) != nullptr) { 736 src_declared_type = as_array_klass(phi_declared_type(phi)); 737 } 738 ciArrayKlass* dst_exact_type = as_array_klass(dst->exact_type()); 739 ciArrayKlass* dst_declared_type = as_array_klass(dst->declared_type()); 740 if (dst_declared_type == nullptr && (phi = dst->as_Phi()) != nullptr) { 741 dst_declared_type = as_array_klass(phi_declared_type(phi)); 742 } 743 744 if (src_exact_type != nullptr && src_exact_type == dst_exact_type) { 745 // the types exactly match so the type is fully known 746 is_exact = true; 747 expected_type = src_exact_type; 748 } else if (dst_exact_type != nullptr && dst_exact_type->is_obj_array_klass()) { 749 ciArrayKlass* dst_type = (ciArrayKlass*) dst_exact_type; 750 ciArrayKlass* src_type = nullptr; 751 if (src_exact_type != nullptr && src_exact_type->is_obj_array_klass()) { 752 src_type = (ciArrayKlass*) src_exact_type; 753 } else if (src_declared_type != nullptr && src_declared_type->is_obj_array_klass()) { 754 src_type = (ciArrayKlass*) src_declared_type; 755 } 756 if (src_type != nullptr) { 757 if (src_type->element_type()->is_subtype_of(dst_type->element_type())) { 758 is_exact = true; 759 expected_type = dst_type; 760 } 761 } 762 } 763 // at least pass along a good guess 764 if (expected_type == nullptr) expected_type = dst_exact_type; 765 if (expected_type == nullptr) expected_type = src_declared_type; 766 if (expected_type == nullptr) expected_type = dst_declared_type; 767 768 src_objarray = (src_exact_type && src_exact_type->is_obj_array_klass()) || (src_declared_type && src_declared_type->is_obj_array_klass()); 769 dst_objarray = (dst_exact_type && dst_exact_type->is_obj_array_klass()) || (dst_declared_type && dst_declared_type->is_obj_array_klass()); 770 } 771 772 // if a probable array type has been identified, figure out if any 773 // of the required checks for a fast case can be elided. 774 int flags = LIR_OpArrayCopy::all_flags; 775 776 if (!src_objarray) 777 flags &= ~LIR_OpArrayCopy::src_objarray; 778 if (!dst_objarray) 779 flags &= ~LIR_OpArrayCopy::dst_objarray; 780 781 if (!x->arg_needs_null_check(0)) 782 flags &= ~LIR_OpArrayCopy::src_null_check; 783 if (!x->arg_needs_null_check(2)) 784 flags &= ~LIR_OpArrayCopy::dst_null_check; 785 786 787 if (expected_type != nullptr) { 788 Value length_limit = nullptr; 789 790 IfOp* ifop = length->as_IfOp(); 791 if (ifop != nullptr) { 792 // look for expressions like min(v, a.length) which ends up as 793 // x > y ? y : x or x >= y ? y : x 794 if ((ifop->cond() == If::gtr || ifop->cond() == If::geq) && 795 ifop->x() == ifop->fval() && 796 ifop->y() == ifop->tval()) { 797 length_limit = ifop->y(); 798 } 799 } 800 801 // try to skip null checks and range checks 802 NewArray* src_array = src->as_NewArray(); 803 if (src_array != nullptr) { 804 flags &= ~LIR_OpArrayCopy::src_null_check; 805 if (length_limit != nullptr && 806 src_array->length() == length_limit && 807 is_constant_zero(src_pos)) { 808 flags &= ~LIR_OpArrayCopy::src_range_check; 809 } 810 } 811 812 NewArray* dst_array = dst->as_NewArray(); 813 if (dst_array != nullptr) { 814 flags &= ~LIR_OpArrayCopy::dst_null_check; 815 if (length_limit != nullptr && 816 dst_array->length() == length_limit && 817 is_constant_zero(dst_pos)) { 818 flags &= ~LIR_OpArrayCopy::dst_range_check; 819 } 820 } 821 822 // check from incoming constant values 823 if (positive_constant(src_pos)) 824 flags &= ~LIR_OpArrayCopy::src_pos_positive_check; 825 if (positive_constant(dst_pos)) 826 flags &= ~LIR_OpArrayCopy::dst_pos_positive_check; 827 if (positive_constant(length)) 828 flags &= ~LIR_OpArrayCopy::length_positive_check; 829 830 // see if the range check can be elided, which might also imply 831 // that src or dst is non-null. 832 ArrayLength* al = length->as_ArrayLength(); 833 if (al != nullptr) { 834 if (al->array() == src) { 835 // it's the length of the source array 836 flags &= ~LIR_OpArrayCopy::length_positive_check; 837 flags &= ~LIR_OpArrayCopy::src_null_check; 838 if (is_constant_zero(src_pos)) 839 flags &= ~LIR_OpArrayCopy::src_range_check; 840 } 841 if (al->array() == dst) { 842 // it's the length of the destination array 843 flags &= ~LIR_OpArrayCopy::length_positive_check; 844 flags &= ~LIR_OpArrayCopy::dst_null_check; 845 if (is_constant_zero(dst_pos)) 846 flags &= ~LIR_OpArrayCopy::dst_range_check; 847 } 848 } 849 if (is_exact) { 850 flags &= ~LIR_OpArrayCopy::type_check; 851 } 852 } 853 854 IntConstant* src_int = src_pos->type()->as_IntConstant(); 855 IntConstant* dst_int = dst_pos->type()->as_IntConstant(); 856 if (src_int && dst_int) { 857 int s_offs = src_int->value(); 858 int d_offs = dst_int->value(); 859 if (src_int->value() >= dst_int->value()) { 860 flags &= ~LIR_OpArrayCopy::overlapping; 861 } 862 if (expected_type != nullptr) { 863 BasicType t = expected_type->element_type()->basic_type(); 864 int element_size = type2aelembytes(t); 865 if (((arrayOopDesc::base_offset_in_bytes(t) + (uint)s_offs * element_size) % HeapWordSize == 0) && 866 ((arrayOopDesc::base_offset_in_bytes(t) + (uint)d_offs * element_size) % HeapWordSize == 0)) { 867 flags &= ~LIR_OpArrayCopy::unaligned; 868 } 869 } 870 } else if (src_pos == dst_pos || is_constant_zero(dst_pos)) { 871 // src and dest positions are the same, or dst is zero so assume 872 // nonoverlapping copy. 873 flags &= ~LIR_OpArrayCopy::overlapping; 874 } 875 876 if (src == dst) { 877 // moving within a single array so no type checks are needed 878 if (flags & LIR_OpArrayCopy::type_check) { 879 flags &= ~LIR_OpArrayCopy::type_check; 880 } 881 } 882 *flagsp = flags; 883 *expected_typep = (ciArrayKlass*)expected_type; 884 } 885 886 887 LIR_Opr LIRGenerator::force_to_spill(LIR_Opr value, BasicType t) { 888 assert(type2size[t] == type2size[value->type()], 889 "size mismatch: t=%s, value->type()=%s", type2name(t), type2name(value->type())); 890 if (!value->is_register()) { 891 // force into a register 892 LIR_Opr r = new_register(value->type()); 893 __ move(value, r); 894 value = r; 895 } 896 897 // create a spill location 898 LIR_Opr tmp = new_register(t); 899 set_vreg_flag(tmp, LIRGenerator::must_start_in_memory); 900 901 // move from register to spill 902 __ move(value, tmp); 903 return tmp; 904 } 905 906 void LIRGenerator::profile_branch(If* if_instr, If::Condition cond) { 907 if (if_instr->should_profile()) { 908 ciMethod* method = if_instr->profiled_method(); 909 assert(method != nullptr, "method should be set if branch is profiled"); 910 ciMethodData* md = method->method_data_or_null(); 911 assert(md != nullptr, "Sanity"); 912 ciProfileData* data = md->bci_to_data(if_instr->profiled_bci()); 913 assert(data != nullptr, "must have profiling data"); 914 assert(data->is_BranchData(), "need BranchData for two-way branches"); 915 int taken_count_offset = md->byte_offset_of_slot(data, BranchData::taken_offset()); 916 int not_taken_count_offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset()); 917 if (if_instr->is_swapped()) { 918 int t = taken_count_offset; 919 taken_count_offset = not_taken_count_offset; 920 not_taken_count_offset = t; 921 } 922 923 LIR_Opr md_reg = new_register(T_METADATA); 924 __ metadata2reg(md->constant_encoding(), md_reg); 925 926 LIR_Opr data_offset_reg = new_pointer_register(); 927 __ cmove(lir_cond(cond), 928 LIR_OprFact::intptrConst(taken_count_offset), 929 LIR_OprFact::intptrConst(not_taken_count_offset), 930 data_offset_reg, as_BasicType(if_instr->x()->type())); 931 932 // MDO cells are intptr_t, so the data_reg width is arch-dependent. 933 LIR_Opr data_reg = new_pointer_register(); 934 LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, data_reg->type()); 935 __ move(data_addr, data_reg); 936 // Use leal instead of add to avoid destroying condition codes on x86 937 LIR_Address* fake_incr_value = new LIR_Address(data_reg, DataLayout::counter_increment, T_INT); 938 __ leal(LIR_OprFact::address(fake_incr_value), data_reg); 939 __ move(data_reg, data_addr); 940 } 941 } 942 943 // Phi technique: 944 // This is about passing live values from one basic block to the other. 945 // In code generated with Java it is rather rare that more than one 946 // value is on the stack from one basic block to the other. 947 // We optimize our technique for efficient passing of one value 948 // (of type long, int, double..) but it can be extended. 949 // When entering or leaving a basic block, all registers and all spill 950 // slots are release and empty. We use the released registers 951 // and spill slots to pass the live values from one block 952 // to the other. The topmost value, i.e., the value on TOS of expression 953 // stack is passed in registers. All other values are stored in spilling 954 // area. Every Phi has an index which designates its spill slot 955 // At exit of a basic block, we fill the register(s) and spill slots. 956 // At entry of a basic block, the block_prolog sets up the content of phi nodes 957 // and locks necessary registers and spilling slots. 958 959 960 // move current value to referenced phi function 961 void LIRGenerator::move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val) { 962 Phi* phi = sux_val->as_Phi(); 963 // cur_val can be null without phi being null in conjunction with inlining 964 if (phi != nullptr && cur_val != nullptr && cur_val != phi && !phi->is_illegal()) { 965 if (phi->is_local()) { 966 for (int i = 0; i < phi->operand_count(); i++) { 967 Value op = phi->operand_at(i); 968 if (op != nullptr && op->type()->is_illegal()) { 969 bailout("illegal phi operand"); 970 } 971 } 972 } 973 Phi* cur_phi = cur_val->as_Phi(); 974 if (cur_phi != nullptr && cur_phi->is_illegal()) { 975 // Phi and local would need to get invalidated 976 // (which is unexpected for Linear Scan). 977 // But this case is very rare so we simply bail out. 978 bailout("propagation of illegal phi"); 979 return; 980 } 981 LIR_Opr operand = cur_val->operand(); 982 if (operand->is_illegal()) { 983 assert(cur_val->as_Constant() != nullptr || cur_val->as_Local() != nullptr, 984 "these can be produced lazily"); 985 operand = operand_for_instruction(cur_val); 986 } 987 resolver->move(operand, operand_for_instruction(phi)); 988 } 989 } 990 991 992 // Moves all stack values into their PHI position 993 void LIRGenerator::move_to_phi(ValueStack* cur_state) { 994 BlockBegin* bb = block(); 995 if (bb->number_of_sux() == 1) { 996 BlockBegin* sux = bb->sux_at(0); 997 assert(sux->number_of_preds() > 0, "invalid CFG"); 998 999 // a block with only one predecessor never has phi functions 1000 if (sux->number_of_preds() > 1) { 1001 PhiResolver resolver(this); 1002 1003 ValueStack* sux_state = sux->state(); 1004 Value sux_value; 1005 int index; 1006 1007 assert(cur_state->scope() == sux_state->scope(), "not matching"); 1008 assert(cur_state->locals_size() == sux_state->locals_size(), "not matching"); 1009 assert(cur_state->stack_size() == sux_state->stack_size(), "not matching"); 1010 1011 for_each_stack_value(sux_state, index, sux_value) { 1012 move_to_phi(&resolver, cur_state->stack_at(index), sux_value); 1013 } 1014 1015 for_each_local_value(sux_state, index, sux_value) { 1016 move_to_phi(&resolver, cur_state->local_at(index), sux_value); 1017 } 1018 1019 assert(cur_state->caller_state() == sux_state->caller_state(), "caller states must be equal"); 1020 } 1021 } 1022 } 1023 1024 1025 LIR_Opr LIRGenerator::new_register(BasicType type) { 1026 int vreg_num = _virtual_register_number; 1027 // Add a little fudge factor for the bailout since the bailout is only checked periodically. This allows us to hand out 1028 // a few extra registers before we really run out which helps to avoid to trip over assertions. 1029 if (vreg_num + 20 >= LIR_Opr::vreg_max) { 1030 bailout("out of virtual registers in LIR generator"); 1031 if (vreg_num + 2 >= LIR_Opr::vreg_max) { 1032 // Wrap it around and continue until bailout really happens to avoid hitting assertions. 1033 _virtual_register_number = LIR_Opr::vreg_base; 1034 vreg_num = LIR_Opr::vreg_base; 1035 } 1036 } 1037 _virtual_register_number += 1; 1038 LIR_Opr vreg = LIR_OprFact::virtual_register(vreg_num, type); 1039 assert(vreg != LIR_OprFact::illegal(), "ran out of virtual registers"); 1040 return vreg; 1041 } 1042 1043 1044 // Try to lock using register in hint 1045 LIR_Opr LIRGenerator::rlock(Value instr) { 1046 return new_register(instr->type()); 1047 } 1048 1049 1050 // does an rlock and sets result 1051 LIR_Opr LIRGenerator::rlock_result(Value x) { 1052 LIR_Opr reg = rlock(x); 1053 set_result(x, reg); 1054 return reg; 1055 } 1056 1057 1058 // does an rlock and sets result 1059 LIR_Opr LIRGenerator::rlock_result(Value x, BasicType type) { 1060 LIR_Opr reg; 1061 switch (type) { 1062 case T_BYTE: 1063 case T_BOOLEAN: 1064 reg = rlock_byte(type); 1065 break; 1066 default: 1067 reg = rlock(x); 1068 break; 1069 } 1070 1071 set_result(x, reg); 1072 return reg; 1073 } 1074 1075 1076 //--------------------------------------------------------------------- 1077 ciObject* LIRGenerator::get_jobject_constant(Value value) { 1078 ObjectType* oc = value->type()->as_ObjectType(); 1079 if (oc) { 1080 return oc->constant_value(); 1081 } 1082 return nullptr; 1083 } 1084 1085 1086 void LIRGenerator::do_ExceptionObject(ExceptionObject* x) { 1087 assert(block()->is_set(BlockBegin::exception_entry_flag), "ExceptionObject only allowed in exception handler block"); 1088 assert(block()->next() == x, "ExceptionObject must be first instruction of block"); 1089 1090 // no moves are created for phi functions at the begin of exception 1091 // handlers, so assign operands manually here 1092 for_each_phi_fun(block(), phi, 1093 if (!phi->is_illegal()) { operand_for_instruction(phi); }); 1094 1095 LIR_Opr thread_reg = getThreadPointer(); 1096 __ move_wide(new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT), 1097 exceptionOopOpr()); 1098 __ move_wide(LIR_OprFact::oopConst(nullptr), 1099 new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT)); 1100 __ move_wide(LIR_OprFact::oopConst(nullptr), 1101 new LIR_Address(thread_reg, in_bytes(JavaThread::exception_pc_offset()), T_OBJECT)); 1102 1103 LIR_Opr result = new_register(T_OBJECT); 1104 __ move(exceptionOopOpr(), result); 1105 set_result(x, result); 1106 } 1107 1108 1109 //---------------------------------------------------------------------- 1110 //---------------------------------------------------------------------- 1111 //---------------------------------------------------------------------- 1112 //---------------------------------------------------------------------- 1113 // visitor functions 1114 //---------------------------------------------------------------------- 1115 //---------------------------------------------------------------------- 1116 //---------------------------------------------------------------------- 1117 //---------------------------------------------------------------------- 1118 1119 void LIRGenerator::do_Phi(Phi* x) { 1120 // phi functions are never visited directly 1121 ShouldNotReachHere(); 1122 } 1123 1124 1125 // Code for a constant is generated lazily unless the constant is frequently used and can't be inlined. 1126 void LIRGenerator::do_Constant(Constant* x) { 1127 if (x->state_before() != nullptr) { 1128 // Any constant with a ValueStack requires patching so emit the patch here 1129 LIR_Opr reg = rlock_result(x); 1130 CodeEmitInfo* info = state_for(x, x->state_before()); 1131 __ oop2reg_patch(nullptr, reg, info); 1132 } else if (x->use_count() > 1 && !can_inline_as_constant(x)) { 1133 if (!x->is_pinned()) { 1134 // unpinned constants are handled specially so that they can be 1135 // put into registers when they are used multiple times within a 1136 // block. After the block completes their operand will be 1137 // cleared so that other blocks can't refer to that register. 1138 set_result(x, load_constant(x)); 1139 } else { 1140 LIR_Opr res = x->operand(); 1141 if (!res->is_valid()) { 1142 res = LIR_OprFact::value_type(x->type()); 1143 } 1144 if (res->is_constant()) { 1145 LIR_Opr reg = rlock_result(x); 1146 __ move(res, reg); 1147 } else { 1148 set_result(x, res); 1149 } 1150 } 1151 } else { 1152 set_result(x, LIR_OprFact::value_type(x->type())); 1153 } 1154 } 1155 1156 1157 void LIRGenerator::do_Local(Local* x) { 1158 // operand_for_instruction has the side effect of setting the result 1159 // so there's no need to do it here. 1160 operand_for_instruction(x); 1161 } 1162 1163 1164 void LIRGenerator::do_Return(Return* x) { 1165 if (compilation()->env()->dtrace_method_probes()) { 1166 BasicTypeList signature; 1167 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread 1168 signature.append(T_METADATA); // Method* 1169 LIR_OprList* args = new LIR_OprList(); 1170 args->append(getThreadPointer()); 1171 LIR_Opr meth = new_register(T_METADATA); 1172 __ metadata2reg(method()->constant_encoding(), meth); 1173 args->append(meth); 1174 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), voidType, nullptr); 1175 } 1176 1177 if (x->type()->is_void()) { 1178 __ return_op(LIR_OprFact::illegalOpr); 1179 } else { 1180 LIR_Opr reg = result_register_for(x->type(), /*callee=*/true); 1181 LIRItem result(x->result(), this); 1182 1183 result.load_item_force(reg); 1184 __ return_op(result.result()); 1185 } 1186 set_no_result(x); 1187 } 1188 1189 // Example: ref.get() 1190 // Combination of LoadField and g1 pre-write barrier 1191 void LIRGenerator::do_Reference_get(Intrinsic* x) { 1192 1193 const int referent_offset = java_lang_ref_Reference::referent_offset(); 1194 1195 assert(x->number_of_arguments() == 1, "wrong type"); 1196 1197 LIRItem reference(x->argument_at(0), this); 1198 reference.load_item(); 1199 1200 // need to perform the null check on the reference object 1201 CodeEmitInfo* info = nullptr; 1202 if (x->needs_null_check()) { 1203 info = state_for(x); 1204 } 1205 1206 LIR_Opr result = rlock_result(x, T_OBJECT); 1207 access_load_at(IN_HEAP | ON_WEAK_OOP_REF, T_OBJECT, 1208 reference, LIR_OprFact::intConst(referent_offset), result, 1209 nullptr, info); 1210 } 1211 1212 // Example: clazz.isInstance(object) 1213 void LIRGenerator::do_isInstance(Intrinsic* x) { 1214 assert(x->number_of_arguments() == 2, "wrong type"); 1215 1216 LIRItem clazz(x->argument_at(0), this); 1217 LIRItem object(x->argument_at(1), this); 1218 clazz.load_item(); 1219 object.load_item(); 1220 LIR_Opr result = rlock_result(x); 1221 1222 // need to perform null check on clazz 1223 if (x->needs_null_check()) { 1224 CodeEmitInfo* info = state_for(x); 1225 __ null_check(clazz.result(), info); 1226 } 1227 1228 address pd_instanceof_fn = isInstance_entry(); 1229 LIR_Opr call_result = call_runtime(clazz.value(), object.value(), 1230 pd_instanceof_fn, 1231 x->type(), 1232 nullptr); // null CodeEmitInfo results in a leaf call 1233 __ move(call_result, result); 1234 } 1235 1236 void LIRGenerator::load_klass(LIR_Opr obj, LIR_Opr klass, CodeEmitInfo* null_check_info) { 1237 __ load_klass(obj, klass, null_check_info); 1238 } 1239 1240 // Example: object.getClass () 1241 void LIRGenerator::do_getClass(Intrinsic* x) { 1242 assert(x->number_of_arguments() == 1, "wrong type"); 1243 1244 LIRItem rcvr(x->argument_at(0), this); 1245 rcvr.load_item(); 1246 LIR_Opr temp = new_register(T_ADDRESS); 1247 LIR_Opr result = rlock_result(x); 1248 1249 // need to perform the null check on the rcvr 1250 CodeEmitInfo* info = nullptr; 1251 if (x->needs_null_check()) { 1252 info = state_for(x); 1253 } 1254 1255 LIR_Opr klass = new_register(T_METADATA); 1256 load_klass(rcvr.result(), klass, info); 1257 __ move_wide(new LIR_Address(klass, in_bytes(Klass::java_mirror_offset()), T_ADDRESS), temp); 1258 // mirror = ((OopHandle)mirror)->resolve(); 1259 access_load(IN_NATIVE, T_OBJECT, 1260 LIR_OprFact::address(new LIR_Address(temp, T_OBJECT)), result); 1261 } 1262 1263 void LIRGenerator::do_getObjectSize(Intrinsic* x) { 1264 assert(x->number_of_arguments() == 3, "wrong type"); 1265 LIR_Opr result_reg = rlock_result(x); 1266 1267 LIRItem value(x->argument_at(2), this); 1268 value.load_item(); 1269 1270 LIR_Opr klass = new_register(T_METADATA); 1271 load_klass(value.result(), klass, nullptr); 1272 LIR_Opr layout = new_register(T_INT); 1273 __ move(new LIR_Address(klass, in_bytes(Klass::layout_helper_offset()), T_INT), layout); 1274 1275 LabelObj* L_done = new LabelObj(); 1276 LabelObj* L_array = new LabelObj(); 1277 1278 __ cmp(lir_cond_lessEqual, layout, 0); 1279 __ branch(lir_cond_lessEqual, L_array->label()); 1280 1281 // Instance case: the layout helper gives us instance size almost directly, 1282 // but we need to mask out the _lh_instance_slow_path_bit. 1283 1284 assert((int) Klass::_lh_instance_slow_path_bit < BytesPerLong, "clear bit"); 1285 1286 LIR_Opr mask = load_immediate(~(jint) right_n_bits(LogBytesPerLong), T_INT); 1287 __ logical_and(layout, mask, layout); 1288 __ convert(Bytecodes::_i2l, layout, result_reg); 1289 1290 __ branch(lir_cond_always, L_done->label()); 1291 1292 // Array case: size is round(header + element_size*arraylength). 1293 // Since arraylength is different for every array instance, we have to 1294 // compute the whole thing at runtime. 1295 1296 __ branch_destination(L_array->label()); 1297 1298 int round_mask = MinObjAlignmentInBytes - 1; 1299 1300 // Figure out header sizes first. 1301 LIR_Opr hss = load_immediate(Klass::_lh_header_size_shift, T_INT); 1302 LIR_Opr hsm = load_immediate(Klass::_lh_header_size_mask, T_INT); 1303 1304 LIR_Opr header_size = new_register(T_INT); 1305 __ move(layout, header_size); 1306 LIR_Opr tmp = new_register(T_INT); 1307 __ unsigned_shift_right(header_size, hss, header_size, tmp); 1308 __ logical_and(header_size, hsm, header_size); 1309 __ add(header_size, LIR_OprFact::intConst(round_mask), header_size); 1310 1311 // Figure out the array length in bytes 1312 assert(Klass::_lh_log2_element_size_shift == 0, "use shift in place"); 1313 LIR_Opr l2esm = load_immediate(Klass::_lh_log2_element_size_mask, T_INT); 1314 __ logical_and(layout, l2esm, layout); 1315 1316 LIR_Opr length_int = new_register(T_INT); 1317 __ move(new LIR_Address(value.result(), arrayOopDesc::length_offset_in_bytes(), T_INT), length_int); 1318 1319 #ifdef _LP64 1320 LIR_Opr length = new_register(T_LONG); 1321 __ convert(Bytecodes::_i2l, length_int, length); 1322 #endif 1323 1324 // Shift-left awkwardness. Normally it is just: 1325 // __ shift_left(length, layout, length); 1326 // But C1 cannot perform shift_left with non-constant count, so we end up 1327 // doing the per-bit loop dance here. x86_32 also does not know how to shift 1328 // longs, so we have to act on ints. 1329 LabelObj* L_shift_loop = new LabelObj(); 1330 LabelObj* L_shift_exit = new LabelObj(); 1331 1332 __ branch_destination(L_shift_loop->label()); 1333 __ cmp(lir_cond_equal, layout, 0); 1334 __ branch(lir_cond_equal, L_shift_exit->label()); 1335 1336 #ifdef _LP64 1337 __ shift_left(length, 1, length); 1338 #else 1339 __ shift_left(length_int, 1, length_int); 1340 #endif 1341 1342 __ sub(layout, LIR_OprFact::intConst(1), layout); 1343 1344 __ branch(lir_cond_always, L_shift_loop->label()); 1345 __ branch_destination(L_shift_exit->label()); 1346 1347 // Mix all up, round, and push to the result. 1348 #ifdef _LP64 1349 LIR_Opr header_size_long = new_register(T_LONG); 1350 __ convert(Bytecodes::_i2l, header_size, header_size_long); 1351 __ add(length, header_size_long, length); 1352 if (round_mask != 0) { 1353 LIR_Opr round_mask_opr = load_immediate(~(jlong)round_mask, T_LONG); 1354 __ logical_and(length, round_mask_opr, length); 1355 } 1356 __ move(length, result_reg); 1357 #else 1358 __ add(length_int, header_size, length_int); 1359 if (round_mask != 0) { 1360 LIR_Opr round_mask_opr = load_immediate(~round_mask, T_INT); 1361 __ logical_and(length_int, round_mask_opr, length_int); 1362 } 1363 __ convert(Bytecodes::_i2l, length_int, result_reg); 1364 #endif 1365 1366 __ branch_destination(L_done->label()); 1367 } 1368 1369 void LIRGenerator::do_scopedValueCache(Intrinsic* x) { 1370 do_JavaThreadField(x, JavaThread::scopedValueCache_offset()); 1371 } 1372 1373 // Example: Thread.currentCarrierThread() 1374 void LIRGenerator::do_currentCarrierThread(Intrinsic* x) { 1375 do_JavaThreadField(x, JavaThread::threadObj_offset()); 1376 } 1377 1378 void LIRGenerator::do_vthread(Intrinsic* x) { 1379 do_JavaThreadField(x, JavaThread::vthread_offset()); 1380 } 1381 1382 void LIRGenerator::do_JavaThreadField(Intrinsic* x, ByteSize offset) { 1383 assert(x->number_of_arguments() == 0, "wrong type"); 1384 LIR_Opr temp = new_register(T_ADDRESS); 1385 LIR_Opr reg = rlock_result(x); 1386 __ move(new LIR_Address(getThreadPointer(), in_bytes(offset), T_ADDRESS), temp); 1387 access_load(IN_NATIVE, T_OBJECT, 1388 LIR_OprFact::address(new LIR_Address(temp, T_OBJECT)), reg); 1389 } 1390 1391 void LIRGenerator::do_RegisterFinalizer(Intrinsic* x) { 1392 assert(x->number_of_arguments() == 1, "wrong type"); 1393 LIRItem receiver(x->argument_at(0), this); 1394 1395 receiver.load_item(); 1396 BasicTypeList signature; 1397 signature.append(T_OBJECT); // receiver 1398 LIR_OprList* args = new LIR_OprList(); 1399 args->append(receiver.result()); 1400 CodeEmitInfo* info = state_for(x, x->state()); 1401 call_runtime(&signature, args, 1402 CAST_FROM_FN_PTR(address, Runtime1::entry_for(C1StubId::register_finalizer_id)), 1403 voidType, info); 1404 1405 set_no_result(x); 1406 } 1407 1408 1409 //------------------------local access-------------------------------------- 1410 1411 LIR_Opr LIRGenerator::operand_for_instruction(Instruction* x) { 1412 if (x->operand()->is_illegal()) { 1413 Constant* c = x->as_Constant(); 1414 if (c != nullptr) { 1415 x->set_operand(LIR_OprFact::value_type(c->type())); 1416 } else { 1417 assert(x->as_Phi() || x->as_Local() != nullptr, "only for Phi and Local"); 1418 // allocate a virtual register for this local or phi 1419 x->set_operand(rlock(x)); 1420 #ifdef ASSERT 1421 _instruction_for_operand.at_put_grow(x->operand()->vreg_number(), x, nullptr); 1422 #endif 1423 } 1424 } 1425 return x->operand(); 1426 } 1427 1428 #ifdef ASSERT 1429 Instruction* LIRGenerator::instruction_for_vreg(int reg_num) { 1430 if (reg_num < _instruction_for_operand.length()) { 1431 return _instruction_for_operand.at(reg_num); 1432 } 1433 return nullptr; 1434 } 1435 #endif 1436 1437 void LIRGenerator::set_vreg_flag(int vreg_num, VregFlag f) { 1438 if (_vreg_flags.size_in_bits() == 0) { 1439 BitMap2D temp(100, num_vreg_flags); 1440 _vreg_flags = temp; 1441 } 1442 _vreg_flags.at_put_grow(vreg_num, f, true); 1443 } 1444 1445 bool LIRGenerator::is_vreg_flag_set(int vreg_num, VregFlag f) { 1446 if (!_vreg_flags.is_valid_index(vreg_num, f)) { 1447 return false; 1448 } 1449 return _vreg_flags.at(vreg_num, f); 1450 } 1451 1452 1453 // Block local constant handling. This code is useful for keeping 1454 // unpinned constants and constants which aren't exposed in the IR in 1455 // registers. Unpinned Constant instructions have their operands 1456 // cleared when the block is finished so that other blocks can't end 1457 // up referring to their registers. 1458 1459 LIR_Opr LIRGenerator::load_constant(Constant* x) { 1460 assert(!x->is_pinned(), "only for unpinned constants"); 1461 _unpinned_constants.append(x); 1462 return load_constant(LIR_OprFact::value_type(x->type())->as_constant_ptr()); 1463 } 1464 1465 1466 LIR_Opr LIRGenerator::load_constant(LIR_Const* c) { 1467 BasicType t = c->type(); 1468 for (int i = 0; i < _constants.length(); i++) { 1469 LIR_Const* other = _constants.at(i); 1470 if (t == other->type()) { 1471 switch (t) { 1472 case T_INT: 1473 case T_FLOAT: 1474 if (c->as_jint_bits() != other->as_jint_bits()) continue; 1475 break; 1476 case T_LONG: 1477 case T_DOUBLE: 1478 if (c->as_jint_hi_bits() != other->as_jint_hi_bits()) continue; 1479 if (c->as_jint_lo_bits() != other->as_jint_lo_bits()) continue; 1480 break; 1481 case T_OBJECT: 1482 if (c->as_jobject() != other->as_jobject()) continue; 1483 break; 1484 default: 1485 break; 1486 } 1487 return _reg_for_constants.at(i); 1488 } 1489 } 1490 1491 LIR_Opr result = new_register(t); 1492 __ move((LIR_Opr)c, result); 1493 _constants.append(c); 1494 _reg_for_constants.append(result); 1495 return result; 1496 } 1497 1498 //------------------------field access-------------------------------------- 1499 1500 void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) { 1501 assert(x->number_of_arguments() == 4, "wrong type"); 1502 LIRItem obj (x->argument_at(0), this); // object 1503 LIRItem offset(x->argument_at(1), this); // offset of field 1504 LIRItem cmp (x->argument_at(2), this); // value to compare with field 1505 LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp 1506 assert(obj.type()->tag() == objectTag, "invalid type"); 1507 assert(cmp.type()->tag() == type->tag(), "invalid type"); 1508 assert(val.type()->tag() == type->tag(), "invalid type"); 1509 1510 LIR_Opr result = access_atomic_cmpxchg_at(IN_HEAP, as_BasicType(type), 1511 obj, offset, cmp, val); 1512 set_result(x, result); 1513 } 1514 1515 // Comment copied form templateTable_i486.cpp 1516 // ---------------------------------------------------------------------------- 1517 // Volatile variables demand their effects be made known to all CPU's in 1518 // order. Store buffers on most chips allow reads & writes to reorder; the 1519 // JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of 1520 // memory barrier (i.e., it's not sufficient that the interpreter does not 1521 // reorder volatile references, the hardware also must not reorder them). 1522 // 1523 // According to the new Java Memory Model (JMM): 1524 // (1) All volatiles are serialized wrt to each other. 1525 // ALSO reads & writes act as acquire & release, so: 1526 // (2) A read cannot let unrelated NON-volatile memory refs that happen after 1527 // the read float up to before the read. It's OK for non-volatile memory refs 1528 // that happen before the volatile read to float down below it. 1529 // (3) Similar a volatile write cannot let unrelated NON-volatile memory refs 1530 // that happen BEFORE the write float down to after the write. It's OK for 1531 // non-volatile memory refs that happen after the volatile write to float up 1532 // before it. 1533 // 1534 // We only put in barriers around volatile refs (they are expensive), not 1535 // _between_ memory refs (that would require us to track the flavor of the 1536 // previous memory refs). Requirements (2) and (3) require some barriers 1537 // before volatile stores and after volatile loads. These nearly cover 1538 // requirement (1) but miss the volatile-store-volatile-load case. This final 1539 // case is placed after volatile-stores although it could just as well go 1540 // before volatile-loads. 1541 1542 1543 void LIRGenerator::do_StoreField(StoreField* x) { 1544 bool needs_patching = x->needs_patching(); 1545 bool is_volatile = x->field()->is_volatile(); 1546 BasicType field_type = x->field_type(); 1547 1548 CodeEmitInfo* info = nullptr; 1549 if (needs_patching) { 1550 assert(x->explicit_null_check() == nullptr, "can't fold null check into patching field access"); 1551 info = state_for(x, x->state_before()); 1552 } else if (x->needs_null_check()) { 1553 NullCheck* nc = x->explicit_null_check(); 1554 if (nc == nullptr) { 1555 info = state_for(x); 1556 } else { 1557 info = state_for(nc); 1558 } 1559 } 1560 1561 LIRItem object(x->obj(), this); 1562 LIRItem value(x->value(), this); 1563 1564 object.load_item(); 1565 1566 if (is_volatile || needs_patching) { 1567 // load item if field is volatile (fewer special cases for volatiles) 1568 // load item if field not initialized 1569 // load item if field not constant 1570 // because of code patching we cannot inline constants 1571 if (field_type == T_BYTE || field_type == T_BOOLEAN) { 1572 value.load_byte_item(); 1573 } else { 1574 value.load_item(); 1575 } 1576 } else { 1577 value.load_for_store(field_type); 1578 } 1579 1580 set_no_result(x); 1581 1582 #ifndef PRODUCT 1583 if (PrintNotLoaded && needs_patching) { 1584 tty->print_cr(" ###class not loaded at store_%s bci %d", 1585 x->is_static() ? "static" : "field", x->printable_bci()); 1586 } 1587 #endif 1588 1589 if (x->needs_null_check() && 1590 (needs_patching || 1591 MacroAssembler::needs_explicit_null_check(x->offset()))) { 1592 // Emit an explicit null check because the offset is too large. 1593 // If the class is not loaded and the object is null, we need to deoptimize to throw a 1594 // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code. 1595 __ null_check(object.result(), new CodeEmitInfo(info), /* deoptimize */ needs_patching); 1596 } 1597 1598 DecoratorSet decorators = IN_HEAP; 1599 if (is_volatile) { 1600 decorators |= MO_SEQ_CST; 1601 } 1602 if (needs_patching) { 1603 decorators |= C1_NEEDS_PATCHING; 1604 } 1605 1606 access_store_at(decorators, field_type, object, LIR_OprFact::intConst(x->offset()), 1607 value.result(), info != nullptr ? new CodeEmitInfo(info) : nullptr, info); 1608 } 1609 1610 void LIRGenerator::do_StoreIndexed(StoreIndexed* x) { 1611 assert(x->is_pinned(),""); 1612 bool needs_range_check = x->compute_needs_range_check(); 1613 bool use_length = x->length() != nullptr; 1614 bool obj_store = is_reference_type(x->elt_type()); 1615 bool needs_store_check = obj_store && (x->value()->as_Constant() == nullptr || 1616 !get_jobject_constant(x->value())->is_null_object() || 1617 x->should_profile()); 1618 1619 LIRItem array(x->array(), this); 1620 LIRItem index(x->index(), this); 1621 LIRItem value(x->value(), this); 1622 LIRItem length(this); 1623 1624 array.load_item(); 1625 index.load_nonconstant(); 1626 1627 if (use_length && needs_range_check) { 1628 length.set_instruction(x->length()); 1629 length.load_item(); 1630 1631 } 1632 if (needs_store_check || x->check_boolean()) { 1633 value.load_item(); 1634 } else { 1635 value.load_for_store(x->elt_type()); 1636 } 1637 1638 set_no_result(x); 1639 1640 // the CodeEmitInfo must be duplicated for each different 1641 // LIR-instruction because spilling can occur anywhere between two 1642 // instructions and so the debug information must be different 1643 CodeEmitInfo* range_check_info = state_for(x); 1644 CodeEmitInfo* null_check_info = nullptr; 1645 if (x->needs_null_check()) { 1646 null_check_info = new CodeEmitInfo(range_check_info); 1647 } 1648 1649 if (needs_range_check) { 1650 if (use_length) { 1651 __ cmp(lir_cond_belowEqual, length.result(), index.result()); 1652 __ branch(lir_cond_belowEqual, new RangeCheckStub(range_check_info, index.result(), array.result())); 1653 } else { 1654 array_range_check(array.result(), index.result(), null_check_info, range_check_info); 1655 // range_check also does the null check 1656 null_check_info = nullptr; 1657 } 1658 } 1659 1660 if (GenerateArrayStoreCheck && needs_store_check) { 1661 CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info); 1662 array_store_check(value.result(), array.result(), store_check_info, x->profiled_method(), x->profiled_bci()); 1663 } 1664 1665 DecoratorSet decorators = IN_HEAP | IS_ARRAY; 1666 if (x->check_boolean()) { 1667 decorators |= C1_MASK_BOOLEAN; 1668 } 1669 1670 access_store_at(decorators, x->elt_type(), array, index.result(), value.result(), 1671 nullptr, null_check_info); 1672 } 1673 1674 void LIRGenerator::access_load_at(DecoratorSet decorators, BasicType type, 1675 LIRItem& base, LIR_Opr offset, LIR_Opr result, 1676 CodeEmitInfo* patch_info, CodeEmitInfo* load_emit_info) { 1677 decorators |= ACCESS_READ; 1678 LIRAccess access(this, decorators, base, offset, type, patch_info, load_emit_info); 1679 if (access.is_raw()) { 1680 _barrier_set->BarrierSetC1::load_at(access, result); 1681 } else { 1682 _barrier_set->load_at(access, result); 1683 } 1684 } 1685 1686 void LIRGenerator::access_load(DecoratorSet decorators, BasicType type, 1687 LIR_Opr addr, LIR_Opr result) { 1688 decorators |= ACCESS_READ; 1689 LIRAccess access(this, decorators, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, type); 1690 access.set_resolved_addr(addr); 1691 if (access.is_raw()) { 1692 _barrier_set->BarrierSetC1::load(access, result); 1693 } else { 1694 _barrier_set->load(access, result); 1695 } 1696 } 1697 1698 void LIRGenerator::access_store_at(DecoratorSet decorators, BasicType type, 1699 LIRItem& base, LIR_Opr offset, LIR_Opr value, 1700 CodeEmitInfo* patch_info, CodeEmitInfo* store_emit_info) { 1701 decorators |= ACCESS_WRITE; 1702 LIRAccess access(this, decorators, base, offset, type, patch_info, store_emit_info); 1703 if (access.is_raw()) { 1704 _barrier_set->BarrierSetC1::store_at(access, value); 1705 } else { 1706 _barrier_set->store_at(access, value); 1707 } 1708 } 1709 1710 LIR_Opr LIRGenerator::access_atomic_cmpxchg_at(DecoratorSet decorators, BasicType type, 1711 LIRItem& base, LIRItem& offset, LIRItem& cmp_value, LIRItem& new_value) { 1712 decorators |= ACCESS_READ; 1713 decorators |= ACCESS_WRITE; 1714 // Atomic operations are SEQ_CST by default 1715 decorators |= ((decorators & MO_DECORATOR_MASK) == 0) ? MO_SEQ_CST : 0; 1716 LIRAccess access(this, decorators, base, offset, type); 1717 if (access.is_raw()) { 1718 return _barrier_set->BarrierSetC1::atomic_cmpxchg_at(access, cmp_value, new_value); 1719 } else { 1720 return _barrier_set->atomic_cmpxchg_at(access, cmp_value, new_value); 1721 } 1722 } 1723 1724 LIR_Opr LIRGenerator::access_atomic_xchg_at(DecoratorSet decorators, BasicType type, 1725 LIRItem& base, LIRItem& offset, LIRItem& value) { 1726 decorators |= ACCESS_READ; 1727 decorators |= ACCESS_WRITE; 1728 // Atomic operations are SEQ_CST by default 1729 decorators |= ((decorators & MO_DECORATOR_MASK) == 0) ? MO_SEQ_CST : 0; 1730 LIRAccess access(this, decorators, base, offset, type); 1731 if (access.is_raw()) { 1732 return _barrier_set->BarrierSetC1::atomic_xchg_at(access, value); 1733 } else { 1734 return _barrier_set->atomic_xchg_at(access, value); 1735 } 1736 } 1737 1738 LIR_Opr LIRGenerator::access_atomic_add_at(DecoratorSet decorators, BasicType type, 1739 LIRItem& base, LIRItem& offset, LIRItem& value) { 1740 decorators |= ACCESS_READ; 1741 decorators |= ACCESS_WRITE; 1742 // Atomic operations are SEQ_CST by default 1743 decorators |= ((decorators & MO_DECORATOR_MASK) == 0) ? MO_SEQ_CST : 0; 1744 LIRAccess access(this, decorators, base, offset, type); 1745 if (access.is_raw()) { 1746 return _barrier_set->BarrierSetC1::atomic_add_at(access, value); 1747 } else { 1748 return _barrier_set->atomic_add_at(access, value); 1749 } 1750 } 1751 1752 void LIRGenerator::do_LoadField(LoadField* x) { 1753 bool needs_patching = x->needs_patching(); 1754 bool is_volatile = x->field()->is_volatile(); 1755 BasicType field_type = x->field_type(); 1756 1757 CodeEmitInfo* info = nullptr; 1758 if (needs_patching) { 1759 assert(x->explicit_null_check() == nullptr, "can't fold null check into patching field access"); 1760 info = state_for(x, x->state_before()); 1761 } else if (x->needs_null_check()) { 1762 NullCheck* nc = x->explicit_null_check(); 1763 if (nc == nullptr) { 1764 info = state_for(x); 1765 } else { 1766 info = state_for(nc); 1767 } 1768 } 1769 1770 LIRItem object(x->obj(), this); 1771 1772 object.load_item(); 1773 1774 #ifndef PRODUCT 1775 if (PrintNotLoaded && needs_patching) { 1776 tty->print_cr(" ###class not loaded at load_%s bci %d", 1777 x->is_static() ? "static" : "field", x->printable_bci()); 1778 } 1779 #endif 1780 1781 bool stress_deopt = StressLoopInvariantCodeMotion && info && info->deoptimize_on_exception(); 1782 if (x->needs_null_check() && 1783 (needs_patching || 1784 MacroAssembler::needs_explicit_null_check(x->offset()) || 1785 stress_deopt)) { 1786 LIR_Opr obj = object.result(); 1787 if (stress_deopt) { 1788 obj = new_register(T_OBJECT); 1789 __ move(LIR_OprFact::oopConst(nullptr), obj); 1790 } 1791 // Emit an explicit null check because the offset is too large. 1792 // If the class is not loaded and the object is null, we need to deoptimize to throw a 1793 // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code. 1794 __ null_check(obj, new CodeEmitInfo(info), /* deoptimize */ needs_patching); 1795 } 1796 1797 DecoratorSet decorators = IN_HEAP; 1798 if (is_volatile) { 1799 decorators |= MO_SEQ_CST; 1800 } 1801 if (needs_patching) { 1802 decorators |= C1_NEEDS_PATCHING; 1803 } 1804 1805 LIR_Opr result = rlock_result(x, field_type); 1806 access_load_at(decorators, field_type, 1807 object, LIR_OprFact::intConst(x->offset()), result, 1808 info ? new CodeEmitInfo(info) : nullptr, info); 1809 } 1810 1811 // int/long jdk.internal.util.Preconditions.checkIndex 1812 void LIRGenerator::do_PreconditionsCheckIndex(Intrinsic* x, BasicType type) { 1813 assert(x->number_of_arguments() == 3, "wrong type"); 1814 LIRItem index(x->argument_at(0), this); 1815 LIRItem length(x->argument_at(1), this); 1816 LIRItem oobef(x->argument_at(2), this); 1817 1818 index.load_item(); 1819 length.load_item(); 1820 oobef.load_item(); 1821 1822 LIR_Opr result = rlock_result(x); 1823 // x->state() is created from copy_state_for_exception, it does not contains arguments 1824 // we should prepare them before entering into interpreter mode due to deoptimization. 1825 ValueStack* state = x->state(); 1826 for (int i = 0; i < x->number_of_arguments(); i++) { 1827 Value arg = x->argument_at(i); 1828 state->push(arg->type(), arg); 1829 } 1830 CodeEmitInfo* info = state_for(x, state); 1831 1832 LIR_Opr len = length.result(); 1833 LIR_Opr zero; 1834 if (type == T_INT) { 1835 zero = LIR_OprFact::intConst(0); 1836 if (length.result()->is_constant()){ 1837 len = LIR_OprFact::intConst(length.result()->as_jint()); 1838 } 1839 } else { 1840 assert(type == T_LONG, "sanity check"); 1841 zero = LIR_OprFact::longConst(0); 1842 if (length.result()->is_constant()){ 1843 len = LIR_OprFact::longConst(length.result()->as_jlong()); 1844 } 1845 } 1846 // C1 can not handle the case that comparing index with constant value while condition 1847 // is neither lir_cond_equal nor lir_cond_notEqual, see LIR_Assembler::comp_op. 1848 LIR_Opr zero_reg = new_register(type); 1849 __ move(zero, zero_reg); 1850 #if defined(X86) && !defined(_LP64) 1851 // BEWARE! On 32-bit x86 cmp clobbers its left argument so we need a temp copy. 1852 LIR_Opr index_copy = new_register(index.type()); 1853 // index >= 0 1854 __ move(index.result(), index_copy); 1855 __ cmp(lir_cond_less, index_copy, zero_reg); 1856 __ branch(lir_cond_less, new DeoptimizeStub(info, Deoptimization::Reason_range_check, 1857 Deoptimization::Action_make_not_entrant)); 1858 // index < length 1859 __ move(index.result(), index_copy); 1860 __ cmp(lir_cond_greaterEqual, index_copy, len); 1861 __ branch(lir_cond_greaterEqual, new DeoptimizeStub(info, Deoptimization::Reason_range_check, 1862 Deoptimization::Action_make_not_entrant)); 1863 #else 1864 // index >= 0 1865 __ cmp(lir_cond_less, index.result(), zero_reg); 1866 __ branch(lir_cond_less, new DeoptimizeStub(info, Deoptimization::Reason_range_check, 1867 Deoptimization::Action_make_not_entrant)); 1868 // index < length 1869 __ cmp(lir_cond_greaterEqual, index.result(), len); 1870 __ branch(lir_cond_greaterEqual, new DeoptimizeStub(info, Deoptimization::Reason_range_check, 1871 Deoptimization::Action_make_not_entrant)); 1872 #endif 1873 __ move(index.result(), result); 1874 } 1875 1876 //------------------------array access-------------------------------------- 1877 1878 1879 void LIRGenerator::do_ArrayLength(ArrayLength* x) { 1880 LIRItem array(x->array(), this); 1881 array.load_item(); 1882 LIR_Opr reg = rlock_result(x); 1883 1884 CodeEmitInfo* info = nullptr; 1885 if (x->needs_null_check()) { 1886 NullCheck* nc = x->explicit_null_check(); 1887 if (nc == nullptr) { 1888 info = state_for(x); 1889 } else { 1890 info = state_for(nc); 1891 } 1892 if (StressLoopInvariantCodeMotion && info->deoptimize_on_exception()) { 1893 LIR_Opr obj = new_register(T_OBJECT); 1894 __ move(LIR_OprFact::oopConst(nullptr), obj); 1895 __ null_check(obj, new CodeEmitInfo(info)); 1896 } 1897 } 1898 __ load(new LIR_Address(array.result(), arrayOopDesc::length_offset_in_bytes(), T_INT), reg, info, lir_patch_none); 1899 } 1900 1901 1902 void LIRGenerator::do_LoadIndexed(LoadIndexed* x) { 1903 bool use_length = x->length() != nullptr; 1904 LIRItem array(x->array(), this); 1905 LIRItem index(x->index(), this); 1906 LIRItem length(this); 1907 bool needs_range_check = x->compute_needs_range_check(); 1908 1909 if (use_length && needs_range_check) { 1910 length.set_instruction(x->length()); 1911 length.load_item(); 1912 } 1913 1914 array.load_item(); 1915 if (index.is_constant() && can_inline_as_constant(x->index())) { 1916 // let it be a constant 1917 index.dont_load_item(); 1918 } else { 1919 index.load_item(); 1920 } 1921 1922 CodeEmitInfo* range_check_info = state_for(x); 1923 CodeEmitInfo* null_check_info = nullptr; 1924 if (x->needs_null_check()) { 1925 NullCheck* nc = x->explicit_null_check(); 1926 if (nc != nullptr) { 1927 null_check_info = state_for(nc); 1928 } else { 1929 null_check_info = range_check_info; 1930 } 1931 if (StressLoopInvariantCodeMotion && null_check_info->deoptimize_on_exception()) { 1932 LIR_Opr obj = new_register(T_OBJECT); 1933 __ move(LIR_OprFact::oopConst(nullptr), obj); 1934 __ null_check(obj, new CodeEmitInfo(null_check_info)); 1935 } 1936 } 1937 1938 if (needs_range_check) { 1939 if (StressLoopInvariantCodeMotion && range_check_info->deoptimize_on_exception()) { 1940 __ branch(lir_cond_always, new RangeCheckStub(range_check_info, index.result(), array.result())); 1941 } else if (use_length) { 1942 // TODO: use a (modified) version of array_range_check that does not require a 1943 // constant length to be loaded to a register 1944 __ cmp(lir_cond_belowEqual, length.result(), index.result()); 1945 __ branch(lir_cond_belowEqual, new RangeCheckStub(range_check_info, index.result(), array.result())); 1946 } else { 1947 array_range_check(array.result(), index.result(), null_check_info, range_check_info); 1948 // The range check performs the null check, so clear it out for the load 1949 null_check_info = nullptr; 1950 } 1951 } 1952 1953 DecoratorSet decorators = IN_HEAP | IS_ARRAY; 1954 1955 LIR_Opr result = rlock_result(x, x->elt_type()); 1956 access_load_at(decorators, x->elt_type(), 1957 array, index.result(), result, 1958 nullptr, null_check_info); 1959 } 1960 1961 1962 void LIRGenerator::do_NullCheck(NullCheck* x) { 1963 if (x->can_trap()) { 1964 LIRItem value(x->obj(), this); 1965 value.load_item(); 1966 CodeEmitInfo* info = state_for(x); 1967 __ null_check(value.result(), info); 1968 } 1969 } 1970 1971 1972 void LIRGenerator::do_TypeCast(TypeCast* x) { 1973 LIRItem value(x->obj(), this); 1974 value.load_item(); 1975 // the result is the same as from the node we are casting 1976 set_result(x, value.result()); 1977 } 1978 1979 1980 void LIRGenerator::do_Throw(Throw* x) { 1981 LIRItem exception(x->exception(), this); 1982 exception.load_item(); 1983 set_no_result(x); 1984 LIR_Opr exception_opr = exception.result(); 1985 CodeEmitInfo* info = state_for(x, x->state()); 1986 1987 #ifndef PRODUCT 1988 if (PrintC1Statistics) { 1989 increment_counter(Runtime1::throw_count_address(), T_INT); 1990 } 1991 #endif 1992 1993 // check if the instruction has an xhandler in any of the nested scopes 1994 bool unwind = false; 1995 if (info->exception_handlers()->length() == 0) { 1996 // this throw is not inside an xhandler 1997 unwind = true; 1998 } else { 1999 // get some idea of the throw type 2000 bool type_is_exact = true; 2001 ciType* throw_type = x->exception()->exact_type(); 2002 if (throw_type == nullptr) { 2003 type_is_exact = false; 2004 throw_type = x->exception()->declared_type(); 2005 } 2006 if (throw_type != nullptr && throw_type->is_instance_klass()) { 2007 ciInstanceKlass* throw_klass = (ciInstanceKlass*)throw_type; 2008 unwind = !x->exception_handlers()->could_catch(throw_klass, type_is_exact); 2009 } 2010 } 2011 2012 // do null check before moving exception oop into fixed register 2013 // to avoid a fixed interval with an oop during the null check. 2014 // Use a copy of the CodeEmitInfo because debug information is 2015 // different for null_check and throw. 2016 if (x->exception()->as_NewInstance() == nullptr && x->exception()->as_ExceptionObject() == nullptr) { 2017 // if the exception object wasn't created using new then it might be null. 2018 __ null_check(exception_opr, new CodeEmitInfo(info, x->state()->copy(ValueStack::ExceptionState, x->state()->bci()))); 2019 } 2020 2021 if (compilation()->env()->jvmti_can_post_on_exceptions()) { 2022 // we need to go through the exception lookup path to get JVMTI 2023 // notification done 2024 unwind = false; 2025 } 2026 2027 // move exception oop into fixed register 2028 __ move(exception_opr, exceptionOopOpr()); 2029 2030 if (unwind) { 2031 __ unwind_exception(exceptionOopOpr()); 2032 } else { 2033 __ throw_exception(exceptionPcOpr(), exceptionOopOpr(), info); 2034 } 2035 } 2036 2037 2038 void LIRGenerator::do_UnsafeGet(UnsafeGet* x) { 2039 BasicType type = x->basic_type(); 2040 LIRItem src(x->object(), this); 2041 LIRItem off(x->offset(), this); 2042 2043 off.load_item(); 2044 src.load_item(); 2045 2046 DecoratorSet decorators = IN_HEAP | C1_UNSAFE_ACCESS; 2047 2048 if (x->is_volatile()) { 2049 decorators |= MO_SEQ_CST; 2050 } 2051 if (type == T_BOOLEAN) { 2052 decorators |= C1_MASK_BOOLEAN; 2053 } 2054 if (is_reference_type(type)) { 2055 decorators |= ON_UNKNOWN_OOP_REF; 2056 } 2057 2058 LIR_Opr result = rlock_result(x, type); 2059 if (!x->is_raw()) { 2060 access_load_at(decorators, type, src, off.result(), result); 2061 } else { 2062 // Currently it is only used in GraphBuilder::setup_osr_entry_block. 2063 // It reads the value from [src + offset] directly. 2064 #ifdef _LP64 2065 LIR_Opr offset = new_register(T_LONG); 2066 __ convert(Bytecodes::_i2l, off.result(), offset); 2067 #else 2068 LIR_Opr offset = off.result(); 2069 #endif 2070 LIR_Address* addr = new LIR_Address(src.result(), offset, type); 2071 if (is_reference_type(type)) { 2072 __ move_wide(addr, result); 2073 } else { 2074 __ move(addr, result); 2075 } 2076 } 2077 } 2078 2079 2080 void LIRGenerator::do_UnsafePut(UnsafePut* x) { 2081 BasicType type = x->basic_type(); 2082 LIRItem src(x->object(), this); 2083 LIRItem off(x->offset(), this); 2084 LIRItem data(x->value(), this); 2085 2086 src.load_item(); 2087 if (type == T_BOOLEAN || type == T_BYTE) { 2088 data.load_byte_item(); 2089 } else { 2090 data.load_item(); 2091 } 2092 off.load_item(); 2093 2094 set_no_result(x); 2095 2096 DecoratorSet decorators = IN_HEAP | C1_UNSAFE_ACCESS; 2097 if (is_reference_type(type)) { 2098 decorators |= ON_UNKNOWN_OOP_REF; 2099 } 2100 if (x->is_volatile()) { 2101 decorators |= MO_SEQ_CST; 2102 } 2103 access_store_at(decorators, type, src, off.result(), data.result()); 2104 } 2105 2106 void LIRGenerator::do_UnsafeGetAndSet(UnsafeGetAndSet* x) { 2107 BasicType type = x->basic_type(); 2108 LIRItem src(x->object(), this); 2109 LIRItem off(x->offset(), this); 2110 LIRItem value(x->value(), this); 2111 2112 DecoratorSet decorators = IN_HEAP | C1_UNSAFE_ACCESS | MO_SEQ_CST; 2113 2114 if (is_reference_type(type)) { 2115 decorators |= ON_UNKNOWN_OOP_REF; 2116 } 2117 2118 LIR_Opr result; 2119 if (x->is_add()) { 2120 result = access_atomic_add_at(decorators, type, src, off, value); 2121 } else { 2122 result = access_atomic_xchg_at(decorators, type, src, off, value); 2123 } 2124 set_result(x, result); 2125 } 2126 2127 void LIRGenerator::do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux) { 2128 int lng = x->length(); 2129 2130 for (int i = 0; i < lng; i++) { 2131 C1SwitchRange* one_range = x->at(i); 2132 int low_key = one_range->low_key(); 2133 int high_key = one_range->high_key(); 2134 BlockBegin* dest = one_range->sux(); 2135 if (low_key == high_key) { 2136 __ cmp(lir_cond_equal, value, low_key); 2137 __ branch(lir_cond_equal, dest); 2138 } else if (high_key - low_key == 1) { 2139 __ cmp(lir_cond_equal, value, low_key); 2140 __ branch(lir_cond_equal, dest); 2141 __ cmp(lir_cond_equal, value, high_key); 2142 __ branch(lir_cond_equal, dest); 2143 } else { 2144 LabelObj* L = new LabelObj(); 2145 __ cmp(lir_cond_less, value, low_key); 2146 __ branch(lir_cond_less, L->label()); 2147 __ cmp(lir_cond_lessEqual, value, high_key); 2148 __ branch(lir_cond_lessEqual, dest); 2149 __ branch_destination(L->label()); 2150 } 2151 } 2152 __ jump(default_sux); 2153 } 2154 2155 2156 SwitchRangeArray* LIRGenerator::create_lookup_ranges(TableSwitch* x) { 2157 SwitchRangeList* res = new SwitchRangeList(); 2158 int len = x->length(); 2159 if (len > 0) { 2160 BlockBegin* sux = x->sux_at(0); 2161 int low = x->lo_key(); 2162 BlockBegin* default_sux = x->default_sux(); 2163 C1SwitchRange* range = new C1SwitchRange(low, sux); 2164 for (int i = 0; i < len; i++) { 2165 int key = low + i; 2166 BlockBegin* new_sux = x->sux_at(i); 2167 if (sux == new_sux) { 2168 // still in same range 2169 range->set_high_key(key); 2170 } else { 2171 // skip tests which explicitly dispatch to the default 2172 if (sux != default_sux) { 2173 res->append(range); 2174 } 2175 range = new C1SwitchRange(key, new_sux); 2176 } 2177 sux = new_sux; 2178 } 2179 if (res->length() == 0 || res->last() != range) res->append(range); 2180 } 2181 return res; 2182 } 2183 2184 2185 // we expect the keys to be sorted by increasing value 2186 SwitchRangeArray* LIRGenerator::create_lookup_ranges(LookupSwitch* x) { 2187 SwitchRangeList* res = new SwitchRangeList(); 2188 int len = x->length(); 2189 if (len > 0) { 2190 BlockBegin* default_sux = x->default_sux(); 2191 int key = x->key_at(0); 2192 BlockBegin* sux = x->sux_at(0); 2193 C1SwitchRange* range = new C1SwitchRange(key, sux); 2194 for (int i = 1; i < len; i++) { 2195 int new_key = x->key_at(i); 2196 BlockBegin* new_sux = x->sux_at(i); 2197 if (key+1 == new_key && sux == new_sux) { 2198 // still in same range 2199 range->set_high_key(new_key); 2200 } else { 2201 // skip tests which explicitly dispatch to the default 2202 if (range->sux() != default_sux) { 2203 res->append(range); 2204 } 2205 range = new C1SwitchRange(new_key, new_sux); 2206 } 2207 key = new_key; 2208 sux = new_sux; 2209 } 2210 if (res->length() == 0 || res->last() != range) res->append(range); 2211 } 2212 return res; 2213 } 2214 2215 2216 void LIRGenerator::do_TableSwitch(TableSwitch* x) { 2217 LIRItem tag(x->tag(), this); 2218 tag.load_item(); 2219 set_no_result(x); 2220 2221 if (x->is_safepoint()) { 2222 __ safepoint(safepoint_poll_register(), state_for(x, x->state_before())); 2223 } 2224 2225 // move values into phi locations 2226 move_to_phi(x->state()); 2227 2228 int lo_key = x->lo_key(); 2229 int len = x->length(); 2230 assert(lo_key <= (lo_key + (len - 1)), "integer overflow"); 2231 LIR_Opr value = tag.result(); 2232 2233 if (compilation()->env()->comp_level() == CompLevel_full_profile && UseSwitchProfiling) { 2234 ciMethod* method = x->state()->scope()->method(); 2235 ciMethodData* md = method->method_data_or_null(); 2236 assert(md != nullptr, "Sanity"); 2237 ciProfileData* data = md->bci_to_data(x->state()->bci()); 2238 assert(data != nullptr, "must have profiling data"); 2239 assert(data->is_MultiBranchData(), "bad profile data?"); 2240 int default_count_offset = md->byte_offset_of_slot(data, MultiBranchData::default_count_offset()); 2241 LIR_Opr md_reg = new_register(T_METADATA); 2242 __ metadata2reg(md->constant_encoding(), md_reg); 2243 LIR_Opr data_offset_reg = new_pointer_register(); 2244 LIR_Opr tmp_reg = new_pointer_register(); 2245 2246 __ move(LIR_OprFact::intptrConst(default_count_offset), data_offset_reg); 2247 for (int i = 0; i < len; i++) { 2248 int count_offset = md->byte_offset_of_slot(data, MultiBranchData::case_count_offset(i)); 2249 __ cmp(lir_cond_equal, value, i + lo_key); 2250 __ move(data_offset_reg, tmp_reg); 2251 __ cmove(lir_cond_equal, 2252 LIR_OprFact::intptrConst(count_offset), 2253 tmp_reg, 2254 data_offset_reg, T_INT); 2255 } 2256 2257 LIR_Opr data_reg = new_pointer_register(); 2258 LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, data_reg->type()); 2259 __ move(data_addr, data_reg); 2260 __ add(data_reg, LIR_OprFact::intptrConst(1), data_reg); 2261 __ move(data_reg, data_addr); 2262 } 2263 2264 if (UseTableRanges) { 2265 do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux()); 2266 } else { 2267 for (int i = 0; i < len; i++) { 2268 __ cmp(lir_cond_equal, value, i + lo_key); 2269 __ branch(lir_cond_equal, x->sux_at(i)); 2270 } 2271 __ jump(x->default_sux()); 2272 } 2273 } 2274 2275 2276 void LIRGenerator::do_LookupSwitch(LookupSwitch* x) { 2277 LIRItem tag(x->tag(), this); 2278 tag.load_item(); 2279 set_no_result(x); 2280 2281 if (x->is_safepoint()) { 2282 __ safepoint(safepoint_poll_register(), state_for(x, x->state_before())); 2283 } 2284 2285 // move values into phi locations 2286 move_to_phi(x->state()); 2287 2288 LIR_Opr value = tag.result(); 2289 int len = x->length(); 2290 2291 if (compilation()->env()->comp_level() == CompLevel_full_profile && UseSwitchProfiling) { 2292 ciMethod* method = x->state()->scope()->method(); 2293 ciMethodData* md = method->method_data_or_null(); 2294 assert(md != nullptr, "Sanity"); 2295 ciProfileData* data = md->bci_to_data(x->state()->bci()); 2296 assert(data != nullptr, "must have profiling data"); 2297 assert(data->is_MultiBranchData(), "bad profile data?"); 2298 int default_count_offset = md->byte_offset_of_slot(data, MultiBranchData::default_count_offset()); 2299 LIR_Opr md_reg = new_register(T_METADATA); 2300 __ metadata2reg(md->constant_encoding(), md_reg); 2301 LIR_Opr data_offset_reg = new_pointer_register(); 2302 LIR_Opr tmp_reg = new_pointer_register(); 2303 2304 __ move(LIR_OprFact::intptrConst(default_count_offset), data_offset_reg); 2305 for (int i = 0; i < len; i++) { 2306 int count_offset = md->byte_offset_of_slot(data, MultiBranchData::case_count_offset(i)); 2307 __ cmp(lir_cond_equal, value, x->key_at(i)); 2308 __ move(data_offset_reg, tmp_reg); 2309 __ cmove(lir_cond_equal, 2310 LIR_OprFact::intptrConst(count_offset), 2311 tmp_reg, 2312 data_offset_reg, T_INT); 2313 } 2314 2315 LIR_Opr data_reg = new_pointer_register(); 2316 LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, data_reg->type()); 2317 __ move(data_addr, data_reg); 2318 __ add(data_reg, LIR_OprFact::intptrConst(1), data_reg); 2319 __ move(data_reg, data_addr); 2320 } 2321 2322 if (UseTableRanges) { 2323 do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux()); 2324 } else { 2325 int len = x->length(); 2326 for (int i = 0; i < len; i++) { 2327 __ cmp(lir_cond_equal, value, x->key_at(i)); 2328 __ branch(lir_cond_equal, x->sux_at(i)); 2329 } 2330 __ jump(x->default_sux()); 2331 } 2332 } 2333 2334 2335 void LIRGenerator::do_Goto(Goto* x) { 2336 set_no_result(x); 2337 2338 if (block()->next()->as_OsrEntry()) { 2339 // need to free up storage used for OSR entry point 2340 LIR_Opr osrBuffer = block()->next()->operand(); 2341 BasicTypeList signature; 2342 signature.append(NOT_LP64(T_INT) LP64_ONLY(T_LONG)); // pass a pointer to osrBuffer 2343 CallingConvention* cc = frame_map()->c_calling_convention(&signature); 2344 __ move(osrBuffer, cc->args()->at(0)); 2345 __ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end), 2346 getThreadTemp(), LIR_OprFact::illegalOpr, cc->args()); 2347 } 2348 2349 if (x->is_safepoint()) { 2350 ValueStack* state = x->state_before() ? x->state_before() : x->state(); 2351 2352 // increment backedge counter if needed 2353 CodeEmitInfo* info = state_for(x, state); 2354 increment_backedge_counter(info, x->profiled_bci()); 2355 CodeEmitInfo* safepoint_info = state_for(x, state); 2356 __ safepoint(safepoint_poll_register(), safepoint_info); 2357 } 2358 2359 // Gotos can be folded Ifs, handle this case. 2360 if (x->should_profile()) { 2361 ciMethod* method = x->profiled_method(); 2362 assert(method != nullptr, "method should be set if branch is profiled"); 2363 ciMethodData* md = method->method_data_or_null(); 2364 assert(md != nullptr, "Sanity"); 2365 ciProfileData* data = md->bci_to_data(x->profiled_bci()); 2366 assert(data != nullptr, "must have profiling data"); 2367 int offset; 2368 if (x->direction() == Goto::taken) { 2369 assert(data->is_BranchData(), "need BranchData for two-way branches"); 2370 offset = md->byte_offset_of_slot(data, BranchData::taken_offset()); 2371 } else if (x->direction() == Goto::not_taken) { 2372 assert(data->is_BranchData(), "need BranchData for two-way branches"); 2373 offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset()); 2374 } else { 2375 assert(data->is_JumpData(), "need JumpData for branches"); 2376 offset = md->byte_offset_of_slot(data, JumpData::taken_offset()); 2377 } 2378 LIR_Opr md_reg = new_register(T_METADATA); 2379 __ metadata2reg(md->constant_encoding(), md_reg); 2380 2381 increment_counter(new LIR_Address(md_reg, offset, 2382 NOT_LP64(T_INT) LP64_ONLY(T_LONG)), DataLayout::counter_increment); 2383 } 2384 2385 // emit phi-instruction move after safepoint since this simplifies 2386 // describing the state as the safepoint. 2387 move_to_phi(x->state()); 2388 2389 __ jump(x->default_sux()); 2390 } 2391 2392 /** 2393 * Emit profiling code if needed for arguments, parameters, return value types 2394 * 2395 * @param md MDO the code will update at runtime 2396 * @param md_base_offset common offset in the MDO for this profile and subsequent ones 2397 * @param md_offset offset in the MDO (on top of md_base_offset) for this profile 2398 * @param profiled_k current profile 2399 * @param obj IR node for the object to be profiled 2400 * @param mdp register to hold the pointer inside the MDO (md + md_base_offset). 2401 * Set once we find an update to make and use for next ones. 2402 * @param not_null true if we know obj cannot be null 2403 * @param signature_at_call_k signature at call for obj 2404 * @param callee_signature_k signature of callee for obj 2405 * at call and callee signatures differ at method handle call 2406 * @return the only klass we know will ever be seen at this profile point 2407 */ 2408 ciKlass* LIRGenerator::profile_type(ciMethodData* md, int md_base_offset, int md_offset, intptr_t profiled_k, 2409 Value obj, LIR_Opr& mdp, bool not_null, ciKlass* signature_at_call_k, 2410 ciKlass* callee_signature_k) { 2411 ciKlass* result = nullptr; 2412 bool do_null = !not_null && !TypeEntries::was_null_seen(profiled_k); 2413 bool do_update = !TypeEntries::is_type_unknown(profiled_k); 2414 // known not to be null or null bit already set and already set to 2415 // unknown: nothing we can do to improve profiling 2416 if (!do_null && !do_update) { 2417 return result; 2418 } 2419 2420 ciKlass* exact_klass = nullptr; 2421 Compilation* comp = Compilation::current(); 2422 if (do_update) { 2423 // try to find exact type, using CHA if possible, so that loading 2424 // the klass from the object can be avoided 2425 ciType* type = obj->exact_type(); 2426 if (type == nullptr) { 2427 type = obj->declared_type(); 2428 type = comp->cha_exact_type(type); 2429 } 2430 assert(type == nullptr || type->is_klass(), "type should be class"); 2431 exact_klass = (type != nullptr && type->is_loaded()) ? (ciKlass*)type : nullptr; 2432 2433 do_update = exact_klass == nullptr || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass; 2434 } 2435 2436 if (!do_null && !do_update) { 2437 return result; 2438 } 2439 2440 ciKlass* exact_signature_k = nullptr; 2441 if (do_update) { 2442 // Is the type from the signature exact (the only one possible)? 2443 exact_signature_k = signature_at_call_k->exact_klass(); 2444 if (exact_signature_k == nullptr) { 2445 exact_signature_k = comp->cha_exact_type(signature_at_call_k); 2446 } else { 2447 result = exact_signature_k; 2448 // Known statically. No need to emit any code: prevent 2449 // LIR_Assembler::emit_profile_type() from emitting useless code 2450 profiled_k = ciTypeEntries::with_status(result, profiled_k); 2451 } 2452 // exact_klass and exact_signature_k can be both non null but 2453 // different if exact_klass is loaded after the ciObject for 2454 // exact_signature_k is created. 2455 if (exact_klass == nullptr && exact_signature_k != nullptr && exact_klass != exact_signature_k) { 2456 // sometimes the type of the signature is better than the best type 2457 // the compiler has 2458 exact_klass = exact_signature_k; 2459 } 2460 if (callee_signature_k != nullptr && 2461 callee_signature_k != signature_at_call_k) { 2462 ciKlass* improved_klass = callee_signature_k->exact_klass(); 2463 if (improved_klass == nullptr) { 2464 improved_klass = comp->cha_exact_type(callee_signature_k); 2465 } 2466 if (exact_klass == nullptr && improved_klass != nullptr && exact_klass != improved_klass) { 2467 exact_klass = exact_signature_k; 2468 } 2469 } 2470 do_update = exact_klass == nullptr || ciTypeEntries::valid_ciklass(profiled_k) != exact_klass; 2471 } 2472 2473 if (!do_null && !do_update) { 2474 return result; 2475 } 2476 2477 if (mdp == LIR_OprFact::illegalOpr) { 2478 mdp = new_register(T_METADATA); 2479 __ metadata2reg(md->constant_encoding(), mdp); 2480 if (md_base_offset != 0) { 2481 LIR_Address* base_type_address = new LIR_Address(mdp, md_base_offset, T_ADDRESS); 2482 mdp = new_pointer_register(); 2483 __ leal(LIR_OprFact::address(base_type_address), mdp); 2484 } 2485 } 2486 LIRItem value(obj, this); 2487 value.load_item(); 2488 __ profile_type(new LIR_Address(mdp, md_offset, T_METADATA), 2489 value.result(), exact_klass, profiled_k, new_pointer_register(), not_null, exact_signature_k != nullptr); 2490 return result; 2491 } 2492 2493 // profile parameters on entry to the root of the compilation 2494 void LIRGenerator::profile_parameters(Base* x) { 2495 if (compilation()->profile_parameters()) { 2496 CallingConvention* args = compilation()->frame_map()->incoming_arguments(); 2497 ciMethodData* md = scope()->method()->method_data_or_null(); 2498 assert(md != nullptr, "Sanity"); 2499 2500 if (md->parameters_type_data() != nullptr) { 2501 ciParametersTypeData* parameters_type_data = md->parameters_type_data(); 2502 ciTypeStackSlotEntries* parameters = parameters_type_data->parameters(); 2503 LIR_Opr mdp = LIR_OprFact::illegalOpr; 2504 for (int java_index = 0, i = 0, j = 0; j < parameters_type_data->number_of_parameters(); i++) { 2505 LIR_Opr src = args->at(i); 2506 assert(!src->is_illegal(), "check"); 2507 BasicType t = src->type(); 2508 if (is_reference_type(t)) { 2509 intptr_t profiled_k = parameters->type(j); 2510 Local* local = x->state()->local_at(java_index)->as_Local(); 2511 ciKlass* exact = profile_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)), 2512 in_bytes(ParametersTypeData::type_offset(j)) - in_bytes(ParametersTypeData::type_offset(0)), 2513 profiled_k, local, mdp, false, local->declared_type()->as_klass(), nullptr); 2514 // If the profile is known statically set it once for all and do not emit any code 2515 if (exact != nullptr) { 2516 md->set_parameter_type(j, exact); 2517 } 2518 j++; 2519 } 2520 java_index += type2size[t]; 2521 } 2522 } 2523 } 2524 } 2525 2526 void LIRGenerator::do_Base(Base* x) { 2527 __ std_entry(LIR_OprFact::illegalOpr); 2528 // Emit moves from physical registers / stack slots to virtual registers 2529 CallingConvention* args = compilation()->frame_map()->incoming_arguments(); 2530 IRScope* irScope = compilation()->hir()->top_scope(); 2531 int java_index = 0; 2532 for (int i = 0; i < args->length(); i++) { 2533 LIR_Opr src = args->at(i); 2534 assert(!src->is_illegal(), "check"); 2535 BasicType t = src->type(); 2536 2537 // Types which are smaller than int are passed as int, so 2538 // correct the type which passed. 2539 switch (t) { 2540 case T_BYTE: 2541 case T_BOOLEAN: 2542 case T_SHORT: 2543 case T_CHAR: 2544 t = T_INT; 2545 break; 2546 default: 2547 break; 2548 } 2549 2550 LIR_Opr dest = new_register(t); 2551 __ move(src, dest); 2552 2553 // Assign new location to Local instruction for this local 2554 Local* local = x->state()->local_at(java_index)->as_Local(); 2555 assert(local != nullptr, "Locals for incoming arguments must have been created"); 2556 #ifndef __SOFTFP__ 2557 // The java calling convention passes double as long and float as int. 2558 assert(as_ValueType(t)->tag() == local->type()->tag(), "check"); 2559 #endif // __SOFTFP__ 2560 local->set_operand(dest); 2561 #ifdef ASSERT 2562 _instruction_for_operand.at_put_grow(dest->vreg_number(), local, nullptr); 2563 #endif 2564 java_index += type2size[t]; 2565 } 2566 2567 if (compilation()->env()->dtrace_method_probes()) { 2568 BasicTypeList signature; 2569 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread 2570 signature.append(T_METADATA); // Method* 2571 LIR_OprList* args = new LIR_OprList(); 2572 args->append(getThreadPointer()); 2573 LIR_Opr meth = new_register(T_METADATA); 2574 __ metadata2reg(method()->constant_encoding(), meth); 2575 args->append(meth); 2576 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, nullptr); 2577 } 2578 2579 MethodDetails method_details(method()); 2580 RuntimeUpcallInfo* upcall = RuntimeUpcalls::get_first_upcall(RuntimeUpcallType::onMethodEntry, method_details); 2581 while (upcall != nullptr) { 2582 BasicTypeList signature; 2583 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread 2584 LIR_OprList* args = new LIR_OprList(); 2585 args->append(getThreadPointer()); 2586 call_runtime(&signature, args, upcall->upcall_address(), voidType, nullptr); 2587 upcall = RuntimeUpcalls::get_next_upcall(RuntimeUpcallType::onMethodEntry, method_details, upcall); 2588 } 2589 2590 if (method()->is_synchronized()) { 2591 LIR_Opr obj; 2592 if (method()->is_static()) { 2593 obj = new_register(T_OBJECT); 2594 __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj); 2595 } else { 2596 Local* receiver = x->state()->local_at(0)->as_Local(); 2597 assert(receiver != nullptr, "must already exist"); 2598 obj = receiver->operand(); 2599 } 2600 assert(obj->is_valid(), "must be valid"); 2601 2602 if (method()->is_synchronized() && GenerateSynchronizationCode) { 2603 LIR_Opr lock = syncLockOpr(); 2604 __ load_stack_address_monitor(0, lock); 2605 2606 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), nullptr, x->check_flag(Instruction::DeoptimizeOnException)); 2607 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info); 2608 2609 // receiver is guaranteed non-null so don't need CodeEmitInfo 2610 __ lock_object(syncTempOpr(), obj, lock, new_register(T_OBJECT), slow_path, nullptr); 2611 } 2612 } 2613 // increment invocation counters if needed 2614 if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting. 2615 profile_parameters(x); 2616 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), nullptr, false); 2617 increment_invocation_counter(info); 2618 } 2619 2620 // all blocks with a successor must end with an unconditional jump 2621 // to the successor even if they are consecutive 2622 __ jump(x->default_sux()); 2623 } 2624 2625 2626 void LIRGenerator::do_OsrEntry(OsrEntry* x) { 2627 // construct our frame and model the production of incoming pointer 2628 // to the OSR buffer. 2629 __ osr_entry(LIR_Assembler::osrBufferPointer()); 2630 LIR_Opr result = rlock_result(x); 2631 __ move(LIR_Assembler::osrBufferPointer(), result); 2632 } 2633 2634 2635 void LIRGenerator::invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list) { 2636 assert(args->length() == arg_list->length(), 2637 "args=%d, arg_list=%d", args->length(), arg_list->length()); 2638 for (int i = x->has_receiver() ? 1 : 0; i < args->length(); i++) { 2639 LIRItem* param = args->at(i); 2640 LIR_Opr loc = arg_list->at(i); 2641 if (loc->is_register()) { 2642 param->load_item_force(loc); 2643 } else { 2644 LIR_Address* addr = loc->as_address_ptr(); 2645 param->load_for_store(addr->type()); 2646 if (addr->type() == T_OBJECT) { 2647 __ move_wide(param->result(), addr); 2648 } else 2649 __ move(param->result(), addr); 2650 } 2651 } 2652 2653 if (x->has_receiver()) { 2654 LIRItem* receiver = args->at(0); 2655 LIR_Opr loc = arg_list->at(0); 2656 if (loc->is_register()) { 2657 receiver->load_item_force(loc); 2658 } else { 2659 assert(loc->is_address(), "just checking"); 2660 receiver->load_for_store(T_OBJECT); 2661 __ move_wide(receiver->result(), loc->as_address_ptr()); 2662 } 2663 } 2664 } 2665 2666 2667 // Visits all arguments, returns appropriate items without loading them 2668 LIRItemList* LIRGenerator::invoke_visit_arguments(Invoke* x) { 2669 LIRItemList* argument_items = new LIRItemList(); 2670 if (x->has_receiver()) { 2671 LIRItem* receiver = new LIRItem(x->receiver(), this); 2672 argument_items->append(receiver); 2673 } 2674 for (int i = 0; i < x->number_of_arguments(); i++) { 2675 LIRItem* param = new LIRItem(x->argument_at(i), this); 2676 argument_items->append(param); 2677 } 2678 return argument_items; 2679 } 2680 2681 2682 // The invoke with receiver has following phases: 2683 // a) traverse and load/lock receiver; 2684 // b) traverse all arguments -> item-array (invoke_visit_argument) 2685 // c) push receiver on stack 2686 // d) load each of the items and push on stack 2687 // e) unlock receiver 2688 // f) move receiver into receiver-register %o0 2689 // g) lock result registers and emit call operation 2690 // 2691 // Before issuing a call, we must spill-save all values on stack 2692 // that are in caller-save register. "spill-save" moves those registers 2693 // either in a free callee-save register or spills them if no free 2694 // callee save register is available. 2695 // 2696 // The problem is where to invoke spill-save. 2697 // - if invoked between e) and f), we may lock callee save 2698 // register in "spill-save" that destroys the receiver register 2699 // before f) is executed 2700 // - if we rearrange f) to be earlier (by loading %o0) it 2701 // may destroy a value on the stack that is currently in %o0 2702 // and is waiting to be spilled 2703 // - if we keep the receiver locked while doing spill-save, 2704 // we cannot spill it as it is spill-locked 2705 // 2706 void LIRGenerator::do_Invoke(Invoke* x) { 2707 CallingConvention* cc = frame_map()->java_calling_convention(x->signature(), true); 2708 2709 LIR_OprList* arg_list = cc->args(); 2710 LIRItemList* args = invoke_visit_arguments(x); 2711 LIR_Opr receiver = LIR_OprFact::illegalOpr; 2712 2713 // setup result register 2714 LIR_Opr result_register = LIR_OprFact::illegalOpr; 2715 if (x->type() != voidType) { 2716 result_register = result_register_for(x->type()); 2717 } 2718 2719 CodeEmitInfo* info = state_for(x, x->state()); 2720 2721 invoke_load_arguments(x, args, arg_list); 2722 2723 if (x->has_receiver()) { 2724 args->at(0)->load_item_force(LIR_Assembler::receiverOpr()); 2725 receiver = args->at(0)->result(); 2726 } 2727 2728 // emit invoke code 2729 assert(receiver->is_illegal() || receiver->is_equal(LIR_Assembler::receiverOpr()), "must match"); 2730 2731 // JSR 292 2732 // Preserve the SP over MethodHandle call sites, if needed. 2733 ciMethod* target = x->target(); 2734 bool is_method_handle_invoke = (// %%% FIXME: Are both of these relevant? 2735 target->is_method_handle_intrinsic() || 2736 target->is_compiled_lambda_form()); 2737 if (is_method_handle_invoke) { 2738 info->set_is_method_handle_invoke(true); 2739 if(FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr) { 2740 __ move(FrameMap::stack_pointer(), FrameMap::method_handle_invoke_SP_save_opr()); 2741 } 2742 } 2743 2744 switch (x->code()) { 2745 case Bytecodes::_invokestatic: 2746 __ call_static(target, result_register, 2747 SharedRuntime::get_resolve_static_call_stub(), 2748 arg_list, info); 2749 break; 2750 case Bytecodes::_invokespecial: 2751 case Bytecodes::_invokevirtual: 2752 case Bytecodes::_invokeinterface: 2753 // for loaded and final (method or class) target we still produce an inline cache, 2754 // in order to be able to call mixed mode 2755 if (x->code() == Bytecodes::_invokespecial || x->target_is_final()) { 2756 __ call_opt_virtual(target, receiver, result_register, 2757 SharedRuntime::get_resolve_opt_virtual_call_stub(), 2758 arg_list, info); 2759 } else { 2760 __ call_icvirtual(target, receiver, result_register, 2761 SharedRuntime::get_resolve_virtual_call_stub(), 2762 arg_list, info); 2763 } 2764 break; 2765 case Bytecodes::_invokedynamic: { 2766 __ call_dynamic(target, receiver, result_register, 2767 SharedRuntime::get_resolve_static_call_stub(), 2768 arg_list, info); 2769 break; 2770 } 2771 default: 2772 fatal("unexpected bytecode: %s", Bytecodes::name(x->code())); 2773 break; 2774 } 2775 2776 // JSR 292 2777 // Restore the SP after MethodHandle call sites, if needed. 2778 if (is_method_handle_invoke 2779 && FrameMap::method_handle_invoke_SP_save_opr() != LIR_OprFact::illegalOpr) { 2780 __ move(FrameMap::method_handle_invoke_SP_save_opr(), FrameMap::stack_pointer()); 2781 } 2782 2783 if (result_register->is_valid()) { 2784 LIR_Opr result = rlock_result(x); 2785 __ move(result_register, result); 2786 } 2787 } 2788 2789 2790 void LIRGenerator::do_FPIntrinsics(Intrinsic* x) { 2791 assert(x->number_of_arguments() == 1, "wrong type"); 2792 LIRItem value (x->argument_at(0), this); 2793 LIR_Opr reg = rlock_result(x); 2794 value.load_item(); 2795 LIR_Opr tmp = force_to_spill(value.result(), as_BasicType(x->type())); 2796 __ move(tmp, reg); 2797 } 2798 2799 2800 2801 // Code for : x->x() {x->cond()} x->y() ? x->tval() : x->fval() 2802 void LIRGenerator::do_IfOp(IfOp* x) { 2803 #ifdef ASSERT 2804 { 2805 ValueTag xtag = x->x()->type()->tag(); 2806 ValueTag ttag = x->tval()->type()->tag(); 2807 assert(xtag == intTag || xtag == objectTag, "cannot handle others"); 2808 assert(ttag == addressTag || ttag == intTag || ttag == objectTag || ttag == longTag, "cannot handle others"); 2809 assert(ttag == x->fval()->type()->tag(), "cannot handle others"); 2810 } 2811 #endif 2812 2813 LIRItem left(x->x(), this); 2814 LIRItem right(x->y(), this); 2815 left.load_item(); 2816 if (can_inline_as_constant(right.value())) { 2817 right.dont_load_item(); 2818 } else { 2819 right.load_item(); 2820 } 2821 2822 LIRItem t_val(x->tval(), this); 2823 LIRItem f_val(x->fval(), this); 2824 t_val.dont_load_item(); 2825 f_val.dont_load_item(); 2826 LIR_Opr reg = rlock_result(x); 2827 2828 __ cmp(lir_cond(x->cond()), left.result(), right.result()); 2829 __ cmove(lir_cond(x->cond()), t_val.result(), f_val.result(), reg, as_BasicType(x->x()->type())); 2830 } 2831 2832 void LIRGenerator::do_RuntimeCall(address routine, Intrinsic* x) { 2833 assert(x->number_of_arguments() == 0, "wrong type"); 2834 // Enforce computation of _reserved_argument_area_size which is required on some platforms. 2835 BasicTypeList signature; 2836 CallingConvention* cc = frame_map()->c_calling_convention(&signature); 2837 LIR_Opr reg = result_register_for(x->type()); 2838 __ call_runtime_leaf(routine, getThreadTemp(), 2839 reg, new LIR_OprList()); 2840 LIR_Opr result = rlock_result(x); 2841 __ move(reg, result); 2842 } 2843 2844 2845 2846 void LIRGenerator::do_Intrinsic(Intrinsic* x) { 2847 switch (x->id()) { 2848 case vmIntrinsics::_intBitsToFloat : 2849 case vmIntrinsics::_doubleToRawLongBits : 2850 case vmIntrinsics::_longBitsToDouble : 2851 case vmIntrinsics::_floatToRawIntBits : { 2852 do_FPIntrinsics(x); 2853 break; 2854 } 2855 2856 #ifdef JFR_HAVE_INTRINSICS 2857 case vmIntrinsics::_counterTime: 2858 do_RuntimeCall(CAST_FROM_FN_PTR(address, JfrTime::time_function()), x); 2859 break; 2860 #endif 2861 2862 case vmIntrinsics::_currentTimeMillis: 2863 do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeMillis), x); 2864 break; 2865 2866 case vmIntrinsics::_nanoTime: 2867 do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeNanos), x); 2868 break; 2869 2870 case vmIntrinsics::_Object_init: do_RegisterFinalizer(x); break; 2871 case vmIntrinsics::_isInstance: do_isInstance(x); break; 2872 case vmIntrinsics::_getClass: do_getClass(x); break; 2873 case vmIntrinsics::_getObjectSize: do_getObjectSize(x); break; 2874 case vmIntrinsics::_currentCarrierThread: do_currentCarrierThread(x); break; 2875 case vmIntrinsics::_currentThread: do_vthread(x); break; 2876 case vmIntrinsics::_scopedValueCache: do_scopedValueCache(x); break; 2877 2878 case vmIntrinsics::_dlog: // fall through 2879 case vmIntrinsics::_dlog10: // fall through 2880 case vmIntrinsics::_dabs: // fall through 2881 case vmIntrinsics::_dsqrt: // fall through 2882 case vmIntrinsics::_dsqrt_strict: // fall through 2883 case vmIntrinsics::_dtan: // fall through 2884 case vmIntrinsics::_dtanh: // fall through 2885 case vmIntrinsics::_dsin : // fall through 2886 case vmIntrinsics::_dcos : // fall through 2887 case vmIntrinsics::_dcbrt : // fall through 2888 case vmIntrinsics::_dexp : // fall through 2889 case vmIntrinsics::_dpow : do_MathIntrinsic(x); break; 2890 case vmIntrinsics::_arraycopy: do_ArrayCopy(x); break; 2891 2892 case vmIntrinsics::_fmaD: do_FmaIntrinsic(x); break; 2893 case vmIntrinsics::_fmaF: do_FmaIntrinsic(x); break; 2894 2895 // Use java.lang.Math intrinsics code since it works for these intrinsics too. 2896 case vmIntrinsics::_floatToFloat16: // fall through 2897 case vmIntrinsics::_float16ToFloat: do_MathIntrinsic(x); break; 2898 2899 case vmIntrinsics::_Preconditions_checkIndex: 2900 do_PreconditionsCheckIndex(x, T_INT); 2901 break; 2902 case vmIntrinsics::_Preconditions_checkLongIndex: 2903 do_PreconditionsCheckIndex(x, T_LONG); 2904 break; 2905 2906 case vmIntrinsics::_compareAndSetReference: 2907 do_CompareAndSwap(x, objectType); 2908 break; 2909 case vmIntrinsics::_compareAndSetInt: 2910 do_CompareAndSwap(x, intType); 2911 break; 2912 case vmIntrinsics::_compareAndSetLong: 2913 do_CompareAndSwap(x, longType); 2914 break; 2915 2916 case vmIntrinsics::_loadFence : 2917 __ membar_acquire(); 2918 break; 2919 case vmIntrinsics::_storeFence: 2920 __ membar_release(); 2921 break; 2922 case vmIntrinsics::_storeStoreFence: 2923 __ membar_storestore(); 2924 break; 2925 case vmIntrinsics::_fullFence : 2926 __ membar(); 2927 break; 2928 case vmIntrinsics::_onSpinWait: 2929 __ on_spin_wait(); 2930 break; 2931 case vmIntrinsics::_Reference_get: 2932 do_Reference_get(x); 2933 break; 2934 2935 case vmIntrinsics::_updateCRC32: 2936 case vmIntrinsics::_updateBytesCRC32: 2937 case vmIntrinsics::_updateByteBufferCRC32: 2938 do_update_CRC32(x); 2939 break; 2940 2941 case vmIntrinsics::_updateBytesCRC32C: 2942 case vmIntrinsics::_updateDirectByteBufferCRC32C: 2943 do_update_CRC32C(x); 2944 break; 2945 2946 case vmIntrinsics::_vectorizedMismatch: 2947 do_vectorizedMismatch(x); 2948 break; 2949 2950 case vmIntrinsics::_blackhole: 2951 do_blackhole(x); 2952 break; 2953 2954 default: ShouldNotReachHere(); break; 2955 } 2956 } 2957 2958 void LIRGenerator::profile_arguments(ProfileCall* x) { 2959 if (compilation()->profile_arguments()) { 2960 int bci = x->bci_of_invoke(); 2961 ciMethodData* md = x->method()->method_data_or_null(); 2962 assert(md != nullptr, "Sanity"); 2963 ciProfileData* data = md->bci_to_data(bci); 2964 if (data != nullptr) { 2965 if ((data->is_CallTypeData() && data->as_CallTypeData()->has_arguments()) || 2966 (data->is_VirtualCallTypeData() && data->as_VirtualCallTypeData()->has_arguments())) { 2967 ByteSize extra = data->is_CallTypeData() ? CallTypeData::args_data_offset() : VirtualCallTypeData::args_data_offset(); 2968 int base_offset = md->byte_offset_of_slot(data, extra); 2969 LIR_Opr mdp = LIR_OprFact::illegalOpr; 2970 ciTypeStackSlotEntries* args = data->is_CallTypeData() ? ((ciCallTypeData*)data)->args() : ((ciVirtualCallTypeData*)data)->args(); 2971 2972 Bytecodes::Code bc = x->method()->java_code_at_bci(bci); 2973 int start = 0; 2974 int stop = data->is_CallTypeData() ? ((ciCallTypeData*)data)->number_of_arguments() : ((ciVirtualCallTypeData*)data)->number_of_arguments(); 2975 if (x->callee()->is_loaded() && x->callee()->is_static() && Bytecodes::has_receiver(bc)) { 2976 // first argument is not profiled at call (method handle invoke) 2977 assert(x->method()->raw_code_at_bci(bci) == Bytecodes::_invokehandle, "invokehandle expected"); 2978 start = 1; 2979 } 2980 ciSignature* callee_signature = x->callee()->signature(); 2981 // method handle call to virtual method 2982 bool has_receiver = x->callee()->is_loaded() && !x->callee()->is_static() && !Bytecodes::has_receiver(bc); 2983 ciSignatureStream callee_signature_stream(callee_signature, has_receiver ? x->callee()->holder() : nullptr); 2984 2985 bool ignored_will_link; 2986 ciSignature* signature_at_call = nullptr; 2987 x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call); 2988 ciSignatureStream signature_at_call_stream(signature_at_call); 2989 2990 // if called through method handle invoke, some arguments may have been popped 2991 for (int i = 0; i < stop && i+start < x->nb_profiled_args(); i++) { 2992 int off = in_bytes(TypeEntriesAtCall::argument_type_offset(i)) - in_bytes(TypeEntriesAtCall::args_data_offset()); 2993 ciKlass* exact = profile_type(md, base_offset, off, 2994 args->type(i), x->profiled_arg_at(i+start), mdp, 2995 !x->arg_needs_null_check(i+start), 2996 signature_at_call_stream.next_klass(), callee_signature_stream.next_klass()); 2997 if (exact != nullptr) { 2998 md->set_argument_type(bci, i, exact); 2999 } 3000 } 3001 } else { 3002 #ifdef ASSERT 3003 Bytecodes::Code code = x->method()->raw_code_at_bci(x->bci_of_invoke()); 3004 int n = x->nb_profiled_args(); 3005 assert(MethodData::profile_parameters() && (MethodData::profile_arguments_jsr292_only() || 3006 (x->inlined() && ((code == Bytecodes::_invokedynamic && n <= 1) || (code == Bytecodes::_invokehandle && n <= 2)))), 3007 "only at JSR292 bytecodes"); 3008 #endif 3009 } 3010 } 3011 } 3012 } 3013 3014 // profile parameters on entry to an inlined method 3015 void LIRGenerator::profile_parameters_at_call(ProfileCall* x) { 3016 if (compilation()->profile_parameters() && x->inlined()) { 3017 ciMethodData* md = x->callee()->method_data_or_null(); 3018 if (md != nullptr) { 3019 ciParametersTypeData* parameters_type_data = md->parameters_type_data(); 3020 if (parameters_type_data != nullptr) { 3021 ciTypeStackSlotEntries* parameters = parameters_type_data->parameters(); 3022 LIR_Opr mdp = LIR_OprFact::illegalOpr; 3023 bool has_receiver = !x->callee()->is_static(); 3024 ciSignature* sig = x->callee()->signature(); 3025 ciSignatureStream sig_stream(sig, has_receiver ? x->callee()->holder() : nullptr); 3026 int i = 0; // to iterate on the Instructions 3027 Value arg = x->recv(); 3028 bool not_null = false; 3029 int bci = x->bci_of_invoke(); 3030 Bytecodes::Code bc = x->method()->java_code_at_bci(bci); 3031 // The first parameter is the receiver so that's what we start 3032 // with if it exists. One exception is method handle call to 3033 // virtual method: the receiver is in the args list 3034 if (arg == nullptr || !Bytecodes::has_receiver(bc)) { 3035 i = 1; 3036 arg = x->profiled_arg_at(0); 3037 not_null = !x->arg_needs_null_check(0); 3038 } 3039 int k = 0; // to iterate on the profile data 3040 for (;;) { 3041 intptr_t profiled_k = parameters->type(k); 3042 ciKlass* exact = profile_type(md, md->byte_offset_of_slot(parameters_type_data, ParametersTypeData::type_offset(0)), 3043 in_bytes(ParametersTypeData::type_offset(k)) - in_bytes(ParametersTypeData::type_offset(0)), 3044 profiled_k, arg, mdp, not_null, sig_stream.next_klass(), nullptr); 3045 // If the profile is known statically set it once for all and do not emit any code 3046 if (exact != nullptr) { 3047 md->set_parameter_type(k, exact); 3048 } 3049 k++; 3050 if (k >= parameters_type_data->number_of_parameters()) { 3051 #ifdef ASSERT 3052 int extra = 0; 3053 if (MethodData::profile_arguments() && TypeProfileParmsLimit != -1 && 3054 x->nb_profiled_args() >= TypeProfileParmsLimit && 3055 x->recv() != nullptr && Bytecodes::has_receiver(bc)) { 3056 extra += 1; 3057 } 3058 assert(i == x->nb_profiled_args() - extra || (TypeProfileParmsLimit != -1 && TypeProfileArgsLimit > TypeProfileParmsLimit), "unused parameters?"); 3059 #endif 3060 break; 3061 } 3062 arg = x->profiled_arg_at(i); 3063 not_null = !x->arg_needs_null_check(i); 3064 i++; 3065 } 3066 } 3067 } 3068 } 3069 } 3070 3071 void LIRGenerator::do_ProfileCall(ProfileCall* x) { 3072 // Need recv in a temporary register so it interferes with the other temporaries 3073 LIR_Opr recv = LIR_OprFact::illegalOpr; 3074 LIR_Opr mdo = new_register(T_METADATA); 3075 // tmp is used to hold the counters on SPARC 3076 LIR_Opr tmp = new_pointer_register(); 3077 3078 if (x->nb_profiled_args() > 0) { 3079 profile_arguments(x); 3080 } 3081 3082 // profile parameters on inlined method entry including receiver 3083 if (x->recv() != nullptr || x->nb_profiled_args() > 0) { 3084 profile_parameters_at_call(x); 3085 } 3086 3087 if (x->recv() != nullptr) { 3088 LIRItem value(x->recv(), this); 3089 value.load_item(); 3090 recv = new_register(T_OBJECT); 3091 __ move(value.result(), recv); 3092 } 3093 __ profile_call(x->method(), x->bci_of_invoke(), x->callee(), mdo, recv, tmp, x->known_holder()); 3094 } 3095 3096 void LIRGenerator::do_ProfileReturnType(ProfileReturnType* x) { 3097 int bci = x->bci_of_invoke(); 3098 ciMethodData* md = x->method()->method_data_or_null(); 3099 assert(md != nullptr, "Sanity"); 3100 ciProfileData* data = md->bci_to_data(bci); 3101 if (data != nullptr) { 3102 assert(data->is_CallTypeData() || data->is_VirtualCallTypeData(), "wrong profile data type"); 3103 ciReturnTypeEntry* ret = data->is_CallTypeData() ? ((ciCallTypeData*)data)->ret() : ((ciVirtualCallTypeData*)data)->ret(); 3104 LIR_Opr mdp = LIR_OprFact::illegalOpr; 3105 3106 bool ignored_will_link; 3107 ciSignature* signature_at_call = nullptr; 3108 x->method()->get_method_at_bci(bci, ignored_will_link, &signature_at_call); 3109 3110 // The offset within the MDO of the entry to update may be too large 3111 // to be used in load/store instructions on some platforms. So have 3112 // profile_type() compute the address of the profile in a register. 3113 ciKlass* exact = profile_type(md, md->byte_offset_of_slot(data, ret->type_offset()), 0, 3114 ret->type(), x->ret(), mdp, 3115 !x->needs_null_check(), 3116 signature_at_call->return_type()->as_klass(), 3117 x->callee()->signature()->return_type()->as_klass()); 3118 if (exact != nullptr) { 3119 md->set_return_type(bci, exact); 3120 } 3121 } 3122 } 3123 3124 void LIRGenerator::do_ProfileInvoke(ProfileInvoke* x) { 3125 // We can safely ignore accessors here, since c2 will inline them anyway, 3126 // accessors are also always mature. 3127 if (!x->inlinee()->is_accessor()) { 3128 CodeEmitInfo* info = state_for(x, x->state(), true); 3129 // Notify the runtime very infrequently only to take care of counter overflows 3130 int freq_log = Tier23InlineeNotifyFreqLog; 3131 double scale; 3132 if (_method->has_option_value(CompileCommandEnum::CompileThresholdScaling, scale)) { 3133 freq_log = CompilerConfig::scaled_freq_log(freq_log, scale); 3134 } 3135 increment_event_counter_impl(info, x->inlinee(), LIR_OprFact::intConst(InvocationCounter::count_increment), right_n_bits(freq_log), InvocationEntryBci, false, true); 3136 } 3137 } 3138 3139 void LIRGenerator::increment_backedge_counter_conditionally(LIR_Condition cond, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info, int left_bci, int right_bci, int bci) { 3140 if (compilation()->is_profiling()) { 3141 #if defined(X86) && !defined(_LP64) 3142 // BEWARE! On 32-bit x86 cmp clobbers its left argument so we need a temp copy. 3143 LIR_Opr left_copy = new_register(left->type()); 3144 __ move(left, left_copy); 3145 __ cmp(cond, left_copy, right); 3146 #else 3147 __ cmp(cond, left, right); 3148 #endif 3149 LIR_Opr step = new_register(T_INT); 3150 LIR_Opr plus_one = LIR_OprFact::intConst(InvocationCounter::count_increment); 3151 LIR_Opr zero = LIR_OprFact::intConst(0); 3152 __ cmove(cond, 3153 (left_bci < bci) ? plus_one : zero, 3154 (right_bci < bci) ? plus_one : zero, 3155 step, left->type()); 3156 increment_backedge_counter(info, step, bci); 3157 } 3158 } 3159 3160 3161 void LIRGenerator::increment_event_counter(CodeEmitInfo* info, LIR_Opr step, int bci, bool backedge) { 3162 int freq_log = 0; 3163 int level = compilation()->env()->comp_level(); 3164 if (level == CompLevel_limited_profile) { 3165 freq_log = (backedge ? Tier2BackedgeNotifyFreqLog : Tier2InvokeNotifyFreqLog); 3166 } else if (level == CompLevel_full_profile) { 3167 freq_log = (backedge ? Tier3BackedgeNotifyFreqLog : Tier3InvokeNotifyFreqLog); 3168 } else { 3169 ShouldNotReachHere(); 3170 } 3171 // Increment the appropriate invocation/backedge counter and notify the runtime. 3172 double scale; 3173 if (_method->has_option_value(CompileCommandEnum::CompileThresholdScaling, scale)) { 3174 freq_log = CompilerConfig::scaled_freq_log(freq_log, scale); 3175 } 3176 increment_event_counter_impl(info, info->scope()->method(), step, right_n_bits(freq_log), bci, backedge, true); 3177 } 3178 3179 void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info, 3180 ciMethod *method, LIR_Opr step, int frequency, 3181 int bci, bool backedge, bool notify) { 3182 if (PreloadOnly) { 3183 // Nothing to do if we only use preload code. 3184 return; 3185 } 3186 assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0"); 3187 int level = _compilation->env()->comp_level(); 3188 assert(level > CompLevel_simple, "Shouldn't be here"); 3189 3190 int offset = -1; 3191 LIR_Opr counter_holder; 3192 if (level == CompLevel_limited_profile) { 3193 MethodCounters* counters_adr = method->ensure_method_counters(); 3194 if (counters_adr == nullptr) { 3195 bailout("method counters allocation failed"); 3196 return; 3197 } 3198 if (AOTCodeCache::is_on()) { 3199 counter_holder = new_register(T_METADATA); 3200 __ metadata2reg(counters_adr, counter_holder); 3201 } else { 3202 counter_holder = new_pointer_register(); 3203 __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder); 3204 } 3205 offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() : 3206 MethodCounters::invocation_counter_offset()); 3207 } else if (level == CompLevel_full_profile) { 3208 counter_holder = new_register(T_METADATA); 3209 offset = in_bytes(backedge ? MethodData::backedge_counter_offset() : 3210 MethodData::invocation_counter_offset()); 3211 ciMethodData* md = method->method_data_or_null(); 3212 assert(md != nullptr, "Sanity"); 3213 __ metadata2reg(md->constant_encoding(), counter_holder); 3214 } else { 3215 ShouldNotReachHere(); 3216 } 3217 LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT); 3218 LIR_Opr result = new_register(T_INT); 3219 __ load(counter, result); 3220 __ add(result, step, result); 3221 __ store(result, counter); 3222 if (notify && (!backedge || UseOnStackReplacement)) { 3223 LIR_Opr meth = LIR_OprFact::metadataConst(method->constant_encoding()); 3224 // The bci for info can point to cmp for if's we want the if bci 3225 CodeStub* overflow = new CounterOverflowStub(info, bci, meth); 3226 int freq = frequency << InvocationCounter::count_shift; 3227 if (freq == 0) { 3228 if (!step->is_constant()) { 3229 __ cmp(lir_cond_notEqual, step, LIR_OprFact::intConst(0)); 3230 __ branch(lir_cond_notEqual, overflow); 3231 } else { 3232 __ branch(lir_cond_always, overflow); 3233 } 3234 } else { 3235 LIR_Opr mask = load_immediate(freq, T_INT); 3236 if (!step->is_constant()) { 3237 // If step is 0, make sure the overflow check below always fails 3238 __ cmp(lir_cond_notEqual, step, LIR_OprFact::intConst(0)); 3239 __ cmove(lir_cond_notEqual, result, LIR_OprFact::intConst(InvocationCounter::count_increment), result, T_INT); 3240 } 3241 __ logical_and(result, mask, result); 3242 __ cmp(lir_cond_equal, result, LIR_OprFact::intConst(0)); 3243 __ branch(lir_cond_equal, overflow); 3244 } 3245 __ branch_destination(overflow->continuation()); 3246 } 3247 } 3248 3249 void LIRGenerator::do_RuntimeCall(RuntimeCall* x) { 3250 LIR_OprList* args = new LIR_OprList(x->number_of_arguments()); 3251 BasicTypeList* signature = new BasicTypeList(x->number_of_arguments()); 3252 3253 if (x->pass_thread()) { 3254 signature->append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread 3255 args->append(getThreadPointer()); 3256 } 3257 3258 for (int i = 0; i < x->number_of_arguments(); i++) { 3259 Value a = x->argument_at(i); 3260 LIRItem* item = new LIRItem(a, this); 3261 item->load_item(); 3262 args->append(item->result()); 3263 signature->append(as_BasicType(a->type())); 3264 } 3265 3266 LIR_Opr result = call_runtime(signature, args, x->entry(), x->type(), nullptr); 3267 if (x->type() == voidType) { 3268 set_no_result(x); 3269 } else { 3270 __ move(result, rlock_result(x)); 3271 } 3272 } 3273 3274 #ifdef ASSERT 3275 void LIRGenerator::do_Assert(Assert *x) { 3276 ValueTag tag = x->x()->type()->tag(); 3277 If::Condition cond = x->cond(); 3278 3279 LIRItem xitem(x->x(), this); 3280 LIRItem yitem(x->y(), this); 3281 LIRItem* xin = &xitem; 3282 LIRItem* yin = &yitem; 3283 3284 assert(tag == intTag, "Only integer assertions are valid!"); 3285 3286 xin->load_item(); 3287 yin->dont_load_item(); 3288 3289 set_no_result(x); 3290 3291 LIR_Opr left = xin->result(); 3292 LIR_Opr right = yin->result(); 3293 3294 __ lir_assert(lir_cond(x->cond()), left, right, x->message(), true); 3295 } 3296 #endif 3297 3298 void LIRGenerator::do_RangeCheckPredicate(RangeCheckPredicate *x) { 3299 3300 3301 Instruction *a = x->x(); 3302 Instruction *b = x->y(); 3303 if (!a || StressRangeCheckElimination) { 3304 assert(!b || StressRangeCheckElimination, "B must also be null"); 3305 3306 CodeEmitInfo *info = state_for(x, x->state()); 3307 CodeStub* stub = new PredicateFailedStub(info); 3308 3309 __ jump(stub); 3310 } else if (a->type()->as_IntConstant() && b->type()->as_IntConstant()) { 3311 int a_int = a->type()->as_IntConstant()->value(); 3312 int b_int = b->type()->as_IntConstant()->value(); 3313 3314 bool ok = false; 3315 3316 switch(x->cond()) { 3317 case Instruction::eql: ok = (a_int == b_int); break; 3318 case Instruction::neq: ok = (a_int != b_int); break; 3319 case Instruction::lss: ok = (a_int < b_int); break; 3320 case Instruction::leq: ok = (a_int <= b_int); break; 3321 case Instruction::gtr: ok = (a_int > b_int); break; 3322 case Instruction::geq: ok = (a_int >= b_int); break; 3323 case Instruction::aeq: ok = ((unsigned int)a_int >= (unsigned int)b_int); break; 3324 case Instruction::beq: ok = ((unsigned int)a_int <= (unsigned int)b_int); break; 3325 default: ShouldNotReachHere(); 3326 } 3327 3328 if (ok) { 3329 3330 CodeEmitInfo *info = state_for(x, x->state()); 3331 CodeStub* stub = new PredicateFailedStub(info); 3332 3333 __ jump(stub); 3334 } 3335 } else { 3336 3337 ValueTag tag = x->x()->type()->tag(); 3338 If::Condition cond = x->cond(); 3339 LIRItem xitem(x->x(), this); 3340 LIRItem yitem(x->y(), this); 3341 LIRItem* xin = &xitem; 3342 LIRItem* yin = &yitem; 3343 3344 assert(tag == intTag, "Only integer deoptimizations are valid!"); 3345 3346 xin->load_item(); 3347 yin->dont_load_item(); 3348 set_no_result(x); 3349 3350 LIR_Opr left = xin->result(); 3351 LIR_Opr right = yin->result(); 3352 3353 CodeEmitInfo *info = state_for(x, x->state()); 3354 CodeStub* stub = new PredicateFailedStub(info); 3355 3356 __ cmp(lir_cond(cond), left, right); 3357 __ branch(lir_cond(cond), stub); 3358 } 3359 } 3360 3361 void LIRGenerator::do_blackhole(Intrinsic *x) { 3362 assert(!x->has_receiver(), "Should have been checked before: only static methods here"); 3363 for (int c = 0; c < x->number_of_arguments(); c++) { 3364 // Load the argument 3365 LIRItem vitem(x->argument_at(c), this); 3366 vitem.load_item(); 3367 // ...and leave it unused. 3368 } 3369 } 3370 3371 LIR_Opr LIRGenerator::call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info) { 3372 LIRItemList args(1); 3373 LIRItem value(arg1, this); 3374 args.append(&value); 3375 BasicTypeList signature; 3376 signature.append(as_BasicType(arg1->type())); 3377 3378 return call_runtime(&signature, &args, entry, result_type, info); 3379 } 3380 3381 3382 LIR_Opr LIRGenerator::call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info) { 3383 LIRItemList args(2); 3384 LIRItem value1(arg1, this); 3385 LIRItem value2(arg2, this); 3386 args.append(&value1); 3387 args.append(&value2); 3388 BasicTypeList signature; 3389 signature.append(as_BasicType(arg1->type())); 3390 signature.append(as_BasicType(arg2->type())); 3391 3392 return call_runtime(&signature, &args, entry, result_type, info); 3393 } 3394 3395 3396 LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIR_OprList* args, 3397 address entry, ValueType* result_type, CodeEmitInfo* info) { 3398 // get a result register 3399 LIR_Opr phys_reg = LIR_OprFact::illegalOpr; 3400 LIR_Opr result = LIR_OprFact::illegalOpr; 3401 if (result_type->tag() != voidTag) { 3402 result = new_register(result_type); 3403 phys_reg = result_register_for(result_type); 3404 } 3405 3406 // move the arguments into the correct location 3407 CallingConvention* cc = frame_map()->c_calling_convention(signature); 3408 assert(cc->length() == args->length(), "argument mismatch"); 3409 for (int i = 0; i < args->length(); i++) { 3410 LIR_Opr arg = args->at(i); 3411 LIR_Opr loc = cc->at(i); 3412 if (loc->is_register()) { 3413 __ move(arg, loc); 3414 } else { 3415 LIR_Address* addr = loc->as_address_ptr(); 3416 // if (!can_store_as_constant(arg)) { 3417 // LIR_Opr tmp = new_register(arg->type()); 3418 // __ move(arg, tmp); 3419 // arg = tmp; 3420 // } 3421 __ move(arg, addr); 3422 } 3423 } 3424 3425 if (info) { 3426 __ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info); 3427 } else { 3428 __ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args()); 3429 } 3430 if (result->is_valid()) { 3431 __ move(phys_reg, result); 3432 } 3433 return result; 3434 } 3435 3436 3437 LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIRItemList* args, 3438 address entry, ValueType* result_type, CodeEmitInfo* info) { 3439 // get a result register 3440 LIR_Opr phys_reg = LIR_OprFact::illegalOpr; 3441 LIR_Opr result = LIR_OprFact::illegalOpr; 3442 if (result_type->tag() != voidTag) { 3443 result = new_register(result_type); 3444 phys_reg = result_register_for(result_type); 3445 } 3446 3447 // move the arguments into the correct location 3448 CallingConvention* cc = frame_map()->c_calling_convention(signature); 3449 3450 assert(cc->length() == args->length(), "argument mismatch"); 3451 for (int i = 0; i < args->length(); i++) { 3452 LIRItem* arg = args->at(i); 3453 LIR_Opr loc = cc->at(i); 3454 if (loc->is_register()) { 3455 arg->load_item_force(loc); 3456 } else { 3457 LIR_Address* addr = loc->as_address_ptr(); 3458 arg->load_for_store(addr->type()); 3459 __ move(arg->result(), addr); 3460 } 3461 } 3462 3463 if (info) { 3464 __ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info); 3465 } else { 3466 __ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args()); 3467 } 3468 if (result->is_valid()) { 3469 __ move(phys_reg, result); 3470 } 3471 return result; 3472 } 3473 3474 void LIRGenerator::do_MemBar(MemBar* x) { 3475 LIR_Code code = x->code(); 3476 switch(code) { 3477 case lir_membar_acquire : __ membar_acquire(); break; 3478 case lir_membar_release : __ membar_release(); break; 3479 case lir_membar : __ membar(); break; 3480 case lir_membar_loadload : __ membar_loadload(); break; 3481 case lir_membar_storestore: __ membar_storestore(); break; 3482 case lir_membar_loadstore : __ membar_loadstore(); break; 3483 case lir_membar_storeload : __ membar_storeload(); break; 3484 default : ShouldNotReachHere(); break; 3485 } 3486 } 3487 3488 LIR_Opr LIRGenerator::mask_boolean(LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info) { 3489 LIR_Opr value_fixed = rlock_byte(T_BYTE); 3490 if (two_operand_lir_form) { 3491 __ move(value, value_fixed); 3492 __ logical_and(value_fixed, LIR_OprFact::intConst(1), value_fixed); 3493 } else { 3494 __ logical_and(value, LIR_OprFact::intConst(1), value_fixed); 3495 } 3496 LIR_Opr klass = new_register(T_METADATA); 3497 load_klass(array, klass, null_check_info); 3498 null_check_info = nullptr; 3499 LIR_Opr layout = new_register(T_INT); 3500 __ move(new LIR_Address(klass, in_bytes(Klass::layout_helper_offset()), T_INT), layout); 3501 int diffbit = Klass::layout_helper_boolean_diffbit(); 3502 __ logical_and(layout, LIR_OprFact::intConst(diffbit), layout); 3503 __ cmp(lir_cond_notEqual, layout, LIR_OprFact::intConst(0)); 3504 __ cmove(lir_cond_notEqual, value_fixed, value, value_fixed, T_BYTE); 3505 value = value_fixed; 3506 return value; 3507 }