< prev index next >

src/hotspot/share/c1/c1_Instruction.hpp

Print this page

  55 class   AccessArray;
  56 class     ArrayLength;
  57 class     AccessIndexed;
  58 class       LoadIndexed;
  59 class       StoreIndexed;
  60 class   NegateOp;
  61 class   Op2;
  62 class     ArithmeticOp;
  63 class     ShiftOp;
  64 class     LogicOp;
  65 class     CompareOp;
  66 class     IfOp;
  67 class   Convert;
  68 class   NullCheck;
  69 class   TypeCast;
  70 class   OsrEntry;
  71 class   ExceptionObject;
  72 class   StateSplit;
  73 class     Invoke;
  74 class     NewInstance;

  75 class     NewArray;
  76 class       NewTypeArray;
  77 class       NewObjectArray;
  78 class       NewMultiArray;

  79 class     TypeCheck;
  80 class       CheckCast;
  81 class       InstanceOf;
  82 class     AccessMonitor;
  83 class       MonitorEnter;
  84 class       MonitorExit;
  85 class     Intrinsic;
  86 class     BlockBegin;
  87 class     BlockEnd;
  88 class       Goto;
  89 class       If;
  90 class       Switch;
  91 class         TableSwitch;
  92 class         LookupSwitch;
  93 class       Return;
  94 class       Throw;
  95 class       Base;
  96 class   RoundFP;
  97 class   UnsafeOp;
  98 class     UnsafeGet;
  99 class     UnsafePut;
 100 class     UnsafeGetAndSet;
 101 class   ProfileCall;
 102 class   ProfileReturnType;

 103 class   ProfileInvoke;
 104 class   RuntimeCall;
 105 class   MemBar;
 106 class   RangeCheckPredicate;
 107 #ifdef ASSERT
 108 class   Assert;
 109 #endif
 110 
 111 // A Value is a reference to the instruction creating the value
 112 typedef Instruction* Value;
 113 typedef GrowableArray<Value> Values;
 114 typedef GrowableArray<ValueStack*> ValueStackStack;
 115 
 116 // BlockClosure is the base class for block traversal/iteration.
 117 
 118 class BlockClosure: public CompilationResourceObj {
 119  public:
 120   virtual void block_do(BlockBegin* block)       = 0;
 121 };
 122 

 155  public:
 156   virtual void do_Phi            (Phi*             x) = 0;
 157   virtual void do_Local          (Local*           x) = 0;
 158   virtual void do_Constant       (Constant*        x) = 0;
 159   virtual void do_LoadField      (LoadField*       x) = 0;
 160   virtual void do_StoreField     (StoreField*      x) = 0;
 161   virtual void do_ArrayLength    (ArrayLength*     x) = 0;
 162   virtual void do_LoadIndexed    (LoadIndexed*     x) = 0;
 163   virtual void do_StoreIndexed   (StoreIndexed*    x) = 0;
 164   virtual void do_NegateOp       (NegateOp*        x) = 0;
 165   virtual void do_ArithmeticOp   (ArithmeticOp*    x) = 0;
 166   virtual void do_ShiftOp        (ShiftOp*         x) = 0;
 167   virtual void do_LogicOp        (LogicOp*         x) = 0;
 168   virtual void do_CompareOp      (CompareOp*       x) = 0;
 169   virtual void do_IfOp           (IfOp*            x) = 0;
 170   virtual void do_Convert        (Convert*         x) = 0;
 171   virtual void do_NullCheck      (NullCheck*       x) = 0;
 172   virtual void do_TypeCast       (TypeCast*        x) = 0;
 173   virtual void do_Invoke         (Invoke*          x) = 0;
 174   virtual void do_NewInstance    (NewInstance*     x) = 0;

 175   virtual void do_NewTypeArray   (NewTypeArray*    x) = 0;
 176   virtual void do_NewObjectArray (NewObjectArray*  x) = 0;
 177   virtual void do_NewMultiArray  (NewMultiArray*   x) = 0;

 178   virtual void do_CheckCast      (CheckCast*       x) = 0;
 179   virtual void do_InstanceOf     (InstanceOf*      x) = 0;
 180   virtual void do_MonitorEnter   (MonitorEnter*    x) = 0;
 181   virtual void do_MonitorExit    (MonitorExit*     x) = 0;
 182   virtual void do_Intrinsic      (Intrinsic*       x) = 0;
 183   virtual void do_BlockBegin     (BlockBegin*      x) = 0;
 184   virtual void do_Goto           (Goto*            x) = 0;
 185   virtual void do_If             (If*              x) = 0;
 186   virtual void do_TableSwitch    (TableSwitch*     x) = 0;
 187   virtual void do_LookupSwitch   (LookupSwitch*    x) = 0;
 188   virtual void do_Return         (Return*          x) = 0;
 189   virtual void do_Throw          (Throw*           x) = 0;
 190   virtual void do_Base           (Base*            x) = 0;
 191   virtual void do_OsrEntry       (OsrEntry*        x) = 0;
 192   virtual void do_ExceptionObject(ExceptionObject* x) = 0;
 193   virtual void do_RoundFP        (RoundFP*         x) = 0;
 194   virtual void do_UnsafeGet      (UnsafeGet*       x) = 0;
 195   virtual void do_UnsafePut      (UnsafePut*       x) = 0;
 196   virtual void do_UnsafeGetAndSet(UnsafeGetAndSet* x) = 0;
 197   virtual void do_ProfileCall    (ProfileCall*     x) = 0;
 198   virtual void do_ProfileReturnType (ProfileReturnType*  x) = 0;

 199   virtual void do_ProfileInvoke  (ProfileInvoke*   x) = 0;
 200   virtual void do_RuntimeCall    (RuntimeCall*     x) = 0;
 201   virtual void do_MemBar         (MemBar*          x) = 0;
 202   virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0;
 203 #ifdef ASSERT
 204   virtual void do_Assert         (Assert*          x) = 0;
 205 #endif
 206 };
 207 
 208 
 209 // Hashing support
 210 //
 211 // Note: This hash functions affect the performance
 212 //       of ValueMap - make changes carefully!
 213 
 214 #define HASH1(x1            )                    ((intx)(x1))
 215 #define HASH2(x1, x2        )                    ((HASH1(x1        ) << 7) ^ HASH1(x2))
 216 #define HASH3(x1, x2, x3    )                    ((HASH2(x1, x2    ) << 7) ^ HASH1(x3))
 217 #define HASH4(x1, x2, x3, x4)                    ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))

 218 
 219 
 220 // The following macros are used to implement instruction-specific hashing.
 221 // By default, each instruction implements hash() and is_equal(Value), used
 222 // for value numbering/common subexpression elimination. The default imple-
 223 // mentation disables value numbering. Each instruction which can be value-
 224 // numbered, should define corresponding hash() and is_equal(Value) functions
 225 // via the macros below. The f arguments specify all the values/op codes, etc.
 226 // that need to be identical for two instructions to be identical.
 227 //
 228 // Note: The default implementation of hash() returns 0 in order to indicate
 229 //       that the instruction should not be considered for value numbering.
 230 //       The currently used hash functions do not guarantee that never a 0
 231 //       is produced. While this is still correct, it may be a performance
 232 //       bug (no value numbering for that node). However, this situation is
 233 //       so unlikely, that we are not going to handle it specially.
 234 
 235 #define HASHING1(class_name, enabled, f1)             \
 236   virtual intx hash() const {                         \
 237     return (enabled) ? HASH2(name(), f1) : 0;         \

 256     if (f1 != _v->f1) return false;                   \
 257     if (f2 != _v->f2) return false;                   \
 258     return true;                                      \
 259   }                                                   \
 260 
 261 
 262 #define HASHING3(class_name, enabled, f1, f2, f3)     \
 263   virtual intx hash() const {                         \
 264     return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
 265   }                                                   \
 266   virtual bool is_equal(Value v) const {              \
 267     if (!(enabled)  ) return false;                   \
 268     class_name* _v = v->as_##class_name();            \
 269     if (_v == NULL  ) return false;                   \
 270     if (f1 != _v->f1) return false;                   \
 271     if (f2 != _v->f2) return false;                   \
 272     if (f3 != _v->f3) return false;                   \
 273     return true;                                      \
 274   }                                                   \
 275 















 276 
 277 // The mother of all instructions...
 278 
 279 class Instruction: public CompilationResourceObj {
 280  private:
 281   int          _id;                              // the unique instruction id
 282 #ifndef PRODUCT
 283   int          _printable_bci;                   // the bci of the instruction for printing
 284 #endif
 285   int          _use_count;                       // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1
 286   int          _pin_state;                       // set of PinReason describing the reason for pinning
 287   ValueType*   _type;                            // the instruction value type
 288   Instruction* _next;                            // the next instruction if any (NULL for BlockEnd instructions)
 289   Instruction* _subst;                           // the substitution instruction if any
 290   LIR_Opr      _operand;                         // LIR specific information
 291   unsigned int _flags;                           // Flag bits
 292 
 293   ValueStack*  _state_before;                    // Copy of state with input operands still on stack (or NULL)
 294   ValueStack*  _exception_state;                 // Copy of state for exception handling
 295   XHandlers*   _exception_handlers;              // Flat list of exception handlers covering this instruction
 296 
 297   friend class UseCountComputer;

 298 
 299   void update_exception_state(ValueStack* state);
 300 
 301  protected:
 302   BlockBegin*  _block;                           // Block that contains this instruction
 303 
 304   void set_type(ValueType* type) {
 305     assert(type != NULL, "type must exist");
 306     _type = type;
 307   }
 308 
 309   // Helper class to keep track of which arguments need a null check
 310   class ArgsNonNullState {
 311   private:
 312     int _nonnull_state; // mask identifying which args are nonnull
 313   public:
 314     ArgsNonNullState()
 315       : _nonnull_state(AllBits) {}
 316 
 317     // Does argument number i needs a null check?

 330         if (check) {
 331           _nonnull_state |= nth_bit(i);
 332         } else {
 333           _nonnull_state &= ~(nth_bit(i));
 334         }
 335       }
 336     }
 337   };
 338 
 339  public:
 340   void* operator new(size_t size) throw() {
 341     Compilation* c = Compilation::current();
 342     void* res = c->arena()->Amalloc(size);
 343     return res;
 344   }
 345 
 346   static const int no_bci = -99;
 347 
 348   enum InstructionFlag {
 349     NeedsNullCheckFlag = 0,

 350     CanTrapFlag,
 351     DirectCompareFlag,
 352     IsEliminatedFlag,
 353     IsSafepointFlag,
 354     IsStaticFlag,
 355     NeedsStoreCheckFlag,
 356     NeedsWriteBarrierFlag,
 357     PreservesStateFlag,
 358     TargetIsFinalFlag,
 359     TargetIsLoadedFlag,
 360     UnorderedIsTrueFlag,
 361     NeedsPatchingFlag,
 362     ThrowIncompatibleClassChangeErrorFlag,
 363     InvokeSpecialReceiverCheckFlag,
 364     ProfileMDOFlag,
 365     IsLinkedInBlockFlag,
 366     NeedsRangeCheckFlag,
 367     InWorkListFlag,
 368     DeoptimizeOnException,
 369     InstructionLastFlag

 422   int id() const                                 { return _id; }
 423 #ifndef PRODUCT
 424   bool has_printable_bci() const                 { return _printable_bci != -99; }
 425   int printable_bci() const                      { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
 426   void set_printable_bci(int bci)                { _printable_bci = bci; }
 427 #endif
 428   int dominator_depth();
 429   int use_count() const                          { return _use_count; }
 430   int pin_state() const                          { return _pin_state; }
 431   bool is_pinned() const                         { return _pin_state != 0 || PinAllInstructions; }
 432   ValueType* type() const                        { return _type; }
 433   BlockBegin *block() const                      { return _block; }
 434   Instruction* prev();                           // use carefully, expensive operation
 435   Instruction* next() const                      { return _next; }
 436   bool has_subst() const                         { return _subst != NULL; }
 437   Instruction* subst()                           { return _subst == NULL ? this : _subst->subst(); }
 438   LIR_Opr operand() const                        { return _operand; }
 439 
 440   void set_needs_null_check(bool f)              { set_flag(NeedsNullCheckFlag, f); }
 441   bool needs_null_check() const                  { return check_flag(NeedsNullCheckFlag); }


 442   bool is_linked() const                         { return check_flag(IsLinkedInBlockFlag); }
 443   bool can_be_linked()                           { return as_Local() == NULL && as_Phi() == NULL; }
 444 
 445   bool is_null_obj()                             { return as_Constant() != NULL && type()->as_ObjectType()->constant_value()->is_null_object(); }
 446 
 447   bool has_uses() const                          { return use_count() > 0; }
 448   ValueStack* state_before() const               { return _state_before; }
 449   ValueStack* exception_state() const            { return _exception_state; }
 450   virtual bool needs_exception_state() const     { return true; }
 451   XHandlers* exception_handlers() const          { return _exception_handlers; }

 452 
 453   // manipulation
 454   void pin(PinReason reason)                     { _pin_state |= reason; }
 455   void pin()                                     { _pin_state |= PinUnknown; }
 456   // DANGEROUS: only used by EliminateStores
 457   void unpin(PinReason reason)                   { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
 458 
 459   Instruction* set_next(Instruction* next) {
 460     assert(next->has_printable_bci(), "_printable_bci should have been set");
 461     assert(next != NULL, "must not be NULL");
 462     assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");
 463     assert(next->can_be_linked(), "shouldn't link these instructions into list");
 464 
 465     BlockBegin *block = this->block();
 466     next->_block = block;
 467 
 468     next->set_flag(Instruction::IsLinkedInBlockFlag, true);
 469     _next = next;
 470     return next;
 471   }

 476 #endif
 477     return set_next(next);
 478   }
 479 
 480   // when blocks are merged
 481   void fixup_block_pointers() {
 482     Instruction *cur = next()->next(); // next()'s block is set in set_next
 483     while (cur && cur->_block != block()) {
 484       cur->_block = block();
 485       cur = cur->next();
 486     }
 487   }
 488 
 489   Instruction *insert_after(Instruction *i) {
 490     Instruction* n = _next;
 491     set_next(i);
 492     i->set_next(n);
 493     return _next;
 494   }
 495 




 496   Instruction *insert_after_same_bci(Instruction *i) {
 497 #ifndef PRODUCT
 498     i->set_printable_bci(printable_bci());
 499 #endif
 500     return insert_after(i);
 501   }
 502 
 503   void set_subst(Instruction* subst)             {
 504     assert(subst == NULL ||
 505            type()->base() == subst->type()->base() ||
 506            subst->type()->base() == illegalType, "type can't change");
 507     _subst = subst;
 508   }
 509   void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
 510   void set_exception_state(ValueStack* s)        { check_state(s); _exception_state = s; }
 511   void set_state_before(ValueStack* s)           { check_state(s); _state_before = s; }
 512 
 513   // machine-specifics
 514   void set_operand(LIR_Opr operand)              { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
 515   void clear_operand()                           { _operand = LIR_OprFact::illegalOpr; }

 523   virtual LoadField*        as_LoadField()       { return NULL; }
 524   virtual StoreField*       as_StoreField()      { return NULL; }
 525   virtual AccessArray*      as_AccessArray()     { return NULL; }
 526   virtual ArrayLength*      as_ArrayLength()     { return NULL; }
 527   virtual AccessIndexed*    as_AccessIndexed()   { return NULL; }
 528   virtual LoadIndexed*      as_LoadIndexed()     { return NULL; }
 529   virtual StoreIndexed*     as_StoreIndexed()    { return NULL; }
 530   virtual NegateOp*         as_NegateOp()        { return NULL; }
 531   virtual Op2*              as_Op2()             { return NULL; }
 532   virtual ArithmeticOp*     as_ArithmeticOp()    { return NULL; }
 533   virtual ShiftOp*          as_ShiftOp()         { return NULL; }
 534   virtual LogicOp*          as_LogicOp()         { return NULL; }
 535   virtual CompareOp*        as_CompareOp()       { return NULL; }
 536   virtual IfOp*             as_IfOp()            { return NULL; }
 537   virtual Convert*          as_Convert()         { return NULL; }
 538   virtual NullCheck*        as_NullCheck()       { return NULL; }
 539   virtual OsrEntry*         as_OsrEntry()        { return NULL; }
 540   virtual StateSplit*       as_StateSplit()      { return NULL; }
 541   virtual Invoke*           as_Invoke()          { return NULL; }
 542   virtual NewInstance*      as_NewInstance()     { return NULL; }

 543   virtual NewArray*         as_NewArray()        { return NULL; }
 544   virtual NewTypeArray*     as_NewTypeArray()    { return NULL; }
 545   virtual NewObjectArray*   as_NewObjectArray()  { return NULL; }
 546   virtual NewMultiArray*    as_NewMultiArray()   { return NULL; }

 547   virtual TypeCheck*        as_TypeCheck()       { return NULL; }
 548   virtual CheckCast*        as_CheckCast()       { return NULL; }
 549   virtual InstanceOf*       as_InstanceOf()      { return NULL; }
 550   virtual TypeCast*         as_TypeCast()        { return NULL; }
 551   virtual AccessMonitor*    as_AccessMonitor()   { return NULL; }
 552   virtual MonitorEnter*     as_MonitorEnter()    { return NULL; }
 553   virtual MonitorExit*      as_MonitorExit()     { return NULL; }
 554   virtual Intrinsic*        as_Intrinsic()       { return NULL; }
 555   virtual BlockBegin*       as_BlockBegin()      { return NULL; }
 556   virtual BlockEnd*         as_BlockEnd()        { return NULL; }
 557   virtual Goto*             as_Goto()            { return NULL; }
 558   virtual If*               as_If()              { return NULL; }
 559   virtual TableSwitch*      as_TableSwitch()     { return NULL; }
 560   virtual LookupSwitch*     as_LookupSwitch()    { return NULL; }
 561   virtual Return*           as_Return()          { return NULL; }
 562   virtual Throw*            as_Throw()           { return NULL; }
 563   virtual Base*             as_Base()            { return NULL; }
 564   virtual RoundFP*          as_RoundFP()         { return NULL; }
 565   virtual ExceptionObject*  as_ExceptionObject() { return NULL; }
 566   virtual UnsafeOp*         as_UnsafeOp()        { return NULL; }

 675   }
 676 
 677   bool is_illegal() const {
 678     return type()->is_illegal();
 679   }
 680 
 681   // generic
 682   virtual void input_values_do(ValueVisitor* f) {
 683   }
 684 };
 685 
 686 
 687 // A local is a placeholder for an incoming argument to a function call.
 688 LEAF(Local, Instruction)
 689  private:
 690   int      _java_index;                          // the local index within the method to which the local belongs
 691   bool     _is_receiver;                         // if local variable holds the receiver: "this" for non-static methods
 692   ciType*  _declared_type;
 693  public:
 694   // creation
 695   Local(ciType* declared, ValueType* type, int index, bool receiver)
 696     : Instruction(type)
 697     , _java_index(index)
 698     , _is_receiver(receiver)
 699     , _declared_type(declared)
 700   {

 701     NOT_PRODUCT(set_printable_bci(-1));
 702   }
 703 
 704   // accessors
 705   int java_index() const                         { return _java_index; }
 706   bool is_receiver() const                       { return _is_receiver; }
 707 
 708   virtual ciType* declared_type() const          { return _declared_type; }
 709 
 710   // generic
 711   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
 712 };
 713 
 714 
 715 LEAF(Constant, Instruction)
 716  public:
 717   // creation
 718   Constant(ValueType* type):
 719       Instruction(type, NULL, /*type_is_constant*/ true)
 720   {

 800 
 801   // manipulation
 802 
 803   // Under certain circumstances, if a previous NullCheck instruction
 804   // proved the target object non-null, we can eliminate the explicit
 805   // null check and do an implicit one, simply specifying the debug
 806   // information from the NullCheck. This field should only be consulted
 807   // if needs_null_check() is true.
 808   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 809 
 810   // generic
 811   virtual bool can_trap() const                  { return needs_null_check() || needs_patching(); }
 812   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_obj); }
 813 };
 814 
 815 
 816 LEAF(LoadField, AccessField)
 817  public:
 818   // creation
 819   LoadField(Value obj, int offset, ciField* field, bool is_static,
 820             ValueStack* state_before, bool needs_patching)

 821   : AccessField(obj, offset, field, is_static, state_before, needs_patching)
 822   {}


 823 
 824   ciType* declared_type() const;
 825 
 826   // generic; cannot be eliminated if needs patching or if volatile.
 827   HASHING3(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset(), declared_type())
 828 };
 829 
 830 
 831 LEAF(StoreField, AccessField)
 832  private:
 833   Value _value;

 834 
 835  public:
 836   // creation
 837   StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
 838              ValueStack* state_before, bool needs_patching)
 839   : AccessField(obj, offset, field, is_static, state_before, needs_patching)
 840   , _value(value)
 841   {
 842     set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
 843     ASSERT_VALUES
 844     pin();
 845   }
 846 
 847   // accessors
 848   Value value() const                            { return _value; }
 849   bool needs_write_barrier() const               { return check_flag(NeedsWriteBarrierFlag); }


 850 
 851   // generic
 852   virtual void input_values_do(ValueVisitor* f)   { AccessField::input_values_do(f); f->visit(&_value); }
 853 };
 854 
 855 
 856 BASE(AccessArray, Instruction)
 857  private:
 858   Value       _array;
 859 
 860  public:
 861   // creation
 862   AccessArray(ValueType* type, Value array, ValueStack* state_before)
 863   : Instruction(type, state_before)
 864   , _array(array)
 865   {
 866     set_needs_null_check(true);
 867     ASSERT_VALUES
 868     pin(); // instruction with side effect (null exception or range check throwing)
 869   }

 887   , _explicit_null_check(NULL) {}
 888 
 889   // accessors
 890   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 891 
 892   // setters
 893   // See LoadField::set_explicit_null_check for documentation
 894   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 895 
 896   // generic
 897   HASHING1(ArrayLength, true, array()->subst())
 898 };
 899 
 900 
 901 BASE(AccessIndexed, AccessArray)
 902  private:
 903   Value     _index;
 904   Value     _length;
 905   BasicType _elt_type;
 906   bool      _mismatched;


 907 
 908  public:
 909   // creation
 910   AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched)
 911   : AccessArray(as_ValueType(elt_type), array, state_before)
 912   , _index(index)
 913   , _length(length)
 914   , _elt_type(elt_type)
 915   , _mismatched(mismatched)

 916   {
 917     set_flag(Instruction::NeedsRangeCheckFlag, true);
 918     ASSERT_VALUES
 919   }
 920 
 921   // accessors
 922   Value index() const                            { return _index; }
 923   Value length() const                           { return _length; }
 924   BasicType elt_type() const                     { return _elt_type; }
 925   bool mismatched() const                        { return _mismatched; }
 926 
 927   void clear_length()                            { _length = NULL; }
 928   // perform elimination of range checks involving constants
 929   bool compute_needs_range_check();
 930 
 931   // generic









 932   virtual void input_values_do(ValueVisitor* f)   { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }
 933 };
 934 

 935 
 936 LEAF(LoadIndexed, AccessIndexed)
 937  private:
 938   NullCheck*  _explicit_null_check;              // For explicit null check elimination


 939 
 940  public:
 941   // creation
 942   LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched = false)
 943   : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
 944   , _explicit_null_check(NULL) {}
 945 
 946   // accessors
 947   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 948 
 949   // setters
 950   // See LoadField::set_explicit_null_check for documentation
 951   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 952 
 953   ciType* exact_type() const;
 954   ciType* declared_type() const;
 955 
 956   // generic;
 957   HASHING3(LoadIndexed, true, type()->tag(), array()->subst(), index()->subst())






 958 };
 959 























 960 
 961 LEAF(StoreIndexed, AccessIndexed)
 962  private:
 963   Value       _value;
 964 
 965   ciMethod* _profiled_method;
 966   int       _profiled_bci;
 967   bool      _check_boolean;
 968 
 969  public:
 970   // creation
 971   StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before,
 972                bool check_boolean, bool mismatched = false)
 973   : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
 974   , _value(value), _profiled_method(NULL), _profiled_bci(0), _check_boolean(check_boolean)
 975   {
 976     set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
 977     set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
 978     ASSERT_VALUES
 979     pin();
 980   }
 981 
 982   // accessors
 983   Value value() const                            { return _value; }
 984   bool needs_write_barrier() const               { return check_flag(NeedsWriteBarrierFlag); }
 985   bool needs_store_check() const                 { return check_flag(NeedsStoreCheckFlag); }
 986   bool check_boolean() const                     { return _check_boolean; }
 987   // Helpers for MethodData* profiling
 988   void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
 989   void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
 990   void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
 991   bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
 992   ciMethod* profiled_method() const                  { return _profiled_method;     }
 993   int       profiled_bci() const                     { return _profiled_bci;        }
 994   // generic
 995   virtual void input_values_do(ValueVisitor* f)   { AccessIndexed::input_values_do(f); f->visit(&_value); }
 996 };
 997 
 998 
 999 LEAF(NegateOp, Instruction)
