< prev index next >

src/hotspot/share/c1/c1_LIR.hpp

Print this page

 319   friend BasicType as_BasicType(OprType t);
 320 
 321   OprType type_field_valid() const               { assert(is_register() || is_stack(), "should not be called otherwise"); return (OprType)(value() & type_mask); }
 322   OprType type_field() const                     { return is_illegal() ? unknown_type : (OprType)(value() & type_mask); }
 323 
 324   static OprSize size_for(BasicType t) {
 325     switch (t) {
 326       case T_LONG:
 327       case T_DOUBLE:
 328         return double_size;
 329         break;
 330 
 331       case T_FLOAT:
 332       case T_BOOLEAN:
 333       case T_CHAR:
 334       case T_BYTE:
 335       case T_SHORT:
 336       case T_INT:
 337       case T_ADDRESS:
 338       case T_OBJECT:

 339       case T_ARRAY:
 340       case T_METADATA:
 341         return single_size;
 342         break;
 343 
 344       default:
 345         ShouldNotReachHere();
 346         return single_size;
 347       }
 348   }
 349 
 350 
 351   void validate_type() const PRODUCT_RETURN;
 352 
 353   BasicType type() const {
 354     if (is_pointer()) {
 355       return pointer()->type();
 356     }
 357     return as_BasicType(type_field());
 358   }

 468   int fpu() const { return lo_reg_half(); }
 469 #endif
 470 
 471   jint      as_jint()    const { return as_constant_ptr()->as_jint(); }
 472   jlong     as_jlong()   const { return as_constant_ptr()->as_jlong(); }
 473   jfloat    as_jfloat()  const { return as_constant_ptr()->as_jfloat(); }
 474   jdouble   as_jdouble() const { return as_constant_ptr()->as_jdouble(); }
 475   jobject   as_jobject() const { return as_constant_ptr()->as_jobject(); }
 476 
 477   void print() const PRODUCT_RETURN;
 478   void print(outputStream* out) const PRODUCT_RETURN;
 479 };
 480 
 481 inline LIR_Opr::OprType as_OprType(BasicType type) {
 482   switch (type) {
 483   case T_INT:      return LIR_Opr::int_type;
 484   case T_LONG:     return LIR_Opr::long_type;
 485   case T_FLOAT:    return LIR_Opr::float_type;
 486   case T_DOUBLE:   return LIR_Opr::double_type;
 487   case T_OBJECT:

 488   case T_ARRAY:    return LIR_Opr::object_type;
 489   case T_ADDRESS:  return LIR_Opr::address_type;
 490   case T_METADATA: return LIR_Opr::metadata_type;
 491   case T_ILLEGAL:  // fall through
 492   default: ShouldNotReachHere(); return LIR_Opr::unknown_type;
 493   }
 494 }
 495 
 496 inline BasicType as_BasicType(LIR_Opr::OprType t) {
 497   switch (t) {
 498   case LIR_Opr::int_type:     return T_INT;
 499   case LIR_Opr::long_type:    return T_LONG;
 500   case LIR_Opr::float_type:   return T_FLOAT;
 501   case LIR_Opr::double_type:  return T_DOUBLE;
 502   case LIR_Opr::object_type:  return T_OBJECT;
 503   case LIR_Opr::address_type: return T_ADDRESS;
 504   case LIR_Opr::metadata_type:return T_METADATA;
 505   case LIR_Opr::unknown_type: // fall through
 506   default: ShouldNotReachHere();  return T_ILLEGAL;
 507   }

 659   }
 660   static LIR_Opr double_xmm(int reg) {
 661     return (LIR_Opr)(intptr_t)((reg << LIR_Opr::reg1_shift) |
 662                                (reg << LIR_Opr::reg2_shift) |
 663                                LIR_Opr::double_type         |
 664                                LIR_Opr::fpu_register        |
 665                                LIR_Opr::double_size         |
 666                                LIR_Opr::is_xmm_mask);
 667   }
 668 #endif // X86
 669 
 670   static LIR_Opr virtual_register(int index, BasicType type) {
 671     if (index > LIR_Opr::vreg_max) {
 672       // Running out of virtual registers. Caller should bailout.
 673       return illegalOpr;
 674     }
 675 
 676     LIR_Opr res;
 677     switch (type) {
 678       case T_OBJECT: // fall through

 679       case T_ARRAY:
 680         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift)  |
 681                                             LIR_Opr::object_type  |
 682                                             LIR_Opr::cpu_register |
 683                                             LIR_Opr::single_size  |
 684                                             LIR_Opr::virtual_mask);
 685         break;
 686 
 687       case T_METADATA:
 688         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift)  |
 689                                             LIR_Opr::metadata_type|
 690                                             LIR_Opr::cpu_register |
 691                                             LIR_Opr::single_size  |
 692                                             LIR_Opr::virtual_mask);
 693         break;
 694 
 695       case T_INT:
 696         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 697                                   LIR_Opr::int_type              |
 698                                   LIR_Opr::cpu_register          |

 764                                t |
 765                                LIR_Opr::cpu_register |
 766                                LIR_Opr::size_for(type) | LIR_Opr::virtual_mask);
 767 #else // __SOFTFP__
 768     LIR_Opr old_res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) | t |
 769                                           ((type == T_FLOAT || type == T_DOUBLE) ?  LIR_Opr::fpu_register : LIR_Opr::cpu_register) |
 770                                LIR_Opr::size_for(type) | LIR_Opr::virtual_mask);
 771     assert(res == old_res, "old and new method not equal");
 772 #endif // __SOFTFP__
 773 #endif // ASSERT
 774 
 775     return res;
 776   }
 777 
 778   // 'index' is computed by FrameMap::local_stack_pos(index); do not use other parameters as
 779   // the index is platform independent; a double stack useing indeces 2 and 3 has always
 780   // index 2.
 781   static LIR_Opr stack(int index, BasicType type) {
 782     LIR_Opr res;
 783     switch (type) {

 784       case T_OBJECT: // fall through
 785       case T_ARRAY:
 786         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 787                                   LIR_Opr::object_type           |
 788                                   LIR_Opr::stack_value           |
 789                                   LIR_Opr::single_size);
 790         break;
 791 
 792       case T_METADATA:
 793         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 794                                   LIR_Opr::metadata_type         |
 795                                   LIR_Opr::stack_value           |
 796                                   LIR_Opr::single_size);
 797         break;
 798       case T_INT:
 799         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 800                                   LIR_Opr::int_type              |
 801                                   LIR_Opr::stack_value           |
 802                                   LIR_Opr::single_size);
 803         break;

 877 class  LIR_Op;
 878 class    LIR_Op0;
 879 class      LIR_OpLabel;
 880 class    LIR_Op1;
 881 class      LIR_OpBranch;
 882 class      LIR_OpConvert;
 883 class      LIR_OpAllocObj;
 884 class      LIR_OpReturn;
 885 class      LIR_OpRoundFP;
 886 class    LIR_Op2;
 887 class    LIR_OpDelay;
 888 class    LIR_Op3;
 889 class      LIR_OpAllocArray;
 890 class    LIR_OpCall;
 891 class      LIR_OpJavaCall;
 892 class      LIR_OpRTCall;
 893 class    LIR_OpArrayCopy;
 894 class    LIR_OpUpdateCRC32;
 895 class    LIR_OpLock;
 896 class    LIR_OpTypeCheck;



 897 class    LIR_OpCompareAndSwap;
 898 class    LIR_OpLoadKlass;
 899 class    LIR_OpProfileCall;
 900 class    LIR_OpProfileType;

 901 #ifdef ASSERT
 902 class    LIR_OpAssert;
 903 #endif
 904 
 905 // LIR operation codes
 906 enum LIR_Code {
 907     lir_none
 908   , begin_op0
 909       , lir_label
 910       , lir_nop
 911       , lir_std_entry
 912       , lir_osr_entry
 913       , lir_fpop_raw
 914       , lir_breakpoint
 915       , lir_rtcall
 916       , lir_membar
 917       , lir_membar_acquire
 918       , lir_membar_release
 919       , lir_membar_loadload
 920       , lir_membar_storestore
 921       , lir_membar_loadstore
 922       , lir_membar_storeload
 923       , lir_get_thread
 924       , lir_on_spin_wait

 925   , end_op0
 926   , begin_op1
 927       , lir_fxch
 928       , lir_fld
 929       , lir_push
 930       , lir_pop
 931       , lir_null_check
 932       , lir_return
 933       , lir_leal
 934       , lir_branch
 935       , lir_cond_float_branch
 936       , lir_move
 937       , lir_convert
 938       , lir_alloc_object
 939       , lir_monaddr
 940       , lir_roundfp
 941       , lir_safepoint
 942       , lir_unwind
 943       , lir_load_klass
 944   , end_op1

 982       , lir_dynamic_call
 983   , end_opJavaCall
 984   , begin_opArrayCopy
 985       , lir_arraycopy
 986   , end_opArrayCopy
 987   , begin_opUpdateCRC32
 988       , lir_updatecrc32
 989   , end_opUpdateCRC32
 990   , begin_opLock
 991     , lir_lock
 992     , lir_unlock
 993   , end_opLock
 994   , begin_delay_slot
 995     , lir_delay_slot
 996   , end_delay_slot
 997   , begin_opTypeCheck
 998     , lir_instanceof
 999     , lir_checkcast
1000     , lir_store_check
1001   , end_opTypeCheck









1002   , begin_opCompareAndSwap
1003     , lir_cas_long
1004     , lir_cas_obj
1005     , lir_cas_int
1006   , end_opCompareAndSwap
1007   , begin_opMDOProfile
1008     , lir_profile_call
1009     , lir_profile_type

1010   , end_opMDOProfile
1011   , begin_opAssert
1012     , lir_assert
1013   , end_opAssert
1014 };
1015 
1016 
1017 enum LIR_Condition {
1018     lir_cond_equal
1019   , lir_cond_notEqual
1020   , lir_cond_less
1021   , lir_cond_lessEqual
1022   , lir_cond_greaterEqual
1023   , lir_cond_greater
1024   , lir_cond_belowEqual
1025   , lir_cond_aboveEqual
1026   , lir_cond_always
1027   , lir_cond_unknown = -1
1028 };
1029 

