1 /*
2 * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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 UnsafeOp;
95 class UnsafeGet;
96 class UnsafePut;
97 class UnsafeGetAndSet;
98 class ProfileCall;
99 class ProfileReturnType;
100 class ProfileInvoke;
101 class RuntimeCall;
102 class MemBar;
103 class RangeCheckPredicate;
104 #ifdef ASSERT
105 class Assert;
106 #endif
107
108 // A Value is a reference to the instruction creating the value
109 typedef Instruction* Value;
110 typedef GrowableArray<Value> Values;
111 typedef GrowableArray<ValueStack*> ValueStackStack;
112
113 // BlockClosure is the base class for block traversal/iteration.
114
115 class BlockClosure: public CompilationResourceObj {
116 public:
117 virtual void block_do(BlockBegin* block) = 0;
118 };
119
174 virtual void do_CheckCast (CheckCast* x) = 0;
175 virtual void do_InstanceOf (InstanceOf* x) = 0;
176 virtual void do_MonitorEnter (MonitorEnter* x) = 0;
177 virtual void do_MonitorExit (MonitorExit* x) = 0;
178 virtual void do_Intrinsic (Intrinsic* x) = 0;
179 virtual void do_BlockBegin (BlockBegin* x) = 0;
180 virtual void do_Goto (Goto* x) = 0;
181 virtual void do_If (If* x) = 0;
182 virtual void do_TableSwitch (TableSwitch* x) = 0;
183 virtual void do_LookupSwitch (LookupSwitch* x) = 0;
184 virtual void do_Return (Return* x) = 0;
185 virtual void do_Throw (Throw* x) = 0;
186 virtual void do_Base (Base* x) = 0;
187 virtual void do_OsrEntry (OsrEntry* x) = 0;
188 virtual void do_ExceptionObject(ExceptionObject* x) = 0;
189 virtual void do_UnsafeGet (UnsafeGet* x) = 0;
190 virtual void do_UnsafePut (UnsafePut* x) = 0;
191 virtual void do_UnsafeGetAndSet(UnsafeGetAndSet* x) = 0;
192 virtual void do_ProfileCall (ProfileCall* x) = 0;
193 virtual void do_ProfileReturnType (ProfileReturnType* x) = 0;
194 virtual void do_ProfileInvoke (ProfileInvoke* x) = 0;
195 virtual void do_RuntimeCall (RuntimeCall* x) = 0;
196 virtual void do_MemBar (MemBar* x) = 0;
197 virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0;
198 #ifdef ASSERT
199 virtual void do_Assert (Assert* x) = 0;
200 #endif
201 };
202
203
204 // Hashing support
205 //
206 // Note: This hash functions affect the performance
207 // of ValueMap - make changes carefully!
208
209 #define HASH1(x1 ) ((intx)(x1))
210 #define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2))
211 #define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3))
212 #define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))
213
214
215 // The following macros are used to implement instruction-specific hashing.
216 // By default, each instruction implements hash() and is_equal(Value), used
217 // for value numbering/common subexpression elimination. The default imple-
218 // mentation disables value numbering. Each instruction which can be value-
219 // numbered, should define corresponding hash() and is_equal(Value) functions
220 // via the macros below. The f arguments specify all the values/op codes, etc.
221 // that need to be identical for two instructions to be identical.
222 //
223 // Note: The default implementation of hash() returns 0 in order to indicate
224 // that the instruction should not be considered for value numbering.
225 // The currently used hash functions do not guarantee that never a 0
226 // is produced. While this is still correct, it may be a performance
227 // bug (no value numbering for that node). However, this situation is
228 // so unlikely, that we are not going to handle it specially.
229
230 #define HASHING1(class_name, enabled, f1) \
231 virtual intx hash() const { \
232 return (enabled) ? HASH2(name(), f1) : 0; \
251 if (f1 != _v->f1) return false; \
252 if (f2 != _v->f2) return false; \
253 return true; \
254 } \
255
256
257 #define HASHING3(class_name, enabled, f1, f2, f3) \
258 virtual intx hash() const { \
259 return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
260 } \
261 virtual bool is_equal(Value v) const { \
262 if (!(enabled) ) return false; \
263 class_name* _v = v->as_##class_name(); \
264 if (_v == nullptr) return false; \
265 if (f1 != _v->f1) return false; \
266 if (f2 != _v->f2) return false; \
267 if (f3 != _v->f3) return false; \
268 return true; \
269 } \
270
271
272 // The mother of all instructions...
273
274 class Instruction: public CompilationResourceObj {
275 private:
276 int _id; // the unique instruction id
277 #ifndef PRODUCT
278 int _printable_bci; // the bci of the instruction for printing
279 #endif
280 int _use_count; // the number of instructions referring to this value (w/o prev/next); only roots can have use count = 0 or > 1
281 int _pin_state; // set of PinReason describing the reason for pinning
282 unsigned int _flags; // Flag bits
283 ValueType* _type; // the instruction value type
284 Instruction* _next; // the next instruction if any (null for BlockEnd instructions)
285 Instruction* _subst; // the substitution instruction if any
286 LIR_Opr _operand; // LIR specific information
287
288 ValueStack* _state_before; // Copy of state with input operands still on stack (or null)
289 ValueStack* _exception_state; // Copy of state for exception handling
290 XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction
291
292 friend class UseCountComputer;
293
294 void update_exception_state(ValueStack* state);
295
296 protected:
297 BlockBegin* _block; // Block that contains this instruction
298
299 void set_type(ValueType* type) {
300 assert(type != nullptr, "type must exist");
301 _type = type;
302 }
303
304 // Helper class to keep track of which arguments need a null check
305 class ArgsNonNullState {
306 private:
307 int _nonnull_state; // mask identifying which args are nonnull
308 public:
309 ArgsNonNullState()
310 : _nonnull_state(AllBits) {}
311
312 // Does argument number i needs a null check?
325 if (check) {
326 _nonnull_state |= (int)nth_bit(i);
327 } else {
328 _nonnull_state &= (int)~(nth_bit(i));
329 }
330 }
331 }
332 };
333
334 public:
335 void* operator new(size_t size) throw() {
336 Compilation* c = Compilation::current();
337 void* res = c->arena()->Amalloc(size);
338 return res;
339 }
340
341 static const int no_bci = -99;
342
343 enum InstructionFlag {
344 NeedsNullCheckFlag = 0,
345 CanTrapFlag,
346 DirectCompareFlag,
347 IsSafepointFlag,
348 IsStaticFlag,
349 PreservesStateFlag,
350 TargetIsFinalFlag,
351 TargetIsLoadedFlag,
352 UnorderedIsTrueFlag,
353 NeedsPatchingFlag,
354 ThrowIncompatibleClassChangeErrorFlag,
355 InvokeSpecialReceiverCheckFlag,
356 ProfileMDOFlag,
357 IsLinkedInBlockFlag,
358 NeedsRangeCheckFlag,
359 DeoptimizeOnException,
360 KillsMemoryFlag,
361 OmitChecksFlag,
362 InstructionLastFlag
363 };
364
415 int id() const { return _id; }
416 #ifndef PRODUCT
417 bool has_printable_bci() const { return _printable_bci != -99; }
418 int printable_bci() const { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
419 void set_printable_bci(int bci) { _printable_bci = bci; }
420 #endif
421 int dominator_depth();
422 int use_count() const { return _use_count; }
423 int pin_state() const { return _pin_state; }
424 bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; }
425 ValueType* type() const { return _type; }
426 BlockBegin *block() const { return _block; }
427 Instruction* prev(); // use carefully, expensive operation
428 Instruction* next() const { return _next; }
429 bool has_subst() const { return _subst != nullptr; }
430 Instruction* subst() { return _subst == nullptr ? this : _subst->subst(); }
431 LIR_Opr operand() const { return _operand; }
432
433 void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); }
434 bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); }
435 bool is_linked() const { return check_flag(IsLinkedInBlockFlag); }
436 bool can_be_linked() { return as_Local() == nullptr && as_Phi() == nullptr; }
437
438 bool is_null_obj() { return as_Constant() != nullptr && type()->as_ObjectType()->constant_value()->is_null_object(); }
439
440 bool has_uses() const { return use_count() > 0; }
441 ValueStack* state_before() const { return _state_before; }
442 ValueStack* exception_state() const { return _exception_state; }
443 virtual bool needs_exception_state() const { return true; }
444 XHandlers* exception_handlers() const { return _exception_handlers; }
445
446 // manipulation
447 void pin(PinReason reason) { _pin_state |= reason; }
448 void pin() { _pin_state |= PinUnknown; }
449 // DANGEROUS: only used by EliminateStores
450 void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
451
452 Instruction* set_next(Instruction* next) {
453 assert(next->has_printable_bci(), "_printable_bci should have been set");
454 assert(next != nullptr, "must not be null");
455 assert(as_BlockEnd() == nullptr, "BlockEnd instructions must have no next");
456 assert(next->can_be_linked(), "shouldn't link these instructions into list");
457
458 BlockBegin *block = this->block();
459 next->_block = block;
460
461 next->set_flag(Instruction::IsLinkedInBlockFlag, true);
462 _next = next;
463 return next;
464 }
469 #endif
470 return set_next(next);
471 }
472
473 // when blocks are merged
474 void fixup_block_pointers() {
475 Instruction *cur = next()->next(); // next()'s block is set in set_next
476 while (cur && cur->_block != block()) {
477 cur->_block = block();
478 cur = cur->next();
479 }
480 }
481
482 Instruction *insert_after(Instruction *i) {
483 Instruction* n = _next;
484 set_next(i);
485 i->set_next(n);
486 return _next;
487 }
488
489 Instruction *insert_after_same_bci(Instruction *i) {
490 #ifndef PRODUCT
491 i->set_printable_bci(printable_bci());
492 #endif
493 return insert_after(i);
494 }
495
496 void set_subst(Instruction* subst) {
497 assert(subst == nullptr ||
498 type()->base() == subst->type()->base() ||
499 subst->type()->base() == illegalType, "type can't change");
500 _subst = subst;
501 }
502 void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
503 void set_exception_state(ValueStack* s) { check_state(s); _exception_state = s; }
504 void set_state_before(ValueStack* s) { check_state(s); _state_before = s; }
505
506 // machine-specifics
507 void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
508 void clear_operand() { _operand = LIR_OprFact::illegalOpr; }
796
797 // Under certain circumstances, if a previous NullCheck instruction
798 // proved the target object non-null, we can eliminate the explicit
799 // null check and do an implicit one, simply specifying the debug
800 // information from the NullCheck. This field should only be consulted
801 // if needs_null_check() is true.
802 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
803
804 // generic
805 virtual bool can_trap() const { return needs_null_check() || needs_patching(); }
806 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
807 };
808
809
810 LEAF(LoadField, AccessField)
811 public:
812 // creation
813 LoadField(Value obj, int offset, ciField* field, bool is_static,
814 ValueStack* state_before, bool needs_patching)
815 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
816 {}
817
818 ciType* declared_type() const;
819
820 // generic; cannot be eliminated if needs patching or if volatile.
821 HASHING3(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset(), declared_type())
822 };
823
824
825 LEAF(StoreField, AccessField)
826 private:
827 Value _value;
828
829 public:
830 // creation
831 StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
832 ValueStack* state_before, bool needs_patching)
833 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
834 , _value(value)
835 {
836 ASSERT_VALUES
837 pin();
838 }
839
840 // accessors
841 Value value() const { return _value; }
842
843 // generic
844 virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); }
845 };
846
847
848 BASE(AccessArray, Instruction)
849 private:
850 Value _array;
851
852 public:
853 // creation
854 AccessArray(ValueType* type, Value array, ValueStack* state_before)
855 : Instruction(type, state_before)
856 , _array(array)
857 {
858 set_needs_null_check(true);
859 ASSERT_VALUES
860 pin(); // instruction with side effect (null exception or range check throwing)
861 }
879 , _explicit_null_check(nullptr) {}
880
881 // accessors
882 NullCheck* explicit_null_check() const { return _explicit_null_check; }
883
884 // setters
885 // See LoadField::set_explicit_null_check for documentation
886 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
887
888 // generic
889 HASHING1(ArrayLength, true, array()->subst())
890 };
891
892
893 BASE(AccessIndexed, AccessArray)
894 private:
895 Value _index;
896 Value _length;
897 BasicType _elt_type;
898 bool _mismatched;
899
900 public:
901 // creation
902 AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched)
903 : AccessArray(as_ValueType(elt_type), array, state_before)
904 , _index(index)
905 , _length(length)
906 , _elt_type(elt_type)
907 , _mismatched(mismatched)
908 {
909 set_flag(Instruction::NeedsRangeCheckFlag, true);
910 ASSERT_VALUES
911 }
912
913 // accessors
914 Value index() const { return _index; }
915 Value length() const { return _length; }
916 BasicType elt_type() const { return _elt_type; }
917 bool mismatched() const { return _mismatched; }
918
919 void clear_length() { _length = nullptr; }
920 // perform elimination of range checks involving constants
921 bool compute_needs_range_check();
922
923 // generic
924 virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != nullptr) f->visit(&_length); }
925 };
926
927
928 LEAF(LoadIndexed, AccessIndexed)
929 private:
930 NullCheck* _explicit_null_check; // For explicit null check elimination
931
932 public:
933 // creation
934 LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched = false)
935 : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
936 , _explicit_null_check(nullptr) {}
937
938 // accessors
939 NullCheck* explicit_null_check() const { return _explicit_null_check; }
940
941 // setters
942 // See LoadField::set_explicit_null_check for documentation
943 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
944
945 ciType* exact_type() const;
946 ciType* declared_type() const;
947
948 // generic;
949 HASHING3(LoadIndexed, true, elt_type(), array()->subst(), index()->subst())
950 };
951
952
953 LEAF(StoreIndexed, AccessIndexed)
954 private:
955 Value _value;
956
957 ciMethod* _profiled_method;
958 int _profiled_bci;
959 bool _check_boolean;
960
961 public:
962 // creation
963 StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before,
964 bool check_boolean, bool mismatched = false)
965 : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
966 , _value(value), _profiled_method(nullptr), _profiled_bci(0), _check_boolean(check_boolean)
967 {
968 ASSERT_VALUES
969 pin();
970 }
971
972 // accessors
973 Value value() const { return _value; }
974 bool check_boolean() const { return _check_boolean; }
975 // Helpers for MethodData* profiling
976 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
977 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
978 void set_profiled_bci(int bci) { _profiled_bci = bci; }
979 bool should_profile() const { return check_flag(ProfileMDOFlag); }
980 ciMethod* profiled_method() const { return _profiled_method; }
981 int profiled_bci() const { return _profiled_bci; }
982 // generic
983 virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); }
984 };
985
986
987 LEAF(NegateOp, Instruction)
988 private:
989 Value _x;
990
991 public:
992 // creation
993 NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
994 ASSERT_VALUES
995 }
996
997 // accessors
998 Value x() const { return _x; }
999
1000 // generic
1001 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); }
1072 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1073 };
1074
1075
1076 LEAF(CompareOp, Op2)
1077 public:
1078 // creation
1079 CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1080 : Op2(intType, op, x, y, state_before)
1081 {}
1082
1083 // generic
1084 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1085 };
1086
1087
1088 LEAF(IfOp, Op2)
1089 private:
1090 Value _tval;
1091 Value _fval;
1092
1093 public:
1094 // creation
1095 IfOp(Value x, Condition cond, Value y, Value tval, Value fval)
1096 : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1097 , _tval(tval)
1098 , _fval(fval)
1099 {
1100 ASSERT_VALUES
1101 assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1102 }
1103
1104 // accessors
1105 virtual bool is_commutative() const;
1106 Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }
1107 Condition cond() const { return (Condition)Op2::op(); }
1108 Value tval() const { return _tval; }
1109 Value fval() const { return _fval; }
1110
1111 // generic
1112 virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1113 };
1114
1115
1116 LEAF(Convert, Instruction)
1117 private:
1118 Bytecodes::Code _op;
1119 Value _value;
1120
1121 public:
1122 // creation
1123 Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1124 ASSERT_VALUES
1125 }
1126
1127 // accessors
1128 Bytecodes::Code op() const { return _op; }
1129 Value value() const { return _value; }
1130
1205 // accessors
1206 ValueStack* state() const { return _state; }
1207 IRScope* scope() const; // the state's scope
1208
1209 // manipulation
1210 void set_state(ValueStack* state) { assert(_state == nullptr, "overwriting existing state"); check_state(state); _state = state; }
1211
1212 // generic
1213 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
1214 virtual void state_values_do(ValueVisitor* f);
1215 };
1216
1217
1218 LEAF(Invoke, StateSplit)
1219 private:
1220 Bytecodes::Code _code;
1221 Value _recv;
1222 Values* _args;
1223 BasicTypeList* _signature;
1224 ciMethod* _target;
1225
1226 public:
1227 // creation
1228 Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1229 ciMethod* target, ValueStack* state_before);
1230
1231 // accessors
1232 Bytecodes::Code code() const { return _code; }
1233 Value receiver() const { return _recv; }
1234 bool has_receiver() const { return receiver() != nullptr; }
1235 int number_of_arguments() const { return _args->length(); }
1236 Value argument_at(int i) const { return _args->at(i); }
1237 BasicTypeList* signature() const { return _signature; }
1238 ciMethod* target() const { return _target; }
1239
1240 ciType* declared_type() const;
1241
1242 // Returns false if target is not loaded
1243 bool target_is_final() const { return check_flag(TargetIsFinalFlag); }
1244 bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }
1245
1246 // JSR 292 support
1247 bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }
1248 bool is_method_handle_intrinsic() const { return target()->is_method_handle_intrinsic(); }
1249
1250 virtual bool needs_exception_state() const { return false; }
1251
1252 // generic
1253 virtual bool can_trap() const { return true; }
1254 virtual void input_values_do(ValueVisitor* f) {
1255 StateSplit::input_values_do(f);
1256 if (has_receiver()) f->visit(&_recv);
1257 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1258 }
1259 virtual void state_values_do(ValueVisitor *f);
1260 };
1261
1262
1263 LEAF(NewInstance, StateSplit)
1264 private:
1265 ciInstanceKlass* _klass;
1266 bool _is_unresolved;
1267
1268 public:
1269 // creation
1270 NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved)
1271 : StateSplit(instanceType, state_before)
1272 , _klass(klass), _is_unresolved(is_unresolved)
1273 {}
1274
1275 // accessors
1276 ciInstanceKlass* klass() const { return _klass; }
1277 bool is_unresolved() const { return _is_unresolved; }
1278
1279 virtual bool needs_exception_state() const { return false; }
1280
1281 // generic
1282 virtual bool can_trap() const { return true; }
1283 ciType* exact_type() const;
1284 ciType* declared_type() const;
1285 };
1286
1287
1288 BASE(NewArray, StateSplit)
1289 private:
1290 Value _length;
1291
1292 public:
1293 // creation
1294 NewArray(Value length, ValueStack* state_before)
1295 : StateSplit(objectType, state_before)
1296 , _length(length)
1297 {
1298 // Do not ASSERT_VALUES since length is null for NewMultiArray
1299 }
1300
1301 // accessors
1302 Value length() const { return _length; }
1303
1304 virtual bool needs_exception_state() const { return false; }
1305
1306 ciType* exact_type() const { return nullptr; }
1307 ciType* declared_type() const;
1321 // creation
1322 NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before, bool zero_array)
1323 : NewArray(length, state_before)
1324 , _elt_type(elt_type)
1325 , _zero_array(zero_array)
1326 {}
1327
1328 // accessors
1329 BasicType elt_type() const { return _elt_type; }
1330 bool zero_array() const { return _zero_array; }
1331 ciType* exact_type() const;
1332 };
1333
1334
1335 LEAF(NewObjectArray, NewArray)
1336 private:
1337 ciKlass* _klass;
1338
1339 public:
1340 // creation
1341 NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}
1342
1343 // accessors
1344 ciKlass* klass() const { return _klass; }
1345 ciType* exact_type() const;
1346 };
1347
1348
1349 LEAF(NewMultiArray, NewArray)
1350 private:
1351 ciKlass* _klass;
1352 Values* _dims;
1353
1354 public:
1355 // creation
1356 NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(nullptr, state_before), _klass(klass), _dims(dims) {
1357 ASSERT_VALUES
1358 }
1359
1360 // accessors
1361 ciKlass* klass() const { return _klass; }
1362 Values* dims() const { return _dims; }
1363 int rank() const { return dims()->length(); }
1364
1365 // generic
1366 virtual void input_values_do(ValueVisitor* f) {
1367 // NOTE: we do not call NewArray::input_values_do since "length"
1368 // is meaningless for a multi-dimensional array; passing the
1369 // zeroth element down to NewArray as its length is a bad idea
1370 // since there will be a copy in the "dims" array which doesn't
1371 // get updated, and the value must not be traversed twice. Was bug
1372 // - kbr 4/10/2001
1373 StateSplit::input_values_do(f);
1374 for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1375 }
1376 };
1377
1378
1379 BASE(TypeCheck, StateSplit)
1380 private:
1381 ciKlass* _klass;
1382 Value _obj;
1383
1384 ciMethod* _profiled_method;
1385 int _profiled_bci;
1386
1387 public:
1388 // creation
1389 TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1390 : StateSplit(type, state_before), _klass(klass), _obj(obj),
1391 _profiled_method(nullptr), _profiled_bci(0) {
1392 ASSERT_VALUES
1393 set_direct_compare(false);
1394 }
1395
1403 void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }
1404
1405 // generic
1406 virtual bool can_trap() const { return true; }
1407 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1408
1409 // Helpers for MethodData* profiling
1410 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1411 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1412 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1413 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1414 ciMethod* profiled_method() const { return _profiled_method; }
1415 int profiled_bci() const { return _profiled_bci; }
1416 };
1417
1418
1419 LEAF(CheckCast, TypeCheck)
1420 public:
1421 // creation
1422 CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1423 : TypeCheck(klass, obj, objectType, state_before) {}
1424
1425 void set_incompatible_class_change_check() {
1426 set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1427 }
1428 bool is_incompatible_class_change_check() const {
1429 return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1430 }
1431 void set_invokespecial_receiver_check() {
1432 set_flag(InvokeSpecialReceiverCheckFlag, true);
1433 }
1434 bool is_invokespecial_receiver_check() const {
1435 return check_flag(InvokeSpecialReceiverCheckFlag);
1436 }
1437
1438 virtual bool needs_exception_state() const {
1439 return !is_invokespecial_receiver_check();
1440 }
1441
1442 ciType* declared_type() const;
1443 };
1461 // creation
1462 AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = nullptr)
1463 : StateSplit(illegalType, state_before)
1464 , _obj(obj)
1465 , _monitor_no(monitor_no)
1466 {
1467 set_needs_null_check(true);
1468 ASSERT_VALUES
1469 }
1470
1471 // accessors
1472 Value obj() const { return _obj; }
1473 int monitor_no() const { return _monitor_no; }
1474
1475 // generic
1476 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1477 };
1478
1479
1480 LEAF(MonitorEnter, AccessMonitor)
1481 public:
1482 // creation
1483 MonitorEnter(Value obj, int monitor_no, ValueStack* state_before)
1484 : AccessMonitor(obj, monitor_no, state_before)
1485 {
1486 ASSERT_VALUES
1487 }
1488
1489 // generic
1490 virtual bool can_trap() const { return true; }
1491 };
1492
1493
1494 LEAF(MonitorExit, AccessMonitor)
1495 public:
1496 // creation
1497 MonitorExit(Value obj, int monitor_no)
1498 : AccessMonitor(obj, monitor_no, nullptr)
1499 {
1500 ASSERT_VALUES
1501 }
1502 };
1503
1504
1505 LEAF(Intrinsic, StateSplit)
1506 private:
1507 vmIntrinsics::ID _id;
1508 ArgsNonNullState _nonnull_state;
1924 Condition cond() const { return _cond; }
1925 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
1926 Value y() const { return _y; }
1927
1928 void always_fail() { _x = _y = nullptr; }
1929
1930 // generic
1931 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }
1932 HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())
1933 };
1934
1935 LEAF(If, BlockEnd)
1936 private:
1937 Value _x;
1938 Condition _cond;
1939 Value _y;
1940 ciMethod* _profiled_method;
1941 int _profiled_bci; // Canonicalizer may alter bci of If node
1942 bool _swapped; // Is the order reversed with respect to the original If in the
1943 // bytecode stream?
1944 public:
1945 // creation
1946 // unordered_is_true is valid for float/double compares only
1947 If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)
1948 : BlockEnd(illegalType, state_before, is_safepoint)
1949 , _x(x)
1950 , _cond(cond)
1951 , _y(y)
1952 , _profiled_method(nullptr)
1953 , _profiled_bci(0)
1954 , _swapped(false)
1955 {
1956 ASSERT_VALUES
1957 set_flag(UnorderedIsTrueFlag, unordered_is_true);
1958 assert(x->type()->tag() == y->type()->tag(), "types must match");
1959 BlockList* s = new BlockList(2);
1960 s->append(tsux);
1961 s->append(fsux);
1962 set_sux(s);
1963 }
1964
1965 // accessors
1966 Value x() const { return _x; }
1967 Condition cond() const { return _cond; }
1968 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
1969 Value y() const { return _y; }
1970 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
1971 BlockBegin* tsux() const { return sux_for(true); }
1972 BlockBegin* fsux() const { return sux_for(false); }
1973 BlockBegin* usux() const { return sux_for(unordered_is_true()); }
1974 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1975 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
1976 int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered
1977 bool is_swapped() const { return _swapped; }
1978
1979 // manipulation
1980 void swap_operands() {
1981 Value t = _x; _x = _y; _y = t;
1982 _cond = mirror(_cond);
1983 }
1984
1985 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1986 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1987 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1988 void set_swapped(bool value) { _swapped = value; }
1989 // generic
1990 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
1991 };
1992
1993
1994 BASE(Switch, BlockEnd)
1995 private:
1996 Value _tag;
1997
1998 public:
1999 // creation
2000 Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
2001 : BlockEnd(illegalType, state_before, is_safepoint)
2002 , _tag(tag) {
2003 ASSERT_VALUES
2004 set_sux(sux);
2005 }
2006
2007 // accessors
2008 Value tag() const { return _tag; }
2279 }
2280 }
2281 };
2282
2283 LEAF(ProfileReturnType, Instruction)
2284 private:
2285 ciMethod* _method;
2286 ciMethod* _callee;
2287 int _bci_of_invoke;
2288 Value _ret;
2289
2290 public:
2291 ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)
2292 : Instruction(voidType)
2293 , _method(method)
2294 , _callee(callee)
2295 , _bci_of_invoke(bci)
2296 , _ret(ret)
2297 {
2298 set_needs_null_check(true);
2299 // The ProfileType has side-effects and must occur precisely where located
2300 pin();
2301 }
2302
2303 ciMethod* method() const { return _method; }
2304 ciMethod* callee() const { return _callee; }
2305 int bci_of_invoke() const { return _bci_of_invoke; }
2306 Value ret() const { return _ret; }
2307
2308 virtual void input_values_do(ValueVisitor* f) {
2309 if (_ret != nullptr) {
2310 f->visit(&_ret);
2311 }
2312 }
2313 };
2314
2315 // Call some C runtime function that doesn't safepoint,
2316 // optionally passing the current thread as the first argument.
2317 LEAF(RuntimeCall, Instruction)
2318 private:
2319 const char* _entry_name;
2320 address _entry;
2321 Values* _args;
2322 bool _pass_thread; // Pass the JavaThread* as an implicit first argument
2323
2324 public:
2325 RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2326 : Instruction(type)
2327 , _entry_name(entry_name)
2328 , _entry(entry)
2329 , _args(args)
2330 , _pass_thread(pass_thread) {
2331 ASSERT_VALUES
2332 pin();
2333 }
2334
|
1 /*
2 * Copyright (c) 1999, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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 Deoptimize;
78 class TypeCheck;
79 class CheckCast;
80 class InstanceOf;
81 class AccessMonitor;
82 class MonitorEnter;
83 class MonitorExit;
84 class Intrinsic;
85 class BlockBegin;
86 class BlockEnd;
87 class Goto;
88 class If;
89 class Switch;
90 class TableSwitch;
91 class LookupSwitch;
92 class Return;
93 class Throw;
94 class Base;
95 class UnsafeOp;
96 class UnsafeGet;
97 class UnsafePut;
98 class UnsafeGetAndSet;
99 class ProfileCall;
100 class ProfileReturnType;
101 class ProfileACmpTypes;
102 class ProfileInvoke;
103 class RuntimeCall;
104 class MemBar;
105 class RangeCheckPredicate;
106 #ifdef ASSERT
107 class Assert;
108 #endif
109
110 // A Value is a reference to the instruction creating the value
111 typedef Instruction* Value;
112 typedef GrowableArray<Value> Values;
113 typedef GrowableArray<ValueStack*> ValueStackStack;
114
115 // BlockClosure is the base class for block traversal/iteration.
116
117 class BlockClosure: public CompilationResourceObj {
118 public:
119 virtual void block_do(BlockBegin* block) = 0;
120 };
121
176 virtual void do_CheckCast (CheckCast* x) = 0;
177 virtual void do_InstanceOf (InstanceOf* x) = 0;
178 virtual void do_MonitorEnter (MonitorEnter* x) = 0;
179 virtual void do_MonitorExit (MonitorExit* x) = 0;
180 virtual void do_Intrinsic (Intrinsic* x) = 0;
181 virtual void do_BlockBegin (BlockBegin* x) = 0;
182 virtual void do_Goto (Goto* x) = 0;
183 virtual void do_If (If* x) = 0;
184 virtual void do_TableSwitch (TableSwitch* x) = 0;
185 virtual void do_LookupSwitch (LookupSwitch* x) = 0;
186 virtual void do_Return (Return* x) = 0;
187 virtual void do_Throw (Throw* x) = 0;
188 virtual void do_Base (Base* x) = 0;
189 virtual void do_OsrEntry (OsrEntry* x) = 0;
190 virtual void do_ExceptionObject(ExceptionObject* 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_ProfileACmpTypes(ProfileACmpTypes* x) = 0;
197 virtual void do_ProfileInvoke (ProfileInvoke* x) = 0;
198 virtual void do_RuntimeCall (RuntimeCall* x) = 0;
199 virtual void do_MemBar (MemBar* x) = 0;
200 virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0;
201 #ifdef ASSERT
202 virtual void do_Assert (Assert* x) = 0;
203 #endif
204 };
205
206
207 // Hashing support
208 //
209 // Note: This hash functions affect the performance
210 // of ValueMap - make changes carefully!
211
212 #define HASH1(x1 ) ((intx)(x1))
213 #define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2))
214 #define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3))
215 #define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3 ) << 7) ^ HASH1(x4))
216 #define HASH5(x1, x2, x3, x4, x5) ((HASH4(x1, x2, x3, x4) << 7) ^ HASH1(x5))
217
218
219 // The following macros are used to implement instruction-specific hashing.
220 // By default, each instruction implements hash() and is_equal(Value), used
221 // for value numbering/common subexpression elimination. The default imple-
222 // mentation disables value numbering. Each instruction which can be value-
223 // numbered, should define corresponding hash() and is_equal(Value) functions
224 // via the macros below. The f arguments specify all the values/op codes, etc.
225 // that need to be identical for two instructions to be identical.
226 //
227 // Note: The default implementation of hash() returns 0 in order to indicate
228 // that the instruction should not be considered for value numbering.
229 // The currently used hash functions do not guarantee that never a 0
230 // is produced. While this is still correct, it may be a performance
231 // bug (no value numbering for that node). However, this situation is
232 // so unlikely, that we are not going to handle it specially.
233
234 #define HASHING1(class_name, enabled, f1) \
235 virtual intx hash() const { \
236 return (enabled) ? HASH2(name(), f1) : 0; \
255 if (f1 != _v->f1) return false; \
256 if (f2 != _v->f2) return false; \
257 return true; \
258 } \
259
260
261 #define HASHING3(class_name, enabled, f1, f2, f3) \
262 virtual intx hash() const { \
263 return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
264 } \
265 virtual bool is_equal(Value v) const { \
266 if (!(enabled) ) return false; \
267 class_name* _v = v->as_##class_name(); \
268 if (_v == nullptr) return false; \
269 if (f1 != _v->f1) return false; \
270 if (f2 != _v->f2) return false; \
271 if (f3 != _v->f3) return false; \
272 return true; \
273 } \
274
275 #define HASHING4(class_name, enabled, f1, f2, f3, f4) \
276 virtual intx hash() const { \
277 return (enabled) ? HASH5(name(), f1, f2, f3, f4) : 0; \
278 } \
279 virtual bool is_equal(Value v) const { \
280 if (!(enabled) ) return false; \
281 class_name* _v = v->as_##class_name(); \
282 if (_v == nullptr ) return false; \
283 if (f1 != _v->f1) return false; \
284 if (f2 != _v->f2) return false; \
285 if (f3 != _v->f3) return false; \
286 if (f4 != _v->f4) return false; \
287 return true; \
288 } \
289
290
291 // The mother of all instructions...
292
293 class Instruction: public CompilationResourceObj {
294 private:
295 int _id; // the unique instruction id
296 #ifndef PRODUCT
297 int _printable_bci; // the bci of the instruction for printing
298 #endif
299 int _use_count; // the number of instructions referring to this value (w/o prev/next); only roots can have use count = 0 or > 1
300 int _pin_state; // set of PinReason describing the reason for pinning
301 unsigned int _flags; // Flag bits
302 ValueType* _type; // the instruction value type
303 Instruction* _next; // the next instruction if any (null for BlockEnd instructions)
304 Instruction* _subst; // the substitution instruction if any
305 LIR_Opr _operand; // LIR specific information
306
307 ValueStack* _state_before; // Copy of state with input operands still on stack (or null)
308 ValueStack* _exception_state; // Copy of state for exception handling
309 XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction
310
311 friend class UseCountComputer;
312 friend class GraphBuilder;
313
314 void update_exception_state(ValueStack* state);
315
316 protected:
317 BlockBegin* _block; // Block that contains this instruction
318
319 void set_type(ValueType* type) {
320 assert(type != nullptr, "type must exist");
321 _type = type;
322 }
323
324 // Helper class to keep track of which arguments need a null check
325 class ArgsNonNullState {
326 private:
327 int _nonnull_state; // mask identifying which args are nonnull
328 public:
329 ArgsNonNullState()
330 : _nonnull_state(AllBits) {}
331
332 // Does argument number i needs a null check?
345 if (check) {
346 _nonnull_state |= (int)nth_bit(i);
347 } else {
348 _nonnull_state &= (int)~(nth_bit(i));
349 }
350 }
351 }
352 };
353
354 public:
355 void* operator new(size_t size) throw() {
356 Compilation* c = Compilation::current();
357 void* res = c->arena()->Amalloc(size);
358 return res;
359 }
360
361 static const int no_bci = -99;
362
363 enum InstructionFlag {
364 NeedsNullCheckFlag = 0,
365 NeverNullFlag,
366 CanTrapFlag,
367 DirectCompareFlag,
368 IsSafepointFlag,
369 IsStaticFlag,
370 PreservesStateFlag,
371 TargetIsFinalFlag,
372 TargetIsLoadedFlag,
373 UnorderedIsTrueFlag,
374 NeedsPatchingFlag,
375 ThrowIncompatibleClassChangeErrorFlag,
376 InvokeSpecialReceiverCheckFlag,
377 ProfileMDOFlag,
378 IsLinkedInBlockFlag,
379 NeedsRangeCheckFlag,
380 DeoptimizeOnException,
381 KillsMemoryFlag,
382 OmitChecksFlag,
383 InstructionLastFlag
384 };
385
436 int id() const { return _id; }
437 #ifndef PRODUCT
438 bool has_printable_bci() const { return _printable_bci != -99; }
439 int printable_bci() const { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
440 void set_printable_bci(int bci) { _printable_bci = bci; }
441 #endif
442 int dominator_depth();
443 int use_count() const { return _use_count; }
444 int pin_state() const { return _pin_state; }
445 bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; }
446 ValueType* type() const { return _type; }
447 BlockBegin *block() const { return _block; }
448 Instruction* prev(); // use carefully, expensive operation
449 Instruction* next() const { return _next; }
450 bool has_subst() const { return _subst != nullptr; }
451 Instruction* subst() { return _subst == nullptr ? this : _subst->subst(); }
452 LIR_Opr operand() const { return _operand; }
453
454 void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); }
455 bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); }
456 void set_null_free(bool f) { set_flag(NeverNullFlag, f); }
457 bool is_null_free() const { return check_flag(NeverNullFlag); }
458 bool is_linked() const { return check_flag(IsLinkedInBlockFlag); }
459 bool can_be_linked() { return as_Local() == nullptr && as_Phi() == nullptr; }
460
461 bool is_null_obj() { return as_Constant() != nullptr && type()->as_ObjectType()->constant_value()->is_null_object(); }
462
463 bool has_uses() const { return use_count() > 0; }
464 ValueStack* state_before() const { return _state_before; }
465 ValueStack* exception_state() const { return _exception_state; }
466 virtual bool needs_exception_state() const { return true; }
467 XHandlers* exception_handlers() const { return _exception_handlers; }
468 ciKlass* as_loaded_klass_or_null() const;
469
470 // manipulation
471 void pin(PinReason reason) { _pin_state |= reason; }
472 void pin() { _pin_state |= PinUnknown; }
473 // DANGEROUS: only used by EliminateStores
474 void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
475
476 Instruction* set_next(Instruction* next) {
477 assert(next->has_printable_bci(), "_printable_bci should have been set");
478 assert(next != nullptr, "must not be null");
479 assert(as_BlockEnd() == nullptr, "BlockEnd instructions must have no next");
480 assert(next->can_be_linked(), "shouldn't link these instructions into list");
481
482 BlockBegin *block = this->block();
483 next->_block = block;
484
485 next->set_flag(Instruction::IsLinkedInBlockFlag, true);
486 _next = next;
487 return next;
488 }
493 #endif
494 return set_next(next);
495 }
496
497 // when blocks are merged
498 void fixup_block_pointers() {
499 Instruction *cur = next()->next(); // next()'s block is set in set_next
500 while (cur && cur->_block != block()) {
501 cur->_block = block();
502 cur = cur->next();
503 }
504 }
505
506 Instruction *insert_after(Instruction *i) {
507 Instruction* n = _next;
508 set_next(i);
509 i->set_next(n);
510 return _next;
511 }
512
513 bool is_loaded_flat_array() const;
514 bool maybe_flat_array() const;
515 bool maybe_null_free_array() const;
516
517 Instruction *insert_after_same_bci(Instruction *i) {
518 #ifndef PRODUCT
519 i->set_printable_bci(printable_bci());
520 #endif
521 return insert_after(i);
522 }
523
524 void set_subst(Instruction* subst) {
525 assert(subst == nullptr ||
526 type()->base() == subst->type()->base() ||
527 subst->type()->base() == illegalType, "type can't change");
528 _subst = subst;
529 }
530 void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
531 void set_exception_state(ValueStack* s) { check_state(s); _exception_state = s; }
532 void set_state_before(ValueStack* s) { check_state(s); _state_before = s; }
533
534 // machine-specifics
535 void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
536 void clear_operand() { _operand = LIR_OprFact::illegalOpr; }
824
825 // Under certain circumstances, if a previous NullCheck instruction
826 // proved the target object non-null, we can eliminate the explicit
827 // null check and do an implicit one, simply specifying the debug
828 // information from the NullCheck. This field should only be consulted
829 // if needs_null_check() is true.
830 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
831
832 // generic
833 virtual bool can_trap() const { return needs_null_check() || needs_patching(); }
834 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
835 };
836
837
838 LEAF(LoadField, AccessField)
839 public:
840 // creation
841 LoadField(Value obj, int offset, ciField* field, bool is_static,
842 ValueStack* state_before, bool needs_patching)
843 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
844 {
845 set_null_free(field->is_null_free());
846 }
847
848 ciType* declared_type() const;
849
850 // generic; cannot be eliminated if needs patching or if volatile.
851 HASHING3(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset(), declared_type())
852 };
853
854
855 LEAF(StoreField, AccessField)
856 private:
857 Value _value;
858 ciField* _enclosing_field; // enclosing field (the flat one) for nested fields
859
860 public:
861 // creation
862 StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
863 ValueStack* state_before, bool needs_patching);
864
865 // accessors
866 Value value() const { return _value; }
867 ciField* enclosing_field() const { return _enclosing_field; }
868 void set_enclosing_field(ciField* field) { _enclosing_field = field; }
869
870 // generic
871 virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); }
872 };
873
874
875 BASE(AccessArray, Instruction)
876 private:
877 Value _array;
878
879 public:
880 // creation
881 AccessArray(ValueType* type, Value array, ValueStack* state_before)
882 : Instruction(type, state_before)
883 , _array(array)
884 {
885 set_needs_null_check(true);
886 ASSERT_VALUES
887 pin(); // instruction with side effect (null exception or range check throwing)
888 }
906 , _explicit_null_check(nullptr) {}
907
908 // accessors
909 NullCheck* explicit_null_check() const { return _explicit_null_check; }
910
911 // setters
912 // See LoadField::set_explicit_null_check for documentation
913 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
914
915 // generic
916 HASHING1(ArrayLength, true, array()->subst())
917 };
918
919
920 BASE(AccessIndexed, AccessArray)
921 private:
922 Value _index;
923 Value _length;
924 BasicType _elt_type;
925 bool _mismatched;
926 ciMethod* _profiled_method;
927 int _profiled_bci;
928
929 public:
930 // creation
931 AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched)
932 : AccessArray(as_ValueType(elt_type), array, state_before)
933 , _index(index)
934 , _length(length)
935 , _elt_type(elt_type)
936 , _mismatched(mismatched)
937 , _profiled_method(nullptr), _profiled_bci(0)
938 {
939 set_flag(Instruction::NeedsRangeCheckFlag, true);
940 ASSERT_VALUES
941 }
942
943 // accessors
944 Value index() const { return _index; }
945 Value length() const { return _length; }
946 BasicType elt_type() const { return _elt_type; }
947 bool mismatched() const { return _mismatched; }
948
949 void clear_length() { _length = nullptr; }
950 // perform elimination of range checks involving constants
951 bool compute_needs_range_check();
952
953 // Helpers for MethodData* profiling
954 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
955 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
956 void set_profiled_bci(int bci) { _profiled_bci = bci; }
957 bool should_profile() const { return check_flag(ProfileMDOFlag); }
958 ciMethod* profiled_method() const { return _profiled_method; }
959 int profiled_bci() const { return _profiled_bci; }
960
961
962 // generic
963 virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != nullptr) f->visit(&_length); }
964 };
965
966 class DelayedLoadIndexed;
967
968 LEAF(LoadIndexed, AccessIndexed)
969 private:
970 NullCheck* _explicit_null_check; // For explicit null check elimination
971 Value _buffer; // Buffer for load from flat arrays
972 DelayedLoadIndexed* _delayed;
973
974 public:
975 // creation
976 LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched = false)
977 : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
978 , _explicit_null_check(nullptr), _buffer(nullptr), _delayed(nullptr) {}
979
980 // accessors
981 NullCheck* explicit_null_check() const { return _explicit_null_check; }
982
983 // setters
984 // See LoadField::set_explicit_null_check for documentation
985 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
986
987 ciType* exact_type() const;
988 ciType* declared_type() const;
989
990 Value buffer() const { return _buffer; }
991
992 void set_buffer(Value buffer) {
993 assert(buffer == nullptr || buffer->as_NewInstance() != nullptr, "LoadIndexed flat array buffer must be a NewInstance");
994 _buffer = buffer;
995 }
996
997 DelayedLoadIndexed* delayed() const { return _delayed; }
998 void set_delayed(DelayedLoadIndexed* delayed) { _delayed = delayed; }
999
1000 virtual void input_values_do(ValueVisitor* f) {
1001 AccessIndexed::input_values_do(f);
1002 if (_buffer != nullptr) {
1003 f->visit(&_buffer);
1004 assert(_buffer->as_NewInstance() != nullptr, "LoadIndexed flat array buffer must stay a NewInstance");
1005 }
1006 }
1007
1008 // generic;
1009 HASHING4(LoadIndexed, delayed() == nullptr && !should_profile(), elt_type(), array()->subst(), index()->subst(), buffer())
1010 };
1011
1012 class DelayedLoadIndexed : public CompilationResourceObj {
1013 private:
1014 LoadIndexed* _load_instr;
1015 ValueStack* _state_before;
1016 ciField* _field;
1017 size_t _offset;
1018 public:
1019 DelayedLoadIndexed(LoadIndexed* load, ValueStack* state_before)
1020 : _load_instr(load)
1021 , _state_before(state_before)
1022 , _field(nullptr)
1023 , _offset(0) { }
1024
1025 void update(ciField* field, int offset) {
1026 assert(offset >= 0, "must be");
1027 _field = field;
1028 _offset += offset;
1029 }
1030
1031 LoadIndexed* load_instr() const { return _load_instr; }
1032 ValueStack* state_before() const { return _state_before; }
1033 ciField* field() const { return _field; }
1034 size_t offset() const { return _offset; }
1035 };
1036
1037 LEAF(StoreIndexed, AccessIndexed)
1038 private:
1039 Value _value;
1040
1041 bool _check_boolean;
1042
1043 public:
1044 // creation
1045 StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before,
1046 bool check_boolean, bool mismatched = false);
1047
1048 // accessors
1049 Value value() const { return _value; }
1050 bool check_boolean() const { return _check_boolean; }
1051
1052 // Flattened array support
1053 bool is_exact_flat_array_store() const;
1054 // generic
1055 virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); }
1056 };
1057
1058
1059 LEAF(NegateOp, Instruction)
1060 private:
1061 Value _x;
1062
1063 public:
1064 // creation
1065 NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
1066 ASSERT_VALUES
1067 }
1068
1069 // accessors
1070 Value x() const { return _x; }
1071
1072 // generic
1073 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); }
1144 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1145 };
1146
1147
1148 LEAF(CompareOp, Op2)
1149 public:
1150 // creation
1151 CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1152 : Op2(intType, op, x, y, state_before)
1153 {}
1154
1155 // generic
1156 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1157 };
1158
1159
1160 LEAF(IfOp, Op2)
1161 private:
1162 Value _tval;
1163 Value _fval;
1164 bool _substitutability_check;
1165
1166 public:
1167 // creation
1168 IfOp(Value x, Condition cond, Value y, Value tval, Value fval, ValueStack* state_before, bool substitutability_check)
1169 : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1170 , _tval(tval)
1171 , _fval(fval)
1172 , _substitutability_check(substitutability_check)
1173 {
1174 ASSERT_VALUES
1175 assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1176 set_state_before(state_before);
1177 }
1178
1179 // accessors
1180 virtual bool is_commutative() const;
1181 Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }
1182 Condition cond() const { return (Condition)Op2::op(); }
1183 Value tval() const { return _tval; }
1184 Value fval() const { return _fval; }
1185 bool substitutability_check() const { return _substitutability_check; }
1186 // generic
1187 virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1188 };
1189
1190
1191 LEAF(Convert, Instruction)
1192 private:
1193 Bytecodes::Code _op;
1194 Value _value;
1195
1196 public:
1197 // creation
1198 Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1199 ASSERT_VALUES
1200 }
1201
1202 // accessors
1203 Bytecodes::Code op() const { return _op; }
1204 Value value() const { return _value; }
1205
1280 // accessors
1281 ValueStack* state() const { return _state; }
1282 IRScope* scope() const; // the state's scope
1283
1284 // manipulation
1285 void set_state(ValueStack* state) { assert(_state == nullptr, "overwriting existing state"); check_state(state); _state = state; }
1286
1287 // generic
1288 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
1289 virtual void state_values_do(ValueVisitor* f);
1290 };
1291
1292
1293 LEAF(Invoke, StateSplit)
1294 private:
1295 Bytecodes::Code _code;
1296 Value _recv;
1297 Values* _args;
1298 BasicTypeList* _signature;
1299 ciMethod* _target;
1300 ciType* _return_type;
1301
1302 public:
1303 // creation
1304 Invoke(Bytecodes::Code code, ciType* return_type, Value recv, Values* args,
1305 ciMethod* target, ValueStack* state_before);
1306
1307 // accessors
1308 Bytecodes::Code code() const { return _code; }
1309 Value receiver() const { return _recv; }
1310 bool has_receiver() const { return receiver() != nullptr; }
1311 int number_of_arguments() const { return _args->length(); }
1312 Value argument_at(int i) const { return _args->at(i); }
1313 BasicTypeList* signature() const { return _signature; }
1314 ciMethod* target() const { return _target; }
1315
1316 ciType* declared_type() const;
1317
1318 // Returns false if target is not loaded
1319 bool target_is_final() const { return check_flag(TargetIsFinalFlag); }
1320 bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }
1321
1322 // JSR 292 support
1323 bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }
1324 bool is_method_handle_intrinsic() const { return target()->is_method_handle_intrinsic(); }
1325
1326 virtual bool needs_exception_state() const { return false; }
1327
1328 // generic
1329 virtual bool can_trap() const { return true; }
1330 virtual void input_values_do(ValueVisitor* f) {
1331 StateSplit::input_values_do(f);
1332 if (has_receiver()) f->visit(&_recv);
1333 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1334 }
1335 virtual void state_values_do(ValueVisitor *f);
1336 };
1337
1338
1339 LEAF(NewInstance, StateSplit)
1340 private:
1341 ciInstanceKlass* _klass;
1342 bool _is_unresolved;
1343 bool _needs_state_before;
1344
1345 public:
1346 // creation
1347 NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved, bool needs_state_before)
1348 : StateSplit(instanceType, state_before)
1349 , _klass(klass), _is_unresolved(is_unresolved), _needs_state_before(needs_state_before)
1350 {}
1351
1352 // accessors
1353 ciInstanceKlass* klass() const { return _klass; }
1354 bool is_unresolved() const { return _is_unresolved; }
1355 bool needs_state_before() const { return _needs_state_before; }
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 BASE(NewArray, StateSplit)
1366 private:
1367 Value _length;
1368
1369 public:
1370 // creation
1371 NewArray(Value length, ValueStack* state_before)
1372 : StateSplit(objectType, state_before)
1373 , _length(length)
1374 {
1375 // Do not ASSERT_VALUES since length is null for NewMultiArray
1376 }
1377
1378 // accessors
1379 Value length() const { return _length; }
1380
1381 virtual bool needs_exception_state() const { return false; }
1382
1383 ciType* exact_type() const { return nullptr; }
1384 ciType* declared_type() const;
1398 // creation
1399 NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before, bool zero_array)
1400 : NewArray(length, state_before)
1401 , _elt_type(elt_type)
1402 , _zero_array(zero_array)
1403 {}
1404
1405 // accessors
1406 BasicType elt_type() const { return _elt_type; }
1407 bool zero_array() const { return _zero_array; }
1408 ciType* exact_type() const;
1409 };
1410
1411
1412 LEAF(NewObjectArray, NewArray)
1413 private:
1414 ciKlass* _klass;
1415
1416 public:
1417 // creation
1418 NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before)
1419 : NewArray(length, state_before), _klass(klass) { }
1420
1421 // accessors
1422 ciKlass* klass() const { return _klass; }
1423 ciType* exact_type() const;
1424 };
1425
1426
1427 LEAF(NewMultiArray, NewArray)
1428 private:
1429 ciKlass* _klass;
1430 Values* _dims;
1431
1432 public:
1433 // creation
1434 NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(nullptr, state_before), _klass(klass), _dims(dims) {
1435 ASSERT_VALUES
1436 }
1437
1438 // accessors
1439 ciKlass* klass() const { return _klass; }
1440 Values* dims() const { return _dims; }
1441 int rank() const { return dims()->length(); }
1442
1443 // generic
1444 virtual void input_values_do(ValueVisitor* f) {
1445 // NOTE: we do not call NewArray::input_values_do since "length"
1446 // is meaningless for a multi-dimensional array; passing the
1447 // zeroth element down to NewArray as its length is a bad idea
1448 // since there will be a copy in the "dims" array which doesn't
1449 // get updated, and the value must not be traversed twice. Was bug
1450 // - kbr 4/10/2001
1451 StateSplit::input_values_do(f);
1452 for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1453 }
1454
1455 ciType* exact_type() const;
1456 };
1457
1458
1459 BASE(TypeCheck, StateSplit)
1460 private:
1461 ciKlass* _klass;
1462 Value _obj;
1463
1464 ciMethod* _profiled_method;
1465 int _profiled_bci;
1466
1467 public:
1468 // creation
1469 TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1470 : StateSplit(type, state_before), _klass(klass), _obj(obj),
1471 _profiled_method(nullptr), _profiled_bci(0) {
1472 ASSERT_VALUES
1473 set_direct_compare(false);
1474 }
1475
1483 void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }
1484
1485 // generic
1486 virtual bool can_trap() const { return true; }
1487 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1488
1489 // Helpers for MethodData* profiling
1490 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1491 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1492 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1493 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1494 ciMethod* profiled_method() const { return _profiled_method; }
1495 int profiled_bci() const { return _profiled_bci; }
1496 };
1497
1498
1499 LEAF(CheckCast, TypeCheck)
1500 public:
1501 // creation
1502 CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1503 : TypeCheck(klass, obj, objectType, state_before) { }
1504
1505 void set_incompatible_class_change_check() {
1506 set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1507 }
1508 bool is_incompatible_class_change_check() const {
1509 return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1510 }
1511 void set_invokespecial_receiver_check() {
1512 set_flag(InvokeSpecialReceiverCheckFlag, true);
1513 }
1514 bool is_invokespecial_receiver_check() const {
1515 return check_flag(InvokeSpecialReceiverCheckFlag);
1516 }
1517
1518 virtual bool needs_exception_state() const {
1519 return !is_invokespecial_receiver_check();
1520 }
1521
1522 ciType* declared_type() const;
1523 };
1541 // creation
1542 AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = nullptr)
1543 : StateSplit(illegalType, state_before)
1544 , _obj(obj)
1545 , _monitor_no(monitor_no)
1546 {
1547 set_needs_null_check(true);
1548 ASSERT_VALUES
1549 }
1550
1551 // accessors
1552 Value obj() const { return _obj; }
1553 int monitor_no() const { return _monitor_no; }
1554
1555 // generic
1556 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1557 };
1558
1559
1560 LEAF(MonitorEnter, AccessMonitor)
1561 bool _maybe_inlinetype;
1562 public:
1563 // creation
1564 MonitorEnter(Value obj, int monitor_no, ValueStack* state_before, bool maybe_inlinetype)
1565 : AccessMonitor(obj, monitor_no, state_before)
1566 , _maybe_inlinetype(maybe_inlinetype)
1567 {
1568 ASSERT_VALUES
1569 }
1570
1571 // accessors
1572 bool maybe_inlinetype() const { return _maybe_inlinetype; }
1573
1574 // generic
1575 virtual bool can_trap() const { return true; }
1576 };
1577
1578
1579 LEAF(MonitorExit, AccessMonitor)
1580 public:
1581 // creation
1582 MonitorExit(Value obj, int monitor_no)
1583 : AccessMonitor(obj, monitor_no, nullptr)
1584 {
1585 ASSERT_VALUES
1586 }
1587 };
1588
1589
1590 LEAF(Intrinsic, StateSplit)
1591 private:
1592 vmIntrinsics::ID _id;
1593 ArgsNonNullState _nonnull_state;
2009 Condition cond() const { return _cond; }
2010 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
2011 Value y() const { return _y; }
2012
2013 void always_fail() { _x = _y = nullptr; }
2014
2015 // generic
2016 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2017 HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())
2018 };
2019
2020 LEAF(If, BlockEnd)
2021 private:
2022 Value _x;
2023 Condition _cond;
2024 Value _y;
2025 ciMethod* _profiled_method;
2026 int _profiled_bci; // Canonicalizer may alter bci of If node
2027 bool _swapped; // Is the order reversed with respect to the original If in the
2028 // bytecode stream?
2029 bool _substitutability_check;
2030 public:
2031 // creation
2032 // unordered_is_true is valid for float/double compares only
2033 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)
2034 : BlockEnd(illegalType, state_before, is_safepoint)
2035 , _x(x)
2036 , _cond(cond)
2037 , _y(y)
2038 , _profiled_method(nullptr)
2039 , _profiled_bci(0)
2040 , _swapped(false)
2041 , _substitutability_check(substitutability_check)
2042 {
2043 ASSERT_VALUES
2044 set_flag(UnorderedIsTrueFlag, unordered_is_true);
2045 assert(x->type()->tag() == y->type()->tag(), "types must match");
2046 BlockList* s = new BlockList(2);
2047 s->append(tsux);
2048 s->append(fsux);
2049 set_sux(s);
2050 }
2051
2052 // accessors
2053 Value x() const { return _x; }
2054 Condition cond() const { return _cond; }
2055 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
2056 Value y() const { return _y; }
2057 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
2058 BlockBegin* tsux() const { return sux_for(true); }
2059 BlockBegin* fsux() const { return sux_for(false); }
2060 BlockBegin* usux() const { return sux_for(unordered_is_true()); }
2061 bool should_profile() const { return check_flag(ProfileMDOFlag); }
2062 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
2063 int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered
2064 bool is_swapped() const { return _swapped; }
2065
2066 // manipulation
2067 void swap_operands() {
2068 Value t = _x; _x = _y; _y = t;
2069 _cond = mirror(_cond);
2070 }
2071
2072 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
2073 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
2074 void set_profiled_bci(int bci) { _profiled_bci = bci; }
2075 void set_swapped(bool value) { _swapped = value; }
2076 bool substitutability_check() const { return _substitutability_check; }
2077 // generic
2078 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2079 };
2080
2081
2082 BASE(Switch, BlockEnd)
2083 private:
2084 Value _tag;
2085
2086 public:
2087 // creation
2088 Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
2089 : BlockEnd(illegalType, state_before, is_safepoint)
2090 , _tag(tag) {
2091 ASSERT_VALUES
2092 set_sux(sux);
2093 }
2094
2095 // accessors
2096 Value tag() const { return _tag; }
2367 }
2368 }
2369 };
2370
2371 LEAF(ProfileReturnType, Instruction)
2372 private:
2373 ciMethod* _method;
2374 ciMethod* _callee;
2375 int _bci_of_invoke;
2376 Value _ret;
2377
2378 public:
2379 ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)
2380 : Instruction(voidType)
2381 , _method(method)
2382 , _callee(callee)
2383 , _bci_of_invoke(bci)
2384 , _ret(ret)
2385 {
2386 set_needs_null_check(true);
2387 // The ProfileReturnType has side-effects and must occur precisely where located
2388 pin();
2389 }
2390
2391 ciMethod* method() const { return _method; }
2392 ciMethod* callee() const { return _callee; }
2393 int bci_of_invoke() const { return _bci_of_invoke; }
2394 Value ret() const { return _ret; }
2395
2396 virtual void input_values_do(ValueVisitor* f) {
2397 if (_ret != nullptr) {
2398 f->visit(&_ret);
2399 }
2400 }
2401 };
2402
2403 LEAF(ProfileACmpTypes, Instruction)
2404 private:
2405 ciMethod* _method;
2406 int _bci;
2407 Value _left;
2408 Value _right;
2409 bool _left_maybe_null;
2410 bool _right_maybe_null;
2411
2412 public:
2413 ProfileACmpTypes(ciMethod* method, int bci, Value left, Value right)
2414 : Instruction(voidType)
2415 , _method(method)
2416 , _bci(bci)
2417 , _left(left)
2418 , _right(right)
2419 {
2420 // The ProfileACmp has side-effects and must occur precisely where located
2421 pin();
2422 _left_maybe_null = true;
2423 _right_maybe_null = true;
2424 }
2425
2426 ciMethod* method() const { return _method; }
2427 int bci() const { return _bci; }
2428 Value left() const { return _left; }
2429 Value right() const { return _right; }
2430 bool left_maybe_null() const { return _left_maybe_null; }
2431 bool right_maybe_null() const { return _right_maybe_null; }
2432 void set_left_maybe_null(bool v) { _left_maybe_null = v; }
2433 void set_right_maybe_null(bool v) { _right_maybe_null = v; }
2434
2435 virtual void input_values_do(ValueVisitor* f) {
2436 if (_left != nullptr) {
2437 f->visit(&_left);
2438 }
2439 if (_right != nullptr) {
2440 f->visit(&_right);
2441 }
2442 }
2443 };
2444
2445 // Call some C runtime function that doesn't safepoint,
2446 // optionally passing the current thread as the first argument.
2447 LEAF(RuntimeCall, Instruction)
2448 private:
2449 const char* _entry_name;
2450 address _entry;
2451 Values* _args;
2452 bool _pass_thread; // Pass the JavaThread* as an implicit first argument
2453
2454 public:
2455 RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2456 : Instruction(type)
2457 , _entry_name(entry_name)
2458 , _entry(entry)
2459 , _args(args)
2460 , _pass_thread(pass_thread) {
2461 ASSERT_VALUES
2462 pin();
2463 }
2464
|