1000  private:
1001   Value _x;
1002 
1003  public:
1004   // creation
1005   NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
1006     ASSERT_VALUES
1007   }
1008 
1009   // accessors
1010   Value x() const                                { return _x; }
1011 
1012   // generic
1013   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_x); }

1084   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1085 };
1086 
1087 
1088 LEAF(CompareOp, Op2)
1089  public:
1090   // creation
1091   CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1092   : Op2(intType, op, x, y, state_before)
1093   {}
1094 
1095   // generic
1096   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1097 };
1098 
1099 
1100 LEAF(IfOp, Op2)
1101  private:
1102   Value _tval;
1103   Value _fval;

1104 
1105  public:
1106   // creation
1107   IfOp(Value x, Condition cond, Value y, Value tval, Value fval)
1108   : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1109   , _tval(tval)
1110   , _fval(fval)

1111   {
1112     ASSERT_VALUES
1113     assert(tval->type()->tag() == fval->type()->tag(), "types must match");

1114   }
1115 
1116   // accessors
1117   virtual bool is_commutative() const;
1118   Bytecodes::Code op() const                     { ShouldNotCallThis(); return Bytecodes::_illegal; }
1119   Condition cond() const                         { return (Condition)Op2::op(); }
1120   Value tval() const                             { return _tval; }
1121   Value fval() const                             { return _fval; }
1122 
1123   // generic
1124   virtual void input_values_do(ValueVisitor* f)   { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1125 };
1126 
1127 
1128 LEAF(Convert, Instruction)
1129  private:
1130   Bytecodes::Code _op;
1131   Value           _value;
1132 
1133  public:
1134   // creation
1135   Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1136     ASSERT_VALUES
1137   }
1138 
1139   // accessors
1140   Bytecodes::Code op() const                     { return _op; }
1141   Value value() const                            { return _value; }
1142 

