Tue, 09 Mar 2010 20:16:19 +0100
6919934: JSR 292 needs to support x86 C1
Summary: This implements JSR 292 support for C1 x86.
Reviewed-by: never, jrose, kvn
1 /*
2 * Copyright 1999-2010 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 // Predefined classes
26 class ciField;
27 class ValueStack;
28 class InstructionPrinter;
29 class IRScope;
30 class LIR_OprDesc;
31 typedef LIR_OprDesc* LIR_Opr;
34 // Instruction class hierarchy
35 //
36 // All leaf classes in the class hierarchy are concrete classes
37 // (i.e., are instantiated). All other classes are abstract and
38 // serve factoring.
40 class Instruction;
41 class HiWord;
42 class Phi;
43 class Local;
44 class Constant;
45 class AccessField;
46 class LoadField;
47 class StoreField;
48 class AccessArray;
49 class ArrayLength;
50 class AccessIndexed;
51 class LoadIndexed;
52 class StoreIndexed;
53 class NegateOp;
54 class Op2;
55 class ArithmeticOp;
56 class ShiftOp;
57 class LogicOp;
58 class CompareOp;
59 class IfOp;
60 class Convert;
61 class NullCheck;
62 class OsrEntry;
63 class ExceptionObject;
64 class StateSplit;
65 class Invoke;
66 class NewInstance;
67 class NewArray;
68 class NewTypeArray;
69 class NewObjectArray;
70 class NewMultiArray;
71 class TypeCheck;
72 class CheckCast;
73 class InstanceOf;
74 class AccessMonitor;
75 class MonitorEnter;
76 class MonitorExit;
77 class Intrinsic;
78 class BlockBegin;
79 class BlockEnd;
80 class Goto;
81 class If;
82 class IfInstanceOf;
83 class Switch;
84 class TableSwitch;
85 class LookupSwitch;
86 class Return;
87 class Throw;
88 class Base;
89 class RoundFP;
90 class UnsafeOp;
91 class UnsafeRawOp;
92 class UnsafeGetRaw;
93 class UnsafePutRaw;
94 class UnsafeObjectOp;
95 class UnsafeGetObject;
96 class UnsafePutObject;
97 class UnsafePrefetch;
98 class UnsafePrefetchRead;
99 class UnsafePrefetchWrite;
100 class ProfileCall;
101 class ProfileCounter;
103 // A Value is a reference to the instruction creating the value
104 typedef Instruction* Value;
105 define_array(ValueArray, Value)
106 define_stack(Values, ValueArray)
108 define_array(ValueStackArray, ValueStack*)
109 define_stack(ValueStackStack, ValueStackArray)
111 // BlockClosure is the base class for block traversal/iteration.
113 class BlockClosure: public CompilationResourceObj {
114 public:
115 virtual void block_do(BlockBegin* block) = 0;
116 };
119 // Some array and list classes
120 define_array(BlockBeginArray, BlockBegin*)
121 define_stack(_BlockList, BlockBeginArray)
123 class BlockList: public _BlockList {
124 public:
125 BlockList(): _BlockList() {}
126 BlockList(const int size): _BlockList(size) {}
127 BlockList(const int size, BlockBegin* init): _BlockList(size, init) {}
129 void iterate_forward(BlockClosure* closure);
130 void iterate_backward(BlockClosure* closure);
131 void blocks_do(void f(BlockBegin*));
132 void values_do(void f(Value*));
133 void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN;
134 };
137 // InstructionVisitors provide type-based dispatch for instructions.
138 // For each concrete Instruction class X, a virtual function do_X is
139 // provided. Functionality that needs to be implemented for all classes
140 // (e.g., printing, code generation) is factored out into a specialised
141 // visitor instead of added to the Instruction classes itself.
143 class InstructionVisitor: public StackObj {
144 public:
145 void do_HiWord (HiWord* x) { ShouldNotReachHere(); }
146 virtual void do_Phi (Phi* x) = 0;
147 virtual void do_Local (Local* x) = 0;
148 virtual void do_Constant (Constant* x) = 0;
149 virtual void do_LoadField (LoadField* x) = 0;
150 virtual void do_StoreField (StoreField* x) = 0;
151 virtual void do_ArrayLength (ArrayLength* x) = 0;
152 virtual void do_LoadIndexed (LoadIndexed* x) = 0;
153 virtual void do_StoreIndexed (StoreIndexed* x) = 0;
154 virtual void do_NegateOp (NegateOp* x) = 0;
155 virtual void do_ArithmeticOp (ArithmeticOp* x) = 0;
156 virtual void do_ShiftOp (ShiftOp* x) = 0;
157 virtual void do_LogicOp (LogicOp* x) = 0;
158 virtual void do_CompareOp (CompareOp* x) = 0;
159 virtual void do_IfOp (IfOp* x) = 0;
160 virtual void do_Convert (Convert* x) = 0;
161 virtual void do_NullCheck (NullCheck* x) = 0;
162 virtual void do_Invoke (Invoke* x) = 0;
163 virtual void do_NewInstance (NewInstance* x) = 0;
164 virtual void do_NewTypeArray (NewTypeArray* x) = 0;
165 virtual void do_NewObjectArray (NewObjectArray* x) = 0;
166 virtual void do_NewMultiArray (NewMultiArray* x) = 0;
167 virtual void do_CheckCast (CheckCast* x) = 0;
168 virtual void do_InstanceOf (InstanceOf* x) = 0;
169 virtual void do_MonitorEnter (MonitorEnter* x) = 0;
170 virtual void do_MonitorExit (MonitorExit* x) = 0;
171 virtual void do_Intrinsic (Intrinsic* x) = 0;
172 virtual void do_BlockBegin (BlockBegin* x) = 0;
173 virtual void do_Goto (Goto* x) = 0;
174 virtual void do_If (If* x) = 0;
175 virtual void do_IfInstanceOf (IfInstanceOf* x) = 0;
176 virtual void do_TableSwitch (TableSwitch* x) = 0;
177 virtual void do_LookupSwitch (LookupSwitch* x) = 0;
178 virtual void do_Return (Return* x) = 0;
179 virtual void do_Throw (Throw* x) = 0;
180 virtual void do_Base (Base* x) = 0;
181 virtual void do_OsrEntry (OsrEntry* x) = 0;
182 virtual void do_ExceptionObject(ExceptionObject* x) = 0;
183 virtual void do_RoundFP (RoundFP* x) = 0;
184 virtual void do_UnsafeGetRaw (UnsafeGetRaw* x) = 0;
185 virtual void do_UnsafePutRaw (UnsafePutRaw* x) = 0;
186 virtual void do_UnsafeGetObject(UnsafeGetObject* x) = 0;
187 virtual void do_UnsafePutObject(UnsafePutObject* x) = 0;
188 virtual void do_UnsafePrefetchRead (UnsafePrefetchRead* x) = 0;
189 virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) = 0;
190 virtual void do_ProfileCall (ProfileCall* x) = 0;
191 virtual void do_ProfileCounter (ProfileCounter* x) = 0;
192 };
195 // Hashing support
196 //
197 // Note: This hash functions affect the performance
198 // of ValueMap - make changes carefully!
200 #define HASH1(x1 ) ((intx)(x1))
201 #define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2))
202 #define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3))
203 #define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))
206 // The following macros are used to implement instruction-specific hashing.
207 // By default, each instruction implements hash() and is_equal(Value), used
208 // for value numbering/common subexpression elimination. The default imple-
209 // mentation disables value numbering. Each instruction which can be value-
210 // numbered, should define corresponding hash() and is_equal(Value) functions
211 // via the macros below. The f arguments specify all the values/op codes, etc.
212 // that need to be identical for two instructions to be identical.
213 //
214 // Note: The default implementation of hash() returns 0 in order to indicate
215 // that the instruction should not be considered for value numbering.
216 // The currently used hash functions do not guarantee that never a 0
217 // is produced. While this is still correct, it may be a performance
218 // bug (no value numbering for that node). However, this situation is
219 // so unlikely, that we are not going to handle it specially.
221 #define HASHING1(class_name, enabled, f1) \
222 virtual intx hash() const { \
223 return (enabled) ? HASH2(name(), f1) : 0; \
224 } \
225 virtual bool is_equal(Value v) const { \
226 if (!(enabled) ) return false; \
227 class_name* _v = v->as_##class_name(); \
228 if (_v == NULL ) return false; \
229 if (f1 != _v->f1) return false; \
230 return true; \
231 } \
234 #define HASHING2(class_name, enabled, f1, f2) \
235 virtual intx hash() const { \
236 return (enabled) ? HASH3(name(), f1, f2) : 0; \
237 } \
238 virtual bool is_equal(Value v) const { \
239 if (!(enabled) ) return false; \
240 class_name* _v = v->as_##class_name(); \
241 if (_v == NULL ) return false; \
242 if (f1 != _v->f1) return false; \
243 if (f2 != _v->f2) return false; \
244 return true; \
245 } \
248 #define HASHING3(class_name, enabled, f1, f2, f3) \
249 virtual intx hash() const { \
250 return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
251 } \
252 virtual bool is_equal(Value v) const { \
253 if (!(enabled) ) return false; \
254 class_name* _v = v->as_##class_name(); \
255 if (_v == NULL ) return false; \
256 if (f1 != _v->f1) return false; \
257 if (f2 != _v->f2) return false; \
258 if (f3 != _v->f3) return false; \
259 return true; \
260 } \
263 // The mother of all instructions...
265 class Instruction: public CompilationResourceObj {
266 private:
267 static int _next_id; // the node counter
269 int _id; // the unique instruction id
270 int _bci; // the instruction bci
271 int _use_count; // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1
272 int _pin_state; // set of PinReason describing the reason for pinning
273 ValueType* _type; // the instruction value type
274 Instruction* _next; // the next instruction if any (NULL for BlockEnd instructions)
275 Instruction* _subst; // the substitution instruction if any
276 LIR_Opr _operand; // LIR specific information
277 unsigned int _flags; // Flag bits
279 XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction
281 #ifdef ASSERT
282 HiWord* _hi_word;
283 #endif
285 friend class UseCountComputer;
287 protected:
288 void set_bci(int bci) { assert(bci == SynchronizationEntryBCI || bci >= 0, "illegal bci"); _bci = bci; }
289 void set_type(ValueType* type) {
290 assert(type != NULL, "type must exist");
291 _type = type;
292 }
294 public:
295 enum InstructionFlag {
296 NeedsNullCheckFlag = 0,
297 CanTrapFlag,
298 DirectCompareFlag,
299 IsEliminatedFlag,
300 IsInitializedFlag,
301 IsLoadedFlag,
302 IsSafepointFlag,
303 IsStaticFlag,
304 IsStrictfpFlag,
305 NeedsStoreCheckFlag,
306 NeedsWriteBarrierFlag,
307 PreservesStateFlag,
308 TargetIsFinalFlag,
309 TargetIsLoadedFlag,
310 TargetIsStrictfpFlag,
311 UnorderedIsTrueFlag,
312 NeedsPatchingFlag,
313 ThrowIncompatibleClassChangeErrorFlag,
314 ProfileMDOFlag,
315 InstructionLastFlag
316 };
318 public:
319 bool check_flag(InstructionFlag id) const { return (_flags & (1 << id)) != 0; }
320 void set_flag(InstructionFlag id, bool f) { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); };
322 // 'globally' used condition values
323 enum Condition {
324 eql, neq, lss, leq, gtr, geq
325 };
327 // Instructions may be pinned for many reasons and under certain conditions
328 // with enough knowledge it's possible to safely unpin them.
329 enum PinReason {
330 PinUnknown = 1 << 0
331 , PinExplicitNullCheck = 1 << 3
332 , PinStackForStateSplit= 1 << 12
333 , PinStateSplitConstructor= 1 << 13
334 , PinGlobalValueNumbering= 1 << 14
335 };
337 static Condition mirror(Condition cond);
338 static Condition negate(Condition cond);
340 // initialization
341 static void initialize() { _next_id = 0; }
342 static int number_of_instructions() { return _next_id; }
344 // creation
345 Instruction(ValueType* type, bool type_is_constant = false, bool create_hi = true)
346 : _id(_next_id++)
347 , _bci(-99)
348 , _use_count(0)
349 , _pin_state(0)
350 , _type(type)
351 , _next(NULL)
352 , _subst(NULL)
353 , _flags(0)
354 , _operand(LIR_OprFact::illegalOpr)
355 , _exception_handlers(NULL)
356 #ifdef ASSERT
357 , _hi_word(NULL)
358 #endif
359 {
360 assert(type != NULL && (!type->is_constant() || type_is_constant), "type must exist");
361 #ifdef ASSERT
362 if (create_hi && type->is_double_word()) {
363 create_hi_word();
364 }
365 #endif
366 }
368 // accessors
369 int id() const { return _id; }
370 int bci() const { return _bci; }
371 int use_count() const { return _use_count; }
372 int pin_state() const { return _pin_state; }
373 bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; }
374 ValueType* type() const { return _type; }
375 Instruction* prev(BlockBegin* block); // use carefully, expensive operation
376 Instruction* next() const { return _next; }
377 bool has_subst() const { return _subst != NULL; }
378 Instruction* subst() { return _subst == NULL ? this : _subst->subst(); }
379 LIR_Opr operand() const { return _operand; }
381 void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); }
382 bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); }
384 bool has_uses() const { return use_count() > 0; }
385 bool is_root() const { return is_pinned() || use_count() > 1; }
386 XHandlers* exception_handlers() const { return _exception_handlers; }
388 // manipulation
389 void pin(PinReason reason) { _pin_state |= reason; }
390 void pin() { _pin_state |= PinUnknown; }
391 // DANGEROUS: only used by EliminateStores
392 void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
393 virtual void set_lock_stack(ValueStack* l) { /* do nothing*/ }
394 virtual ValueStack* lock_stack() const { return NULL; }
396 Instruction* set_next(Instruction* next, int bci) {
397 if (next != NULL) {
398 assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");
399 assert(next->as_Phi() == NULL && next->as_Local() == NULL, "shouldn't link these instructions into list");
400 next->set_bci(bci);
401 }
402 _next = next;
403 return next;
404 }
406 void set_subst(Instruction* subst) {
407 assert(subst == NULL ||
408 type()->base() == subst->type()->base() ||
409 subst->type()->base() == illegalType, "type can't change");
410 _subst = subst;
411 }
412 void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
414 #ifdef ASSERT
415 // HiWord is used for debugging and is allocated early to avoid
416 // allocation at inconvenient points
417 HiWord* hi_word() { return _hi_word; }
418 void create_hi_word();
419 #endif
422 // machine-specifics
423 void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
424 void clear_operand() { _operand = LIR_OprFact::illegalOpr; }
426 // generic
427 virtual Instruction* as_Instruction() { return this; } // to satisfy HASHING1 macro
428 virtual HiWord* as_HiWord() { return NULL; }
429 virtual Phi* as_Phi() { return NULL; }
430 virtual Local* as_Local() { return NULL; }
431 virtual Constant* as_Constant() { return NULL; }
432 virtual AccessField* as_AccessField() { return NULL; }
433 virtual LoadField* as_LoadField() { return NULL; }
434 virtual StoreField* as_StoreField() { return NULL; }
435 virtual AccessArray* as_AccessArray() { return NULL; }
436 virtual ArrayLength* as_ArrayLength() { return NULL; }
437 virtual AccessIndexed* as_AccessIndexed() { return NULL; }
438 virtual LoadIndexed* as_LoadIndexed() { return NULL; }
439 virtual StoreIndexed* as_StoreIndexed() { return NULL; }
440 virtual NegateOp* as_NegateOp() { return NULL; }
441 virtual Op2* as_Op2() { return NULL; }
442 virtual ArithmeticOp* as_ArithmeticOp() { return NULL; }
443 virtual ShiftOp* as_ShiftOp() { return NULL; }
444 virtual LogicOp* as_LogicOp() { return NULL; }
445 virtual CompareOp* as_CompareOp() { return NULL; }
446 virtual IfOp* as_IfOp() { return NULL; }
447 virtual Convert* as_Convert() { return NULL; }
448 virtual NullCheck* as_NullCheck() { return NULL; }
449 virtual OsrEntry* as_OsrEntry() { return NULL; }
450 virtual StateSplit* as_StateSplit() { return NULL; }
451 virtual Invoke* as_Invoke() { return NULL; }
452 virtual NewInstance* as_NewInstance() { return NULL; }
453 virtual NewArray* as_NewArray() { return NULL; }
454 virtual NewTypeArray* as_NewTypeArray() { return NULL; }
455 virtual NewObjectArray* as_NewObjectArray() { return NULL; }
456 virtual NewMultiArray* as_NewMultiArray() { return NULL; }
457 virtual TypeCheck* as_TypeCheck() { return NULL; }
458 virtual CheckCast* as_CheckCast() { return NULL; }
459 virtual InstanceOf* as_InstanceOf() { return NULL; }
460 virtual AccessMonitor* as_AccessMonitor() { return NULL; }
461 virtual MonitorEnter* as_MonitorEnter() { return NULL; }
462 virtual MonitorExit* as_MonitorExit() { return NULL; }
463 virtual Intrinsic* as_Intrinsic() { return NULL; }
464 virtual BlockBegin* as_BlockBegin() { return NULL; }
465 virtual BlockEnd* as_BlockEnd() { return NULL; }
466 virtual Goto* as_Goto() { return NULL; }
467 virtual If* as_If() { return NULL; }
468 virtual IfInstanceOf* as_IfInstanceOf() { return NULL; }
469 virtual TableSwitch* as_TableSwitch() { return NULL; }
470 virtual LookupSwitch* as_LookupSwitch() { return NULL; }
471 virtual Return* as_Return() { return NULL; }
472 virtual Throw* as_Throw() { return NULL; }
473 virtual Base* as_Base() { return NULL; }
474 virtual RoundFP* as_RoundFP() { return NULL; }
475 virtual ExceptionObject* as_ExceptionObject() { return NULL; }
476 virtual UnsafeOp* as_UnsafeOp() { return NULL; }
478 virtual void visit(InstructionVisitor* v) = 0;
480 virtual bool can_trap() const { return false; }
482 virtual void input_values_do(void f(Value*)) = 0;
483 virtual void state_values_do(void f(Value*)) { /* usually no state - override on demand */ }
484 virtual void other_values_do(void f(Value*)) { /* usually no other - override on demand */ }
485 void values_do(void f(Value*)) { input_values_do(f); state_values_do(f); other_values_do(f); }
487 virtual ciType* exact_type() const { return NULL; }
488 virtual ciType* declared_type() const { return NULL; }
490 // hashing
491 virtual const char* name() const = 0;
492 HASHING1(Instruction, false, id()) // hashing disabled by default
494 // debugging
495 void print() PRODUCT_RETURN;
496 void print_line() PRODUCT_RETURN;
497 void print(InstructionPrinter& ip) PRODUCT_RETURN;
498 };
501 // The following macros are used to define base (i.e., non-leaf)
502 // and leaf instruction classes. They define class-name related
503 // generic functionality in one place.
505 #define BASE(class_name, super_class_name) \
506 class class_name: public super_class_name { \
507 public: \
508 virtual class_name* as_##class_name() { return this; } \
511 #define LEAF(class_name, super_class_name) \
512 BASE(class_name, super_class_name) \
513 public: \
514 virtual const char* name() const { return #class_name; } \
515 virtual void visit(InstructionVisitor* v) { v->do_##class_name(this); } \
518 // Debugging support
520 #ifdef ASSERT
521 static void assert_value(Value* x) { assert((*x) != NULL, "value must exist"); }
522 #define ASSERT_VALUES values_do(assert_value);
523 #else
524 #define ASSERT_VALUES
525 #endif // ASSERT
528 // A HiWord occupies the 'high word' of a 2-word
529 // expression stack entry. Hi & lo words must be
530 // paired on the expression stack (otherwise the
531 // bytecode sequence is illegal). Note that 'hi'
532 // refers to the IR expression stack format and
533 // does *not* imply a machine word ordering. No
534 // HiWords are used in optimized mode for speed,
535 // but NULL pointers are used instead.
537 LEAF(HiWord, Instruction)
538 private:
539 Value _lo_word;
541 public:
542 // creation
543 HiWord(Value lo_word)
544 : Instruction(illegalType, false, false),
545 _lo_word(lo_word) {
546 // hi-words are also allowed for illegal lo-words
547 assert(lo_word->type()->is_double_word() || lo_word->type()->is_illegal(),
548 "HiWord must be used for 2-word values only");
549 }
551 // accessors
552 Value lo_word() const { return _lo_word->subst(); }
554 // for invalidating of HiWords
555 void make_illegal() { set_type(illegalType); }
557 // generic
558 virtual void input_values_do(void f(Value*)) { ShouldNotReachHere(); }
559 };
562 // A Phi is a phi function in the sense of SSA form. It stands for
563 // the value of a local variable at the beginning of a join block.
564 // A Phi consists of n operands, one for every incoming branch.
566 LEAF(Phi, Instruction)
567 private:
568 BlockBegin* _block; // the block to which the phi function belongs
569 int _pf_flags; // the flags of the phi function
570 int _index; // to value on operand stack (index < 0) or to local
571 public:
572 // creation
573 Phi(ValueType* type, BlockBegin* b, int index)
574 : Instruction(type->base())
575 , _pf_flags(0)
576 , _block(b)
577 , _index(index)
578 {
579 if (type->is_illegal()) {
580 make_illegal();
581 }
582 }
584 // flags
585 enum Flag {
586 no_flag = 0,
587 visited = 1 << 0,
588 cannot_simplify = 1 << 1
589 };
591 // accessors
592 bool is_local() const { return _index >= 0; }
593 bool is_on_stack() const { return !is_local(); }
594 int local_index() const { assert(is_local(), ""); return _index; }
595 int stack_index() const { assert(is_on_stack(), ""); return -(_index+1); }
597 Value operand_at(int i) const;
598 int operand_count() const;
600 BlockBegin* block() const { return _block; }
602 void set(Flag f) { _pf_flags |= f; }
603 void clear(Flag f) { _pf_flags &= ~f; }
604 bool is_set(Flag f) const { return (_pf_flags & f) != 0; }
606 // Invalidates phis corresponding to merges of locals of two different types
607 // (these should never be referenced, otherwise the bytecodes are illegal)
608 void make_illegal() {
609 set(cannot_simplify);
610 set_type(illegalType);
611 }
613 bool is_illegal() const {
614 return type()->is_illegal();
615 }
617 // generic
618 virtual void input_values_do(void f(Value*)) {
619 }
620 };
623 // A local is a placeholder for an incoming argument to a function call.
624 LEAF(Local, Instruction)
625 private:
626 int _java_index; // the local index within the method to which the local belongs
627 public:
628 // creation
629 Local(ValueType* type, int index)
630 : Instruction(type)
631 , _java_index(index)
632 {}
634 // accessors
635 int java_index() const { return _java_index; }
637 // generic
638 virtual void input_values_do(void f(Value*)) { /* no values */ }
639 };
642 LEAF(Constant, Instruction)
643 ValueStack* _state;
645 public:
646 // creation
647 Constant(ValueType* type):
648 Instruction(type, true)
649 , _state(NULL) {
650 assert(type->is_constant(), "must be a constant");
651 }
653 Constant(ValueType* type, ValueStack* state):
654 Instruction(type, true)
655 , _state(state) {
656 assert(state != NULL, "only used for constants which need patching");
657 assert(type->is_constant(), "must be a constant");
658 // since it's patching it needs to be pinned
659 pin();
660 }
662 ValueStack* state() const { return _state; }
664 // generic
665 virtual bool can_trap() const { return state() != NULL; }
666 virtual void input_values_do(void f(Value*)) { /* no values */ }
667 virtual void other_values_do(void f(Value*));
669 virtual intx hash() const;
670 virtual bool is_equal(Value v) const;
672 virtual BlockBegin* compare(Instruction::Condition condition, Value right,
673 BlockBegin* true_sux, BlockBegin* false_sux);
674 };
677 BASE(AccessField, Instruction)
678 private:
679 Value _obj;
680 int _offset;
681 ciField* _field;
682 ValueStack* _state_before; // state is set only for unloaded or uninitialized fields
683 ValueStack* _lock_stack; // contains lock and scope information
684 NullCheck* _explicit_null_check; // For explicit null check elimination
686 public:
687 // creation
688 AccessField(Value obj, int offset, ciField* field, bool is_static, ValueStack* lock_stack,
689 ValueStack* state_before, bool is_loaded, bool is_initialized)
690 : Instruction(as_ValueType(field->type()->basic_type()))
691 , _obj(obj)
692 , _offset(offset)
693 , _field(field)
694 , _lock_stack(lock_stack)
695 , _state_before(state_before)
696 , _explicit_null_check(NULL)
697 {
698 set_needs_null_check(!is_static);
699 set_flag(IsLoadedFlag, is_loaded);
700 set_flag(IsInitializedFlag, is_initialized);
701 set_flag(IsStaticFlag, is_static);
702 ASSERT_VALUES
703 if (!is_loaded || (PatchALot && !field->is_volatile())) {
704 // need to patch if the holder wasn't loaded or we're testing
705 // using PatchALot. Don't allow PatchALot for fields which are
706 // known to be volatile they aren't patchable.
707 set_flag(NeedsPatchingFlag, true);
708 }
709 // pin of all instructions with memory access
710 pin();
711 }
713 // accessors
714 Value obj() const { return _obj; }
715 int offset() const { return _offset; }
716 ciField* field() const { return _field; }
717 BasicType field_type() const { return _field->type()->basic_type(); }
718 bool is_static() const { return check_flag(IsStaticFlag); }
719 bool is_loaded() const { return check_flag(IsLoadedFlag); }
720 bool is_initialized() const { return check_flag(IsInitializedFlag); }
721 ValueStack* state_before() const { return _state_before; }
722 ValueStack* lock_stack() const { return _lock_stack; }
723 NullCheck* explicit_null_check() const { return _explicit_null_check; }
724 bool needs_patching() const { return check_flag(NeedsPatchingFlag); }
726 // manipulation
727 void set_lock_stack(ValueStack* l) { _lock_stack = l; }
728 // Under certain circumstances, if a previous NullCheck instruction
729 // proved the target object non-null, we can eliminate the explicit
730 // null check and do an implicit one, simply specifying the debug
731 // information from the NullCheck. This field should only be consulted
732 // if needs_null_check() is true.
733 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
735 // generic
736 virtual bool can_trap() const { return needs_null_check() || needs_patching(); }
737 virtual void input_values_do(void f(Value*)) { f(&_obj); }
738 virtual void other_values_do(void f(Value*));
739 };
742 LEAF(LoadField, AccessField)
743 public:
744 // creation
745 LoadField(Value obj, int offset, ciField* field, bool is_static, ValueStack* lock_stack,
746 ValueStack* state_before, bool is_loaded, bool is_initialized)
747 : AccessField(obj, offset, field, is_static, lock_stack, state_before, is_loaded, is_initialized)
748 {}
750 ciType* declared_type() const;
751 ciType* exact_type() const;
753 // generic
754 HASHING2(LoadField, is_loaded() && !field()->is_volatile(), obj()->subst(), offset()) // cannot be eliminated if not yet loaded or if volatile
755 };
758 LEAF(StoreField, AccessField)
759 private:
760 Value _value;
762 public:
763 // creation
764 StoreField(Value obj, int offset, ciField* field, Value value, bool is_static, ValueStack* lock_stack,
765 ValueStack* state_before, bool is_loaded, bool is_initialized)
766 : AccessField(obj, offset, field, is_static, lock_stack, state_before, is_loaded, is_initialized)
767 , _value(value)
768 {
769 set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
770 ASSERT_VALUES
771 pin();
772 }
774 // accessors
775 Value value() const { return _value; }
776 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
778 // generic
779 virtual void input_values_do(void f(Value*)) { AccessField::input_values_do(f); f(&_value); }
780 };
783 BASE(AccessArray, Instruction)
784 private:
785 Value _array;
786 ValueStack* _lock_stack;
788 public:
789 // creation
790 AccessArray(ValueType* type, Value array, ValueStack* lock_stack)
791 : Instruction(type)
792 , _array(array)
793 , _lock_stack(lock_stack) {
794 set_needs_null_check(true);
795 ASSERT_VALUES
796 pin(); // instruction with side effect (null exception or range check throwing)
797 }
799 Value array() const { return _array; }
800 ValueStack* lock_stack() const { return _lock_stack; }
802 // setters
803 void set_lock_stack(ValueStack* l) { _lock_stack = l; }
805 // generic
806 virtual bool can_trap() const { return needs_null_check(); }
807 virtual void input_values_do(void f(Value*)) { f(&_array); }
808 virtual void other_values_do(void f(Value*));
809 };
812 LEAF(ArrayLength, AccessArray)
813 private:
814 NullCheck* _explicit_null_check; // For explicit null check elimination
816 public:
817 // creation
818 ArrayLength(Value array, ValueStack* lock_stack)
819 : AccessArray(intType, array, lock_stack)
820 , _explicit_null_check(NULL) {}
822 // accessors
823 NullCheck* explicit_null_check() const { return _explicit_null_check; }
825 // setters
826 // See LoadField::set_explicit_null_check for documentation
827 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
829 // generic
830 HASHING1(ArrayLength, true, array()->subst())
831 };
834 BASE(AccessIndexed, AccessArray)
835 private:
836 Value _index;
837 Value _length;
838 BasicType _elt_type;
840 public:
841 // creation
842 AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* lock_stack)
843 : AccessArray(as_ValueType(elt_type), array, lock_stack)
844 , _index(index)
845 , _length(length)
846 , _elt_type(elt_type)
847 {
848 ASSERT_VALUES
849 }
851 // accessors
852 Value index() const { return _index; }
853 Value length() const { return _length; }
854 BasicType elt_type() const { return _elt_type; }
856 // perform elimination of range checks involving constants
857 bool compute_needs_range_check();
859 // generic
860 virtual void input_values_do(void f(Value*)) { AccessArray::input_values_do(f); f(&_index); if (_length != NULL) f(&_length); }
861 };
864 LEAF(LoadIndexed, AccessIndexed)
865 private:
866 NullCheck* _explicit_null_check; // For explicit null check elimination
868 public:
869 // creation
870 LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* lock_stack)
871 : AccessIndexed(array, index, length, elt_type, lock_stack)
872 , _explicit_null_check(NULL) {}
874 // accessors
875 NullCheck* explicit_null_check() const { return _explicit_null_check; }
877 // setters
878 // See LoadField::set_explicit_null_check for documentation
879 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
881 ciType* exact_type() const;
882 ciType* declared_type() const;
884 // generic
885 HASHING2(LoadIndexed, true, array()->subst(), index()->subst())
886 };
889 LEAF(StoreIndexed, AccessIndexed)
890 private:
891 Value _value;
893 public:
894 // creation
895 StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* lock_stack)
896 : AccessIndexed(array, index, length, elt_type, lock_stack)
897 , _value(value)
898 {
899 set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
900 set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
901 ASSERT_VALUES
902 pin();
903 }
905 // accessors
906 Value value() const { return _value; }
907 IRScope* scope() const; // the state's scope
908 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
909 bool needs_store_check() const { return check_flag(NeedsStoreCheckFlag); }
911 // generic
912 virtual void input_values_do(void f(Value*)) { AccessIndexed::input_values_do(f); f(&_value); }
913 };
916 LEAF(NegateOp, Instruction)
917 private:
918 Value _x;
920 public:
921 // creation
922 NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
923 ASSERT_VALUES
924 }
926 // accessors
927 Value x() const { return _x; }
929 // generic
930 virtual void input_values_do(void f(Value*)) { f(&_x); }
931 };
934 BASE(Op2, Instruction)
935 private:
936 Bytecodes::Code _op;
937 Value _x;
938 Value _y;
940 public:
941 // creation
942 Op2(ValueType* type, Bytecodes::Code op, Value x, Value y) : Instruction(type), _op(op), _x(x), _y(y) {
943 ASSERT_VALUES
944 }
946 // accessors
947 Bytecodes::Code op() const { return _op; }
948 Value x() const { return _x; }
949 Value y() const { return _y; }
951 // manipulators
952 void swap_operands() {
953 assert(is_commutative(), "operation must be commutative");
954 Value t = _x; _x = _y; _y = t;
955 }
957 // generic
958 virtual bool is_commutative() const { return false; }
959 virtual void input_values_do(void f(Value*)) { f(&_x); f(&_y); }
960 };
963 LEAF(ArithmeticOp, Op2)
964 private:
965 ValueStack* _lock_stack; // used only for division operations
966 public:
967 // creation
968 ArithmeticOp(Bytecodes::Code op, Value x, Value y, bool is_strictfp, ValueStack* lock_stack)
969 : Op2(x->type()->meet(y->type()), op, x, y)
970 , _lock_stack(lock_stack) {
971 set_flag(IsStrictfpFlag, is_strictfp);
972 if (can_trap()) pin();
973 }
975 // accessors
976 ValueStack* lock_stack() const { return _lock_stack; }
977 bool is_strictfp() const { return check_flag(IsStrictfpFlag); }
979 // setters
980 void set_lock_stack(ValueStack* l) { _lock_stack = l; }
982 // generic
983 virtual bool is_commutative() const;
984 virtual bool can_trap() const;
985 virtual void other_values_do(void f(Value*));
986 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
987 };
990 LEAF(ShiftOp, Op2)
991 public:
992 // creation
993 ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}
995 // generic
996 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
997 };
1000 LEAF(LogicOp, Op2)
1001 public:
1002 // creation
1003 LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}
1005 // generic
1006 virtual bool is_commutative() const;
1007 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1008 };
1011 LEAF(CompareOp, Op2)
1012 private:
1013 ValueStack* _state_before; // for deoptimization, when canonicalizing
1014 public:
1015 // creation
1016 CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1017 : Op2(intType, op, x, y)
1018 , _state_before(state_before)
1019 {}
1021 // accessors
1022 ValueStack* state_before() const { return _state_before; }
1024 // generic
1025 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1026 virtual void other_values_do(void f(Value*));
1027 };
1030 LEAF(IfOp, Op2)
1031 private:
1032 Value _tval;
1033 Value _fval;
1035 public:
1036 // creation
1037 IfOp(Value x, Condition cond, Value y, Value tval, Value fval)
1038 : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1039 , _tval(tval)
1040 , _fval(fval)
1041 {
1042 ASSERT_VALUES
1043 assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1044 }
1046 // accessors
1047 virtual bool is_commutative() const;
1048 Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }
1049 Condition cond() const { return (Condition)Op2::op(); }
1050 Value tval() const { return _tval; }
1051 Value fval() const { return _fval; }
1053 // generic
1054 virtual void input_values_do(void f(Value*)) { Op2::input_values_do(f); f(&_tval); f(&_fval); }
1055 };
1058 LEAF(Convert, Instruction)
1059 private:
1060 Bytecodes::Code _op;
1061 Value _value;
1063 public:
1064 // creation
1065 Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1066 ASSERT_VALUES
1067 }
1069 // accessors
1070 Bytecodes::Code op() const { return _op; }
1071 Value value() const { return _value; }
1073 // generic
1074 virtual void input_values_do(void f(Value*)) { f(&_value); }
1075 HASHING2(Convert, true, op(), value()->subst())
1076 };
1079 LEAF(NullCheck, Instruction)
1080 private:
1081 Value _obj;
1082 ValueStack* _lock_stack;
1084 public:
1085 // creation
1086 NullCheck(Value obj, ValueStack* lock_stack) : Instruction(obj->type()->base()), _obj(obj), _lock_stack(lock_stack) {
1087 ASSERT_VALUES
1088 set_can_trap(true);
1089 assert(_obj->type()->is_object(), "null check must be applied to objects only");
1090 pin(Instruction::PinExplicitNullCheck);
1091 }
1093 // accessors
1094 Value obj() const { return _obj; }
1095 ValueStack* lock_stack() const { return _lock_stack; }
1097 // setters
1098 void set_lock_stack(ValueStack* l) { _lock_stack = l; }
1099 void set_can_trap(bool can_trap) { set_flag(CanTrapFlag, can_trap); }
1101 // generic
1102 virtual bool can_trap() const { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }
1103 virtual void input_values_do(void f(Value*)) { f(&_obj); }
1104 virtual void other_values_do(void f(Value*));
1105 HASHING1(NullCheck, true, obj()->subst())
1106 };
1109 BASE(StateSplit, Instruction)
1110 private:
1111 ValueStack* _state;
1113 protected:
1114 static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);
1116 public:
1117 // creation
1118 StateSplit(ValueType* type) : Instruction(type), _state(NULL) {
1119 pin(PinStateSplitConstructor);
1120 }
1122 // accessors
1123 ValueStack* state() const { return _state; }
1124 IRScope* scope() const; // the state's scope
1126 // manipulation
1127 void set_state(ValueStack* state) { _state = state; }
1129 // generic
1130 virtual void input_values_do(void f(Value*)) { /* no values */ }
1131 virtual void state_values_do(void f(Value*));
1132 };
1135 LEAF(Invoke, StateSplit)
1136 private:
1137 Bytecodes::Code _code;
1138 Value _recv;
1139 Values* _args;
1140 BasicTypeList* _signature;
1141 int _vtable_index;
1142 ciMethod* _target;
1143 ValueStack* _state_before; // Required for deoptimization.
1145 public:
1146 // creation
1147 Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1148 int vtable_index, ciMethod* target, ValueStack* state_before);
1150 // accessors
1151 Bytecodes::Code code() const { return _code; }
1152 Value receiver() const { return _recv; }
1153 bool has_receiver() const { return receiver() != NULL; }
1154 int number_of_arguments() const { return _args->length(); }
1155 Value argument_at(int i) const { return _args->at(i); }
1156 int vtable_index() const { return _vtable_index; }
1157 BasicTypeList* signature() const { return _signature; }
1158 ciMethod* target() const { return _target; }
1159 ValueStack* state_before() const { return _state_before; }
1161 // Returns false if target is not loaded
1162 bool target_is_final() const { return check_flag(TargetIsFinalFlag); }
1163 bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }
1164 // Returns false if target is not loaded
1165 bool target_is_strictfp() const { return check_flag(TargetIsStrictfpFlag); }
1167 // JSR 292 support
1168 bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }
1170 // generic
1171 virtual bool can_trap() const { return true; }
1172 virtual void input_values_do(void f(Value*)) {
1173 StateSplit::input_values_do(f);
1174 if (has_receiver()) f(&_recv);
1175 for (int i = 0; i < _args->length(); i++) f(_args->adr_at(i));
1176 }
1177 virtual void state_values_do(void f(Value*));
1178 };
1181 LEAF(NewInstance, StateSplit)
1182 private:
1183 ciInstanceKlass* _klass;
1185 public:
1186 // creation
1187 NewInstance(ciInstanceKlass* klass) : StateSplit(instanceType), _klass(klass) {}
1189 // accessors
1190 ciInstanceKlass* klass() const { return _klass; }
1192 // generic
1193 virtual bool can_trap() const { return true; }
1194 ciType* exact_type() const;
1195 };
1198 BASE(NewArray, StateSplit)
1199 private:
1200 Value _length;
1201 ValueStack* _state_before;
1203 public:
1204 // creation
1205 NewArray(Value length, ValueStack* state_before) : StateSplit(objectType), _length(length), _state_before(state_before) {
1206 // Do not ASSERT_VALUES since length is NULL for NewMultiArray
1207 }
1209 // accessors
1210 ValueStack* state_before() const { return _state_before; }
1211 Value length() const { return _length; }
1213 // generic
1214 virtual bool can_trap() const { return true; }
1215 virtual void input_values_do(void f(Value*)) { StateSplit::input_values_do(f); f(&_length); }
1216 virtual void other_values_do(void f(Value*));
1217 };
1220 LEAF(NewTypeArray, NewArray)
1221 private:
1222 BasicType _elt_type;
1224 public:
1225 // creation
1226 NewTypeArray(Value length, BasicType elt_type) : NewArray(length, NULL), _elt_type(elt_type) {}
1228 // accessors
1229 BasicType elt_type() const { return _elt_type; }
1230 ciType* exact_type() const;
1231 };
1234 LEAF(NewObjectArray, NewArray)
1235 private:
1236 ciKlass* _klass;
1238 public:
1239 // creation
1240 NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}
1242 // accessors
1243 ciKlass* klass() const { return _klass; }
1244 ciType* exact_type() const;
1245 };
1248 LEAF(NewMultiArray, NewArray)
1249 private:
1250 ciKlass* _klass;
1251 Values* _dims;
1253 public:
1254 // creation
1255 NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
1256 ASSERT_VALUES
1257 }
1259 // accessors
1260 ciKlass* klass() const { return _klass; }
1261 Values* dims() const { return _dims; }
1262 int rank() const { return dims()->length(); }
1264 // generic
1265 virtual void input_values_do(void f(Value*)) {
1266 // NOTE: we do not call NewArray::input_values_do since "length"
1267 // is meaningless for a multi-dimensional array; passing the
1268 // zeroth element down to NewArray as its length is a bad idea
1269 // since there will be a copy in the "dims" array which doesn't
1270 // get updated, and the value must not be traversed twice. Was bug
1271 // - kbr 4/10/2001
1272 StateSplit::input_values_do(f);
1273 for (int i = 0; i < _dims->length(); i++) f(_dims->adr_at(i));
1274 }
1275 };
1278 BASE(TypeCheck, StateSplit)
1279 private:
1280 ciKlass* _klass;
1281 Value _obj;
1282 ValueStack* _state_before;
1284 public:
1285 // creation
1286 TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before) : StateSplit(type), _klass(klass), _obj(obj), _state_before(state_before) {
1287 ASSERT_VALUES
1288 set_direct_compare(false);
1289 }
1291 // accessors
1292 ValueStack* state_before() const { return _state_before; }
1293 ciKlass* klass() const { return _klass; }
1294 Value obj() const { return _obj; }
1295 bool is_loaded() const { return klass() != NULL; }
1296 bool direct_compare() const { return check_flag(DirectCompareFlag); }
1298 // manipulation
1299 void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }
1301 // generic
1302 virtual bool can_trap() const { return true; }
1303 virtual void input_values_do(void f(Value*)) { StateSplit::input_values_do(f); f(&_obj); }
1304 virtual void other_values_do(void f(Value*));
1305 };
1308 LEAF(CheckCast, TypeCheck)
1309 private:
1310 ciMethod* _profiled_method;
1311 int _profiled_bci;
1313 public:
1314 // creation
1315 CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1316 : TypeCheck(klass, obj, objectType, state_before)
1317 , _profiled_method(NULL)
1318 , _profiled_bci(0) {}
1320 void set_incompatible_class_change_check() {
1321 set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1322 }
1323 bool is_incompatible_class_change_check() const {
1324 return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1325 }
1327 // Helpers for methodDataOop profiling
1328 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1329 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1330 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1331 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1332 ciMethod* profiled_method() const { return _profiled_method; }
1333 int profiled_bci() const { return _profiled_bci; }
1335 ciType* declared_type() const;
1336 ciType* exact_type() const;
1338 };
1341 LEAF(InstanceOf, TypeCheck)
1342 public:
1343 // creation
1344 InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}
1345 };
1348 BASE(AccessMonitor, StateSplit)
1349 private:
1350 Value _obj;
1351 int _monitor_no;
1353 public:
1354 // creation
1355 AccessMonitor(Value obj, int monitor_no)
1356 : StateSplit(illegalType)
1357 , _obj(obj)
1358 , _monitor_no(monitor_no)
1359 {
1360 set_needs_null_check(true);
1361 ASSERT_VALUES
1362 }
1364 // accessors
1365 Value obj() const { return _obj; }
1366 int monitor_no() const { return _monitor_no; }
1368 // generic
1369 virtual void input_values_do(void f(Value*)) { StateSplit::input_values_do(f); f(&_obj); }
1370 };
1373 LEAF(MonitorEnter, AccessMonitor)
1374 private:
1375 ValueStack* _lock_stack_before;
1377 public:
1378 // creation
1379 MonitorEnter(Value obj, int monitor_no, ValueStack* lock_stack_before)
1380 : AccessMonitor(obj, monitor_no)
1381 , _lock_stack_before(lock_stack_before)
1382 {
1383 ASSERT_VALUES
1384 }
1386 // accessors
1387 ValueStack* lock_stack_before() const { return _lock_stack_before; }
1388 virtual void state_values_do(void f(Value*));
1390 // generic
1391 virtual bool can_trap() const { return true; }
1392 };
1395 LEAF(MonitorExit, AccessMonitor)
1396 public:
1397 // creation
1398 MonitorExit(Value obj, int monitor_no) : AccessMonitor(obj, monitor_no) {}
1399 };
1402 LEAF(Intrinsic, StateSplit)
1403 private:
1404 vmIntrinsics::ID _id;
1405 Values* _args;
1406 ValueStack* _lock_stack;
1407 Value _recv;
1409 public:
1410 // preserves_state can be set to true for Intrinsics
1411 // which are guaranteed to preserve register state across any slow
1412 // cases; setting it to true does not mean that the Intrinsic can
1413 // not trap, only that if we continue execution in the same basic
1414 // block after the Intrinsic, all of the registers are intact. This
1415 // allows load elimination and common expression elimination to be
1416 // performed across the Intrinsic. The default value is false.
1417 Intrinsic(ValueType* type,
1418 vmIntrinsics::ID id,
1419 Values* args,
1420 bool has_receiver,
1421 ValueStack* lock_stack,
1422 bool preserves_state,
1423 bool cantrap = true)
1424 : StateSplit(type)
1425 , _id(id)
1426 , _args(args)
1427 , _lock_stack(lock_stack)
1428 , _recv(NULL)
1429 {
1430 assert(args != NULL, "args must exist");
1431 ASSERT_VALUES
1432 set_flag(PreservesStateFlag, preserves_state);
1433 set_flag(CanTrapFlag, cantrap);
1434 if (has_receiver) {
1435 _recv = argument_at(0);
1436 }
1437 set_needs_null_check(has_receiver);
1439 // some intrinsics can't trap, so don't force them to be pinned
1440 if (!can_trap()) {
1441 unpin(PinStateSplitConstructor);
1442 }
1443 }
1445 // accessors
1446 vmIntrinsics::ID id() const { return _id; }
1447 int number_of_arguments() const { return _args->length(); }
1448 Value argument_at(int i) const { return _args->at(i); }
1449 ValueStack* lock_stack() const { return _lock_stack; }
1451 bool has_receiver() const { return (_recv != NULL); }
1452 Value receiver() const { assert(has_receiver(), "must have receiver"); return _recv; }
1453 bool preserves_state() const { return check_flag(PreservesStateFlag); }
1455 // generic
1456 virtual bool can_trap() const { return check_flag(CanTrapFlag); }
1457 virtual void input_values_do(void f(Value*)) {
1458 StateSplit::input_values_do(f);
1459 for (int i = 0; i < _args->length(); i++) f(_args->adr_at(i));
1460 }
1461 virtual void state_values_do(void f(Value*));
1463 };
1466 class LIR_List;
1468 LEAF(BlockBegin, StateSplit)
1469 private:
1470 static int _next_block_id; // the block counter
1472 int _block_id; // the unique block id
1473 int _depth_first_number; // number of this block in a depth-first ordering
1474 int _linear_scan_number; // number of this block in linear-scan ordering
1475 int _loop_depth; // the loop nesting level of this block
1476 int _loop_index; // number of the innermost loop of this block
1477 int _flags; // the flags associated with this block
1479 // fields used by BlockListBuilder
1480 int _total_preds; // number of predecessors found by BlockListBuilder
1481 BitMap _stores_to_locals; // bit is set when a local variable is stored in the block
1483 // SSA specific fields: (factor out later)
1484 BlockList _successors; // the successors of this block
1485 BlockList _predecessors; // the predecessors of this block
1486 BlockBegin* _dominator; // the dominator of this block
1487 // SSA specific ends
1488 BlockEnd* _end; // the last instruction of this block
1489 BlockList _exception_handlers; // the exception handlers potentially invoked by this block
1490 ValueStackStack* _exception_states; // only for xhandler entries: states of all instructions that have an edge to this xhandler
1491 int _exception_handler_pco; // if this block is the start of an exception handler,
1492 // this records the PC offset in the assembly code of the
1493 // first instruction in this block
1494 Label _label; // the label associated with this block
1495 LIR_List* _lir; // the low level intermediate representation for this block
1497 BitMap _live_in; // set of live LIR_Opr registers at entry to this block
1498 BitMap _live_out; // set of live LIR_Opr registers at exit from this block
1499 BitMap _live_gen; // set of registers used before any redefinition in this block
1500 BitMap _live_kill; // set of registers defined in this block
1502 BitMap _fpu_register_usage;
1503 intArray* _fpu_stack_state; // For x86 FPU code generation with UseLinearScan
1504 int _first_lir_instruction_id; // ID of first LIR instruction in this block
1505 int _last_lir_instruction_id; // ID of last LIR instruction in this block
1507 void iterate_preorder (boolArray& mark, BlockClosure* closure);
1508 void iterate_postorder(boolArray& mark, BlockClosure* closure);
1510 friend class SuxAndWeightAdjuster;
1512 public:
1513 // initialization/counting
1514 static void initialize() { _next_block_id = 0; }
1515 static int number_of_blocks() { return _next_block_id; }
1517 // creation
1518 BlockBegin(int bci)
1519 : StateSplit(illegalType)
1520 , _block_id(_next_block_id++)
1521 , _depth_first_number(-1)
1522 , _linear_scan_number(-1)
1523 , _loop_depth(0)
1524 , _flags(0)
1525 , _dominator(NULL)
1526 , _end(NULL)
1527 , _predecessors(2)
1528 , _successors(2)
1529 , _exception_handlers(1)
1530 , _exception_states(NULL)
1531 , _exception_handler_pco(-1)
1532 , _lir(NULL)
1533 , _loop_index(-1)
1534 , _live_in()
1535 , _live_out()
1536 , _live_gen()
1537 , _live_kill()
1538 , _fpu_register_usage()
1539 , _fpu_stack_state(NULL)
1540 , _first_lir_instruction_id(-1)
1541 , _last_lir_instruction_id(-1)
1542 , _total_preds(0)
1543 , _stores_to_locals()
1544 {
1545 set_bci(bci);
1546 }
1548 // accessors
1549 int block_id() const { return _block_id; }
1550 BlockList* successors() { return &_successors; }
1551 BlockBegin* dominator() const { return _dominator; }
1552 int loop_depth() const { return _loop_depth; }
1553 int depth_first_number() const { return _depth_first_number; }
1554 int linear_scan_number() const { return _linear_scan_number; }
1555 BlockEnd* end() const { return _end; }
1556 Label* label() { return &_label; }
1557 LIR_List* lir() const { return _lir; }
1558 int exception_handler_pco() const { return _exception_handler_pco; }
1559 BitMap& live_in() { return _live_in; }
1560 BitMap& live_out() { return _live_out; }
1561 BitMap& live_gen() { return _live_gen; }
1562 BitMap& live_kill() { return _live_kill; }
1563 BitMap& fpu_register_usage() { return _fpu_register_usage; }
1564 intArray* fpu_stack_state() const { return _fpu_stack_state; }
1565 int first_lir_instruction_id() const { return _first_lir_instruction_id; }
1566 int last_lir_instruction_id() const { return _last_lir_instruction_id; }
1567 int total_preds() const { return _total_preds; }
1568 BitMap& stores_to_locals() { return _stores_to_locals; }
1570 // manipulation
1571 void set_bci(int bci) { Instruction::set_bci(bci); }
1572 void set_dominator(BlockBegin* dom) { _dominator = dom; }
1573 void set_loop_depth(int d) { _loop_depth = d; }
1574 void set_depth_first_number(int dfn) { _depth_first_number = dfn; }
1575 void set_linear_scan_number(int lsn) { _linear_scan_number = lsn; }
1576 void set_end(BlockEnd* end);
1577 void disconnect_from_graph();
1578 static void disconnect_edge(BlockBegin* from, BlockBegin* to);
1579 BlockBegin* insert_block_between(BlockBegin* sux);
1580 void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1581 void set_lir(LIR_List* lir) { _lir = lir; }
1582 void set_exception_handler_pco(int pco) { _exception_handler_pco = pco; }
1583 void set_live_in (BitMap map) { _live_in = map; }
1584 void set_live_out (BitMap map) { _live_out = map; }
1585 void set_live_gen (BitMap map) { _live_gen = map; }
1586 void set_live_kill (BitMap map) { _live_kill = map; }
1587 void set_fpu_register_usage(BitMap map) { _fpu_register_usage = map; }
1588 void set_fpu_stack_state(intArray* state) { _fpu_stack_state = state; }
1589 void set_first_lir_instruction_id(int id) { _first_lir_instruction_id = id; }
1590 void set_last_lir_instruction_id(int id) { _last_lir_instruction_id = id; }
1591 void increment_total_preds(int n = 1) { _total_preds += n; }
1592 void init_stores_to_locals(int locals_count) { _stores_to_locals = BitMap(locals_count); _stores_to_locals.clear(); }
1594 // generic
1595 virtual void state_values_do(void f(Value*));
1597 // successors and predecessors
1598 int number_of_sux() const;
1599 BlockBegin* sux_at(int i) const;
1600 void add_successor(BlockBegin* sux);
1601 void remove_successor(BlockBegin* pred);
1602 bool is_successor(BlockBegin* sux) const { return _successors.contains(sux); }
1604 void add_predecessor(BlockBegin* pred);
1605 void remove_predecessor(BlockBegin* pred);
1606 bool is_predecessor(BlockBegin* pred) const { return _predecessors.contains(pred); }
1607 int number_of_preds() const { return _predecessors.length(); }
1608 BlockBegin* pred_at(int i) const { return _predecessors[i]; }
1610 // exception handlers potentially invoked by this block
1611 void add_exception_handler(BlockBegin* b);
1612 bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }
1613 int number_of_exception_handlers() const { return _exception_handlers.length(); }
1614 BlockBegin* exception_handler_at(int i) const { return _exception_handlers.at(i); }
1616 // states of the instructions that have an edge to this exception handler
1617 int number_of_exception_states() { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); }
1618 ValueStack* exception_state_at(int idx) const { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }
1619 int add_exception_state(ValueStack* state);
1621 // flags
1622 enum Flag {
1623 no_flag = 0,
1624 std_entry_flag = 1 << 0,
1625 osr_entry_flag = 1 << 1,
1626 exception_entry_flag = 1 << 2,
1627 subroutine_entry_flag = 1 << 3,
1628 backward_branch_target_flag = 1 << 4,
1629 is_on_work_list_flag = 1 << 5,
1630 was_visited_flag = 1 << 6,
1631 default_exception_handler_flag = 1 << 8, // identify block which represents the default exception handler
1632 parser_loop_header_flag = 1 << 9, // set by parser to identify blocks where phi functions can not be created on demand
1633 critical_edge_split_flag = 1 << 10, // set for all blocks that are introduced when critical edges are split
1634 linear_scan_loop_header_flag = 1 << 11, // set during loop-detection for LinearScan
1635 linear_scan_loop_end_flag = 1 << 12 // set during loop-detection for LinearScan
1636 };
1638 void set(Flag f) { _flags |= f; }
1639 void clear(Flag f) { _flags &= ~f; }
1640 bool is_set(Flag f) const { return (_flags & f) != 0; }
1641 bool is_entry_block() const {
1642 const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;
1643 return (_flags & entry_mask) != 0;
1644 }
1646 // iteration
1647 void iterate_preorder (BlockClosure* closure);
1648 void iterate_postorder (BlockClosure* closure);
1650 void block_values_do(void f(Value*));
1652 // loops
1653 void set_loop_index(int ix) { _loop_index = ix; }
1654 int loop_index() const { return _loop_index; }
1656 // merging
1657 bool try_merge(ValueStack* state); // try to merge states at block begin
1658 void merge(ValueStack* state) { bool b = try_merge(state); assert(b, "merge failed"); }
1660 // debugging
1661 void print_block() PRODUCT_RETURN;
1662 void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;
1663 };
1666 BASE(BlockEnd, StateSplit)
1667 private:
1668 BlockBegin* _begin;
1669 BlockList* _sux;
1670 ValueStack* _state_before;
1672 protected:
1673 BlockList* sux() const { return _sux; }
1675 void set_sux(BlockList* sux) {
1676 #ifdef ASSERT
1677 assert(sux != NULL, "sux must exist");
1678 for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist");
1679 #endif
1680 _sux = sux;
1681 }
1683 public:
1684 // creation
1685 BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)
1686 : StateSplit(type)
1687 , _begin(NULL)
1688 , _sux(NULL)
1689 , _state_before(state_before) {
1690 set_flag(IsSafepointFlag, is_safepoint);
1691 }
1693 // accessors
1694 ValueStack* state_before() const { return _state_before; }
1695 bool is_safepoint() const { return check_flag(IsSafepointFlag); }
1696 BlockBegin* begin() const { return _begin; }
1698 // manipulation
1699 void set_begin(BlockBegin* begin);
1701 // generic
1702 virtual void other_values_do(void f(Value*));
1704 // successors
1705 int number_of_sux() const { return _sux != NULL ? _sux->length() : 0; }
1706 BlockBegin* sux_at(int i) const { return _sux->at(i); }
1707 BlockBegin* default_sux() const { return sux_at(number_of_sux() - 1); }
1708 BlockBegin** addr_sux_at(int i) const { return _sux->adr_at(i); }
1709 int sux_index(BlockBegin* sux) const { return _sux->find(sux); }
1710 void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1711 };
1714 LEAF(Goto, BlockEnd)
1715 public:
1716 // creation
1717 Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false) : BlockEnd(illegalType, state_before, is_safepoint) {
1718 BlockList* s = new BlockList(1);
1719 s->append(sux);
1720 set_sux(s);
1721 }
1723 Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint) {
1724 BlockList* s = new BlockList(1);
1725 s->append(sux);
1726 set_sux(s);
1727 }
1729 };
1732 LEAF(If, BlockEnd)
1733 private:
1734 Value _x;
1735 Condition _cond;
1736 Value _y;
1737 ciMethod* _profiled_method;
1738 int _profiled_bci; // Canonicalizer may alter bci of If node
1739 public:
1740 // creation
1741 // unordered_is_true is valid for float/double compares only
1742 If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)
1743 : BlockEnd(illegalType, state_before, is_safepoint)
1744 , _x(x)
1745 , _cond(cond)
1746 , _y(y)
1747 , _profiled_method(NULL)
1748 , _profiled_bci(0)
1749 {
1750 ASSERT_VALUES
1751 set_flag(UnorderedIsTrueFlag, unordered_is_true);
1752 assert(x->type()->tag() == y->type()->tag(), "types must match");
1753 BlockList* s = new BlockList(2);
1754 s->append(tsux);
1755 s->append(fsux);
1756 set_sux(s);
1757 }
1759 // accessors
1760 Value x() const { return _x; }
1761 Condition cond() const { return _cond; }
1762 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
1763 Value y() const { return _y; }
1764 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
1765 BlockBegin* tsux() const { return sux_for(true); }
1766 BlockBegin* fsux() const { return sux_for(false); }
1767 BlockBegin* usux() const { return sux_for(unordered_is_true()); }
1768 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1769 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
1770 int profiled_bci() const { return _profiled_bci; } // set only for profiled branches
1772 // manipulation
1773 void swap_operands() {
1774 Value t = _x; _x = _y; _y = t;
1775 _cond = mirror(_cond);
1776 }
1778 void swap_sux() {
1779 assert(number_of_sux() == 2, "wrong number of successors");
1780 BlockList* s = sux();
1781 BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
1782 _cond = negate(_cond);
1783 set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));
1784 }
1786 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1787 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1788 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1790 // generic
1791 virtual void input_values_do(void f(Value*)) { BlockEnd::input_values_do(f); f(&_x); f(&_y); }
1792 };
1795 LEAF(IfInstanceOf, BlockEnd)
1796 private:
1797 ciKlass* _klass;
1798 Value _obj;
1799 bool _test_is_instance; // jump if instance
1800 int _instanceof_bci;
1802 public:
1803 IfInstanceOf(ciKlass* klass, Value obj, bool test_is_instance, int instanceof_bci, BlockBegin* tsux, BlockBegin* fsux)
1804 : BlockEnd(illegalType, NULL, false) // temporary set to false
1805 , _klass(klass)
1806 , _obj(obj)
1807 , _test_is_instance(test_is_instance)
1808 , _instanceof_bci(instanceof_bci)
1809 {
1810 ASSERT_VALUES
1811 assert(instanceof_bci >= 0, "illegal bci");
1812 BlockList* s = new BlockList(2);
1813 s->append(tsux);
1814 s->append(fsux);
1815 set_sux(s);
1816 }
1818 // accessors
1819 //
1820 // Note 1: If test_is_instance() is true, IfInstanceOf tests if obj *is* an
1821 // instance of klass; otherwise it tests if it is *not* and instance
1822 // of klass.
1823 //
1824 // Note 2: IfInstanceOf instructions are created by combining an InstanceOf
1825 // and an If instruction. The IfInstanceOf bci() corresponds to the
1826 // bci that the If would have had; the (this->) instanceof_bci() is
1827 // the bci of the original InstanceOf instruction.
1828 ciKlass* klass() const { return _klass; }
1829 Value obj() const { return _obj; }
1830 int instanceof_bci() const { return _instanceof_bci; }
1831 bool test_is_instance() const { return _test_is_instance; }
1832 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
1833 BlockBegin* tsux() const { return sux_for(true); }
1834 BlockBegin* fsux() const { return sux_for(false); }
1836 // manipulation
1837 void swap_sux() {
1838 assert(number_of_sux() == 2, "wrong number of successors");
1839 BlockList* s = sux();
1840 BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
1841 _test_is_instance = !_test_is_instance;
1842 }
1844 // generic
1845 virtual void input_values_do(void f(Value*)) { BlockEnd::input_values_do(f); f(&_obj); }
1846 };
1849 BASE(Switch, BlockEnd)
1850 private:
1851 Value _tag;
1853 public:
1854 // creation
1855 Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
1856 : BlockEnd(illegalType, state_before, is_safepoint)
1857 , _tag(tag) {
1858 ASSERT_VALUES
1859 set_sux(sux);
1860 }
1862 // accessors
1863 Value tag() const { return _tag; }
1864 int length() const { return number_of_sux() - 1; }
1866 // generic
1867 virtual void input_values_do(void f(Value*)) { BlockEnd::input_values_do(f); f(&_tag); }
1868 };
1871 LEAF(TableSwitch, Switch)
1872 private:
1873 int _lo_key;
1875 public:
1876 // creation
1877 TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)
1878 : Switch(tag, sux, state_before, is_safepoint)
1879 , _lo_key(lo_key) {}
1881 // accessors
1882 int lo_key() const { return _lo_key; }
1883 int hi_key() const { return _lo_key + length() - 1; }
1884 };
1887 LEAF(LookupSwitch, Switch)
1888 private:
1889 intArray* _keys;
1891 public:
1892 // creation
1893 LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)
1894 : Switch(tag, sux, state_before, is_safepoint)
1895 , _keys(keys) {
1896 assert(keys != NULL, "keys must exist");
1897 assert(keys->length() == length(), "sux & keys have incompatible lengths");
1898 }
1900 // accessors
1901 int key_at(int i) const { return _keys->at(i); }
1902 };
1905 LEAF(Return, BlockEnd)
1906 private:
1907 Value _result;
1909 public:
1910 // creation
1911 Return(Value result) :
1912 BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true),
1913 _result(result) {}
1915 // accessors
1916 Value result() const { return _result; }
1917 bool has_result() const { return result() != NULL; }
1919 // generic
1920 virtual void input_values_do(void f(Value*)) {
1921 BlockEnd::input_values_do(f);
1922 if (has_result()) f(&_result);
1923 }
1924 };
1927 LEAF(Throw, BlockEnd)
1928 private:
1929 Value _exception;
1931 public:
1932 // creation
1933 Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {
1934 ASSERT_VALUES
1935 }
1937 // accessors
1938 Value exception() const { return _exception; }
1940 // generic
1941 virtual bool can_trap() const { return true; }
1942 virtual void input_values_do(void f(Value*)) { BlockEnd::input_values_do(f); f(&_exception); }
1943 virtual void state_values_do(void f(Value*));
1944 };
1947 LEAF(Base, BlockEnd)
1948 public:
1949 // creation
1950 Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, NULL, false) {
1951 assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged");
1952 assert(osr_entry == NULL || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged");
1953 BlockList* s = new BlockList(2);
1954 if (osr_entry != NULL) s->append(osr_entry);
1955 s->append(std_entry); // must be default sux!
1956 set_sux(s);
1957 }
1959 // accessors
1960 BlockBegin* std_entry() const { return default_sux(); }
1961 BlockBegin* osr_entry() const { return number_of_sux() < 2 ? NULL : sux_at(0); }
1962 };
1965 LEAF(OsrEntry, Instruction)
1966 public:
1967 // creation
1968 #ifdef _LP64
1969 OsrEntry() : Instruction(longType, false) { pin(); }
1970 #else
1971 OsrEntry() : Instruction(intType, false) { pin(); }
1972 #endif
1974 // generic
1975 virtual void input_values_do(void f(Value*)) { }
1976 };
1979 // Models the incoming exception at a catch site
1980 LEAF(ExceptionObject, Instruction)
1981 public:
1982 // creation
1983 ExceptionObject() : Instruction(objectType, false) {
1984 pin();
1985 }
1987 // generic
1988 virtual void input_values_do(void f(Value*)) { }
1989 };
1992 // Models needed rounding for floating-point values on Intel.
1993 // Currently only used to represent rounding of double-precision
1994 // values stored into local variables, but could be used to model
1995 // intermediate rounding of single-precision values as well.
1996 LEAF(RoundFP, Instruction)
1997 private:
1998 Value _input; // floating-point value to be rounded
2000 public:
2001 RoundFP(Value input)
2002 : Instruction(input->type()) // Note: should not be used for constants
2003 , _input(input)
2004 {
2005 ASSERT_VALUES
2006 }
2008 // accessors
2009 Value input() const { return _input; }
2011 // generic
2012 virtual void input_values_do(void f(Value*)) { f(&_input); }
2013 };
2016 BASE(UnsafeOp, Instruction)
2017 private:
2018 BasicType _basic_type; // ValueType can not express byte-sized integers
2020 protected:
2021 // creation
2022 UnsafeOp(BasicType basic_type, bool is_put)
2023 : Instruction(is_put ? voidType : as_ValueType(basic_type))
2024 , _basic_type(basic_type)
2025 {
2026 //Note: Unsafe ops are not not guaranteed to throw NPE.
2027 // Convservatively, Unsafe operations must be pinned though we could be
2028 // looser about this if we wanted to..
2029 pin();
2030 }
2032 public:
2033 // accessors
2034 BasicType basic_type() { return _basic_type; }
2036 // generic
2037 virtual void input_values_do(void f(Value*)) { }
2038 virtual void other_values_do(void f(Value*)) { }
2039 };
2042 BASE(UnsafeRawOp, UnsafeOp)
2043 private:
2044 Value _base; // Base address (a Java long)
2045 Value _index; // Index if computed by optimizer; initialized to NULL
2046 int _log2_scale; // Scale factor: 0, 1, 2, or 3.
2047 // Indicates log2 of number of bytes (1, 2, 4, or 8)
2048 // to scale index by.
2050 protected:
2051 UnsafeRawOp(BasicType basic_type, Value addr, bool is_put)
2052 : UnsafeOp(basic_type, is_put)
2053 , _base(addr)
2054 , _index(NULL)
2055 , _log2_scale(0)
2056 {
2057 // Can not use ASSERT_VALUES because index may be NULL
2058 assert(addr != NULL && addr->type()->is_long(), "just checking");
2059 }
2061 UnsafeRawOp(BasicType basic_type, Value base, Value index, int log2_scale, bool is_put)
2062 : UnsafeOp(basic_type, is_put)
2063 , _base(base)
2064 , _index(index)
2065 , _log2_scale(log2_scale)
2066 {
2067 }
2069 public:
2070 // accessors
2071 Value base() { return _base; }
2072 Value index() { return _index; }
2073 bool has_index() { return (_index != NULL); }
2074 int log2_scale() { return _log2_scale; }
2076 // setters
2077 void set_base (Value base) { _base = base; }
2078 void set_index(Value index) { _index = index; }
2079 void set_log2_scale(int log2_scale) { _log2_scale = log2_scale; }
2081 // generic
2082 virtual void input_values_do(void f(Value*)) { UnsafeOp::input_values_do(f);
2083 f(&_base);
2084 if (has_index()) f(&_index); }
2085 };
2088 LEAF(UnsafeGetRaw, UnsafeRawOp)
2089 private:
2090 bool _may_be_unaligned; // For OSREntry
2092 public:
2093 UnsafeGetRaw(BasicType basic_type, Value addr, bool may_be_unaligned)
2094 : UnsafeRawOp(basic_type, addr, false) {
2095 _may_be_unaligned = may_be_unaligned;
2096 }
2098 UnsafeGetRaw(BasicType basic_type, Value base, Value index, int log2_scale, bool may_be_unaligned)
2099 : UnsafeRawOp(basic_type, base, index, log2_scale, false) {
2100 _may_be_unaligned = may_be_unaligned;
2101 }
2103 bool may_be_unaligned() { return _may_be_unaligned; }
2104 };
2107 LEAF(UnsafePutRaw, UnsafeRawOp)
2108 private:
2109 Value _value; // Value to be stored
2111 public:
2112 UnsafePutRaw(BasicType basic_type, Value addr, Value value)
2113 : UnsafeRawOp(basic_type, addr, true)
2114 , _value(value)
2115 {
2116 assert(value != NULL, "just checking");
2117 ASSERT_VALUES
2118 }
2120 UnsafePutRaw(BasicType basic_type, Value base, Value index, int log2_scale, Value value)
2121 : UnsafeRawOp(basic_type, base, index, log2_scale, true)
2122 , _value(value)
2123 {
2124 assert(value != NULL, "just checking");
2125 ASSERT_VALUES
2126 }
2128 // accessors
2129 Value value() { return _value; }
2131 // generic
2132 virtual void input_values_do(void f(Value*)) { UnsafeRawOp::input_values_do(f);
2133 f(&_value); }
2134 };
2137 BASE(UnsafeObjectOp, UnsafeOp)
2138 private:
2139 Value _object; // Object to be fetched from or mutated
2140 Value _offset; // Offset within object
2141 bool _is_volatile; // true if volatile - dl/JSR166
2142 public:
2143 UnsafeObjectOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile)
2144 : UnsafeOp(basic_type, is_put), _object(object), _offset(offset), _is_volatile(is_volatile)
2145 {
2146 }
2148 // accessors
2149 Value object() { return _object; }
2150 Value offset() { return _offset; }
2151 bool is_volatile() { return _is_volatile; }
2152 // generic
2153 virtual void input_values_do(void f(Value*)) { UnsafeOp::input_values_do(f);
2154 f(&_object);
2155 f(&_offset); }
2156 };
2159 LEAF(UnsafeGetObject, UnsafeObjectOp)
2160 public:
2161 UnsafeGetObject(BasicType basic_type, Value object, Value offset, bool is_volatile)
2162 : UnsafeObjectOp(basic_type, object, offset, false, is_volatile)
2163 {
2164 ASSERT_VALUES
2165 }
2166 };
2169 LEAF(UnsafePutObject, UnsafeObjectOp)
2170 private:
2171 Value _value; // Value to be stored
2172 public:
2173 UnsafePutObject(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile)
2174 : UnsafeObjectOp(basic_type, object, offset, true, is_volatile)
2175 , _value(value)
2176 {
2177 ASSERT_VALUES
2178 }
2180 // accessors
2181 Value value() { return _value; }
2183 // generic
2184 virtual void input_values_do(void f(Value*)) { UnsafeObjectOp::input_values_do(f);
2185 f(&_value); }
2186 };
2189 BASE(UnsafePrefetch, UnsafeObjectOp)
2190 public:
2191 UnsafePrefetch(Value object, Value offset)
2192 : UnsafeObjectOp(T_VOID, object, offset, false, false)
2193 {
2194 }
2195 };
2198 LEAF(UnsafePrefetchRead, UnsafePrefetch)
2199 public:
2200 UnsafePrefetchRead(Value object, Value offset)
2201 : UnsafePrefetch(object, offset)
2202 {
2203 ASSERT_VALUES
2204 }
2205 };
2208 LEAF(UnsafePrefetchWrite, UnsafePrefetch)
2209 public:
2210 UnsafePrefetchWrite(Value object, Value offset)
2211 : UnsafePrefetch(object, offset)
2212 {
2213 ASSERT_VALUES
2214 }
2215 };
2218 LEAF(ProfileCall, Instruction)
2219 private:
2220 ciMethod* _method;
2221 int _bci_of_invoke;
2222 Value _recv;
2223 ciKlass* _known_holder;
2225 public:
2226 ProfileCall(ciMethod* method, int bci, Value recv, ciKlass* known_holder)
2227 : Instruction(voidType)
2228 , _method(method)
2229 , _bci_of_invoke(bci)
2230 , _recv(recv)
2231 , _known_holder(known_holder)
2232 {
2233 // The ProfileCall has side-effects and must occur precisely where located
2234 pin();
2235 }
2237 ciMethod* method() { return _method; }
2238 int bci_of_invoke() { return _bci_of_invoke; }
2239 Value recv() { return _recv; }
2240 ciKlass* known_holder() { return _known_holder; }
2242 virtual void input_values_do(void f(Value*)) { if (_recv != NULL) f(&_recv); }
2243 };
2246 //
2247 // Simple node representing a counter update generally used for updating MDOs
2248 //
2249 LEAF(ProfileCounter, Instruction)
2250 private:
2251 Value _mdo;
2252 int _offset;
2253 int _increment;
2255 public:
2256 ProfileCounter(Value mdo, int offset, int increment = 1)
2257 : Instruction(voidType)
2258 , _mdo(mdo)
2259 , _offset(offset)
2260 , _increment(increment)
2261 {
2262 // The ProfileCounter has side-effects and must occur precisely where located
2263 pin();
2264 }
2266 Value mdo() { return _mdo; }
2267 int offset() { return _offset; }
2268 int increment() { return _increment; }
2270 virtual void input_values_do(void f(Value*)) { f(&_mdo); }
2271 };
2274 class BlockPair: public CompilationResourceObj {
2275 private:
2276 BlockBegin* _from;
2277 BlockBegin* _to;
2278 public:
2279 BlockPair(BlockBegin* from, BlockBegin* to): _from(from), _to(to) {}
2280 BlockBegin* from() const { return _from; }
2281 BlockBegin* to() const { return _to; }
2282 bool is_same(BlockBegin* from, BlockBegin* to) const { return _from == from && _to == to; }
2283 bool is_same(BlockPair* p) const { return _from == p->from() && _to == p->to(); }
2284 void set_to(BlockBegin* b) { _to = b; }
2285 void set_from(BlockBegin* b) { _from = b; }
2286 };
2289 define_array(BlockPairArray, BlockPair*)
2290 define_stack(BlockPairList, BlockPairArray)
2293 inline int BlockBegin::number_of_sux() const { assert(_end == NULL || _end->number_of_sux() == _successors.length(), "mismatch"); return _successors.length(); }
2294 inline BlockBegin* BlockBegin::sux_at(int i) const { assert(_end == NULL || _end->sux_at(i) == _successors.at(i), "mismatch"); return _successors.at(i); }
2295 inline void BlockBegin::add_successor(BlockBegin* sux) { assert(_end == NULL, "Would create mismatch with successors of BlockEnd"); _successors.append(sux); }
2297 #undef ASSERT_VALUES