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