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