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