1 /* 2 * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "c1/c1_Compilation.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_Runtime1.hpp" 32 #include "c1/c1_ValueStack.hpp" 33 #include "ci/ciArray.hpp" 34 #include "ci/ciObjArrayKlass.hpp" 35 #include "ci/ciTypeArrayKlass.hpp" 36 #include "runtime/safepointMechanism.hpp" 37 #include "runtime/sharedRuntime.hpp" 38 #include "runtime/stubRoutines.hpp" 39 #include "vmreg_sparc.inline.hpp" 40 41 #ifdef ASSERT 42 #define __ gen()->lir(__FILE__, __LINE__)-> 43 #else 44 #define __ gen()->lir()-> 45 #endif 46 47 void LIRItem::load_byte_item() { 48 // byte loads use same registers as other loads 49 load_item(); 50 } 51 52 53 void LIRItem::load_nonconstant() { 54 LIR_Opr r = value()->operand(); 55 if (_gen->can_inline_as_constant(value())) { 56 if (!r->is_constant()) { 57 r = LIR_OprFact::value_type(value()->type()); 58 } 59 _result = r; 60 } else { 61 load_item(); 62 } 63 } 64 65 66 //-------------------------------------------------------------- 67 // LIRGenerator 68 //-------------------------------------------------------------- 69 70 LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::Oexception_opr; } 71 LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::Oissuing_pc_opr; } 72 LIR_Opr LIRGenerator::syncLockOpr() { return new_register(T_INT); } 73 LIR_Opr LIRGenerator::syncTempOpr() { return new_register(T_OBJECT); } 74 LIR_Opr LIRGenerator::getThreadTemp() { return rlock_callee_saved(T_LONG); } 75 76 LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) { 77 LIR_Opr opr; 78 switch (type->tag()) { 79 case intTag: opr = callee ? FrameMap::I0_opr : FrameMap::O0_opr; break; 80 case objectTag: opr = callee ? FrameMap::I0_oop_opr : FrameMap::O0_oop_opr; break; 81 case longTag: opr = callee ? FrameMap::in_long_opr : FrameMap::out_long_opr; break; 82 case floatTag: opr = FrameMap::F0_opr; break; 83 case doubleTag: opr = FrameMap::F0_double_opr; break; 84 85 case addressTag: 86 default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr; 87 } 88 89 assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch"); 90 return opr; 91 } 92 93 LIR_Opr LIRGenerator::rlock_callee_saved(BasicType type) { 94 LIR_Opr reg = new_register(type); 95 set_vreg_flag(reg, callee_saved); 96 return reg; 97 } 98 99 100 LIR_Opr LIRGenerator::rlock_byte(BasicType type) { 101 return new_register(T_INT); 102 } 103 104 105 106 107 108 //--------- loading items into registers -------------------------------- 109 110 // SPARC cannot inline all constants 111 bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const { 112 if (v->type()->as_IntConstant() != NULL) { 113 return v->type()->as_IntConstant()->value() == 0; 114 } else if (v->type()->as_LongConstant() != NULL) { 115 return v->type()->as_LongConstant()->value() == 0L; 116 } else if (v->type()->as_ObjectConstant() != NULL) { 117 return v->type()->as_ObjectConstant()->value()->is_null_object(); 118 } else { 119 return false; 120 } 121 } 122 123 124 // only simm13 constants can be inlined 125 bool LIRGenerator:: can_inline_as_constant(Value i) const { 126 if (i->type()->as_IntConstant() != NULL) { 127 return Assembler::is_simm13(i->type()->as_IntConstant()->value()); 128 } else { 129 return can_store_as_constant(i, as_BasicType(i->type())); 130 } 131 } 132 133 134 bool LIRGenerator:: can_inline_as_constant(LIR_Const* c) const { 135 if (c->type() == T_INT) { 136 return Assembler::is_simm13(c->as_jint()); 137 } 138 return false; 139 } 140 141 142 LIR_Opr LIRGenerator::safepoint_poll_register() { 143 return new_register(T_INT); 144 } 145 146 147 148 LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index, 149 int shift, int disp, BasicType type) { 150 assert(base->is_register(), "must be"); 151 intx large_disp = disp; 152 153 // accumulate fixed displacements 154 if (index->is_constant()) { 155 large_disp += (intx)(index->as_constant_ptr()->as_jint()) << shift; 156 index = LIR_OprFact::illegalOpr; 157 } 158 159 if (index->is_register()) { 160 // apply the shift and accumulate the displacement 161 if (shift > 0) { 162 LIR_Opr tmp = new_pointer_register(); 163 __ shift_left(index, shift, tmp); 164 index = tmp; 165 } 166 if (large_disp != 0) { 167 LIR_Opr tmp = new_pointer_register(); 168 if (Assembler::is_simm13(large_disp)) { 169 __ add(tmp, LIR_OprFact::intptrConst(large_disp), tmp); 170 index = tmp; 171 } else { 172 __ move(LIR_OprFact::intptrConst(large_disp), tmp); 173 __ add(tmp, index, tmp); 174 index = tmp; 175 } 176 large_disp = 0; 177 } 178 } else if (large_disp != 0 && !Assembler::is_simm13(large_disp)) { 179 // index is illegal so replace it with the displacement loaded into a register 180 index = new_pointer_register(); 181 __ move(LIR_OprFact::intptrConst(large_disp), index); 182 large_disp = 0; 183 } 184 185 // at this point we either have base + index or base + displacement 186 if (large_disp == 0) { 187 return new LIR_Address(base, index, type); 188 } else { 189 assert(Assembler::is_simm13(large_disp), "must be"); 190 return new LIR_Address(base, large_disp, type); 191 } 192 } 193 194 195 LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr, 196 BasicType type, bool needs_card_mark) { 197 int elem_size = type2aelembytes(type); 198 int shift = exact_log2(elem_size); 199 200 LIR_Opr base_opr; 201 intx offset = arrayOopDesc::base_offset_in_bytes(type); 202 203 if (index_opr->is_constant()) { 204 intx i = index_opr->as_constant_ptr()->as_jint(); 205 intx array_offset = i * elem_size; 206 if (Assembler::is_simm13(array_offset + offset)) { 207 base_opr = array_opr; 208 offset = array_offset + offset; 209 } else { 210 base_opr = new_pointer_register(); 211 if (Assembler::is_simm13(array_offset)) { 212 __ add(array_opr, LIR_OprFact::intptrConst(array_offset), base_opr); 213 } else { 214 __ move(LIR_OprFact::intptrConst(array_offset), base_opr); 215 __ add(base_opr, array_opr, base_opr); 216 } 217 } 218 } else { 219 if (index_opr->type() == T_INT) { 220 LIR_Opr tmp = new_register(T_LONG); 221 __ convert(Bytecodes::_i2l, index_opr, tmp); 222 index_opr = tmp; 223 } 224 225 base_opr = new_pointer_register(); 226 assert (index_opr->is_register(), "Must be register"); 227 if (shift > 0) { 228 __ shift_left(index_opr, shift, base_opr); 229 __ add(base_opr, array_opr, base_opr); 230 } else { 231 __ add(index_opr, array_opr, base_opr); 232 } 233 } 234 if (needs_card_mark) { 235 LIR_Opr ptr = new_pointer_register(); 236 __ add(base_opr, LIR_OprFact::intptrConst(offset), ptr); 237 return new LIR_Address(ptr, type); 238 } else { 239 return new LIR_Address(base_opr, offset, type); 240 } 241 } 242 243 LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) { 244 LIR_Opr r; 245 if (type == T_LONG) { 246 r = LIR_OprFact::longConst(x); 247 } else if (type == T_INT) { 248 r = LIR_OprFact::intConst(x); 249 } else { 250 ShouldNotReachHere(); 251 } 252 if (!Assembler::is_simm13(x)) { 253 LIR_Opr tmp = new_register(type); 254 __ move(r, tmp); 255 return tmp; 256 } 257 return r; 258 } 259 260 void LIRGenerator::increment_counter(address counter, BasicType type, int step) { 261 LIR_Opr pointer = new_pointer_register(); 262 __ move(LIR_OprFact::intptrConst(counter), pointer); 263 LIR_Address* addr = new LIR_Address(pointer, type); 264 increment_counter(addr, step); 265 } 266 267 void LIRGenerator::increment_counter(LIR_Address* addr, int step) { 268 LIR_Opr temp = new_register(addr->type()); 269 __ move(addr, temp); 270 __ add(temp, load_immediate(step, addr->type()), temp); 271 __ move(temp, addr); 272 } 273 274 void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) { 275 LIR_Opr o7opr = FrameMap::O7_opr; 276 __ load(new LIR_Address(base, disp, T_INT), o7opr, info); 277 __ cmp(condition, o7opr, c); 278 } 279 280 281 void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) { 282 LIR_Opr o7opr = FrameMap::O7_opr; 283 __ load(new LIR_Address(base, disp, type), o7opr, info); 284 __ cmp(condition, reg, o7opr); 285 } 286 287 288 void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, LIR_Opr disp, BasicType type, CodeEmitInfo* info) { 289 LIR_Opr o7opr = FrameMap::O7_opr; 290 __ load(new LIR_Address(base, disp, type), o7opr, info); 291 __ cmp(condition, reg, o7opr); 292 } 293 294 295 bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) { 296 assert(left != result, "should be different registers"); 297 if (is_power_of_2(c + 1)) { 298 __ shift_left(left, log2_intptr(c + 1), result); 299 __ sub(result, left, result); 300 return true; 301 } else if (is_power_of_2(c - 1)) { 302 __ shift_left(left, log2_intptr(c - 1), result); 303 __ add(result, left, result); 304 return true; 305 } 306 return false; 307 } 308 309 310 void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) { 311 BasicType t = item->type(); 312 LIR_Opr sp_opr = FrameMap::SP_opr; 313 if ((t == T_LONG || t == T_DOUBLE) && 314 ((in_bytes(offset_from_sp) - STACK_BIAS) % 8 != 0)) { 315 __ unaligned_move(item, new LIR_Address(sp_opr, in_bytes(offset_from_sp), t)); 316 } else { 317 __ move(item, new LIR_Address(sp_opr, in_bytes(offset_from_sp), t)); 318 } 319 } 320 321 //---------------------------------------------------------------------- 322 // visitor functions 323 //---------------------------------------------------------------------- 324 325 326 void LIRGenerator::do_StoreIndexed(StoreIndexed* x) { 327 assert(x->is_pinned(),""); 328 bool needs_range_check = x->compute_needs_range_check(); 329 bool use_length = x->length() != NULL; 330 bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT; 331 bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL || 332 !get_jobject_constant(x->value())->is_null_object() || 333 x->should_profile()); 334 335 LIRItem array(x->array(), this); 336 LIRItem index(x->index(), this); 337 LIRItem value(x->value(), this); 338 LIRItem length(this); 339 340 array.load_item(); 341 index.load_nonconstant(); 342 343 if (use_length && needs_range_check) { 344 length.set_instruction(x->length()); 345 length.load_item(); 346 } 347 if (needs_store_check || x->check_boolean()) { 348 value.load_item(); 349 } else { 350 value.load_for_store(x->elt_type()); 351 } 352 353 set_no_result(x); 354 355 // the CodeEmitInfo must be duplicated for each different 356 // LIR-instruction because spilling can occur anywhere between two 357 // instructions and so the debug information must be different 358 CodeEmitInfo* range_check_info = state_for(x); 359 CodeEmitInfo* null_check_info = NULL; 360 if (x->needs_null_check()) { 361 null_check_info = new CodeEmitInfo(range_check_info); 362 } 363 364 // emit array address setup early so it schedules better 365 LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), obj_store); 366 367 if (GenerateRangeChecks && needs_range_check) { 368 if (use_length) { 369 __ cmp(lir_cond_belowEqual, length.result(), index.result()); 370 __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result())); 371 } else { 372 array_range_check(array.result(), index.result(), null_check_info, range_check_info); 373 // range_check also does the null check 374 null_check_info = NULL; 375 } 376 } 377 378 if (GenerateArrayStoreCheck && needs_store_check) { 379 LIR_Opr tmp1 = FrameMap::G1_opr; 380 LIR_Opr tmp2 = FrameMap::G3_opr; 381 LIR_Opr tmp3 = FrameMap::G5_opr; 382 383 CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info); 384 __ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci()); 385 } 386 387 if (obj_store) { 388 // Needs GC write barriers. 389 pre_barrier(LIR_OprFact::address(array_addr), LIR_OprFact::illegalOpr /* pre_val */, 390 true /* do_load */, false /* patch */, NULL); 391 } 392 LIR_Opr result = maybe_mask_boolean(x, array.result(), value.result(), null_check_info); 393 __ move(result, array_addr, null_check_info); 394 if (obj_store) { 395 // Precise card mark 396 post_barrier(LIR_OprFact::address(array_addr), value.result()); 397 } 398 } 399 400 401 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) { 402 assert(x->is_pinned(),""); 403 LIRItem obj(x->obj(), this); 404 obj.load_item(); 405 406 set_no_result(x); 407 408 LIR_Opr lock = FrameMap::G1_opr; 409 LIR_Opr scratch = FrameMap::G3_opr; 410 LIR_Opr hdr = FrameMap::G4_opr; 411 412 CodeEmitInfo* info_for_exception = NULL; 413 if (x->needs_null_check()) { 414 info_for_exception = state_for(x); 415 } 416 417 // this CodeEmitInfo must not have the xhandlers because here the 418 // object is already locked (xhandlers expects object to be unlocked) 419 CodeEmitInfo* info = state_for(x, x->state(), true); 420 monitor_enter(obj.result(), lock, hdr, scratch, x->monitor_no(), info_for_exception, info); 421 } 422 423 424 void LIRGenerator::do_MonitorExit(MonitorExit* x) { 425 assert(x->is_pinned(),""); 426 LIRItem obj(x->obj(), this); 427 obj.dont_load_item(); 428 429 set_no_result(x); 430 LIR_Opr lock = FrameMap::G1_opr; 431 LIR_Opr hdr = FrameMap::G3_opr; 432 LIR_Opr obj_temp = FrameMap::G4_opr; 433 monitor_exit(obj_temp, lock, hdr, LIR_OprFact::illegalOpr, x->monitor_no()); 434 } 435 436 437 // _ineg, _lneg, _fneg, _dneg 438 void LIRGenerator::do_NegateOp(NegateOp* x) { 439 LIRItem value(x->x(), this); 440 value.load_item(); 441 LIR_Opr reg = rlock_result(x); 442 __ negate(value.result(), reg); 443 } 444 445 446 447 // for _fadd, _fmul, _fsub, _fdiv, _frem 448 // _dadd, _dmul, _dsub, _ddiv, _drem 449 void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) { 450 switch (x->op()) { 451 case Bytecodes::_fadd: 452 case Bytecodes::_fmul: 453 case Bytecodes::_fsub: 454 case Bytecodes::_fdiv: 455 case Bytecodes::_dadd: 456 case Bytecodes::_dmul: 457 case Bytecodes::_dsub: 458 case Bytecodes::_ddiv: { 459 LIRItem left(x->x(), this); 460 LIRItem right(x->y(), this); 461 left.load_item(); 462 right.load_item(); 463 rlock_result(x); 464 arithmetic_op_fpu(x->op(), x->operand(), left.result(), right.result(), x->is_strictfp()); 465 } 466 break; 467 468 case Bytecodes::_frem: 469 case Bytecodes::_drem: { 470 address entry; 471 switch (x->op()) { 472 case Bytecodes::_frem: 473 entry = CAST_FROM_FN_PTR(address, SharedRuntime::frem); 474 break; 475 case Bytecodes::_drem: 476 entry = CAST_FROM_FN_PTR(address, SharedRuntime::drem); 477 break; 478 default: 479 ShouldNotReachHere(); 480 } 481 LIR_Opr result = call_runtime(x->x(), x->y(), entry, x->type(), NULL); 482 set_result(x, result); 483 } 484 break; 485 486 default: ShouldNotReachHere(); 487 } 488 } 489 490 491 // for _ladd, _lmul, _lsub, _ldiv, _lrem 492 void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) { 493 switch (x->op()) { 494 case Bytecodes::_lrem: 495 case Bytecodes::_lmul: 496 case Bytecodes::_ldiv: { 497 498 if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) { 499 LIRItem right(x->y(), this); 500 right.load_item(); 501 502 CodeEmitInfo* info = state_for(x); 503 LIR_Opr item = right.result(); 504 assert(item->is_register(), "must be"); 505 __ cmp(lir_cond_equal, item, LIR_OprFact::longConst(0)); 506 __ branch(lir_cond_equal, T_LONG, new DivByZeroStub(info)); 507 } 508 509 address entry; 510 switch (x->op()) { 511 case Bytecodes::_lrem: 512 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem); 513 break; // check if dividend is 0 is done elsewhere 514 case Bytecodes::_ldiv: 515 entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv); 516 break; // check if dividend is 0 is done elsewhere 517 case Bytecodes::_lmul: 518 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lmul); 519 break; 520 default: 521 ShouldNotReachHere(); 522 } 523 524 // order of arguments to runtime call is reversed. 525 LIR_Opr result = call_runtime(x->y(), x->x(), entry, x->type(), NULL); 526 set_result(x, result); 527 break; 528 } 529 case Bytecodes::_ladd: 530 case Bytecodes::_lsub: { 531 LIRItem left(x->x(), this); 532 LIRItem right(x->y(), this); 533 left.load_item(); 534 right.load_item(); 535 rlock_result(x); 536 537 arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL); 538 break; 539 } 540 default: ShouldNotReachHere(); 541 } 542 } 543 544 545 // Returns if item is an int constant that can be represented by a simm13 546 static bool is_simm13(LIR_Opr item) { 547 if (item->is_constant() && item->type() == T_INT) { 548 return Assembler::is_simm13(item->as_constant_ptr()->as_jint()); 549 } else { 550 return false; 551 } 552 } 553 554 555 // for: _iadd, _imul, _isub, _idiv, _irem 556 void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) { 557 bool is_div_rem = x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem; 558 LIRItem left(x->x(), this); 559 LIRItem right(x->y(), this); 560 // missing test if instr is commutative and if we should swap 561 right.load_nonconstant(); 562 assert(right.is_constant() || right.is_register(), "wrong state of right"); 563 left.load_item(); 564 rlock_result(x); 565 if (is_div_rem) { 566 CodeEmitInfo* info = state_for(x); 567 LIR_Opr tmp = FrameMap::G1_opr; 568 if (x->op() == Bytecodes::_irem) { 569 __ irem(left.result(), right.result(), x->operand(), tmp, info); 570 } else if (x->op() == Bytecodes::_idiv) { 571 __ idiv(left.result(), right.result(), x->operand(), tmp, info); 572 } 573 } else { 574 arithmetic_op_int(x->op(), x->operand(), left.result(), right.result(), FrameMap::G1_opr); 575 } 576 } 577 578 579 void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) { 580 ValueTag tag = x->type()->tag(); 581 assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters"); 582 switch (tag) { 583 case floatTag: 584 case doubleTag: do_ArithmeticOp_FPU(x); return; 585 case longTag: do_ArithmeticOp_Long(x); return; 586 case intTag: do_ArithmeticOp_Int(x); return; 587 } 588 ShouldNotReachHere(); 589 } 590 591 592 // _ishl, _lshl, _ishr, _lshr, _iushr, _lushr 593 void LIRGenerator::do_ShiftOp(ShiftOp* x) { 594 LIRItem value(x->x(), this); 595 LIRItem count(x->y(), this); 596 // Long shift destroys count register 597 if (value.type()->is_long()) { 598 count.set_destroys_register(); 599 } 600 value.load_item(); 601 // the old backend doesn't support this 602 if (count.is_constant() && count.type()->as_IntConstant() != NULL && value.type()->is_int()) { 603 jint c = count.get_jint_constant() & 0x1f; 604 assert(c >= 0 && c < 32, "should be small"); 605 count.dont_load_item(); 606 } else { 607 count.load_item(); 608 } 609 LIR_Opr reg = rlock_result(x); 610 shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr); 611 } 612 613 614 // _iand, _land, _ior, _lor, _ixor, _lxor 615 void LIRGenerator::do_LogicOp(LogicOp* x) { 616 LIRItem left(x->x(), this); 617 LIRItem right(x->y(), this); 618 619 left.load_item(); 620 right.load_nonconstant(); 621 LIR_Opr reg = rlock_result(x); 622 623 logic_op(x->op(), reg, left.result(), right.result()); 624 } 625 626 627 628 // _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg 629 void LIRGenerator::do_CompareOp(CompareOp* x) { 630 LIRItem left(x->x(), this); 631 LIRItem right(x->y(), this); 632 left.load_item(); 633 right.load_item(); 634 LIR_Opr reg = rlock_result(x); 635 if (x->x()->type()->is_float_kind()) { 636 Bytecodes::Code code = x->op(); 637 __ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl)); 638 } else if (x->x()->type()->tag() == longTag) { 639 __ lcmp2int(left.result(), right.result(), reg); 640 } else { 641 Unimplemented(); 642 } 643 } 644 645 646 void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) { 647 assert(x->number_of_arguments() == 4, "wrong type"); 648 LIRItem obj (x->argument_at(0), this); // object 649 LIRItem offset(x->argument_at(1), this); // offset of field 650 LIRItem cmp (x->argument_at(2), this); // value to compare with field 651 LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp 652 653 // Use temps to avoid kills 654 LIR_Opr t1 = FrameMap::G1_opr; 655 LIR_Opr t2 = FrameMap::G3_opr; 656 LIR_Opr addr = new_pointer_register(); 657 658 // get address of field 659 obj.load_item(); 660 offset.load_item(); 661 cmp.load_item(); 662 val.load_item(); 663 664 __ add(obj.result(), offset.result(), addr); 665 666 if (type == objectType) { // Write-barrier needed for Object fields. 667 pre_barrier(addr, LIR_OprFact::illegalOpr /* pre_val */, 668 true /* do_load */, false /* patch */, NULL); 669 } 670 671 if (type == objectType) 672 __ cas_obj(addr, cmp.result(), val.result(), t1, t2); 673 else if (type == intType) 674 __ cas_int(addr, cmp.result(), val.result(), t1, t2); 675 else if (type == longType) 676 __ cas_long(addr, cmp.result(), val.result(), t1, t2); 677 else { 678 ShouldNotReachHere(); 679 } 680 // generate conditional move of boolean result 681 LIR_Opr result = rlock_result(x); 682 __ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0), 683 result, as_BasicType(type)); 684 if (type == objectType) { // Write-barrier needed for Object fields. 685 // Precise card mark since could either be object or array 686 post_barrier(addr, val.result()); 687 } 688 } 689 690 691 void LIRGenerator::do_MathIntrinsic(Intrinsic* x) { 692 switch (x->id()) { 693 case vmIntrinsics::_dabs: 694 case vmIntrinsics::_dsqrt: { 695 assert(x->number_of_arguments() == 1, "wrong type"); 696 LIRItem value(x->argument_at(0), this); 697 value.load_item(); 698 LIR_Opr dst = rlock_result(x); 699 700 switch (x->id()) { 701 case vmIntrinsics::_dsqrt: { 702 __ sqrt(value.result(), dst, LIR_OprFact::illegalOpr); 703 break; 704 } 705 case vmIntrinsics::_dabs: { 706 __ abs(value.result(), dst, LIR_OprFact::illegalOpr); 707 break; 708 } 709 } 710 break; 711 } 712 case vmIntrinsics::_dlog10: // fall through 713 case vmIntrinsics::_dlog: // fall through 714 case vmIntrinsics::_dsin: // fall through 715 case vmIntrinsics::_dtan: // fall through 716 case vmIntrinsics::_dcos: // fall through 717 case vmIntrinsics::_dexp: { 718 assert(x->number_of_arguments() == 1, "wrong type"); 719 720 address runtime_entry = NULL; 721 switch (x->id()) { 722 case vmIntrinsics::_dsin: 723 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin); 724 break; 725 case vmIntrinsics::_dcos: 726 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos); 727 break; 728 case vmIntrinsics::_dtan: 729 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan); 730 break; 731 case vmIntrinsics::_dlog: 732 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog); 733 break; 734 case vmIntrinsics::_dlog10: 735 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10); 736 break; 737 case vmIntrinsics::_dexp: 738 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dexp); 739 break; 740 default: 741 ShouldNotReachHere(); 742 } 743 744 LIR_Opr result = call_runtime(x->argument_at(0), runtime_entry, x->type(), NULL); 745 set_result(x, result); 746 break; 747 } 748 case vmIntrinsics::_dpow: { 749 assert(x->number_of_arguments() == 2, "wrong type"); 750 address runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dpow); 751 LIR_Opr result = call_runtime(x->argument_at(0), x->argument_at(1), runtime_entry, x->type(), NULL); 752 set_result(x, result); 753 break; 754 } 755 } 756 } 757 758 759 void LIRGenerator::do_ArrayCopy(Intrinsic* x) { 760 assert(x->number_of_arguments() == 5, "wrong type"); 761 762 // Make all state_for calls early since they can emit code 763 CodeEmitInfo* info = state_for(x, x->state()); 764 765 // Note: spill caller save before setting the item 766 LIRItem src (x->argument_at(0), this); 767 LIRItem src_pos (x->argument_at(1), this); 768 LIRItem dst (x->argument_at(2), this); 769 LIRItem dst_pos (x->argument_at(3), this); 770 LIRItem length (x->argument_at(4), this); 771 // load all values in callee_save_registers, as this makes the 772 // parameter passing to the fast case simpler 773 src.load_item_force (rlock_callee_saved(T_OBJECT)); 774 src_pos.load_item_force (rlock_callee_saved(T_INT)); 775 dst.load_item_force (rlock_callee_saved(T_OBJECT)); 776 dst_pos.load_item_force (rlock_callee_saved(T_INT)); 777 length.load_item_force (rlock_callee_saved(T_INT)); 778 779 int flags; 780 ciArrayKlass* expected_type; 781 arraycopy_helper(x, &flags, &expected_type); 782 783 __ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), 784 length.result(), rlock_callee_saved(T_INT), 785 expected_type, flags, info); 786 set_no_result(x); 787 } 788 789 void LIRGenerator::do_update_CRC32(Intrinsic* x) { 790 // Make all state_for calls early since they can emit code 791 LIR_Opr result = rlock_result(x); 792 int flags = 0; 793 switch (x->id()) { 794 case vmIntrinsics::_updateCRC32: { 795 LIRItem crc(x->argument_at(0), this); 796 LIRItem val(x->argument_at(1), this); 797 // val is destroyed by update_crc32 798 val.set_destroys_register(); 799 crc.load_item(); 800 val.load_item(); 801 __ update_crc32(crc.result(), val.result(), result); 802 break; 803 } 804 case vmIntrinsics::_updateBytesCRC32: 805 case vmIntrinsics::_updateByteBufferCRC32: { 806 807 bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32); 808 809 LIRItem crc(x->argument_at(0), this); 810 LIRItem buf(x->argument_at(1), this); 811 LIRItem off(x->argument_at(2), this); 812 LIRItem len(x->argument_at(3), this); 813 814 buf.load_item(); 815 off.load_nonconstant(); 816 817 LIR_Opr index = off.result(); 818 int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0; 819 if(off.result()->is_constant()) { 820 index = LIR_OprFact::illegalOpr; 821 offset += off.result()->as_jint(); 822 } 823 824 LIR_Opr base_op = buf.result(); 825 826 if (index->is_valid()) { 827 LIR_Opr tmp = new_register(T_LONG); 828 __ convert(Bytecodes::_i2l, index, tmp); 829 index = tmp; 830 if (index->is_constant()) { 831 offset += index->as_constant_ptr()->as_jint(); 832 index = LIR_OprFact::illegalOpr; 833 } else if (index->is_register()) { 834 LIR_Opr tmp2 = new_register(T_LONG); 835 LIR_Opr tmp3 = new_register(T_LONG); 836 __ move(base_op, tmp2); 837 __ move(index, tmp3); 838 __ add(tmp2, tmp3, tmp2); 839 base_op = tmp2; 840 } else { 841 ShouldNotReachHere(); 842 } 843 } 844 845 LIR_Address* a = new LIR_Address(base_op, offset, T_BYTE); 846 847 BasicTypeList signature(3); 848 signature.append(T_INT); 849 signature.append(T_ADDRESS); 850 signature.append(T_INT); 851 CallingConvention* cc = frame_map()->c_calling_convention(&signature); 852 const LIR_Opr result_reg = result_register_for(x->type()); 853 854 LIR_Opr addr = new_pointer_register(); 855 __ leal(LIR_OprFact::address(a), addr); 856 857 crc.load_item_force(cc->at(0)); 858 __ move(addr, cc->at(1)); 859 len.load_item_force(cc->at(2)); 860 861 __ call_runtime_leaf(StubRoutines::updateBytesCRC32(), getThreadTemp(), result_reg, cc->args()); 862 __ move(result_reg, result); 863 864 break; 865 } 866 default: { 867 ShouldNotReachHere(); 868 } 869 } 870 } 871 872 void LIRGenerator::do_update_CRC32C(Intrinsic* x) { 873 // Make all state_for calls early since they can emit code 874 LIR_Opr result = rlock_result(x); 875 int flags = 0; 876 switch (x->id()) { 877 case vmIntrinsics::_updateBytesCRC32C: 878 case vmIntrinsics::_updateDirectByteBufferCRC32C: { 879 880 bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32C); 881 int array_offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0; 882 883 LIRItem crc(x->argument_at(0), this); 884 LIRItem buf(x->argument_at(1), this); 885 LIRItem off(x->argument_at(2), this); 886 LIRItem end(x->argument_at(3), this); 887 888 buf.load_item(); 889 off.load_nonconstant(); 890 end.load_nonconstant(); 891 892 // len = end - off 893 LIR_Opr len = end.result(); 894 LIR_Opr tmpA = new_register(T_INT); 895 LIR_Opr tmpB = new_register(T_INT); 896 __ move(end.result(), tmpA); 897 __ move(off.result(), tmpB); 898 __ sub(tmpA, tmpB, tmpA); 899 len = tmpA; 900 901 LIR_Opr index = off.result(); 902 903 if(off.result()->is_constant()) { 904 index = LIR_OprFact::illegalOpr; 905 array_offset += off.result()->as_jint(); 906 } 907 908 LIR_Opr base_op = buf.result(); 909 910 if (index->is_valid()) { 911 LIR_Opr tmp = new_register(T_LONG); 912 __ convert(Bytecodes::_i2l, index, tmp); 913 index = tmp; 914 if (index->is_constant()) { 915 array_offset += index->as_constant_ptr()->as_jint(); 916 index = LIR_OprFact::illegalOpr; 917 } else if (index->is_register()) { 918 LIR_Opr tmp2 = new_register(T_LONG); 919 LIR_Opr tmp3 = new_register(T_LONG); 920 __ move(base_op, tmp2); 921 __ move(index, tmp3); 922 __ add(tmp2, tmp3, tmp2); 923 base_op = tmp2; 924 } else { 925 ShouldNotReachHere(); 926 } 927 } 928 929 LIR_Address* a = new LIR_Address(base_op, array_offset, T_BYTE); 930 931 BasicTypeList signature(3); 932 signature.append(T_INT); 933 signature.append(T_ADDRESS); 934 signature.append(T_INT); 935 CallingConvention* cc = frame_map()->c_calling_convention(&signature); 936 const LIR_Opr result_reg = result_register_for(x->type()); 937 938 LIR_Opr addr = new_pointer_register(); 939 __ leal(LIR_OprFact::address(a), addr); 940 941 crc.load_item_force(cc->at(0)); 942 __ move(addr, cc->at(1)); 943 __ move(len, cc->at(2)); 944 945 __ call_runtime_leaf(StubRoutines::updateBytesCRC32C(), getThreadTemp(), result_reg, cc->args()); 946 __ move(result_reg, result); 947 948 break; 949 } 950 default: { 951 ShouldNotReachHere(); 952 } 953 } 954 } 955 956 void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) { 957 assert(x->number_of_arguments() == 3, "wrong type"); 958 assert(UseFMA, "Needs FMA instructions support."); 959 960 LIRItem a(x->argument_at(0), this); 961 LIRItem b(x->argument_at(1), this); 962 LIRItem c(x->argument_at(2), this); 963 964 a.load_item(); 965 b.load_item(); 966 c.load_item(); 967 968 LIR_Opr ina = a.result(); 969 LIR_Opr inb = b.result(); 970 LIR_Opr inc = c.result(); 971 LIR_Opr res = rlock_result(x); 972 973 switch (x->id()) { 974 case vmIntrinsics::_fmaF: __ fmaf(ina, inb, inc, res); break; 975 case vmIntrinsics::_fmaD: __ fmad(ina, inb, inc, res); break; 976 default: 977 ShouldNotReachHere(); 978 break; 979 } 980 } 981 982 void LIRGenerator::do_vectorizedMismatch(Intrinsic* x) { 983 fatal("vectorizedMismatch intrinsic is not implemented on this platform"); 984 } 985 986 // _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f 987 // _i2b, _i2c, _i2s 988 void LIRGenerator::do_Convert(Convert* x) { 989 990 switch (x->op()) { 991 case Bytecodes::_f2l: 992 case Bytecodes::_d2l: 993 case Bytecodes::_d2i: 994 case Bytecodes::_l2f: 995 case Bytecodes::_l2d: { 996 997 address entry; 998 switch (x->op()) { 999 case Bytecodes::_l2f: 1000 entry = CAST_FROM_FN_PTR(address, SharedRuntime::l2f); 1001 break; 1002 case Bytecodes::_l2d: 1003 entry = CAST_FROM_FN_PTR(address, SharedRuntime::l2d); 1004 break; 1005 case Bytecodes::_f2l: 1006 entry = CAST_FROM_FN_PTR(address, SharedRuntime::f2l); 1007 break; 1008 case Bytecodes::_d2l: 1009 entry = CAST_FROM_FN_PTR(address, SharedRuntime::d2l); 1010 break; 1011 case Bytecodes::_d2i: 1012 entry = CAST_FROM_FN_PTR(address, SharedRuntime::d2i); 1013 break; 1014 default: 1015 ShouldNotReachHere(); 1016 } 1017 LIR_Opr result = call_runtime(x->value(), entry, x->type(), NULL); 1018 set_result(x, result); 1019 break; 1020 } 1021 1022 case Bytecodes::_i2f: 1023 case Bytecodes::_i2d: { 1024 LIRItem value(x->value(), this); 1025 1026 LIR_Opr reg = rlock_result(x); 1027 // To convert an int to double, we need to load the 32-bit int 1028 // from memory into a single precision floating point register 1029 // (even numbered). Then the sparc fitod instruction takes care 1030 // of the conversion. This is a bit ugly, but is the best way to 1031 // get the int value in a single precision floating point register 1032 value.load_item(); 1033 LIR_Opr tmp = force_to_spill(value.result(), T_FLOAT); 1034 __ convert(x->op(), tmp, reg); 1035 break; 1036 } 1037 break; 1038 1039 case Bytecodes::_i2l: 1040 case Bytecodes::_i2b: 1041 case Bytecodes::_i2c: 1042 case Bytecodes::_i2s: 1043 case Bytecodes::_l2i: 1044 case Bytecodes::_f2d: 1045 case Bytecodes::_d2f: { // inline code 1046 LIRItem value(x->value(), this); 1047 1048 value.load_item(); 1049 LIR_Opr reg = rlock_result(x); 1050 __ convert(x->op(), value.result(), reg, false); 1051 } 1052 break; 1053 1054 case Bytecodes::_f2i: { 1055 LIRItem value (x->value(), this); 1056 value.set_destroys_register(); 1057 value.load_item(); 1058 LIR_Opr reg = rlock_result(x); 1059 set_vreg_flag(reg, must_start_in_memory); 1060 __ convert(x->op(), value.result(), reg, false); 1061 } 1062 break; 1063 1064 default: ShouldNotReachHere(); 1065 } 1066 } 1067 1068 1069 void LIRGenerator::do_NewInstance(NewInstance* x) { 1070 print_if_not_loaded(x); 1071 1072 // This instruction can be deoptimized in the slow path : use 1073 // O0 as result register. 1074 const LIR_Opr reg = result_register_for(x->type()); 1075 1076 CodeEmitInfo* info = state_for(x, x->state()); 1077 LIR_Opr tmp1 = FrameMap::G1_oop_opr; 1078 LIR_Opr tmp2 = FrameMap::G3_oop_opr; 1079 LIR_Opr tmp3 = FrameMap::G4_oop_opr; 1080 LIR_Opr tmp4 = FrameMap::O1_oop_opr; 1081 LIR_Opr klass_reg = FrameMap::G5_metadata_opr; 1082 new_instance(reg, x->klass(), x->is_unresolved(), tmp1, tmp2, tmp3, tmp4, klass_reg, info); 1083 LIR_Opr result = rlock_result(x); 1084 __ move(reg, result); 1085 } 1086 1087 1088 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) { 1089 // Evaluate state_for early since it may emit code 1090 CodeEmitInfo* info = state_for(x, x->state()); 1091 1092 LIRItem length(x->length(), this); 1093 length.load_item(); 1094 1095 LIR_Opr reg = result_register_for(x->type()); 1096 LIR_Opr tmp1 = FrameMap::G1_oop_opr; 1097 LIR_Opr tmp2 = FrameMap::G3_oop_opr; 1098 LIR_Opr tmp3 = FrameMap::G4_oop_opr; 1099 LIR_Opr tmp4 = FrameMap::O1_oop_opr; 1100 LIR_Opr klass_reg = FrameMap::G5_metadata_opr; 1101 LIR_Opr len = length.result(); 1102 BasicType elem_type = x->elt_type(); 1103 1104 __ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg); 1105 1106 CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info); 1107 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path); 1108 1109 LIR_Opr result = rlock_result(x); 1110 __ move(reg, result); 1111 } 1112 1113 1114 void LIRGenerator::do_NewObjectArray(NewObjectArray* x) { 1115 // Evaluate state_for early since it may emit code. 1116 CodeEmitInfo* info = state_for(x, x->state()); 1117 // in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction 1118 // and therefore provide the state before the parameters have been consumed 1119 CodeEmitInfo* patching_info = NULL; 1120 if (!x->klass()->is_loaded() || PatchALot) { 1121 patching_info = state_for(x, x->state_before()); 1122 } 1123 1124 LIRItem length(x->length(), this); 1125 length.load_item(); 1126 1127 const LIR_Opr reg = result_register_for(x->type()); 1128 LIR_Opr tmp1 = FrameMap::G1_oop_opr; 1129 LIR_Opr tmp2 = FrameMap::G3_oop_opr; 1130 LIR_Opr tmp3 = FrameMap::G4_oop_opr; 1131 LIR_Opr tmp4 = FrameMap::O1_oop_opr; 1132 LIR_Opr klass_reg = FrameMap::G5_metadata_opr; 1133 LIR_Opr len = length.result(); 1134 1135 CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info); 1136 ciMetadata* obj = ciObjArrayKlass::make(x->klass()); 1137 if (obj == ciEnv::unloaded_ciobjarrayklass()) { 1138 BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error"); 1139 } 1140 klass2reg_with_patching(klass_reg, obj, patching_info); 1141 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path); 1142 1143 LIR_Opr result = rlock_result(x); 1144 __ move(reg, result); 1145 } 1146 1147 1148 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) { 1149 Values* dims = x->dims(); 1150 int i = dims->length(); 1151 LIRItemList* items = new LIRItemList(i, i, NULL); 1152 while (i-- > 0) { 1153 LIRItem* size = new LIRItem(dims->at(i), this); 1154 items->at_put(i, size); 1155 } 1156 1157 // Evaluate state_for early since it may emit code. 1158 CodeEmitInfo* patching_info = NULL; 1159 if (!x->klass()->is_loaded() || PatchALot) { 1160 patching_info = state_for(x, x->state_before()); 1161 1162 // Cannot re-use same xhandlers for multiple CodeEmitInfos, so 1163 // clone all handlers (NOTE: Usually this is handled transparently 1164 // by the CodeEmitInfo cloning logic in CodeStub constructors but 1165 // is done explicitly here because a stub isn't being used). 1166 x->set_exception_handlers(new XHandlers(x->exception_handlers())); 1167 } 1168 CodeEmitInfo* info = state_for(x, x->state()); 1169 1170 i = dims->length(); 1171 while (i-- > 0) { 1172 LIRItem* size = items->at(i); 1173 size->load_item(); 1174 store_stack_parameter (size->result(), 1175 in_ByteSize(STACK_BIAS + 1176 frame::memory_parameter_word_sp_offset * wordSize + 1177 i * sizeof(jint))); 1178 } 1179 1180 // This instruction can be deoptimized in the slow path : use 1181 // O0 as result register. 1182 const LIR_Opr klass_reg = FrameMap::O0_metadata_opr; 1183 klass2reg_with_patching(klass_reg, x->klass(), patching_info); 1184 LIR_Opr rank = FrameMap::O1_opr; 1185 __ move(LIR_OprFact::intConst(x->rank()), rank); 1186 LIR_Opr varargs = FrameMap::as_pointer_opr(O2); 1187 int offset_from_sp = (frame::memory_parameter_word_sp_offset * wordSize) + STACK_BIAS; 1188 __ add(FrameMap::SP_opr, 1189 LIR_OprFact::intptrConst(offset_from_sp), 1190 varargs); 1191 LIR_OprList* args = new LIR_OprList(3); 1192 args->append(klass_reg); 1193 args->append(rank); 1194 args->append(varargs); 1195 const LIR_Opr reg = result_register_for(x->type()); 1196 __ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id), 1197 LIR_OprFact::illegalOpr, 1198 reg, args, info); 1199 1200 LIR_Opr result = rlock_result(x); 1201 __ move(reg, result); 1202 } 1203 1204 1205 void LIRGenerator::do_BlockBegin(BlockBegin* x) { 1206 } 1207 1208 1209 void LIRGenerator::do_CheckCast(CheckCast* x) { 1210 LIRItem obj(x->obj(), this); 1211 CodeEmitInfo* patching_info = NULL; 1212 if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check())) { 1213 // must do this before locking the destination register as an oop register, 1214 // and before the obj is loaded (so x->obj()->item() is valid for creating a debug info location) 1215 patching_info = state_for(x, x->state_before()); 1216 } 1217 obj.load_item(); 1218 LIR_Opr out_reg = rlock_result(x); 1219 CodeStub* stub; 1220 CodeEmitInfo* info_for_exception = 1221 (x->needs_exception_state() ? state_for(x) : 1222 state_for(x, x->state_before(), true /*ignore_xhandler*/)); 1223 1224 if (x->is_incompatible_class_change_check()) { 1225 assert(patching_info == NULL, "can't patch this"); 1226 stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception); 1227 } else if (x->is_invokespecial_receiver_check()) { 1228 assert(patching_info == NULL, "can't patch this"); 1229 stub = new DeoptimizeStub(info_for_exception, 1230 Deoptimization::Reason_class_check, 1231 Deoptimization::Action_none); 1232 } else { 1233 stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception); 1234 } 1235 LIR_Opr tmp1 = FrameMap::G1_oop_opr; 1236 LIR_Opr tmp2 = FrameMap::G3_oop_opr; 1237 LIR_Opr tmp3 = FrameMap::G4_oop_opr; 1238 __ checkcast(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3, 1239 x->direct_compare(), info_for_exception, patching_info, stub, 1240 x->profiled_method(), x->profiled_bci()); 1241 } 1242 1243 1244 void LIRGenerator::do_InstanceOf(InstanceOf* x) { 1245 LIRItem obj(x->obj(), this); 1246 CodeEmitInfo* patching_info = NULL; 1247 if (!x->klass()->is_loaded() || PatchALot) { 1248 patching_info = state_for(x, x->state_before()); 1249 } 1250 // ensure the result register is not the input register because the result is initialized before the patching safepoint 1251 obj.load_item(); 1252 LIR_Opr out_reg = rlock_result(x); 1253 LIR_Opr tmp1 = FrameMap::G1_oop_opr; 1254 LIR_Opr tmp2 = FrameMap::G3_oop_opr; 1255 LIR_Opr tmp3 = FrameMap::G4_oop_opr; 1256 __ instanceof(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3, 1257 x->direct_compare(), patching_info, 1258 x->profiled_method(), x->profiled_bci()); 1259 } 1260 1261 1262 void LIRGenerator::do_If(If* x) { 1263 assert(x->number_of_sux() == 2, "inconsistency"); 1264 ValueTag tag = x->x()->type()->tag(); 1265 LIRItem xitem(x->x(), this); 1266 LIRItem yitem(x->y(), this); 1267 LIRItem* xin = &xitem; 1268 LIRItem* yin = &yitem; 1269 If::Condition cond = x->cond(); 1270 1271 if (tag == longTag) { 1272 // for longs, only conditions "eql", "neq", "lss", "geq" are valid; 1273 // mirror for other conditions 1274 if (cond == If::gtr || cond == If::leq) { 1275 // swap inputs 1276 cond = Instruction::mirror(cond); 1277 xin = &yitem; 1278 yin = &xitem; 1279 } 1280 xin->set_destroys_register(); 1281 } 1282 1283 LIR_Opr left = LIR_OprFact::illegalOpr; 1284 LIR_Opr right = LIR_OprFact::illegalOpr; 1285 1286 xin->load_item(); 1287 left = xin->result(); 1288 1289 if (is_simm13(yin->result())) { 1290 // inline int constants which are small enough to be immediate operands 1291 right = LIR_OprFact::value_type(yin->value()->type()); 1292 } else if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && 1293 (cond == If::eql || cond == If::neq)) { 1294 // inline long zero 1295 right = LIR_OprFact::value_type(yin->value()->type()); 1296 } else if (tag == objectTag && yin->is_constant() && (yin->get_jobject_constant()->is_null_object())) { 1297 right = LIR_OprFact::value_type(yin->value()->type()); 1298 } else { 1299 yin->load_item(); 1300 right = yin->result(); 1301 } 1302 set_no_result(x); 1303 1304 // add safepoint before generating condition code so it can be recomputed 1305 if (x->is_safepoint()) { 1306 // increment backedge counter if needed 1307 increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci()); 1308 __ safepoint(safepoint_poll_register(), state_for(x, x->state_before())); 1309 } 1310 1311 __ cmp(lir_cond(cond), left, right); 1312 // Generate branch profiling. Profiling code doesn't kill flags. 1313 profile_branch(x, cond); 1314 move_to_phi(x->state()); 1315 if (x->x()->type()->is_float_kind()) { 1316 __ branch(lir_cond(cond), right->type(), x->tsux(), x->usux()); 1317 } else { 1318 __ branch(lir_cond(cond), right->type(), x->tsux()); 1319 } 1320 assert(x->default_sux() == x->fsux(), "wrong destination above"); 1321 __ jump(x->default_sux()); 1322 } 1323 1324 1325 LIR_Opr LIRGenerator::getThreadPointer() { 1326 return FrameMap::as_pointer_opr(G2); 1327 } 1328 1329 1330 void LIRGenerator::trace_block_entry(BlockBegin* block) { 1331 __ move(LIR_OprFact::intConst(block->block_id()), FrameMap::O0_opr); 1332 LIR_OprList* args = new LIR_OprList(1); 1333 args->append(FrameMap::O0_opr); 1334 address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry); 1335 __ call_runtime_leaf(func, rlock_callee_saved(T_INT), LIR_OprFact::illegalOpr, args); 1336 } 1337 1338 1339 void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address, 1340 CodeEmitInfo* info) { 1341 __ store(value, address, info); 1342 } 1343 1344 void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result, 1345 CodeEmitInfo* info) { 1346 __ load(address, result, info); 1347 } 1348 1349 1350 void LIRGenerator::put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data, 1351 BasicType type, bool is_volatile) { 1352 LIR_Opr base_op = src; 1353 LIR_Opr index_op = offset; 1354 1355 bool is_obj = (type == T_ARRAY || type == T_OBJECT); 1356 { 1357 if (type == T_BOOLEAN) { 1358 type = T_BYTE; 1359 } 1360 LIR_Address* addr; 1361 if (type == T_ARRAY || type == T_OBJECT) { 1362 LIR_Opr tmp = new_pointer_register(); 1363 __ add(base_op, index_op, tmp); 1364 addr = new LIR_Address(tmp, type); 1365 } else { 1366 addr = new LIR_Address(base_op, index_op, type); 1367 } 1368 1369 if (is_obj) { 1370 pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */, 1371 true /* do_load */, false /* patch */, NULL); 1372 // _bs->c1_write_barrier_pre(this, LIR_OprFact::address(addr)); 1373 } 1374 __ move(data, addr); 1375 if (is_obj) { 1376 // This address is precise 1377 post_barrier(LIR_OprFact::address(addr), data); 1378 } 1379 } 1380 } 1381 1382 1383 void LIRGenerator::get_Object_unsafe(LIR_Opr dst, LIR_Opr src, LIR_Opr offset, 1384 BasicType type, bool is_volatile) { 1385 { 1386 LIR_Address* addr = new LIR_Address(src, offset, type); 1387 __ load(addr, dst); 1388 } 1389 } 1390 1391 void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) { 1392 BasicType type = x->basic_type(); 1393 LIRItem src(x->object(), this); 1394 LIRItem off(x->offset(), this); 1395 LIRItem value(x->value(), this); 1396 1397 src.load_item(); 1398 value.load_item(); 1399 off.load_nonconstant(); 1400 1401 LIR_Opr dst = rlock_result(x, type); 1402 LIR_Opr data = value.result(); 1403 bool is_obj = (type == T_ARRAY || type == T_OBJECT); 1404 LIR_Opr offset = off.result(); 1405 1406 // Because we want a 2-arg form of xchg 1407 __ move(data, dst); 1408 1409 assert (!x->is_add() && (type == T_INT || (is_obj && UseCompressedOops)), "unexpected type"); 1410 LIR_Address* addr; 1411 if (offset->is_constant()) { 1412 1413 jlong l = offset->as_jlong(); 1414 assert((jlong)((jint)l) == l, "offset too large for constant"); 1415 jint c = (jint)l; 1416 addr = new LIR_Address(src.result(), c, type); 1417 } else { 1418 addr = new LIR_Address(src.result(), offset, type); 1419 } 1420 1421 LIR_Opr tmp = LIR_OprFact::illegalOpr; 1422 LIR_Opr ptr = LIR_OprFact::illegalOpr; 1423 1424 if (is_obj) { 1425 // Do the pre-write barrier, if any. 1426 // barriers on sparc don't work with a base + index address 1427 tmp = FrameMap::G3_opr; 1428 ptr = new_pointer_register(); 1429 __ add(src.result(), off.result(), ptr); 1430 pre_barrier(ptr, LIR_OprFact::illegalOpr /* pre_val */, 1431 true /* do_load */, false /* patch */, NULL); 1432 } 1433 __ xchg(LIR_OprFact::address(addr), dst, dst, tmp); 1434 if (is_obj) { 1435 // Seems to be a precise address 1436 post_barrier(ptr, data); 1437 } 1438 }