1132   virtual bool is_patching() { return false; }
1133   virtual LIR_OpCall* as_OpCall() { return NULL; }
1134   virtual LIR_OpJavaCall* as_OpJavaCall() { return NULL; }
1135   virtual LIR_OpLabel* as_OpLabel() { return NULL; }
1136   virtual LIR_OpDelay* as_OpDelay() { return NULL; }
1137   virtual LIR_OpLock* as_OpLock() { return NULL; }
1138   virtual LIR_OpAllocArray* as_OpAllocArray() { return NULL; }
1139   virtual LIR_OpAllocObj* as_OpAllocObj() { return NULL; }
1140   virtual LIR_OpRoundFP* as_OpRoundFP() { return NULL; }
1141   virtual LIR_OpBranch* as_OpBranch() { return NULL; }
1142   virtual LIR_OpReturn* as_OpReturn() { return NULL; }
1143   virtual LIR_OpRTCall* as_OpRTCall() { return NULL; }
1144   virtual LIR_OpConvert* as_OpConvert() { return NULL; }
1145   virtual LIR_Op0* as_Op0() { return NULL; }
1146   virtual LIR_Op1* as_Op1() { return NULL; }
1147   virtual LIR_Op2* as_Op2() { return NULL; }
1148   virtual LIR_Op3* as_Op3() { return NULL; }
1149   virtual LIR_OpArrayCopy* as_OpArrayCopy() { return NULL; }
1150   virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return NULL; }
1151   virtual LIR_OpTypeCheck* as_OpTypeCheck() { return NULL; }



1152   virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return NULL; }
1153   virtual LIR_OpLoadKlass* as_OpLoadKlass() { return NULL; }
1154   virtual LIR_OpProfileCall* as_OpProfileCall() { return NULL; }
1155   virtual LIR_OpProfileType* as_OpProfileType() { return NULL; }

1156 #ifdef ASSERT
1157   virtual LIR_OpAssert* as_OpAssert() { return NULL; }
1158 #endif
1159 
1160   virtual void verify() const {}
1161 };
1162 
1163 // for calls
1164 class LIR_OpCall: public LIR_Op {
1165  friend class LIR_OpVisitState;
1166 
1167  protected:
1168   address      _addr;
1169   LIR_OprList* _arguments;
1170  protected:
1171   LIR_OpCall(LIR_Code code, address addr, LIR_Opr result,
1172              LIR_OprList* arguments, CodeEmitInfo* info = NULL)
1173     : LIR_Op(code, result, info)
1174     , _addr(addr)
1175     , _arguments(arguments) {}

1208                  LIR_OprList* arguments, CodeEmitInfo* info)
1209   : LIR_OpCall(code, (address)vtable_offset, result, arguments, info)
1210   , _method(method)
1211   , _receiver(receiver)
1212   , _method_handle_invoke_SP_save_opr(LIR_OprFact::illegalOpr)
1213   { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1214 
1215   LIR_Opr receiver() const                       { return _receiver; }
1216   ciMethod* method() const                       { return _method;   }
1217 
1218   // JSR 292 support.
1219   bool is_invokedynamic() const                  { return code() == lir_dynamic_call; }
1220   bool is_method_handle_invoke() const {
1221     return method()->is_compiled_lambda_form() ||   // Java-generated lambda form
1222            method()->is_method_handle_intrinsic();  // JVM-generated MH intrinsic
1223   }
1224 
1225   virtual void emit_code(LIR_Assembler* masm);
1226   virtual LIR_OpJavaCall* as_OpJavaCall() { return this; }
1227   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;


1228 };
1229 
1230 // --------------------------------------------------
1231 // LIR_OpLabel
1232 // --------------------------------------------------
1233 // Location where a branch can continue
1234 class LIR_OpLabel: public LIR_Op {
1235  friend class LIR_OpVisitState;
1236 
1237  private:
1238   Label* _label;
1239  public:
1240   LIR_OpLabel(Label* lbl)
1241    : LIR_Op(lir_label, LIR_OprFact::illegalOpr, NULL)
1242    , _label(lbl)                                 {}
1243   Label* label() const                           { return _label; }
1244 
1245   virtual void emit_code(LIR_Assembler* masm);
1246   virtual LIR_OpLabel* as_OpLabel() { return this; }
1247   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;

1259   LIR_Opr   _dst_pos;
1260   LIR_Opr   _length;
1261   LIR_Opr   _tmp;
1262   ciArrayKlass* _expected_type;
1263   int       _flags;
1264 
1265 public:
1266   enum Flags {
1267     src_null_check         = 1 << 0,
1268     dst_null_check         = 1 << 1,
1269     src_pos_positive_check = 1 << 2,
1270     dst_pos_positive_check = 1 << 3,
1271     length_positive_check  = 1 << 4,
1272     src_range_check        = 1 << 5,
1273     dst_range_check        = 1 << 6,
1274     type_check             = 1 << 7,
1275     overlapping            = 1 << 8,
1276     unaligned              = 1 << 9,
1277     src_objarray           = 1 << 10,
1278     dst_objarray           = 1 << 11,
1279     all_flags              = (1 << 12) - 1



1280   };
1281 
1282   LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp,
1283                   ciArrayKlass* expected_type, int flags, CodeEmitInfo* info);
1284 
1285   LIR_Opr src() const                            { return _src; }
1286   LIR_Opr src_pos() const                        { return _src_pos; }
1287   LIR_Opr dst() const                            { return _dst; }
1288   LIR_Opr dst_pos() const                        { return _dst_pos; }
1289   LIR_Opr length() const                         { return _length; }
1290   LIR_Opr tmp() const                            { return _tmp; }
1291   int flags() const                              { return _flags; }
1292   ciArrayKlass* expected_type() const            { return _expected_type; }
1293   ArrayCopyStub* stub() const                    { return _stub; }
1294 
1295   virtual void emit_code(LIR_Assembler* masm);
1296   virtual LIR_OpArrayCopy* as_OpArrayCopy() { return this; }
1297   void print_instr(outputStream* out) const PRODUCT_RETURN;
1298 };
1299 