1221   // manipulation
1222   void set_state(ValueStack* state)              { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }
1223 
1224   // generic
1225   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
1226   virtual void state_values_do(ValueVisitor* f);
1227 };
1228 
1229 
1230 LEAF(Invoke, StateSplit)
1231  private:
1232   Bytecodes::Code _code;
1233   Value           _recv;
1234   Values*         _args;
1235   BasicTypeList*  _signature;
1236   ciMethod*       _target;
1237 
1238  public:
1239   // creation
1240   Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1241          ciMethod* target, ValueStack* state_before);
1242 
1243   // accessors
1244   Bytecodes::Code code() const                   { return _code; }
1245   Value receiver() const                         { return _recv; }
1246   bool has_receiver() const                      { return receiver() != NULL; }
1247   int number_of_arguments() const                { return _args->length(); }
1248   Value argument_at(int i) const                 { return _args->at(i); }
1249   BasicTypeList* signature() const               { return _signature; }
1250   ciMethod* target() const                       { return _target; }
1251 
1252   ciType* declared_type() const;
1253 
1254   // Returns false if target is not loaded
1255   bool target_is_final() const                   { return check_flag(TargetIsFinalFlag); }
1256   bool target_is_loaded() const                  { return check_flag(TargetIsLoadedFlag); }
1257 
1258   // JSR 292 support
1259   bool is_invokedynamic() const                  { return code() == Bytecodes::_invokedynamic; }
1260   bool is_method_handle_intrinsic() const        { return target()->is_method_handle_intrinsic(); }
1261 

1279 
1280  public:
1281   // creation
1282   NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved)
1283   : StateSplit(instanceType, state_before)
1284   , _klass(klass), _is_unresolved(is_unresolved)
1285   {}
1286 
1287   // accessors
1288   ciInstanceKlass* klass() const                 { return _klass; }
1289   bool is_unresolved() const                     { return _is_unresolved; }
1290 
1291   virtual bool needs_exception_state() const     { return false; }
1292 
1293   // generic
1294   virtual bool can_trap() const                  { return true; }
1295   ciType* exact_type() const;
1296   ciType* declared_type() const;
1297 };
1298 
















































1299 
1300 BASE(NewArray, StateSplit)
1301  private:
1302   Value       _length;
1303 
1304  public:
1305   // creation
1306   NewArray(Value length, ValueStack* state_before)
1307   : StateSplit(objectType, state_before)
1308   , _length(length)
1309   {
1310     // Do not ASSERT_VALUES since length is NULL for NewMultiArray
1311   }
1312 
1313   // accessors
1314   Value length() const                           { return _length; }
1315 
1316   virtual bool needs_exception_state() const     { return false; }
1317 
1318   ciType* exact_type() const                     { return NULL; }

1330 
1331  public:
1332   // creation
1333   NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)
1334   : NewArray(length, state_before)
1335   , _elt_type(elt_type)
1336   {}
1337 
1338   // accessors
1339   BasicType elt_type() const                     { return _elt_type; }
1340   ciType* exact_type() const;
1341 };
1342 
1343 
1344 LEAF(NewObjectArray, NewArray)
1345  private:
1346   ciKlass* _klass;
1347 
1348  public:
1349   // creation
1350   NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}



1351 
1352   // accessors
1353   ciKlass* klass() const                         { return _klass; }
1354   ciType* exact_type() const;
1355 };
1356 
1357 
1358 LEAF(NewMultiArray, NewArray)
1359  private:
1360   ciKlass* _klass;
1361   Values*  _dims;
1362 
1363  public:
1364   // creation
1365   NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
1366     ASSERT_VALUES
1367   }
1368 
1369   // accessors
1370   ciKlass* klass() const                         { return _klass; }
1371   Values* dims() const                           { return _dims; }
1372   int rank() const                               { return dims()->length(); }
1373 
1374   // generic
1375   virtual void input_values_do(ValueVisitor* f) {
1376     // NOTE: we do not call NewArray::input_values_do since "length"
1377     // is meaningless for a multi-dimensional array; passing the
1378     // zeroth element down to NewArray as its length is a bad idea
1379     // since there will be a copy in the "dims" array which doesn't
1380     // get updated, and the value must not be traversed twice. Was bug
1381     // - kbr 4/10/2001
1382     StateSplit::input_values_do(f);
1383     for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1384   }


1385 };
1386 











1387 
1388 BASE(TypeCheck, StateSplit)
1389  private:
1390   ciKlass*    _klass;
1391   Value       _obj;
1392 
1393   ciMethod* _profiled_method;
1394   int       _profiled_bci;
1395 
1396  public:
1397   // creation
1398   TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1399   : StateSplit(type, state_before), _klass(klass), _obj(obj),
1400     _profiled_method(NULL), _profiled_bci(0) {
1401     ASSERT_VALUES
1402     set_direct_compare(false);
1403   }
1404 
1405   // accessors
1406   ciKlass* klass() const                         { return _klass; }

1411   // manipulation
1412   void set_direct_compare(bool flag)             { set_flag(DirectCompareFlag, flag); }
1413 
1414   // generic
1415   virtual bool can_trap() const                  { return true; }
1416   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
1417 
1418   // Helpers for MethodData* profiling
1419   void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
1420   void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
1421   void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
1422   bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
1423   ciMethod* profiled_method() const                  { return _profiled_method;     }
1424   int       profiled_bci() const                     { return _profiled_bci;        }
1425 };
1426 
1427 
1428 LEAF(CheckCast, TypeCheck)
1429  public:
1430   // creation
1431   CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1432   : TypeCheck(klass, obj, objectType, state_before) {}


