< prev index next >

src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp

Print this page

  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "c1/c1_Compilation.hpp"
  26 #include "c1/c1_FrameMap.hpp"
  27 #include "c1/c1_Instruction.hpp"
  28 #include "c1/c1_LIRAssembler.hpp"
  29 #include "c1/c1_LIRGenerator.hpp"
  30 #include "c1/c1_Runtime1.hpp"
  31 #include "c1/c1_ValueStack.hpp"
  32 #include "ci/ciArray.hpp"

  33 #include "ci/ciObjArrayKlass.hpp"
  34 #include "ci/ciTypeArrayKlass.hpp"
  35 #include "gc/shared/c1/barrierSetC1.hpp"
  36 #include "runtime/sharedRuntime.hpp"
  37 #include "runtime/stubRoutines.hpp"
  38 #include "utilities/powerOfTwo.hpp"
  39 #include "vmreg_x86.inline.hpp"
  40 
  41 #ifdef ASSERT
  42 #define __ gen()->lir(__FILE__, __LINE__)->
  43 #else
  44 #define __ gen()->lir()->
  45 #endif
  46 
  47 // Item will be loaded into a byte register; Intel only
  48 void LIRItem::load_byte_item() {
  49   load_item();
  50   LIR_Opr res = result();
  51 
  52   if (!res->is_virtual() || !_gen->is_vreg_flag_set(res, LIRGenerator::byte_reg)) {

  93     case objectTag:  opr = FrameMap::rax_oop_opr;      break;
  94     case longTag:    opr = FrameMap::long0_opr;        break;
  95     case floatTag:   opr = FrameMap::xmm0_float_opr;   break;
  96     case doubleTag:  opr = FrameMap::xmm0_double_opr;  break;
  97     case addressTag:
  98     default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
  99   }
 100 
 101   assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");
 102   return opr;
 103 }
 104 
 105 
 106 LIR_Opr LIRGenerator::rlock_byte(BasicType type) {
 107   LIR_Opr reg = new_register(T_INT);
 108   set_vreg_flag(reg, LIRGenerator::byte_reg);
 109   return reg;
 110 }
 111 
 112 













 113 //--------- loading items into registers --------------------------------
 114 
 115 
 116 // i486 instructions can inline constants
 117 bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {
 118   if (type == T_SHORT || type == T_CHAR) {
 119     return false;
 120   }
 121   Constant* c = v->as_Constant();
 122   if (c && c->state_before() == nullptr) {
 123     // constants of any type can be stored directly, except for
 124     // unloaded object constants.
 125     return true;
 126   }
 127   return false;
 128 }
 129 
 130 
 131 bool LIRGenerator::can_inline_as_constant(Value v) const {
 132   if (v->type()->tag() == longTag) return false;

 264 void LIRGenerator::array_store_check(LIR_Opr value, LIR_Opr array, CodeEmitInfo* store_check_info, ciMethod* profiled_method, int profiled_bci) {
 265   LIR_Opr tmp1 = new_register(objectType);
 266   LIR_Opr tmp2 = new_register(objectType);
 267   LIR_Opr tmp3 = new_register(objectType);
 268   __ store_check(value, array, tmp1, tmp2, tmp3, store_check_info, profiled_method, profiled_bci);
 269 }
 270 
 271 //----------------------------------------------------------------------
 272 //             visitor functions
 273 //----------------------------------------------------------------------
 274 
 275 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
 276   assert(x->is_pinned(),"");
 277   LIRItem obj(x->obj(), this);
 278   obj.load_item();
 279 
 280   set_no_result(x);
 281 
 282   // "lock" stores the address of the monitor stack slot, so this is not an oop
 283   LIR_Opr lock = new_register(T_INT);






 284 
 285   CodeEmitInfo* info_for_exception = nullptr;
 286   if (x->needs_null_check()) {
 287     info_for_exception = state_for(x);
 288   }






 289   // this CodeEmitInfo must not have the xhandlers because here the
 290   // object is already locked (xhandlers expect object to be unlocked)
 291   CodeEmitInfo* info = state_for(x, x->state(), true);
 292   LIR_Opr tmp = LockingMode == LM_LIGHTWEIGHT ? new_register(T_ADDRESS) : LIR_OprFact::illegalOpr;
 293   monitor_enter(obj.result(), lock, syncTempOpr(), tmp,
 294                         x->monitor_no(), info_for_exception, info);
 295 }
 296 
 297 
 298 void LIRGenerator::do_MonitorExit(MonitorExit* x) {
 299   assert(x->is_pinned(),"");
 300 
 301   LIRItem obj(x->obj(), this);
 302   obj.dont_load_item();
 303 
 304   LIR_Opr lock = new_register(T_INT);
 305   LIR_Opr obj_temp = new_register(T_INT);
 306   set_no_result(x);
 307   monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());
 308 }
 309 
 310 // _ineg, _lneg, _fneg, _dneg
 311 void LIRGenerator::do_NegateOp(NegateOp* x) {
 312   LIRItem value(x->x(), this);
 313   value.set_destroys_register();
 314   value.load_item();

1099   log2ArrayIndexScale.load_item_force(cc->at(3));
1100 
1101   __ call_runtime_leaf(StubRoutines::vectorizedMismatch(), getThreadTemp(), result_reg, cc->args());
1102   __ move(result_reg, result);
1103 }
1104 
1105 void LIRGenerator::do_Convert(Convert* x) {
1106   LIRItem value(x->value(), this);
1107   value.load_item();
1108   LIR_Opr input = value.result();
1109   LIR_Opr result = rlock(x);
1110   __ convert(x->op(), input, result);
1111   assert(result->is_virtual(), "result must be virtual register");
1112   set_result(x, result);
1113 }
1114 
1115 
1116 void LIRGenerator::do_NewInstance(NewInstance* x) {
1117   print_if_not_loaded(x);
1118 
1119   CodeEmitInfo* info = state_for(x, x->state());
1120   LIR_Opr reg = result_register_for(x->type());
1121   new_instance(reg, x->klass(), x->is_unresolved(),
1122                        FrameMap::rcx_oop_opr,
1123                        FrameMap::rdi_oop_opr,
1124                        FrameMap::rsi_oop_opr,
1125                        LIR_OprFact::illegalOpr,
1126                        FrameMap::rdx_metadata_opr, info);

1127   LIR_Opr result = rlock_result(x);
1128   __ move(reg, result);
1129 }
1130 
1131 
1132 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
1133   CodeEmitInfo* info = nullptr;
1134   if (x->state_before() != nullptr && x->state_before()->force_reexecute()) {
1135     info = state_for(x, x->state_before());
1136     info->set_force_reexecute();
1137   } else {
1138     info = state_for(x, x->state());
1139   }
1140 
1141   LIRItem length(x->length(), this);
1142   length.load_item_force(FrameMap::rbx_opr);
1143 
1144   LIR_Opr reg = result_register_for(x->type());
1145   LIR_Opr tmp1 = FrameMap::rcx_oop_opr;
1146   LIR_Opr tmp2 = FrameMap::rsi_oop_opr;
1147   LIR_Opr tmp3 = FrameMap::rdi_oop_opr;
1148   LIR_Opr tmp4 = reg;
1149   LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;
1150   LIR_Opr len = length.result();
1151   BasicType elem_type = x->elt_type();

