1 /*
   2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_C1_C1_INSTRUCTION_HPP
  26 #define SHARE_C1_C1_INSTRUCTION_HPP
  27 
  28 #include "c1/c1_Compilation.hpp"
  29 #include "c1/c1_LIR.hpp"
  30 #include "c1/c1_ValueType.hpp"
  31 #include "ci/ciField.hpp"
  32 
  33 // Predefined classes
  34 class ciField;
  35 class ValueStack;
  36 class InstructionPrinter;
  37 class IRScope;
  38 class LIR_OprDesc;
  39 typedef LIR_OprDesc* LIR_Opr;
  40 
  41 
  42 // Instruction class hierarchy
  43 //
  44 // All leaf classes in the class hierarchy are concrete classes
  45 // (i.e., are instantiated). All other classes are abstract and
  46 // serve factoring.
  47 
  48 class Instruction;
  49 class   Phi;
  50 class   Local;
  51 class   Constant;
  52 class   AccessField;
  53 class     LoadField;
  54 class     StoreField;
  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     NewValueTypeInstance;
  76 class     NewArray;
  77 class       NewTypeArray;
  78 class       NewObjectArray;
  79 class       NewMultiArray;
  80 class     WithField;
  81 class     DefaultValue;
  82 class     TypeCheck;
  83 class       CheckCast;
  84 class       InstanceOf;
  85 class     AccessMonitor;
  86 class       MonitorEnter;
  87 class       MonitorExit;
  88 class     Intrinsic;
  89 class     BlockBegin;
  90 class     BlockEnd;
  91 class       Goto;
  92 class       If;
  93 class       IfInstanceOf;
  94 class       Switch;
  95 class         TableSwitch;
  96 class         LookupSwitch;
  97 class       Return;
  98 class       Throw;
  99 class       Base;
 100 class   RoundFP;
 101 class   UnsafeOp;
 102 class     UnsafeRawOp;
 103 class       UnsafeGetRaw;
 104 class       UnsafePutRaw;
 105 class     UnsafeObjectOp;
 106 class       UnsafeGetObject;
 107 class       UnsafePutObject;
 108 class         UnsafeGetAndSetObject;
 109 class   ProfileCall;
 110 class   ProfileReturnType;
 111 class   ProfileInvoke;
 112 class   RuntimeCall;
 113 class   MemBar;
 114 class   RangeCheckPredicate;
 115 #ifdef ASSERT
 116 class   Assert;
 117 #endif
 118 
 119 // A Value is a reference to the instruction creating the value
 120 typedef Instruction* Value;
 121 typedef GrowableArray<Value> Values;
 122 typedef GrowableArray<ValueStack*> ValueStackStack;
 123 
 124 // BlockClosure is the base class for block traversal/iteration.
 125 
 126 class BlockClosure: public CompilationResourceObj {
 127  public:
 128   virtual void block_do(BlockBegin* block)       = 0;
 129 };
 130 
 131 
 132 // A simple closure class for visiting the values of an Instruction
 133 class ValueVisitor: public StackObj {
 134  public:
 135   virtual void visit(Value* v) = 0;
 136 };
 137 
 138 
 139 // Some array and list classes
 140 typedef GrowableArray<BlockBegin*> BlockBeginArray;
 141 
 142 class BlockList: public GrowableArray<BlockBegin*> {
 143  public:
 144   BlockList(): GrowableArray<BlockBegin*>() {}
 145   BlockList(const int size): GrowableArray<BlockBegin*>(size) {}
 146   BlockList(const int size, BlockBegin* init): GrowableArray<BlockBegin*>(size, size, init) {}
 147 
 148   void iterate_forward(BlockClosure* closure);
 149   void iterate_backward(BlockClosure* closure);
 150   void blocks_do(void f(BlockBegin*));
 151   void values_do(ValueVisitor* f);
 152   void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN;
 153 };
 154 
 155 
 156 // InstructionVisitors provide type-based dispatch for instructions.
 157 // For each concrete Instruction class X, a virtual function do_X is
 158 // provided. Functionality that needs to be implemented for all classes
 159 // (e.g., printing, code generation) is factored out into a specialised
 160 // visitor instead of added to the Instruction classes itself.
 161 
 162 class InstructionVisitor: public StackObj {
 163  public:
 164   virtual void do_Phi            (Phi*             x) = 0;
 165   virtual void do_Local          (Local*           x) = 0;
 166   virtual void do_Constant       (Constant*        x) = 0;
 167   virtual void do_LoadField      (LoadField*       x) = 0;
 168   virtual void do_StoreField     (StoreField*      x) = 0;
 169   virtual void do_ArrayLength    (ArrayLength*     x) = 0;
 170   virtual void do_LoadIndexed    (LoadIndexed*     x) = 0;
 171   virtual void do_StoreIndexed   (StoreIndexed*    x) = 0;
 172   virtual void do_NegateOp       (NegateOp*        x) = 0;
 173   virtual void do_ArithmeticOp   (ArithmeticOp*    x) = 0;
 174   virtual void do_ShiftOp        (ShiftOp*         x) = 0;
 175   virtual void do_LogicOp        (LogicOp*         x) = 0;
 176   virtual void do_CompareOp      (CompareOp*       x) = 0;
 177   virtual void do_IfOp           (IfOp*            x) = 0;
 178   virtual void do_Convert        (Convert*         x) = 0;
 179   virtual void do_NullCheck      (NullCheck*       x) = 0;
 180   virtual void do_TypeCast       (TypeCast*        x) = 0;
 181   virtual void do_Invoke         (Invoke*          x) = 0;
 182   virtual void do_NewInstance    (NewInstance*     x) = 0;
 183   virtual void do_NewValueTypeInstance(NewValueTypeInstance* x) = 0;
 184   virtual void do_NewTypeArray   (NewTypeArray*    x) = 0;
 185   virtual void do_NewObjectArray (NewObjectArray*  x) = 0;
 186   virtual void do_NewMultiArray  (NewMultiArray*   x) = 0;
 187   virtual void do_WithField      (WithField*       x) = 0;
 188   virtual void do_DefaultValue   (DefaultValue*    x) = 0;
 189   virtual void do_CheckCast      (CheckCast*       x) = 0;
 190   virtual void do_InstanceOf     (InstanceOf*      x) = 0;
 191   virtual void do_MonitorEnter   (MonitorEnter*    x) = 0;
 192   virtual void do_MonitorExit    (MonitorExit*     x) = 0;
 193   virtual void do_Intrinsic      (Intrinsic*       x) = 0;
 194   virtual void do_BlockBegin     (BlockBegin*      x) = 0;
 195   virtual void do_Goto           (Goto*            x) = 0;
 196   virtual void do_If             (If*              x) = 0;
 197   virtual void do_IfInstanceOf   (IfInstanceOf*    x) = 0;
 198   virtual void do_TableSwitch    (TableSwitch*     x) = 0;
 199   virtual void do_LookupSwitch   (LookupSwitch*    x) = 0;
 200   virtual void do_Return         (Return*          x) = 0;
 201   virtual void do_Throw          (Throw*           x) = 0;
 202   virtual void do_Base           (Base*            x) = 0;
 203   virtual void do_OsrEntry       (OsrEntry*        x) = 0;
 204   virtual void do_ExceptionObject(ExceptionObject* x) = 0;
 205   virtual void do_RoundFP        (RoundFP*         x) = 0;
 206   virtual void do_UnsafeGetRaw   (UnsafeGetRaw*    x) = 0;
 207   virtual void do_UnsafePutRaw   (UnsafePutRaw*    x) = 0;
 208   virtual void do_UnsafeGetObject(UnsafeGetObject* x) = 0;
 209   virtual void do_UnsafePutObject(UnsafePutObject* x) = 0;
 210   virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) = 0;
 211   virtual void do_ProfileCall    (ProfileCall*     x) = 0;
 212   virtual void do_ProfileReturnType (ProfileReturnType*  x) = 0;
 213   virtual void do_ProfileInvoke  (ProfileInvoke*   x) = 0;
 214   virtual void do_RuntimeCall    (RuntimeCall*     x) = 0;
 215   virtual void do_MemBar         (MemBar*          x) = 0;
 216   virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0;
 217 #ifdef ASSERT
 218   virtual void do_Assert         (Assert*          x) = 0;
 219 #endif
 220 };
 221 
 222 
 223 // Hashing support
 224 //
 225 // Note: This hash functions affect the performance
 226 //       of ValueMap - make changes carefully!
 227 
 228 #define HASH1(x1            )                    ((intx)(x1))
 229 #define HASH2(x1, x2        )                    ((HASH1(x1        ) << 7) ^ HASH1(x2))
 230 #define HASH3(x1, x2, x3    )                    ((HASH2(x1, x2    ) << 7) ^ HASH1(x3))
 231 #define HASH4(x1, x2, x3, x4)                    ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))
 232 
 233 
 234 // The following macros are used to implement instruction-specific hashing.
 235 // By default, each instruction implements hash() and is_equal(Value), used
 236 // for value numbering/common subexpression elimination. The default imple-
 237 // mentation disables value numbering. Each instruction which can be value-
 238 // numbered, should define corresponding hash() and is_equal(Value) functions
 239 // via the macros below. The f arguments specify all the values/op codes, etc.
 240 // that need to be identical for two instructions to be identical.
 241 //
 242 // Note: The default implementation of hash() returns 0 in order to indicate
 243 //       that the instruction should not be considered for value numbering.
 244 //       The currently used hash functions do not guarantee that never a 0
 245 //       is produced. While this is still correct, it may be a performance
 246 //       bug (no value numbering for that node). However, this situation is
 247 //       so unlikely, that we are not going to handle it specially.
 248 
 249 #define HASHING1(class_name, enabled, f1)             \
 250   virtual intx hash() const {                         \
 251     return (enabled) ? HASH2(name(), f1) : 0;         \
 252   }                                                   \
 253   virtual bool is_equal(Value v) const {              \
 254     if (!(enabled)  ) return false;                   \
 255     class_name* _v = v->as_##class_name();            \
 256     if (_v == NULL  ) return false;                   \
 257     if (f1 != _v->f1) return false;                   \
 258     return true;                                      \
 259   }                                                   \
 260 
 261 
 262 #define HASHING2(class_name, enabled, f1, f2)         \
 263   virtual intx hash() const {                         \
 264     return (enabled) ? HASH3(name(), f1, f2) : 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     return true;                                      \
 273   }                                                   \
 274 
 275 
 276 #define HASHING3(class_name, enabled, f1, f2, f3)     \
 277   virtual intx hash() const {                          \
 278     return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
 279   }                                                   \
 280   virtual bool is_equal(Value v) const {              \
 281     if (!(enabled)  ) return false;                   \
 282     class_name* _v = v->as_##class_name();            \
 283     if (_v == NULL  ) return false;                   \
 284     if (f1 != _v->f1) return false;                   \
 285     if (f2 != _v->f2) return false;                   \
 286     if (f3 != _v->f3) return false;                   \
 287     return true;                                      \
 288   }                                                   \
 289 
 290 
 291 // The mother of all instructions...
 292 
 293 class Instruction: public CompilationResourceObj {
 294  private:
 295   int          _id;                              // the unique instruction id
 296 #ifndef PRODUCT
 297   int          _printable_bci;                   // the bci of the instruction for printing
 298 #endif
 299   int          _use_count;                       // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1
 300   int          _pin_state;                       // set of PinReason describing the reason for pinning
 301   ValueType*   _type;                            // the instruction value type
 302   Instruction* _next;                            // the next instruction if any (NULL for BlockEnd instructions)
 303   Instruction* _subst;                           // the substitution instruction if any
 304   LIR_Opr      _operand;                         // LIR specific information
 305   unsigned int _flags;                           // Flag bits
 306 
 307   ValueStack*  _state_before;                    // Copy of state with input operands still on stack (or NULL)
 308   ValueStack*  _exception_state;                 // Copy of state for exception handling
 309   XHandlers*   _exception_handlers;              // Flat list of exception handlers covering this instruction
 310 
 311   friend class UseCountComputer;
 312   friend class BlockBegin;
 313 
 314   void update_exception_state(ValueStack* state);
 315 
 316  protected:
 317   BlockBegin*  _block;                           // Block that contains this instruction
 318 
 319   void set_type(ValueType* type) {
 320     assert(type != NULL, "type must exist");
 321     _type = type;
 322   }
 323 
 324   // Helper class to keep track of which arguments need a null check
 325   class ArgsNonNullState {
 326   private:
 327     int _nonnull_state; // mask identifying which args are nonnull
 328   public:
 329     ArgsNonNullState()
 330       : _nonnull_state(AllBits) {}
 331 
 332     // Does argument number i needs a null check?
 333     bool arg_needs_null_check(int i) const {
 334       // No data is kept for arguments starting at position 33 so
 335       // conservatively assume that they need a null check.
 336       if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
 337         return is_set_nth_bit(_nonnull_state, i);
 338       }
 339       return true;
 340     }
 341 
 342     // Set whether argument number i needs a null check or not
 343     void set_arg_needs_null_check(int i, bool check) {
 344       if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
 345         if (check) {
 346           _nonnull_state |= nth_bit(i);
 347         } else {
 348           _nonnull_state &= ~(nth_bit(i));
 349         }
 350       }
 351     }
 352   };
 353 
 354  public:
 355   void* operator new(size_t size) throw() {
 356     Compilation* c = Compilation::current();
 357     void* res = c->arena()->Amalloc(size);
 358     ((Instruction*)res)->_id = c->get_next_id();
 359     return res;
 360   }
 361 
 362   static const int no_bci = -99;
 363 
 364   enum InstructionFlag {
 365     NeedsNullCheckFlag = 0,
 366     NeverNullFlag,          // For "Q" signatures
 367     CanTrapFlag,
 368     DirectCompareFlag,
 369     IsEliminatedFlag,
 370     IsSafepointFlag,
 371     IsStaticFlag,
 372     IsStrictfpFlag,
 373     NeedsStoreCheckFlag,
 374     NeedsWriteBarrierFlag,
 375     PreservesStateFlag,
 376     TargetIsFinalFlag,
 377     TargetIsLoadedFlag,
 378     TargetIsStrictfpFlag,
 379     UnorderedIsTrueFlag,
 380     NeedsPatchingFlag,
 381     ThrowIncompatibleClassChangeErrorFlag,
 382     InvokeSpecialReceiverCheckFlag,
 383     ProfileMDOFlag,
 384     IsLinkedInBlockFlag,
 385     NeedsRangeCheckFlag,
 386     InWorkListFlag,
 387     DeoptimizeOnException,
 388     InstructionLastFlag
 389   };
 390 
 391  public:
 392   bool check_flag(InstructionFlag id) const      { return (_flags & (1 << id)) != 0;    }
 393   void set_flag(InstructionFlag id, bool f)      { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); };
 394 
 395   // 'globally' used condition values
 396   enum Condition {
 397     eql, neq, lss, leq, gtr, geq, aeq, beq
 398   };
 399 
 400   // Instructions may be pinned for many reasons and under certain conditions
 401   // with enough knowledge it's possible to safely unpin them.
 402   enum PinReason {
 403       PinUnknown           = 1 << 0
 404     , PinExplicitNullCheck = 1 << 3
 405     , PinStackForStateSplit= 1 << 12
 406     , PinStateSplitConstructor= 1 << 13
 407     , PinGlobalValueNumbering= 1 << 14
 408   };
 409 
 410   static Condition mirror(Condition cond);
 411   static Condition negate(Condition cond);
 412 
 413   // initialization
 414   static int number_of_instructions() {
 415     return Compilation::current()->number_of_instructions();
 416   }
 417 
 418   // creation
 419   Instruction(ValueType* type, ValueStack* state_before = NULL, bool type_is_constant = false)
 420   :
 421 #ifndef PRODUCT
 422   _printable_bci(-99),
 423 #endif
 424     _use_count(0)
 425   , _pin_state(0)
 426   , _type(type)
 427   , _next(NULL)
 428   , _subst(NULL)
 429   , _operand(LIR_OprFact::illegalOpr)
 430   , _flags(0)
 431   , _state_before(state_before)
 432   , _exception_handlers(NULL)
 433   , _block(NULL)
 434   {
 435     check_state(state_before);
 436     assert(type != NULL && (!type->is_constant() || type_is_constant), "type must exist");
 437     update_exception_state(_state_before);
 438   }
 439 
 440   // accessors
 441   int id() const                                 { return _id; }
 442 #ifndef PRODUCT
 443   bool has_printable_bci() const                 { return _printable_bci != -99; }
 444   int printable_bci() const                      { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
 445   void set_printable_bci(int bci)                { _printable_bci = bci; }
 446 #endif
 447   int dominator_depth();
 448   int use_count() const                          { return _use_count; }
 449   int pin_state() const                          { return _pin_state; }
 450   bool is_pinned() const                         { return _pin_state != 0 || PinAllInstructions; }
 451   ValueType* type() const                        { return _type; }
 452   BlockBegin *block() const                      { return _block; }
 453   Instruction* prev();                           // use carefully, expensive operation
 454   Instruction* next() const                      { return _next; }
 455   bool has_subst() const                         { return _subst != NULL; }
 456   Instruction* subst()                           { return _subst == NULL ? this : _subst->subst(); }
 457   LIR_Opr operand() const                        { return _operand; }
 458 
 459   void set_needs_null_check(bool f)              { set_flag(NeedsNullCheckFlag, f); }
 460   bool needs_null_check() const                  { return check_flag(NeedsNullCheckFlag); }
 461   void set_never_null(bool f)                    { set_flag(NeverNullFlag, f); }
 462   bool is_never_null() const                     { return check_flag(NeverNullFlag); }
 463   bool is_linked() const                         { return check_flag(IsLinkedInBlockFlag); }
 464   bool can_be_linked()                           { return as_Local() == NULL && as_Phi() == NULL; }
 465 
 466   bool has_uses() const                          { return use_count() > 0; }
 467   ValueStack* state_before() const               { return _state_before; }
 468   ValueStack* exception_state() const            { return _exception_state; }
 469   virtual bool needs_exception_state() const     { return true; }
 470   XHandlers* exception_handlers() const          { return _exception_handlers; }
 471   ciKlass* as_loaded_klass_or_null() const;
 472 
 473   // manipulation
 474   void pin(PinReason reason)                     { _pin_state |= reason; }
 475   void pin()                                     { _pin_state |= PinUnknown; }
 476   // DANGEROUS: only used by EliminateStores
 477   void unpin(PinReason reason)                   { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
 478 
 479   Instruction* set_next(Instruction* next) {
 480     assert(next->has_printable_bci(), "_printable_bci should have been set");
 481     assert(next != NULL, "must not be NULL");
 482     assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");
 483     assert(next->can_be_linked(), "shouldn't link these instructions into list");
 484 
 485     BlockBegin *block = this->block();
 486     next->_block = block;
 487 
 488     next->set_flag(Instruction::IsLinkedInBlockFlag, true);
 489     _next = next;
 490     return next;
 491   }
 492 
 493   Instruction* set_next(Instruction* next, int bci) {
 494 #ifndef PRODUCT
 495     next->set_printable_bci(bci);
 496 #endif
 497     return set_next(next);
 498   }
 499 
 500   // when blocks are merged
 501   void fixup_block_pointers() {
 502     Instruction *cur = next()->next(); // next()'s block is set in set_next
 503     while (cur && cur->_block != block()) {
 504       cur->_block = block();
 505       cur = cur->next();
 506     }
 507   }
 508 
 509   Instruction *insert_after(Instruction *i) {
 510     Instruction* n = _next;
 511     set_next(i);
 512     i->set_next(n);
 513     return _next;
 514   }
 515 
 516   bool is_loaded_flattened_array() const;
 517   bool maybe_flattened_array();
 518   bool maybe_null_free_array();
 519 
 520   Instruction *insert_after_same_bci(Instruction *i) {
 521 #ifndef PRODUCT
 522     i->set_printable_bci(printable_bci());
 523 #endif
 524     return insert_after(i);
 525   }
 526 
 527   void set_subst(Instruction* subst)             {
 528     assert(subst == NULL ||
 529            type()->base() == subst->type()->base() ||
 530            subst->type()->base() == illegalType, "type can't change");
 531     _subst = subst;
 532   }
 533   void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
 534   void set_exception_state(ValueStack* s)        { check_state(s); _exception_state = s; }
 535   void set_state_before(ValueStack* s)           { check_state(s); _state_before = s; }
 536 
 537   // machine-specifics
 538   void set_operand(LIR_Opr operand)              { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
 539   void clear_operand()                           { _operand = LIR_OprFact::illegalOpr; }
 540 
 541   // generic
 542   virtual Instruction*      as_Instruction()     { return this; } // to satisfy HASHING1 macro
 543   virtual Phi*              as_Phi()             { return NULL; }
 544   virtual Local*            as_Local()           { return NULL; }
 545   virtual Constant*         as_Constant()        { return NULL; }
 546   virtual AccessField*      as_AccessField()     { return NULL; }
 547   virtual LoadField*        as_LoadField()       { return NULL; }
 548   virtual StoreField*       as_StoreField()      { return NULL; }
 549   virtual AccessArray*      as_AccessArray()     { return NULL; }
 550   virtual ArrayLength*      as_ArrayLength()     { return NULL; }
 551   virtual AccessIndexed*    as_AccessIndexed()   { return NULL; }
 552   virtual LoadIndexed*      as_LoadIndexed()     { return NULL; }
 553   virtual StoreIndexed*     as_StoreIndexed()    { return NULL; }
 554   virtual NegateOp*         as_NegateOp()        { return NULL; }
 555   virtual Op2*              as_Op2()             { return NULL; }
 556   virtual ArithmeticOp*     as_ArithmeticOp()    { return NULL; }
 557   virtual ShiftOp*          as_ShiftOp()         { return NULL; }
 558   virtual LogicOp*          as_LogicOp()         { return NULL; }
 559   virtual CompareOp*        as_CompareOp()       { return NULL; }
 560   virtual IfOp*             as_IfOp()            { return NULL; }
 561   virtual Convert*          as_Convert()         { return NULL; }
 562   virtual NullCheck*        as_NullCheck()       { return NULL; }
 563   virtual OsrEntry*         as_OsrEntry()        { return NULL; }
 564   virtual StateSplit*       as_StateSplit()      { return NULL; }
 565   virtual Invoke*           as_Invoke()          { return NULL; }
 566   virtual NewInstance*      as_NewInstance()     { return NULL; }
 567   virtual NewValueTypeInstance* as_NewValueTypeInstance() { return NULL; }
 568   virtual NewArray*         as_NewArray()        { return NULL; }
 569   virtual NewTypeArray*     as_NewTypeArray()    { return NULL; }
 570   virtual NewObjectArray*   as_NewObjectArray()  { return NULL; }
 571   virtual NewMultiArray*    as_NewMultiArray()   { return NULL; }
 572   virtual WithField*        as_WithField()       { return NULL; }
 573   virtual DefaultValue*     as_DefaultValue()    { return NULL; }
 574   virtual TypeCheck*        as_TypeCheck()       { return NULL; }
 575   virtual CheckCast*        as_CheckCast()       { return NULL; }
 576   virtual InstanceOf*       as_InstanceOf()      { return NULL; }
 577   virtual TypeCast*         as_TypeCast()        { return NULL; }
 578   virtual AccessMonitor*    as_AccessMonitor()   { return NULL; }
 579   virtual MonitorEnter*     as_MonitorEnter()    { return NULL; }
 580   virtual MonitorExit*      as_MonitorExit()     { return NULL; }
 581   virtual Intrinsic*        as_Intrinsic()       { return NULL; }
 582   virtual BlockBegin*       as_BlockBegin()      { return NULL; }
 583   virtual BlockEnd*         as_BlockEnd()        { return NULL; }
 584   virtual Goto*             as_Goto()            { return NULL; }
 585   virtual If*               as_If()              { return NULL; }
 586   virtual IfInstanceOf*     as_IfInstanceOf()    { return NULL; }
 587   virtual TableSwitch*      as_TableSwitch()     { return NULL; }
 588   virtual LookupSwitch*     as_LookupSwitch()    { return NULL; }
 589   virtual Return*           as_Return()          { return NULL; }
 590   virtual Throw*            as_Throw()           { return NULL; }
 591   virtual Base*             as_Base()            { return NULL; }
 592   virtual RoundFP*          as_RoundFP()         { return NULL; }
 593   virtual ExceptionObject*  as_ExceptionObject() { return NULL; }
 594   virtual UnsafeOp*         as_UnsafeOp()        { return NULL; }
 595   virtual ProfileInvoke*    as_ProfileInvoke()   { return NULL; }
 596   virtual RangeCheckPredicate* as_RangeCheckPredicate() { return NULL; }
 597 
 598 #ifdef ASSERT
 599   virtual Assert*           as_Assert()          { return NULL; }
 600 #endif
 601 
 602   virtual void visit(InstructionVisitor* v)      = 0;
 603 
 604   virtual bool can_trap() const                  { return false; }
 605 
 606   virtual void input_values_do(ValueVisitor* f)   = 0;
 607   virtual void state_values_do(ValueVisitor* f);
 608   virtual void other_values_do(ValueVisitor* f)   { /* usually no other - override on demand */ }
 609           void       values_do(ValueVisitor* f)   { input_values_do(f); state_values_do(f); other_values_do(f); }
 610 
 611   virtual ciType* exact_type() const;
 612   virtual ciType* declared_type() const          { return NULL; }
 613 
 614   // hashing
 615   virtual const char* name() const               = 0;
 616   HASHING1(Instruction, false, id())             // hashing disabled by default
 617 
 618   // debugging
 619   static void check_state(ValueStack* state)     PRODUCT_RETURN;
 620   void print()                                   PRODUCT_RETURN;
 621   void print_line()                              PRODUCT_RETURN;
 622   void print(InstructionPrinter& ip)             PRODUCT_RETURN;
 623 };
 624 
 625 
 626 // The following macros are used to define base (i.e., non-leaf)
 627 // and leaf instruction classes. They define class-name related
 628 // generic functionality in one place.
 629 
 630 #define BASE(class_name, super_class_name)       \
 631   class class_name: public super_class_name {    \
 632    public:                                       \
 633     virtual class_name* as_##class_name()        { return this; }              \
 634 
 635 
 636 #define LEAF(class_name, super_class_name)       \
 637   BASE(class_name, super_class_name)             \
 638    public:                                       \
 639     virtual const char* name() const             { return #class_name; }       \
 640     virtual void visit(InstructionVisitor* v)    { v->do_##class_name(this); } \
 641 
 642 
 643 // Debugging support
 644 
 645 
 646 #ifdef ASSERT
 647 class AssertValues: public ValueVisitor {
 648   void visit(Value* x)             { assert((*x) != NULL, "value must exist"); }
 649 };
 650   #define ASSERT_VALUES                          { AssertValues assert_value; values_do(&assert_value); }
 651 #else
 652   #define ASSERT_VALUES
 653 #endif // ASSERT
 654 
 655 
 656 // A Phi is a phi function in the sense of SSA form. It stands for
 657 // the value of a local variable at the beginning of a join block.
 658 // A Phi consists of n operands, one for every incoming branch.
 659 
 660 LEAF(Phi, Instruction)
 661  private:
 662   int         _pf_flags; // the flags of the phi function
 663   int         _index;    // to value on operand stack (index < 0) or to local
 664  public:
 665   // creation
 666   Phi(ValueType* type, BlockBegin* b, int index)
 667   : Instruction(type->base())
 668   , _pf_flags(0)
 669   , _index(index)
 670   {
 671     _block = b;
 672     NOT_PRODUCT(set_printable_bci(Value(b)->printable_bci()));
 673     if (type->is_illegal()) {
 674       make_illegal();
 675     }
 676   }
 677 
 678   // flags
 679   enum Flag {
 680     no_flag         = 0,
 681     visited         = 1 << 0,
 682     cannot_simplify = 1 << 1
 683   };
 684 
 685   // accessors
 686   bool  is_local() const          { return _index >= 0; }
 687   bool  is_on_stack() const       { return !is_local(); }
 688   int   local_index() const       { assert(is_local(), ""); return _index; }
 689   int   stack_index() const       { assert(is_on_stack(), ""); return -(_index+1); }
 690 
 691   Value operand_at(int i) const;
 692   int   operand_count() const;
 693 
 694   void   set(Flag f)              { _pf_flags |=  f; }
 695   void   clear(Flag f)            { _pf_flags &= ~f; }
 696   bool   is_set(Flag f) const     { return (_pf_flags & f) != 0; }
 697 
 698   // Invalidates phis corresponding to merges of locals of two different types
 699   // (these should never be referenced, otherwise the bytecodes are illegal)
 700   void   make_illegal() {
 701     set(cannot_simplify);
 702     set_type(illegalType);
 703   }
 704 
 705   bool is_illegal() const {
 706     return type()->is_illegal();
 707   }
 708 
 709   // generic
 710   virtual void input_values_do(ValueVisitor* f) {
 711   }
 712 };
 713 
 714 
 715 // A local is a placeholder for an incoming argument to a function call.
 716 LEAF(Local, Instruction)
 717  private:
 718   int      _java_index;                          // the local index within the method to which the local belongs
 719   bool     _is_receiver;                         // if local variable holds the receiver: "this" for non-static methods
 720   ciType*  _declared_type;
 721  public:
 722   // creation
 723   Local(ciType* declared, ValueType* type, int index, bool receiver, bool never_null)
 724     : Instruction(type)
 725     , _java_index(index)
 726     , _is_receiver(receiver)
 727     , _declared_type(declared)
 728   {
 729     set_never_null(never_null);
 730     NOT_PRODUCT(set_printable_bci(-1));
 731   }
 732 
 733   // accessors
 734   int java_index() const                         { return _java_index; }
 735   bool is_receiver() const                       { return _is_receiver; }
 736 
 737   virtual ciType* declared_type() const          { return _declared_type; }
 738 
 739   // generic
 740   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
 741 };
 742 
 743 
 744 LEAF(Constant, Instruction)
 745  public:
 746   // creation
 747   Constant(ValueType* type):
 748       Instruction(type, NULL, /*type_is_constant*/ true)
 749   {
 750     assert(type->is_constant(), "must be a constant");
 751   }
 752 
 753   Constant(ValueType* type, ValueStack* state_before):
 754     Instruction(type, state_before, /*type_is_constant*/ true)
 755   {
 756     assert(state_before != NULL, "only used for constants which need patching");
 757     assert(type->is_constant(), "must be a constant");
 758     // since it's patching it needs to be pinned
 759     pin();
 760   }
 761 
 762   // generic
 763   virtual bool can_trap() const                  { return state_before() != NULL; }
 764   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
 765 
 766   virtual intx hash() const;
 767   virtual bool is_equal(Value v) const;
 768 
 769   virtual ciType* exact_type() const;
 770 
 771   enum CompareResult { not_comparable = -1, cond_false, cond_true };
 772 
 773   virtual CompareResult compare(Instruction::Condition condition, Value right) const;
 774   BlockBegin* compare(Instruction::Condition cond, Value right,
 775                       BlockBegin* true_sux, BlockBegin* false_sux) const {
 776     switch (compare(cond, right)) {
 777     case not_comparable:
 778       return NULL;
 779     case cond_false:
 780       return false_sux;
 781     case cond_true:
 782       return true_sux;
 783     default:
 784       ShouldNotReachHere();
 785       return NULL;
 786     }
 787   }
 788 };
 789 
 790 
 791 BASE(AccessField, Instruction)
 792  private:
 793   Value       _obj;
 794   int         _offset;
 795   ciField*    _field;
 796   NullCheck*  _explicit_null_check;              // For explicit null check elimination
 797 
 798  public:
 799   // creation
 800   AccessField(Value obj, int offset, ciField* field, bool is_static,
 801               ValueStack* state_before, bool needs_patching)
 802   : Instruction(as_ValueType(field->type()->basic_type()), state_before)
 803   , _obj(obj)
 804   , _offset(offset)
 805   , _field(field)
 806   , _explicit_null_check(NULL)
 807   {
 808     set_needs_null_check(!is_static);
 809     set_flag(IsStaticFlag, is_static);
 810     set_flag(NeedsPatchingFlag, needs_patching);
 811     ASSERT_VALUES
 812     // pin of all instructions with memory access
 813     pin();
 814   }
 815 
 816   // accessors
 817   Value obj() const                              { return _obj; }
 818   int offset() const                             { return _offset; }
 819   ciField* field() const                         { return _field; }
 820   BasicType field_type() const                   { return _field->type()->basic_type(); }
 821   bool is_static() const                         { return check_flag(IsStaticFlag); }
 822   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 823   bool needs_patching() const                    { return check_flag(NeedsPatchingFlag); }
 824 
 825   // Unresolved getstatic and putstatic can cause initialization.
 826   // Technically it occurs at the Constant that materializes the base
 827   // of the static fields but it's simpler to model it here.
 828   bool is_init_point() const                     { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); }
 829 
 830   // manipulation
 831 
 832   // Under certain circumstances, if a previous NullCheck instruction
 833   // proved the target object non-null, we can eliminate the explicit
 834   // null check and do an implicit one, simply specifying the debug
 835   // information from the NullCheck. This field should only be consulted
 836   // if needs_null_check() is true.
 837   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 838 
 839   // generic
 840   virtual bool can_trap() const                  { return needs_null_check() || needs_patching(); }
 841   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_obj); }
 842 };
 843 
 844 
 845 LEAF(LoadField, AccessField)
 846  public:
 847   // creation
 848   LoadField(Value obj, int offset, ciField* field, bool is_static,
 849             ValueStack* state_before, bool needs_patching,
 850             ciValueKlass* value_klass = NULL, Value default_value = NULL )
 851   : AccessField(obj, offset, field, is_static, state_before, needs_patching)
 852   {}
 853 
 854   ciType* declared_type() const;
 855 
 856   // generic
 857   HASHING2(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset())  // cannot be eliminated if needs patching or if volatile
 858 };
 859 
 860 
 861 LEAF(StoreField, AccessField)
 862  private:
 863   Value _value;
 864 
 865  public:
 866   // creation
 867   StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
 868              ValueStack* state_before, bool needs_patching)
 869   : AccessField(obj, offset, field, is_static, state_before, needs_patching)
 870   , _value(value)
 871   {
 872     set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
 873     ASSERT_VALUES
 874     pin();
 875   }
 876 
 877   // accessors
 878   Value value() const                            { return _value; }
 879   bool needs_write_barrier() const               { return check_flag(NeedsWriteBarrierFlag); }
 880 
 881   // generic
 882   virtual void input_values_do(ValueVisitor* f)   { AccessField::input_values_do(f); f->visit(&_value); }
 883 };
 884 
 885 
 886 BASE(AccessArray, Instruction)
 887  private:
 888   Value       _array;
 889 
 890  public:
 891   // creation
 892   AccessArray(ValueType* type, Value array, ValueStack* state_before)
 893   : Instruction(type, state_before)
 894   , _array(array)
 895   {
 896     set_needs_null_check(true);
 897     ASSERT_VALUES
 898     pin(); // instruction with side effect (null exception or range check throwing)
 899   }
 900 
 901   Value array() const                            { return _array; }
 902 
 903   // generic
 904   virtual bool can_trap() const                  { return needs_null_check(); }
 905   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_array); }
 906 };
 907 
 908 
 909 LEAF(ArrayLength, AccessArray)
 910  private:
 911   NullCheck*  _explicit_null_check;              // For explicit null check elimination
 912 
 913  public:
 914   // creation
 915   ArrayLength(Value array, ValueStack* state_before)
 916   : AccessArray(intType, array, state_before)
 917   , _explicit_null_check(NULL) {}
 918 
 919   // accessors
 920   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 921 
 922   // setters
 923   // See LoadField::set_explicit_null_check for documentation
 924   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 925 
 926   // generic
 927   HASHING1(ArrayLength, true, array()->subst())
 928 };
 929 
 930 
 931 BASE(AccessIndexed, AccessArray)
 932  private:
 933   Value     _index;
 934   Value     _length;
 935   BasicType _elt_type;
 936   bool      _mismatched;
 937 
 938  public:
 939   // creation
 940   AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched)
 941   : AccessArray(as_ValueType(elt_type), array, state_before)
 942   , _index(index)
 943   , _length(length)
 944   , _elt_type(elt_type)
 945   , _mismatched(mismatched)
 946   {
 947     set_flag(Instruction::NeedsRangeCheckFlag, true);
 948     ASSERT_VALUES
 949   }
 950 
 951   // accessors
 952   Value index() const                            { return _index; }
 953   Value length() const                           { return _length; }
 954   BasicType elt_type() const                     { return _elt_type; }
 955   bool mismatched() const                        { return _mismatched; }
 956 
 957   void clear_length()                            { _length = NULL; }
 958   // perform elimination of range checks involving constants
 959   bool compute_needs_range_check();
 960 
 961   // generic
 962   virtual void input_values_do(ValueVisitor* f)   { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }
 963 };
 964 
 965 
 966 LEAF(LoadIndexed, AccessIndexed)
 967  private:
 968   NullCheck*  _explicit_null_check;              // For explicit null check elimination
 969   NewValueTypeInstance* _vt;
 970 
 971  public:
 972   // creation
 973   LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched = false)
 974   : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
 975   , _explicit_null_check(NULL), _vt(NULL) {}
 976 
 977   // accessors
 978   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
 979 
 980   // setters
 981   // See LoadField::set_explicit_null_check for documentation
 982   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
 983 
 984   ciType* exact_type() const;
 985   ciType* declared_type() const;
 986 
 987   NewValueTypeInstance* vt() { return _vt; }
 988   void set_vt(NewValueTypeInstance* vt) { _vt = vt; }
 989 
 990   // generic
 991   HASHING2(LoadIndexed, true, array()->subst(), index()->subst())
 992 };
 993 
 994 
 995 LEAF(StoreIndexed, AccessIndexed)
 996  private:
 997   Value       _value;
 998 
 999   ciMethod* _profiled_method;