1433 
1434   void set_incompatible_class_change_check() {
1435     set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1436   }
1437   bool is_incompatible_class_change_check() const {
1438     return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1439   }
1440   void set_invokespecial_receiver_check() {
1441     set_flag(InvokeSpecialReceiverCheckFlag, true);
1442   }
1443   bool is_invokespecial_receiver_check() const {
1444     return check_flag(InvokeSpecialReceiverCheckFlag);
1445   }
1446 
1447   virtual bool needs_exception_state() const {
1448     return !is_invokespecial_receiver_check();
1449   }
1450 
1451   ciType* declared_type() const;
1452 };

1470   // creation
1471   AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)
1472   : StateSplit(illegalType, state_before)
1473   , _obj(obj)
1474   , _monitor_no(monitor_no)
1475   {
1476     set_needs_null_check(true);
1477     ASSERT_VALUES
1478   }
1479 
1480   // accessors
1481   Value obj() const                              { return _obj; }
1482   int monitor_no() const                         { return _monitor_no; }
1483 
1484   // generic
1485   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
1486 };
1487 
1488 
1489 LEAF(MonitorEnter, AccessMonitor)

1490  public:
1491   // creation
1492   MonitorEnter(Value obj, int monitor_no, ValueStack* state_before)
1493   : AccessMonitor(obj, monitor_no, state_before)

1494   {
1495     ASSERT_VALUES
1496   }
1497 



1498   // generic
1499   virtual bool can_trap() const                  { return true; }
1500 };
1501 
1502 
1503 LEAF(MonitorExit, AccessMonitor)
1504  public:
1505   // creation
1506   MonitorExit(Value obj, int monitor_no)
1507   : AccessMonitor(obj, monitor_no, NULL)
1508   {
1509     ASSERT_VALUES
1510   }
1511 };
1512 
1513 
1514 LEAF(Intrinsic, StateSplit)
1515  private:
1516   vmIntrinsics::ID _id;
1517   Values*          _args;

1942   Condition cond() const                         { return _cond; }
1943   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
1944   Value y() const                                { return _y; }
1945 
1946   void always_fail()                             { _x = _y = NULL; }
1947 
1948   // generic
1949   virtual void input_values_do(ValueVisitor* f)  { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }
1950   HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())
1951 };
1952 
1953 LEAF(If, BlockEnd)
1954  private:
1955   Value       _x;
1956   Condition   _cond;
1957   Value       _y;
1958   ciMethod*   _profiled_method;
1959   int         _profiled_bci; // Canonicalizer may alter bci of If node
1960   bool        _swapped;      // Is the order reversed with respect to the original If in the
1961                              // bytecode stream?

1962  public:
1963   // creation
1964   // unordered_is_true is valid for float/double compares only
1965   If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)
1966     : BlockEnd(illegalType, state_before, is_safepoint)
1967   , _x(x)
1968   , _cond(cond)
1969   , _y(y)
1970   , _profiled_method(NULL)
1971   , _profiled_bci(0)
1972   , _swapped(false)

1973   {
1974     ASSERT_VALUES
1975     set_flag(UnorderedIsTrueFlag, unordered_is_true);
1976     assert(x->type()->tag() == y->type()->tag(), "types must match");
1977     BlockList* s = new BlockList(2);
1978     s->append(tsux);
1979     s->append(fsux);
1980     set_sux(s);




1981   }
1982 
1983   // accessors
1984   Value x() const                                { return _x; }
1985   Condition cond() const                         { return _cond; }
1986   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
1987   Value y() const                                { return _y; }
1988   BlockBegin* sux_for(bool is_true) const        { return sux_at(is_true ? 0 : 1); }
1989   BlockBegin* tsux() const                       { return sux_for(true); }
1990   BlockBegin* fsux() const                       { return sux_for(false); }
1991   BlockBegin* usux() const                       { return sux_for(unordered_is_true()); }
1992   bool should_profile() const                    { return check_flag(ProfileMDOFlag); }
1993   ciMethod* profiled_method() const              { return _profiled_method; } // set only for profiled branches
1994   int profiled_bci() const                       { return _profiled_bci; }    // set for profiled branches and tiered
1995   bool is_swapped() const                        { return _swapped; }
1996 
1997   // manipulation
1998   void swap_operands() {
1999     Value t = _x; _x = _y; _y = t;
2000     _cond = mirror(_cond);
2001   }
2002 
2003   void swap_sux() {
2004     assert(number_of_sux() == 2, "wrong number of successors");
2005     BlockList* s = sux();
2006     BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
2007     _cond = negate(_cond);
2008     set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));
2009   }
2010 
2011   void set_should_profile(bool value)             { set_flag(ProfileMDOFlag, value); }
2012   void set_profiled_method(ciMethod* method)      { _profiled_method = method; }
2013   void set_profiled_bci(int bci)                  { _profiled_bci = bci;       }
2014   void set_swapped(bool value)                    { _swapped = value;         }

2015   // generic
2016   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2017 };
2018 
2019 
2020 BASE(Switch, BlockEnd)
2021  private:
2022   Value       _tag;
2023 
2024  public:
2025   // creation
2026   Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
2027   : BlockEnd(illegalType, state_before, is_safepoint)
2028   , _tag(tag) {
2029     ASSERT_VALUES
2030     set_sux(sux);
2031   }
2032 
2033   // accessors
2034   Value tag() const                              { return _tag; }

2329     }
2330   }
2331 };
2332 
2333 LEAF(ProfileReturnType, Instruction)
2334  private:
2335   ciMethod*        _method;
2336   ciMethod*        _callee;
2337   int              _bci_of_invoke;
2338   Value            _ret;
2339 
2340  public:
2341   ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)
2342     : Instruction(voidType)
2343     , _method(method)
2344     , _callee(callee)
2345     , _bci_of_invoke(bci)
2346     , _ret(ret)
2347   {
2348     set_needs_null_check(true);
2349     // The ProfileType has side-effects and must occur precisely where located
2350     pin();
2351   }
2352 
2353   ciMethod* method()             const { return _method; }
2354   ciMethod* callee()             const { return _callee; }
2355   int bci_of_invoke()            const { return _bci_of_invoke; }
2356   Value ret()                    const { return _ret; }
2357 
2358   virtual void input_values_do(ValueVisitor* f)   {
2359     if (_ret != NULL) {
2360       f->visit(&_ret);
2361     }
2362   }
2363 };
2364 










