1561 };
1562 
1563 // LIR_OpTypeCheck
1564 class LIR_OpTypeCheck: public LIR_Op {
1565  friend class LIR_OpVisitState;
1566 
1567  private:
1568   LIR_Opr       _object;
1569   LIR_Opr       _array;
1570   ciKlass*      _klass;
1571   LIR_Opr       _tmp1;
1572   LIR_Opr       _tmp2;
1573   LIR_Opr       _tmp3;
1574   bool          _fast_check;
1575   CodeEmitInfo* _info_for_patch;
1576   CodeEmitInfo* _info_for_exception;
1577   CodeStub*     _stub;
1578   ciMethod*     _profiled_method;
1579   int           _profiled_bci;
1580   bool          _should_profile;

1581 
1582 public:
1583   LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1584                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1585                   CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub);
1586   LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1587                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1588 
1589   LIR_Opr object() const                         { return _object;         }
1590   LIR_Opr array() const                          { assert(code() == lir_store_check, "not valid"); return _array;         }
1591   LIR_Opr tmp1() const                           { return _tmp1;           }
1592   LIR_Opr tmp2() const                           { return _tmp2;           }
1593   LIR_Opr tmp3() const                           { return _tmp3;           }
1594   ciKlass* klass() const                         { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass;          }
1595   bool fast_check() const                        { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check;     }
1596   CodeEmitInfo* info_for_patch() const           { return _info_for_patch;  }
1597   CodeEmitInfo* info_for_exception() const       { return _info_for_exception; }
1598   CodeStub* stub() const                         { return _stub;           }
1599 
1600   // MethodData* profiling
1601   void set_profiled_method(ciMethod *method)     { _profiled_method = method; }
1602   void set_profiled_bci(int bci)                 { _profiled_bci = bci;       }
1603   void set_should_profile(bool b)                { _should_profile = b;       }
1604   ciMethod* profiled_method() const              { return _profiled_method;   }
1605   int       profiled_bci() const                 { return _profiled_bci;      }
1606   bool      should_profile() const               { return _should_profile;    }
1607 
1608   virtual bool is_patching() { return _info_for_patch != NULL; }
1609   virtual void emit_code(LIR_Assembler* masm);
1610   virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1611   void print_instr(outputStream* out) const PRODUCT_RETURN;
1612 };
1613 












































































1614 // LIR_Op2
1615 class LIR_Op2: public LIR_Op {
1616  friend class LIR_OpVisitState;
1617 
1618   int  _fpu_stack_size; // for sin/cos implementation on Intel
1619 
1620  protected:
1621   LIR_Opr   _opr1;
1622   LIR_Opr   _opr2;
1623   BasicType _type;
1624   LIR_Opr   _tmp1;
1625   LIR_Opr   _tmp2;
1626   LIR_Opr   _tmp3;
1627   LIR_Opr   _tmp4;
1628   LIR_Opr   _tmp5;
1629   LIR_Condition _condition;
1630 
1631   void verify() const;
1632 
1633  public:

1786 
1787 //--------------------------------
1788 class LabelObj: public CompilationResourceObj {
1789  private:
1790   Label _label;
1791  public:
1792   LabelObj()                                     {}
1793   Label* label()                                 { return &_label; }
1794 };
1795 
1796 
1797 class LIR_OpLock: public LIR_Op {
1798  friend class LIR_OpVisitState;
1799 
1800  private:
1801   LIR_Opr _hdr;
1802   LIR_Opr _obj;
1803   LIR_Opr _lock;
1804   LIR_Opr _scratch;
1805   CodeStub* _stub;

1806  public:
1807   LIR_OpLock(LIR_Code code, LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info)
1808     : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1809     , _hdr(hdr)
1810     , _obj(obj)
1811     , _lock(lock)
1812     , _scratch(scratch)
1813     , _stub(stub)                      {}

1814 
1815   LIR_Opr hdr_opr() const                        { return _hdr; }
1816   LIR_Opr obj_opr() const                        { return _obj; }
1817   LIR_Opr lock_opr() const                       { return _lock; }
1818   LIR_Opr scratch_opr() const                    { return _scratch; }
1819   CodeStub* stub() const                         { return _stub; }

1820 
1821   virtual void emit_code(LIR_Assembler* masm);
1822   virtual LIR_OpLock* as_OpLock() { return this; }
1823   void print_instr(outputStream* out) const PRODUCT_RETURN;
1824 };
1825 
1826 class LIR_OpLoadKlass: public LIR_Op {
1827   friend class LIR_OpVisitState;
1828 
1829  private:
1830   LIR_Opr _obj;
1831  public:
1832   LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
1833     : LIR_Op(lir_load_klass, result, info)
1834     , _obj(obj)
1835     {}
1836 
1837   LIR_Opr obj()        const { return _obj;  }
1838 
1839   virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }

1983     , _obj(obj)
1984     , _tmp(tmp)
1985     , _exact_klass(exact_klass)
1986     , _current_klass(current_klass)
1987     , _not_null(not_null)
1988     , _no_conflict(no_conflict) { }
1989 
1990   LIR_Opr      mdp()              const             { return _mdp;              }
1991   LIR_Opr      obj()              const             { return _obj;              }
1992   LIR_Opr      tmp()              const             { return _tmp;              }
1993   ciKlass*     exact_klass()      const             { return _exact_klass;      }
1994   intptr_t     current_klass()    const             { return _current_klass;    }
1995   bool         not_null()         const             { return _not_null;         }
1996   bool         no_conflict()      const             { return _no_conflict;      }
1997 
1998   virtual void emit_code(LIR_Assembler* masm);
1999   virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2000   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2001 };
2002 
