1164   LIRItem length(x->length(), this);
1165   // in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction
1166   // and therefore provide the state before the parameters have been consumed
1167   CodeEmitInfo* patching_info = nullptr;
1168   if (!x->klass()->is_loaded() || PatchALot) {
1169     patching_info =  state_for(x, x->state_before());
1170   }
1171 
1172   CodeEmitInfo* info = state_for(x, x->state());
1173 
1174   const LIR_Opr reg = result_register_for(x->type());
1175   LIR_Opr tmp1 = FrameMap::rcx_oop_opr;
1176   LIR_Opr tmp2 = FrameMap::rsi_oop_opr;
1177   LIR_Opr tmp3 = FrameMap::rdi_oop_opr;
1178   LIR_Opr tmp4 = reg;
1179   LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;
1180 
1181   length.load_item_force(FrameMap::rbx_opr);
1182   LIR_Opr len = length.result();
1183 
1184   CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);
1185   ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass());
1186   if (obj == ciEnv::unloaded_ciobjarrayklass()) {
1187     BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");
1188   }
1189   klass2reg_with_patching(klass_reg, obj, patching_info);
1190   __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);
1191 
1192   LIR_Opr result = rlock_result(x);
1193   __ move(reg, result);
1194 }
1195 
1196 
1197 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {
1198   Values* dims = x->dims();
1199   int i = dims->length();
1200   LIRItemList* items = new LIRItemList(i, i, nullptr);
1201   while (i-- > 0) {
1202     LIRItem* size = new LIRItem(dims->at(i), this);
1203     items->at_put(i, size);
1204   }
1205 
1206   // Evaluate state_for early since it may emit code.
1207   CodeEmitInfo* patching_info = nullptr;
1208   if (!x->klass()->is_loaded() || PatchALot) {
1209     patching_info = state_for(x, x->state_before());
1210 

1249   // nothing to do for now
1250 }
1251 
1252 
1253 void LIRGenerator::do_CheckCast(CheckCast* x) {
1254   LIRItem obj(x->obj(), this);
1255 
1256   CodeEmitInfo* patching_info = nullptr;
1257   if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check() && !x->is_invokespecial_receiver_check())) {
1258     // must do this before locking the destination register as an oop register,
1259     // and before the obj is loaded (the latter is for deoptimization)
1260     patching_info = state_for(x, x->state_before());
1261   }
1262   obj.load_item();
1263 
1264   // info for exceptions
1265   CodeEmitInfo* info_for_exception =
1266       (x->needs_exception_state() ? state_for(x) :
1267                                     state_for(x, x->state_before(), true /*ignore_xhandler*/));
1268 