2365 // Call some C runtime function that doesn't safepoint,
2366 // optionally passing the current thread as the first argument.
2367 LEAF(RuntimeCall, Instruction)
2368  private:
2369   const char* _entry_name;
2370   address     _entry;
2371   Values*     _args;
2372   bool        _pass_thread;  // Pass the JavaThread* as an implicit first argument
2373 
2374  public:
2375   RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2376     : Instruction(type)
2377     , _entry_name(entry_name)
2378     , _entry(entry)
2379     , _args(args)
2380     , _pass_thread(pass_thread) {
2381     ASSERT_VALUES
2382     pin();
2383   }
2384 

  55 class   AccessArray;
  56 class     ArrayLength;
  57 class     AccessIndexed;
  58 class       LoadIndexed;
  59 class       StoreIndexed;
  60 class   NegateOp;
  61 class   Op2;
  62 class     ArithmeticOp;
  63 class     ShiftOp;
  64 class     LogicOp;
  65 class     CompareOp;
  66 class     IfOp;
  67 class   Convert;
  68 class   NullCheck;
  69 class   TypeCast;
  70 class   OsrEntry;
  71 class   ExceptionObject;
  72 class   StateSplit;
  73 class     Invoke;
  74 class     NewInstance;
  75 class     NewInlineTypeInstance;
  76 class     NewArray;
  77 class       NewTypeArray;
  78 class       NewObjectArray;
  79 class       NewMultiArray;
  80 class     Deoptimize;
  81 class     TypeCheck;
  82 class       CheckCast;
  83 class       InstanceOf;
  84 class     AccessMonitor;
  85 class       MonitorEnter;
  86 class       MonitorExit;
  87 class     Intrinsic;
  88 class     BlockBegin;
  89 class     BlockEnd;
  90 class       Goto;
  91 class       If;
  92 class       Switch;
  93 class         TableSwitch;
  94 class         LookupSwitch;
  95 class       Return;
  96 class       Throw;
  97 class       Base;
  98 class   RoundFP;
  99 class   UnsafeOp;
 100 class     UnsafeGet;
 101 class     UnsafePut;
 102 class     UnsafeGetAndSet;
 103 class   ProfileCall;
 104 class   ProfileReturnType;
 105 class   ProfileACmpTypes;
 106 class   ProfileInvoke;
 107 class   RuntimeCall;
 108 class   MemBar;
 109 class   RangeCheckPredicate;
 110 #ifdef ASSERT
 111 class   Assert;
 112 #endif
 113 
 114 // A Value is a reference to the instruction creating the value
 115 typedef Instruction* Value;
 116 typedef GrowableArray<Value> Values;
 117 typedef GrowableArray<ValueStack*> ValueStackStack;
 118 
 119 // BlockClosure is the base class for block traversal/iteration.
 120 
 121 class BlockClosure: public CompilationResourceObj {
 122  public:
 123   virtual void block_do(BlockBegin* block)       = 0;
 124 };
 125 

 158  public:
 159   virtual void do_Phi            (Phi*             x) = 0;
 160   virtual void do_Local          (Local*           x) = 0;
 161   virtual void do_Constant       (Constant*        x) = 0;
 162   virtual void do_LoadField      (LoadField*       x) = 0;
 163   virtual void do_StoreField     (StoreField*      x) = 0;
 164   virtual void do_ArrayLength    (ArrayLength*     x) = 0;
 165   virtual void do_LoadIndexed    (LoadIndexed*     x) = 0;
 166   virtual void do_StoreIndexed   (StoreIndexed*    x) = 0;
 167   virtual void do_NegateOp       (NegateOp*        x) = 0;
 168   virtual void do_ArithmeticOp   (ArithmeticOp*    x) = 0;
 169   virtual void do_ShiftOp        (ShiftOp*         x) = 0;
 170   virtual void do_LogicOp        (LogicOp*         x) = 0;
 171   virtual void do_CompareOp      (CompareOp*       x) = 0;
 172   virtual void do_IfOp           (IfOp*            x) = 0;
 173   virtual void do_Convert        (Convert*         x) = 0;
 174   virtual void do_NullCheck      (NullCheck*       x) = 0;
 175   virtual void do_TypeCast       (TypeCast*        x) = 0;
 176   virtual void do_Invoke         (Invoke*          x) = 0;
 177   virtual void do_NewInstance    (NewInstance*     x) = 0;
 178   virtual void do_NewInlineTypeInstance(NewInlineTypeInstance* x) = 0;
 179   virtual void do_NewTypeArray   (NewTypeArray*    x) = 0;
 180   virtual void do_NewObjectArray (NewObjectArray*  x) = 0;
 181   virtual void do_NewMultiArray  (NewMultiArray*   x) = 0;
 182   virtual void do_Deoptimize     (Deoptimize*      x) = 0;
 183   virtual void do_CheckCast      (CheckCast*       x) = 0;
 184   virtual void do_InstanceOf     (InstanceOf*      x) = 0;
 185   virtual void do_MonitorEnter   (MonitorEnter*    x) = 0;
 186   virtual void do_MonitorExit    (MonitorExit*     x) = 0;
 187   virtual void do_Intrinsic      (Intrinsic*       x) = 0;
 188   virtual void do_BlockBegin     (BlockBegin*      x) = 0;
 189   virtual void do_Goto           (Goto*            x) = 0;
 190   virtual void do_If             (If*              x) = 0;
 191   virtual void do_TableSwitch    (TableSwitch*     x) = 0;
 192   virtual void do_LookupSwitch   (LookupSwitch*    x) = 0;
 193   virtual void do_Return         (Return*          x) = 0;
 194   virtual void do_Throw          (Throw*           x) = 0;
 195   virtual void do_Base           (Base*            x) = 0;
 196   virtual void do_OsrEntry       (OsrEntry*        x) = 0;
 197   virtual void do_ExceptionObject(ExceptionObject* x) = 0;
 198   virtual void do_RoundFP        (RoundFP*         x) = 0;
 199   virtual void do_UnsafeGet      (UnsafeGet*       x) = 0;
 200   virtual void do_UnsafePut      (UnsafePut*       x) = 0;
 201   virtual void do_UnsafeGetAndSet(UnsafeGetAndSet* x) = 0;
 202   virtual void do_ProfileCall    (ProfileCall*     x) = 0;
 203   virtual void do_ProfileReturnType (ProfileReturnType*  x) = 0;
 204   virtual void do_ProfileACmpTypes(ProfileACmpTypes*  x) = 0;
 205   virtual void do_ProfileInvoke  (ProfileInvoke*   x) = 0;
 206   virtual void do_RuntimeCall    (RuntimeCall*     x) = 0;
 207   virtual void do_MemBar         (MemBar*          x) = 0;
 208   virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0;
 209 #ifdef ASSERT
 210   virtual void do_Assert         (Assert*          x) = 0;
 211 #endif
 212 };
 213 
 214 
 215 // Hashing support
 216 //
 217 // Note: This hash functions affect the performance
 218 //       of ValueMap - make changes carefully!
 219 
 220 #define HASH1(x1            )                    ((intx)(x1))
 221 #define HASH2(x1, x2        )                    ((HASH1(x1            ) << 7) ^ HASH1(x2))
 222 #define HASH3(x1, x2, x3    )                    ((HASH2(x1, x2        ) << 7) ^ HASH1(x3))
 223 #define HASH4(x1, x2, x3, x4)                    ((HASH3(x1, x2, x3    ) << 7) ^ HASH1(x4))
 224 #define HASH5(x1, x2, x3, x4, x5)                ((HASH4(x1, x2, x3, x4) << 7) ^ HASH1(x5))
 225 
 226 
 227 // The following macros are used to implement instruction-specific hashing.
 228 // By default, each instruction implements hash() and is_equal(Value), used
 229 // for value numbering/common subexpression elimination. The default imple-
 230 // mentation disables value numbering. Each instruction which can be value-
 231 // numbered, should define corresponding hash() and is_equal(Value) functions
 232 // via the macros below. The f arguments specify all the values/op codes, etc.
 233 // that need to be identical for two instructions to be identical.
 234 //
 235 // Note: The default implementation of hash() returns 0 in order to indicate
 236 //       that the instruction should not be considered for value numbering.
 237 //       The currently used hash functions do not guarantee that never a 0
 238 //       is produced. While this is still correct, it may be a performance
 239 //       bug (no value numbering for that node). However, this situation is
 240 //       so unlikely, that we are not going to handle it specially.
 241 
 242 #define HASHING1(class_name, enabled, f1)             \
 243   virtual intx hash() const {                         \
 244     return (enabled) ? HASH2(name(), f1) : 0;         \

 263     if (f1 != _v->f1) return false;                   \
 264     if (f2 != _v->f2) return false;                   \
 265     return true;                                      \
 266   }                                                   \
 267 
 268 
 269 #define HASHING3(class_name, enabled, f1, f2, f3)     \
 270   virtual intx hash() const {                         \
 271     return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
 272   }                                                   \
 273   virtual bool is_equal(Value v) const {              \
 274     if (!(enabled)  ) return false;                   \
 275     class_name* _v = v->as_##class_name();            \
 276     if (_v == NULL  ) return false;                   \
 277     if (f1 != _v->f1) return false;                   \
 278     if (f2 != _v->f2) return false;                   \
 279     if (f3 != _v->f3) return false;                   \
 280     return true;                                      \
 281   }                                                   \
 282 
 283 #define HASHING4(class_name, enabled, f1, f2, f3, f4) \
 284   virtual intx hash() const {                         \
 285     return (enabled) ? HASH5(name(), f1, f2, f3, f4) : 0; \
 286   }                                                   \
 287   virtual bool is_equal(Value v) const {              \
 288     if (!(enabled)  ) return false;                   \
 289     class_name* _v = v->as_##class_name();            \
 290     if (_v == NULL  ) return false;                   \
 291     if (f1 != _v->f1) return false;                   \
 292     if (f2 != _v->f2) return false;                   \
 293     if (f3 != _v->f3) return false;                   \
 294     if (f4 != _v->f4) return false;                   \
 295     return true;                                      \
 296   }                                                   \
 297 
 298 
 299 // The mother of all instructions...
 300 
 301 class Instruction: public CompilationResourceObj {
 302  private:
 303   int          _id;                              // the unique instruction id
 304 #ifndef PRODUCT
 305   int          _printable_bci;                   // the bci of the instruction for printing
 306 #endif
 307   int          _use_count;                       // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1
 308   int          _pin_state;                       // set of PinReason describing the reason for pinning
 309   ValueType*   _type;                            // the instruction value type
 310   Instruction* _next;                            // the next instruction if any (NULL for BlockEnd instructions)
 311   Instruction* _subst;                           // the substitution instruction if any
 312   LIR_Opr      _operand;                         // LIR specific information
 313   unsigned int _flags;                           // Flag bits
 314 
 315   ValueStack*  _state_before;                    // Copy of state with input operands still on stack (or NULL)
 316   ValueStack*  _exception_state;                 // Copy of state for exception handling
 317   XHandlers*   _exception_handlers;              // Flat list of exception handlers covering this instruction
 318 
 319   friend class UseCountComputer;
 320   friend class GraphBuilder;
 321 
 322   void update_exception_state(ValueStack* state);
 323 
 324  protected:
 325   BlockBegin*  _block;                           // Block that contains this instruction
 326 
 327   void set_type(ValueType* type) {
 328     assert(type != NULL, "type must exist");
 329     _type = type;
 330   }
 331 
 332   // Helper class to keep track of which arguments need a null check
 333   class ArgsNonNullState {
 334   private:
 335     int _nonnull_state; // mask identifying which args are nonnull
 336   public:
 337     ArgsNonNullState()
 338       : _nonnull_state(AllBits) {}
 339 
 340     // Does argument number i needs a null check?

 353         if (check) {
 354           _nonnull_state |= nth_bit(i);
 355         } else {
 356           _nonnull_state &= ~(nth_bit(i));
 357         }
 358       }
 359     }
 360   };
 361 
 362  public:
 363   void* operator new(size_t size) throw() {
 364     Compilation* c = Compilation::current();
 365     void* res = c->arena()->Amalloc(size);
 366     return res;
 367   }
 368 
 369   static const int no_bci = -99;
 370 
 371   enum InstructionFlag {
 372     NeedsNullCheckFlag = 0,
 373     NeverNullFlag,          // For "Q" signatures
 374     CanTrapFlag,
 375     DirectCompareFlag,
 376     IsEliminatedFlag,
 377     IsSafepointFlag,
 378     IsStaticFlag,
 379     NeedsStoreCheckFlag,
 380     NeedsWriteBarrierFlag,
 381     PreservesStateFlag,
 382     TargetIsFinalFlag,
 383     TargetIsLoadedFlag,
 384     UnorderedIsTrueFlag,
 385     NeedsPatchingFlag,
 386     ThrowIncompatibleClassChangeErrorFlag,
 387     InvokeSpecialReceiverCheckFlag,
 388     ProfileMDOFlag,
 389     IsLinkedInBlockFlag,
 390     NeedsRangeCheckFlag,
 391     InWorkListFlag,
 392     DeoptimizeOnException,
 393     InstructionLastFlag

 446   int id() const                                 { return _id; }
 447 #ifndef PRODUCT
 448   bool has_printable_bci() const                 { return _printable_bci != -99; }
 449   int printable_bci() const                      { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
 450   void set_printable_bci(int bci)                { _printable_bci = bci; }
 451 #endif
 452   int dominator_depth();
 453   int use_count() const                          { return _use_count; }
 454   int pin_state() const                          { return _pin_state; }
 455   bool is_pinned() const                         { return _pin_state != 0 || PinAllInstructions; }
 456   ValueType* type() const                        { return _type; }
 457   BlockBegin *block() const                      { return _block; }
 458   Instruction* prev();                           // use carefully, expensive operation
 459   Instruction* next() const                      { return _next; }
 460   bool has_subst() const                         { return _subst != NULL; }
 461   Instruction* subst()                           { return _subst == NULL ? this : _subst->subst(); }
 462   LIR_Opr operand() const                        { return _operand; }
 463 
 464   void set_needs_null_check(bool f)              { set_flag(NeedsNullCheckFlag, f); }
 465   bool needs_null_check() const                  { return check_flag(NeedsNullCheckFlag); }
 466   void set_null_free(bool f)                     { set_flag(NeverNullFlag, f); }
 467   bool is_null_free() const                      { return check_flag(NeverNullFlag); }
 468   bool is_linked() const                         { return check_flag(IsLinkedInBlockFlag); }
 469   bool can_be_linked()                           { return as_Local() == NULL && as_Phi() == NULL; }
 470 
 471   bool is_null_obj()                             { return as_Constant() != NULL && type()->as_ObjectType()->constant_value()->is_null_object(); }
 472 
 473   bool has_uses() const                          { return use_count() > 0; }
 474   ValueStack* state_before() const               { return _state_before; }
 475   ValueStack* exception_state() const            { return _exception_state; }
 476   virtual bool needs_exception_state() const     { return true; }
 477   XHandlers* exception_handlers() const          { return _exception_handlers; }
 478   ciKlass* as_loaded_klass_or_null() const;
 479 
 480   // manipulation
 481   void pin(PinReason reason)                     { _pin_state |= reason; }
 482   void pin()                                     { _pin_state |= PinUnknown; }
 483   // DANGEROUS: only used by EliminateStores
 484   void unpin(PinReason reason)                   { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
 485 
 486   Instruction* set_next(Instruction* next) {
 487     assert(next->has_printable_bci(), "_printable_bci should have been set");
 488     assert(next != NULL, "must not be NULL");
 489     assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");
 490     assert(next->can_be_linked(), "shouldn't link these instructions into list");
 491 
 492     BlockBegin *block = this->block();
 493     next->_block = block;
 494 
 495     next->set_flag(Instruction::IsLinkedInBlockFlag, true);
 496     _next = next;
 497     return next;
 498   }

 503 #endif
 504     return set_next(next);
 505   }
 506 
 507   // when blocks are merged
 508   void fixup_block_pointers() {
 509     Instruction *cur = next()->next(); // next()'s block is set in set_next
 510     while (cur && cur->_block != block()) {
 511       cur->_block = block();
 512       cur = cur->next();
 513     }
 514   }
 515 
 516   Instruction *insert_after(Instruction *i) {
 517     Instruction* n = _next;
 518     set_next(i);
 519     i->set_next(n);
 520     return _next;
 521   }
 522 
 523   bool is_loaded_flattened_array() const;
 524   bool maybe_flattened_array();
 525   bool maybe_null_free_array();
 526 
 527   Instruction *insert_after_same_bci(Instruction *i) {
 528 #ifndef PRODUCT
 529     i->set_printable_bci(printable_bci());
 530 #endif
 531     return insert_after(i);
 532   }
 533 
 534   void set_subst(Instruction* subst)             {
 535     assert(subst == NULL ||
 536            type()->base() == subst->type()->base() ||
 537            subst->type()->base() == illegalType, "type can't change");
 538     _subst = subst;
 539   }
 540   void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
 541   void set_exception_state(ValueStack* s)        { check_state(s); _exception_state = s; }
 542   void set_state_before(ValueStack* s)           { check_state(s); _state_before = s; }
 543 
 544   // machine-specifics
 545   void set_operand(LIR_Opr operand)              { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
 546   void clear_operand()                           { _operand = LIR_OprFact::illegalOpr; }

 554   virtual LoadField*        as_LoadField()       { return NULL; }
 555   virtual StoreField*       as_StoreField()      { return NULL; }
 556   virtual AccessArray*      as_AccessArray()     { return NULL; }
 557   virtual ArrayLength*      as_ArrayLength()     { return NULL; }
 558   virtual AccessIndexed*    as_AccessIndexed()   { return NULL; }
 559   virtual LoadIndexed*      as_LoadIndexed()     { return NULL; }
 560   virtual StoreIndexed*     as_StoreIndexed()    { return NULL; }
 561   virtual NegateOp*         as_NegateOp()        { return NULL; }
 562   virtual Op2*              as_Op2()             { return NULL; }
 563   virtual ArithmeticOp*     as_ArithmeticOp()    { return NULL; }
 564   virtual ShiftOp*          as_ShiftOp()         { return NULL; }
 565   virtual LogicOp*          as_LogicOp()         { return NULL; }
 566   virtual CompareOp*        as_CompareOp()       { return NULL; }
 567   virtual IfOp*             as_IfOp()            { return NULL; }
 568   virtual Convert*          as_Convert()         { return NULL; }
 569   virtual NullCheck*        as_NullCheck()       { return NULL; }
 570   virtual OsrEntry*         as_OsrEntry()        { return NULL; }
 571   virtual StateSplit*       as_StateSplit()      { return NULL; }
 572   virtual Invoke*           as_Invoke()          { return NULL; }
 573   virtual NewInstance*      as_NewInstance()     { return NULL; }
 574   virtual NewInlineTypeInstance* as_NewInlineTypeInstance() { return NULL; }
 575   virtual NewArray*         as_NewArray()        { return NULL; }
 576   virtual NewTypeArray*     as_NewTypeArray()    { return NULL; }
 577   virtual NewObjectArray*   as_NewObjectArray()  { return NULL; }
 578   virtual NewMultiArray*    as_NewMultiArray()   { return NULL; }
 579   virtual Deoptimize*       as_Deoptimize()      { return NULL; }
 580   virtual TypeCheck*        as_TypeCheck()       { return NULL; }
 581   virtual CheckCast*        as_CheckCast()       { return NULL; }
 582   virtual InstanceOf*       as_InstanceOf()      { return NULL; }
 583   virtual TypeCast*         as_TypeCast()        { return NULL; }
 584   virtual AccessMonitor*    as_AccessMonitor()   { return NULL; }
 585   virtual MonitorEnter*     as_MonitorEnter()    { return NULL; }
 586   virtual MonitorExit*      as_MonitorExit()     { return NULL; }
 587   virtual Intrinsic*        as_Intrinsic()       { return NULL; }
 588   virtual BlockBegin*       as_BlockBegin()      { return NULL; }
 589   virtual BlockEnd*         as_BlockEnd()        { return NULL; }
 590   virtual Goto*             as_Goto()            { return NULL; }
 591   virtual If*               as_If()              { return NULL; }
 592   virtual TableSwitch*      as_TableSwitch()     { return NULL; }
 593   virtual LookupSwitch*     as_LookupSwitch()    { return NULL; }
 594   virtual Return*           as_Return()          { return NULL; }
 595   virtual Throw*            as_Throw()           { return NULL; }
 596   virtual Base*             as_Base()            { return NULL; }
 597   virtual RoundFP*          as_RoundFP()         { return NULL; }
 598   virtual ExceptionObject*  as_ExceptionObject() { return NULL; }
 599   virtual UnsafeOp*         as_UnsafeOp()        { return NULL; }

 708   }
 709 
 710   bool is_illegal() const {
 711     return type()->is_illegal();
 712   }
 713 
 714   // generic
 715   virtual void input_values_do(ValueVisitor* f) {
 716   }
 717 };
 718 
 719 
 720 // A local is a placeholder for an incoming argument to a function call.
 721 LEAF(Local, Instruction)
 722  private:
 723   int      _java_index;                          // the local index within the method to which the local belongs
 724   bool     _is_receiver;                         // if local variable holds the receiver: "this" for non-static methods
 725   ciType*  _declared_type;
 726  public:
 727   // creation
 728   Local(ciType* declared, ValueType* type, int index, bool receiver, bool null_free)
 729     : Instruction(type)
 730     , _java_index(index)
 731     , _is_receiver(receiver)
 732     , _declared_type(declared)
 733   {
 734     set_null_free(null_free);
 735     NOT_PRODUCT(set_printable_bci(-1));
 736   }
 737 
 738   // accessors
 739   int java_index() const                         { return _java_index; }
 740   bool is_receiver() const                       { return _is_receiver; }
 741 
 742   virtual ciType* declared_type() const          { return _declared_type; }
 743 
 744   // generic
 745   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
 746 };
 747 
 748 
 749 LEAF(Constant, Instruction)
 750  public:
 751   // creation
 752   Constant(ValueType* type):
 753       Instruction(type, NULL, /*type_is_constant*/ true)
 754   {

 834 
 835   // manipulation
 836 
 837   // Under certain circumstances, if a previous NullCheck instruction
 838   // proved the target object non-null, we can eliminate the explicit
 839   // null check and do an implicit one, simply specifying the debug
 840   // information from the NullCheck. This field should only be consulted
 841   // if needs_null_check() is true.
 842   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 843 
 844   // generic
 845   virtual bool can_trap() const                  { return needs_null_check() || needs_patching(); }
 846   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_obj); }
 847 };
 848 
 849 
 850 LEAF(LoadField, AccessField)
 851  public:
 852   // creation
 853   LoadField(Value obj, int offset, ciField* field, bool is_static,
 854             ValueStack* state_before, bool needs_patching,
 855             ciInlineKlass* inline_klass = NULL, Value default_value = NULL )
 856   : AccessField(obj, offset, field, is_static, state_before, needs_patching)
 857   {
 858     set_null_free(field->is_null_free());
 859   }
 860 
 861   ciType* declared_type() const;
 862 
 863   // generic; cannot be eliminated if needs patching or if volatile.
 864   HASHING3(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset(), declared_type())
 865 };
 866 
 867 
 868 LEAF(StoreField, AccessField)
 869  private:
 870   Value _value;
 871   ciField* _enclosing_field;   // enclosing field (the flattened one) for nested fields
 872 
 873  public:
 874   // creation
 875   StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
 876              ValueStack* state_before, bool needs_patching);







 877 
 878   // accessors
 879   Value value() const                            { return _value; }
 880   bool needs_write_barrier() const               { return check_flag(NeedsWriteBarrierFlag); }
 881   ciField* enclosing_field() const               { return _enclosing_field; }
 882   void set_enclosing_field(ciField* field)       { _enclosing_field = field; }
 883 
 884   // generic
 885   virtual void input_values_do(ValueVisitor* f)   { AccessField::input_values_do(f); f->visit(&_value); }
 886 };
 887 
 888 
 889 BASE(AccessArray, Instruction)
 890  private:
 891   Value       _array;
 892 
 893  public:
 894   // creation
 895   AccessArray(ValueType* type, Value array, ValueStack* state_before)
 896   : Instruction(type, state_before)
 897   , _array(array)
 898   {
 899     set_needs_null_check(true);
 900     ASSERT_VALUES
 901     pin(); // instruction with side effect (null exception or range check throwing)
 902   }

 920   , _explicit_null_check(NULL) {}
 921 
 922   // accessors
 923   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 924 
 925   // setters
 926   // See LoadField::set_explicit_null_check for documentation
 927   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 928 
 929   // generic
 930   HASHING1(ArrayLength, true, array()->subst())
 931 };
 932 
 933 
 934 BASE(AccessIndexed, AccessArray)
 935  private:
 936   Value     _index;
 937   Value     _length;
 938   BasicType _elt_type;
 939   bool      _mismatched;
 940   ciMethod* _profiled_method;
 941   int       _profiled_bci;
 942 
 943  public:
 944   // creation
 945   AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched)
 946   : AccessArray(as_ValueType(elt_type), array, state_before)
 947   , _index(index)
 948   , _length(length)
 949   , _elt_type(elt_type)
 950   , _mismatched(mismatched)
 951   , _profiled_method(NULL), _profiled_bci(0)
 952   {
 953     set_flag(Instruction::NeedsRangeCheckFlag, true);
 954     ASSERT_VALUES
 955   }
 956 
 957   // accessors
 958   Value index() const                            { return _index; }
 959   Value length() const                           { return _length; }
 960   BasicType elt_type() const                     { return _elt_type; }
 961   bool mismatched() const                        { return _mismatched; }
 962 
 963   void clear_length()                            { _length = NULL; }
 964   // perform elimination of range checks involving constants
 965   bool compute_needs_range_check();
 966 
 967   // Helpers for MethodData* profiling
 968   void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
 969   void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
 970   void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
 971   bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
 972   ciMethod* profiled_method() const                  { return _profiled_method;     }
 973   int       profiled_bci() const                     { return _profiled_bci;        }
 974 
 975 
 976 // generic
 977   virtual void input_values_do(ValueVisitor* f)   { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }
 978 };
 979 
 980 class DelayedLoadIndexed;
 981 
 982 LEAF(LoadIndexed, AccessIndexed)
 983  private:
 984   NullCheck*  _explicit_null_check;              // For explicit null check elimination
 985   NewInlineTypeInstance* _vt;
 986   DelayedLoadIndexed* _delayed;
 987 
 988  public:
 989   // creation
 990   LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched = false)
 991   : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
 992   , _explicit_null_check(NULL), _vt(NULL), _delayed(NULL) {}
 993 
 994   // accessors
 995   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 996 
 997   // setters
 998   // See LoadField::set_explicit_null_check for documentation
 999   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
