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