2003 class LIR_InsertionBuffer;
2004 
2005 //--------------------------------LIR_List---------------------------------------------------
2006 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2007 // The LIR instructions are appended by the LIR_List class itself;
2008 //
2009 // Notes:
2010 // - all offsets are(should be) in bytes
2011 // - local positions are specified with an offset, with offset 0 being local 0
2012 
2013 class LIR_List: public CompilationResourceObj {
2014  private:
2015   LIR_OpList  _operations;
2016 
2017   Compilation*  _compilation;
2018 #ifndef PRODUCT
2019   BlockBegin*   _block;
2020 #endif
2021 #ifdef ASSERT
2022   const char *  _file;

2240   void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2241 
2242   void shift_left(LIR_Opr value, int count, LIR_Opr dst)       { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2243   void shift_right(LIR_Opr value, int count, LIR_Opr dst)      { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2244   void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2245 
2246   void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst)        { append(new LIR_Op2(lir_cmp_l2i,  left, right, dst)); }
2247   void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2248 
2249   void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2250     append(new LIR_OpRTCall(routine, tmp, result, arguments));
2251   }
2252 
2253   void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2254                     LIR_OprList* arguments, CodeEmitInfo* info) {
2255     append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2256   }
2257 
2258   void load_stack_address_monitor(int monitor_ix, LIR_Opr dst)  { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2259   void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2260   void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info);
2261 
2262   void breakpoint()                                                  { append(new LIR_Op0(lir_breakpoint)); }
2263 
2264   void arraycopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info) { append(new LIR_OpArrayCopy(src, src_pos, dst, dst_pos, length, tmp, expected_type, flags, info)); }
2265 
2266   void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res)  { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2267 
2268   void instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci);
2269   void store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci);






2270 
2271   void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2272                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2273                   CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2274                   ciMethod* profiled_method, int profiled_bci);
2275   // MethodData* profiling
2276   void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2277     append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2278   }
2279   void profile_type(LIR_Address* mdp, LIR_Opr obj, ciKlass* exact_klass, intptr_t current_klass, LIR_Opr tmp, bool not_null, bool no_conflict) {
2280     append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2281   }



