53 class AccessArray;
54 class ArrayLength;
55 class AccessIndexed;
56 class LoadIndexed;
57 class StoreIndexed;
58 class NegateOp;
59 class Op2;
60 class ArithmeticOp;
61 class ShiftOp;
62 class LogicOp;
63 class CompareOp;
64 class IfOp;
65 class Convert;
66 class NullCheck;
67 class TypeCast;
68 class OsrEntry;
69 class ExceptionObject;
70 class StateSplit;
71 class Invoke;
72 class NewInstance;
73 class NewArray;
74 class NewTypeArray;
75 class NewObjectArray;
76 class NewMultiArray;
77 class TypeCheck;
78 class CheckCast;
79 class InstanceOf;
80 class AccessMonitor;
81 class MonitorEnter;
82 class MonitorExit;
83 class Intrinsic;
84 class BlockBegin;
85 class BlockEnd;
86 class Goto;
87 class If;
88 class Switch;
89 class TableSwitch;
90 class LookupSwitch;
91 class Return;
92 class Throw;
93 class Base;
94 class RoundFP;
95 class UnsafeOp;
96 class UnsafeGet;
97 class UnsafePut;
98 class UnsafeGetAndSet;
99 class ProfileCall;
100 class ProfileReturnType;
101 class ProfileInvoke;
102 class RuntimeCall;
103 class MemBar;
104 class RangeCheckPredicate;
105 #ifdef ASSERT
106 class Assert;
107 #endif
108
109 // A Value is a reference to the instruction creating the value
110 typedef Instruction* Value;
111 typedef GrowableArray<Value> Values;
112 typedef GrowableArray<ValueStack*> ValueStackStack;
113
114 // BlockClosure is the base class for block traversal/iteration.
115
116 class BlockClosure: public CompilationResourceObj {
117 public:
118 virtual void block_do(BlockBegin* block) = 0;
119 };
120
152 public:
153 virtual void do_Phi (Phi* x) = 0;
154 virtual void do_Local (Local* x) = 0;
155 virtual void do_Constant (Constant* x) = 0;
156 virtual void do_LoadField (LoadField* x) = 0;
157 virtual void do_StoreField (StoreField* x) = 0;
158 virtual void do_ArrayLength (ArrayLength* x) = 0;
159 virtual void do_LoadIndexed (LoadIndexed* x) = 0;
160 virtual void do_StoreIndexed (StoreIndexed* x) = 0;
161 virtual void do_NegateOp (NegateOp* x) = 0;
162 virtual void do_ArithmeticOp (ArithmeticOp* x) = 0;
163 virtual void do_ShiftOp (ShiftOp* x) = 0;
164 virtual void do_LogicOp (LogicOp* x) = 0;
165 virtual void do_CompareOp (CompareOp* x) = 0;
166 virtual void do_IfOp (IfOp* x) = 0;
167 virtual void do_Convert (Convert* x) = 0;
168 virtual void do_NullCheck (NullCheck* x) = 0;
169 virtual void do_TypeCast (TypeCast* x) = 0;
170 virtual void do_Invoke (Invoke* x) = 0;
171 virtual void do_NewInstance (NewInstance* x) = 0;
172 virtual void do_NewTypeArray (NewTypeArray* x) = 0;
173 virtual void do_NewObjectArray (NewObjectArray* x) = 0;
174 virtual void do_NewMultiArray (NewMultiArray* x) = 0;
175 virtual void do_CheckCast (CheckCast* x) = 0;
176 virtual void do_InstanceOf (InstanceOf* x) = 0;
177 virtual void do_MonitorEnter (MonitorEnter* x) = 0;
178 virtual void do_MonitorExit (MonitorExit* x) = 0;
179 virtual void do_Intrinsic (Intrinsic* x) = 0;
180 virtual void do_BlockBegin (BlockBegin* x) = 0;
181 virtual void do_Goto (Goto* x) = 0;
182 virtual void do_If (If* x) = 0;
183 virtual void do_TableSwitch (TableSwitch* x) = 0;
184 virtual void do_LookupSwitch (LookupSwitch* x) = 0;
185 virtual void do_Return (Return* x) = 0;
186 virtual void do_Throw (Throw* x) = 0;
187 virtual void do_Base (Base* x) = 0;
188 virtual void do_OsrEntry (OsrEntry* x) = 0;
189 virtual void do_ExceptionObject(ExceptionObject* x) = 0;
190 virtual void do_RoundFP (RoundFP* x) = 0;
191 virtual void do_UnsafeGet (UnsafeGet* x) = 0;
192 virtual void do_UnsafePut (UnsafePut* x) = 0;
193 virtual void do_UnsafeGetAndSet(UnsafeGetAndSet* x) = 0;
194 virtual void do_ProfileCall (ProfileCall* x) = 0;
195 virtual void do_ProfileReturnType (ProfileReturnType* x) = 0;
196 virtual void do_ProfileInvoke (ProfileInvoke* x) = 0;
197 virtual void do_RuntimeCall (RuntimeCall* x) = 0;
198 virtual void do_MemBar (MemBar* x) = 0;
199 virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0;
200 #ifdef ASSERT
201 virtual void do_Assert (Assert* x) = 0;
202 #endif
203 };
204
205
206 // Hashing support
207 //
208 // Note: This hash functions affect the performance
209 // of ValueMap - make changes carefully!
210
211 #define HASH1(x1 ) ((intx)(x1))
212 #define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2))
213 #define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3))
214 #define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))
215
216
217 // The following macros are used to implement instruction-specific hashing.
218 // By default, each instruction implements hash() and is_equal(Value), used
219 // for value numbering/common subexpression elimination. The default imple-
220 // mentation disables value numbering. Each instruction which can be value-
221 // numbered, should define corresponding hash() and is_equal(Value) functions
222 // via the macros below. The f arguments specify all the values/op codes, etc.
223 // that need to be identical for two instructions to be identical.
224 //
225 // Note: The default implementation of hash() returns 0 in order to indicate
226 // that the instruction should not be considered for value numbering.
227 // The currently used hash functions do not guarantee that never a 0
228 // is produced. While this is still correct, it may be a performance
229 // bug (no value numbering for that node). However, this situation is
230 // so unlikely, that we are not going to handle it specially.
231
232 #define HASHING1(class_name, enabled, f1) \
233 virtual intx hash() const { \
234 return (enabled) ? HASH2(name(), f1) : 0; \
253 if (f1 != _v->f1) return false; \
254 if (f2 != _v->f2) return false; \
255 return true; \
256 } \
257
258
259 #define HASHING3(class_name, enabled, f1, f2, f3) \
260 virtual intx hash() const { \
261 return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
262 } \
263 virtual bool is_equal(Value v) const { \
264 if (!(enabled) ) return false; \
265 class_name* _v = v->as_##class_name(); \
266 if (_v == NULL ) return false; \
267 if (f1 != _v->f1) return false; \
268 if (f2 != _v->f2) return false; \
269 if (f3 != _v->f3) return false; \
270 return true; \
271 } \
272
273
274 // The mother of all instructions...
275
276 class Instruction: public CompilationResourceObj {
277 private:
278 int _id; // the unique instruction id
279 #ifndef PRODUCT
280 int _printable_bci; // the bci of the instruction for printing
281 #endif
282 int _use_count; // the number of instructions referring to this value (w/o prev/next); only roots can have use count = 0 or > 1
283 int _pin_state; // set of PinReason describing the reason for pinning
284 ValueType* _type; // the instruction value type
285 Instruction* _next; // the next instruction if any (NULL for BlockEnd instructions)
286 Instruction* _subst; // the substitution instruction if any
287 LIR_Opr _operand; // LIR specific information
288 unsigned int _flags; // Flag bits
289
290 ValueStack* _state_before; // Copy of state with input operands still on stack (or NULL)
291 ValueStack* _exception_state; // Copy of state for exception handling
292 XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction
293
294 friend class UseCountComputer;
295
296 void update_exception_state(ValueStack* state);
297
298 protected:
299 BlockBegin* _block; // Block that contains this instruction
300
301 void set_type(ValueType* type) {
302 assert(type != NULL, "type must exist");
303 _type = type;
304 }
305
306 // Helper class to keep track of which arguments need a null check
307 class ArgsNonNullState {
308 private:
309 int _nonnull_state; // mask identifying which args are nonnull
310 public:
311 ArgsNonNullState()
312 : _nonnull_state(AllBits) {}
313
314 // Does argument number i needs a null check?
327 if (check) {
328 _nonnull_state |= nth_bit(i);
329 } else {
330 _nonnull_state &= ~(nth_bit(i));
331 }
332 }
333 }
334 };
335
336 public:
337 void* operator new(size_t size) throw() {
338 Compilation* c = Compilation::current();
339 void* res = c->arena()->Amalloc(size);
340 return res;
341 }
342
343 static const int no_bci = -99;
344
345 enum InstructionFlag {
346 NeedsNullCheckFlag = 0,
347 CanTrapFlag,
348 DirectCompareFlag,
349 IsEliminatedFlag,
350 IsSafepointFlag,
351 IsStaticFlag,
352 NeedsStoreCheckFlag,
353 NeedsWriteBarrierFlag,
354 PreservesStateFlag,
355 TargetIsFinalFlag,
356 TargetIsLoadedFlag,
357 UnorderedIsTrueFlag,
358 NeedsPatchingFlag,
359 ThrowIncompatibleClassChangeErrorFlag,
360 InvokeSpecialReceiverCheckFlag,
361 ProfileMDOFlag,
362 IsLinkedInBlockFlag,
363 NeedsRangeCheckFlag,
364 InWorkListFlag,
365 DeoptimizeOnException,
366 KillsMemoryFlag,
420 int id() const { return _id; }
421 #ifndef PRODUCT
422 bool has_printable_bci() const { return _printable_bci != -99; }
423 int printable_bci() const { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
424 void set_printable_bci(int bci) { _printable_bci = bci; }
425 #endif
426 int dominator_depth();
427 int use_count() const { return _use_count; }
428 int pin_state() const { return _pin_state; }
429 bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; }
430 ValueType* type() const { return _type; }
431 BlockBegin *block() const { return _block; }
432 Instruction* prev(); // use carefully, expensive operation
433 Instruction* next() const { return _next; }
434 bool has_subst() const { return _subst != NULL; }
435 Instruction* subst() { return _subst == NULL ? this : _subst->subst(); }
436 LIR_Opr operand() const { return _operand; }
437
438 void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); }
439 bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); }
440 bool is_linked() const { return check_flag(IsLinkedInBlockFlag); }
441 bool can_be_linked() { return as_Local() == NULL && as_Phi() == NULL; }
442
443 bool is_null_obj() { return as_Constant() != NULL && type()->as_ObjectType()->constant_value()->is_null_object(); }
444
445 bool has_uses() const { return use_count() > 0; }
446 ValueStack* state_before() const { return _state_before; }
447 ValueStack* exception_state() const { return _exception_state; }
448 virtual bool needs_exception_state() const { return true; }
449 XHandlers* exception_handlers() const { return _exception_handlers; }
450
451 // manipulation
452 void pin(PinReason reason) { _pin_state |= reason; }
453 void pin() { _pin_state |= PinUnknown; }
454 // DANGEROUS: only used by EliminateStores
455 void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
456
457 Instruction* set_next(Instruction* next) {
458 assert(next->has_printable_bci(), "_printable_bci should have been set");
459 assert(next != NULL, "must not be NULL");
460 assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");
461 assert(next->can_be_linked(), "shouldn't link these instructions into list");
462
463 BlockBegin *block = this->block();
464 next->_block = block;
465
466 next->set_flag(Instruction::IsLinkedInBlockFlag, true);
467 _next = next;
468 return next;
469 }
474 #endif
475 return set_next(next);
476 }
477
478 // when blocks are merged
479 void fixup_block_pointers() {
480 Instruction *cur = next()->next(); // next()'s block is set in set_next
481 while (cur && cur->_block != block()) {
482 cur->_block = block();
483 cur = cur->next();
484 }
485 }
486
487 Instruction *insert_after(Instruction *i) {
488 Instruction* n = _next;
489 set_next(i);
490 i->set_next(n);
491 return _next;
492 }
493
494 Instruction *insert_after_same_bci(Instruction *i) {
495 #ifndef PRODUCT
496 i->set_printable_bci(printable_bci());
497 #endif
498 return insert_after(i);
499 }
500
501 void set_subst(Instruction* subst) {
502 assert(subst == NULL ||
503 type()->base() == subst->type()->base() ||
504 subst->type()->base() == illegalType, "type can't change");
505 _subst = subst;
506 }
507 void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
508 void set_exception_state(ValueStack* s) { check_state(s); _exception_state = s; }
509 void set_state_before(ValueStack* s) { check_state(s); _state_before = s; }
510
511 // machine-specifics
512 void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
513 void clear_operand() { _operand = LIR_OprFact::illegalOpr; }
521 virtual LoadField* as_LoadField() { return NULL; }
522 virtual StoreField* as_StoreField() { return NULL; }
523 virtual AccessArray* as_AccessArray() { return NULL; }
524 virtual ArrayLength* as_ArrayLength() { return NULL; }
525 virtual AccessIndexed* as_AccessIndexed() { return NULL; }
526 virtual LoadIndexed* as_LoadIndexed() { return NULL; }
527 virtual StoreIndexed* as_StoreIndexed() { return NULL; }
528 virtual NegateOp* as_NegateOp() { return NULL; }
529 virtual Op2* as_Op2() { return NULL; }
530 virtual ArithmeticOp* as_ArithmeticOp() { return NULL; }
531 virtual ShiftOp* as_ShiftOp() { return NULL; }
532 virtual LogicOp* as_LogicOp() { return NULL; }
533 virtual CompareOp* as_CompareOp() { return NULL; }
534 virtual IfOp* as_IfOp() { return NULL; }
535 virtual Convert* as_Convert() { return NULL; }
536 virtual NullCheck* as_NullCheck() { return NULL; }
537 virtual OsrEntry* as_OsrEntry() { return NULL; }
538 virtual StateSplit* as_StateSplit() { return NULL; }
539 virtual Invoke* as_Invoke() { return NULL; }
540 virtual NewInstance* as_NewInstance() { return NULL; }
541 virtual NewArray* as_NewArray() { return NULL; }
542 virtual NewTypeArray* as_NewTypeArray() { return NULL; }
543 virtual NewObjectArray* as_NewObjectArray() { return NULL; }
544 virtual NewMultiArray* as_NewMultiArray() { return NULL; }
545 virtual TypeCheck* as_TypeCheck() { return NULL; }
546 virtual CheckCast* as_CheckCast() { return NULL; }
547 virtual InstanceOf* as_InstanceOf() { return NULL; }
548 virtual TypeCast* as_TypeCast() { return NULL; }
549 virtual AccessMonitor* as_AccessMonitor() { return NULL; }
550 virtual MonitorEnter* as_MonitorEnter() { return NULL; }
551 virtual MonitorExit* as_MonitorExit() { return NULL; }
552 virtual Intrinsic* as_Intrinsic() { return NULL; }
553 virtual BlockBegin* as_BlockBegin() { return NULL; }
554 virtual BlockEnd* as_BlockEnd() { return NULL; }
555 virtual Goto* as_Goto() { return NULL; }
556 virtual If* as_If() { return NULL; }
557 virtual TableSwitch* as_TableSwitch() { return NULL; }
558 virtual LookupSwitch* as_LookupSwitch() { return NULL; }
559 virtual Return* as_Return() { return NULL; }
560 virtual Throw* as_Throw() { return NULL; }
561 virtual Base* as_Base() { return NULL; }
562 virtual RoundFP* as_RoundFP() { return NULL; }
563 virtual ExceptionObject* as_ExceptionObject() { return NULL; }
564 virtual UnsafeOp* as_UnsafeOp() { return NULL; }
673 }
674
675 bool is_illegal() const {
676 return type()->is_illegal();
677 }
678
679 // generic
680 virtual void input_values_do(ValueVisitor* f) {
681 }
682 };
683
684
685 // A local is a placeholder for an incoming argument to a function call.
686 LEAF(Local, Instruction)
687 private:
688 int _java_index; // the local index within the method to which the local belongs
689 bool _is_receiver; // if local variable holds the receiver: "this" for non-static methods
690 ciType* _declared_type;
691 public:
692 // creation
693 Local(ciType* declared, ValueType* type, int index, bool receiver)
694 : Instruction(type)
695 , _java_index(index)
696 , _is_receiver(receiver)
697 , _declared_type(declared)
698 {
699 NOT_PRODUCT(set_printable_bci(-1));
700 }
701
702 // accessors
703 int java_index() const { return _java_index; }
704 bool is_receiver() const { return _is_receiver; }
705
706 virtual ciType* declared_type() const { return _declared_type; }
707
708 // generic
709 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
710 };
711
712
713 LEAF(Constant, Instruction)
714 public:
715 // creation
716 Constant(ValueType* type):
717 Instruction(type, NULL, /*type_is_constant*/ true)
718 {
800
801 // manipulation
802
803 // Under certain circumstances, if a previous NullCheck instruction
804 // proved the target object non-null, we can eliminate the explicit
805 // null check and do an implicit one, simply specifying the debug
806 // information from the NullCheck. This field should only be consulted
807 // if needs_null_check() is true.
808 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
809
810 // generic
811 virtual bool can_trap() const { return needs_null_check() || needs_patching(); }
812 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
813 };
814
815
816 LEAF(LoadField, AccessField)
817 public:
818 // creation
819 LoadField(Value obj, int offset, ciField* field, bool is_static,
820 ValueStack* state_before, bool needs_patching)
821 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
822 {}
823
824 ciType* declared_type() const;
825
826 // generic; cannot be eliminated if needs patching or if volatile.
827 HASHING3(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset(), declared_type())
828 };
829
830
831 LEAF(StoreField, AccessField)
832 private:
833 Value _value;
834
835 public:
836 // creation
837 StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
838 ValueStack* state_before, bool needs_patching)
839 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
840 , _value(value)
841 {
842 set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
843 ASSERT_VALUES
844 pin();
845 }
846
847 // accessors
848 Value value() const { return _value; }
849 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
850
851 // generic
852 virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); }
853 };
854
855
856 BASE(AccessArray, Instruction)
857 private:
858 Value _array;
859
860 public:
861 // creation
862 AccessArray(ValueType* type, Value array, ValueStack* state_before)
863 : Instruction(type, state_before)
864 , _array(array)
865 {
866 set_needs_null_check(true);
867 ASSERT_VALUES
868 pin(); // instruction with side effect (null exception or range check throwing)
869 }
887 , _explicit_null_check(NULL) {}
888
889 // accessors
890 NullCheck* explicit_null_check() const { return _explicit_null_check; }
891
892 // setters
893 // See LoadField::set_explicit_null_check for documentation
894 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
895
896 // generic
897 HASHING1(ArrayLength, true, array()->subst())
898 };
899
900
901 BASE(AccessIndexed, AccessArray)
902 private:
903 Value _index;
904 Value _length;
905 BasicType _elt_type;
906 bool _mismatched;
907
908 public:
909 // creation
910 AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched)
911 : AccessArray(as_ValueType(elt_type), array, state_before)
912 , _index(index)
913 , _length(length)
914 , _elt_type(elt_type)
915 , _mismatched(mismatched)
916 {
917 set_flag(Instruction::NeedsRangeCheckFlag, true);
918 ASSERT_VALUES
919 }
920
921 // accessors
922 Value index() const { return _index; }
923 Value length() const { return _length; }
924 BasicType elt_type() const { return _elt_type; }
925 bool mismatched() const { return _mismatched; }
926
927 void clear_length() { _length = NULL; }
928 // perform elimination of range checks involving constants
929 bool compute_needs_range_check();
930
931 // generic
932 virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }
933 };
934
935
936 LEAF(LoadIndexed, AccessIndexed)
937 private:
938 NullCheck* _explicit_null_check; // For explicit null check elimination
939
940 public:
941 // creation
942 LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched = false)
943 : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
944 , _explicit_null_check(NULL) {}
945
946 // accessors
947 NullCheck* explicit_null_check() const { return _explicit_null_check; }
948
949 // setters
950 // See LoadField::set_explicit_null_check for documentation
951 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
952
953 ciType* exact_type() const;
954 ciType* declared_type() const;
955
956 // generic;
957 HASHING3(LoadIndexed, true, type()->tag(), array()->subst(), index()->subst())
958 };
959
960
961 LEAF(StoreIndexed, AccessIndexed)
962 private:
963 Value _value;
964
965 ciMethod* _profiled_method;
966 int _profiled_bci;
967 bool _check_boolean;
968
969 public:
970 // creation
971 StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before,
972 bool check_boolean, bool mismatched = false)
973 : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
974 , _value(value), _profiled_method(NULL), _profiled_bci(0), _check_boolean(check_boolean)
975 {
976 set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
977 set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
978 ASSERT_VALUES
979 pin();
980 }
981
982 // accessors
983 Value value() const { return _value; }
984 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
985 bool needs_store_check() const { return check_flag(NeedsStoreCheckFlag); }
986 bool check_boolean() const { return _check_boolean; }
987 // Helpers for MethodData* profiling
988 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
989 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
990 void set_profiled_bci(int bci) { _profiled_bci = bci; }
991 bool should_profile() const { return check_flag(ProfileMDOFlag); }
992 ciMethod* profiled_method() const { return _profiled_method; }
993 int profiled_bci() const { return _profiled_bci; }
994 // generic
995 virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); }
996 };
997
998
999 LEAF(NegateOp, Instruction)
1000 private:
1001 Value _x;
1002
1003 public:
1004 // creation
1005 NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
1006 ASSERT_VALUES
1007 }
1008
1009 // accessors
1010 Value x() const { return _x; }
1011
1012 // generic
1013 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); }
1084 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1085 };
1086
1087
1088 LEAF(CompareOp, Op2)
1089 public:
1090 // creation
1091 CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1092 : Op2(intType, op, x, y, state_before)
1093 {}
1094
1095 // generic
1096 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1097 };
1098
1099
1100 LEAF(IfOp, Op2)
1101 private:
1102 Value _tval;
1103 Value _fval;
1104
1105 public:
1106 // creation
1107 IfOp(Value x, Condition cond, Value y, Value tval, Value fval)
1108 : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1109 , _tval(tval)
1110 , _fval(fval)
1111 {
1112 ASSERT_VALUES
1113 assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1114 }
1115
1116 // accessors
1117 virtual bool is_commutative() const;
1118 Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }
1119 Condition cond() const { return (Condition)Op2::op(); }
1120 Value tval() const { return _tval; }
1121 Value fval() const { return _fval; }
1122
1123 // generic
1124 virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1125 };
1126
1127
1128 LEAF(Convert, Instruction)
1129 private:
1130 Bytecodes::Code _op;
1131 Value _value;
1132
1133 public:
1134 // creation
1135 Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1136 ASSERT_VALUES
1137 }
1138
1139 // accessors
1140 Bytecodes::Code op() const { return _op; }
1141 Value value() const { return _value; }
1142
1221 // manipulation
1222 void set_state(ValueStack* state) { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }
1223
1224 // generic
1225 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
1226 virtual void state_values_do(ValueVisitor* f);
1227 };
1228
1229
1230 LEAF(Invoke, StateSplit)
1231 private:
1232 Bytecodes::Code _code;
1233 Value _recv;
1234 Values* _args;
1235 BasicTypeList* _signature;
1236 ciMethod* _target;
1237
1238 public:
1239 // creation
1240 Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1241 ciMethod* target, ValueStack* state_before);
1242
1243 // accessors
1244 Bytecodes::Code code() const { return _code; }
1245 Value receiver() const { return _recv; }
1246 bool has_receiver() const { return receiver() != NULL; }
1247 int number_of_arguments() const { return _args->length(); }
1248 Value argument_at(int i) const { return _args->at(i); }
1249 BasicTypeList* signature() const { return _signature; }
1250 ciMethod* target() const { return _target; }
1251
1252 ciType* declared_type() const;
1253
1254 // Returns false if target is not loaded
1255 bool target_is_final() const { return check_flag(TargetIsFinalFlag); }
1256 bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }
1257
1258 // JSR 292 support
1259 bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }
1260 bool is_method_handle_intrinsic() const { return target()->is_method_handle_intrinsic(); }
1261
1279
1280 public:
1281 // creation
1282 NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved)
1283 : StateSplit(instanceType, state_before)
1284 , _klass(klass), _is_unresolved(is_unresolved)
1285 {}
1286
1287 // accessors
1288 ciInstanceKlass* klass() const { return _klass; }
1289 bool is_unresolved() const { return _is_unresolved; }
1290
1291 virtual bool needs_exception_state() const { return false; }
1292
1293 // generic
1294 virtual bool can_trap() const { return true; }
1295 ciType* exact_type() const;
1296 ciType* declared_type() const;
1297 };
1298
1299
1300 BASE(NewArray, StateSplit)
1301 private:
1302 Value _length;
1303
1304 public:
1305 // creation
1306 NewArray(Value length, ValueStack* state_before)
1307 : StateSplit(objectType, state_before)
1308 , _length(length)
1309 {
1310 // Do not ASSERT_VALUES since length is NULL for NewMultiArray
1311 }
1312
1313 // accessors
1314 Value length() const { return _length; }
1315
1316 virtual bool needs_exception_state() const { return false; }
1317
1318 ciType* exact_type() const { return NULL; }
1330
1331 public:
1332 // creation
1333 NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)
1334 : NewArray(length, state_before)
1335 , _elt_type(elt_type)
1336 {}
1337
1338 // accessors
1339 BasicType elt_type() const { return _elt_type; }
1340 ciType* exact_type() const;
1341 };
1342
1343
1344 LEAF(NewObjectArray, NewArray)
1345 private:
1346 ciKlass* _klass;
1347
1348 public:
1349 // creation
1350 NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}
1351
1352 // accessors
1353 ciKlass* klass() const { return _klass; }
1354 ciType* exact_type() const;
1355 };
1356
1357
1358 LEAF(NewMultiArray, NewArray)
1359 private:
1360 ciKlass* _klass;
1361 Values* _dims;
1362
1363 public:
1364 // creation
1365 NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
1366 ASSERT_VALUES
1367 }
1368
1369 // accessors
1370 ciKlass* klass() const { return _klass; }
1371 Values* dims() const { return _dims; }
1372 int rank() const { return dims()->length(); }
1373
1374 // generic
1375 virtual void input_values_do(ValueVisitor* f) {
1376 // NOTE: we do not call NewArray::input_values_do since "length"
1377 // is meaningless for a multi-dimensional array; passing the
1378 // zeroth element down to NewArray as its length is a bad idea
1379 // since there will be a copy in the "dims" array which doesn't
1380 // get updated, and the value must not be traversed twice. Was bug
1381 // - kbr 4/10/2001
1382 StateSplit::input_values_do(f);
1383 for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1384 }
1385 };
1386
1387
1388 BASE(TypeCheck, StateSplit)
1389 private:
1390 ciKlass* _klass;
1391 Value _obj;
1392
1393 ciMethod* _profiled_method;
1394 int _profiled_bci;
1395
1396 public:
1397 // creation
1398 TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1399 : StateSplit(type, state_before), _klass(klass), _obj(obj),
1400 _profiled_method(NULL), _profiled_bci(0) {
1401 ASSERT_VALUES
1402 set_direct_compare(false);
1403 }
1404
1405 // accessors
1406 ciKlass* klass() const { return _klass; }
1411 // manipulation
1412 void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }
1413
1414 // generic
1415 virtual bool can_trap() const { return true; }
1416 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1417
1418 // Helpers for MethodData* profiling
1419 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1420 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1421 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1422 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1423 ciMethod* profiled_method() const { return _profiled_method; }
1424 int profiled_bci() const { return _profiled_bci; }
1425 };
1426
1427
1428 LEAF(CheckCast, TypeCheck)
1429 public:
1430 // creation
1431 CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1432 : TypeCheck(klass, obj, objectType, state_before) {}
1433
1434 void set_incompatible_class_change_check() {
1435 set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1436 }
1437 bool is_incompatible_class_change_check() const {
1438 return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1439 }
1440 void set_invokespecial_receiver_check() {
1441 set_flag(InvokeSpecialReceiverCheckFlag, true);
1442 }
1443 bool is_invokespecial_receiver_check() const {
1444 return check_flag(InvokeSpecialReceiverCheckFlag);
1445 }
1446
1447 virtual bool needs_exception_state() const {
1448 return !is_invokespecial_receiver_check();
1449 }
1450
1451 ciType* declared_type() const;
1452 };
1470 // creation
1471 AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)
1472 : StateSplit(illegalType, state_before)
1473 , _obj(obj)
1474 , _monitor_no(monitor_no)
1475 {
1476 set_needs_null_check(true);
1477 ASSERT_VALUES
1478 }
1479
1480 // accessors
1481 Value obj() const { return _obj; }
1482 int monitor_no() const { return _monitor_no; }
1483
1484 // generic
1485 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1486 };
1487
1488
1489 LEAF(MonitorEnter, AccessMonitor)
1490 public:
1491 // creation
1492 MonitorEnter(Value obj, int monitor_no, ValueStack* state_before)
1493 : AccessMonitor(obj, monitor_no, state_before)
1494 {
1495 ASSERT_VALUES
1496 }
1497
1498 // generic
1499 virtual bool can_trap() const { return true; }
1500 };
1501
1502
1503 LEAF(MonitorExit, AccessMonitor)
1504 public:
1505 // creation
1506 MonitorExit(Value obj, int monitor_no)
1507 : AccessMonitor(obj, monitor_no, NULL)
1508 {
1509 ASSERT_VALUES
1510 }
1511 };
1512
1513
1514 LEAF(Intrinsic, StateSplit)
1515 private:
1516 vmIntrinsics::ID _id;
1517 Values* _args;
1937 Condition cond() const { return _cond; }
1938 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
1939 Value y() const { return _y; }
1940
1941 void always_fail() { _x = _y = NULL; }
1942
1943 // generic
1944 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }
1945 HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())
1946 };
1947
1948 LEAF(If, BlockEnd)
1949 private:
1950 Value _x;
1951 Condition _cond;
1952 Value _y;
1953 ciMethod* _profiled_method;
1954 int _profiled_bci; // Canonicalizer may alter bci of If node
1955 bool _swapped; // Is the order reversed with respect to the original If in the
1956 // bytecode stream?
1957 public:
1958 // creation
1959 // unordered_is_true is valid for float/double compares only
1960 If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)
1961 : BlockEnd(illegalType, state_before, is_safepoint)
1962 , _x(x)
1963 , _cond(cond)
1964 , _y(y)
1965 , _profiled_method(NULL)
1966 , _profiled_bci(0)
1967 , _swapped(false)
1968 {
1969 ASSERT_VALUES
1970 set_flag(UnorderedIsTrueFlag, unordered_is_true);
1971 assert(x->type()->tag() == y->type()->tag(), "types must match");
1972 BlockList* s = new BlockList(2);
1973 s->append(tsux);
1974 s->append(fsux);
1975 set_sux(s);
1976 }
1977
1978 // accessors
1979 Value x() const { return _x; }
1980 Condition cond() const { return _cond; }
1981 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
1982 Value y() const { return _y; }
1983 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
1984 BlockBegin* tsux() const { return sux_for(true); }
1985 BlockBegin* fsux() const { return sux_for(false); }
1986 BlockBegin* usux() const { return sux_for(unordered_is_true()); }
1987 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1988 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
1989 int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered
1990 bool is_swapped() const { return _swapped; }
1991
1992 // manipulation
1993 void swap_operands() {
1994 Value t = _x; _x = _y; _y = t;
1995 _cond = mirror(_cond);
1996 }
1997
1998 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1999 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
2000 void set_profiled_bci(int bci) { _profiled_bci = bci; }
2001 void set_swapped(bool value) { _swapped = value; }
2002 // generic
2003 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2004 };
2005
2006
2007 BASE(Switch, BlockEnd)
2008 private:
2009 Value _tag;
2010
2011 public:
2012 // creation
2013 Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
2014 : BlockEnd(illegalType, state_before, is_safepoint)
2015 , _tag(tag) {
2016 ASSERT_VALUES
2017 set_sux(sux);
2018 }
2019
2020 // accessors
2021 Value tag() const { return _tag; }
2316 }
2317 }
2318 };
2319
2320 LEAF(ProfileReturnType, Instruction)
2321 private:
2322 ciMethod* _method;
2323 ciMethod* _callee;
2324 int _bci_of_invoke;
2325 Value _ret;
2326
2327 public:
2328 ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)
2329 : Instruction(voidType)
2330 , _method(method)
2331 , _callee(callee)
2332 , _bci_of_invoke(bci)
2333 , _ret(ret)
2334 {
2335 set_needs_null_check(true);
2336 // The ProfileType has side-effects and must occur precisely where located
2337 pin();
2338 }
2339
2340 ciMethod* method() const { return _method; }
2341 ciMethod* callee() const { return _callee; }
2342 int bci_of_invoke() const { return _bci_of_invoke; }
2343 Value ret() const { return _ret; }
2344
2345 virtual void input_values_do(ValueVisitor* f) {
2346 if (_ret != NULL) {
2347 f->visit(&_ret);
2348 }
2349 }
2350 };
2351
2352 // Call some C runtime function that doesn't safepoint,
2353 // optionally passing the current thread as the first argument.
2354 LEAF(RuntimeCall, Instruction)
2355 private:
2356 const char* _entry_name;
2357 address _entry;
2358 Values* _args;
2359 bool _pass_thread; // Pass the JavaThread* as an implicit first argument
2360
2361 public:
2362 RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2363 : Instruction(type)
2364 , _entry_name(entry_name)
2365 , _entry(entry)
2366 , _args(args)
2367 , _pass_thread(pass_thread) {
2368 ASSERT_VALUES
2369 pin();
2370 }
2371
|
53 class AccessArray;
54 class ArrayLength;
55 class AccessIndexed;
56 class LoadIndexed;
57 class StoreIndexed;
58 class NegateOp;
59 class Op2;
60 class ArithmeticOp;
61 class ShiftOp;
62 class LogicOp;
63 class CompareOp;
64 class IfOp;
65 class Convert;
66 class NullCheck;
67 class TypeCast;
68 class OsrEntry;
69 class ExceptionObject;
70 class StateSplit;
71 class Invoke;
72 class NewInstance;
73 class NewInlineTypeInstance;
74 class NewArray;
75 class NewTypeArray;
76 class NewObjectArray;
77 class NewMultiArray;
78 class Deoptimize;
79 class TypeCheck;
80 class CheckCast;
81 class InstanceOf;
82 class AccessMonitor;
83 class MonitorEnter;
84 class MonitorExit;
85 class Intrinsic;
86 class BlockBegin;
87 class BlockEnd;
88 class Goto;
89 class If;
90 class Switch;
91 class TableSwitch;
92 class LookupSwitch;
93 class Return;
94 class Throw;
95 class Base;
96 class RoundFP;
97 class UnsafeOp;
98 class UnsafeGet;
99 class UnsafePut;
100 class UnsafeGetAndSet;
101 class ProfileCall;
102 class ProfileReturnType;
103 class ProfileACmpTypes;
104 class ProfileInvoke;
105 class RuntimeCall;
106 class MemBar;
107 class RangeCheckPredicate;
108 #ifdef ASSERT
109 class Assert;
110 #endif
111
112 // A Value is a reference to the instruction creating the value
113 typedef Instruction* Value;
114 typedef GrowableArray<Value> Values;
115 typedef GrowableArray<ValueStack*> ValueStackStack;
116
117 // BlockClosure is the base class for block traversal/iteration.
118
119 class BlockClosure: public CompilationResourceObj {
120 public:
121 virtual void block_do(BlockBegin* block) = 0;
122 };
123
155 public:
156 virtual void do_Phi (Phi* x) = 0;
157 virtual void do_Local (Local* x) = 0;
158 virtual void do_Constant (Constant* x) = 0;
159 virtual void do_LoadField (LoadField* x) = 0;
160 virtual void do_StoreField (StoreField* x) = 0;
161 virtual void do_ArrayLength (ArrayLength* x) = 0;
162 virtual void do_LoadIndexed (LoadIndexed* x) = 0;
163 virtual void do_StoreIndexed (StoreIndexed* x) = 0;
164 virtual void do_NegateOp (NegateOp* x) = 0;
165 virtual void do_ArithmeticOp (ArithmeticOp* x) = 0;
166 virtual void do_ShiftOp (ShiftOp* x) = 0;
167 virtual void do_LogicOp (LogicOp* x) = 0;
168 virtual void do_CompareOp (CompareOp* x) = 0;
169 virtual void do_IfOp (IfOp* x) = 0;
170 virtual void do_Convert (Convert* x) = 0;
171 virtual void do_NullCheck (NullCheck* x) = 0;
172 virtual void do_TypeCast (TypeCast* x) = 0;
173 virtual void do_Invoke (Invoke* x) = 0;
174 virtual void do_NewInstance (NewInstance* x) = 0;
175 virtual void do_NewInlineTypeInstance(NewInlineTypeInstance* x) = 0;
176 virtual void do_NewTypeArray (NewTypeArray* x) = 0;
177 virtual void do_NewObjectArray (NewObjectArray* x) = 0;
178 virtual void do_NewMultiArray (NewMultiArray* x) = 0;
179 virtual void do_Deoptimize (Deoptimize* x) = 0;
180 virtual void do_CheckCast (CheckCast* x) = 0;
181 virtual void do_InstanceOf (InstanceOf* x) = 0;
182 virtual void do_MonitorEnter (MonitorEnter* x) = 0;
183 virtual void do_MonitorExit (MonitorExit* x) = 0;
184 virtual void do_Intrinsic (Intrinsic* x) = 0;
185 virtual void do_BlockBegin (BlockBegin* x) = 0;
186 virtual void do_Goto (Goto* x) = 0;
187 virtual void do_If (If* x) = 0;
188 virtual void do_TableSwitch (TableSwitch* x) = 0;
189 virtual void do_LookupSwitch (LookupSwitch* x) = 0;
190 virtual void do_Return (Return* x) = 0;
191 virtual void do_Throw (Throw* x) = 0;
192 virtual void do_Base (Base* x) = 0;
193 virtual void do_OsrEntry (OsrEntry* x) = 0;
194 virtual void do_ExceptionObject(ExceptionObject* x) = 0;
195 virtual void do_RoundFP (RoundFP* x) = 0;
196 virtual void do_UnsafeGet (UnsafeGet* x) = 0;
197 virtual void do_UnsafePut (UnsafePut* x) = 0;
198 virtual void do_UnsafeGetAndSet(UnsafeGetAndSet* x) = 0;
199 virtual void do_ProfileCall (ProfileCall* x) = 0;
200 virtual void do_ProfileReturnType (ProfileReturnType* x) = 0;
201 virtual void do_ProfileACmpTypes(ProfileACmpTypes* x) = 0;
202 virtual void do_ProfileInvoke (ProfileInvoke* x) = 0;
203 virtual void do_RuntimeCall (RuntimeCall* x) = 0;
204 virtual void do_MemBar (MemBar* x) = 0;
205 virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0;
206 #ifdef ASSERT
207 virtual void do_Assert (Assert* x) = 0;
208 #endif
209 };
210
211
212 // Hashing support
213 //
214 // Note: This hash functions affect the performance
215 // of ValueMap - make changes carefully!
216
217 #define HASH1(x1 ) ((intx)(x1))
218 #define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2))
219 #define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3))
220 #define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3 ) << 7) ^ HASH1(x4))
221 #define HASH5(x1, x2, x3, x4, x5) ((HASH4(x1, x2, x3, x4) << 7) ^ HASH1(x5))
222
223
224 // The following macros are used to implement instruction-specific hashing.
225 // By default, each instruction implements hash() and is_equal(Value), used
226 // for value numbering/common subexpression elimination. The default imple-
227 // mentation disables value numbering. Each instruction which can be value-
228 // numbered, should define corresponding hash() and is_equal(Value) functions
229 // via the macros below. The f arguments specify all the values/op codes, etc.
230 // that need to be identical for two instructions to be identical.
231 //
232 // Note: The default implementation of hash() returns 0 in order to indicate
233 // that the instruction should not be considered for value numbering.
234 // The currently used hash functions do not guarantee that never a 0
235 // is produced. While this is still correct, it may be a performance
236 // bug (no value numbering for that node). However, this situation is
237 // so unlikely, that we are not going to handle it specially.
238
239 #define HASHING1(class_name, enabled, f1) \
240 virtual intx hash() const { \
241 return (enabled) ? HASH2(name(), f1) : 0; \
260 if (f1 != _v->f1) return false; \
261 if (f2 != _v->f2) return false; \
262 return true; \
263 } \
264
265
266 #define HASHING3(class_name, enabled, f1, f2, f3) \
267 virtual intx hash() const { \
268 return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
269 } \
270 virtual bool is_equal(Value v) const { \
271 if (!(enabled) ) return false; \
272 class_name* _v = v->as_##class_name(); \
273 if (_v == NULL ) return false; \
274 if (f1 != _v->f1) return false; \
275 if (f2 != _v->f2) return false; \
276 if (f3 != _v->f3) return false; \
277 return true; \
278 } \
279
280 #define HASHING4(class_name, enabled, f1, f2, f3, f4) \
281 virtual intx hash() const { \
282 return (enabled) ? HASH5(name(), f1, f2, f3, f4) : 0; \
283 } \
284 virtual bool is_equal(Value v) const { \
285 if (!(enabled) ) return false; \
286 class_name* _v = v->as_##class_name(); \
287 if (_v == NULL ) return false; \
288 if (f1 != _v->f1) return false; \
289 if (f2 != _v->f2) return false; \
290 if (f3 != _v->f3) return false; \
291 if (f4 != _v->f4) return false; \
292 return true; \
293 } \
294
295
296 // The mother of all instructions...
297
298 class Instruction: public CompilationResourceObj {
299 private:
300 int _id; // the unique instruction id
301 #ifndef PRODUCT
302 int _printable_bci; // the bci of the instruction for printing
303 #endif
304 int _use_count; // the number of instructions referring to this value (w/o prev/next); only roots can have use count = 0 or > 1
305 int _pin_state; // set of PinReason describing the reason for pinning
306 ValueType* _type; // the instruction value type
307 Instruction* _next; // the next instruction if any (NULL for BlockEnd instructions)
308 Instruction* _subst; // the substitution instruction if any
309 LIR_Opr _operand; // LIR specific information
310 unsigned int _flags; // Flag bits
311
312 ValueStack* _state_before; // Copy of state with input operands still on stack (or NULL)
313 ValueStack* _exception_state; // Copy of state for exception handling
314 XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction
315
316 friend class UseCountComputer;
317 friend class GraphBuilder;
318
319 void update_exception_state(ValueStack* state);
320
321 protected:
322 BlockBegin* _block; // Block that contains this instruction
323
324 void set_type(ValueType* type) {
325 assert(type != NULL, "type must exist");
326 _type = type;
327 }
328
329 // Helper class to keep track of which arguments need a null check
330 class ArgsNonNullState {
331 private:
332 int _nonnull_state; // mask identifying which args are nonnull
333 public:
334 ArgsNonNullState()
335 : _nonnull_state(AllBits) {}
336
337 // Does argument number i needs a null check?
350 if (check) {
351 _nonnull_state |= nth_bit(i);
352 } else {
353 _nonnull_state &= ~(nth_bit(i));
354 }
355 }
356 }
357 };
358
359 public:
360 void* operator new(size_t size) throw() {
361 Compilation* c = Compilation::current();
362 void* res = c->arena()->Amalloc(size);
363 return res;
364 }
365
366 static const int no_bci = -99;
367
368 enum InstructionFlag {
369 NeedsNullCheckFlag = 0,
370 NeverNullFlag, // For "Q" signatures
371 CanTrapFlag,
372 DirectCompareFlag,
373 IsEliminatedFlag,
374 IsSafepointFlag,
375 IsStaticFlag,
376 NeedsStoreCheckFlag,
377 NeedsWriteBarrierFlag,
378 PreservesStateFlag,
379 TargetIsFinalFlag,
380 TargetIsLoadedFlag,
381 UnorderedIsTrueFlag,
382 NeedsPatchingFlag,
383 ThrowIncompatibleClassChangeErrorFlag,
384 InvokeSpecialReceiverCheckFlag,
385 ProfileMDOFlag,
386 IsLinkedInBlockFlag,
387 NeedsRangeCheckFlag,
388 InWorkListFlag,
389 DeoptimizeOnException,
390 KillsMemoryFlag,
444 int id() const { return _id; }
445 #ifndef PRODUCT
446 bool has_printable_bci() const { return _printable_bci != -99; }
447 int printable_bci() const { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
448 void set_printable_bci(int bci) { _printable_bci = bci; }
449 #endif
450 int dominator_depth();
451 int use_count() const { return _use_count; }
452 int pin_state() const { return _pin_state; }
453 bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; }
454 ValueType* type() const { return _type; }
455 BlockBegin *block() const { return _block; }
456 Instruction* prev(); // use carefully, expensive operation
457 Instruction* next() const { return _next; }
458 bool has_subst() const { return _subst != NULL; }
459 Instruction* subst() { return _subst == NULL ? this : _subst->subst(); }
460 LIR_Opr operand() const { return _operand; }
461
462 void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); }
463 bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); }
464 void set_null_free(bool f) { set_flag(NeverNullFlag, f); }
465 bool is_null_free() const { return check_flag(NeverNullFlag); }
466 bool is_linked() const { return check_flag(IsLinkedInBlockFlag); }
467 bool can_be_linked() { return as_Local() == NULL && as_Phi() == NULL; }
468
469 bool is_null_obj() { return as_Constant() != NULL && type()->as_ObjectType()->constant_value()->is_null_object(); }
470
471 bool has_uses() const { return use_count() > 0; }
472 ValueStack* state_before() const { return _state_before; }
473 ValueStack* exception_state() const { return _exception_state; }
474 virtual bool needs_exception_state() const { return true; }
475 XHandlers* exception_handlers() const { return _exception_handlers; }
476 ciKlass* as_loaded_klass_or_null() const;
477
478 // manipulation
479 void pin(PinReason reason) { _pin_state |= reason; }
480 void pin() { _pin_state |= PinUnknown; }
481 // DANGEROUS: only used by EliminateStores
482 void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
483
484 Instruction* set_next(Instruction* next) {
485 assert(next->has_printable_bci(), "_printable_bci should have been set");
486 assert(next != NULL, "must not be NULL");
487 assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");
488 assert(next->can_be_linked(), "shouldn't link these instructions into list");
489
490 BlockBegin *block = this->block();
491 next->_block = block;
492
493 next->set_flag(Instruction::IsLinkedInBlockFlag, true);
494 _next = next;
495 return next;
496 }
501 #endif
502 return set_next(next);
503 }
504
505 // when blocks are merged
506 void fixup_block_pointers() {
507 Instruction *cur = next()->next(); // next()'s block is set in set_next
508 while (cur && cur->_block != block()) {
509 cur->_block = block();
510 cur = cur->next();
511 }
512 }
513
514 Instruction *insert_after(Instruction *i) {
515 Instruction* n = _next;
516 set_next(i);
517 i->set_next(n);
518 return _next;
519 }
520
521 bool is_loaded_flattened_array() const;
522 bool maybe_flattened_array();
523 bool maybe_null_free_array();
524
525 Instruction *insert_after_same_bci(Instruction *i) {
526 #ifndef PRODUCT
527 i->set_printable_bci(printable_bci());
528 #endif
529 return insert_after(i);
530 }
531
532 void set_subst(Instruction* subst) {
533 assert(subst == NULL ||
534 type()->base() == subst->type()->base() ||
535 subst->type()->base() == illegalType, "type can't change");
536 _subst = subst;
537 }
538 void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
539 void set_exception_state(ValueStack* s) { check_state(s); _exception_state = s; }
540 void set_state_before(ValueStack* s) { check_state(s); _state_before = s; }
541
542 // machine-specifics
543 void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
544 void clear_operand() { _operand = LIR_OprFact::illegalOpr; }
552 virtual LoadField* as_LoadField() { return NULL; }
553 virtual StoreField* as_StoreField() { return NULL; }
554 virtual AccessArray* as_AccessArray() { return NULL; }
555 virtual ArrayLength* as_ArrayLength() { return NULL; }
556 virtual AccessIndexed* as_AccessIndexed() { return NULL; }
557 virtual LoadIndexed* as_LoadIndexed() { return NULL; }
558 virtual StoreIndexed* as_StoreIndexed() { return NULL; }
559 virtual NegateOp* as_NegateOp() { return NULL; }
560 virtual Op2* as_Op2() { return NULL; }
561 virtual ArithmeticOp* as_ArithmeticOp() { return NULL; }
562 virtual ShiftOp* as_ShiftOp() { return NULL; }
563 virtual LogicOp* as_LogicOp() { return NULL; }
564 virtual CompareOp* as_CompareOp() { return NULL; }
565 virtual IfOp* as_IfOp() { return NULL; }
566 virtual Convert* as_Convert() { return NULL; }
567 virtual NullCheck* as_NullCheck() { return NULL; }
568 virtual OsrEntry* as_OsrEntry() { return NULL; }
569 virtual StateSplit* as_StateSplit() { return NULL; }
570 virtual Invoke* as_Invoke() { return NULL; }
571 virtual NewInstance* as_NewInstance() { return NULL; }
572 virtual NewInlineTypeInstance* as_NewInlineTypeInstance() { return NULL; }
573 virtual NewArray* as_NewArray() { return NULL; }
574 virtual NewTypeArray* as_NewTypeArray() { return NULL; }
575 virtual NewObjectArray* as_NewObjectArray() { return NULL; }
576 virtual NewMultiArray* as_NewMultiArray() { return NULL; }
577 virtual Deoptimize* as_Deoptimize() { return NULL; }
578 virtual TypeCheck* as_TypeCheck() { return NULL; }
579 virtual CheckCast* as_CheckCast() { return NULL; }
580 virtual InstanceOf* as_InstanceOf() { return NULL; }
581 virtual TypeCast* as_TypeCast() { return NULL; }
582 virtual AccessMonitor* as_AccessMonitor() { return NULL; }
583 virtual MonitorEnter* as_MonitorEnter() { return NULL; }
584 virtual MonitorExit* as_MonitorExit() { return NULL; }
585 virtual Intrinsic* as_Intrinsic() { return NULL; }
586 virtual BlockBegin* as_BlockBegin() { return NULL; }
587 virtual BlockEnd* as_BlockEnd() { return NULL; }
588 virtual Goto* as_Goto() { return NULL; }
589 virtual If* as_If() { return NULL; }
590 virtual TableSwitch* as_TableSwitch() { return NULL; }
591 virtual LookupSwitch* as_LookupSwitch() { return NULL; }
592 virtual Return* as_Return() { return NULL; }
593 virtual Throw* as_Throw() { return NULL; }
594 virtual Base* as_Base() { return NULL; }
595 virtual RoundFP* as_RoundFP() { return NULL; }
596 virtual ExceptionObject* as_ExceptionObject() { return NULL; }
597 virtual UnsafeOp* as_UnsafeOp() { return NULL; }
706 }
707
708 bool is_illegal() const {
709 return type()->is_illegal();
710 }
711
712 // generic
713 virtual void input_values_do(ValueVisitor* f) {
714 }
715 };
716
717
718 // A local is a placeholder for an incoming argument to a function call.
719 LEAF(Local, Instruction)
720 private:
721 int _java_index; // the local index within the method to which the local belongs
722 bool _is_receiver; // if local variable holds the receiver: "this" for non-static methods
723 ciType* _declared_type;
724 public:
725 // creation
726 Local(ciType* declared, ValueType* type, int index, bool receiver, bool null_free)
727 : Instruction(type)
728 , _java_index(index)
729 , _is_receiver(receiver)
730 , _declared_type(declared)
731 {
732 set_null_free(null_free);
733 NOT_PRODUCT(set_printable_bci(-1));
734 }
735
736 // accessors
737 int java_index() const { return _java_index; }
738 bool is_receiver() const { return _is_receiver; }
739
740 virtual ciType* declared_type() const { return _declared_type; }
741
742 // generic
743 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
744 };
745
746
747 LEAF(Constant, Instruction)
748 public:
749 // creation
750 Constant(ValueType* type):
751 Instruction(type, NULL, /*type_is_constant*/ true)
752 {
834
835 // manipulation
836
837 // Under certain circumstances, if a previous NullCheck instruction
838 // proved the target object non-null, we can eliminate the explicit
839 // null check and do an implicit one, simply specifying the debug
840 // information from the NullCheck. This field should only be consulted
841 // if needs_null_check() is true.
842 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
843
844 // generic
845 virtual bool can_trap() const { return needs_null_check() || needs_patching(); }
846 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
847 };
848
849
850 LEAF(LoadField, AccessField)
851 public:
852 // creation
853 LoadField(Value obj, int offset, ciField* field, bool is_static,
854 ValueStack* state_before, bool needs_patching,
855 ciInlineKlass* inline_klass = NULL, Value default_value = NULL )
856 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
857 {
858 set_null_free(field->is_null_free());
859 }
860
861 ciType* declared_type() const;
862
863 // generic; cannot be eliminated if needs patching or if volatile.
864 HASHING3(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset(), declared_type())
865 };
866
867
868 LEAF(StoreField, AccessField)
869 private:
870 Value _value;
871 ciField* _enclosing_field; // enclosing field (the flattened one) for nested fields
872
873 public:
874 // creation
875 StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
876 ValueStack* state_before, bool needs_patching);
877
878 // accessors
879 Value value() const { return _value; }
880 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
881 ciField* enclosing_field() const { return _enclosing_field; }
882 void set_enclosing_field(ciField* field) { _enclosing_field = field; }
883
884 // generic
885 virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); }
886 };
887
888
889 BASE(AccessArray, Instruction)
890 private:
891 Value _array;
892
893 public:
894 // creation
895 AccessArray(ValueType* type, Value array, ValueStack* state_before)
896 : Instruction(type, state_before)
897 , _array(array)
898 {
899 set_needs_null_check(true);
900 ASSERT_VALUES
901 pin(); // instruction with side effect (null exception or range check throwing)
902 }
920 , _explicit_null_check(NULL) {}
921
922 // accessors
923 NullCheck* explicit_null_check() const { return _explicit_null_check; }
924
925 // setters
926 // See LoadField::set_explicit_null_check for documentation
927 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
928
929 // generic
930 HASHING1(ArrayLength, true, array()->subst())
931 };
932
933
934 BASE(AccessIndexed, AccessArray)
935 private:
936 Value _index;
937 Value _length;
938 BasicType _elt_type;
939 bool _mismatched;
940 ciMethod* _profiled_method;
941 int _profiled_bci;
942
943 public:
944 // creation
945 AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched)
946 : AccessArray(as_ValueType(elt_type), array, state_before)
947 , _index(index)
948 , _length(length)
949 , _elt_type(elt_type)
950 , _mismatched(mismatched)
951 , _profiled_method(NULL), _profiled_bci(0)
952 {
953 set_flag(Instruction::NeedsRangeCheckFlag, true);
954 ASSERT_VALUES
955 }
956
957 // accessors
958 Value index() const { return _index; }
959 Value length() const { return _length; }
960 BasicType elt_type() const { return _elt_type; }
961 bool mismatched() const { return _mismatched; }
962
963 void clear_length() { _length = NULL; }
964 // perform elimination of range checks involving constants
965 bool compute_needs_range_check();
966
967 // Helpers for MethodData* profiling
968 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
969 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
970 void set_profiled_bci(int bci) { _profiled_bci = bci; }
971 bool should_profile() const { return check_flag(ProfileMDOFlag); }
972 ciMethod* profiled_method() const { return _profiled_method; }
973 int profiled_bci() const { return _profiled_bci; }
974
975
976 // generic
977 virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }
978 };
979
980 class DelayedLoadIndexed;
981
982 LEAF(LoadIndexed, AccessIndexed)
983 private:
984 NullCheck* _explicit_null_check; // For explicit null check elimination
985 NewInlineTypeInstance* _vt;
986 DelayedLoadIndexed* _delayed;
987
988 public:
989 // creation
990 LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched = false)
991 : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
992 , _explicit_null_check(NULL), _vt(NULL), _delayed(NULL) {}
993
994 // accessors
995 NullCheck* explicit_null_check() const { return _explicit_null_check; }
996
997 // setters
998 // See LoadField::set_explicit_null_check for documentation
999 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
1000
1001 ciType* exact_type() const;
1002 ciType* declared_type() const;
1003
1004 NewInlineTypeInstance* vt() const { return _vt; }
1005 void set_vt(NewInlineTypeInstance* vt) { _vt = vt; }
1006
1007 DelayedLoadIndexed* delayed() const { return _delayed; }
1008 void set_delayed(DelayedLoadIndexed* delayed) { _delayed = delayed; }
1009
1010 // generic
1011 HASHING4(LoadIndexed, delayed() == NULL && !should_profile(), type()->tag(), array()->subst(), index()->subst(), vt())
1012 };
1013
1014 class DelayedLoadIndexed : public CompilationResourceObj {
1015 private:
1016 LoadIndexed* _load_instr;
1017 ValueStack* _state_before;
1018 ciField* _field;
1019 int _offset;
1020 public:
1021 DelayedLoadIndexed(LoadIndexed* load, ValueStack* state_before)
1022 : _load_instr(load)
1023 , _state_before(state_before)
1024 , _field(NULL)
1025 , _offset(0) { }
1026
1027 void update(ciField* field, int offset) {
1028 _field = field;
1029 _offset += offset;
1030 }
1031
1032 LoadIndexed* load_instr() const { return _load_instr; }
1033 ValueStack* state_before() const { return _state_before; }
1034 ciField* field() const { return _field; }
1035 int offset() const { return _offset; }
1036 };
1037
1038 LEAF(StoreIndexed, AccessIndexed)
1039 private:
1040 Value _value;
1041
1042 bool _check_boolean;
1043
1044 public:
1045 // creation
1046 StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before,
1047 bool check_boolean, bool mismatched = false);
1048
1049 // accessors
1050 Value value() const { return _value; }
1051 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
1052 bool needs_store_check() const { return check_flag(NeedsStoreCheckFlag); }
1053 bool check_boolean() const { return _check_boolean; }
1054
1055 // Flattened array support
1056 bool is_exact_flattened_array_store() const;
1057 // generic
1058 virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); }
1059 };
1060
1061
1062 LEAF(NegateOp, Instruction)
1063 private:
1064 Value _x;
1065
1066 public:
1067 // creation
1068 NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
1069 ASSERT_VALUES
1070 }
1071
1072 // accessors
1073 Value x() const { return _x; }
1074
1075 // generic
1076 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); }
1147 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1148 };
1149
1150
1151 LEAF(CompareOp, Op2)
1152 public:
1153 // creation
1154 CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1155 : Op2(intType, op, x, y, state_before)
1156 {}
1157
1158 // generic
1159 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1160 };
1161
1162
1163 LEAF(IfOp, Op2)
1164 private:
1165 Value _tval;
1166 Value _fval;
1167 bool _substitutability_check;
1168
1169 public:
1170 // creation
1171 IfOp(Value x, Condition cond, Value y, Value tval, Value fval, ValueStack* state_before, bool substitutability_check)
1172 : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1173 , _tval(tval)
1174 , _fval(fval)
1175 , _substitutability_check(substitutability_check)
1176 {
1177 ASSERT_VALUES
1178 assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1179 set_state_before(state_before);
1180 }
1181
1182 // accessors
1183 virtual bool is_commutative() const;
1184 Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }
1185 Condition cond() const { return (Condition)Op2::op(); }
1186 Value tval() const { return _tval; }
1187 Value fval() const { return _fval; }
1188 bool substitutability_check() const { return _substitutability_check; }
1189 // generic
1190 virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1191 };
1192
1193
1194 LEAF(Convert, Instruction)
1195 private:
1196 Bytecodes::Code _op;
1197 Value _value;
1198
1199 public:
1200 // creation
1201 Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1202 ASSERT_VALUES
1203 }
1204
1205 // accessors
1206 Bytecodes::Code op() const { return _op; }
1207 Value value() const { return _value; }
1208
1287 // manipulation
1288 void set_state(ValueStack* state) { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }
1289
1290 // generic
1291 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
1292 virtual void state_values_do(ValueVisitor* f);
1293 };
1294
1295
1296 LEAF(Invoke, StateSplit)
1297 private:
1298 Bytecodes::Code _code;
1299 Value _recv;
1300 Values* _args;
1301 BasicTypeList* _signature;
1302 ciMethod* _target;
1303
1304 public:
1305 // creation
1306 Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1307 ciMethod* target, ValueStack* state_before, bool null_free);
1308
1309 // accessors
1310 Bytecodes::Code code() const { return _code; }
1311 Value receiver() const { return _recv; }
1312 bool has_receiver() const { return receiver() != NULL; }
1313 int number_of_arguments() const { return _args->length(); }
1314 Value argument_at(int i) const { return _args->at(i); }
1315 BasicTypeList* signature() const { return _signature; }
1316 ciMethod* target() const { return _target; }
1317
1318 ciType* declared_type() const;
1319
1320 // Returns false if target is not loaded
1321 bool target_is_final() const { return check_flag(TargetIsFinalFlag); }
1322 bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }
1323
1324 // JSR 292 support
1325 bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }
1326 bool is_method_handle_intrinsic() const { return target()->is_method_handle_intrinsic(); }
1327
1345
1346 public:
1347 // creation
1348 NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved)
1349 : StateSplit(instanceType, state_before)
1350 , _klass(klass), _is_unresolved(is_unresolved)
1351 {}
1352
1353 // accessors
1354 ciInstanceKlass* klass() const { return _klass; }
1355 bool is_unresolved() const { return _is_unresolved; }
1356
1357 virtual bool needs_exception_state() const { return false; }
1358
1359 // generic
1360 virtual bool can_trap() const { return true; }
1361 ciType* exact_type() const;
1362 ciType* declared_type() const;
1363 };
1364
1365 LEAF(NewInlineTypeInstance, StateSplit)
1366 ciInlineKlass* _klass;
1367 bool _in_larval_state;
1368 int _first_local_index;
1369 int _on_stack_count;
1370 public:
1371
1372 // Default creation, always allocated for now
1373 NewInlineTypeInstance(ciInlineKlass* klass, ValueStack* state_before)
1374 : StateSplit(instanceType, state_before)
1375 , _klass(klass)
1376 , _in_larval_state(true)
1377 , _first_local_index(-1)
1378 , _on_stack_count(1)
1379 {
1380 set_null_free(true);
1381 }
1382
1383 // accessors
1384 ciInlineKlass* klass() const { return _klass; }
1385 virtual bool needs_exception_state() const { return false; }
1386
1387 // generic
1388 virtual bool can_trap() const { return true; }
1389 ciType* exact_type() const;
1390 ciType* declared_type() const;
1391
1392 // Only done in LIR Generator -> map everything to object
1393 void set_to_object_type() { set_type(instanceType); }
1394
1395 void set_local_index(int index) {
1396 decrement_on_stack_count();
1397 if (_first_local_index != index) {
1398 if (_first_local_index == -1) {
1399 _first_local_index = index;
1400 } else {
1401 set_not_larva_anymore();
1402 }
1403 }
1404 }
1405
1406 bool in_larval_state() const { return _in_larval_state; }
1407 void set_not_larva_anymore() { _in_larval_state = false; }
1408
1409 int on_stack_count() const { return _on_stack_count; }
1410 void increment_on_stack_count() { _on_stack_count++; }
1411 void decrement_on_stack_count() { _on_stack_count--; }
1412 };
1413
1414 BASE(NewArray, StateSplit)
1415 private:
1416 Value _length;
1417
1418 public:
1419 // creation
1420 NewArray(Value length, ValueStack* state_before)
1421 : StateSplit(objectType, state_before)
1422 , _length(length)
1423 {
1424 // Do not ASSERT_VALUES since length is NULL for NewMultiArray
1425 }
1426
1427 // accessors
1428 Value length() const { return _length; }
1429
1430 virtual bool needs_exception_state() const { return false; }
1431
1432 ciType* exact_type() const { return NULL; }
1444
1445 public:
1446 // creation
1447 NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)
1448 : NewArray(length, state_before)
1449 , _elt_type(elt_type)
1450 {}
1451
1452 // accessors
1453 BasicType elt_type() const { return _elt_type; }
1454 ciType* exact_type() const;
1455 };
1456
1457
1458 LEAF(NewObjectArray, NewArray)
1459 private:
1460 ciKlass* _klass;
1461
1462 public:
1463 // creation
1464 NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before, bool null_free)
1465 : NewArray(length, state_before), _klass(klass) {
1466 set_null_free(null_free);
1467 }
1468
1469 // accessors
1470 ciKlass* klass() const { return _klass; }
1471 ciType* exact_type() const;
1472 };
1473
1474
1475 LEAF(NewMultiArray, NewArray)
1476 private:
1477 ciKlass* _klass;
1478 Values* _dims;
1479
1480 public:
1481 // creation
1482 NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
1483 ASSERT_VALUES
1484 }
1485
1486 // accessors
1487 ciKlass* klass() const { return _klass; }
1488 Values* dims() const { return _dims; }
1489 int rank() const { return dims()->length(); }
1490
1491 // generic
1492 virtual void input_values_do(ValueVisitor* f) {
1493 // NOTE: we do not call NewArray::input_values_do since "length"
1494 // is meaningless for a multi-dimensional array; passing the
1495 // zeroth element down to NewArray as its length is a bad idea
1496 // since there will be a copy in the "dims" array which doesn't
1497 // get updated, and the value must not be traversed twice. Was bug
1498 // - kbr 4/10/2001
1499 StateSplit::input_values_do(f);
1500 for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1501 }
1502
1503 ciType* exact_type() const;
1504 };
1505
1506 LEAF(Deoptimize, StateSplit)
1507 private:
1508 ciKlass* _klass;
1509
1510 public:
1511 Deoptimize(ciKlass* klass, ValueStack* state_before)
1512 : StateSplit(objectType, state_before), _klass(klass) {}
1513
1514 // accessors
1515 ciKlass* klass() const { return _klass; }
1516 };
1517
1518 BASE(TypeCheck, StateSplit)
1519 private:
1520 ciKlass* _klass;
1521 Value _obj;
1522
1523 ciMethod* _profiled_method;
1524 int _profiled_bci;
1525
1526 public:
1527 // creation
1528 TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1529 : StateSplit(type, state_before), _klass(klass), _obj(obj),
1530 _profiled_method(NULL), _profiled_bci(0) {
1531 ASSERT_VALUES
1532 set_direct_compare(false);
1533 }
1534
1535 // accessors
1536 ciKlass* klass() const { return _klass; }
1541 // manipulation
1542 void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }
1543
1544 // generic
1545 virtual bool can_trap() const { return true; }
1546 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1547
1548 // Helpers for MethodData* profiling
1549 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1550 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1551 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1552 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1553 ciMethod* profiled_method() const { return _profiled_method; }
1554 int profiled_bci() const { return _profiled_bci; }
1555 };
1556
1557
1558 LEAF(CheckCast, TypeCheck)
1559 public:
1560 // creation
1561 CheckCast(ciKlass* klass, Value obj, ValueStack* state_before, bool null_free = false)
1562 : TypeCheck(klass, obj, objectType, state_before) {
1563 set_null_free(null_free);
1564 }
1565
1566 void set_incompatible_class_change_check() {
1567 set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1568 }
1569 bool is_incompatible_class_change_check() const {
1570 return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1571 }
1572 void set_invokespecial_receiver_check() {
1573 set_flag(InvokeSpecialReceiverCheckFlag, true);
1574 }
1575 bool is_invokespecial_receiver_check() const {
1576 return check_flag(InvokeSpecialReceiverCheckFlag);
1577 }
1578
1579 virtual bool needs_exception_state() const {
1580 return !is_invokespecial_receiver_check();
1581 }
1582
1583 ciType* declared_type() const;
1584 };
1602 // creation
1603 AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)
1604 : StateSplit(illegalType, state_before)
1605 , _obj(obj)
1606 , _monitor_no(monitor_no)
1607 {
1608 set_needs_null_check(true);
1609 ASSERT_VALUES
1610 }
1611
1612 // accessors
1613 Value obj() const { return _obj; }
1614 int monitor_no() const { return _monitor_no; }
1615
1616 // generic
1617 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1618 };
1619
1620
1621 LEAF(MonitorEnter, AccessMonitor)
1622 bool _maybe_inlinetype;
1623 public:
1624 // creation
1625 MonitorEnter(Value obj, int monitor_no, ValueStack* state_before, bool maybe_inlinetype)
1626 : AccessMonitor(obj, monitor_no, state_before)
1627 , _maybe_inlinetype(maybe_inlinetype)
1628 {
1629 ASSERT_VALUES
1630 }
1631
1632 // accessors
1633 bool maybe_inlinetype() const { return _maybe_inlinetype; }
1634
1635 // generic
1636 virtual bool can_trap() const { return true; }
1637 };
1638
1639
1640 LEAF(MonitorExit, AccessMonitor)
1641 public:
1642 // creation
1643 MonitorExit(Value obj, int monitor_no)
1644 : AccessMonitor(obj, monitor_no, NULL)
1645 {
1646 ASSERT_VALUES
1647 }
1648 };
1649
1650
1651 LEAF(Intrinsic, StateSplit)
1652 private:
1653 vmIntrinsics::ID _id;
1654 Values* _args;
2074 Condition cond() const { return _cond; }
2075 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
2076 Value y() const { return _y; }
2077
2078 void always_fail() { _x = _y = NULL; }
2079
2080 // generic
2081 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2082 HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())
2083 };
2084
2085 LEAF(If, BlockEnd)
2086 private:
2087 Value _x;
2088 Condition _cond;
2089 Value _y;
2090 ciMethod* _profiled_method;
2091 int _profiled_bci; // Canonicalizer may alter bci of If node
2092 bool _swapped; // Is the order reversed with respect to the original If in the
2093 // bytecode stream?
2094 bool _substitutability_check;
2095 public:
2096 // creation
2097 // unordered_is_true is valid for float/double compares only
2098 If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint, bool substitutability_check=false)
2099 : BlockEnd(illegalType, state_before, is_safepoint)
2100 , _x(x)
2101 , _cond(cond)
2102 , _y(y)
2103 , _profiled_method(NULL)
2104 , _profiled_bci(0)
2105 , _swapped(false)
2106 , _substitutability_check(substitutability_check)
2107 {
2108 ASSERT_VALUES
2109 set_flag(UnorderedIsTrueFlag, unordered_is_true);
2110 assert(x->type()->tag() == y->type()->tag(), "types must match");
2111 BlockList* s = new BlockList(2);
2112 s->append(tsux);
2113 s->append(fsux);
2114 set_sux(s);
2115 if (!_substitutability_check) {
2116 assert(x->as_NewInlineTypeInstance() == NULL || y->type() == objectNull, "Sanity check");
2117 assert(y->as_NewInlineTypeInstance() == NULL || x->type() == objectNull, "Sanity check");
2118 }
2119 }
2120
2121 // accessors
2122 Value x() const { return _x; }
2123 Condition cond() const { return _cond; }
2124 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
2125 Value y() const { return _y; }
2126 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
2127 BlockBegin* tsux() const { return sux_for(true); }
2128 BlockBegin* fsux() const { return sux_for(false); }
2129 BlockBegin* usux() const { return sux_for(unordered_is_true()); }
2130 bool should_profile() const { return check_flag(ProfileMDOFlag); }
2131 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
2132 int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered
2133 bool is_swapped() const { return _swapped; }
2134
2135 // manipulation
2136 void swap_operands() {
2137 Value t = _x; _x = _y; _y = t;
2138 _cond = mirror(_cond);
2139 }
2140
2141 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
2142 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
2143 void set_profiled_bci(int bci) { _profiled_bci = bci; }
2144 void set_swapped(bool value) { _swapped = value; }
2145 bool substitutability_check() const { return _substitutability_check; }
2146 // generic
2147 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2148 };
2149
2150
2151 BASE(Switch, BlockEnd)
2152 private:
2153 Value _tag;
2154
2155 public:
2156 // creation
2157 Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
2158 : BlockEnd(illegalType, state_before, is_safepoint)
2159 , _tag(tag) {
2160 ASSERT_VALUES
2161 set_sux(sux);
2162 }
2163
2164 // accessors
2165 Value tag() const { return _tag; }
2460 }
2461 }
2462 };
2463
2464 LEAF(ProfileReturnType, Instruction)
2465 private:
2466 ciMethod* _method;
2467 ciMethod* _callee;
2468 int _bci_of_invoke;
2469 Value _ret;
2470
2471 public:
2472 ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)
2473 : Instruction(voidType)
2474 , _method(method)
2475 , _callee(callee)
2476 , _bci_of_invoke(bci)
2477 , _ret(ret)
2478 {
2479 set_needs_null_check(true);
2480 // The ProfileReturnType has side-effects and must occur precisely where located
2481 pin();
2482 }
2483
2484 ciMethod* method() const { return _method; }
2485 ciMethod* callee() const { return _callee; }
2486 int bci_of_invoke() const { return _bci_of_invoke; }
2487 Value ret() const { return _ret; }
2488
2489 virtual void input_values_do(ValueVisitor* f) {
2490 if (_ret != NULL) {
2491 f->visit(&_ret);
2492 }
2493 }
2494 };
2495
2496 LEAF(ProfileACmpTypes, Instruction)
2497 private:
2498 ciMethod* _method;
2499 int _bci;
2500 Value _left;
2501 Value _right;
2502 bool _left_maybe_null;
2503 bool _right_maybe_null;
2504
2505 public:
2506 ProfileACmpTypes(ciMethod* method, int bci, Value left, Value right)
2507 : Instruction(voidType)
2508 , _method(method)
2509 , _bci(bci)
2510 , _left(left)
2511 , _right(right)
2512 {
2513 // The ProfileACmp has side-effects and must occur precisely where located
2514 pin();
2515 _left_maybe_null = true;
2516 _right_maybe_null = true;
2517 }
2518
2519 ciMethod* method() const { return _method; }
2520 int bci() const { return _bci; }
2521 Value left() const { return _left; }
2522 Value right() const { return _right; }
2523 bool left_maybe_null() const { return _left_maybe_null; }
2524 bool right_maybe_null() const { return _right_maybe_null; }
2525 void set_left_maybe_null(bool v) { _left_maybe_null = v; }
2526 void set_right_maybe_null(bool v) { _right_maybe_null = v; }
2527
2528 virtual void input_values_do(ValueVisitor* f) {
2529 if (_left != NULL) {
2530 f->visit(&_left);
2531 }
2532 if (_right != NULL) {
2533 f->visit(&_right);
2534 }
2535 }
2536 };
2537
2538 // Call some C runtime function that doesn't safepoint,
2539 // optionally passing the current thread as the first argument.
2540 LEAF(RuntimeCall, Instruction)
2541 private:
2542 const char* _entry_name;
2543 address _entry;
2544 Values* _args;
2545 bool _pass_thread; // Pass the JavaThread* as an implicit first argument
2546
2547 public:
2548 RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2549 : Instruction(type)
2550 , _entry_name(entry_name)
2551 , _entry(entry)
2552 , _args(args)
2553 , _pass_thread(pass_thread) {
2554 ASSERT_VALUES
2555 pin();
2556 }
2557
|