1269   CodeStub* stub;
1270   if (x->is_incompatible_class_change_check()) {
1271     assert(patching_info == nullptr, "can't patch this");
1272     stub = new SimpleExceptionStub(C1StubId::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);
1273   } else if (x->is_invokespecial_receiver_check()) {
1274     assert(patching_info == nullptr, "can't patch this");
1275     stub = new DeoptimizeStub(info_for_exception, Deoptimization::Reason_class_check, Deoptimization::Action_none);
1276   } else {
1277     stub = new SimpleExceptionStub(C1StubId::throw_class_cast_exception_id, obj.result(), info_for_exception);
1278   }
1279   LIR_Opr reg = rlock_result(x);
1280   LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
1281   if (!x->klass()->is_loaded() || UseCompressedClassPointers) {
1282     tmp3 = new_register(objectType);
1283   }
1284   __ checkcast(reg, obj.result(), x->klass(),
1285                new_register(objectType), new_register(objectType), tmp3,
1286                x->direct_compare(), info_for_exception, patching_info, stub,
1287                x->profiled_method(), x->profiled_bci());
1288 }
1289 
1290 
1291 void LIRGenerator::do_InstanceOf(InstanceOf* x) {
1292   LIRItem obj(x->obj(), this);
1293 
1294   // result and test object may not be in same register
1295   LIR_Opr reg = rlock_result(x);
1296   CodeEmitInfo* patching_info = nullptr;
1297   if ((!x->klass()->is_loaded() || PatchALot)) {
1298     // must do this before locking the destination register as an oop register
1299     patching_info = state_for(x, x->state_before());
1300   }
1301   obj.load_item();
1302   LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
1303   if (!x->klass()->is_loaded() || UseCompressedClassPointers) {
1304     tmp3 = new_register(objectType);
1305   }
1306   __ instanceof(reg, obj.result(), x->klass(),
1307                 new_register(objectType), new_register(objectType), tmp3,

1323 
1324   LIRItem xitem(x->x(), this);
1325   LIRItem yitem(x->y(), this);
1326   LIRItem* xin = &xitem;
1327   LIRItem* yin = &yitem;
1328 
1329   if (tag == longTag) {
1330     // for longs, only conditions "eql", "neq", "lss", "geq" are valid;
1331     // mirror for other conditions
1332     if (cond == If::gtr || cond == If::leq) {
1333       cond = Instruction::mirror(cond);
1334       xin = &yitem;
1335       yin = &xitem;
1336     }
1337     xin->set_destroys_register();
1338   }
1339   xin->load_item();
1340   if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) {
1341     // inline long zero
1342     yin->dont_load_item();
1343   } else if (tag == longTag || tag == floatTag || tag == doubleTag) {
1344     // longs cannot handle constants at right side
1345     yin->load_item();
1346   } else {
1347     yin->dont_load_item();
1348   }
1349 
1350   LIR_Opr left = xin->result();
1351   LIR_Opr right = yin->result();
1352 
1353   set_no_result(x);
1354 
1355   // add safepoint before generating condition code so it can be recomputed
1356   if (x->is_safepoint()) {
1357     // increment backedge counter if needed
1358     increment_backedge_counter_conditionally(lir_cond(cond), left, right, state_for(x, x->state_before()),
1359         x->tsux()->bci(), x->fsux()->bci(), x->profiled_bci());
1360     __ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));
1361   }
1362 
1363   __ cmp(lir_cond(cond), left, right);