2282 
2283   void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2284   void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2285 
2286   void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2287 
2288 #ifdef ASSERT
2289   void lir_assert(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, const char* msg, bool halt) { append(new LIR_OpAssert(condition, opr1, opr2, msg, halt)); }
2290 #endif
2291 };
2292 
2293 void print_LIR(BlockList* blocks);
2294 
2295 class LIR_InsertionBuffer : public CompilationResourceObj {
2296  private:
2297   LIR_List*   _lir;   // the lir list where ops of this buffer should be inserted later (NULL when uninitialized)
2298 
2299   // list of insertion points. index and count are stored alternately:
2300   // _index_and_count[i * 2]:     the index into lir list where "count" ops should be inserted
2301   // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index

 319   friend BasicType as_BasicType(OprType t);
 320 
 321   OprType type_field_valid() const               { assert(is_register() || is_stack(), "should not be called otherwise"); return (OprType)(value() & type_mask); }
 322   OprType type_field() const                     { return is_illegal() ? unknown_type : (OprType)(value() & type_mask); }
 323 
 324   static OprSize size_for(BasicType t) {
 325     switch (t) {
 326       case T_LONG:
 327       case T_DOUBLE:
 328         return double_size;
 329         break;
 330 
 331       case T_FLOAT:
 332       case T_BOOLEAN:
 333       case T_CHAR:
 334       case T_BYTE:
 335       case T_SHORT:
 336       case T_INT:
 337       case T_ADDRESS:
 338       case T_OBJECT:
 339       case T_PRIMITIVE_OBJECT:
 340       case T_ARRAY:
 341       case T_METADATA:
 342         return single_size;
 343         break;
 344 
 345       default:
 346         ShouldNotReachHere();
 347         return single_size;
 348       }
 349   }
 350 
 351 
 352   void validate_type() const PRODUCT_RETURN;
 353 
 354   BasicType type() const {
 355     if (is_pointer()) {
 356       return pointer()->type();
 357     }
 358     return as_BasicType(type_field());
 359   }

 469   int fpu() const { return lo_reg_half(); }
 470 #endif
 471 
 472   jint      as_jint()    const { return as_constant_ptr()->as_jint(); }
 473   jlong     as_jlong()   const { return as_constant_ptr()->as_jlong(); }
 474   jfloat    as_jfloat()  const { return as_constant_ptr()->as_jfloat(); }
 475   jdouble   as_jdouble() const { return as_constant_ptr()->as_jdouble(); }
 476   jobject   as_jobject() const { return as_constant_ptr()->as_jobject(); }
 477 
 478   void print() const PRODUCT_RETURN;
 479   void print(outputStream* out) const PRODUCT_RETURN;
 480 };
 481 
 482 inline LIR_Opr::OprType as_OprType(BasicType type) {
 483   switch (type) {
 484   case T_INT:      return LIR_Opr::int_type;
 485   case T_LONG:     return LIR_Opr::long_type;
 486   case T_FLOAT:    return LIR_Opr::float_type;
 487   case T_DOUBLE:   return LIR_Opr::double_type;
 488   case T_OBJECT:
 489   case T_PRIMITIVE_OBJECT:
 490   case T_ARRAY:    return LIR_Opr::object_type;
 491   case T_ADDRESS:  return LIR_Opr::address_type;
 492   case T_METADATA: return LIR_Opr::metadata_type;
 493   case T_ILLEGAL:  // fall through
 494   default: ShouldNotReachHere(); return LIR_Opr::unknown_type;
 495   }
 496 }
 497 
 498 inline BasicType as_BasicType(LIR_Opr::OprType t) {
 499   switch (t) {
 500   case LIR_Opr::int_type:     return T_INT;
 501   case LIR_Opr::long_type:    return T_LONG;
 502   case LIR_Opr::float_type:   return T_FLOAT;
 503   case LIR_Opr::double_type:  return T_DOUBLE;
 504   case LIR_Opr::object_type:  return T_OBJECT;
 505   case LIR_Opr::address_type: return T_ADDRESS;
 506   case LIR_Opr::metadata_type:return T_METADATA;
 507   case LIR_Opr::unknown_type: // fall through
 508   default: ShouldNotReachHere();  return T_ILLEGAL;
 509   }

 661   }
 662   static LIR_Opr double_xmm(int reg) {
 663     return (LIR_Opr)(intptr_t)((reg << LIR_Opr::reg1_shift) |
 664                                (reg << LIR_Opr::reg2_shift) |
 665                                LIR_Opr::double_type         |
 666                                LIR_Opr::fpu_register        |
 667                                LIR_Opr::double_size         |
 668                                LIR_Opr::is_xmm_mask);
 669   }
 670 #endif // X86
 671 
 672   static LIR_Opr virtual_register(int index, BasicType type) {
 673     if (index > LIR_Opr::vreg_max) {
 674       // Running out of virtual registers. Caller should bailout.
 675       return illegalOpr;
 676     }
 677 
 678     LIR_Opr res;
 679     switch (type) {
 680       case T_OBJECT: // fall through
 681       case T_PRIMITIVE_OBJECT: // fall through
 682       case T_ARRAY:
 683         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift)  |
 684                                             LIR_Opr::object_type  |
 685                                             LIR_Opr::cpu_register |
 686                                             LIR_Opr::single_size  |
 687                                             LIR_Opr::virtual_mask);
 688         break;
 689 
 690       case T_METADATA:
 691         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift)  |
 692                                             LIR_Opr::metadata_type|
 693                                             LIR_Opr::cpu_register |
 694                                             LIR_Opr::single_size  |
 695                                             LIR_Opr::virtual_mask);
 696         break;
 697 
 698       case T_INT:
 699         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 700                                   LIR_Opr::int_type              |
 701                                   LIR_Opr::cpu_register          |

 767                                t |
 768                                LIR_Opr::cpu_register |
 769                                LIR_Opr::size_for(type) | LIR_Opr::virtual_mask);
 770 #else // __SOFTFP__
 771     LIR_Opr old_res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) | t |
 772                                           ((type == T_FLOAT || type == T_DOUBLE) ?  LIR_Opr::fpu_register : LIR_Opr::cpu_register) |
 773                                LIR_Opr::size_for(type) | LIR_Opr::virtual_mask);
 774     assert(res == old_res, "old and new method not equal");
 775 #endif // __SOFTFP__
 776 #endif // ASSERT
 777 
 778     return res;
 779   }
 780 
 781   // 'index' is computed by FrameMap::local_stack_pos(index); do not use other parameters as
 782   // the index is platform independent; a double stack useing indeces 2 and 3 has always
 783   // index 2.
 784   static LIR_Opr stack(int index, BasicType type) {
 785     LIR_Opr res;
 786     switch (type) {
 787       case T_PRIMITIVE_OBJECT: // fall through
 788       case T_OBJECT: // fall through
 789       case T_ARRAY:
 790         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 791                                   LIR_Opr::object_type           |
 792                                   LIR_Opr::stack_value           |
 793                                   LIR_Opr::single_size);
 794         break;
 795 
 796       case T_METADATA:
 797         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 798                                   LIR_Opr::metadata_type         |
 799                                   LIR_Opr::stack_value           |
 800                                   LIR_Opr::single_size);
 801         break;
 802       case T_INT:
 803         res = (LIR_Opr)(intptr_t)((index << LIR_Opr::data_shift) |
 804                                   LIR_Opr::int_type              |
 805                                   LIR_Opr::stack_value           |
 806                                   LIR_Opr::single_size);
 807         break;

 881 class  LIR_Op;
 882 class    LIR_Op0;
 883 class      LIR_OpLabel;
 884 class    LIR_Op1;
 885 class      LIR_OpBranch;
 886 class      LIR_OpConvert;
 887 class      LIR_OpAllocObj;
 888 class      LIR_OpReturn;
 889 class      LIR_OpRoundFP;
 890 class    LIR_Op2;
 891 class    LIR_OpDelay;
 892 class    LIR_Op3;
 893 class      LIR_OpAllocArray;
 894 class    LIR_OpCall;
 895 class      LIR_OpJavaCall;
 896 class      LIR_OpRTCall;
 897 class    LIR_OpArrayCopy;
 898 class    LIR_OpUpdateCRC32;
 899 class    LIR_OpLock;
 900 class    LIR_OpTypeCheck;
 901 class    LIR_OpFlattenedArrayCheck;
 902 class    LIR_OpNullFreeArrayCheck;
 903 class    LIR_OpSubstitutabilityCheck;
 904 class    LIR_OpCompareAndSwap;
 905 class    LIR_OpLoadKlass;
 906 class    LIR_OpProfileCall;
 907 class    LIR_OpProfileType;
 908 class    LIR_OpProfileInlineType;
 909 #ifdef ASSERT
 910 class    LIR_OpAssert;
 911 #endif
 912 
 913 // LIR operation codes
 914 enum LIR_Code {
 915     lir_none
 916   , begin_op0
 917       , lir_label
 918       , lir_nop
 919       , lir_std_entry
 920       , lir_osr_entry
 921       , lir_fpop_raw
 922       , lir_breakpoint
 923       , lir_rtcall
 924       , lir_membar
 925       , lir_membar_acquire
 926       , lir_membar_release
 927       , lir_membar_loadload
 928       , lir_membar_storestore
 929       , lir_membar_loadstore
 930       , lir_membar_storeload
 931       , lir_get_thread
 932       , lir_on_spin_wait
 933       , lir_check_orig_pc
 934   , end_op0
 935   , begin_op1
 936       , lir_fxch
 937       , lir_fld
 938       , lir_push
 939       , lir_pop
 940       , lir_null_check
 941       , lir_return
 942       , lir_leal
 943       , lir_branch
 944       , lir_cond_float_branch
 945       , lir_move
 946       , lir_convert
 947       , lir_alloc_object
 948       , lir_monaddr
 949       , lir_roundfp
 950       , lir_safepoint
 951       , lir_unwind
 952       , lir_load_klass
 953   , end_op1

 991       , lir_dynamic_call
 992   , end_opJavaCall
 993   , begin_opArrayCopy
 994       , lir_arraycopy
 995   , end_opArrayCopy
 996   , begin_opUpdateCRC32
 997       , lir_updatecrc32
 998   , end_opUpdateCRC32
 999   , begin_opLock
1000     , lir_lock
1001     , lir_unlock
1002   , end_opLock
1003   , begin_delay_slot
1004     , lir_delay_slot
1005   , end_delay_slot
1006   , begin_opTypeCheck
1007     , lir_instanceof
1008     , lir_checkcast
1009     , lir_store_check
1010   , end_opTypeCheck
1011   , begin_opFlattenedArrayCheck
1012     , lir_flattened_array_check
1013   , end_opFlattenedArrayCheck
1014   , begin_opNullFreeArrayCheck
1015     , lir_null_free_array_check
1016   , end_opNullFreeArrayCheck
1017   , begin_opSubstitutabilityCheck
1018     , lir_substitutability_check
1019   , end_opSubstitutabilityCheck
1020   , begin_opCompareAndSwap
1021     , lir_cas_long
1022     , lir_cas_obj
1023     , lir_cas_int
1024   , end_opCompareAndSwap
1025   , begin_opMDOProfile
1026     , lir_profile_call
1027     , lir_profile_type
1028     , lir_profile_inline_type
1029   , end_opMDOProfile
1030   , begin_opAssert
1031     , lir_assert
1032   , end_opAssert
1033 };
1034 
1035 
1036 enum LIR_Condition {
1037     lir_cond_equal
1038   , lir_cond_notEqual
1039   , lir_cond_less
1040   , lir_cond_lessEqual
1041   , lir_cond_greaterEqual
1042   , lir_cond_greater
1043   , lir_cond_belowEqual
1044   , lir_cond_aboveEqual
1045   , lir_cond_always
1046   , lir_cond_unknown = -1
1047 };
1048 

