src/share/vm/c1/c1_Instruction.hpp

Wed, 30 May 2012 12:17:07 -0700

author
twisti
date
Wed, 30 May 2012 12:17:07 -0700
changeset 3836
c8289830e172
parent 3592
701a83c86f28
child 3969
1d7922586cf6
permissions
-rw-r--r--

7172843: C1: fix "assert(has_printable_bci()) failed: _printable_bci should have been set"
Reviewed-by: twisti
Contributed-by: Krystal Mok <sajia@taobao.com>

     1 /*
     2  * Copyright (c) 1999, 2011, 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   OsrEntry;
    70 class   ExceptionObject;
    71 class   StateSplit;
    72 class     Invoke;
    73 class     NewInstance;
    74 class     NewArray;
    75 class       NewTypeArray;
    76 class       NewObjectArray;
    77 class       NewMultiArray;
    78 class     TypeCheck;
    79 class       CheckCast;
    80 class       InstanceOf;
    81 class     AccessMonitor;
    82 class       MonitorEnter;
    83 class       MonitorExit;
    84 class     Intrinsic;
    85 class     BlockBegin;
    86 class     BlockEnd;
    87 class       Goto;
    88 class       If;
    89 class       IfInstanceOf;
    90 class       Switch;
    91 class         TableSwitch;
    92 class         LookupSwitch;
    93 class       Return;
    94 class       Throw;
    95 class       Base;
    96 class   RoundFP;
    97 class   UnsafeOp;
    98 class     UnsafeRawOp;
    99 class       UnsafeGetRaw;
   100 class       UnsafePutRaw;
   101 class     UnsafeObjectOp;
   102 class       UnsafeGetObject;
   103 class       UnsafePutObject;
   104 class       UnsafePrefetch;
   105 class         UnsafePrefetchRead;
   106 class         UnsafePrefetchWrite;
   107 class   ProfileCall;
   108 class   ProfileInvoke;
   109 class   RuntimeCall;
   110 class   MemBar;
   112 // A Value is a reference to the instruction creating the value
   113 typedef Instruction* Value;
   114 define_array(ValueArray, Value)
   115 define_stack(Values, ValueArray)
   117 define_array(ValueStackArray, ValueStack*)
   118 define_stack(ValueStackStack, ValueStackArray)
   120 // BlockClosure is the base class for block traversal/iteration.
   122 class BlockClosure: public CompilationResourceObj {
   123  public:
   124   virtual void block_do(BlockBegin* block)       = 0;
   125 };
   128 // A simple closure class for visiting the values of an Instruction
   129 class ValueVisitor: public StackObj {
   130  public:
   131   virtual void visit(Value* v) = 0;
   132 };
   135 // Some array and list classes
   136 define_array(BlockBeginArray, BlockBegin*)
   137 define_stack(_BlockList, BlockBeginArray)
   139 class BlockList: public _BlockList {
   140  public:
   141   BlockList(): _BlockList() {}
   142   BlockList(const int size): _BlockList(size) {}
   143   BlockList(const int size, BlockBegin* init): _BlockList(size, init) {}
   145   void iterate_forward(BlockClosure* closure);
   146   void iterate_backward(BlockClosure* closure);
   147   void blocks_do(void f(BlockBegin*));
   148   void values_do(ValueVisitor* f);
   149   void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN;
   150 };
   153 // InstructionVisitors provide type-based dispatch for instructions.
   154 // For each concrete Instruction class X, a virtual function do_X is
   155 // provided. Functionality that needs to be implemented for all classes
   156 // (e.g., printing, code generation) is factored out into a specialised
   157 // visitor instead of added to the Instruction classes itself.
   159 class InstructionVisitor: public StackObj {
   160  public:
   161   virtual void do_Phi            (Phi*             x) = 0;
   162   virtual void do_Local          (Local*           x) = 0;
   163   virtual void do_Constant       (Constant*        x) = 0;
   164   virtual void do_LoadField      (LoadField*       x) = 0;
   165   virtual void do_StoreField     (StoreField*      x) = 0;
   166   virtual void do_ArrayLength    (ArrayLength*     x) = 0;
   167   virtual void do_LoadIndexed    (LoadIndexed*     x) = 0;
   168   virtual void do_StoreIndexed   (StoreIndexed*    x) = 0;
   169   virtual void do_NegateOp       (NegateOp*        x) = 0;
   170   virtual void do_ArithmeticOp   (ArithmeticOp*    x) = 0;
   171   virtual void do_ShiftOp        (ShiftOp*         x) = 0;
   172   virtual void do_LogicOp        (LogicOp*         x) = 0;
   173   virtual void do_CompareOp      (CompareOp*       x) = 0;
   174   virtual void do_IfOp           (IfOp*            x) = 0;
   175   virtual void do_Convert        (Convert*         x) = 0;
   176   virtual void do_NullCheck      (NullCheck*       x) = 0;
   177   virtual void do_Invoke         (Invoke*          x) = 0;
   178   virtual void do_NewInstance    (NewInstance*     x) = 0;
   179   virtual void do_NewTypeArray   (NewTypeArray*    x) = 0;
   180   virtual void do_NewObjectArray (NewObjectArray*  x) = 0;
   181   virtual void do_NewMultiArray  (NewMultiArray*   x) = 0;
   182   virtual void do_CheckCast      (CheckCast*       x) = 0;
   183   virtual void do_InstanceOf     (InstanceOf*      x) = 0;
   184   virtual void do_MonitorEnter   (MonitorEnter*    x) = 0;
   185   virtual void do_MonitorExit    (MonitorExit*     x) = 0;
   186   virtual void do_Intrinsic      (Intrinsic*       x) = 0;
   187   virtual void do_BlockBegin     (BlockBegin*      x) = 0;
   188   virtual void do_Goto           (Goto*            x) = 0;
   189   virtual void do_If             (If*              x) = 0;
   190   virtual void do_IfInstanceOf   (IfInstanceOf*    x) = 0;
   191   virtual void do_TableSwitch    (TableSwitch*     x) = 0;
   192   virtual void do_LookupSwitch   (LookupSwitch*    x) = 0;
   193   virtual void do_Return         (Return*          x) = 0;
   194   virtual void do_Throw          (Throw*           x) = 0;
   195   virtual void do_Base           (Base*            x) = 0;
   196   virtual void do_OsrEntry       (OsrEntry*        x) = 0;
   197   virtual void do_ExceptionObject(ExceptionObject* x) = 0;
   198   virtual void do_RoundFP        (RoundFP*         x) = 0;
   199   virtual void do_UnsafeGetRaw   (UnsafeGetRaw*    x) = 0;
   200   virtual void do_UnsafePutRaw   (UnsafePutRaw*    x) = 0;
   201   virtual void do_UnsafeGetObject(UnsafeGetObject* x) = 0;
   202   virtual void do_UnsafePutObject(UnsafePutObject* x) = 0;
   203   virtual void do_UnsafePrefetchRead (UnsafePrefetchRead*  x) = 0;
   204   virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) = 0;
   205   virtual void do_ProfileCall    (ProfileCall*     x) = 0;
   206   virtual void do_ProfileInvoke  (ProfileInvoke*   x) = 0;
   207   virtual void do_RuntimeCall    (RuntimeCall*     x) = 0;
   208   virtual void do_MemBar         (MemBar*          x) = 0;
   209 };
   212 // Hashing support
   213 //
   214 // Note: This hash functions affect the performance
   215 //       of ValueMap - make changes carefully!
   217 #define HASH1(x1            )                    ((intx)(x1))
   218 #define HASH2(x1, x2        )                    ((HASH1(x1        ) << 7) ^ HASH1(x2))
   219 #define HASH3(x1, x2, x3    )                    ((HASH2(x1, x2    ) << 7) ^ HASH1(x3))
   220 #define HASH4(x1, x2, x3, x4)                    ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))
   223 // The following macros are used to implement instruction-specific hashing.
   224 // By default, each instruction implements hash() and is_equal(Value), used
   225 // for value numbering/common subexpression elimination. The default imple-
   226 // mentation disables value numbering. Each instruction which can be value-
   227 // numbered, should define corresponding hash() and is_equal(Value) functions
   228 // via the macros below. The f arguments specify all the values/op codes, etc.
   229 // that need to be identical for two instructions to be identical.
   230 //
   231 // Note: The default implementation of hash() returns 0 in order to indicate
   232 //       that the instruction should not be considered for value numbering.
   233 //       The currently used hash functions do not guarantee that never a 0
   234 //       is produced. While this is still correct, it may be a performance
   235 //       bug (no value numbering for that node). However, this situation is
   236 //       so unlikely, that we are not going to handle it specially.
   238 #define HASHING1(class_name, enabled, f1)             \
   239   virtual intx hash() const {                         \
   240     return (enabled) ? HASH2(name(), f1) : 0;         \
   241   }                                                   \
   242   virtual bool is_equal(Value v) const {              \
   243     if (!(enabled)  ) return false;                   \
   244     class_name* _v = v->as_##class_name();            \
   245     if (_v == NULL  ) return false;                   \
   246     if (f1 != _v->f1) return false;                   \
   247     return true;                                      \
   248   }                                                   \
   251 #define HASHING2(class_name, enabled, f1, f2)         \
   252   virtual intx hash() const {                         \
   253     return (enabled) ? HASH3(name(), f1, f2) : 0;     \
   254   }                                                   \
   255   virtual bool is_equal(Value v) const {              \
   256     if (!(enabled)  ) return false;                   \
   257     class_name* _v = v->as_##class_name();            \
   258     if (_v == NULL  ) return false;                   \
   259     if (f1 != _v->f1) return false;                   \
   260     if (f2 != _v->f2) return false;                   \
   261     return true;                                      \
   262   }                                                   \
   265 #define HASHING3(class_name, enabled, f1, f2, f3)     \
   266   virtual intx hash() const {                          \
   267     return (enabled) ? HASH4(name(), f1, f2, f3) : 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     if (f3 != _v->f3) return false;                   \
   276     return true;                                      \
   277   }                                                   \
   280 // The mother of all instructions...
   282 class Instruction: public CompilationResourceObj {
   283  private:
   284   int          _id;                              // the unique instruction id
   285 #ifndef PRODUCT
   286   int          _printable_bci;                   // the bci of the instruction for printing
   287 #endif
   288   int          _use_count;                       // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1
   289   int          _pin_state;                       // set of PinReason describing the reason for pinning
   290   ValueType*   _type;                            // the instruction value type
   291   Instruction* _next;                            // the next instruction if any (NULL for BlockEnd instructions)
   292   Instruction* _subst;                           // the substitution instruction if any
   293   LIR_Opr      _operand;                         // LIR specific information
   294   unsigned int _flags;                           // Flag bits
   296   ValueStack*  _state_before;                    // Copy of state with input operands still on stack (or NULL)
   297   ValueStack*  _exception_state;                 // Copy of state for exception handling
   298   XHandlers*   _exception_handlers;              // Flat list of exception handlers covering this instruction
   300   friend class UseCountComputer;
   301   friend class BlockBegin;
   303   void update_exception_state(ValueStack* state);
   305  protected:
   306   void set_type(ValueType* type) {
   307     assert(type != NULL, "type must exist");
   308     _type = type;
   309   }
   311  public:
   312   void* operator new(size_t size) {
   313     Compilation* c = Compilation::current();
   314     void* res = c->arena()->Amalloc(size);
   315     ((Instruction*)res)->_id = c->get_next_id();
   316     return res;
   317   }
   319   static const int no_bci = -99;
   321   enum InstructionFlag {
   322     NeedsNullCheckFlag = 0,
   323     CanTrapFlag,
   324     DirectCompareFlag,
   325     IsEliminatedFlag,
   326     IsSafepointFlag,
   327     IsStaticFlag,
   328     IsStrictfpFlag,
   329     NeedsStoreCheckFlag,
   330     NeedsWriteBarrierFlag,
   331     PreservesStateFlag,
   332     TargetIsFinalFlag,
   333     TargetIsLoadedFlag,
   334     TargetIsStrictfpFlag,
   335     UnorderedIsTrueFlag,
   336     NeedsPatchingFlag,
   337     ThrowIncompatibleClassChangeErrorFlag,
   338     ProfileMDOFlag,
   339     IsLinkedInBlockFlag,
   340     InstructionLastFlag
   341   };
   343  public:
   344   bool check_flag(InstructionFlag id) const      { return (_flags & (1 << id)) != 0;    }
   345   void set_flag(InstructionFlag id, bool f)      { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); };
   347   // 'globally' used condition values
   348   enum Condition {
   349     eql, neq, lss, leq, gtr, geq
   350   };
   352   // Instructions may be pinned for many reasons and under certain conditions
   353   // with enough knowledge it's possible to safely unpin them.
   354   enum PinReason {
   355       PinUnknown           = 1 << 0
   356     , PinExplicitNullCheck = 1 << 3
   357     , PinStackForStateSplit= 1 << 12
   358     , PinStateSplitConstructor= 1 << 13
   359     , PinGlobalValueNumbering= 1 << 14
   360   };
   362   static Condition mirror(Condition cond);
   363   static Condition negate(Condition cond);
   365   // initialization
   366   static int number_of_instructions() {
   367     return Compilation::current()->number_of_instructions();
   368   }
   370   // creation
   371   Instruction(ValueType* type, ValueStack* state_before = NULL, bool type_is_constant = false)
   372   : _use_count(0)
   373 #ifndef PRODUCT
   374   , _printable_bci(-99)
   375 #endif
   376   , _pin_state(0)
   377   , _type(type)
   378   , _next(NULL)
   379   , _subst(NULL)
   380   , _flags(0)
   381   , _operand(LIR_OprFact::illegalOpr)
   382   , _state_before(state_before)
   383   , _exception_handlers(NULL)
   384   {
   385     check_state(state_before);
   386     assert(type != NULL && (!type->is_constant() || type_is_constant), "type must exist");
   387     update_exception_state(_state_before);
   388   }
   390   // accessors
   391   int id() const                                 { return _id; }
   392 #ifndef PRODUCT
   393   bool has_printable_bci() const                 { return _printable_bci != -99; }
   394   int printable_bci() const                      { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
   395   void set_printable_bci(int bci)                { _printable_bci = bci; }
   396 #endif
   397   int use_count() const                          { return _use_count; }
   398   int pin_state() const                          { return _pin_state; }
   399   bool is_pinned() const                         { return _pin_state != 0 || PinAllInstructions; }
   400   ValueType* type() const                        { return _type; }
   401   Instruction* prev(BlockBegin* block);          // use carefully, expensive operation
   402   Instruction* next() const                      { return _next; }
   403   bool has_subst() const                         { return _subst != NULL; }
   404   Instruction* subst()                           { return _subst == NULL ? this : _subst->subst(); }
   405   LIR_Opr operand() const                        { return _operand; }
   407   void set_needs_null_check(bool f)              { set_flag(NeedsNullCheckFlag, f); }
   408   bool needs_null_check() const                  { return check_flag(NeedsNullCheckFlag); }
   409   bool is_linked() const                         { return check_flag(IsLinkedInBlockFlag); }
   410   bool can_be_linked()                           { return as_Local() == NULL && as_Phi() == NULL; }
   412   bool has_uses() const                          { return use_count() > 0; }
   413   ValueStack* state_before() const               { return _state_before; }
   414   ValueStack* exception_state() const            { return _exception_state; }
   415   virtual bool needs_exception_state() const     { return true; }
   416   XHandlers* exception_handlers() const          { return _exception_handlers; }
   418   // manipulation
   419   void pin(PinReason reason)                     { _pin_state |= reason; }
   420   void pin()                                     { _pin_state |= PinUnknown; }
   421   // DANGEROUS: only used by EliminateStores
   422   void unpin(PinReason reason)                   { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
   424   Instruction* set_next(Instruction* next) {
   425     assert(next->has_printable_bci(), "_printable_bci should have been set");
   426     assert(next != NULL, "must not be NULL");
   427     assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");
   428     assert(next->can_be_linked(), "shouldn't link these instructions into list");
   430     next->set_flag(Instruction::IsLinkedInBlockFlag, true);
   431     _next = next;
   432     return next;
   433   }
   435   Instruction* set_next(Instruction* next, int bci) {
   436 #ifndef PRODUCT
   437     next->set_printable_bci(bci);
   438 #endif
   439     return set_next(next);
   440   }
   442   void set_subst(Instruction* subst)             {
   443     assert(subst == NULL ||
   444            type()->base() == subst->type()->base() ||
   445            subst->type()->base() == illegalType, "type can't change");
   446     _subst = subst;
   447   }
   448   void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
   449   void set_exception_state(ValueStack* s)        { check_state(s); _exception_state = s; }
   451   // machine-specifics
   452   void set_operand(LIR_Opr operand)              { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
   453   void clear_operand()                           { _operand = LIR_OprFact::illegalOpr; }
   455   // generic
   456   virtual Instruction*      as_Instruction()     { return this; } // to satisfy HASHING1 macro
   457   virtual Phi*              as_Phi()             { return NULL; }
   458   virtual Local*            as_Local()           { return NULL; }
   459   virtual Constant*         as_Constant()        { return NULL; }
   460   virtual AccessField*      as_AccessField()     { return NULL; }
   461   virtual LoadField*        as_LoadField()       { return NULL; }
   462   virtual StoreField*       as_StoreField()      { return NULL; }
   463   virtual AccessArray*      as_AccessArray()     { return NULL; }
   464   virtual ArrayLength*      as_ArrayLength()     { return NULL; }
   465   virtual AccessIndexed*    as_AccessIndexed()   { return NULL; }
   466   virtual LoadIndexed*      as_LoadIndexed()     { return NULL; }
   467   virtual StoreIndexed*     as_StoreIndexed()    { return NULL; }
   468   virtual NegateOp*         as_NegateOp()        { return NULL; }
   469   virtual Op2*              as_Op2()             { return NULL; }
   470   virtual ArithmeticOp*     as_ArithmeticOp()    { return NULL; }
   471   virtual ShiftOp*          as_ShiftOp()         { return NULL; }
   472   virtual LogicOp*          as_LogicOp()         { return NULL; }
   473   virtual CompareOp*        as_CompareOp()       { return NULL; }
   474   virtual IfOp*             as_IfOp()            { return NULL; }
   475   virtual Convert*          as_Convert()         { return NULL; }
   476   virtual NullCheck*        as_NullCheck()       { return NULL; }
   477   virtual OsrEntry*         as_OsrEntry()        { return NULL; }
   478   virtual StateSplit*       as_StateSplit()      { return NULL; }
   479   virtual Invoke*           as_Invoke()          { return NULL; }
   480   virtual NewInstance*      as_NewInstance()     { return NULL; }
   481   virtual NewArray*         as_NewArray()        { return NULL; }
   482   virtual NewTypeArray*     as_NewTypeArray()    { return NULL; }
   483   virtual NewObjectArray*   as_NewObjectArray()  { return NULL; }
   484   virtual NewMultiArray*    as_NewMultiArray()   { return NULL; }
   485   virtual TypeCheck*        as_TypeCheck()       { return NULL; }
   486   virtual CheckCast*        as_CheckCast()       { return NULL; }
   487   virtual InstanceOf*       as_InstanceOf()      { return NULL; }
   488   virtual AccessMonitor*    as_AccessMonitor()   { return NULL; }
   489   virtual MonitorEnter*     as_MonitorEnter()    { return NULL; }
   490   virtual MonitorExit*      as_MonitorExit()     { return NULL; }
   491   virtual Intrinsic*        as_Intrinsic()       { return NULL; }
   492   virtual BlockBegin*       as_BlockBegin()      { return NULL; }
   493   virtual BlockEnd*         as_BlockEnd()        { return NULL; }
   494   virtual Goto*             as_Goto()            { return NULL; }
   495   virtual If*               as_If()              { return NULL; }
   496   virtual IfInstanceOf*     as_IfInstanceOf()    { return NULL; }
   497   virtual TableSwitch*      as_TableSwitch()     { return NULL; }
   498   virtual LookupSwitch*     as_LookupSwitch()    { return NULL; }
   499   virtual Return*           as_Return()          { return NULL; }
   500   virtual Throw*            as_Throw()           { return NULL; }
   501   virtual Base*             as_Base()            { return NULL; }
   502   virtual RoundFP*          as_RoundFP()         { return NULL; }
   503   virtual ExceptionObject*  as_ExceptionObject() { return NULL; }
   504   virtual UnsafeOp*         as_UnsafeOp()        { return NULL; }
   505   virtual ProfileInvoke*    as_ProfileInvoke()   { return NULL; }
   507   virtual void visit(InstructionVisitor* v)      = 0;
   509   virtual bool can_trap() const                  { return false; }
   511   virtual void input_values_do(ValueVisitor* f)   = 0;
   512   virtual void state_values_do(ValueVisitor* f);
   513   virtual void other_values_do(ValueVisitor* f)   { /* usually no other - override on demand */ }
   514           void       values_do(ValueVisitor* f)   { input_values_do(f); state_values_do(f); other_values_do(f); }
   516   virtual ciType* exact_type() const             { return NULL; }
   517   virtual ciType* declared_type() const          { return NULL; }
   519   // hashing
   520   virtual const char* name() const               = 0;
   521   HASHING1(Instruction, false, id())             // hashing disabled by default
   523   // debugging
   524   static void check_state(ValueStack* state)     PRODUCT_RETURN;
   525   void print()                                   PRODUCT_RETURN;
   526   void print_line()                              PRODUCT_RETURN;
   527   void print(InstructionPrinter& ip)             PRODUCT_RETURN;
   528 };
   531 // The following macros are used to define base (i.e., non-leaf)
   532 // and leaf instruction classes. They define class-name related
   533 // generic functionality in one place.
   535 #define BASE(class_name, super_class_name)       \
   536   class class_name: public super_class_name {    \
   537    public:                                       \
   538     virtual class_name* as_##class_name()        { return this; }              \
   541 #define LEAF(class_name, super_class_name)       \
   542   BASE(class_name, super_class_name)             \
   543    public:                                       \
   544     virtual const char* name() const             { return #class_name; }       \
   545     virtual void visit(InstructionVisitor* v)    { v->do_##class_name(this); } \
   548 // Debugging support
   551 #ifdef ASSERT
   552 class AssertValues: public ValueVisitor {
   553   void visit(Value* x)             { assert((*x) != NULL, "value must exist"); }
   554 };
   555   #define ASSERT_VALUES                          { AssertValues assert_value; values_do(&assert_value); }
   556 #else
   557   #define ASSERT_VALUES
   558 #endif // ASSERT
   561 // A Phi is a phi function in the sense of SSA form. It stands for
   562 // the value of a local variable at the beginning of a join block.
   563 // A Phi consists of n operands, one for every incoming branch.
   565 LEAF(Phi, Instruction)
   566  private:
   567   BlockBegin* _block;    // the block to which the phi function belongs
   568   int         _pf_flags; // the flags of the phi function
   569   int         _index;    // to value on operand stack (index < 0) or to local
   570  public:
   571   // creation
   572   Phi(ValueType* type, BlockBegin* b, int index)
   573   : Instruction(type->base())
   574   , _pf_flags(0)
   575   , _block(b)
   576   , _index(index)
   577   {
   578     NOT_PRODUCT(set_printable_bci(Value(b)->printable_bci()));
   579     if (type->is_illegal()) {
   580       make_illegal();
   581     }
   582   }
   584   // flags
   585   enum Flag {
   586     no_flag         = 0,
   587     visited         = 1 << 0,
   588     cannot_simplify = 1 << 1
   589   };
   591   // accessors
   592   bool  is_local() const          { return _index >= 0; }
   593   bool  is_on_stack() const       { return !is_local(); }
   594   int   local_index() const       { assert(is_local(), ""); return _index; }
   595   int   stack_index() const       { assert(is_on_stack(), ""); return -(_index+1); }
   597   Value operand_at(int i) const;
   598   int   operand_count() const;
   600   BlockBegin* block() const       { return _block; }
   602   void   set(Flag f)              { _pf_flags |=  f; }
   603   void   clear(Flag f)            { _pf_flags &= ~f; }
   604   bool   is_set(Flag f) const     { return (_pf_flags & f) != 0; }
   606   // Invalidates phis corresponding to merges of locals of two different types
   607   // (these should never be referenced, otherwise the bytecodes are illegal)
   608   void   make_illegal() {
   609     set(cannot_simplify);
   610     set_type(illegalType);
   611   }
   613   bool is_illegal() const {
   614     return type()->is_illegal();
   615   }
   617   // generic
   618   virtual void input_values_do(ValueVisitor* f) {
   619   }
   620 };
   623 // A local is a placeholder for an incoming argument to a function call.
   624 LEAF(Local, Instruction)
   625  private:
   626   int      _java_index;                          // the local index within the method to which the local belongs
   627   ciType*  _declared_type;
   628  public:
   629   // creation
   630   Local(ciType* declared, ValueType* type, int index)
   631     : Instruction(type)
   632     , _java_index(index)
   633     , _declared_type(declared)
   634   {
   635     NOT_PRODUCT(set_printable_bci(-1));
   636   }
   638   // accessors
   639   int java_index() const                         { return _java_index; }
   641   ciType* declared_type() const                  { return _declared_type; }
   642   ciType* exact_type() const;
   644   // generic
   645   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
   646 };
   649 LEAF(Constant, Instruction)
   650  public:
   651   // creation
   652   Constant(ValueType* type):
   653       Instruction(type, NULL, true)
   654   {
   655     assert(type->is_constant(), "must be a constant");
   656   }
   658   Constant(ValueType* type, ValueStack* state_before):
   659     Instruction(type, state_before, true)
   660   {
   661     assert(state_before != NULL, "only used for constants which need patching");
   662     assert(type->is_constant(), "must be a constant");
   663     // since it's patching it needs to be pinned
   664     pin();
   665   }
   667   virtual bool can_trap() const                  { return state_before() != NULL; }
   668   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
   670   virtual intx hash() const;
   671   virtual bool is_equal(Value v) const;
   674   enum CompareResult { not_comparable = -1, cond_false, cond_true };
   676   virtual CompareResult compare(Instruction::Condition condition, Value right) const;
   677   BlockBegin* compare(Instruction::Condition cond, Value right,
   678                       BlockBegin* true_sux, BlockBegin* false_sux) const {
   679     switch (compare(cond, right)) {
   680     case not_comparable:
   681       return NULL;
   682     case cond_false:
   683       return false_sux;
   684     case cond_true:
   685       return true_sux;
   686     default:
   687       ShouldNotReachHere();
   688       return NULL;
   689     }
   690   }
   691 };
   694 BASE(AccessField, Instruction)
   695  private:
   696   Value       _obj;
   697   int         _offset;
   698   ciField*    _field;
   699   NullCheck*  _explicit_null_check;              // For explicit null check elimination
   701  public:
   702   // creation
   703   AccessField(Value obj, int offset, ciField* field, bool is_static,
   704               ValueStack* state_before, bool needs_patching)
   705   : Instruction(as_ValueType(field->type()->basic_type()), state_before)
   706   , _obj(obj)
   707   , _offset(offset)
   708   , _field(field)
   709   , _explicit_null_check(NULL)
   710   {
   711     set_needs_null_check(!is_static);
   712     set_flag(IsStaticFlag, is_static);
   713     set_flag(NeedsPatchingFlag, needs_patching);
   714     ASSERT_VALUES
   715     // pin of all instructions with memory access
   716     pin();
   717   }
   719   // accessors
   720   Value obj() const                              { return _obj; }
   721   int offset() const                             { return _offset; }
   722   ciField* field() const                         { return _field; }
   723   BasicType field_type() const                   { return _field->type()->basic_type(); }
   724   bool is_static() const                         { return check_flag(IsStaticFlag); }
   725   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
   726   bool needs_patching() const                    { return check_flag(NeedsPatchingFlag); }
   728   // Unresolved getstatic and putstatic can cause initialization.
   729   // Technically it occurs at the Constant that materializes the base
   730   // of the static fields but it's simpler to model it here.
   731   bool is_init_point() const                     { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); }
   733   // manipulation
   735   // Under certain circumstances, if a previous NullCheck instruction
   736   // proved the target object non-null, we can eliminate the explicit
   737   // null check and do an implicit one, simply specifying the debug
   738   // information from the NullCheck. This field should only be consulted
   739   // if needs_null_check() is true.
   740   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
   742   // generic
   743   virtual bool can_trap() const                  { return needs_null_check() || needs_patching(); }
   744   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_obj); }
   745 };
   748 LEAF(LoadField, AccessField)
   749  public:
   750   // creation
   751   LoadField(Value obj, int offset, ciField* field, bool is_static,
   752             ValueStack* state_before, bool needs_patching)
   753   : AccessField(obj, offset, field, is_static, state_before, needs_patching)
   754   {}
   756   ciType* declared_type() const;
   757   ciType* exact_type() const;
   759   // generic
   760   HASHING2(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset())  // cannot be eliminated if needs patching or if volatile
   761 };
   764 LEAF(StoreField, AccessField)
   765  private:
   766   Value _value;
   768  public:
   769   // creation
   770   StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
   771              ValueStack* state_before, bool needs_patching)
   772   : AccessField(obj, offset, field, is_static, state_before, needs_patching)
   773   , _value(value)
   774   {
   775     set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
   776     ASSERT_VALUES
   777     pin();
   778   }
   780   // accessors
   781   Value value() const                            { return _value; }
   782   bool needs_write_barrier() const               { return check_flag(NeedsWriteBarrierFlag); }
   784   // generic
   785   virtual void input_values_do(ValueVisitor* f)   { AccessField::input_values_do(f); f->visit(&_value); }
   786 };
   789 BASE(AccessArray, Instruction)
   790  private:
   791   Value       _array;
   793  public:
   794   // creation
   795   AccessArray(ValueType* type, Value array, ValueStack* state_before)
   796   : Instruction(type, state_before)
   797   , _array(array)
   798   {
   799     set_needs_null_check(true);
   800     ASSERT_VALUES
   801     pin(); // instruction with side effect (null exception or range check throwing)
   802   }
   804   Value array() const                            { return _array; }
   806   // generic
   807   virtual bool can_trap() const                  { return needs_null_check(); }
   808   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_array); }
   809 };
   812 LEAF(ArrayLength, AccessArray)
   813  private:
   814   NullCheck*  _explicit_null_check;              // For explicit null check elimination
   816  public:
   817   // creation
   818   ArrayLength(Value array, ValueStack* state_before)
   819   : AccessArray(intType, array, state_before)
   820   , _explicit_null_check(NULL) {}
   822   // accessors
   823   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
   825   // setters
   826   // See LoadField::set_explicit_null_check for documentation
   827   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
   829   // generic
   830   HASHING1(ArrayLength, true, array()->subst())
   831 };
   834 BASE(AccessIndexed, AccessArray)
   835  private:
   836   Value     _index;
   837   Value     _length;
   838   BasicType _elt_type;
   840  public:
   841   // creation
   842   AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
   843   : AccessArray(as_ValueType(elt_type), array, state_before)
   844   , _index(index)
   845   , _length(length)
   846   , _elt_type(elt_type)
   847   {
   848     ASSERT_VALUES
   849   }
   851   // accessors
   852   Value index() const                            { return _index; }
   853   Value length() const                           { return _length; }
   854   BasicType elt_type() const                     { return _elt_type; }
   856   // perform elimination of range checks involving constants
   857   bool compute_needs_range_check();
   859   // generic
   860   virtual void input_values_do(ValueVisitor* f)   { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }
   861 };
   864 LEAF(LoadIndexed, AccessIndexed)
   865  private:
   866   NullCheck*  _explicit_null_check;              // For explicit null check elimination
   868  public:
   869   // creation
   870   LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
   871   : AccessIndexed(array, index, length, elt_type, state_before)
   872   , _explicit_null_check(NULL) {}
   874   // accessors
   875   NullCheck* explicit_null_check() const         { return _explicit_null_check; }
   877   // setters
   878   // See LoadField::set_explicit_null_check for documentation
   879   void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
   881   ciType* exact_type() const;
   882   ciType* declared_type() const;
   884   // generic
   885   HASHING2(LoadIndexed, true, array()->subst(), index()->subst())
   886 };
   889 LEAF(StoreIndexed, AccessIndexed)
   890  private:
   891   Value       _value;
   893   ciMethod* _profiled_method;
   894   int       _profiled_bci;
   895  public:
   896   // creation
   897   StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before)
   898   : AccessIndexed(array, index, length, elt_type, state_before)
   899   , _value(value), _profiled_method(NULL), _profiled_bci(0)
   900   {
   901     set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
   902     set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
   903     ASSERT_VALUES
   904     pin();
   905   }
   907   // accessors
   908   Value value() const                            { return _value; }
   909   bool needs_write_barrier() const               { return check_flag(NeedsWriteBarrierFlag); }
   910   bool needs_store_check() const                 { return check_flag(NeedsStoreCheckFlag); }
   911   // Helpers for methodDataOop profiling
   912   void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
   913   void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
   914   void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
   915   bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
   916   ciMethod* profiled_method() const                  { return _profiled_method;     }
   917   int       profiled_bci() const                     { return _profiled_bci;        }
   918   // generic
   919   virtual void input_values_do(ValueVisitor* f)   { AccessIndexed::input_values_do(f); f->visit(&_value); }
   920 };
   923 LEAF(NegateOp, Instruction)
   924  private:
   925   Value _x;
   927  public:
   928   // creation
   929   NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
   930     ASSERT_VALUES
   931   }
   933   // accessors
   934   Value x() const                                { return _x; }
   936   // generic
   937   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_x); }
   938 };
   941 BASE(Op2, Instruction)
   942  private:
   943   Bytecodes::Code _op;
   944   Value           _x;
   945   Value           _y;
   947  public:
   948   // creation
   949   Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = NULL)
   950   : Instruction(type, state_before)
   951   , _op(op)
   952   , _x(x)
   953   , _y(y)
   954   {
   955     ASSERT_VALUES
   956   }
   958   // accessors
   959   Bytecodes::Code op() const                     { return _op; }
   960   Value x() const                                { return _x; }
   961   Value y() const                                { return _y; }
   963   // manipulators
   964   void swap_operands() {
   965     assert(is_commutative(), "operation must be commutative");
   966     Value t = _x; _x = _y; _y = t;
   967   }
   969   // generic
   970   virtual bool is_commutative() const            { return false; }
   971   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_x); f->visit(&_y); }
   972 };
   975 LEAF(ArithmeticOp, Op2)
   976  public:
   977   // creation
   978   ArithmeticOp(Bytecodes::Code op, Value x, Value y, bool is_strictfp, ValueStack* state_before)
   979   : Op2(x->type()->meet(y->type()), op, x, y, state_before)
   980   {
   981     set_flag(IsStrictfpFlag, is_strictfp);
   982     if (can_trap()) pin();
   983   }
   985   // accessors
   986   bool        is_strictfp() const                { return check_flag(IsStrictfpFlag); }
   988   // generic
   989   virtual bool is_commutative() const;
   990   virtual bool can_trap() const;
   991   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
   992 };
   995 LEAF(ShiftOp, Op2)
   996  public:
   997   // creation
   998   ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}
  1000   // generic
  1001   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
  1002 };
  1005 LEAF(LogicOp, Op2)
  1006  public:
  1007   // creation
  1008   LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}
  1010   // generic
  1011   virtual bool is_commutative() const;
  1012   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
  1013 };
  1016 LEAF(CompareOp, Op2)
  1017  public:
  1018   // creation
  1019   CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
  1020   : Op2(intType, op, x, y, state_before)
  1021   {}
  1023   // generic
  1024   HASHING3(Op2, true, op(), x()->subst(), y()->subst())
  1025 };
  1028 LEAF(IfOp, Op2)
  1029  private:
  1030   Value _tval;
  1031   Value _fval;
  1033  public:
  1034   // creation
  1035   IfOp(Value x, Condition cond, Value y, Value tval, Value fval)
  1036   : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
  1037   , _tval(tval)
  1038   , _fval(fval)
  1040     ASSERT_VALUES
  1041     assert(tval->type()->tag() == fval->type()->tag(), "types must match");
  1044   // accessors
  1045   virtual bool is_commutative() const;
  1046   Bytecodes::Code op() const                     { ShouldNotCallThis(); return Bytecodes::_illegal; }
  1047   Condition cond() const                         { return (Condition)Op2::op(); }
  1048   Value tval() const                             { return _tval; }
  1049   Value fval() const                             { return _fval; }
  1051   // generic
  1052   virtual void input_values_do(ValueVisitor* f)   { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
  1053 };
  1056 LEAF(Convert, Instruction)
  1057  private:
  1058   Bytecodes::Code _op;
  1059   Value           _value;
  1061  public:
  1062   // creation
  1063   Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
  1064     ASSERT_VALUES
  1067   // accessors
  1068   Bytecodes::Code op() const                     { return _op; }
  1069   Value value() const                            { return _value; }
  1071   // generic
  1072   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_value); }
  1073   HASHING2(Convert, true, op(), value()->subst())
  1074 };
  1077 LEAF(NullCheck, Instruction)
  1078  private:
  1079   Value       _obj;
  1081  public:
  1082   // creation
  1083   NullCheck(Value obj, ValueStack* state_before)
  1084   : Instruction(obj->type()->base(), state_before)
  1085   , _obj(obj)
  1087     ASSERT_VALUES
  1088     set_can_trap(true);
  1089     assert(_obj->type()->is_object(), "null check must be applied to objects only");
  1090     pin(Instruction::PinExplicitNullCheck);
  1093   // accessors
  1094   Value obj() const                              { return _obj; }
  1096   // setters
  1097   void set_can_trap(bool can_trap)               { set_flag(CanTrapFlag, can_trap); }
  1099   // generic
  1100   virtual bool can_trap() const                  { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }
  1101   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_obj); }
  1102   HASHING1(NullCheck, true, obj()->subst())
  1103 };
  1106 BASE(StateSplit, Instruction)
  1107  private:
  1108   ValueStack* _state;
  1110  protected:
  1111   static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);
  1113  public:
  1114   // creation
  1115   StateSplit(ValueType* type, ValueStack* state_before = NULL)
  1116   : Instruction(type, state_before)
  1117   , _state(NULL)
  1119     pin(PinStateSplitConstructor);
  1122   // accessors
  1123   ValueStack* state() const                      { return _state; }
  1124   IRScope* scope() const;                        // the state's scope
  1126   // manipulation
  1127   void set_state(ValueStack* state)              { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }
  1129   // generic
  1130   virtual void input_values_do(ValueVisitor* f)   { /* no values */ }
  1131   virtual void state_values_do(ValueVisitor* f);
  1132 };
  1135 LEAF(Invoke, StateSplit)
  1136  private:
  1137   Bytecodes::Code _code;
  1138   Value           _recv;
  1139   Values*         _args;
  1140   BasicTypeList*  _signature;
  1141   int             _vtable_index;
  1142   ciMethod*       _target;
  1144  public:
  1145   // creation
  1146   Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
  1147          int vtable_index, ciMethod* target, ValueStack* state_before);
  1149   // accessors
  1150   Bytecodes::Code code() const                   { return _code; }
  1151   Value receiver() const                         { return _recv; }
  1152   bool has_receiver() const                      { return receiver() != NULL; }
  1153   int number_of_arguments() const                { return _args->length(); }
  1154   Value argument_at(int i) const                 { return _args->at(i); }
  1155   int vtable_index() const                       { return _vtable_index; }
  1156   BasicTypeList* signature() const               { return _signature; }
  1157   ciMethod* target() const                       { return _target; }
  1159   ciType* declared_type() const;
  1161   // Returns false if target is not loaded
  1162   bool target_is_final() const                   { return check_flag(TargetIsFinalFlag); }
  1163   bool target_is_loaded() const                  { return check_flag(TargetIsLoadedFlag); }
  1164   // Returns false if target is not loaded
  1165   bool target_is_strictfp() const                { return check_flag(TargetIsStrictfpFlag); }
  1167   // JSR 292 support
  1168   bool is_invokedynamic() const                  { return code() == Bytecodes::_invokedynamic; }
  1170   virtual bool needs_exception_state() const     { return false; }
  1172   // generic
  1173   virtual bool can_trap() const                  { return true; }
  1174   virtual void input_values_do(ValueVisitor* f) {
  1175     StateSplit::input_values_do(f);
  1176     if (has_receiver()) f->visit(&_recv);
  1177     for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
  1179   virtual void state_values_do(ValueVisitor *f);
  1180 };
  1183 LEAF(NewInstance, StateSplit)
  1184  private:
  1185   ciInstanceKlass* _klass;
  1187  public:
  1188   // creation
  1189   NewInstance(ciInstanceKlass* klass, ValueStack* state_before)
  1190   : StateSplit(instanceType, state_before)
  1191   , _klass(klass)
  1192   {}
  1194   // accessors
  1195   ciInstanceKlass* klass() const                 { return _klass; }
  1197   virtual bool needs_exception_state() const     { return false; }
  1199   // generic
  1200   virtual bool can_trap() const                  { return true; }
  1201   ciType* exact_type() const;
  1202   ciType* declared_type() const;
  1203 };
  1206 BASE(NewArray, StateSplit)
  1207  private:
  1208   Value       _length;
  1210  public:
  1211   // creation
  1212   NewArray(Value length, ValueStack* state_before)
  1213   : StateSplit(objectType, state_before)
  1214   , _length(length)
  1216     // Do not ASSERT_VALUES since length is NULL for NewMultiArray
  1219   // accessors
  1220   Value length() const                           { return _length; }
  1222   virtual bool needs_exception_state() const     { return false; }
  1224   ciType* declared_type() const;
  1226   // generic
  1227   virtual bool can_trap() const                  { return true; }
  1228   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_length); }
  1229 };
  1232 LEAF(NewTypeArray, NewArray)
  1233  private:
  1234   BasicType _elt_type;
  1236  public:
  1237   // creation
  1238   NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)
  1239   : NewArray(length, state_before)
  1240   , _elt_type(elt_type)
  1241   {}
  1243   // accessors
  1244   BasicType elt_type() const                     { return _elt_type; }
  1245   ciType* exact_type() const;
  1246 };
  1249 LEAF(NewObjectArray, NewArray)
  1250  private:
  1251   ciKlass* _klass;
  1253  public:
  1254   // creation
  1255   NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}
  1257   // accessors
  1258   ciKlass* klass() const                         { return _klass; }
  1259   ciType* exact_type() const;
  1260 };
  1263 LEAF(NewMultiArray, NewArray)
  1264  private:
  1265   ciKlass* _klass;
  1266   Values*  _dims;
  1268  public:
  1269   // creation
  1270   NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
  1271     ASSERT_VALUES
  1274   // accessors
  1275   ciKlass* klass() const                         { return _klass; }
  1276   Values* dims() const                           { return _dims; }
  1277   int rank() const                               { return dims()->length(); }
  1279   // generic
  1280   virtual void input_values_do(ValueVisitor* f) {
  1281     // NOTE: we do not call NewArray::input_values_do since "length"
  1282     // is meaningless for a multi-dimensional array; passing the
  1283     // zeroth element down to NewArray as its length is a bad idea
  1284     // since there will be a copy in the "dims" array which doesn't
  1285     // get updated, and the value must not be traversed twice. Was bug
  1286     // - kbr 4/10/2001
  1287     StateSplit::input_values_do(f);
  1288     for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
  1290 };
  1293 BASE(TypeCheck, StateSplit)
  1294  private:
  1295   ciKlass*    _klass;
  1296   Value       _obj;
  1298   ciMethod* _profiled_method;
  1299   int       _profiled_bci;
  1301  public:
  1302   // creation
  1303   TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
  1304   : StateSplit(type, state_before), _klass(klass), _obj(obj),
  1305     _profiled_method(NULL), _profiled_bci(0) {
  1306     ASSERT_VALUES
  1307     set_direct_compare(false);
  1310   // accessors
  1311   ciKlass* klass() const                         { return _klass; }
  1312   Value obj() const                              { return _obj; }
  1313   bool is_loaded() const                         { return klass() != NULL; }
  1314   bool direct_compare() const                    { return check_flag(DirectCompareFlag); }
  1316   // manipulation
  1317   void set_direct_compare(bool flag)             { set_flag(DirectCompareFlag, flag); }
  1319   // generic
  1320   virtual bool can_trap() const                  { return true; }
  1321   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
  1323   // Helpers for methodDataOop profiling
  1324   void set_should_profile(bool value)                { set_flag(ProfileMDOFlag, value); }
  1325   void set_profiled_method(ciMethod* method)         { _profiled_method = method;   }
  1326   void set_profiled_bci(int bci)                     { _profiled_bci = bci;         }
  1327   bool      should_profile() const                   { return check_flag(ProfileMDOFlag); }
  1328   ciMethod* profiled_method() const                  { return _profiled_method;     }
  1329   int       profiled_bci() const                     { return _profiled_bci;        }
  1330 };
  1333 LEAF(CheckCast, TypeCheck)
  1334  public:
  1335   // creation
  1336   CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
  1337   : TypeCheck(klass, obj, objectType, state_before) {}
  1339   void set_incompatible_class_change_check() {
  1340     set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
  1342   bool is_incompatible_class_change_check() const {
  1343     return check_flag(ThrowIncompatibleClassChangeErrorFlag);
  1346   ciType* declared_type() const;
  1347   ciType* exact_type() const;
  1348 };
  1351 LEAF(InstanceOf, TypeCheck)
  1352  public:
  1353   // creation
  1354   InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}
  1356   virtual bool needs_exception_state() const     { return false; }
  1357 };
  1360 BASE(AccessMonitor, StateSplit)
  1361  private:
  1362   Value       _obj;
  1363   int         _monitor_no;
  1365  public:
  1366   // creation
  1367   AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)
  1368   : StateSplit(illegalType, state_before)
  1369   , _obj(obj)
  1370   , _monitor_no(monitor_no)
  1372     set_needs_null_check(true);
  1373     ASSERT_VALUES
  1376   // accessors
  1377   Value obj() const                              { return _obj; }
  1378   int monitor_no() const                         { return _monitor_no; }
  1380   // generic
  1381   virtual void input_values_do(ValueVisitor* f)   { StateSplit::input_values_do(f); f->visit(&_obj); }
  1382 };
  1385 LEAF(MonitorEnter, AccessMonitor)
  1386  public:
  1387   // creation
  1388   MonitorEnter(Value obj, int monitor_no, ValueStack* state_before)
  1389   : AccessMonitor(obj, monitor_no, state_before)
  1391     ASSERT_VALUES
  1394   // generic
  1395   virtual bool can_trap() const                  { return true; }
  1396 };
  1399 LEAF(MonitorExit, AccessMonitor)
  1400  public:
  1401   // creation
  1402   MonitorExit(Value obj, int monitor_no)
  1403   : AccessMonitor(obj, monitor_no, NULL)
  1405     ASSERT_VALUES
  1407 };
  1410 LEAF(Intrinsic, StateSplit)
  1411  private:
  1412   vmIntrinsics::ID _id;
  1413   Values*          _args;
  1414   Value            _recv;
  1415   int              _nonnull_state; // mask identifying which args are nonnull
  1417  public:
  1418   // preserves_state can be set to true for Intrinsics
  1419   // which are guaranteed to preserve register state across any slow
  1420   // cases; setting it to true does not mean that the Intrinsic can
  1421   // not trap, only that if we continue execution in the same basic
  1422   // block after the Intrinsic, all of the registers are intact. This
  1423   // allows load elimination and common expression elimination to be
  1424   // performed across the Intrinsic.  The default value is false.
  1425   Intrinsic(ValueType* type,
  1426             vmIntrinsics::ID id,
  1427             Values* args,
  1428             bool has_receiver,
  1429             ValueStack* state_before,
  1430             bool preserves_state,
  1431             bool cantrap = true)
  1432   : StateSplit(type, state_before)
  1433   , _id(id)
  1434   , _args(args)
  1435   , _recv(NULL)
  1436   , _nonnull_state(AllBits)
  1438     assert(args != NULL, "args must exist");
  1439     ASSERT_VALUES
  1440     set_flag(PreservesStateFlag, preserves_state);
  1441     set_flag(CanTrapFlag,        cantrap);
  1442     if (has_receiver) {
  1443       _recv = argument_at(0);
  1445     set_needs_null_check(has_receiver);
  1447     // some intrinsics can't trap, so don't force them to be pinned
  1448     if (!can_trap()) {
  1449       unpin(PinStateSplitConstructor);
  1453   // accessors
  1454   vmIntrinsics::ID id() const                    { return _id; }
  1455   int number_of_arguments() const                { return _args->length(); }
  1456   Value argument_at(int i) const                 { return _args->at(i); }
  1458   bool has_receiver() const                      { return (_recv != NULL); }
  1459   Value receiver() const                         { assert(has_receiver(), "must have receiver"); return _recv; }
  1460   bool preserves_state() const                   { return check_flag(PreservesStateFlag); }
  1462   bool arg_needs_null_check(int i) {
  1463     if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
  1464       return is_set_nth_bit(_nonnull_state, i);
  1466     return true;
  1469   void set_arg_needs_null_check(int i, bool check) {
  1470     if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
  1471       if (check) {
  1472         _nonnull_state |= nth_bit(i);
  1473       } else {
  1474         _nonnull_state &= ~(nth_bit(i));
  1479   // generic
  1480   virtual bool can_trap() const                  { return check_flag(CanTrapFlag); }
  1481   virtual void input_values_do(ValueVisitor* f) {
  1482     StateSplit::input_values_do(f);
  1483     for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
  1485 };
  1488 class LIR_List;
  1490 LEAF(BlockBegin, StateSplit)
  1491  private:
  1492   int        _block_id;                          // the unique block id
  1493   int        _bci;                               // start-bci of block
  1494   int        _depth_first_number;                // number of this block in a depth-first ordering
  1495   int        _linear_scan_number;                // number of this block in linear-scan ordering
  1496   int        _loop_depth;                        // the loop nesting level of this block
  1497   int        _loop_index;                        // number of the innermost loop of this block
  1498   int        _flags;                             // the flags associated with this block
  1500   // fields used by BlockListBuilder
  1501   int        _total_preds;                       // number of predecessors found by BlockListBuilder
  1502   BitMap     _stores_to_locals;                  // bit is set when a local variable is stored in the block
  1504   // SSA specific fields: (factor out later)
  1505   BlockList   _successors;                       // the successors of this block
  1506   BlockList   _predecessors;                     // the predecessors of this block
  1507   BlockBegin* _dominator;                        // the dominator of this block
  1508   // SSA specific ends
  1509   BlockEnd*  _end;                               // the last instruction of this block
  1510   BlockList  _exception_handlers;                // the exception handlers potentially invoked by this block
  1511   ValueStackStack* _exception_states;            // only for xhandler entries: states of all instructions that have an edge to this xhandler
  1512   int        _exception_handler_pco;             // if this block is the start of an exception handler,
  1513                                                  // this records the PC offset in the assembly code of the
  1514                                                  // first instruction in this block
  1515   Label      _label;                             // the label associated with this block
  1516   LIR_List*  _lir;                               // the low level intermediate representation for this block
  1518   BitMap      _live_in;                          // set of live LIR_Opr registers at entry to this block
  1519   BitMap      _live_out;                         // set of live LIR_Opr registers at exit from this block
  1520   BitMap      _live_gen;                         // set of registers used before any redefinition in this block
  1521   BitMap      _live_kill;                        // set of registers defined in this block
  1523   BitMap      _fpu_register_usage;
  1524   intArray*   _fpu_stack_state;                  // For x86 FPU code generation with UseLinearScan
  1525   int         _first_lir_instruction_id;         // ID of first LIR instruction in this block
  1526   int         _last_lir_instruction_id;          // ID of last LIR instruction in this block
  1528   void iterate_preorder (boolArray& mark, BlockClosure* closure);
  1529   void iterate_postorder(boolArray& mark, BlockClosure* closure);
  1531   friend class SuxAndWeightAdjuster;
  1533  public:
  1534    void* operator new(size_t size) {
  1535     Compilation* c = Compilation::current();
  1536     void* res = c->arena()->Amalloc(size);
  1537     ((BlockBegin*)res)->_id = c->get_next_id();
  1538     ((BlockBegin*)res)->_block_id = c->get_next_block_id();
  1539     return res;
  1542   // initialization/counting
  1543   static int  number_of_blocks() {
  1544     return Compilation::current()->number_of_blocks();
  1547   // creation
  1548   BlockBegin(int bci)
  1549   : StateSplit(illegalType)
  1550   , _bci(bci)
  1551   , _depth_first_number(-1)
  1552   , _linear_scan_number(-1)
  1553   , _loop_depth(0)
  1554   , _flags(0)
  1555   , _dominator(NULL)
  1556   , _end(NULL)
  1557   , _predecessors(2)
  1558   , _successors(2)
  1559   , _exception_handlers(1)
  1560   , _exception_states(NULL)
  1561   , _exception_handler_pco(-1)
  1562   , _lir(NULL)
  1563   , _loop_index(-1)
  1564   , _live_in()
  1565   , _live_out()
  1566   , _live_gen()
  1567   , _live_kill()
  1568   , _fpu_register_usage()
  1569   , _fpu_stack_state(NULL)
  1570   , _first_lir_instruction_id(-1)
  1571   , _last_lir_instruction_id(-1)
  1572   , _total_preds(0)
  1573   , _stores_to_locals()
  1575 #ifndef PRODUCT
  1576     set_printable_bci(bci);
  1577 #endif
  1580   // accessors
  1581   int block_id() const                           { return _block_id; }
  1582   int bci() const                                { return _bci; }
  1583   BlockList* successors()                        { return &_successors; }
  1584   BlockBegin* dominator() const                  { return _dominator; }
  1585   int loop_depth() const                         { return _loop_depth; }
  1586   int depth_first_number() const                 { return _depth_first_number; }
  1587   int linear_scan_number() const                 { return _linear_scan_number; }
  1588   BlockEnd* end() const                          { return _end; }
  1589   Label* label()                                 { return &_label; }
  1590   LIR_List* lir() const                          { return _lir; }
  1591   int exception_handler_pco() const              { return _exception_handler_pco; }
  1592   BitMap& live_in()                              { return _live_in;        }
  1593   BitMap& live_out()                             { return _live_out;       }
  1594   BitMap& live_gen()                             { return _live_gen;       }
  1595   BitMap& live_kill()                            { return _live_kill;      }
  1596   BitMap& fpu_register_usage()                   { return _fpu_register_usage; }
  1597   intArray* fpu_stack_state() const              { return _fpu_stack_state;    }
  1598   int first_lir_instruction_id() const           { return _first_lir_instruction_id; }
  1599   int last_lir_instruction_id() const            { return _last_lir_instruction_id; }
  1600   int total_preds() const                        { return _total_preds; }
  1601   BitMap& stores_to_locals()                     { return _stores_to_locals; }
  1603   // manipulation
  1604   void set_dominator(BlockBegin* dom)            { _dominator = dom; }
  1605   void set_loop_depth(int d)                     { _loop_depth = d; }
  1606   void set_depth_first_number(int dfn)           { _depth_first_number = dfn; }
  1607   void set_linear_scan_number(int lsn)           { _linear_scan_number = lsn; }
  1608   void set_end(BlockEnd* end);
  1609   void clear_end();
  1610   void disconnect_from_graph();
  1611   static void disconnect_edge(BlockBegin* from, BlockBegin* to);
  1612   BlockBegin* insert_block_between(BlockBegin* sux);
  1613   void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
  1614   void set_lir(LIR_List* lir)                    { _lir = lir; }
  1615   void set_exception_handler_pco(int pco)        { _exception_handler_pco = pco; }
  1616   void set_live_in       (BitMap map)            { _live_in = map;        }
  1617   void set_live_out      (BitMap map)            { _live_out = map;       }
  1618   void set_live_gen      (BitMap map)            { _live_gen = map;       }
  1619   void set_live_kill     (BitMap map)            { _live_kill = map;      }
  1620   void set_fpu_register_usage(BitMap map)        { _fpu_register_usage = map; }
  1621   void set_fpu_stack_state(intArray* state)      { _fpu_stack_state = state;  }
  1622   void set_first_lir_instruction_id(int id)      { _first_lir_instruction_id = id;  }
  1623   void set_last_lir_instruction_id(int id)       { _last_lir_instruction_id = id;  }
  1624   void increment_total_preds(int n = 1)          { _total_preds += n; }
  1625   void init_stores_to_locals(int locals_count)   { _stores_to_locals = BitMap(locals_count); _stores_to_locals.clear(); }
  1627   // generic
  1628   virtual void state_values_do(ValueVisitor* f);
  1630   // successors and predecessors
  1631   int number_of_sux() const;
  1632   BlockBegin* sux_at(int i) const;
  1633   void add_successor(BlockBegin* sux);
  1634   void remove_successor(BlockBegin* pred);
  1635   bool is_successor(BlockBegin* sux) const       { return _successors.contains(sux); }
  1637   void add_predecessor(BlockBegin* pred);
  1638   void remove_predecessor(BlockBegin* pred);
  1639   bool is_predecessor(BlockBegin* pred) const    { return _predecessors.contains(pred); }
  1640   int number_of_preds() const                    { return _predecessors.length(); }
  1641   BlockBegin* pred_at(int i) const               { return _predecessors[i]; }
  1643   // exception handlers potentially invoked by this block
  1644   void add_exception_handler(BlockBegin* b);
  1645   bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }
  1646   int  number_of_exception_handlers() const      { return _exception_handlers.length(); }
  1647   BlockBegin* exception_handler_at(int i) const  { return _exception_handlers.at(i); }
  1649   // states of the instructions that have an edge to this exception handler
  1650   int number_of_exception_states()               { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); }
  1651   ValueStack* exception_state_at(int idx) const  { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }
  1652   int add_exception_state(ValueStack* state);
  1654   // flags
  1655   enum Flag {
  1656     no_flag                       = 0,
  1657     std_entry_flag                = 1 << 0,
  1658     osr_entry_flag                = 1 << 1,
  1659     exception_entry_flag          = 1 << 2,
  1660     subroutine_entry_flag         = 1 << 3,
  1661     backward_branch_target_flag   = 1 << 4,
  1662     is_on_work_list_flag          = 1 << 5,
  1663     was_visited_flag              = 1 << 6,
  1664     parser_loop_header_flag       = 1 << 7,  // set by parser to identify blocks where phi functions can not be created on demand
  1665     critical_edge_split_flag      = 1 << 8, // set for all blocks that are introduced when critical edges are split
  1666     linear_scan_loop_header_flag  = 1 << 9, // set during loop-detection for LinearScan
  1667     linear_scan_loop_end_flag     = 1 << 10  // set during loop-detection for LinearScan
  1668   };
  1670   void set(Flag f)                               { _flags |= f; }
  1671   void clear(Flag f)                             { _flags &= ~f; }
  1672   bool is_set(Flag f) const                      { return (_flags & f) != 0; }
  1673   bool is_entry_block() const {
  1674     const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;
  1675     return (_flags & entry_mask) != 0;
  1678   // iteration
  1679   void iterate_preorder   (BlockClosure* closure);
  1680   void iterate_postorder  (BlockClosure* closure);
  1682   void block_values_do(ValueVisitor* f);
  1684   // loops
  1685   void set_loop_index(int ix)                    { _loop_index = ix;        }
  1686   int  loop_index() const                        { return _loop_index;      }
  1688   // merging
  1689   bool try_merge(ValueStack* state);             // try to merge states at block begin
  1690   void merge(ValueStack* state)                  { bool b = try_merge(state); assert(b, "merge failed"); }
  1692   // debugging
  1693   void print_block()                             PRODUCT_RETURN;
  1694   void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;
  1695 };
  1698 BASE(BlockEnd, StateSplit)
  1699  private:
  1700   BlockBegin* _begin;
  1701   BlockList*  _sux;
  1703  protected:
  1704   BlockList* sux() const                         { return _sux; }
  1706   void set_sux(BlockList* sux) {
  1707 #ifdef ASSERT
  1708     assert(sux != NULL, "sux must exist");
  1709     for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist");
  1710 #endif
  1711     _sux = sux;
  1714  public:
  1715   // creation
  1716   BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)
  1717   : StateSplit(type, state_before)
  1718   , _begin(NULL)
  1719   , _sux(NULL)
  1721     set_flag(IsSafepointFlag, is_safepoint);
  1724   // accessors
  1725   bool is_safepoint() const                      { return check_flag(IsSafepointFlag); }
  1726   BlockBegin* begin() const                      { return _begin; }
  1728   // manipulation
  1729   void set_begin(BlockBegin* begin);
  1731   // successors
  1732   int number_of_sux() const                      { return _sux != NULL ? _sux->length() : 0; }
  1733   BlockBegin* sux_at(int i) const                { return _sux->at(i); }
  1734   BlockBegin* default_sux() const                { return sux_at(number_of_sux() - 1); }
  1735   BlockBegin** addr_sux_at(int i) const          { return _sux->adr_at(i); }
  1736   int sux_index(BlockBegin* sux) const           { return _sux->find(sux); }
  1737   void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
  1738 };
  1741 LEAF(Goto, BlockEnd)
  1742  public:
  1743   enum Direction {
  1744     none,            // Just a regular goto
  1745     taken, not_taken // Goto produced from If
  1746   };
  1747  private:
  1748   ciMethod*   _profiled_method;
  1749   int         _profiled_bci;
  1750   Direction   _direction;
  1751  public:
  1752   // creation
  1753   Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false)
  1754     : BlockEnd(illegalType, state_before, is_safepoint)
  1755     , _direction(none)
  1756     , _profiled_method(NULL)
  1757     , _profiled_bci(0) {
  1758     BlockList* s = new BlockList(1);
  1759     s->append(sux);
  1760     set_sux(s);
  1763   Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint)
  1764                                            , _direction(none)
  1765                                            , _profiled_method(NULL)
  1766                                            , _profiled_bci(0) {
  1767     BlockList* s = new BlockList(1);
  1768     s->append(sux);
  1769     set_sux(s);
  1772   bool should_profile() const                    { return check_flag(ProfileMDOFlag); }
  1773   ciMethod* profiled_method() const              { return _profiled_method; } // set only for profiled branches
  1774   int profiled_bci() const                       { return _profiled_bci; }
  1775   Direction direction() const                    { return _direction; }
  1777   void set_should_profile(bool value)            { set_flag(ProfileMDOFlag, value); }
  1778   void set_profiled_method(ciMethod* method)     { _profiled_method = method; }
  1779   void set_profiled_bci(int bci)                 { _profiled_bci = bci; }
  1780   void set_direction(Direction d)                { _direction = d; }
  1781 };
  1784 LEAF(If, BlockEnd)
  1785  private:
  1786   Value       _x;
  1787   Condition   _cond;
  1788   Value       _y;
  1789   ciMethod*   _profiled_method;
  1790   int         _profiled_bci; // Canonicalizer may alter bci of If node
  1791   bool        _swapped;      // Is the order reversed with respect to the original If in the
  1792                              // bytecode stream?
  1793  public:
  1794   // creation
  1795   // unordered_is_true is valid for float/double compares only
  1796   If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)
  1797     : BlockEnd(illegalType, state_before, is_safepoint)
  1798   , _x(x)
  1799   , _cond(cond)
  1800   , _y(y)
  1801   , _profiled_method(NULL)
  1802   , _profiled_bci(0)
  1803   , _swapped(false)
  1805     ASSERT_VALUES
  1806     set_flag(UnorderedIsTrueFlag, unordered_is_true);
  1807     assert(x->type()->tag() == y->type()->tag(), "types must match");
  1808     BlockList* s = new BlockList(2);
  1809     s->append(tsux);
  1810     s->append(fsux);
  1811     set_sux(s);
  1814   // accessors
  1815   Value x() const                                { return _x; }
  1816   Condition cond() const                         { return _cond; }
  1817   bool unordered_is_true() const                 { return check_flag(UnorderedIsTrueFlag); }
  1818   Value y() const                                { return _y; }
  1819   BlockBegin* sux_for(bool is_true) const        { return sux_at(is_true ? 0 : 1); }
  1820   BlockBegin* tsux() const                       { return sux_for(true); }
  1821   BlockBegin* fsux() const                       { return sux_for(false); }
  1822   BlockBegin* usux() const                       { return sux_for(unordered_is_true()); }
  1823   bool should_profile() const                    { return check_flag(ProfileMDOFlag); }
  1824   ciMethod* profiled_method() const              { return _profiled_method; } // set only for profiled branches
  1825   int profiled_bci() const                       { return _profiled_bci; }    // set for profiled branches and tiered
  1826   bool is_swapped() const                        { return _swapped; }
  1828   // manipulation
  1829   void swap_operands() {
  1830     Value t = _x; _x = _y; _y = t;
  1831     _cond = mirror(_cond);
  1834   void swap_sux() {
  1835     assert(number_of_sux() == 2, "wrong number of successors");
  1836     BlockList* s = sux();
  1837     BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
  1838     _cond = negate(_cond);
  1839     set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));
  1842   void set_should_profile(bool value)             { set_flag(ProfileMDOFlag, value); }
  1843   void set_profiled_method(ciMethod* method)      { _profiled_method = method; }
  1844   void set_profiled_bci(int bci)                  { _profiled_bci = bci;       }
  1845   void set_swapped(bool value)                    { _swapped = value;         }
  1846   // generic
  1847   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
  1848 };
  1851 LEAF(IfInstanceOf, BlockEnd)
  1852  private:
  1853   ciKlass* _klass;
  1854   Value    _obj;
  1855   bool     _test_is_instance;                    // jump if instance
  1856   int      _instanceof_bci;
  1858  public:
  1859   IfInstanceOf(ciKlass* klass, Value obj, bool test_is_instance, int instanceof_bci, BlockBegin* tsux, BlockBegin* fsux)
  1860   : BlockEnd(illegalType, NULL, false) // temporary set to false
  1861   , _klass(klass)
  1862   , _obj(obj)
  1863   , _test_is_instance(test_is_instance)
  1864   , _instanceof_bci(instanceof_bci)
  1866     ASSERT_VALUES
  1867     assert(instanceof_bci >= 0, "illegal bci");
  1868     BlockList* s = new BlockList(2);
  1869     s->append(tsux);
  1870     s->append(fsux);
  1871     set_sux(s);
  1874   // accessors
  1875   //
  1876   // Note 1: If test_is_instance() is true, IfInstanceOf tests if obj *is* an
  1877   //         instance of klass; otherwise it tests if it is *not* and instance
  1878   //         of klass.
  1879   //
  1880   // Note 2: IfInstanceOf instructions are created by combining an InstanceOf
  1881   //         and an If instruction. The IfInstanceOf bci() corresponds to the
  1882   //         bci that the If would have had; the (this->) instanceof_bci() is
  1883   //         the bci of the original InstanceOf instruction.
  1884   ciKlass* klass() const                         { return _klass; }
  1885   Value obj() const                              { return _obj; }
  1886   int instanceof_bci() const                     { return _instanceof_bci; }
  1887   bool test_is_instance() const                  { return _test_is_instance; }
  1888   BlockBegin* sux_for(bool is_true) const        { return sux_at(is_true ? 0 : 1); }
  1889   BlockBegin* tsux() const                       { return sux_for(true); }
  1890   BlockBegin* fsux() const                       { return sux_for(false); }
  1892   // manipulation
  1893   void swap_sux() {
  1894     assert(number_of_sux() == 2, "wrong number of successors");
  1895     BlockList* s = sux();
  1896     BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
  1897     _test_is_instance = !_test_is_instance;
  1900   // generic
  1901   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_obj); }
  1902 };
  1905 BASE(Switch, BlockEnd)
  1906  private:
  1907   Value       _tag;
  1909  public:
  1910   // creation
  1911   Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
  1912   : BlockEnd(illegalType, state_before, is_safepoint)
  1913   , _tag(tag) {
  1914     ASSERT_VALUES
  1915     set_sux(sux);
  1918   // accessors
  1919   Value tag() const                              { return _tag; }
  1920   int length() const                             { return number_of_sux() - 1; }
  1922   virtual bool needs_exception_state() const     { return false; }
  1924   // generic
  1925   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_tag); }
  1926 };
  1929 LEAF(TableSwitch, Switch)
  1930  private:
  1931   int _lo_key;
  1933  public:
  1934   // creation
  1935   TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)
  1936     : Switch(tag, sux, state_before, is_safepoint)
  1937   , _lo_key(lo_key) {}
  1939   // accessors
  1940   int lo_key() const                             { return _lo_key; }
  1941   int hi_key() const                             { return _lo_key + length() - 1; }
  1942 };
  1945 LEAF(LookupSwitch, Switch)
  1946  private:
  1947   intArray* _keys;
  1949  public:
  1950   // creation
  1951   LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)
  1952   : Switch(tag, sux, state_before, is_safepoint)
  1953   , _keys(keys) {
  1954     assert(keys != NULL, "keys must exist");
  1955     assert(keys->length() == length(), "sux & keys have incompatible lengths");
  1958   // accessors
  1959   int key_at(int i) const                        { return _keys->at(i); }
  1960 };
  1963 LEAF(Return, BlockEnd)
  1964  private:
  1965   Value _result;
  1967  public:
  1968   // creation
  1969   Return(Value result) :
  1970     BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true),
  1971     _result(result) {}
  1973   // accessors
  1974   Value result() const                           { return _result; }
  1975   bool has_result() const                        { return result() != NULL; }
  1977   // generic
  1978   virtual void input_values_do(ValueVisitor* f) {
  1979     BlockEnd::input_values_do(f);
  1980     if (has_result()) f->visit(&_result);
  1982 };
  1985 LEAF(Throw, BlockEnd)
  1986  private:
  1987   Value _exception;
  1989  public:
  1990   // creation
  1991   Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {
  1992     ASSERT_VALUES
  1995   // accessors
  1996   Value exception() const                        { return _exception; }
  1998   // generic
  1999   virtual bool can_trap() const                  { return true; }
  2000   virtual void input_values_do(ValueVisitor* f)   { BlockEnd::input_values_do(f); f->visit(&_exception); }
  2001 };
  2004 LEAF(Base, BlockEnd)
  2005  public:
  2006   // creation
  2007   Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, NULL, false) {
  2008     assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged");
  2009     assert(osr_entry == NULL || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged");
  2010     BlockList* s = new BlockList(2);
  2011     if (osr_entry != NULL) s->append(osr_entry);
  2012     s->append(std_entry); // must be default sux!
  2013     set_sux(s);
  2016   // accessors
  2017   BlockBegin* std_entry() const                  { return default_sux(); }
  2018   BlockBegin* osr_entry() const                  { return number_of_sux() < 2 ? NULL : sux_at(0); }
  2019 };
  2022 LEAF(OsrEntry, Instruction)
  2023  public:
  2024   // creation
  2025 #ifdef _LP64
  2026   OsrEntry() : Instruction(longType) { pin(); }
  2027 #else
  2028   OsrEntry() : Instruction(intType)  { pin(); }
  2029 #endif
  2031   // generic
  2032   virtual void input_values_do(ValueVisitor* f)   { }
  2033 };
  2036 // Models the incoming exception at a catch site
  2037 LEAF(ExceptionObject, Instruction)
  2038  public:
  2039   // creation
  2040   ExceptionObject() : Instruction(objectType) {
  2041     pin();
  2044   // generic
  2045   virtual void input_values_do(ValueVisitor* f)   { }
  2046 };
  2049 // Models needed rounding for floating-point values on Intel.
  2050 // Currently only used to represent rounding of double-precision
  2051 // values stored into local variables, but could be used to model
  2052 // intermediate rounding of single-precision values as well.
  2053 LEAF(RoundFP, Instruction)
  2054  private:
  2055   Value _input;             // floating-point value to be rounded
  2057  public:
  2058   RoundFP(Value input)
  2059   : Instruction(input->type()) // Note: should not be used for constants
  2060   , _input(input)
  2062     ASSERT_VALUES
  2065   // accessors
  2066   Value input() const                            { return _input; }
  2068   // generic
  2069   virtual void input_values_do(ValueVisitor* f)   { f->visit(&_input); }
  2070 };
  2073 BASE(UnsafeOp, Instruction)
  2074  private:
  2075   BasicType _basic_type;    // ValueType can not express byte-sized integers
  2077  protected:
  2078   // creation
  2079   UnsafeOp(BasicType basic_type, bool is_put)
  2080   : Instruction(is_put ? voidType : as_ValueType(basic_type))
  2081   , _basic_type(basic_type)
  2083     //Note:  Unsafe ops are not not guaranteed to throw NPE.
  2084     // Convservatively, Unsafe operations must be pinned though we could be
  2085     // looser about this if we wanted to..
  2086     pin();
  2089  public:
  2090   // accessors
  2091   BasicType basic_type()                         { return _basic_type; }
  2093   // generic
  2094   virtual void input_values_do(ValueVisitor* f)   { }
  2095 };
  2098 BASE(UnsafeRawOp, UnsafeOp)
  2099  private:
  2100   Value _base;                                   // Base address (a Java long)
  2101   Value _index;                                  // Index if computed by optimizer; initialized to NULL
  2102   int   _log2_scale;                             // Scale factor: 0, 1, 2, or 3.
  2103                                                  // Indicates log2 of number of bytes (1, 2, 4, or 8)
  2104                                                  // to scale index by.
  2106  protected:
  2107   UnsafeRawOp(BasicType basic_type, Value addr, bool is_put)
  2108   : UnsafeOp(basic_type, is_put)
  2109   , _base(addr)
  2110   , _index(NULL)
  2111   , _log2_scale(0)
  2113     // Can not use ASSERT_VALUES because index may be NULL
  2114     assert(addr != NULL && addr->type()->is_long(), "just checking");
  2117   UnsafeRawOp(BasicType basic_type, Value base, Value index, int log2_scale, bool is_put)
  2118   : UnsafeOp(basic_type, is_put)
  2119   , _base(base)
  2120   , _index(index)
  2121   , _log2_scale(log2_scale)
  2125  public:
  2126   // accessors
  2127   Value base()                                   { return _base; }
  2128   Value index()                                  { return _index; }
  2129   bool  has_index()                              { return (_index != NULL); }
  2130   int   log2_scale()                             { return _log2_scale; }
  2132   // setters
  2133   void set_base (Value base)                     { _base  = base; }
  2134   void set_index(Value index)                    { _index = index; }
  2135   void set_log2_scale(int log2_scale)            { _log2_scale = log2_scale; }
  2137   // generic
  2138   virtual void input_values_do(ValueVisitor* f)   { UnsafeOp::input_values_do(f);
  2139                                                    f->visit(&_base);
  2140                                                    if (has_index()) f->visit(&_index); }
  2141 };
  2144 LEAF(UnsafeGetRaw, UnsafeRawOp)
  2145  private:
  2146  bool _may_be_unaligned, _is_wide;  // For OSREntry
  2148  public:
  2149  UnsafeGetRaw(BasicType basic_type, Value addr, bool may_be_unaligned, bool is_wide = false)
  2150   : UnsafeRawOp(basic_type, addr, false) {
  2151     _may_be_unaligned = may_be_unaligned;
  2152     _is_wide = is_wide;
  2155  UnsafeGetRaw(BasicType basic_type, Value base, Value index, int log2_scale, bool may_be_unaligned, bool is_wide = false)
  2156   : UnsafeRawOp(basic_type, base, index, log2_scale, false) {
  2157     _may_be_unaligned = may_be_unaligned;
  2158     _is_wide = is_wide;
  2161   bool may_be_unaligned()                         { return _may_be_unaligned; }
  2162   bool is_wide()                                  { return _is_wide; }
  2163 };
  2166 LEAF(UnsafePutRaw, UnsafeRawOp)
  2167  private:
  2168   Value _value;                                  // Value to be stored
  2170  public:
  2171   UnsafePutRaw(BasicType basic_type, Value addr, Value value)
  2172   : UnsafeRawOp(basic_type, addr, true)
  2173   , _value(value)
  2175     assert(value != NULL, "just checking");
  2176     ASSERT_VALUES
  2179   UnsafePutRaw(BasicType basic_type, Value base, Value index, int log2_scale, Value value)
  2180   : UnsafeRawOp(basic_type, base, index, log2_scale, true)
  2181   , _value(value)
  2183     assert(value != NULL, "just checking");
  2184     ASSERT_VALUES
  2187   // accessors
  2188   Value value()                                  { return _value; }
  2190   // generic
  2191   virtual void input_values_do(ValueVisitor* f)   { UnsafeRawOp::input_values_do(f);
  2192                                                    f->visit(&_value); }
  2193 };
  2196 BASE(UnsafeObjectOp, UnsafeOp)
  2197  private:
  2198   Value _object;                                 // Object to be fetched from or mutated
  2199   Value _offset;                                 // Offset within object
  2200   bool  _is_volatile;                            // true if volatile - dl/JSR166
  2201  public:
  2202   UnsafeObjectOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile)
  2203     : UnsafeOp(basic_type, is_put), _object(object), _offset(offset), _is_volatile(is_volatile)
  2207   // accessors
  2208   Value object()                                 { return _object; }
  2209   Value offset()                                 { return _offset; }
  2210   bool  is_volatile()                            { return _is_volatile; }
  2211   // generic
  2212   virtual void input_values_do(ValueVisitor* f)   { UnsafeOp::input_values_do(f);
  2213                                                    f->visit(&_object);
  2214                                                    f->visit(&_offset); }
  2215 };
  2218 LEAF(UnsafeGetObject, UnsafeObjectOp)
  2219  public:
  2220   UnsafeGetObject(BasicType basic_type, Value object, Value offset, bool is_volatile)
  2221   : UnsafeObjectOp(basic_type, object, offset, false, is_volatile)
  2223     ASSERT_VALUES
  2225 };
  2228 LEAF(UnsafePutObject, UnsafeObjectOp)
  2229  private:
  2230   Value _value;                                  // Value to be stored
  2231  public:
  2232   UnsafePutObject(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile)
  2233   : UnsafeObjectOp(basic_type, object, offset, true, is_volatile)
  2234     , _value(value)
  2236     ASSERT_VALUES
  2239   // accessors
  2240   Value value()                                  { return _value; }
  2242   // generic
  2243   virtual void input_values_do(ValueVisitor* f)   { UnsafeObjectOp::input_values_do(f);
  2244                                                    f->visit(&_value); }
  2245 };
  2248 BASE(UnsafePrefetch, UnsafeObjectOp)
  2249  public:
  2250   UnsafePrefetch(Value object, Value offset)
  2251   : UnsafeObjectOp(T_VOID, object, offset, false, false)
  2254 };
  2257 LEAF(UnsafePrefetchRead, UnsafePrefetch)
  2258  public:
  2259   UnsafePrefetchRead(Value object, Value offset)
  2260   : UnsafePrefetch(object, offset)
  2262     ASSERT_VALUES
  2264 };
  2267 LEAF(UnsafePrefetchWrite, UnsafePrefetch)
  2268  public:
  2269   UnsafePrefetchWrite(Value object, Value offset)
  2270   : UnsafePrefetch(object, offset)
  2272     ASSERT_VALUES
  2274 };
  2276 LEAF(ProfileCall, Instruction)
  2277  private:
  2278   ciMethod* _method;
  2279   int       _bci_of_invoke;
  2280   Value     _recv;
  2281   ciKlass*  _known_holder;
  2283  public:
  2284   ProfileCall(ciMethod* method, int bci, Value recv, ciKlass* known_holder)
  2285     : Instruction(voidType)
  2286     , _method(method)
  2287     , _bci_of_invoke(bci)
  2288     , _recv(recv)
  2289     , _known_holder(known_holder)
  2291     // The ProfileCall has side-effects and must occur precisely where located
  2292     pin();
  2295   ciMethod* method()      { return _method; }
  2296   int bci_of_invoke()     { return _bci_of_invoke; }
  2297   Value recv()            { return _recv; }
  2298   ciKlass* known_holder() { return _known_holder; }
  2300   virtual void input_values_do(ValueVisitor* f)   { if (_recv != NULL) f->visit(&_recv); }
  2301 };
  2304 // Call some C runtime function that doesn't safepoint,
  2305 // optionally passing the current thread as the first argument.
  2306 LEAF(RuntimeCall, Instruction)
  2307  private:
  2308   const char* _entry_name;
  2309   address     _entry;
  2310   Values*     _args;
  2311   bool        _pass_thread;  // Pass the JavaThread* as an implicit first argument
  2313  public:
  2314   RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
  2315     : Instruction(type)
  2316     , _entry(entry)
  2317     , _args(args)
  2318     , _entry_name(entry_name)
  2319     , _pass_thread(pass_thread) {
  2320     ASSERT_VALUES
  2321     pin();
  2324   const char* entry_name() const  { return _entry_name; }
  2325   address entry() const           { return _entry; }
  2326   int number_of_arguments() const { return _args->length(); }
  2327   Value argument_at(int i) const  { return _args->at(i); }
  2328   bool pass_thread() const        { return _pass_thread; }
  2330   virtual void input_values_do(ValueVisitor* f)   {
  2331     for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
  2333 };
  2335 // Use to trip invocation counter of an inlined method
  2337 LEAF(ProfileInvoke, Instruction)
  2338  private:
  2339   ciMethod*   _inlinee;
  2340   ValueStack* _state;
  2342  public:
  2343   ProfileInvoke(ciMethod* inlinee,  ValueStack* state)
  2344     : Instruction(voidType)
  2345     , _inlinee(inlinee)
  2346     , _state(state)
  2348     // The ProfileInvoke has side-effects and must occur precisely where located QQQ???
  2349     pin();
  2352   ciMethod* inlinee()      { return _inlinee; }
  2353   ValueStack* state()      { return _state; }
  2354   virtual void input_values_do(ValueVisitor*)   {}
  2355   virtual void state_values_do(ValueVisitor*);
  2356 };
  2358 LEAF(MemBar, Instruction)
  2359  private:
  2360   LIR_Code _code;
  2362  public:
  2363   MemBar(LIR_Code code)
  2364     : Instruction(voidType)
  2365     , _code(code)
  2367     pin();
  2370   LIR_Code code()           { return _code; }
  2372   virtual void input_values_do(ValueVisitor*)   {}
  2373 };
  2375 class BlockPair: public CompilationResourceObj {
  2376  private:
  2377   BlockBegin* _from;
  2378   BlockBegin* _to;
  2379  public:
  2380   BlockPair(BlockBegin* from, BlockBegin* to): _from(from), _to(to) {}
  2381   BlockBegin* from() const { return _from; }
  2382   BlockBegin* to() const   { return _to;   }
  2383   bool is_same(BlockBegin* from, BlockBegin* to) const { return  _from == from && _to == to; }
  2384   bool is_same(BlockPair* p) const { return  _from == p->from() && _to == p->to(); }
  2385   void set_to(BlockBegin* b)   { _to = b; }
  2386   void set_from(BlockBegin* b) { _from = b; }
  2387 };
  2390 define_array(BlockPairArray, BlockPair*)
  2391 define_stack(BlockPairList, BlockPairArray)
  2394 inline int         BlockBegin::number_of_sux() const            { assert(_end == NULL || _end->number_of_sux() == _successors.length(), "mismatch"); return _successors.length(); }
  2395 inline BlockBegin* BlockBegin::sux_at(int i) const              { assert(_end == NULL || _end->sux_at(i) == _successors.at(i), "mismatch");          return _successors.at(i); }
  2396 inline void        BlockBegin::add_successor(BlockBegin* sux)   { assert(_end == NULL, "Would create mismatch with successors of BlockEnd");         _successors.append(sux); }
  2398 #undef ASSERT_VALUES
  2400 #endif // SHARE_VM_C1_C1_INSTRUCTION_HPP

mercurial