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