1151   virtual bool is_patching() { return false; }
1152   virtual LIR_OpCall* as_OpCall() { return NULL; }
1153   virtual LIR_OpJavaCall* as_OpJavaCall() { return NULL; }
1154   virtual LIR_OpLabel* as_OpLabel() { return NULL; }
1155   virtual LIR_OpDelay* as_OpDelay() { return NULL; }
1156   virtual LIR_OpLock* as_OpLock() { return NULL; }
1157   virtual LIR_OpAllocArray* as_OpAllocArray() { return NULL; }
1158   virtual LIR_OpAllocObj* as_OpAllocObj() { return NULL; }
1159   virtual LIR_OpRoundFP* as_OpRoundFP() { return NULL; }
1160   virtual LIR_OpBranch* as_OpBranch() { return NULL; }
1161   virtual LIR_OpReturn* as_OpReturn() { return NULL; }
1162   virtual LIR_OpRTCall* as_OpRTCall() { return NULL; }
1163   virtual LIR_OpConvert* as_OpConvert() { return NULL; }
1164   virtual LIR_Op0* as_Op0() { return NULL; }
1165   virtual LIR_Op1* as_Op1() { return NULL; }
1166   virtual LIR_Op2* as_Op2() { return NULL; }
1167   virtual LIR_Op3* as_Op3() { return NULL; }
1168   virtual LIR_OpArrayCopy* as_OpArrayCopy() { return NULL; }
1169   virtual LIR_OpUpdateCRC32* as_OpUpdateCRC32() { return NULL; }
1170   virtual LIR_OpTypeCheck* as_OpTypeCheck() { return NULL; }
1171   virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return NULL; }
1172   virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return NULL; }
1173   virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return NULL; }
1174   virtual LIR_OpCompareAndSwap* as_OpCompareAndSwap() { return NULL; }
1175   virtual LIR_OpLoadKlass* as_OpLoadKlass() { return NULL; }
1176   virtual LIR_OpProfileCall* as_OpProfileCall() { return NULL; }
1177   virtual LIR_OpProfileType* as_OpProfileType() { return NULL; }
1178   virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return NULL; }
1179 #ifdef ASSERT
1180   virtual LIR_OpAssert* as_OpAssert() { return NULL; }
1181 #endif
1182 
1183   virtual void verify() const {}
1184 };
1185 
1186 // for calls
1187 class LIR_OpCall: public LIR_Op {
1188  friend class LIR_OpVisitState;
1189 
1190  protected:
1191   address      _addr;
1192   LIR_OprList* _arguments;
1193  protected:
1194   LIR_OpCall(LIR_Code code, address addr, LIR_Opr result,
1195              LIR_OprList* arguments, CodeEmitInfo* info = NULL)
1196     : LIR_Op(code, result, info)
1197     , _addr(addr)
1198     , _arguments(arguments) {}

1231                  LIR_OprList* arguments, CodeEmitInfo* info)
1232   : LIR_OpCall(code, (address)vtable_offset, result, arguments, info)
1233   , _method(method)
1234   , _receiver(receiver)
1235   , _method_handle_invoke_SP_save_opr(LIR_OprFact::illegalOpr)
1236   { assert(is_in_range(code, begin_opJavaCall, end_opJavaCall), "code check"); }
1237 
1238   LIR_Opr receiver() const                       { return _receiver; }
1239   ciMethod* method() const                       { return _method;   }
1240 
1241   // JSR 292 support.
1242   bool is_invokedynamic() const                  { return code() == lir_dynamic_call; }
1243   bool is_method_handle_invoke() const {
1244     return method()->is_compiled_lambda_form() ||   // Java-generated lambda form
1245            method()->is_method_handle_intrinsic();  // JVM-generated MH intrinsic
1246   }
1247 
1248   virtual void emit_code(LIR_Assembler* masm);
1249   virtual LIR_OpJavaCall* as_OpJavaCall() { return this; }
1250   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1251 
1252   bool maybe_return_as_fields(ciInlineKlass** vk = NULL) const;
1253 };
1254 
1255 // --------------------------------------------------
1256 // LIR_OpLabel
1257 // --------------------------------------------------
1258 // Location where a branch can continue
1259 class LIR_OpLabel: public LIR_Op {
1260  friend class LIR_OpVisitState;
1261 
1262  private:
1263   Label* _label;
1264  public:
1265   LIR_OpLabel(Label* lbl)
1266    : LIR_Op(lir_label, LIR_OprFact::illegalOpr, NULL)
1267    , _label(lbl)                                 {}
1268   Label* label() const                           { return _label; }
1269 
1270   virtual void emit_code(LIR_Assembler* masm);
1271   virtual LIR_OpLabel* as_OpLabel() { return this; }
1272   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;

1284   LIR_Opr   _dst_pos;
1285   LIR_Opr   _length;
1286   LIR_Opr   _tmp;
1287   ciArrayKlass* _expected_type;
1288   int       _flags;
1289 
1290 public:
1291   enum Flags {
1292     src_null_check         = 1 << 0,
1293     dst_null_check         = 1 << 1,
1294     src_pos_positive_check = 1 << 2,
1295     dst_pos_positive_check = 1 << 3,
1296     length_positive_check  = 1 << 4,
1297     src_range_check        = 1 << 5,
1298     dst_range_check        = 1 << 6,
1299     type_check             = 1 << 7,
1300     overlapping            = 1 << 8,
1301     unaligned              = 1 << 9,
1302     src_objarray           = 1 << 10,
1303     dst_objarray           = 1 << 11,
1304     always_slow_path       = 1 << 12,
1305     src_inlinetype_check   = 1 << 13,
1306     dst_inlinetype_check   = 1 << 14,
1307     all_flags              = (1 << 15) - 1
1308   };
1309 
1310   LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp,
1311                   ciArrayKlass* expected_type, int flags, CodeEmitInfo* info);
1312 
1313   LIR_Opr src() const                            { return _src; }
1314   LIR_Opr src_pos() const                        { return _src_pos; }
1315   LIR_Opr dst() const                            { return _dst; }
1316   LIR_Opr dst_pos() const                        { return _dst_pos; }
1317   LIR_Opr length() const                         { return _length; }
1318   LIR_Opr tmp() const                            { return _tmp; }
1319   int flags() const                              { return _flags; }
1320   ciArrayKlass* expected_type() const            { return _expected_type; }
1321   ArrayCopyStub* stub() const                    { return _stub; }
1322 
1323   virtual void emit_code(LIR_Assembler* masm);
1324   virtual LIR_OpArrayCopy* as_OpArrayCopy() { return this; }
1325   void print_instr(outputStream* out) const PRODUCT_RETURN;
1326 };
1327 

