src/share/vm/c1/c1_Instruction.hpp

Tue, 24 Feb 2015 15:04:52 -0500

author
dlong
date
Tue, 24 Feb 2015 15:04:52 -0500
changeset 7598
ddce0b7cee93
parent 7058
2fd0fd493045
child 7535
7ae4e26cb1e0
child 8368
32b682649973
permissions
-rw-r--r--

8072383: resolve conflicts between open and closed ports
Summary: refactor close to remove references to closed ports
Reviewed-by: kvn, simonis, sgehwolf, dholmes

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

mercurial