1000 
1001   ciType* exact_type() const;
1002   ciType* declared_type() const;
1003 
1004   NewInlineTypeInstance* vt() const { return _vt; }
1005   void set_vt(NewInlineTypeInstance* vt) { _vt = vt; }
1006 
1007   DelayedLoadIndexed* delayed() const { return _delayed; }
1008   void set_delayed(DelayedLoadIndexed* delayed) { _delayed = delayed; }
1009 
1010   // generic
1011   HASHING4(LoadIndexed, delayed() == NULL && !should_profile(), type()->tag(), array()->subst(), index()->subst(), vt())
1012 };
1013 
1014 class DelayedLoadIndexed : public CompilationResourceObj {
1015 private:
1016   LoadIndexed* _load_instr;
1017   ValueStack* _state_before;
1018   ciField* _field;
1019   int _offset;
1020  public:
1021   DelayedLoadIndexed(LoadIndexed* load, ValueStack* state_before)
1022   : _load_instr(load)
1023   , _state_before(state_before)
1024   , _field(NULL)
1025   , _offset(0) { }
1026 
1027   void update(ciField* field, int offset) {
1028     _field = field;
1029     _offset += offset;
1030   }
1031 
1032   LoadIndexed* load_instr() const { return _load_instr; }
1033   ValueStack* state_before() const { return _state_before; }
1034   ciField* field() const { return _field; }
1035   int offset() const { return _offset; }
1036 };
1037 
1038 LEAF(StoreIndexed, AccessIndexed)
1039  private:
1040   Value       _value;
1041 


