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