rev 49800 : 8201593: Print array length in ArrayIndexOutOfBoundsException.

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