1042   bool      _check_boolean;
1043 
1044  public:
1045   // creation
1046   StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before,
1047                bool check_boolean, bool mismatched = false);








1048 
1049   // accessors
1050   Value value() const                            { return _value; }
1051   bool needs_write_barrier() const               { return check_flag(NeedsWriteBarrierFlag); }
1052   bool needs_store_check() const                 { return check_flag(NeedsStoreCheckFlag); }
1053   bool check_boolean() const                     { return _check_boolean; }
1054 
1055   // Flattened array support
1056   bool is_exact_flattened_array_store() const;




1057   // generic
1058   virtual void input_values_do(ValueVisitor* f)   { AccessIndexed::input_values_do(f); f->visit(&_value); }
1059 };
1060 
1061 
1062 LEAF(NegateOp, Instruction)
1063  private:
1064   Value _x;
1065 
1066  public:
1067   // creation
1068   NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
1069     ASSERT_VALUES
1070   }
1071 
1072   // accessors
1073   Value x() const                                { return _x; }
1074 
1075   // generic
1076   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_x); }

1147   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1148 };
1149 
1150 
1151 LEAF(CompareOp, Op2)
1152  public:
1153   // creation
1154   CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1155   : Op2(intType, op, x, y, state_before)
1156   {}
1157 
1158   // generic
1159   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1160 };
1161 
1162 
1163 LEAF(IfOp, Op2)
1164  private:
1165   Value _tval;
1166   Value _fval;
1167   bool _substitutability_check;
1168 
1169  public:
1170   // creation
1171   IfOp(Value x, Condition cond, Value y, Value tval, Value fval, ValueStack* state_before, bool substitutability_check)
1172   : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1173   , _tval(tval)
1174   , _fval(fval)
1175   , _substitutability_check(substitutability_check)
1176   {
1177     ASSERT_VALUES
1178     assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1179     set_state_before(state_before);
1180   }
1181 
1182   // accessors
1183   virtual bool is_commutative() const;
1184   Bytecodes::Code op() const                     { ShouldNotCallThis(); return Bytecodes::_illegal; }
1185   Condition cond() const                         { return (Condition)Op2::op(); }
1186   Value tval() const                             { return _tval; }
1187   Value fval() const                             { return _fval; }
1188   bool substitutability_check() const             { return _substitutability_check; }
1189   // generic
1190   virtual void input_values_do(ValueVisitor* f)   { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1191 };
1192 
1193 
1194 LEAF(Convert, Instruction)
1195  private:
1196   Bytecodes::Code _op;
1197   Value           _value;
1198 
1199  public:
1200   // creation
1201   Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1202     ASSERT_VALUES
1203   }
1204 
1205   // accessors
1206   Bytecodes::Code op() const                     { return _op; }
1207   Value value() const                            { return _value; }
1208 

1287   // manipulation
1288   void set_state(ValueStack* state)              { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }
1289 
1290   // generic
1291   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
1292   virtual void state_values_do(ValueVisitor* f);
1293 };
1294 
1295 
1296 LEAF(Invoke, StateSplit)
1297  private:
1298   Bytecodes::Code _code;
1299   Value           _recv;
1300   Values*         _args;
1301   BasicTypeList*  _signature;
1302   ciMethod*       _target;
1303 
1304  public:
1305   // creation
1306   Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1307          ciMethod* target, ValueStack* state_before, bool null_free);
1308 
1309   // accessors
1310   Bytecodes::Code code() const                   { return _code; }
1311   Value receiver() const                         { return _recv; }
1312   bool has_receiver() const                      { return receiver() != NULL; }
1313   int number_of_arguments() const                { return _args->length(); }
1314   Value argument_at(int i) const                 { return _args->at(i); }
1315   BasicTypeList* signature() const               { return _signature; }
1316   ciMethod* target() const                       { return _target; }
1317 
1318   ciType* declared_type() const;
1319 
1320   // Returns false if target is not loaded
1321   bool target_is_final() const                   { return check_flag(TargetIsFinalFlag); }
1322   bool target_is_loaded() const                  { return check_flag(TargetIsLoadedFlag); }
1323 
1324   // JSR 292 support
1325   bool is_invokedynamic() const                  { return code() == Bytecodes::_invokedynamic; }
1326   bool is_method_handle_intrinsic() const        { return target()->is_method_handle_intrinsic(); }
1327 

1345 
1346  public:
1347   // creation
1348   NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved)
1349   : StateSplit(instanceType, state_before)
1350   , _klass(klass), _is_unresolved(is_unresolved)
1351   {}
1352 
1353   // accessors
1354   ciInstanceKlass* klass() const                 { return _klass; }
1355   bool is_unresolved() const                     { return _is_unresolved; }
1356 
1357   virtual bool needs_exception_state() const     { return false; }
1358 
1359   // generic
1360   virtual bool can_trap() const                  { return true; }
1361   ciType* exact_type() const;
1362   ciType* declared_type() const;
1363 };
1364 
1365 LEAF(NewInlineTypeInstance, StateSplit)
1366   ciInlineKlass* _klass;
1367   bool _in_larval_state;
1368   int _first_local_index;
1369   int _on_stack_count;
1370 public:
1371 
1372   // Default creation, always allocated for now
1373   NewInlineTypeInstance(ciInlineKlass* klass, ValueStack* state_before)
1374   : StateSplit(instanceType, state_before)
1375    , _klass(klass)
1376    , _in_larval_state(true)
1377    , _first_local_index(-1)
1378    , _on_stack_count(1)
1379   {
1380     set_null_free(true);
1381   }
1382 
1383   // accessors
1384   ciInlineKlass* klass() const { return _klass; }
1385   virtual bool needs_exception_state() const     { return false; }
1386 
1387   // generic
1388   virtual bool can_trap() const                  { return true; }
1389   ciType* exact_type() const;
1390   ciType* declared_type() const;
1391 
1392   // Only done in LIR Generator -> map everything to object
1393   void set_to_object_type() { set_type(instanceType); }
1394 
1395   void set_local_index(int index) {
1396     decrement_on_stack_count();
1397     if (_first_local_index != index) {
1398       if (_first_local_index == -1) {
1399         _first_local_index = index;
1400       } else {
1401         set_not_larva_anymore();
1402       }
1403     }
1404   }
1405 
1406   bool in_larval_state() const { return _in_larval_state; }
1407   void set_not_larva_anymore() { _in_larval_state = false; }
1408 
1409   int on_stack_count() const { return _on_stack_count; }
1410   void increment_on_stack_count() { _on_stack_count++; }
1411   void decrement_on_stack_count() { _on_stack_count--; }
1412 };
1413 
1414 BASE(NewArray, StateSplit)
1415  private:
1416   Value       _length;
1417 
1418  public:
1419   // creation
1420   NewArray(Value length, ValueStack* state_before)
1421   : StateSplit(objectType, state_before)
1422   , _length(length)
1423   {
1424     // Do not ASSERT_VALUES since length is NULL for NewMultiArray
1425   }
1426 
1427   // accessors
1428   Value length() const                           { return _length; }
1429 
1430   virtual bool needs_exception_state() const     { return false; }
1431 
1432   ciType* exact_type() const                     { return NULL; }

1444 
1445  public:
1446   // creation
1447   NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)
1448   : NewArray(length, state_before)
1449   , _elt_type(elt_type)
1450   {}
1451 
1452   // accessors
1453   BasicType elt_type() const                     { return _elt_type; }
1454   ciType* exact_type() const;
1455 };
1456 
1457 
1458 LEAF(NewObjectArray, NewArray)
1459  private:
1460   ciKlass* _klass;
1461 
1462  public:
1463   // creation
1464   NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before, bool null_free)
1465   : NewArray(length, state_before), _klass(klass) {
1466     set_null_free(null_free);
1467   }
1468 
1469   // accessors
1470   ciKlass* klass() const                         { return _klass; }
1471   ciType* exact_type() const;
1472 };
1473 
1474 
1475 LEAF(NewMultiArray, NewArray)
1476  private:
1477   ciKlass* _klass;
1478   Values*  _dims;
1479 
1480  public:
1481   // creation
1482   NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
1483     ASSERT_VALUES
1484   }
1485 
1486   // accessors
1487   ciKlass* klass() const                         { return _klass; }
1488   Values* dims() const                           { return _dims; }
1489   int rank() const                               { return dims()->length(); }
1490 
1491   // generic
1492   virtual void input_values_do(ValueVisitor* f) {
1493     // NOTE: we do not call NewArray::input_values_do since "length"
1494     // is meaningless for a multi-dimensional array; passing the
1495     // zeroth element down to NewArray as its length is a bad idea
1496     // since there will be a copy in the "dims" array which doesn't
1497     // get updated, and the value must not be traversed twice. Was bug
1498     // - kbr 4/10/2001
1499     StateSplit::input_values_do(f);
1500     for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1501   }
1502 
1503   ciType* exact_type() const;
1504 };
1505 
1506 LEAF(Deoptimize, StateSplit)
1507 private:
1508   ciKlass*    _klass;
1509 
1510  public:
1511   Deoptimize(ciKlass* klass, ValueStack* state_before)
1512   : StateSplit(objectType, state_before), _klass(klass) {}
1513 
1514   // accessors
1515   ciKlass* klass() const                         { return _klass; }
1516 };
1517 
1518 BASE(TypeCheck, StateSplit)
1519  private:
1520   ciKlass*    _klass;
1521   Value       _obj;
1522 
1523   ciMethod* _profiled_method;
1524   int       _profiled_bci;
1525 
1526  public:
1527   // creation
1528   TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1529   : StateSplit(type, state_before), _klass(klass), _obj(obj),
1530     _profiled_method(NULL), _profiled_bci(0) {
1531     ASSERT_VALUES
1532     set_direct_compare(false);
1533   }
1534 
1535   // accessors
1536   ciKlass* klass() const                         { return _klass; }