1000   int       _profiled_bci;
1001   bool      _check_boolean;
1002 
1003  public:
1004   // creation
1005   StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before,
1006                bool check_boolean, bool mismatched = false)
1007   : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
1008   , _value(value), _profiled_method(NULL), _profiled_bci(0), _check_boolean(check_boolean)
1009   {
1010     set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
1011     set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
1012     ASSERT_VALUES
1013     pin();
1014   }
1015 
1016   // accessors
1017   Value value() const                            { return _value; }
1018   bool needs_write_barrier() const               { return check_flag(NeedsWriteBarrierFlag); }
1019   bool needs_store_check() const                 { return check_flag(NeedsStoreCheckFlag); }
1020   bool check_boolean() const                     { return _check_boolean; }
1021   // Helpers for MethodData* profiling
1022   void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
1023   void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
1024   void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
1025   bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
1026   ciMethod* profiled_method() const                  { return _profiled_method;     }
1027   int       profiled_bci() const                     { return _profiled_bci;        }
1028   // Flattened array support
1029   bool is_exact_flattened_array_store() const;
1030   // generic
1031   virtual void input_values_do(ValueVisitor* f)   { AccessIndexed::input_values_do(f); f->visit(&_value); }
1032 };
1033 
1034 
1035 LEAF(NegateOp, Instruction)
1036  private:
1037   Value _x;
1038 
1039  public:
1040   // creation
1041   NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
1042     ASSERT_VALUES
1043   }
1044 
1045   // accessors
1046   Value x() const                                { return _x; }
1047 
1048   // generic
1049   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_x); }
1050 };
1051 
1052 
1053 BASE(Op2, Instruction)
1054  private:
1055   Bytecodes::Code _op;
1056   Value           _x;
1057   Value           _y;
1058 
1059  public:
1060   // creation
1061   Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = NULL)
1062   : Instruction(type, state_before)
1063   , _op(op)
1064   , _x(x)
1065   , _y(y)
1066   {
1067     ASSERT_VALUES
1068   }
1069 
1070   // accessors
1071   Bytecodes::Code op() const                     { return _op; }
1072   Value x() const                                { return _x; }
1073   Value y() const                                { return _y; }
1074 
1075   // manipulators
1076   void swap_operands() {
1077     assert(is_commutative(), "operation must be commutative");
1078     Value t = _x; _x = _y; _y = t;
1079   }
1080 
1081   // generic
1082   virtual bool is_commutative() const            { return false; }
1083   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_x); f->visit(&_y); }
1084 };
1085 
1086 
1087 LEAF(ArithmeticOp, Op2)
1088  public:
1089   // creation
1090   ArithmeticOp(Bytecodes::Code op, Value x, Value y, bool is_strictfp, ValueStack* state_before)
1091   : Op2(x->type()->meet(y->type()), op, x, y, state_before)
1092   {
1093     set_flag(IsStrictfpFlag, is_strictfp);
1094     if (can_trap()) pin();
1095   }
1096 
1097   // accessors
1098   bool        is_strictfp() const                { return check_flag(IsStrictfpFlag); }
1099 
1100   // generic
1101   virtual bool is_commutative() const;
1102   virtual bool can_trap() const;
1103   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1104 };
1105 
1106 
1107 LEAF(ShiftOp, Op2)
1108  public:
1109   // creation
1110   ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}
1111 
1112   // generic
1113   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1114 };
1115 
1116 
1117 LEAF(LogicOp, Op2)
1118  public:
1119   // creation
1120   LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}
1121 
1122   // generic
1123   virtual bool is_commutative() const;
1124   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1125 };
1126 
1127 
1128 LEAF(CompareOp, Op2)
1129  public:
1130   // creation
1131   CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1132   : Op2(intType, op, x, y, state_before)
1133   {}
1134 
1135   // generic
1136   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1137 };
1138 
1139 
1140 LEAF(IfOp, Op2)
1141  private:
1142   Value _tval;
1143   Value _fval;
1144   bool _substitutability_check;
1145 
1146  public:
1147   // creation
1148   IfOp(Value x, Condition cond, Value y, Value tval, Value fval, ValueStack* state_before, bool substitutability_check)
1149   : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1150   , _tval(tval)
1151   , _fval(fval)
1152   , _substitutability_check(substitutability_check)
1153   {
1154     ASSERT_VALUES
1155     assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1156     set_state_before(state_before);
1157   }
1158 
1159   // accessors
1160   virtual bool is_commutative() const;
1161   Bytecodes::Code op() const                     { ShouldNotCallThis(); return Bytecodes::_illegal; }
1162   Condition cond() const                         { return (Condition)Op2::op(); }
1163   Value tval() const                             { return _tval; }
1164   Value fval() const                             { return _fval; }
1165   bool substitutability_check() const             { return _substitutability_check; }
1166   // generic
1167   virtual void input_values_do(ValueVisitor* f)   { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1168 };
1169 
1170 
1171 LEAF(Convert, Instruction)
1172  private:
1173   Bytecodes::Code _op;
1174   Value           _value;
1175 
1176  public:
1177   // creation
1178   Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1179     ASSERT_VALUES
1180   }
1181 
1182   // accessors
1183   Bytecodes::Code op() const                     { return _op; }
1184   Value value() const                            { return _value; }
1185 
1186   // generic
1187   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_value); }
1188   HASHING2(Convert, true, op(), value()->subst())
1189 };
1190 
1191 
1192 LEAF(NullCheck, Instruction)
1193  private:
1194   Value       _obj;
1195 
1196  public:
1197   // creation
1198   NullCheck(Value obj, ValueStack* state_before)
1199   : Instruction(obj->type()->base(), state_before)
1200   , _obj(obj)
1201   {
1202     ASSERT_VALUES
1203     set_can_trap(true);
1204     assert(_obj->type()->is_object(), "null check must be applied to objects only");
1205     pin(Instruction::PinExplicitNullCheck);
1206   }
1207 
1208   // accessors
1209   Value obj() const                              { return _obj; }
1210 
1211   // setters
1212   void set_can_trap(bool can_trap)               { set_flag(CanTrapFlag, can_trap); }
1213 
1214   // generic
1215   virtual bool can_trap() const                  { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }
1216   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_obj); }
1217   HASHING1(NullCheck, true, obj()->subst())
1218 };
1219 
1220 
1221 // This node is supposed to cast the type of another node to a more precise
1222 // declared type.
1223 LEAF(TypeCast, Instruction)
1224  private:
1225   ciType* _declared_type;
1226   Value   _obj;
1227 
1228  public:
1229   // The type of this node is the same type as the object type (and it might be constant).
1230   TypeCast(ciType* type, Value obj, ValueStack* state_before)
1231   : Instruction(obj->type(), state_before, obj->type()->is_constant()),
1232     _declared_type(type),
1233     _obj(obj) {}
1234 
1235   // accessors
1236   ciType* declared_type() const                  { return _declared_type; }
1237   Value   obj() const                            { return _obj; }
1238 
1239   // generic
1240   virtual void input_values_do(ValueVisitor* f)  { f->visit(&_obj); }
1241 };
1242 
1243 
1244 BASE(StateSplit, Instruction)
1245  private:
1246   ValueStack* _state;
1247 
1248  protected:
1249   static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);
1250 
1251  public:
1252   // creation
1253   StateSplit(ValueType* type, ValueStack* state_before = NULL)
1254   : Instruction(type, state_before)
1255   , _state(NULL)
1256   {
1257     pin(PinStateSplitConstructor);
1258   }
1259 
1260   // accessors
1261   ValueStack* state() const                      { return _state; }
1262   IRScope* scope() const;                        // the state's scope
1263 
1264   // manipulation
1265   void set_state(ValueStack* state)              { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }
1266 
1267   // generic
1268   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
1269   virtual void state_values_do(ValueVisitor* f);
1270 };
1271 
1272 
1273 LEAF(Invoke, StateSplit)
1274  private:
1275   Bytecodes::Code _code;
1276   Value           _recv;
1277   Values*         _args;
1278   BasicTypeList*  _signature;
1279   int             _vtable_index;
1280   ciMethod*       _target;
1281 
1282  public:
1283   // creation
1284   Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1285          int vtable_index, ciMethod* target, ValueStack* state_before, bool never_null);
1286 
1287   // accessors
1288   Bytecodes::Code code() const                   { return _code; }
1289   Value receiver() const                         { return _recv; }
1290   bool has_receiver() const                      { return receiver() != NULL; }
1291   int number_of_arguments() const                { return _args->length(); }
1292   Value argument_at(int i) const                 { return _args->at(i); }
1293   int vtable_index() const                       { return _vtable_index; }
1294   BasicTypeList* signature() const               { return _signature; }
1295   ciMethod* target() const                       { return _target; }
1296 
1297   ciType* declared_type() const;
1298 
1299   // Returns false if target is not loaded
1300   bool target_is_final() const                   { return check_flag(TargetIsFinalFlag); }
1301   bool target_is_loaded() const                  { return check_flag(TargetIsLoadedFlag); }
1302   // Returns false if target is not loaded
1303   bool target_is_strictfp() const                { return check_flag(TargetIsStrictfpFlag); }
1304 
1305   // JSR 292 support
1306   bool is_invokedynamic() const                  { return code() == Bytecodes::_invokedynamic; }
1307   bool is_method_handle_intrinsic() const        { return target()->is_method_handle_intrinsic(); }
1308 
1309   virtual bool needs_exception_state() const     { return false; }
1310 
1311   // generic
1312   virtual bool can_trap() const                  { return true; }
1313   virtual void input_values_do(ValueVisitor* f) {
1314     StateSplit::input_values_do(f);
1315     if (has_receiver()) f->visit(&_recv);
1316     for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1317   }
1318   virtual void state_values_do(ValueVisitor *f);
1319 };
1320 
1321 
1322 LEAF(NewInstance, StateSplit)
1323  private:
1324   ciInstanceKlass* _klass;
1325   bool _is_unresolved;
1326 
1327  public:
1328   // creation
1329   NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved)
1330   : StateSplit(instanceType, state_before)
1331   , _klass(klass), _is_unresolved(is_unresolved)
1332   {}
1333 
1334   // accessors
1335   ciInstanceKlass* klass() const                 { return _klass; }
1336   bool is_unresolved() const                     { return _is_unresolved; }
1337 
1338   virtual bool needs_exception_state() const     { return false; }
1339 
1340   // generic
1341   virtual bool can_trap() const                  { return true; }
1342   ciType* exact_type() const;
1343   ciType* declared_type() const;
1344 };
1345 
1346 LEAF(NewValueTypeInstance, StateSplit)
1347   bool _is_unresolved;
1348   ciValueKlass* _klass;
1349   Value _depends_on;      // Link to instance on with withfield was called on
1350 
1351 public:
1352 
1353   // Default creation, always allocated for now
1354   NewValueTypeInstance(ciValueKlass* klass, ValueStack* state_before, bool is_unresolved, Value depends_on = NULL)
1355   : StateSplit(instanceType, state_before)
1356    , _is_unresolved(is_unresolved)
1357    , _klass(klass)
1358   {
1359     if (depends_on == NULL) {
1360       _depends_on = this;
1361     } else {
1362       _depends_on = depends_on;
1363     }
1364     set_never_null(true);
1365   }
1366 
1367   // accessors
1368   bool is_unresolved() const                     { return _is_unresolved; }
1369   Value depends_on();
1370 
1371   ciValueKlass* klass() const { return _klass; }
1372 
1373   virtual bool needs_exception_state() const     { return false; }
1374 
1375   // generic
1376   virtual bool can_trap() const                  { return true; }
1377   ciType* exact_type() const;
1378   ciType* declared_type() const;
1379 
1380   // Only done in LIR Generator -> map everything to object
1381   void set_to_object_type() { set_type(instanceType); }
1382 };
1383 
1384 BASE(NewArray, StateSplit)
1385  private:
1386   Value       _length;
1387 
1388  public:
1389   // creation
1390   NewArray(Value length, ValueStack* state_before)
1391   : StateSplit(objectType, state_before)
1392   , _length(length)
1393   {
1394     // Do not ASSERT_VALUES since length is NULL for NewMultiArray
1395   }
1396 
1397   // accessors
1398   Value length() const                           { return _length; }
1399 
1400   virtual bool needs_exception_state() const     { return false; }
1401 
1402   ciType* exact_type() const                     { return NULL; }
1403   ciType* declared_type() const;
1404 
1405   // generic
1406   virtual bool can_trap() const                  { return true; }
1407   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_length); }
1408 };
1409 
1410 
1411 LEAF(NewTypeArray, NewArray)
1412  private:
1413   BasicType _elt_type;
1414 
1415  public:
1416   // creation
1417   NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)
1418   : NewArray(length, state_before)
1419   , _elt_type(elt_type)
1420   {}
1421 
1422   // accessors
1423   BasicType elt_type() const                     { return _elt_type; }
1424   ciType* exact_type() const;
1425 };
1426 
1427 
1428 LEAF(NewObjectArray, NewArray)
1429  private:
1430   ciKlass* _klass;
1431 
1432  public:
1433   // creation
1434   NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before, bool never_null)
1435   : NewArray(length, state_before), _klass(klass) {
1436     set_never_null(never_null);
1437   }
1438 
1439   // accessors
1440   ciKlass* klass() const                         { return _klass; }
1441   ciType* exact_type() const;
1442 };
1443 
1444 
1445 LEAF(NewMultiArray, NewArray)
1446  private:
1447   ciKlass* _klass;
1448   Values*  _dims;
1449 
1450  public:
1451   // creation
1452   NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
1453     ASSERT_VALUES
1454   }
1455 
1456   // accessors
1457   ciKlass* klass() const                         { return _klass; }
1458   Values* dims() const                           { return _dims; }
1459   int rank() const                               { return dims()->length(); }
1460 
1461   // generic
1462   virtual void input_values_do(ValueVisitor* f) {
1463     // NOTE: we do not call NewArray::input_values_do since "length"
1464     // is meaningless for a multi-dimensional array; passing the
1465     // zeroth element down to NewArray as its length is a bad idea
1466     // since there will be a copy in the "dims" array which doesn't
1467     // get updated, and the value must not be traversed twice. Was bug
1468     // - kbr 4/10/2001
1469     StateSplit::input_values_do(f);
1470     for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1471   }
1472 
1473   ciType* exact_type() const;
1474 };
1475 
1476 LEAF(WithField, StateSplit)
1477  public:
1478   // creation
1479   WithField(ValueType* type, ValueStack* state_before)
1480   : StateSplit(type, state_before) {}
1481 };
1482 
1483 LEAF(DefaultValue, StateSplit)
1484  public:
1485   // creation
1486   DefaultValue(ValueType* type, ValueStack* state_before)
1487   : StateSplit(type, state_before) {}
1488 };
1489 
1490 BASE(TypeCheck, StateSplit)
1491  private:
1492   ciKlass*    _klass;
1493   Value       _obj;
1494 
1495   ciMethod* _profiled_method;
1496   int       _profiled_bci;
1497 
1498  public:
1499   // creation
1500   TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1501   : StateSplit(type, state_before), _klass(klass), _obj(obj),
1502     _profiled_method(NULL), _profiled_bci(0) {
1503     ASSERT_VALUES
1504     set_direct_compare(false);
1505   }
1506 
1507   // accessors
1508   ciKlass* klass() const                         { return _klass; }
1509   Value obj() const                              { return _obj; }
1510   bool is_loaded() const                         { return klass() != NULL; }
1511   bool direct_compare() const                    { return check_flag(DirectCompareFlag); }
1512 
1513   // manipulation
1514   void set_direct_compare(bool flag)             { set_flag(DirectCompareFlag, flag); }
1515 
1516   // generic
1517   virtual bool can_trap() const                  { return true; }
1518   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
1519 
1520   // Helpers for MethodData* profiling
1521   void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
1522   void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
1523   void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
1524   bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
1525   ciMethod* profiled_method() const                  { return _profiled_method;     }
1526   int       profiled_bci() const                     { return _profiled_bci;        }
1527 };
1528 
1529 
1530 LEAF(CheckCast, TypeCheck)
1531  public:
1532   // creation
1533   CheckCast(ciKlass* klass, Value obj, ValueStack* state_before, bool never_null = false)
1534   : TypeCheck(klass, obj, objectType, state_before) {
1535     set_never_null(never_null);
1536   }
1537 
1538   void set_incompatible_class_change_check() {
1539     set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1540   }
1541   bool is_incompatible_class_change_check() const {
1542     return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1543   }
1544   void set_invokespecial_receiver_check() {
1545     set_flag(InvokeSpecialReceiverCheckFlag, true);
1546   }
1547   bool is_invokespecial_receiver_check() const {
1548     return check_flag(InvokeSpecialReceiverCheckFlag);
1549   }
1550 
1551   virtual bool needs_exception_state() const {
1552     return !is_invokespecial_receiver_check();
1553   }
1554 
1555   ciType* declared_type() const;
1556 };
1557 
1558 
1559 LEAF(InstanceOf, TypeCheck)
1560  public:
1561   // creation
1562   InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}
1563 
1564   virtual bool needs_exception_state() const     { return false; }
1565 };
1566 
1567 
1568 BASE(AccessMonitor, StateSplit)
1569  private:
1570   Value       _obj;
1571   int         _monitor_no;
1572 
1573  public:
1574   // creation
1575   AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)
1576   : StateSplit(illegalType, state_before)
1577   , _obj(obj)
1578   , _monitor_no(monitor_no)
1579   {
1580     set_needs_null_check(true);
1581     ASSERT_VALUES
1582   }
1583 
1584   // accessors
1585   Value obj() const                              { return _obj; }
1586   int monitor_no() const                         { return _monitor_no; }
1587 
1588   // generic
1589   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
1590 };
1591 
1592 
1593 LEAF(MonitorEnter, AccessMonitor)
1594   bool _maybe_valuetype;
1595  public:
1596   // creation
1597   MonitorEnter(Value obj, int monitor_no, ValueStack* state_before, bool maybe_valuetype)
1598   : AccessMonitor(obj, monitor_no, state_before)
1599   , _maybe_valuetype(maybe_valuetype)
1600   {
1601     ASSERT_VALUES
1602   }
1603 
1604   // accessors
1605   bool maybe_valuetype() const                   { return _maybe_valuetype; }
1606 
1607   // generic
1608   virtual bool can_trap() const                  { return true; }
1609 };
1610 
1611 
1612 LEAF(MonitorExit, AccessMonitor)
1613  public:
1614   // creation
1615   MonitorExit(Value obj, int monitor_no)
1616   : AccessMonitor(obj, monitor_no, NULL)
1617   {
1618     ASSERT_VALUES
1619   }
1620 };
1621 
1622 
1623 LEAF(Intrinsic, StateSplit)
1624  private:
1625   vmIntrinsics::ID _id;
1626   Values*          _args;
1627   Value            _recv;
1628   ArgsNonNullState _nonnull_state;
1629 
1630  public:
1631   // preserves_state can be set to true for Intrinsics
1632   // which are guaranteed to preserve register state across any slow
1633   // cases; setting it to true does not mean that the Intrinsic can
1634   // not trap, only that if we continue execution in the same basic
1635   // block after the Intrinsic, all of the registers are intact. This
1636   // allows load elimination and common expression elimination to be
1637   // performed across the Intrinsic.  The default value is false.
1638   Intrinsic(ValueType* type,
1639             vmIntrinsics::ID id,
1640             Values* args,
1641             bool has_receiver,
1642             ValueStack* state_before,
1643             bool preserves_state,
1644             bool cantrap = true)
1645   : StateSplit(type, state_before)
1646   , _id(id)
1647   , _args(args)
1648   , _recv(NULL)
1649   {
1650     assert(args != NULL, "args must exist");
1651     ASSERT_VALUES
1652     set_flag(PreservesStateFlag, preserves_state);
1653     set_flag(CanTrapFlag,        cantrap);
1654     if (has_receiver) {
1655       _recv = argument_at(0);
1656     }
1657     set_needs_null_check(has_receiver);
1658 
1659     // some intrinsics can't trap, so don't force them to be pinned
1660     if (!can_trap() && !vmIntrinsics::should_be_pinned(_id)) {
1661       unpin(PinStateSplitConstructor);
1662     }
1663   }
1664 
1665   // accessors
1666   vmIntrinsics::ID id() const                    { return _id; }
1667   int number_of_arguments() const                { return _args->length(); }
1668   Value argument_at(int i) const                 { return _args->at(i); }
1669 
1670   bool has_receiver() const                      { return (_recv != NULL); }
1671   Value receiver() const                         { assert(has_receiver(), "must have receiver"); return _recv; }
1672   bool preserves_state() const                   { return check_flag(PreservesStateFlag); }
1673 
1674   bool arg_needs_null_check(int i) const {
1675     return _nonnull_state.arg_needs_null_check(i);
1676   }
1677 
1678   void set_arg_needs_null_check(int i, bool check) {
1679     _nonnull_state.set_arg_needs_null_check(i, check);
1680   }
1681 
1682   // generic
1683   virtual bool can_trap() const                  { return check_flag(CanTrapFlag); }
1684   virtual void input_values_do(ValueVisitor* f) {
1685     StateSplit::input_values_do(f);
1686     for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1687   }
1688 };
1689 
1690 
1691 class LIR_List;
1692 
1693 LEAF(BlockBegin, StateSplit)
1694  private:
1695   int        _block_id;                          // the unique block id
1696   int        _bci;                               // start-bci of block
1697   int        _depth_first_number;                // number of this block in a depth-first ordering
1698   int        _linear_scan_number;                // number of this block in linear-scan ordering
1699   int        _dominator_depth;
1700   int        _loop_depth;                        // the loop nesting level of this block
1701   int        _loop_index;                        // number of the innermost loop of this block
1702   int        _flags;                             // the flags associated with this block
1703 
1704   // fields used by BlockListBuilder
1705   int            _total_preds;                   // number of predecessors found by BlockListBuilder
1706   ResourceBitMap _stores_to_locals;              // bit is set when a local variable is stored in the block
1707 
1708   // SSA specific fields: (factor out later)
1709   BlockList   _successors;                       // the successors of this block
1710   BlockList   _predecessors;                     // the predecessors of this block
1711   BlockList   _dominates;                        // list of blocks that are dominated by this block
1712   BlockBegin* _dominator;                        // the dominator of this block
1713   // SSA specific ends
1714   BlockEnd*  _end;                               // the last instruction of this block
1715   BlockList  _exception_handlers;                // the exception handlers potentially invoked by this block
1716   ValueStackStack* _exception_states;            // only for xhandler entries: states of all instructions that have an edge to this xhandler
1717   int        _exception_handler_pco;             // if this block is the start of an exception handler,
1718                                                  // this records the PC offset in the assembly code of the
1719                                                  // first instruction in this block
1720   Label      _label;                             // the label associated with this block
1721   LIR_List*  _lir;                               // the low level intermediate representation for this block
1722 
1723   ResourceBitMap _live_in;                       // set of live LIR_Opr registers at entry to this block
1724   ResourceBitMap _live_out;                      // set of live LIR_Opr registers at exit from this block
1725   ResourceBitMap _live_gen;                      // set of registers used before any redefinition in this block
1726   ResourceBitMap _live_kill;                     // set of registers defined in this block
1727 
1728   ResourceBitMap _fpu_register_usage;
1729   intArray*      _fpu_stack_state;               // For x86 FPU code generation with UseLinearScan
1730   int            _first_lir_instruction_id;      // ID of first LIR instruction in this block
1731   int            _last_lir_instruction_id;       // ID of last LIR instruction in this block
1732 
1733   void iterate_preorder (boolArray& mark, BlockClosure* closure);
1734   void iterate_postorder(boolArray& mark, BlockClosure* closure);
1735 
1736   friend class SuxAndWeightAdjuster;
1737 
1738  public:
1739    void* operator new(size_t size) throw() {
1740     Compilation* c = Compilation::current();
1741     void* res = c->arena()->Amalloc(size);
1742     ((BlockBegin*)res)->_id = c->get_next_id();
1743     ((BlockBegin*)res)->_block_id = c->get_next_block_id();
1744     return res;
1745   }
1746 
1747   // initialization/counting
1748   static int  number_of_blocks() {
1749     return Compilation::current()->number_of_blocks();
1750   }
1751 
1752   // creation
1753   BlockBegin(int bci)
1754   : StateSplit(illegalType)
1755   , _bci(bci)
1756   , _depth_first_number(-1)
1757   , _linear_scan_number(-1)
1758   , _dominator_depth(-1)
1759   , _loop_depth(0)
1760   , _loop_index(-1)
1761   , _flags(0)
1762   , _total_preds(0)
1763   , _stores_to_locals()
1764   , _successors(2)
1765   , _predecessors(2)
1766   , _dominates(2)
1767   , _dominator(NULL)
1768   , _end(NULL)
1769   , _exception_handlers(1)
1770   , _exception_states(NULL)
1771   , _exception_handler_pco(-1)
1772   , _lir(NULL)
1773   , _live_in()
1774   , _live_out()
1775   , _live_gen()
1776   , _live_kill()
1777   , _fpu_register_usage()
1778   , _fpu_stack_state(NULL)
1779   , _first_lir_instruction_id(-1)
1780   , _last_lir_instruction_id(-1)
1781   {
1782     _block = this;
1783 #ifndef PRODUCT
1784     set_printable_bci(bci);
1785 #endif
1786   }
1787 
1788   // accessors
1789   int block_id() const                           { return _block_id; }
1790   int bci() const                                { return _bci; }
1791   BlockList* successors()                        { return &_successors; }
1792   BlockList* dominates()                         { return &_dominates; }
1793   BlockBegin* dominator() const                  { return _dominator; }
1794   int loop_depth() const                         { return _loop_depth; }
1795   int dominator_depth() const                    { return _dominator_depth; }
1796   int depth_first_number() const                 { return _depth_first_number; }
1797   int linear_scan_number() const                 { return _linear_scan_number; }
1798   BlockEnd* end() const                          { return _end; }
1799   Label* label()                                 { return &_label; }
1800   LIR_List* lir() const                          { return _lir; }
1801   int exception_handler_pco() const              { return _exception_handler_pco; }
1802   ResourceBitMap& live_in()                      { return _live_in;        }
1803   ResourceBitMap& live_out()                     { return _live_out;       }
1804   ResourceBitMap& live_gen()                     { return _live_gen;       }
1805   ResourceBitMap& live_kill()                    { return _live_kill;      }
1806   ResourceBitMap& fpu_register_usage()           { return _fpu_register_usage; }
1807   intArray* fpu_stack_state() const              { return _fpu_stack_state;    }
1808   int first_lir_instruction_id() const           { return _first_lir_instruction_id; }
1809   int last_lir_instruction_id() const            { return _last_lir_instruction_id; }
1810   int total_preds() const                        { return _total_preds; }
1811   BitMap& stores_to_locals()                     { return _stores_to_locals; }
1812 
1813   // manipulation
1814   void set_dominator(BlockBegin* dom)            { _dominator = dom; }
1815   void set_loop_depth(int d)                     { _loop_depth = d; }
1816   void set_dominator_depth(int d)                { _dominator_depth = d; }
1817   void set_depth_first_number(int dfn)           { _depth_first_number = dfn; }
1818   void set_linear_scan_number(int lsn)           { _linear_scan_number = lsn; }
1819   void set_end(BlockEnd* end);
1820   void clear_end();
1821   void disconnect_from_graph();
1822   static void disconnect_edge(BlockBegin* from, BlockBegin* to);
1823   BlockBegin* insert_block_between(BlockBegin* sux);
1824   void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1825   void set_lir(LIR_List* lir)                    { _lir = lir; }
1826   void set_exception_handler_pco(int pco)        { _exception_handler_pco = pco; }
1827   void set_live_in  (const ResourceBitMap& map)  { _live_in = map;   }
1828   void set_live_out (const ResourceBitMap& map)  { _live_out = map;  }
1829   void set_live_gen (const ResourceBitMap& map)  { _live_gen = map;  }
1830   void set_live_kill(const ResourceBitMap& map)  { _live_kill = map; }
1831   void set_fpu_register_usage(const ResourceBitMap& map) { _fpu_register_usage = map; }
1832   void set_fpu_stack_state(intArray* state)      { _fpu_stack_state = state;  }
1833   void set_first_lir_instruction_id(int id)      { _first_lir_instruction_id = id;  }
1834   void set_last_lir_instruction_id(int id)       { _last_lir_instruction_id = id;  }
1835   void increment_total_preds(int n = 1)          { _total_preds += n; }
1836   void init_stores_to_locals(int locals_count)   { _stores_to_locals.initialize(locals_count); }
1837 
1838   // generic
1839   virtual void state_values_do(ValueVisitor* f);
1840 
1841   // successors and predecessors
1842   int number_of_sux() const;
1843   BlockBegin* sux_at(int i) const;
1844   void add_successor(BlockBegin* sux);
1845   void remove_successor(BlockBegin* pred);
1846   bool is_successor(BlockBegin* sux) const       { return _successors.contains(sux); }
1847 
1848   void add_predecessor(BlockBegin* pred);
1849   void remove_predecessor(BlockBegin* pred);
1850   bool is_predecessor(BlockBegin* pred) const    { return _predecessors.contains(pred); }
1851   int number_of_preds() const                    { return _predecessors.length(); }
1852   BlockBegin* pred_at(int i) const               { return _predecessors.at(i); }
1853 
1854   // exception handlers potentially invoked by this block
1855   void add_exception_handler(BlockBegin* b);
1856   bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }
1857   int  number_of_exception_handlers() const      { return _exception_handlers.length(); }
1858   BlockBegin* exception_handler_at(int i) const  { return _exception_handlers.at(i); }
1859 
1860   // states of the instructions that have an edge to this exception handler
1861   int number_of_exception_states()               { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); }
1862   ValueStack* exception_state_at(int idx) const  { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }
1863   int add_exception_state(ValueStack* state);
1864 
1865   // flags
1866   enum Flag {
1867     no_flag                       = 0,
1868     std_entry_flag                = 1 << 0,
1869     osr_entry_flag                = 1 << 1,
1870     exception_entry_flag          = 1 << 2,
1871     subroutine_entry_flag         = 1 << 3,
1872     backward_branch_target_flag   = 1 << 4,
1873     is_on_work_list_flag          = 1 << 5,
1874     was_visited_flag              = 1 << 6,
1875     parser_loop_header_flag       = 1 << 7,  // set by parser to identify blocks where phi functions can not be created on demand
1876     critical_edge_split_flag      = 1 << 8, // set for all blocks that are introduced when critical edges are split
1877     linear_scan_loop_header_flag  = 1 << 9, // set during loop-detection for LinearScan
1878     linear_scan_loop_end_flag     = 1 << 10, // set during loop-detection for LinearScan
1879     donot_eliminate_range_checks  = 1 << 11  // Should be try to eliminate range checks in this block
1880   };
1881 
1882   void set(Flag f)                               { _flags |= f; }
1883   void clear(Flag f)                             { _flags &= ~f; }
1884   bool is_set(Flag f) const                      { return (_flags & f) != 0; }
1885   bool is_entry_block() const {
1886     const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;
1887     return (_flags & entry_mask) != 0;
1888   }
1889 
1890   // iteration
1891   void iterate_preorder   (BlockClosure* closure);
1892   void iterate_postorder  (BlockClosure* closure);
1893 
1894   void block_values_do(ValueVisitor* f);
1895 
1896   // loops
1897   void set_loop_index(int ix)                    { _loop_index = ix;        }
1898   int  loop_index() const                        { return _loop_index;      }
1899 
1900   // merging
1901   bool try_merge(ValueStack* state);             // try to merge states at block begin
1902   void merge(ValueStack* state)                  { bool b = try_merge(state); assert(b, "merge failed"); }
1903 
1904   // debugging
1905   void print_block()                             PRODUCT_RETURN;
1906   void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;
1907 };
1908 
1909 
1910 BASE(BlockEnd, StateSplit)
1911  private:
1912   BlockList*  _sux;
1913 
1914  protected:
1915   BlockList* sux() const                         { return _sux; }
1916 
1917   void set_sux(BlockList* sux) {
1918 #ifdef ASSERT
1919     assert(sux != NULL, "sux must exist");
1920     for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist");
1921 #endif
1922     _sux = sux;
1923   }
1924 
1925  public:
1926   // creation
1927   BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)
1928   : StateSplit(type, state_before)
1929   , _sux(NULL)
1930   {
1931     set_flag(IsSafepointFlag, is_safepoint);
1932   }
1933 
1934   // accessors
1935   bool is_safepoint() const                      { return check_flag(IsSafepointFlag); }
1936   // For compatibility with old code, for new code use block()
1937   BlockBegin* begin() const                      { return _block; }
1938 
1939   // manipulation
1940   void set_begin(BlockBegin* begin);
1941 
1942   // successors
1943   int number_of_sux() const                      { return _sux != NULL ? _sux->length() : 0; }
1944   BlockBegin* sux_at(int i) const                { return _sux->at(i); }
1945   BlockBegin* default_sux() const                { return sux_at(number_of_sux() - 1); }
1946   BlockBegin** addr_sux_at(int i) const          { return _sux->adr_at(i); }
1947   int sux_index(BlockBegin* sux) const           { return _sux->find(sux); }
1948   void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1949 };
1950 
1951 
1952 LEAF(Goto, BlockEnd)
1953  public:
1954   enum Direction {
1955     none,            // Just a regular goto
1956     taken, not_taken // Goto produced from If
1957   };
1958  private:
1959   ciMethod*   _profiled_method;
1960   int         _profiled_bci;
1961   Direction   _direction;
1962  public:
1963   // creation
1964   Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false)
1965     : BlockEnd(illegalType, state_before, is_safepoint)
1966     , _profiled_method(NULL)
1967     , _profiled_bci(0)
1968     , _direction(none) {
1969     BlockList* s = new BlockList(1);
1970     s->append(sux);
1971     set_sux(s);
1972   }
1973 
1974   Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint)
1975                                            , _profiled_method(NULL)
1976                                            , _profiled_bci(0)
1977                                            , _direction(none) {
1978     BlockList* s = new BlockList(1);
1979     s->append(sux);
1980     set_sux(s);
1981   }
1982 
1983   bool should_profile() const                    { return check_flag(ProfileMDOFlag); }
1984   ciMethod* profiled_method() const              { return _profiled_method; } // set only for profiled branches
1985   int profiled_bci() const                       { return _profiled_bci; }
1986   Direction direction() const                    { return _direction; }
1987 
1988   void set_should_profile(bool value)            { set_flag(ProfileMDOFlag, value); }
1989   void set_profiled_method(ciMethod* method)     { _profiled_method = method; }
1990   void set_profiled_bci(int bci)                 { _profiled_bci = bci; }
1991   void set_direction(Direction d)                { _direction = d; }
1992 };
1993 
1994 #ifdef ASSERT
1995 LEAF(Assert, Instruction)
1996   private:
1997   Value       _x;
1998   Condition   _cond;
1999   Value       _y;
2000   char        *_message;
2001 
2002  public:
2003   // creation
2004   // unordered_is_true is valid for float/double compares only
2005    Assert(Value x, Condition cond, bool unordered_is_true, Value y);
2006 
2007   // accessors
2008   Value x() const                                { return _x; }
2009   Condition cond() const                         { return _cond; }
2010   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
2011   Value y() const                                { return _y; }
2012   const char *message() const                    { return _message; }
2013 
2014   // generic
2015   virtual void input_values_do(ValueVisitor* f)  { f->visit(&_x); f->visit(&_y); }
2016 };
2017 #endif
2018 
2019 LEAF(RangeCheckPredicate, StateSplit)
2020  private:
2021   Value       _x;
2022   Condition   _cond;
2023   Value       _y;
2024 
2025   void check_state();
2026 
2027  public:
2028   // creation
2029   // unordered_is_true is valid for float/double compares only
2030    RangeCheckPredicate(Value x, Condition cond, bool unordered_is_true, Value y, ValueStack* state) : StateSplit(illegalType)
2031   , _x(x)
2032   , _cond(cond)
2033   , _y(y)
2034   {
2035     ASSERT_VALUES
2036     set_flag(UnorderedIsTrueFlag, unordered_is_true);
2037     assert(x->type()->tag() == y->type()->tag(), "types must match");
2038     this->set_state(state);
2039     check_state();
2040   }
2041 
2042   // Always deoptimize
2043   RangeCheckPredicate(ValueStack* state) : StateSplit(illegalType)
2044   {
2045     this->set_state(state);
2046     _x = _y = NULL;
2047     check_state();
2048   }
2049 
2050   // accessors
2051   Value x() const                                { return _x; }
2052   Condition cond() const                         { return _cond; }
2053   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
2054   Value y() const                                { return _y; }
2055 
2056   void always_fail()                             { _x = _y = NULL; }
2057 
2058   // generic
2059   virtual void input_values_do(ValueVisitor* f)  { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2060   HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())
2061 };
2062 
2063 LEAF(If, BlockEnd)
2064  private:
2065   Value       _x;
2066   Condition   _cond;
2067   Value       _y;
2068   ciMethod*   _profiled_method;
2069   int         _profiled_bci; // Canonicalizer may alter bci of If node
2070   bool        _swapped;      // Is the order reversed with respect to the original If in the
2071                              // bytecode stream?
2072   bool        _substitutability_check;
2073  public:
2074   // creation
2075   // unordered_is_true is valid for float/double compares only
2076   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)
2077     : BlockEnd(illegalType, state_before, is_safepoint)
2078   , _x(x)
2079   , _cond(cond)
2080   , _y(y)
2081   , _profiled_method(NULL)
2082   , _profiled_bci(0)
2083   , _swapped(false)
2084   , _substitutability_check(substitutability_check)
2085   {
2086     ASSERT_VALUES
2087     set_flag(UnorderedIsTrueFlag, unordered_is_true);
2088     assert(x->type()->tag() == y->type()->tag(), "types must match");
2089     BlockList* s = new BlockList(2);
2090     s->append(tsux);
2091     s->append(fsux);
2092     set_sux(s);
2093   }
2094 
2095   // accessors
2096   Value x() const                                { return _x; }
2097   Condition cond() const                         { return _cond; }
2098   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
2099   Value y() const                                { return _y; }
2100   BlockBegin* sux_for(bool is_true) const        { return sux_at(is_true ? 0 : 1); }
2101   BlockBegin* tsux() const                       { return sux_for(true); }
2102   BlockBegin* fsux() const                       { return sux_for(false); }
2103   BlockBegin* usux() const                       { return sux_for(unordered_is_true()); }
2104   bool should_profile() const                    { return check_flag(ProfileMDOFlag); }
2105   ciMethod* profiled_method() const              { return _profiled_method; } // set only for profiled branches
2106   int profiled_bci() const                       { return _profiled_bci; }    // set for profiled branches and tiered
2107   bool is_swapped() const                        { return _swapped; }
2108 
2109   // manipulation
2110   void swap_operands() {
2111     Value t = _x; _x = _y; _y = t;
2112     _cond = mirror(_cond);
2113   }
2114 
2115   void swap_sux() {
2116     assert(number_of_sux() == 2, "wrong number of successors");
2117     BlockList* s = sux();
2118     BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
2119     _cond = negate(_cond);
2120     set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));
2121   }
2122 
2123   void set_should_profile(bool value)             { set_flag(ProfileMDOFlag, value); }
2124   void set_profiled_method(ciMethod* method)      { _profiled_method = method; }
2125   void set_profiled_bci(int bci)                  { _profiled_bci = bci;       }
2126   void set_swapped(bool value)                    { _swapped = value;         }
2127   bool substitutability_check() const              { return _substitutability_check; }
2128   // generic
2129   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2130 };
2131 
2132 
2133 LEAF(IfInstanceOf, BlockEnd)
2134  private:
2135   ciKlass* _klass;
2136   Value    _obj;
2137   bool     _test_is_instance;                    // jump if instance
2138   int      _instanceof_bci;
2139 
2140  public:
2141   IfInstanceOf(ciKlass* klass, Value obj, bool test_is_instance, int instanceof_bci, BlockBegin* tsux, BlockBegin* fsux)
2142   : BlockEnd(illegalType, NULL, false) // temporary set to false
2143   , _klass(klass)
2144   , _obj(obj)
2145   , _test_is_instance(test_is_instance)
2146   , _instanceof_bci(instanceof_bci)
2147   {
2148     ASSERT_VALUES
2149     assert(instanceof_bci >= 0, "illegal bci");
2150     BlockList* s = new BlockList(2);
2151     s->append(tsux);
2152     s->append(fsux);
2153     set_sux(s);
2154   }
2155 
2156   // accessors
2157   //
2158   // Note 1: If test_is_instance() is true, IfInstanceOf tests if obj *is* an
2159   //         instance of klass; otherwise it tests if it is *not* and instance
2160   //         of klass.
2161   //
2162   // Note 2: IfInstanceOf instructions are created by combining an InstanceOf
2163   //         and an If instruction. The IfInstanceOf bci() corresponds to the
2164   //         bci that the If would have had; the (this->) instanceof_bci() is
2165   //         the bci of the original InstanceOf instruction.
2166   ciKlass* klass() const                         { return _klass; }
2167   Value obj() const                              { return _obj; }
2168   int instanceof_bci() const                     { return _instanceof_bci; }
2169   bool test_is_instance() const                  { return _test_is_instance; }
2170   BlockBegin* sux_for(bool is_true) const        { return sux_at(is_true ? 0 : 1); }
2171   BlockBegin* tsux() const                       { return sux_for(true); }
2172   BlockBegin* fsux() const                       { return sux_for(false); }
2173 
2174   // manipulation
2175   void swap_sux() {
2176     assert(number_of_sux() == 2, "wrong number of successors");
2177     BlockList* s = sux();
2178     BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
2179     _test_is_instance = !_test_is_instance;
2180   }
2181 
2182   // generic
2183   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_obj); }
2184 };
2185 
2186 
2187 BASE(Switch, BlockEnd)
2188  private:
2189   Value       _tag;
2190 
2191  public:
2192   // creation
2193   Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
2194   : BlockEnd(illegalType, state_before, is_safepoint)
2195   , _tag(tag) {
2196     ASSERT_VALUES
2197     set_sux(sux);
2198   }
2199 
2200   // accessors
2201   Value tag() const                              { return _tag; }
2202   int length() const                             { return number_of_sux() - 1; }
2203 
2204   virtual bool needs_exception_state() const     { return false; }
2205 
2206   // generic
2207   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_tag); }
2208 };
2209 
2210 
2211 LEAF(TableSwitch, Switch)
2212  private:
2213   int _lo_key;
2214 
2215  public:
2216   // creation
2217   TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)
2218     : Switch(tag, sux, state_before, is_safepoint)
2219   , _lo_key(lo_key) { assert(_lo_key <= hi_key(), "integer overflow"); }
2220 
2221   // accessors
2222   int lo_key() const                             { return _lo_key; }
2223   int hi_key() const                             { return _lo_key + (length() - 1); }
2224 };
2225 
2226 
2227 LEAF(LookupSwitch, Switch)
2228  private:
2229   intArray* _keys;
2230 
2231  public:
2232   // creation
2233   LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)
2234   : Switch(tag, sux, state_before, is_safepoint)
2235   , _keys(keys) {
2236     assert(keys != NULL, "keys must exist");
2237     assert(keys->length() == length(), "sux & keys have incompatible lengths");
2238   }
2239 
2240   // accessors
2241   int key_at(int i) const                        { return _keys->at(i); }
2242 };
2243 
2244 
2245 LEAF(Return, BlockEnd)
2246  private:
2247   Value _result;
2248 
2249  public:
2250   // creation
2251   Return(Value result) :
2252     BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true),
2253     _result(result) {}
2254 
2255   // accessors
2256   Value result() const                           { return _result; }
2257   bool has_result() const                        { return result() != NULL; }
2258 
2259   // generic
2260   virtual void input_values_do(ValueVisitor* f) {
2261     BlockEnd::input_values_do(f);
2262     if (has_result()) f->visit(&_result);
2263   }
2264 };
2265 
2266 
2267 LEAF(Throw, BlockEnd)
2268  private:
2269   Value _exception;
2270 
2271  public:
2272   // creation
2273   Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {
2274     ASSERT_VALUES
2275   }
2276 
2277   // accessors
2278   Value exception() const                        { return _exception; }
2279 
2280   // generic
2281   virtual bool can_trap() const                  { return true; }
2282   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_exception); }
2283 };
2284 
2285 
2286 LEAF(Base, BlockEnd)
2287  public:
2288   // creation
2289   Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, NULL, false) {
2290     assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged");
2291     assert(osr_entry == NULL || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged");
2292     BlockList* s = new BlockList(2);
2293     if (osr_entry != NULL) s->append(osr_entry);
2294     s->append(std_entry); // must be default sux!
2295     set_sux(s);
2296   }
2297 
2298   // accessors
2299   BlockBegin* std_entry() const                  { return default_sux(); }
2300   BlockBegin* osr_entry() const                  { return number_of_sux() < 2 ? NULL : sux_at(0); }
2301 };
2302 
2303 
2304 LEAF(OsrEntry, Instruction)
2305  public:
2306   // creation
2307 #ifdef _LP64
2308   OsrEntry() : Instruction(longType) { pin(); }
2309 #else
2310   OsrEntry() : Instruction(intType)  { pin(); }
2311 #endif
2312 
2313   // generic
2314   virtual void input_values_do(ValueVisitor* f)   { }
2315 };
2316 
2317 
2318 // Models the incoming exception at a catch site
2319 LEAF(ExceptionObject, Instruction)
2320  public:
2321   // creation
2322   ExceptionObject() : Instruction(objectType) {
2323     pin();
2324   }
2325 
2326   // generic
2327   virtual void input_values_do(ValueVisitor* f)   { }
2328 };
2329 
2330 
2331 // Models needed rounding for floating-point values on Intel.
2332 // Currently only used to represent rounding of double-precision
2333 // values stored into local variables, but could be used to model
2334 // intermediate rounding of single-precision values as well.
2335 LEAF(RoundFP, Instruction)
2336  private:
2337   Value _input;             // floating-point value to be rounded
2338 
2339  public:
2340   RoundFP(Value input)
2341   : Instruction(input->type()) // Note: should not be used for constants
2342   , _input(input)
2343   {
2344     ASSERT_VALUES
2345   }
2346 
2347   // accessors
2348   Value input() const                            { return _input; }
2349 
2350   // generic
2351   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_input); }
2352 };
2353 
2354 
2355 BASE(UnsafeOp, Instruction)
2356  private:
2357   BasicType _basic_type;    // ValueType can not express byte-sized integers
2358 
2359  protected:
2360   // creation
2361   UnsafeOp(BasicType basic_type, bool is_put)
2362   : Instruction(is_put ? voidType : as_ValueType(basic_type))
2363   , _basic_type(basic_type)
2364   {
2365     //Note:  Unsafe ops are not not guaranteed to throw NPE.
2366     // Convservatively, Unsafe operations must be pinned though we could be
2367     // looser about this if we wanted to..
2368     pin();
2369   }
2370 
2371  public:
2372   // accessors
2373   BasicType basic_type()                         { return _basic_type; }
2374 
2375   // generic
2376   virtual void input_values_do(ValueVisitor* f)   { }
2377 };
2378 
2379 
2380 BASE(UnsafeRawOp, UnsafeOp)
2381  private:
2382   Value _base;                                   // Base address (a Java long)
2383   Value _index;                                  // Index if computed by optimizer; initialized to NULL
2384   int   _log2_scale;                             // Scale factor: 0, 1, 2, or 3.
2385                                                  // Indicates log2 of number of bytes (1, 2, 4, or 8)
2386                                                  // to scale index by.
2387 
2388  protected:
2389   UnsafeRawOp(BasicType basic_type, Value addr, bool is_put)
2390   : UnsafeOp(basic_type, is_put)
2391   , _base(addr)
2392   , _index(NULL)
2393   , _log2_scale(0)
2394   {
2395     // Can not use ASSERT_VALUES because index may be NULL
2396     assert(addr != NULL && addr->type()->is_long(), "just checking");
2397   }
2398 
2399   UnsafeRawOp(BasicType basic_type, Value base, Value index, int log2_scale, bool is_put)
2400   : UnsafeOp(basic_type, is_put)
2401   , _base(base)
2402   , _index(index)
2403   , _log2_scale(log2_scale)
2404   {
2405   }
2406 
2407  public:
2408   // accessors
2409   Value base()                                   { return _base; }
2410   Value index()                                  { return _index; }
2411   bool  has_index()                              { return (_index != NULL); }
2412   int   log2_scale()                             { return _log2_scale; }
2413 
2414   // setters
2415   void set_base (Value base)                     { _base  = base; }
2416   void set_index(Value index)                    { _index = index; }
2417   void set_log2_scale(int log2_scale)            { _log2_scale = log2_scale; }
2418 
2419   // generic
2420   virtual void input_values_do(ValueVisitor* f)   { UnsafeOp::input_values_do(f);
2421                                                    f->visit(&_base);
2422                                                    if (has_index()) f->visit(&_index); }
2423 };
2424 
2425 
2426 LEAF(UnsafeGetRaw, UnsafeRawOp)
2427  private:
2428  bool _may_be_unaligned, _is_wide;  // For OSREntry
2429 
2430  public:
2431  UnsafeGetRaw(BasicType basic_type, Value addr, bool may_be_unaligned, bool is_wide = false)
2432   : UnsafeRawOp(basic_type, addr, false) {
2433     _may_be_unaligned = may_be_unaligned;
2434     _is_wide = is_wide;
2435   }
2436 
2437  UnsafeGetRaw(BasicType basic_type, Value base, Value index, int log2_scale, bool may_be_unaligned, bool is_wide = false)
2438   : UnsafeRawOp(basic_type, base, index, log2_scale, false) {
2439     _may_be_unaligned = may_be_unaligned;
2440     _is_wide = is_wide;
2441   }
2442 
2443   bool may_be_unaligned()                         { return _may_be_unaligned; }
2444   bool is_wide()                                  { return _is_wide; }
2445 };
2446 
2447 
2448 LEAF(UnsafePutRaw, UnsafeRawOp)
2449  private:
2450   Value _value;                                  // Value to be stored
2451 
2452  public:
2453   UnsafePutRaw(BasicType basic_type, Value addr, Value value)
2454   : UnsafeRawOp(basic_type, addr, true)
2455   , _value(value)
2456   {
2457     assert(value != NULL, "just checking");
2458     ASSERT_VALUES
2459   }
2460 
2461   UnsafePutRaw(BasicType basic_type, Value base, Value index, int log2_scale, Value value)
2462   : UnsafeRawOp(basic_type, base, index, log2_scale, true)
2463   , _value(value)
2464   {
2465     assert(value != NULL, "just checking");
2466     ASSERT_VALUES
2467   }
2468 
2469   // accessors
2470   Value value()                                  { return _value; }
2471 
2472   // generic
2473   virtual void input_values_do(ValueVisitor* f)   { UnsafeRawOp::input_values_do(f);
2474                                                    f->visit(&_value); }
2475 };
2476 
2477 
2478 BASE(UnsafeObjectOp, UnsafeOp)
2479  private:
2480   Value _object;                                 // Object to be fetched from or mutated
2481   Value _offset;                                 // Offset within object
2482   bool  _is_volatile;                            // true if volatile - dl/JSR166
2483  public:
2484   UnsafeObjectOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile)
2485     : UnsafeOp(basic_type, is_put), _object(object), _offset(offset), _is_volatile(is_volatile)
2486   {
2487   }
2488 
2489   // accessors
2490   Value object()                                 { return _object; }
2491   Value offset()                                 { return _offset; }
2492   bool  is_volatile()                            { return _is_volatile; }
2493   // generic
2494   virtual void input_values_do(ValueVisitor* f)   { UnsafeOp::input_values_do(f);
2495                                                    f->visit(&_object);
2496                                                    f->visit(&_offset); }
2497 };
2498 
2499 
2500 LEAF(UnsafeGetObject, UnsafeObjectOp)
2501  public:
2502   UnsafeGetObject(BasicType basic_type, Value object, Value offset, bool is_volatile)
2503   : UnsafeObjectOp(basic_type, object, offset, false, is_volatile)
2504   {
2505     ASSERT_VALUES
2506   }
2507 };
2508 
2509 
2510 LEAF(UnsafePutObject, UnsafeObjectOp)
2511  private:
2512   Value _value;                                  // Value to be stored
2513  public:
2514   UnsafePutObject(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile)
2515   : UnsafeObjectOp(basic_type, object, offset, true, is_volatile)
2516     , _value(value)
2517   {
2518     ASSERT_VALUES
2519   }
2520 
2521   // accessors
2522   Value value()                                  { return _value; }
2523 
2524   // generic
2525   virtual void input_values_do(ValueVisitor* f)   { UnsafeObjectOp::input_values_do(f);
2526                                                    f->visit(&_value); }
2527 };
2528 
2529 LEAF(UnsafeGetAndSetObject, UnsafeObjectOp)
2530  private:
2531   Value _value;                                  // Value to be stored
2532   bool  _is_add;
2533  public:
2534   UnsafeGetAndSetObject(BasicType basic_type, Value object, Value offset, Value value, bool is_add)
2535   : UnsafeObjectOp(basic_type, object, offset, false, false)
2536     , _value(value)
2537     , _is_add(is_add)
2538   {
2539     ASSERT_VALUES
2540   }
2541 
2542   // accessors
2543   bool is_add() const                            { return _is_add; }
2544   Value value()                                  { return _value; }
2545 
2546   // generic
2547   virtual void input_values_do(ValueVisitor* f)   { UnsafeObjectOp::input_values_do(f);
2548                                                    f->visit(&_value); }
2549 };
2550 
2551 LEAF(ProfileCall, Instruction)
2552  private:
2553   ciMethod*        _method;
2554   int              _bci_of_invoke;
2555   ciMethod*        _callee;         // the method that is called at the given bci
2556   Value            _recv;
2557   ciKlass*         _known_holder;
2558   Values*          _obj_args;       // arguments for type profiling
2559   ArgsNonNullState _nonnull_state;  // Do we know whether some arguments are never null?
2560   bool             _inlined;        // Are we profiling a call that is inlined
2561 
2562  public:
2563   ProfileCall(ciMethod* method, int bci, ciMethod* callee, Value recv, ciKlass* known_holder, Values* obj_args, bool inlined)
2564     : Instruction(voidType)
2565     , _method(method)
2566     , _bci_of_invoke(bci)
2567     , _callee(callee)
2568     , _recv(recv)
2569     , _known_holder(known_holder)
2570     , _obj_args(obj_args)
2571     , _inlined(inlined)
2572   {
2573     // The ProfileCall has side-effects and must occur precisely where located
2574     pin();
2575   }
2576 
2577   ciMethod* method()             const { return _method; }
2578   int bci_of_invoke()            const { return _bci_of_invoke; }
2579   ciMethod* callee()             const { return _callee; }
2580   Value recv()                   const { return _recv; }
2581   ciKlass* known_holder()        const { return _known_holder; }
2582   int nb_profiled_args()         const { return _obj_args == NULL ? 0 : _obj_args->length(); }
2583   Value profiled_arg_at(int i)   const { return _obj_args->at(i); }
2584   bool arg_needs_null_check(int i) const {
2585     return _nonnull_state.arg_needs_null_check(i);
2586   }
2587   bool inlined()                 const { return _inlined; }
2588 
2589   void set_arg_needs_null_check(int i, bool check) {
2590     _nonnull_state.set_arg_needs_null_check(i, check);
2591   }
2592 
2593   virtual void input_values_do(ValueVisitor* f)   {
2594     if (_recv != NULL) {
2595       f->visit(&_recv);
2596     }
2597     for (int i = 0; i < nb_profiled_args(); i++) {
2598       f->visit(_obj_args->adr_at(i));
2599     }
2600   }
2601 };
2602 
2603 LEAF(ProfileReturnType, Instruction)
2604  private:
2605   ciMethod*        _method;
2606   ciMethod*        _callee;
2607   int              _bci_of_invoke;
2608   Value            _ret;
2609 
2610  public:
2611   ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)
2612     : Instruction(voidType)
2613     , _method(method)
2614     , _callee(callee)
2615     , _bci_of_invoke(bci)
2616     , _ret(ret)
2617   {
2618     set_needs_null_check(true);
2619     // The ProfileType has side-effects and must occur precisely where located
2620     pin();
2621   }
2622 
2623   ciMethod* method()             const { return _method; }
2624   ciMethod* callee()             const { return _callee; }
2625   int bci_of_invoke()            const { return _bci_of_invoke; }
2626   Value ret()                    const { return _ret; }
2627 
2628   virtual void input_values_do(ValueVisitor* f)   {
2629     if (_ret != NULL) {
2630       f->visit(&_ret);
2631     }
2632   }
2633 };
2634 
2635 // Call some C runtime function that doesn't safepoint,
2636 // optionally passing the current thread as the first argument.
2637 LEAF(RuntimeCall, Instruction)
2638  private:
2639   const char* _entry_name;
2640   address     _entry;
2641   Values*     _args;
2642   bool        _pass_thread;  // Pass the JavaThread* as an implicit first argument
2643 
2644  public:
2645   RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2646     : Instruction(type)
2647     , _entry_name(entry_name)
2648     , _entry(entry)
2649     , _args(args)
2650     , _pass_thread(pass_thread) {
2651     ASSERT_VALUES
2652     pin();
2653   }
2654 
2655   const char* entry_name() const  { return _entry_name; }
2656   address entry() const           { return _entry; }
2657   int number_of_arguments() const { return _args->length(); }
2658   Value argument_at(int i) const  { return _args->at(i); }
2659   bool pass_thread() const        { return _pass_thread; }
2660 
2661   virtual void input_values_do(ValueVisitor* f)   {
2662     for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
2663   }
2664 };
2665 
2666 // Use to trip invocation counter of an inlined method
2667 
2668 LEAF(ProfileInvoke, Instruction)
2669  private:
2670   ciMethod*   _inlinee;
2671   ValueStack* _state;
2672 
2673  public:
2674   ProfileInvoke(ciMethod* inlinee,  ValueStack* state)
2675     : Instruction(voidType)
2676     , _inlinee(inlinee)
2677     , _state(state)
2678   {
2679     // The ProfileInvoke has side-effects and must occur precisely where located QQQ???
2680     pin();
2681   }
2682 
2683   ciMethod* inlinee()      { return _inlinee; }
2684   ValueStack* state()      { return _state; }
2685   virtual void input_values_do(ValueVisitor*)   {}
2686   virtual void state_values_do(ValueVisitor*);
2687 };
2688 
2689 LEAF(MemBar, Instruction)
2690  private:
2691   LIR_Code _code;
2692 
2693  public:
2694   MemBar(LIR_Code code)
2695     : Instruction(voidType)
2696     , _code(code)
2697   {
2698     pin();
2699   }
2700 
2701   LIR_Code code()           { return _code; }
2702 
2703   virtual void input_values_do(ValueVisitor*)   {}
2704 };
2705 
2706 class BlockPair: public CompilationResourceObj {
2707  private:
2708   BlockBegin* _from;
2709   BlockBegin* _to;
2710  public:
2711   BlockPair(BlockBegin* from, BlockBegin* to): _from(from), _to(to) {}
2712   BlockBegin* from() const { return _from; }
2713   BlockBegin* to() const   { return _to;   }
2714   bool is_same(BlockBegin* from, BlockBegin* to) const { return  _from == from && _to == to; }
2715   bool is_same(BlockPair* p) const { return  _from == p->from() && _to == p->to(); }
2716   void set_to(BlockBegin* b)   { _to = b; }
2717   void set_from(BlockBegin* b) { _from = b; }
2718 };
2719 
2720 typedef GrowableArray<BlockPair*> BlockPairList;
2721 
2722 inline int         BlockBegin::number_of_sux() const            { assert(_end == NULL || _end->number_of_sux() == _successors.length(), "mismatch"); return _successors.length(); }
2723 inline BlockBegin* BlockBegin::sux_at(int i) const              { assert(_end == NULL || _end->sux_at(i) == _successors.at(i), "mismatch");          return _successors.at(i); }
2724 inline void        BlockBegin::add_successor(BlockBegin* sux)   { assert(_end == NULL, "Would create mismatch with successors of BlockEnd");         _successors.append(sux); }
2725 
2726 #undef ASSERT_VALUES
2727 
2728 #endif // SHARE_C1_C1_INSTRUCTION_HPP