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();
515 bool maybe_null_free_array();
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 NewInstance* _vt;
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), _vt(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 NewInstance* vt() const { return _vt; }
991 void set_vt(NewInstance* vt) { _vt = vt; }
992
993 DelayedLoadIndexed* delayed() const { return _delayed; }
994 void set_delayed(DelayedLoadIndexed* delayed) { _delayed = delayed; }
995
996 // generic;
997 HASHING4(LoadIndexed, delayed() == nullptr && !should_profile(), elt_type(), array()->subst(), index()->subst(), vt())
998 };
999
1000 class DelayedLoadIndexed : public CompilationResourceObj {
1001 private:
1002 LoadIndexed* _load_instr;
1003 ValueStack* _state_before;
1004 ciField* _field;
1005 size_t _offset;
1006 public:
1007 DelayedLoadIndexed(LoadIndexed* load, ValueStack* state_before)
1008 : _load_instr(load)
1009 , _state_before(state_before)
1010 , _field(nullptr)
1011 , _offset(0) { }
1012
1013 void update(ciField* field, int offset) {
1014 assert(offset >= 0, "must be");
1015 _field = field;
1016 _offset += offset;
1017 }
1018
1019 LoadIndexed* load_instr() const { return _load_instr; }
1020 ValueStack* state_before() const { return _state_before; }
1021 ciField* field() const { return _field; }
1022 size_t offset() const { return _offset; }
1023 };
1024
1025 LEAF(StoreIndexed, AccessIndexed)
1026 private:
1027 Value _value;
1028
1029 bool _check_boolean;
1030
1031 public:
1032 // creation
1033 StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before,
1034 bool check_boolean, bool mismatched = false);
1035
1036 // accessors
1037 Value value() const { return _value; }
1038 bool check_boolean() const { return _check_boolean; }
1039
1040 // Flattened array support
1041 bool is_exact_flat_array_store() const;
1042 // generic
1043 virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); }
1044 };
1045
1046
1047 LEAF(NegateOp, Instruction)
1048 private:
1049 Value _x;
1050
1051 public:
1052 // creation
1053 NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
1054 ASSERT_VALUES
1055 }
1056
1057 // accessors
1058 Value x() const { return _x; }
1059
1060 // generic
1061 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); }
1132 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1133 };
1134
1135
1136 LEAF(CompareOp, Op2)
1137 public:
1138 // creation
1139 CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1140 : Op2(intType, op, x, y, state_before)
1141 {}
1142
1143 // generic
1144 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1145 };
1146
1147
1148 LEAF(IfOp, Op2)
1149 private:
1150 Value _tval;
1151 Value _fval;
1152 bool _substitutability_check;
1153
1154 public:
1155 // creation
1156 IfOp(Value x, Condition cond, Value y, Value tval, Value fval, ValueStack* state_before, bool substitutability_check)
1157 : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1158 , _tval(tval)
1159 , _fval(fval)
1160 , _substitutability_check(substitutability_check)
1161 {
1162 ASSERT_VALUES
1163 assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1164 set_state_before(state_before);
1165 }
1166
1167 // accessors
1168 virtual bool is_commutative() const;
1169 Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }
1170 Condition cond() const { return (Condition)Op2::op(); }
1171 Value tval() const { return _tval; }
1172 Value fval() const { return _fval; }
1173 bool substitutability_check() const { return _substitutability_check; }
1174 // generic
1175 virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1176 };
1177
1178
1179 LEAF(Convert, Instruction)
1180 private:
1181 Bytecodes::Code _op;
1182 Value _value;
1183
1184 public:
1185 // creation
1186 Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1187 ASSERT_VALUES
1188 }
1189
1190 // accessors
1191 Bytecodes::Code op() const { return _op; }
1192 Value value() const { return _value; }
1193
1268 // accessors
1269 ValueStack* state() const { return _state; }
1270 IRScope* scope() const; // the state's scope
1271
1272 // manipulation
1273 void set_state(ValueStack* state) { assert(_state == nullptr, "overwriting existing state"); check_state(state); _state = state; }
1274
1275 // generic
1276 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
1277 virtual void state_values_do(ValueVisitor* f);
1278 };
1279
1280
1281 LEAF(Invoke, StateSplit)
1282 private:
1283 Bytecodes::Code _code;
1284 Value _recv;
1285 Values* _args;
1286 BasicTypeList* _signature;
1287 ciMethod* _target;
1288 ciType* _return_type;
1289
1290 public:
1291 // creation
1292 Invoke(Bytecodes::Code code, ciType* return_type, Value recv, Values* args,
1293 ciMethod* target, ValueStack* state_before);
1294
1295 // accessors
1296 Bytecodes::Code code() const { return _code; }
1297 Value receiver() const { return _recv; }
1298 bool has_receiver() const { return receiver() != nullptr; }
1299 int number_of_arguments() const { return _args->length(); }
1300 Value argument_at(int i) const { return _args->at(i); }
1301 BasicTypeList* signature() const { return _signature; }
1302 ciMethod* target() const { return _target; }
1303
1304 ciType* declared_type() const;
1305
1306 // Returns false if target is not loaded
1307 bool target_is_final() const { return check_flag(TargetIsFinalFlag); }
1308 bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }
1309
1310 // JSR 292 support
1311 bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }
1312 bool is_method_handle_intrinsic() const { return target()->is_method_handle_intrinsic(); }
1313
1314 virtual bool needs_exception_state() const { return false; }
1315
1316 // generic
1317 virtual bool can_trap() const { return true; }
1318 virtual void input_values_do(ValueVisitor* f) {
1319 StateSplit::input_values_do(f);
1320 if (has_receiver()) f->visit(&_recv);
1321 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1322 }
1323 virtual void state_values_do(ValueVisitor *f);
1324 };
1325
1326
1327 LEAF(NewInstance, StateSplit)
1328 private:
1329 ciInstanceKlass* _klass;
1330 bool _is_unresolved;
1331 bool _needs_state_before;
1332
1333 public:
1334 // creation
1335 NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved, bool needs_state_before)
1336 : StateSplit(instanceType, state_before)
1337 , _klass(klass), _is_unresolved(is_unresolved), _needs_state_before(needs_state_before)
1338 {}
1339
1340 // accessors
1341 ciInstanceKlass* klass() const { return _klass; }
1342 bool is_unresolved() const { return _is_unresolved; }
1343 bool needs_state_before() const { return _needs_state_before; }
1344
1345 virtual bool needs_exception_state() const { return false; }
1346
1347 // generic
1348 virtual bool can_trap() const { return true; }
1349 ciType* exact_type() const;
1350 ciType* declared_type() const;
1351 };
1352
1353 BASE(NewArray, StateSplit)
1354 private:
1355 Value _length;
1356
1357 public:
1358 // creation
1359 NewArray(Value length, ValueStack* state_before)
1360 : StateSplit(objectType, state_before)
1361 , _length(length)
1362 {
1363 // Do not ASSERT_VALUES since length is null for NewMultiArray
1364 }
1365
1366 // accessors
1367 Value length() const { return _length; }
1368
1369 virtual bool needs_exception_state() const { return false; }
1370
1371 ciType* exact_type() const { return nullptr; }
1372 ciType* declared_type() const;
1386 // creation
1387 NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before, bool zero_array)
1388 : NewArray(length, state_before)
1389 , _elt_type(elt_type)
1390 , _zero_array(zero_array)
1391 {}
1392
1393 // accessors
1394 BasicType elt_type() const { return _elt_type; }
1395 bool zero_array() const { return _zero_array; }
1396 ciType* exact_type() const;
1397 };
1398
1399
1400 LEAF(NewObjectArray, NewArray)
1401 private:
1402 ciKlass* _klass;
1403
1404 public:
1405 // creation
1406 NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before)
1407 : NewArray(length, state_before), _klass(klass) { }
1408
1409 // accessors
1410 ciKlass* klass() const { return _klass; }
1411 ciType* exact_type() const;
1412 };
1413
1414
1415 LEAF(NewMultiArray, NewArray)
1416 private:
1417 ciKlass* _klass;
1418 Values* _dims;
1419
1420 public:
1421 // creation
1422 NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(nullptr, state_before), _klass(klass), _dims(dims) {
1423 ASSERT_VALUES
1424 }
1425
1426 // accessors
1427 ciKlass* klass() const { return _klass; }
1428 Values* dims() const { return _dims; }
1429 int rank() const { return dims()->length(); }
1430
1431 // generic
1432 virtual void input_values_do(ValueVisitor* f) {
1433 // NOTE: we do not call NewArray::input_values_do since "length"
1434 // is meaningless for a multi-dimensional array; passing the
1435 // zeroth element down to NewArray as its length is a bad idea
1436 // since there will be a copy in the "dims" array which doesn't
1437 // get updated, and the value must not be traversed twice. Was bug
1438 // - kbr 4/10/2001
1439 StateSplit::input_values_do(f);
1440 for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1441 }
1442
1443 ciType* exact_type() const;
1444 };
1445
1446
1447 BASE(TypeCheck, StateSplit)
1448 private:
1449 ciKlass* _klass;
1450 Value _obj;
1451
1452 ciMethod* _profiled_method;
1453 int _profiled_bci;
1454
1455 public:
1456 // creation
1457 TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1458 : StateSplit(type, state_before), _klass(klass), _obj(obj),
1459 _profiled_method(nullptr), _profiled_bci(0) {
1460 ASSERT_VALUES
1461 set_direct_compare(false);
1462 }
1463
1471 void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }
1472
1473 // generic
1474 virtual bool can_trap() const { return true; }
1475 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1476
1477 // Helpers for MethodData* profiling
1478 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1479 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1480 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1481 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1482 ciMethod* profiled_method() const { return _profiled_method; }
1483 int profiled_bci() const { return _profiled_bci; }
1484 };
1485
1486
1487 LEAF(CheckCast, TypeCheck)
1488 public:
1489 // creation
1490 CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1491 : TypeCheck(klass, obj, objectType, state_before) { }
1492
1493 void set_incompatible_class_change_check() {
1494 set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1495 }
1496 bool is_incompatible_class_change_check() const {
1497 return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1498 }
1499 void set_invokespecial_receiver_check() {
1500 set_flag(InvokeSpecialReceiverCheckFlag, true);
1501 }
1502 bool is_invokespecial_receiver_check() const {
1503 return check_flag(InvokeSpecialReceiverCheckFlag);
1504 }
1505
1506 virtual bool needs_exception_state() const {
1507 return !is_invokespecial_receiver_check();
1508 }
1509
1510 ciType* declared_type() const;
1511 };
1529 // creation
1530 AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = nullptr)
1531 : StateSplit(illegalType, state_before)
1532 , _obj(obj)
1533 , _monitor_no(monitor_no)
1534 {
1535 set_needs_null_check(true);
1536 ASSERT_VALUES
1537 }
1538
1539 // accessors
1540 Value obj() const { return _obj; }
1541 int monitor_no() const { return _monitor_no; }
1542
1543 // generic
1544 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1545 };
1546
1547
1548 LEAF(MonitorEnter, AccessMonitor)
1549 bool _maybe_inlinetype;
1550 public:
1551 // creation
1552 MonitorEnter(Value obj, int monitor_no, ValueStack* state_before, bool maybe_inlinetype)
1553 : AccessMonitor(obj, monitor_no, state_before)
1554 , _maybe_inlinetype(maybe_inlinetype)
1555 {
1556 ASSERT_VALUES
1557 }
1558
1559 // accessors
1560 bool maybe_inlinetype() const { return _maybe_inlinetype; }
1561
1562 // generic
1563 virtual bool can_trap() const { return true; }
1564 };
1565
1566
1567 LEAF(MonitorExit, AccessMonitor)
1568 public:
1569 // creation
1570 MonitorExit(Value obj, int monitor_no)
1571 : AccessMonitor(obj, monitor_no, nullptr)
1572 {
1573 ASSERT_VALUES
1574 }
1575 };
1576
1577
1578 LEAF(Intrinsic, StateSplit)
1579 private:
1580 vmIntrinsics::ID _id;
1581 ArgsNonNullState _nonnull_state;
1997 Condition cond() const { return _cond; }
1998 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
1999 Value y() const { return _y; }
2000
2001 void always_fail() { _x = _y = nullptr; }
2002
2003 // generic
2004 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2005 HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())
2006 };
2007
2008 LEAF(If, BlockEnd)
2009 private:
2010 Value _x;
2011 Condition _cond;
2012 Value _y;
2013 ciMethod* _profiled_method;
2014 int _profiled_bci; // Canonicalizer may alter bci of If node
2015 bool _swapped; // Is the order reversed with respect to the original If in the
2016 // bytecode stream?
2017 bool _substitutability_check;
2018 public:
2019 // creation
2020 // unordered_is_true is valid for float/double compares only
2021 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)
2022 : BlockEnd(illegalType, state_before, is_safepoint)
2023 , _x(x)
2024 , _cond(cond)
2025 , _y(y)
2026 , _profiled_method(nullptr)
2027 , _profiled_bci(0)
2028 , _swapped(false)
2029 , _substitutability_check(substitutability_check)
2030 {
2031 ASSERT_VALUES
2032 set_flag(UnorderedIsTrueFlag, unordered_is_true);
2033 assert(x->type()->tag() == y->type()->tag(), "types must match");
2034 BlockList* s = new BlockList(2);
2035 s->append(tsux);
2036 s->append(fsux);
2037 set_sux(s);
2038 }
2039
2040 // accessors
2041 Value x() const { return _x; }
2042 Condition cond() const { return _cond; }
2043 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
2044 Value y() const { return _y; }
2045 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
2046 BlockBegin* tsux() const { return sux_for(true); }
2047 BlockBegin* fsux() const { return sux_for(false); }
2048 BlockBegin* usux() const { return sux_for(unordered_is_true()); }
2049 bool should_profile() const { return check_flag(ProfileMDOFlag); }
2050 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
2051 int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered
2052 bool is_swapped() const { return _swapped; }
2053
2054 // manipulation
2055 void swap_operands() {
2056 Value t = _x; _x = _y; _y = t;
2057 _cond = mirror(_cond);
2058 }
2059
2060 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
2061 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
2062 void set_profiled_bci(int bci) { _profiled_bci = bci; }
2063 void set_swapped(bool value) { _swapped = value; }
2064 bool substitutability_check() const { return _substitutability_check; }
2065 // generic
2066 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
2067 };
2068
2069
2070 BASE(Switch, BlockEnd)
2071 private:
2072 Value _tag;
2073
2074 public:
2075 // creation
2076 Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
2077 : BlockEnd(illegalType, state_before, is_safepoint)
2078 , _tag(tag) {
2079 ASSERT_VALUES
2080 set_sux(sux);
2081 }
2082
2083 // accessors
2084 Value tag() const { return _tag; }
2355 }
2356 }
2357 };
2358
2359 LEAF(ProfileReturnType, Instruction)
2360 private:
2361 ciMethod* _method;
2362 ciMethod* _callee;
2363 int _bci_of_invoke;
2364 Value _ret;
2365
2366 public:
2367 ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)
2368 : Instruction(voidType)
2369 , _method(method)
2370 , _callee(callee)
2371 , _bci_of_invoke(bci)
2372 , _ret(ret)
2373 {
2374 set_needs_null_check(true);
2375 // The ProfileReturnType has side-effects and must occur precisely where located
2376 pin();
2377 }
2378
2379 ciMethod* method() const { return _method; }
2380 ciMethod* callee() const { return _callee; }
2381 int bci_of_invoke() const { return _bci_of_invoke; }
2382 Value ret() const { return _ret; }
2383
2384 virtual void input_values_do(ValueVisitor* f) {
2385 if (_ret != nullptr) {
2386 f->visit(&_ret);
2387 }
2388 }
2389 };
2390
2391 LEAF(ProfileACmpTypes, Instruction)
2392 private:
2393 ciMethod* _method;
2394 int _bci;
2395 Value _left;
2396 Value _right;
2397 bool _left_maybe_null;
2398 bool _right_maybe_null;
2399
2400 public:
2401 ProfileACmpTypes(ciMethod* method, int bci, Value left, Value right)
2402 : Instruction(voidType)
2403 , _method(method)
2404 , _bci(bci)
2405 , _left(left)
2406 , _right(right)
2407 {
2408 // The ProfileACmp has side-effects and must occur precisely where located
2409 pin();
2410 _left_maybe_null = true;
2411 _right_maybe_null = true;
2412 }
2413
2414 ciMethod* method() const { return _method; }
2415 int bci() const { return _bci; }
2416 Value left() const { return _left; }
2417 Value right() const { return _right; }
2418 bool left_maybe_null() const { return _left_maybe_null; }
2419 bool right_maybe_null() const { return _right_maybe_null; }
2420 void set_left_maybe_null(bool v) { _left_maybe_null = v; }
2421 void set_right_maybe_null(bool v) { _right_maybe_null = v; }
2422
2423 virtual void input_values_do(ValueVisitor* f) {
2424 if (_left != nullptr) {
2425 f->visit(&_left);
2426 }
2427 if (_right != nullptr) {
2428 f->visit(&_right);
2429 }
2430 }
2431 };
2432
2433 // Call some C runtime function that doesn't safepoint,
2434 // optionally passing the current thread as the first argument.
2435 LEAF(RuntimeCall, Instruction)
2436 private:
2437 const char* _entry_name;
2438 address _entry;
2439 Values* _args;
2440 bool _pass_thread; // Pass the JavaThread* as an implicit first argument
2441
2442 public:
2443 RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2444 : Instruction(type)
2445 , _entry_name(entry_name)
2446 , _entry(entry)
2447 , _args(args)
2448 , _pass_thread(pass_thread) {
2449 ASSERT_VALUES
2450 pin();
2451 }
2452
|