1541   // manipulation
1542   void set_direct_compare(bool flag)             { set_flag(DirectCompareFlag, flag); }
1543 
1544   // generic
1545   virtual bool can_trap() const                  { return true; }
1546   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
1547 
1548   // Helpers for MethodData* profiling
1549   void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
1550   void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
1551   void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
1552   bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
1553   ciMethod* profiled_method() const                  { return _profiled_method;     }
1554   int       profiled_bci() const                     { return _profiled_bci;        }
1555 };
1556 
1557 
1558 LEAF(CheckCast, TypeCheck)
1559  public:
1560   // creation
1561   CheckCast(ciKlass* klass, Value obj, ValueStack* state_before, bool null_free = false)
1562   : TypeCheck(klass, obj, objectType, state_before) {
1563     set_null_free(null_free);
1564   }
1565 
1566   void set_incompatible_class_change_check() {
1567     set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1568   }
1569   bool is_incompatible_class_change_check() const {
1570     return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1571   }
1572   void set_invokespecial_receiver_check() {
1573     set_flag(InvokeSpecialReceiverCheckFlag, true);
1574   }
1575   bool is_invokespecial_receiver_check() const {
1576     return check_flag(InvokeSpecialReceiverCheckFlag);
1577   }
1578 
1579   virtual bool needs_exception_state() const {
1580     return !is_invokespecial_receiver_check();
1581   }
1582 
1583   ciType* declared_type() const;
1584 };

1602   // creation
1603   AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)
1604   : StateSplit(illegalType, state_before)
1605   , _obj(obj)
1606   , _monitor_no(monitor_no)
1607   {
1608     set_needs_null_check(true);
1609     ASSERT_VALUES
1610   }
1611 
1612   // accessors
1613   Value obj() const                              { return _obj; }
1614   int monitor_no() const                         { return _monitor_no; }
1615 
1616   // generic
1617   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
1618 };
1619 
1620 
1621 LEAF(MonitorEnter, AccessMonitor)
1622   bool _maybe_inlinetype;
1623  public:
1624   // creation
1625   MonitorEnter(Value obj, int monitor_no, ValueStack* state_before, bool maybe_inlinetype)
1626   : AccessMonitor(obj, monitor_no, state_before)
1627   , _maybe_inlinetype(maybe_inlinetype)
1628   {
1629     ASSERT_VALUES
1630   }
1631 
1632   // accessors
1633   bool maybe_inlinetype() const                   { return _maybe_inlinetype; }
1634 
1635   // generic
1636   virtual bool can_trap() const                  { return true; }
1637 };
1638 
1639 
1640 LEAF(MonitorExit, AccessMonitor)
1641  public:
1642   // creation
1643   MonitorExit(Value obj, int monitor_no)
1644   : AccessMonitor(obj, monitor_no, NULL)
1645   {
1646     ASSERT_VALUES
1647   }
1648 };
1649 
1650 
1651 LEAF(Intrinsic, StateSplit)
1652  private:
1653   vmIntrinsics::ID _id;
1654   Values*          _args;

2079   Condition cond() const                         { return _cond; }
2080   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
2081   Value y() const                                { return _y; }
2082 
2083   void always_fail()                             { _x = _y = NULL; }
2084 
2085   // generic
2086   virtual void input_values_do(ValueVisitor* f)  { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2087   HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())
2088 };
2089 
2090 LEAF(If, BlockEnd)
2091  private:
2092   Value       _x;
2093   Condition   _cond;
2094   Value       _y;
2095   ciMethod*   _profiled_method;
2096   int         _profiled_bci; // Canonicalizer may alter bci of If node
2097   bool        _swapped;      // Is the order reversed with respect to the original If in the
2098                              // bytecode stream?
2099   bool        _substitutability_check;
2100  public:
2101   // creation
2102   // unordered_is_true is valid for float/double compares only
2103   If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint, bool substitutability_check=false)
2104     : BlockEnd(illegalType, state_before, is_safepoint)
2105   , _x(x)
2106   , _cond(cond)
2107   , _y(y)
2108   , _profiled_method(NULL)
2109   , _profiled_bci(0)
2110   , _swapped(false)
2111   , _substitutability_check(substitutability_check)
2112   {
2113     ASSERT_VALUES
2114     set_flag(UnorderedIsTrueFlag, unordered_is_true);
2115     assert(x->type()->tag() == y->type()->tag(), "types must match");
2116     BlockList* s = new BlockList(2);
2117     s->append(tsux);
2118     s->append(fsux);
2119     set_sux(s);
2120     if (!_substitutability_check) {
2121       assert(x->as_NewInlineTypeInstance() == NULL || y->type() == objectNull, "Sanity check");
2122       assert(y->as_NewInlineTypeInstance() == NULL || x->type() == objectNull, "Sanity check");
2123     }
2124   }
2125 
2126   // accessors
2127   Value x() const                                { return _x; }
2128   Condition cond() const                         { return _cond; }
2129   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
2130   Value y() const                                { return _y; }
2131   BlockBegin* sux_for(bool is_true) const        { return sux_at(is_true ? 0 : 1); }
2132   BlockBegin* tsux() const                       { return sux_for(true); }
2133   BlockBegin* fsux() const                       { return sux_for(false); }
2134   BlockBegin* usux() const                       { return sux_for(unordered_is_true()); }
2135   bool should_profile() const                    { return check_flag(ProfileMDOFlag); }
2136   ciMethod* profiled_method() const              { return _profiled_method; } // set only for profiled branches
2137   int profiled_bci() const                       { return _profiled_bci; }    // set for profiled branches and tiered
2138   bool is_swapped() const                        { return _swapped; }
2139 
2140   // manipulation
2141   void swap_operands() {
2142     Value t = _x; _x = _y; _y = t;
2143     _cond = mirror(_cond);
2144   }
2145 
2146   void swap_sux() {
2147     assert(number_of_sux() == 2, "wrong number of successors");
2148     BlockList* s = sux();
2149     BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
2150     _cond = negate(_cond);
2151     set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));
2152   }
2153 
2154   void set_should_profile(bool value)             { set_flag(ProfileMDOFlag, value); }
2155   void set_profiled_method(ciMethod* method)      { _profiled_method = method; }
2156   void set_profiled_bci(int bci)                  { _profiled_bci = bci;       }
2157   void set_swapped(bool value)                    { _swapped = value;         }
2158   bool substitutability_check() const              { return _substitutability_check; }
2159   // generic
2160   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2161 };
2162 
2163 
2164 BASE(Switch, BlockEnd)
2165  private:
2166   Value       _tag;
2167 
2168  public:
2169   // creation
2170   Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
2171   : BlockEnd(illegalType, state_before, is_safepoint)
2172   , _tag(tag) {
2173     ASSERT_VALUES
2174     set_sux(sux);
2175   }
2176 
2177   // accessors
2178   Value tag() const                              { return _tag; }

2473     }
2474   }
2475 };
2476 
2477 LEAF(ProfileReturnType, Instruction)
2478  private:
2479   ciMethod*        _method;
2480   ciMethod*        _callee;
2481   int              _bci_of_invoke;
2482   Value            _ret;
2483 
2484  public:
2485   ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)
2486     : Instruction(voidType)
2487     , _method(method)
2488     , _callee(callee)
2489     , _bci_of_invoke(bci)
2490     , _ret(ret)
2491   {
2492     set_needs_null_check(true);
2493     // The ProfileReturnType has side-effects and must occur precisely where located
2494     pin();
2495   }
2496 
2497   ciMethod* method()             const { return _method; }
2498   ciMethod* callee()             const { return _callee; }
2499   int bci_of_invoke()            const { return _bci_of_invoke; }
2500   Value ret()                    const { return _ret; }
2501 
2502   virtual void input_values_do(ValueVisitor* f)   {
2503     if (_ret != NULL) {
2504       f->visit(&_ret);
2505     }
2506   }
2507 };
2508 
2509 LEAF(ProfileACmpTypes, Instruction)
2510  private:
2511   ciMethod*        _method;
2512   int              _bci;
2513   Value            _left;
2514   Value            _right;
2515   bool             _left_maybe_null;
2516   bool             _right_maybe_null;
2517 
2518  public:
2519   ProfileACmpTypes(ciMethod* method, int bci, Value left, Value right)
2520     : Instruction(voidType)
2521     , _method(method)
2522     , _bci(bci)
2523     , _left(left)
2524     , _right(right)
2525   {
2526     // The ProfileACmp has side-effects and must occur precisely where located
2527     pin();
2528     _left_maybe_null = true;
2529     _right_maybe_null = true;
2530   }
2531 
2532   ciMethod* method()             const { return _method; }
2533   int bci()                      const { return _bci; }
2534   Value left()                   const { return _left; }
2535   Value right()                  const { return _right; }
2536   bool left_maybe_null()         const { return _left_maybe_null; }
2537   bool right_maybe_null()        const { return _right_maybe_null; }
2538   void set_left_maybe_null(bool v)     { _left_maybe_null = v; }
2539   void set_right_maybe_null(bool v)    { _right_maybe_null = v; }
2540 
2541   virtual void input_values_do(ValueVisitor* f)   {
2542     if (_left != NULL) {
2543       f->visit(&_left);
2544     }
2545     if (_right != NULL) {
2546       f->visit(&_right);
2547     }
2548   }
2549 };
2550 
2551 // Call some C runtime function that doesn't safepoint,
2552 // optionally passing the current thread as the first argument.
2553 LEAF(RuntimeCall, Instruction)
2554  private:
2555   const char* _entry_name;
2556   address     _entry;
2557   Values*     _args;
2558   bool        _pass_thread;  // Pass the JavaThread* as an implicit first argument
2559 
2560  public:
2561   RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2562     : Instruction(type)
2563     , _entry_name(entry_name)
2564     , _entry(entry)
2565     , _args(args)
2566     , _pass_thread(pass_thread) {
2567     ASSERT_VALUES
2568     pin();
2569   }
2570 
< prev index next >