1364   // Generate branch profiling. Profiling code doesn't kill flags.
1365   profile_branch(x, cond);
1366   move_to_phi(x->state());
1367   if (x->x()->type()->is_float_kind()) {
1368     __ branch(lir_cond(cond), x->tsux(), x->usux());
1369   } else {
1370     __ branch(lir_cond(cond), x->tsux());
1371   }
1372   assert(x->default_sux() == x->fsux(), "wrong destination above");
1373   __ jump(x->default_sux());
1374 }
1375 
1376 
1377 LIR_Opr LIRGenerator::getThreadPointer() {
1378   return FrameMap::as_pointer_opr(r15_thread);
1379 }
1380 
1381 void LIRGenerator::trace_block_entry(BlockBegin* block) {
1382   store_stack_parameter(LIR_OprFact::intConst(block->block_id()), in_ByteSize(0));
1383   LIR_OprList* args = new LIR_OprList();

  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "c1/c1_Compilation.hpp"
  26 #include "c1/c1_FrameMap.hpp"
  27 #include "c1/c1_Instruction.hpp"
  28 #include "c1/c1_LIRAssembler.hpp"
  29 #include "c1/c1_LIRGenerator.hpp"
  30 #include "c1/c1_Runtime1.hpp"
  31 #include "c1/c1_ValueStack.hpp"
  32 #include "ci/ciArray.hpp"
  33 #include "ci/ciInlineKlass.hpp"
  34 #include "ci/ciObjArrayKlass.hpp"
  35 #include "ci/ciTypeArrayKlass.hpp"
  36 #include "gc/shared/c1/barrierSetC1.hpp"
  37 #include "runtime/sharedRuntime.hpp"
  38 #include "runtime/stubRoutines.hpp"
  39 #include "utilities/powerOfTwo.hpp"
  40 #include "vmreg_x86.inline.hpp"
  41 
  42 #ifdef ASSERT
  43 #define __ gen()->lir(__FILE__, __LINE__)->
  44 #else
  45 #define __ gen()->lir()->
  46 #endif
  47 
  48 // Item will be loaded into a byte register; Intel only
  49 void LIRItem::load_byte_item() {
  50   load_item();
  51   LIR_Opr res = result();
  52 
  53   if (!res->is_virtual() || !_gen->is_vreg_flag_set(res, LIRGenerator::byte_reg)) {

  94     case objectTag:  opr = FrameMap::rax_oop_opr;      break;
  95     case longTag:    opr = FrameMap::long0_opr;        break;
  96     case floatTag:   opr = FrameMap::xmm0_float_opr;   break;
  97     case doubleTag:  opr = FrameMap::xmm0_double_opr;  break;
  98     case addressTag:
  99     default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
 100   }
 101 
 102   assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");
 103   return opr;
 104 }
 105 
 106 
 107 LIR_Opr LIRGenerator::rlock_byte(BasicType type) {
 108   LIR_Opr reg = new_register(T_INT);
 109   set_vreg_flag(reg, LIRGenerator::byte_reg);
 110   return reg;
 111 }
 112 
 113 
 114 void LIRGenerator::init_temps_for_substitutability_check(LIR_Opr& tmp1, LIR_Opr& tmp2) {
 115   // We just need one 32-bit temp register for x86/x64, to check whether both
 116   // oops have markWord::always_locked_pattern. See LIR_Assembler::emit_opSubstitutabilityCheck().
 117   // @temp = %r10d
 118   // mov $0x405, %r10d
 119   // and (%left), %r10d   /* if need to check left */
 120   // and (%right), %r10d  /* if need to check right */
 121   // cmp $0x405, $r10d
 122   // jne L_oops_not_equal
 123   tmp1 = new_register(T_INT);
 124   tmp2 = LIR_OprFact::illegalOpr;
 125 }
 126 
 127 //--------- loading items into registers --------------------------------
 128 
 129 
 130 // i486 instructions can inline constants
 131 bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {
 132   if (type == T_SHORT || type == T_CHAR) {
 133     return false;
 134   }
 135   Constant* c = v->as_Constant();
 136   if (c && c->state_before() == nullptr) {
 137     // constants of any type can be stored directly, except for
 138     // unloaded object constants.
 139     return true;
 140   }
 141   return false;
 142 }
 143 
 144 
 145 bool LIRGenerator::can_inline_as_constant(Value v) const {
 146   if (v->type()->tag() == longTag) return false;

 278 void LIRGenerator::array_store_check(LIR_Opr value, LIR_Opr array, CodeEmitInfo* store_check_info, ciMethod* profiled_method, int profiled_bci) {
 279   LIR_Opr tmp1 = new_register(objectType);
 280   LIR_Opr tmp2 = new_register(objectType);
 281   LIR_Opr tmp3 = new_register(objectType);
 282   __ store_check(value, array, tmp1, tmp2, tmp3, store_check_info, profiled_method, profiled_bci);
 283 }
 284 
 285 //----------------------------------------------------------------------
 286 //             visitor functions
 287 //----------------------------------------------------------------------
 288 
 289 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
 290   assert(x->is_pinned(),"");
 291   LIRItem obj(x->obj(), this);
 292   obj.load_item();
 293 
 294   set_no_result(x);
 295 
 296   // "lock" stores the address of the monitor stack slot, so this is not an oop
 297   LIR_Opr lock = new_register(T_INT);
 298   // Need a scratch register for inline types on x86
 299   LIR_Opr scratch = LIR_OprFact::illegalOpr;
 300   if ((LockingMode == LM_LIGHTWEIGHT) ||
 301       (EnableValhalla && x->maybe_inlinetype())) {
 302     scratch = new_register(T_ADDRESS);
 303   }
 304 
 305   CodeEmitInfo* info_for_exception = nullptr;
 306   if (x->needs_null_check()) {
 307     info_for_exception = state_for(x);
 308   }
 309 
 310   CodeStub* throw_ie_stub = x->maybe_inlinetype() ?
 311       new SimpleExceptionStub(C1StubId::throw_identity_exception_id,
 312                               obj.result(), state_for(x))
 313     : nullptr;
 314 
 315   // this CodeEmitInfo must not have the xhandlers because here the
 316   // object is already locked (xhandlers expect object to be unlocked)
 317   CodeEmitInfo* info = state_for(x, x->state(), true);
 318   monitor_enter(obj.result(), lock, syncTempOpr(), scratch,
 319                 x->monitor_no(), info_for_exception, info, throw_ie_stub);

 320 }
 321 
 322 
 323 void LIRGenerator::do_MonitorExit(MonitorExit* x) {
 324   assert(x->is_pinned(),"");
 325 
 326   LIRItem obj(x->obj(), this);
 327   obj.dont_load_item();
 328 
 329   LIR_Opr lock = new_register(T_INT);
 330   LIR_Opr obj_temp = new_register(T_INT);
 331   set_no_result(x);
 332   monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());
 333 }
 334 
 335 // _ineg, _lneg, _fneg, _dneg
 336 void LIRGenerator::do_NegateOp(NegateOp* x) {
 337   LIRItem value(x->x(), this);
 338   value.set_destroys_register();
 339   value.load_item();

1124   log2ArrayIndexScale.load_item_force(cc->at(3));
1125 
1126   __ call_runtime_leaf(StubRoutines::vectorizedMismatch(), getThreadTemp(), result_reg, cc->args());
1127   __ move(result_reg, result);
1128 }
1129 
1130 void LIRGenerator::do_Convert(Convert* x) {
1131   LIRItem value(x->value(), this);
1132   value.load_item();
1133   LIR_Opr input = value.result();
1134   LIR_Opr result = rlock(x);
1135   __ convert(x->op(), input, result);
1136   assert(result->is_virtual(), "result must be virtual register");
1137   set_result(x, result);
1138 }
1139 
1140 
1141 void LIRGenerator::do_NewInstance(NewInstance* x) {
1142   print_if_not_loaded(x);
1143 
1144   CodeEmitInfo* info = state_for(x, x->needs_state_before() ? x->state_before() : x->state());
1145   LIR_Opr reg = result_register_for(x->type());
1146   new_instance(reg, x->klass(), x->is_unresolved(),
1147                !x->is_unresolved() && x->klass()->is_inlinetype(),
1148                FrameMap::rcx_oop_opr,
1149                FrameMap::rdi_oop_opr,
1150                FrameMap::rsi_oop_opr,
1151                LIR_OprFact::illegalOpr,
1152                FrameMap::rdx_metadata_opr, info);
1153   LIR_Opr result = rlock_result(x);
1154   __ move(reg, result);
1155 }
1156 

