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