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