1589 };
1590 
1591 // LIR_OpTypeCheck
1592 class LIR_OpTypeCheck: public LIR_Op {
1593  friend class LIR_OpVisitState;
1594 
1595  private:
1596   LIR_Opr       _object;
1597   LIR_Opr       _array;
1598   ciKlass*      _klass;
1599   LIR_Opr       _tmp1;
1600   LIR_Opr       _tmp2;
1601   LIR_Opr       _tmp3;
1602   bool          _fast_check;
1603   CodeEmitInfo* _info_for_patch;
1604   CodeEmitInfo* _info_for_exception;
1605   CodeStub*     _stub;
1606   ciMethod*     _profiled_method;
1607   int           _profiled_bci;
1608   bool          _should_profile;
1609   bool          _need_null_check;
1610 
1611 public:
1612   LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
1613                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1614                   CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub, bool need_null_check = true);
1615   LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array,
1616                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception);
1617 
1618   LIR_Opr object() const                         { return _object;         }
1619   LIR_Opr array() const                          { assert(code() == lir_store_check, "not valid"); return _array;         }
1620   LIR_Opr tmp1() const                           { return _tmp1;           }
1621   LIR_Opr tmp2() const                           { return _tmp2;           }
1622   LIR_Opr tmp3() const                           { return _tmp3;           }
1623   ciKlass* klass() const                         { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _klass;          }
1624   bool fast_check() const                        { assert(code() == lir_instanceof || code() == lir_checkcast, "not valid"); return _fast_check;     }
1625   CodeEmitInfo* info_for_patch() const           { return _info_for_patch;  }
1626   CodeEmitInfo* info_for_exception() const       { return _info_for_exception; }
1627   CodeStub* stub() const                         { return _stub;           }
1628 
1629   // MethodData* profiling
1630   void set_profiled_method(ciMethod *method)     { _profiled_method = method; }
1631   void set_profiled_bci(int bci)                 { _profiled_bci = bci;       }
1632   void set_should_profile(bool b)                { _should_profile = b;       }
1633   ciMethod* profiled_method() const              { return _profiled_method;   }
1634   int       profiled_bci() const                 { return _profiled_bci;      }
1635   bool      should_profile() const               { return _should_profile;    }
1636   bool      need_null_check() const              { return _need_null_check;   }
1637   virtual bool is_patching() { return _info_for_patch != NULL; }
1638   virtual void emit_code(LIR_Assembler* masm);
1639   virtual LIR_OpTypeCheck* as_OpTypeCheck() { return this; }
1640   void print_instr(outputStream* out) const PRODUCT_RETURN;
1641 };
1642 
1643 // LIR_OpFlattenedArrayCheck
1644 class LIR_OpFlattenedArrayCheck: public LIR_Op {
1645  friend class LIR_OpVisitState;
1646 
1647  private:
1648   LIR_Opr       _array;
1649   LIR_Opr       _value;
1650   LIR_Opr       _tmp;
1651   CodeStub*     _stub;
1652 public:
1653   LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
1654   LIR_Opr array() const                          { return _array;         }
1655   LIR_Opr value() const                          { return _value;         }
1656   LIR_Opr tmp() const                            { return _tmp;           }
1657   CodeStub* stub() const                         { return _stub;          }
1658 
1659   virtual void emit_code(LIR_Assembler* masm);
1660   virtual LIR_OpFlattenedArrayCheck* as_OpFlattenedArrayCheck() { return this; }
1661   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1662 };
1663 
1664 // LIR_OpNullFreeArrayCheck
1665 class LIR_OpNullFreeArrayCheck: public LIR_Op {
1666  friend class LIR_OpVisitState;
1667 
1668  private:
1669   LIR_Opr       _array;
1670   LIR_Opr       _tmp;
1671 public:
1672   LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp);
1673   LIR_Opr array() const                          { return _array;         }
1674   LIR_Opr tmp() const                            { return _tmp;           }
1675 
1676   virtual void emit_code(LIR_Assembler* masm);
1677   virtual LIR_OpNullFreeArrayCheck* as_OpNullFreeArrayCheck() { return this; }
1678   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1679 };
1680 
1681 class LIR_OpSubstitutabilityCheck: public LIR_Op {
1682  friend class LIR_OpVisitState;
1683 
1684  private:
1685   LIR_Opr       _left;
1686   LIR_Opr       _right;
1687   LIR_Opr       _equal_result;
1688   LIR_Opr       _not_equal_result;
1689   LIR_Opr       _tmp1;
1690   LIR_Opr       _tmp2;
1691   ciKlass*      _left_klass;
1692   ciKlass*      _right_klass;
1693   LIR_Opr       _left_klass_op;
1694   LIR_Opr       _right_klass_op;
1695   CodeStub*     _stub;
1696 public:
1697   LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
1698                               LIR_Opr tmp1, LIR_Opr tmp2,
1699                               ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
1700                               CodeEmitInfo* info, CodeStub* stub);
1701 
1702   LIR_Opr left() const             { return _left; }
1703   LIR_Opr right() const            { return _right; }
1704   LIR_Opr equal_result() const     { return _equal_result; }
1705   LIR_Opr not_equal_result() const { return _not_equal_result; }
1706   LIR_Opr tmp1() const             { return _tmp1; }
1707   LIR_Opr tmp2() const             { return _tmp2; }
1708   ciKlass* left_klass() const      { return _left_klass; }
1709   ciKlass* right_klass() const     { return _right_klass; }
1710   LIR_Opr left_klass_op() const    { return _left_klass_op; }
1711   LIR_Opr right_klass_op() const   { return _right_klass_op; }
1712   CodeStub* stub() const           { return _stub; }
1713 
1714   virtual void emit_code(LIR_Assembler* masm);
1715   virtual LIR_OpSubstitutabilityCheck* as_OpSubstitutabilityCheck() { return this; }
1716   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
1717 };
1718 
1719 // LIR_Op2
1720 class LIR_Op2: public LIR_Op {
1721  friend class LIR_OpVisitState;
1722 
1723   int  _fpu_stack_size; // for sin/cos implementation on Intel
1724 
1725  protected:
1726   LIR_Opr   _opr1;
1727   LIR_Opr   _opr2;
1728   BasicType _type;
1729   LIR_Opr   _tmp1;
1730   LIR_Opr   _tmp2;
1731   LIR_Opr   _tmp3;
1732   LIR_Opr   _tmp4;
1733   LIR_Opr   _tmp5;
1734   LIR_Condition _condition;
1735 
1736   void verify() const;
1737 
1738  public:

1891 
1892 //--------------------------------
1893 class LabelObj: public CompilationResourceObj {
1894  private:
1895   Label _label;
1896  public:
1897   LabelObj()                                     {}
1898   Label* label()                                 { return &_label; }
1899 };
1900 
1901 
1902 class LIR_OpLock: public LIR_Op {
1903  friend class LIR_OpVisitState;
1904 
1905  private:
1906   LIR_Opr _hdr;
1907   LIR_Opr _obj;
1908   LIR_Opr _lock;
1909   LIR_Opr _scratch;
1910   CodeStub* _stub;
1911   CodeStub* _throw_imse_stub;
1912  public:
1913   LIR_OpLock(LIR_Code code, LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_imse_stub=NULL)
1914     : LIR_Op(code, LIR_OprFact::illegalOpr, info)
1915     , _hdr(hdr)
1916     , _obj(obj)
1917     , _lock(lock)
1918     , _scratch(scratch)
1919     , _stub(stub)
1920     , _throw_imse_stub(throw_imse_stub)                    {}
1921 
1922   LIR_Opr hdr_opr() const                        { return _hdr; }
1923   LIR_Opr obj_opr() const                        { return _obj; }
1924   LIR_Opr lock_opr() const                       { return _lock; }
1925   LIR_Opr scratch_opr() const                    { return _scratch; }
1926   CodeStub* stub() const                         { return _stub; }
1927   CodeStub* throw_imse_stub() const              { return _throw_imse_stub; }
1928 
1929   virtual void emit_code(LIR_Assembler* masm);
1930   virtual LIR_OpLock* as_OpLock() { return this; }
1931   void print_instr(outputStream* out) const PRODUCT_RETURN;
1932 };
1933 
1934 class LIR_OpLoadKlass: public LIR_Op {
1935   friend class LIR_OpVisitState;
1936 
1937  private:
1938   LIR_Opr _obj;
1939  public:
1940   LIR_OpLoadKlass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info)
1941     : LIR_Op(lir_load_klass, result, info)
1942     , _obj(obj)
1943     {}
1944 
1945   LIR_Opr obj()        const { return _obj;  }
1946 
1947   virtual LIR_OpLoadKlass* as_OpLoadKlass() { return this; }

2091     , _obj(obj)
2092     , _tmp(tmp)
2093     , _exact_klass(exact_klass)
2094     , _current_klass(current_klass)
2095     , _not_null(not_null)
2096     , _no_conflict(no_conflict) { }
2097 
2098   LIR_Opr      mdp()              const             { return _mdp;              }
2099   LIR_Opr      obj()              const             { return _obj;              }
2100   LIR_Opr      tmp()              const             { return _tmp;              }
2101   ciKlass*     exact_klass()      const             { return _exact_klass;      }
2102   intptr_t     current_klass()    const             { return _current_klass;    }
2103   bool         not_null()         const             { return _not_null;         }
2104   bool         no_conflict()      const             { return _no_conflict;      }
2105 
2106   virtual void emit_code(LIR_Assembler* masm);
2107   virtual LIR_OpProfileType* as_OpProfileType() { return this; }
2108   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2109 };
2110 
2111 // LIR_OpProfileInlineType
2112 class LIR_OpProfileInlineType : public LIR_Op {
2113  friend class LIR_OpVisitState;
2114 
2115  private:
2116   LIR_Opr      _mdp;
2117   LIR_Opr      _obj;
2118   int          _flag;
2119   LIR_Opr      _tmp;
2120   bool         _not_null;      // true if we know statically that _obj cannot be null
2121 
2122  public:
2123   // Destroys recv
2124   LIR_OpProfileInlineType(LIR_Opr mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null)
2125     : LIR_Op(lir_profile_inline_type, LIR_OprFact::illegalOpr, NULL)  // no result, no info
2126     , _mdp(mdp)
2127     , _obj(obj)
2128     , _flag(flag)
2129     , _tmp(tmp)
2130     , _not_null(not_null) { }
2131 
2132   LIR_Opr      mdp()              const             { return _mdp;              }
2133   LIR_Opr      obj()              const             { return _obj;              }
2134   int          flag()             const             { return _flag;             }
2135   LIR_Opr      tmp()              const             { return _tmp;              }
2136   bool         not_null()         const             { return _not_null;         }
2137 
2138   virtual void emit_code(LIR_Assembler* masm);
2139   virtual LIR_OpProfileInlineType* as_OpProfileInlineType() { return this; }
2140   virtual void print_instr(outputStream* out) const PRODUCT_RETURN;
2141 };
2142 
2143 class LIR_InsertionBuffer;
2144 
2145 //--------------------------------LIR_List---------------------------------------------------
2146 // Maintains a list of LIR instructions (one instance of LIR_List per basic block)
2147 // The LIR instructions are appended by the LIR_List class itself;
2148 //
2149 // Notes:
2150 // - all offsets are(should be) in bytes
2151 // - local positions are specified with an offset, with offset 0 being local 0
2152 
2153 class LIR_List: public CompilationResourceObj {
2154  private:
2155   LIR_OpList  _operations;
2156 
2157   Compilation*  _compilation;
2158 #ifndef PRODUCT
2159   BlockBegin*   _block;
2160 #endif
2161 #ifdef ASSERT
2162   const char *  _file;

2380   void unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp);
2381 
2382   void shift_left(LIR_Opr value, int count, LIR_Opr dst)       { shift_left(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2383   void shift_right(LIR_Opr value, int count, LIR_Opr dst)      { shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2384   void unsigned_shift_right(LIR_Opr value, int count, LIR_Opr dst) { unsigned_shift_right(value, LIR_OprFact::intConst(count), dst, LIR_OprFact::illegalOpr); }
2385 
2386   void lcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst)        { append(new LIR_Op2(lir_cmp_l2i,  left, right, dst)); }
2387   void fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less);
2388 
2389   void call_runtime_leaf(address routine, LIR_Opr tmp, LIR_Opr result, LIR_OprList* arguments) {
2390     append(new LIR_OpRTCall(routine, tmp, result, arguments));
2391   }
2392 
2393   void call_runtime(address routine, LIR_Opr tmp, LIR_Opr result,
2394                     LIR_OprList* arguments, CodeEmitInfo* info) {
2395     append(new LIR_OpRTCall(routine, tmp, result, arguments, info));
2396   }
2397 
2398   void load_stack_address_monitor(int monitor_ix, LIR_Opr dst)  { append(new LIR_Op1(lir_monaddr, LIR_OprFact::intConst(monitor_ix), dst)); }
2399   void unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub);
2400   void lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_imse_stub=NULL);
2401 
2402   void breakpoint()                                                  { append(new LIR_Op0(lir_breakpoint)); }
2403 
2404   void arraycopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length, LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info) { append(new LIR_OpArrayCopy(src, src_pos, dst, dst_pos, length, tmp, expected_type, flags, info)); }
2405 
2406   void update_crc32(LIR_Opr crc, LIR_Opr val, LIR_Opr res)  { append(new LIR_OpUpdateCRC32(crc, val, res)); }
2407 
2408   void instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci);
2409   void store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci);
2410   void check_flattened_array(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub);
2411   void check_null_free_array(LIR_Opr array, LIR_Opr tmp);
2412   void substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
2413                               LIR_Opr tmp1, LIR_Opr tmp2,
2414                               ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
2415                               CodeEmitInfo* info, CodeStub* stub);
2416 
2417   void checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
2418                   LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
2419                   CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
2420                   ciMethod* profiled_method, int profiled_bci, bool is_null_free);
2421   // MethodData* profiling
2422   void profile_call(ciMethod* method, int bci, ciMethod* callee, LIR_Opr mdo, LIR_Opr recv, LIR_Opr t1, ciKlass* cha_klass) {
2423     append(new LIR_OpProfileCall(method, bci, callee, mdo, recv, t1, cha_klass));
2424   }
2425   void profile_type(LIR_Address* mdp, LIR_Opr obj, ciKlass* exact_klass, intptr_t current_klass, LIR_Opr tmp, bool not_null, bool no_conflict) {
2426     append(new LIR_OpProfileType(LIR_OprFact::address(mdp), obj, exact_klass, current_klass, tmp, not_null, no_conflict));
2427   }
2428   void profile_inline_type(LIR_Address* mdp, LIR_Opr obj, int flag, LIR_Opr tmp, bool not_null) {
2429     append(new LIR_OpProfileInlineType(LIR_OprFact::address(mdp), obj, flag, tmp, not_null));
2430   }
2431 
2432   void xadd(LIR_Opr src, LIR_Opr add, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xadd, src, add, res, tmp)); }
2433   void xchg(LIR_Opr src, LIR_Opr set, LIR_Opr res, LIR_Opr tmp) { append(new LIR_Op2(lir_xchg, src, set, res, tmp)); }
2434 
2435   void load_klass(LIR_Opr obj, LIR_Opr result, CodeEmitInfo* info) { append(new LIR_OpLoadKlass(obj, result, info)); }
2436 
2437 #ifdef ASSERT
2438   void lir_assert(LIR_Condition condition, LIR_Opr opr1, LIR_Opr opr2, const char* msg, bool halt) { append(new LIR_OpAssert(condition, opr1, opr2, msg, halt)); }
2439 #endif
2440 };
2441 
2442 void print_LIR(BlockList* blocks);
2443 
2444 class LIR_InsertionBuffer : public CompilationResourceObj {
2445  private:
2446   LIR_List*   _lir;   // the lir list where ops of this buffer should be inserted later (NULL when uninitialized)
2447 
2448   // list of insertion points. index and count are stored alternately:
2449   // _index_and_count[i * 2]:     the index into lir list where "count" ops should be inserted
2450   // _index_and_count[i * 2 + 1]: the number of ops to be inserted at index
< prev index next >