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