1157 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
1158   CodeEmitInfo* info = nullptr;
1159   if (x->state_before() != nullptr && x->state_before()->force_reexecute()) {
1160     info = state_for(x, x->state_before());
1161     info->set_force_reexecute();
1162   } else {
1163     info = state_for(x, x->state());
1164   }
1165 
1166   LIRItem length(x->length(), this);
1167   length.load_item_force(FrameMap::rbx_opr);
1168 
1169   LIR_Opr reg = result_register_for(x->type());
1170   LIR_Opr tmp1 = FrameMap::rcx_oop_opr;
1171   LIR_Opr tmp2 = FrameMap::rsi_oop_opr;
1172   LIR_Opr tmp3 = FrameMap::rdi_oop_opr;
1173   LIR_Opr tmp4 = reg;
1174   LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;
1175   LIR_Opr len = length.result();
1176   BasicType elem_type = x->elt_type();

1189   LIRItem length(x->length(), this);
1190   // in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction
1191   // and therefore provide the state before the parameters have been consumed
1192   CodeEmitInfo* patching_info = nullptr;
1193   if (!x->klass()->is_loaded() || PatchALot) {
1194     patching_info =  state_for(x, x->state_before());
1195   }
1196 
1197   CodeEmitInfo* info = state_for(x, x->state());
1198 
1199   const LIR_Opr reg = result_register_for(x->type());
1200   LIR_Opr tmp1 = FrameMap::rcx_oop_opr;
1201   LIR_Opr tmp2 = FrameMap::rsi_oop_opr;
1202   LIR_Opr tmp3 = FrameMap::rdi_oop_opr;
1203   LIR_Opr tmp4 = reg;
1204   LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;
1205 
1206   length.load_item_force(FrameMap::rbx_opr);
1207   LIR_Opr len = length.result();
1208 
1209   ciKlass* obj = (ciKlass*) x->exact_type();
1210   CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info, x->is_null_free());
1211   if (obj == ciEnv::unloaded_ciobjarrayklass()) {
1212     BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");
1213   }
1214   klass2reg_with_patching(klass_reg, obj, patching_info);
1215   __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path, true, x->is_null_free());
1216 
1217   LIR_Opr result = rlock_result(x);
1218   __ move(reg, result);
1219 }
1220 
1221 
1222 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {
1223   Values* dims = x->dims();
1224   int i = dims->length();
1225   LIRItemList* items = new LIRItemList(i, i, nullptr);
1226   while (i-- > 0) {
1227     LIRItem* size = new LIRItem(dims->at(i), this);
1228     items->at_put(i, size);
1229   }
1230 
1231   // Evaluate state_for early since it may emit code.
1232   CodeEmitInfo* patching_info = nullptr;
1233   if (!x->klass()->is_loaded() || PatchALot) {
1234     patching_info = state_for(x, x->state_before());
1235 

1274   // nothing to do for now
1275 }
1276 
1277 
1278 void LIRGenerator::do_CheckCast(CheckCast* x) {
1279   LIRItem obj(x->obj(), this);
1280 
1281   CodeEmitInfo* patching_info = nullptr;
1282   if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check() && !x->is_invokespecial_receiver_check())) {
1283     // must do this before locking the destination register as an oop register,
1284     // and before the obj is loaded (the latter is for deoptimization)
1285     patching_info = state_for(x, x->state_before());
1286   }
1287   obj.load_item();
1288 
1289   // info for exceptions
1290   CodeEmitInfo* info_for_exception =
1291       (x->needs_exception_state() ? state_for(x) :
1292                                     state_for(x, x->state_before(), true /*ignore_xhandler*/));
1293 
1294   if (x->is_null_free()) {
1295     __ null_check(obj.result(), new CodeEmitInfo(info_for_exception));
1296   }
1297 
1298   CodeStub* stub;
1299   if (x->is_incompatible_class_change_check()) {
1300     assert(patching_info == nullptr, "can't patch this");
1301     stub = new SimpleExceptionStub(C1StubId::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);
1302   } else if (x->is_invokespecial_receiver_check()) {
1303     assert(patching_info == nullptr, "can't patch this");
1304     stub = new DeoptimizeStub(info_for_exception, Deoptimization::Reason_class_check, Deoptimization::Action_none);
1305   } else {
1306     stub = new SimpleExceptionStub(C1StubId::throw_class_cast_exception_id, obj.result(), info_for_exception);
1307   }
1308   LIR_Opr reg = rlock_result(x);
1309   LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
1310   if (!x->klass()->is_loaded() || UseCompressedClassPointers) {
1311     tmp3 = new_register(objectType);
1312   }
1313   __ checkcast(reg, obj.result(), x->klass(),
1314                new_register(objectType), new_register(objectType), tmp3,
1315                x->direct_compare(), info_for_exception, patching_info, stub,
1316                x->profiled_method(), x->profiled_bci(), x->is_null_free());
1317 }
1318 
1319 
1320 void LIRGenerator::do_InstanceOf(InstanceOf* x) {
1321   LIRItem obj(x->obj(), this);
1322 
1323   // result and test object may not be in same register
1324   LIR_Opr reg = rlock_result(x);
1325   CodeEmitInfo* patching_info = nullptr;
1326   if ((!x->klass()->is_loaded() || PatchALot)) {
1327     // must do this before locking the destination register as an oop register
1328     patching_info = state_for(x, x->state_before());
1329   }
1330   obj.load_item();
1331   LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
1332   if (!x->klass()->is_loaded() || UseCompressedClassPointers) {
1333     tmp3 = new_register(objectType);
1334   }
1335   __ instanceof(reg, obj.result(), x->klass(),
1336                 new_register(objectType), new_register(objectType), tmp3,

1352 
1353   LIRItem xitem(x->x(), this);
1354   LIRItem yitem(x->y(), this);
1355   LIRItem* xin = &xitem;
1356   LIRItem* yin = &yitem;
1357 
1358   if (tag == longTag) {
1359     // for longs, only conditions "eql", "neq", "lss", "geq" are valid;
1360     // mirror for other conditions
1361     if (cond == If::gtr || cond == If::leq) {
1362       cond = Instruction::mirror(cond);
1363       xin = &yitem;
1364       yin = &xitem;
1365     }
1366     xin->set_destroys_register();
1367   }
1368   xin->load_item();
1369   if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) {
1370     // inline long zero
1371     yin->dont_load_item();
1372   } else if (tag == longTag || tag == floatTag || tag == doubleTag || x->substitutability_check()) {
1373     // longs cannot handle constants at right side
1374     yin->load_item();
1375   } else {
1376     yin->dont_load_item();
1377   }
1378 
1379   LIR_Opr left = xin->result();
1380   LIR_Opr right = yin->result();
1381 
1382   set_no_result(x);
1383 
1384   // add safepoint before generating condition code so it can be recomputed
1385   if (x->is_safepoint()) {
1386     // increment backedge counter if needed
1387     increment_backedge_counter_conditionally(lir_cond(cond), left, right, state_for(x, x->state_before()),
1388         x->tsux()->bci(), x->fsux()->bci(), x->profiled_bci());
1389     __ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));
1390   }
1391 
1392   if (x->substitutability_check()) {
1393     substitutability_check(x, *xin, *yin);
1394   } else {
1395     __ cmp(lir_cond(cond), left, right);
1396   }
1397   // Generate branch profiling. Profiling code doesn't kill flags.
1398   profile_branch(x, cond);
1399   move_to_phi(x->state());
1400   if (x->x()->type()->is_float_kind()) {
1401     __ branch(lir_cond(cond), x->tsux(), x->usux());
1402   } else {
1403     __ branch(lir_cond(cond), x->tsux());
1404   }
1405   assert(x->default_sux() == x->fsux(), "wrong destination above");
1406   __ jump(x->default_sux());
1407 }
1408 
1409 
1410 LIR_Opr LIRGenerator::getThreadPointer() {
1411   return FrameMap::as_pointer_opr(r15_thread);
1412 }
1413 
1414 void LIRGenerator::trace_block_entry(BlockBegin* block) {
1415   store_stack_parameter(LIR_OprFact::intConst(block->block_id()), in_ByteSize(0));
1416   LIR_OprList* args = new LIR_OprList();
< prev index next >