Thu, 29 Sep 2011 23:09:54 -0700
7096639: Tiered: Incorrect counter overflow handling for inlined methods
Summary: Enable invocation events for inlinees
Reviewed-by: kvn
1 /*
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #ifndef SHARE_VM_C1_C1_INSTRUCTION_HPP
26 #define SHARE_VM_C1_C1_INSTRUCTION_HPP
28 #include "c1/c1_Compilation.hpp"
29 #include "c1/c1_LIR.hpp"
30 #include "c1/c1_ValueType.hpp"
31 #include "ci/ciField.hpp"
33 // Predefined classes
34 class ciField;
35 class ValueStack;
36 class InstructionPrinter;
37 class IRScope;
38 class LIR_OprDesc;
39 typedef LIR_OprDesc* LIR_Opr;
42 // Instruction class hierarchy
43 //
44 // All leaf classes in the class hierarchy are concrete classes
45 // (i.e., are instantiated). All other classes are abstract and
46 // serve factoring.
48 class Instruction;
49 class Phi;
50 class Local;
51 class Constant;
52 class AccessField;
53 class LoadField;
54 class StoreField;
55 class AccessArray;
56 class ArrayLength;
57 class AccessIndexed;
58 class LoadIndexed;
59 class StoreIndexed;
60 class NegateOp;
61 class Op2;
62 class ArithmeticOp;
63 class ShiftOp;
64 class LogicOp;
65 class CompareOp;
66 class IfOp;
67 class Convert;
68 class NullCheck;
69 class OsrEntry;
70 class ExceptionObject;
71 class StateSplit;
72 class Invoke;
73 class NewInstance;
74 class NewArray;
75 class NewTypeArray;
76 class NewObjectArray;
77 class NewMultiArray;
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 IfInstanceOf;
90 class Switch;
91 class TableSwitch;
92 class LookupSwitch;
93 class Return;
94 class Throw;
95 class Base;
96 class RoundFP;
97 class UnsafeOp;
98 class UnsafeRawOp;
99 class UnsafeGetRaw;
100 class UnsafePutRaw;
101 class UnsafeObjectOp;
102 class UnsafeGetObject;
103 class UnsafePutObject;
104 class UnsafePrefetch;
105 class UnsafePrefetchRead;
106 class UnsafePrefetchWrite;
107 class ProfileCall;
108 class ProfileInvoke;
109 class RuntimeCall;
111 // A Value is a reference to the instruction creating the value
112 typedef Instruction* Value;
113 define_array(ValueArray, Value)
114 define_stack(Values, ValueArray)
116 define_array(ValueStackArray, ValueStack*)
117 define_stack(ValueStackStack, ValueStackArray)
119 // BlockClosure is the base class for block traversal/iteration.
121 class BlockClosure: public CompilationResourceObj {
122 public:
123 virtual void block_do(BlockBegin* block) = 0;
124 };
127 // A simple closure class for visiting the values of an Instruction
128 class ValueVisitor: public StackObj {
129 public:
130 virtual void visit(Value* v) = 0;
131 };
134 // Some array and list classes
135 define_array(BlockBeginArray, BlockBegin*)
136 define_stack(_BlockList, BlockBeginArray)
138 class BlockList: public _BlockList {
139 public:
140 BlockList(): _BlockList() {}
141 BlockList(const int size): _BlockList(size) {}
142 BlockList(const int size, BlockBegin* init): _BlockList(size, init) {}
144 void iterate_forward(BlockClosure* closure);
145 void iterate_backward(BlockClosure* closure);
146 void blocks_do(void f(BlockBegin*));
147 void values_do(ValueVisitor* f);
148 void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN;
149 };
152 // InstructionVisitors provide type-based dispatch for instructions.
153 // For each concrete Instruction class X, a virtual function do_X is
154 // provided. Functionality that needs to be implemented for all classes
155 // (e.g., printing, code generation) is factored out into a specialised
156 // visitor instead of added to the Instruction classes itself.
158 class InstructionVisitor: public StackObj {
159 public:
160 virtual void do_Phi (Phi* x) = 0;
161 virtual void do_Local (Local* x) = 0;
162 virtual void do_Constant (Constant* x) = 0;
163 virtual void do_LoadField (LoadField* x) = 0;
164 virtual void do_StoreField (StoreField* x) = 0;
165 virtual void do_ArrayLength (ArrayLength* x) = 0;
166 virtual void do_LoadIndexed (LoadIndexed* x) = 0;
167 virtual void do_StoreIndexed (StoreIndexed* x) = 0;
168 virtual void do_NegateOp (NegateOp* x) = 0;
169 virtual void do_ArithmeticOp (ArithmeticOp* x) = 0;
170 virtual void do_ShiftOp (ShiftOp* x) = 0;
171 virtual void do_LogicOp (LogicOp* x) = 0;
172 virtual void do_CompareOp (CompareOp* x) = 0;
173 virtual void do_IfOp (IfOp* x) = 0;
174 virtual void do_Convert (Convert* x) = 0;
175 virtual void do_NullCheck (NullCheck* x) = 0;
176 virtual void do_Invoke (Invoke* x) = 0;
177 virtual void do_NewInstance (NewInstance* x) = 0;
178 virtual void do_NewTypeArray (NewTypeArray* x) = 0;
179 virtual void do_NewObjectArray (NewObjectArray* x) = 0;
180 virtual void do_NewMultiArray (NewMultiArray* x) = 0;
181 virtual void do_CheckCast (CheckCast* x) = 0;
182 virtual void do_InstanceOf (InstanceOf* x) = 0;
183 virtual void do_MonitorEnter (MonitorEnter* x) = 0;
184 virtual void do_MonitorExit (MonitorExit* x) = 0;
185 virtual void do_Intrinsic (Intrinsic* x) = 0;
186 virtual void do_BlockBegin (BlockBegin* x) = 0;
187 virtual void do_Goto (Goto* x) = 0;
188 virtual void do_If (If* x) = 0;
189 virtual void do_IfInstanceOf (IfInstanceOf* x) = 0;
190 virtual void do_TableSwitch (TableSwitch* x) = 0;
191 virtual void do_LookupSwitch (LookupSwitch* x) = 0;
192 virtual void do_Return (Return* x) = 0;
193 virtual void do_Throw (Throw* x) = 0;
194 virtual void do_Base (Base* x) = 0;
195 virtual void do_OsrEntry (OsrEntry* x) = 0;
196 virtual void do_ExceptionObject(ExceptionObject* x) = 0;
197 virtual void do_RoundFP (RoundFP* x) = 0;
198 virtual void do_UnsafeGetRaw (UnsafeGetRaw* x) = 0;
199 virtual void do_UnsafePutRaw (UnsafePutRaw* x) = 0;
200 virtual void do_UnsafeGetObject(UnsafeGetObject* x) = 0;
201 virtual void do_UnsafePutObject(UnsafePutObject* x) = 0;
202 virtual void do_UnsafePrefetchRead (UnsafePrefetchRead* x) = 0;
203 virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) = 0;
204 virtual void do_ProfileCall (ProfileCall* x) = 0;
205 virtual void do_ProfileInvoke (ProfileInvoke* x) = 0;
206 virtual void do_RuntimeCall (RuntimeCall* x) = 0;
207 };
210 // Hashing support
211 //
212 // Note: This hash functions affect the performance
213 // of ValueMap - make changes carefully!
215 #define HASH1(x1 ) ((intx)(x1))
216 #define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2))
217 #define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3))
218 #define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))
221 // The following macros are used to implement instruction-specific hashing.
222 // By default, each instruction implements hash() and is_equal(Value), used
223 // for value numbering/common subexpression elimination. The default imple-
224 // mentation disables value numbering. Each instruction which can be value-
225 // numbered, should define corresponding hash() and is_equal(Value) functions
226 // via the macros below. The f arguments specify all the values/op codes, etc.
227 // that need to be identical for two instructions to be identical.
228 //
229 // Note: The default implementation of hash() returns 0 in order to indicate
230 // that the instruction should not be considered for value numbering.
231 // The currently used hash functions do not guarantee that never a 0
232 // is produced. While this is still correct, it may be a performance
233 // bug (no value numbering for that node). However, this situation is
234 // so unlikely, that we are not going to handle it specially.
236 #define HASHING1(class_name, enabled, f1) \
237 virtual intx hash() const { \
238 return (enabled) ? HASH2(name(), f1) : 0; \
239 } \
240 virtual bool is_equal(Value v) const { \
241 if (!(enabled) ) return false; \
242 class_name* _v = v->as_##class_name(); \
243 if (_v == NULL ) return false; \
244 if (f1 != _v->f1) return false; \
245 return true; \
246 } \
249 #define HASHING2(class_name, enabled, f1, f2) \
250 virtual intx hash() const { \
251 return (enabled) ? HASH3(name(), f1, f2) : 0; \
252 } \
253 virtual bool is_equal(Value v) const { \
254 if (!(enabled) ) return false; \
255 class_name* _v = v->as_##class_name(); \
256 if (_v == NULL ) return false; \
257 if (f1 != _v->f1) return false; \
258 if (f2 != _v->f2) return false; \
259 return true; \
260 } \
263 #define HASHING3(class_name, enabled, f1, f2, f3) \
264 virtual intx hash() const { \
265 return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
266 } \
267 virtual bool is_equal(Value v) const { \
268 if (!(enabled) ) return false; \
269 class_name* _v = v->as_##class_name(); \
270 if (_v == NULL ) return false; \
271 if (f1 != _v->f1) return false; \
272 if (f2 != _v->f2) return false; \
273 if (f3 != _v->f3) return false; \
274 return true; \
275 } \
278 // The mother of all instructions...
280 class Instruction: public CompilationResourceObj {
281 private:
282 int _id; // the unique instruction id
283 #ifndef PRODUCT
284 int _printable_bci; // the bci of the instruction for printing
285 #endif
286 int _use_count; // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1
287 int _pin_state; // set of PinReason describing the reason for pinning
288 ValueType* _type; // the instruction value type
289 Instruction* _next; // the next instruction if any (NULL for BlockEnd instructions)
290 Instruction* _subst; // the substitution instruction if any
291 LIR_Opr _operand; // LIR specific information
292 unsigned int _flags; // Flag bits
294 ValueStack* _state_before; // Copy of state with input operands still on stack (or NULL)
295 ValueStack* _exception_state; // Copy of state for exception handling
296 XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction
298 friend class UseCountComputer;
299 friend class BlockBegin;
301 void update_exception_state(ValueStack* state);
303 bool has_printable_bci() const { return NOT_PRODUCT(_printable_bci != -99) PRODUCT_ONLY(false); }
305 protected:
306 void set_type(ValueType* type) {
307 assert(type != NULL, "type must exist");
308 _type = type;
309 }
311 public:
312 void* operator new(size_t size) {
313 Compilation* c = Compilation::current();
314 void* res = c->arena()->Amalloc(size);
315 ((Instruction*)res)->_id = c->get_next_id();
316 return res;
317 }
319 static const int no_bci = -99;
321 enum InstructionFlag {
322 NeedsNullCheckFlag = 0,
323 CanTrapFlag,
324 DirectCompareFlag,
325 IsEliminatedFlag,
326 IsSafepointFlag,
327 IsStaticFlag,
328 IsStrictfpFlag,
329 NeedsStoreCheckFlag,
330 NeedsWriteBarrierFlag,
331 PreservesStateFlag,
332 TargetIsFinalFlag,
333 TargetIsLoadedFlag,
334 TargetIsStrictfpFlag,
335 UnorderedIsTrueFlag,
336 NeedsPatchingFlag,
337 ThrowIncompatibleClassChangeErrorFlag,
338 ProfileMDOFlag,
339 IsLinkedInBlockFlag,
340 InstructionLastFlag
341 };
343 public:
344 bool check_flag(InstructionFlag id) const { return (_flags & (1 << id)) != 0; }
345 void set_flag(InstructionFlag id, bool f) { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); };
347 // 'globally' used condition values
348 enum Condition {
349 eql, neq, lss, leq, gtr, geq
350 };
352 // Instructions may be pinned for many reasons and under certain conditions
353 // with enough knowledge it's possible to safely unpin them.
354 enum PinReason {
355 PinUnknown = 1 << 0
356 , PinExplicitNullCheck = 1 << 3
357 , PinStackForStateSplit= 1 << 12
358 , PinStateSplitConstructor= 1 << 13
359 , PinGlobalValueNumbering= 1 << 14
360 };
362 static Condition mirror(Condition cond);
363 static Condition negate(Condition cond);
365 // initialization
366 static int number_of_instructions() {
367 return Compilation::current()->number_of_instructions();
368 }
370 // creation
371 Instruction(ValueType* type, ValueStack* state_before = NULL, bool type_is_constant = false)
372 : _use_count(0)
373 #ifndef PRODUCT
374 , _printable_bci(-99)
375 #endif
376 , _pin_state(0)
377 , _type(type)
378 , _next(NULL)
379 , _subst(NULL)
380 , _flags(0)
381 , _operand(LIR_OprFact::illegalOpr)
382 , _state_before(state_before)
383 , _exception_handlers(NULL)
384 {
385 check_state(state_before);
386 assert(type != NULL && (!type->is_constant() || type_is_constant), "type must exist");
387 update_exception_state(_state_before);
388 }
390 // accessors
391 int id() const { return _id; }
392 #ifndef PRODUCT
393 int printable_bci() const { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
394 void set_printable_bci(int bci) { NOT_PRODUCT(_printable_bci = bci;) }
395 #endif
396 int use_count() const { return _use_count; }
397 int pin_state() const { return _pin_state; }
398 bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; }
399 ValueType* type() const { return _type; }
400 Instruction* prev(BlockBegin* block); // use carefully, expensive operation
401 Instruction* next() const { return _next; }
402 bool has_subst() const { return _subst != NULL; }
403 Instruction* subst() { return _subst == NULL ? this : _subst->subst(); }
404 LIR_Opr operand() const { return _operand; }
406 void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); }
407 bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); }
408 bool is_linked() const { return check_flag(IsLinkedInBlockFlag); }
409 bool can_be_linked() { return as_Local() == NULL && as_Phi() == NULL; }
411 bool has_uses() const { return use_count() > 0; }
412 ValueStack* state_before() const { return _state_before; }
413 ValueStack* exception_state() const { return _exception_state; }
414 virtual bool needs_exception_state() const { return true; }
415 XHandlers* exception_handlers() const { return _exception_handlers; }
417 // manipulation
418 void pin(PinReason reason) { _pin_state |= reason; }
419 void pin() { _pin_state |= PinUnknown; }
420 // DANGEROUS: only used by EliminateStores
421 void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
423 Instruction* set_next(Instruction* next) {
424 assert(next->has_printable_bci(), "_printable_bci should have been set");
425 assert(next != NULL, "must not be NULL");
426 assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");
427 assert(next->can_be_linked(), "shouldn't link these instructions into list");
429 next->set_flag(Instruction::IsLinkedInBlockFlag, true);
430 _next = next;
431 return next;
432 }
434 Instruction* set_next(Instruction* next, int bci) {
435 #ifndef PRODUCT
436 next->set_printable_bci(bci);
437 #endif
438 return set_next(next);
439 }
441 void set_subst(Instruction* subst) {
442 assert(subst == NULL ||
443 type()->base() == subst->type()->base() ||
444 subst->type()->base() == illegalType, "type can't change");
445 _subst = subst;
446 }
447 void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
448 void set_exception_state(ValueStack* s) { check_state(s); _exception_state = s; }
450 // machine-specifics
451 void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
452 void clear_operand() { _operand = LIR_OprFact::illegalOpr; }
454 // generic
455 virtual Instruction* as_Instruction() { return this; } // to satisfy HASHING1 macro
456 virtual Phi* as_Phi() { return NULL; }
457 virtual Local* as_Local() { return NULL; }
458 virtual Constant* as_Constant() { return NULL; }
459 virtual AccessField* as_AccessField() { return NULL; }
460 virtual LoadField* as_LoadField() { return NULL; }
461 virtual StoreField* as_StoreField() { return NULL; }
462 virtual AccessArray* as_AccessArray() { return NULL; }
463 virtual ArrayLength* as_ArrayLength() { return NULL; }
464 virtual AccessIndexed* as_AccessIndexed() { return NULL; }
465 virtual LoadIndexed* as_LoadIndexed() { return NULL; }
466 virtual StoreIndexed* as_StoreIndexed() { return NULL; }
467 virtual NegateOp* as_NegateOp() { return NULL; }
468 virtual Op2* as_Op2() { return NULL; }
469 virtual ArithmeticOp* as_ArithmeticOp() { return NULL; }
470 virtual ShiftOp* as_ShiftOp() { return NULL; }
471 virtual LogicOp* as_LogicOp() { return NULL; }
472 virtual CompareOp* as_CompareOp() { return NULL; }
473 virtual IfOp* as_IfOp() { return NULL; }
474 virtual Convert* as_Convert() { return NULL; }
475 virtual NullCheck* as_NullCheck() { return NULL; }
476 virtual OsrEntry* as_OsrEntry() { return NULL; }
477 virtual StateSplit* as_StateSplit() { return NULL; }
478 virtual Invoke* as_Invoke() { return NULL; }
479 virtual NewInstance* as_NewInstance() { return NULL; }
480 virtual NewArray* as_NewArray() { return NULL; }
481 virtual NewTypeArray* as_NewTypeArray() { return NULL; }
482 virtual NewObjectArray* as_NewObjectArray() { return NULL; }
483 virtual NewMultiArray* as_NewMultiArray() { return NULL; }
484 virtual TypeCheck* as_TypeCheck() { return NULL; }
485 virtual CheckCast* as_CheckCast() { return NULL; }
486 virtual InstanceOf* as_InstanceOf() { return NULL; }
487 virtual AccessMonitor* as_AccessMonitor() { return NULL; }
488 virtual MonitorEnter* as_MonitorEnter() { return NULL; }
489 virtual MonitorExit* as_MonitorExit() { return NULL; }
490 virtual Intrinsic* as_Intrinsic() { return NULL; }
491 virtual BlockBegin* as_BlockBegin() { return NULL; }
492 virtual BlockEnd* as_BlockEnd() { return NULL; }
493 virtual Goto* as_Goto() { return NULL; }
494 virtual If* as_If() { return NULL; }
495 virtual IfInstanceOf* as_IfInstanceOf() { return NULL; }
496 virtual TableSwitch* as_TableSwitch() { return NULL; }
497 virtual LookupSwitch* as_LookupSwitch() { return NULL; }
498 virtual Return* as_Return() { return NULL; }
499 virtual Throw* as_Throw() { return NULL; }
500 virtual Base* as_Base() { return NULL; }
501 virtual RoundFP* as_RoundFP() { return NULL; }
502 virtual ExceptionObject* as_ExceptionObject() { return NULL; }
503 virtual UnsafeOp* as_UnsafeOp() { return NULL; }
505 virtual void visit(InstructionVisitor* v) = 0;
507 virtual bool can_trap() const { return false; }
509 virtual void input_values_do(ValueVisitor* f) = 0;
510 virtual void state_values_do(ValueVisitor* f);
511 virtual void other_values_do(ValueVisitor* f) { /* usually no other - override on demand */ }
512 void values_do(ValueVisitor* f) { input_values_do(f); state_values_do(f); other_values_do(f); }
514 virtual ciType* exact_type() const { return NULL; }
515 virtual ciType* declared_type() const { return NULL; }
517 // hashing
518 virtual const char* name() const = 0;
519 HASHING1(Instruction, false, id()) // hashing disabled by default
521 // debugging
522 static void check_state(ValueStack* state) PRODUCT_RETURN;
523 void print() PRODUCT_RETURN;
524 void print_line() PRODUCT_RETURN;
525 void print(InstructionPrinter& ip) PRODUCT_RETURN;
526 };
529 // The following macros are used to define base (i.e., non-leaf)
530 // and leaf instruction classes. They define class-name related
531 // generic functionality in one place.
533 #define BASE(class_name, super_class_name) \
534 class class_name: public super_class_name { \
535 public: \
536 virtual class_name* as_##class_name() { return this; } \
539 #define LEAF(class_name, super_class_name) \
540 BASE(class_name, super_class_name) \
541 public: \
542 virtual const char* name() const { return #class_name; } \
543 virtual void visit(InstructionVisitor* v) { v->do_##class_name(this); } \
546 // Debugging support
549 #ifdef ASSERT
550 class AssertValues: public ValueVisitor {
551 void visit(Value* x) { assert((*x) != NULL, "value must exist"); }
552 };
553 #define ASSERT_VALUES { AssertValues assert_value; values_do(&assert_value); }
554 #else
555 #define ASSERT_VALUES
556 #endif // ASSERT
559 // A Phi is a phi function in the sense of SSA form. It stands for
560 // the value of a local variable at the beginning of a join block.
561 // A Phi consists of n operands, one for every incoming branch.
563 LEAF(Phi, Instruction)
564 private:
565 BlockBegin* _block; // the block to which the phi function belongs
566 int _pf_flags; // the flags of the phi function
567 int _index; // to value on operand stack (index < 0) or to local
568 public:
569 // creation
570 Phi(ValueType* type, BlockBegin* b, int index)
571 : Instruction(type->base())
572 , _pf_flags(0)
573 , _block(b)
574 , _index(index)
575 {
576 if (type->is_illegal()) {
577 make_illegal();
578 }
579 }
581 // flags
582 enum Flag {
583 no_flag = 0,
584 visited = 1 << 0,
585 cannot_simplify = 1 << 1
586 };
588 // accessors
589 bool is_local() const { return _index >= 0; }
590 bool is_on_stack() const { return !is_local(); }
591 int local_index() const { assert(is_local(), ""); return _index; }
592 int stack_index() const { assert(is_on_stack(), ""); return -(_index+1); }
594 Value operand_at(int i) const;
595 int operand_count() const;
597 BlockBegin* block() const { return _block; }
599 void set(Flag f) { _pf_flags |= f; }
600 void clear(Flag f) { _pf_flags &= ~f; }
601 bool is_set(Flag f) const { return (_pf_flags & f) != 0; }
603 // Invalidates phis corresponding to merges of locals of two different types
604 // (these should never be referenced, otherwise the bytecodes are illegal)
605 void make_illegal() {
606 set(cannot_simplify);
607 set_type(illegalType);
608 }
610 bool is_illegal() const {
611 return type()->is_illegal();
612 }
614 // generic
615 virtual void input_values_do(ValueVisitor* f) {
616 }
617 };
620 // A local is a placeholder for an incoming argument to a function call.
621 LEAF(Local, Instruction)
622 private:
623 int _java_index; // the local index within the method to which the local belongs
624 ciType* _declared_type;
625 public:
626 // creation
627 Local(ciType* declared, ValueType* type, int index)
628 : Instruction(type)
629 , _java_index(index)
630 , _declared_type(declared)
631 {}
633 // accessors
634 int java_index() const { return _java_index; }
636 ciType* declared_type() const { return _declared_type; }
637 ciType* exact_type() const;
639 // generic
640 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
641 };
644 LEAF(Constant, Instruction)
645 public:
646 // creation
647 Constant(ValueType* type):
648 Instruction(type, NULL, true)
649 {
650 assert(type->is_constant(), "must be a constant");
651 }
653 Constant(ValueType* type, ValueStack* state_before):
654 Instruction(type, state_before, true)
655 {
656 assert(state_before != NULL, "only used for constants which need patching");
657 assert(type->is_constant(), "must be a constant");
658 // since it's patching it needs to be pinned
659 pin();
660 }
662 virtual bool can_trap() const { return state_before() != NULL; }
663 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
665 virtual intx hash() const;
666 virtual bool is_equal(Value v) const;
669 enum CompareResult { not_comparable = -1, cond_false, cond_true };
671 virtual CompareResult compare(Instruction::Condition condition, Value right) const;
672 BlockBegin* compare(Instruction::Condition cond, Value right,
673 BlockBegin* true_sux, BlockBegin* false_sux) const {
674 switch (compare(cond, right)) {
675 case not_comparable:
676 return NULL;
677 case cond_false:
678 return false_sux;
679 case cond_true:
680 return true_sux;
681 default:
682 ShouldNotReachHere();
683 return NULL;
684 }
685 }
686 };
689 BASE(AccessField, Instruction)
690 private:
691 Value _obj;
692 int _offset;
693 ciField* _field;
694 NullCheck* _explicit_null_check; // For explicit null check elimination
696 public:
697 // creation
698 AccessField(Value obj, int offset, ciField* field, bool is_static,
699 ValueStack* state_before, bool needs_patching)
700 : Instruction(as_ValueType(field->type()->basic_type()), state_before)
701 , _obj(obj)
702 , _offset(offset)
703 , _field(field)
704 , _explicit_null_check(NULL)
705 {
706 set_needs_null_check(!is_static);
707 set_flag(IsStaticFlag, is_static);
708 set_flag(NeedsPatchingFlag, needs_patching);
709 ASSERT_VALUES
710 // pin of all instructions with memory access
711 pin();
712 }
714 // accessors
715 Value obj() const { return _obj; }
716 int offset() const { return _offset; }
717 ciField* field() const { return _field; }
718 BasicType field_type() const { return _field->type()->basic_type(); }
719 bool is_static() const { return check_flag(IsStaticFlag); }
720 NullCheck* explicit_null_check() const { return _explicit_null_check; }
721 bool needs_patching() const { return check_flag(NeedsPatchingFlag); }
723 // Unresolved getstatic and putstatic can cause initialization.
724 // Technically it occurs at the Constant that materializes the base
725 // of the static fields but it's simpler to model it here.
726 bool is_init_point() const { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); }
728 // manipulation
730 // Under certain circumstances, if a previous NullCheck instruction
731 // proved the target object non-null, we can eliminate the explicit
732 // null check and do an implicit one, simply specifying the debug
733 // information from the NullCheck. This field should only be consulted
734 // if needs_null_check() is true.
735 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
737 // generic
738 virtual bool can_trap() const { return needs_null_check() || needs_patching(); }
739 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
740 };
743 LEAF(LoadField, AccessField)
744 public:
745 // creation
746 LoadField(Value obj, int offset, ciField* field, bool is_static,
747 ValueStack* state_before, bool needs_patching)
748 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
749 {}
751 ciType* declared_type() const;
752 ciType* exact_type() const;
754 // generic
755 HASHING2(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset()) // cannot be eliminated if needs patching or if volatile
756 };
759 LEAF(StoreField, AccessField)
760 private:
761 Value _value;
763 public:
764 // creation
765 StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
766 ValueStack* state_before, bool needs_patching)
767 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
768 , _value(value)
769 {
770 set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
771 ASSERT_VALUES
772 pin();
773 }
775 // accessors
776 Value value() const { return _value; }
777 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
779 // generic
780 virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); }
781 };
784 BASE(AccessArray, Instruction)
785 private:
786 Value _array;
788 public:
789 // creation
790 AccessArray(ValueType* type, Value array, ValueStack* state_before)
791 : Instruction(type, state_before)
792 , _array(array)
793 {
794 set_needs_null_check(true);
795 ASSERT_VALUES
796 pin(); // instruction with side effect (null exception or range check throwing)
797 }
799 Value array() const { return _array; }
801 // generic
802 virtual bool can_trap() const { return needs_null_check(); }
803 virtual void input_values_do(ValueVisitor* f) { f->visit(&_array); }
804 };
807 LEAF(ArrayLength, AccessArray)
808 private:
809 NullCheck* _explicit_null_check; // For explicit null check elimination
811 public:
812 // creation
813 ArrayLength(Value array, ValueStack* state_before)
814 : AccessArray(intType, array, state_before)
815 , _explicit_null_check(NULL) {}
817 // accessors
818 NullCheck* explicit_null_check() const { return _explicit_null_check; }
820 // setters
821 // See LoadField::set_explicit_null_check for documentation
822 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
824 // generic
825 HASHING1(ArrayLength, true, array()->subst())
826 };
829 BASE(AccessIndexed, AccessArray)
830 private:
831 Value _index;
832 Value _length;
833 BasicType _elt_type;
835 public:
836 // creation
837 AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
838 : AccessArray(as_ValueType(elt_type), array, state_before)
839 , _index(index)
840 , _length(length)
841 , _elt_type(elt_type)
842 {
843 ASSERT_VALUES
844 }
846 // accessors
847 Value index() const { return _index; }
848 Value length() const { return _length; }
849 BasicType elt_type() const { return _elt_type; }
851 // perform elimination of range checks involving constants
852 bool compute_needs_range_check();
854 // generic
855 virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }
856 };
859 LEAF(LoadIndexed, AccessIndexed)
860 private:
861 NullCheck* _explicit_null_check; // For explicit null check elimination
863 public:
864 // creation
865 LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
866 : AccessIndexed(array, index, length, elt_type, state_before)
867 , _explicit_null_check(NULL) {}
869 // accessors
870 NullCheck* explicit_null_check() const { return _explicit_null_check; }
872 // setters
873 // See LoadField::set_explicit_null_check for documentation
874 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
876 ciType* exact_type() const;
877 ciType* declared_type() const;
879 // generic
880 HASHING2(LoadIndexed, true, array()->subst(), index()->subst())
881 };
884 LEAF(StoreIndexed, AccessIndexed)
885 private:
886 Value _value;
888 ciMethod* _profiled_method;
889 int _profiled_bci;
890 public:
891 // creation
892 StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before)
893 : AccessIndexed(array, index, length, elt_type, state_before)
894 , _value(value), _profiled_method(NULL), _profiled_bci(0)
895 {
896 set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
897 set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
898 ASSERT_VALUES
899 pin();
900 }
902 // accessors
903 Value value() const { return _value; }
904 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
905 bool needs_store_check() const { return check_flag(NeedsStoreCheckFlag); }
906 // Helpers for methodDataOop profiling
907 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
908 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
909 void set_profiled_bci(int bci) { _profiled_bci = bci; }
910 bool should_profile() const { return check_flag(ProfileMDOFlag); }
911 ciMethod* profiled_method() const { return _profiled_method; }
912 int profiled_bci() const { return _profiled_bci; }
913 // generic
914 virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); }
915 };
918 LEAF(NegateOp, Instruction)
919 private:
920 Value _x;
922 public:
923 // creation
924 NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
925 ASSERT_VALUES
926 }
928 // accessors
929 Value x() const { return _x; }
931 // generic
932 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); }
933 };
936 BASE(Op2, Instruction)
937 private:
938 Bytecodes::Code _op;
939 Value _x;
940 Value _y;
942 public:
943 // creation
944 Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = NULL)
945 : Instruction(type, state_before)
946 , _op(op)
947 , _x(x)
948 , _y(y)
949 {
950 ASSERT_VALUES
951 }
953 // accessors
954 Bytecodes::Code op() const { return _op; }
955 Value x() const { return _x; }
956 Value y() const { return _y; }
958 // manipulators
959 void swap_operands() {
960 assert(is_commutative(), "operation must be commutative");
961 Value t = _x; _x = _y; _y = t;
962 }
964 // generic
965 virtual bool is_commutative() const { return false; }
966 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); }
967 };
970 LEAF(ArithmeticOp, Op2)
971 public:
972 // creation
973 ArithmeticOp(Bytecodes::Code op, Value x, Value y, bool is_strictfp, ValueStack* state_before)
974 : Op2(x->type()->meet(y->type()), op, x, y, state_before)
975 {
976 set_flag(IsStrictfpFlag, is_strictfp);
977 if (can_trap()) pin();
978 }
980 // accessors
981 bool is_strictfp() const { return check_flag(IsStrictfpFlag); }
983 // generic
984 virtual bool is_commutative() const;
985 virtual bool can_trap() const;
986 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
987 };
990 LEAF(ShiftOp, Op2)
991 public:
992 // creation
993 ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}
995 // generic
996 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
997 };
1000 LEAF(LogicOp, Op2)
1001 public:
1002 // creation
1003 LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}
1005 // generic
1006 virtual bool is_commutative() const;
1007 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1008 };
1011 LEAF(CompareOp, Op2)
1012 public:
1013 // creation
1014 CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1015 : Op2(intType, op, x, y, state_before)
1016 {}
1018 // generic
1019 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1020 };
1023 LEAF(IfOp, Op2)
1024 private:
1025 Value _tval;
1026 Value _fval;
1028 public:
1029 // creation
1030 IfOp(Value x, Condition cond, Value y, Value tval, Value fval)
1031 : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1032 , _tval(tval)
1033 , _fval(fval)
1034 {
1035 ASSERT_VALUES
1036 assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1037 }
1039 // accessors
1040 virtual bool is_commutative() const;
1041 Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }
1042 Condition cond() const { return (Condition)Op2::op(); }
1043 Value tval() const { return _tval; }
1044 Value fval() const { return _fval; }
1046 // generic
1047 virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1048 };
1051 LEAF(Convert, Instruction)
1052 private:
1053 Bytecodes::Code _op;
1054 Value _value;
1056 public:
1057 // creation
1058 Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1059 ASSERT_VALUES
1060 }
1062 // accessors
1063 Bytecodes::Code op() const { return _op; }
1064 Value value() const { return _value; }
1066 // generic
1067 virtual void input_values_do(ValueVisitor* f) { f->visit(&_value); }
1068 HASHING2(Convert, true, op(), value()->subst())
1069 };
1072 LEAF(NullCheck, Instruction)
1073 private:
1074 Value _obj;
1076 public:
1077 // creation
1078 NullCheck(Value obj, ValueStack* state_before)
1079 : Instruction(obj->type()->base(), state_before)
1080 , _obj(obj)
1081 {
1082 ASSERT_VALUES
1083 set_can_trap(true);
1084 assert(_obj->type()->is_object(), "null check must be applied to objects only");
1085 pin(Instruction::PinExplicitNullCheck);
1086 }
1088 // accessors
1089 Value obj() const { return _obj; }
1091 // setters
1092 void set_can_trap(bool can_trap) { set_flag(CanTrapFlag, can_trap); }
1094 // generic
1095 virtual bool can_trap() const { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }
1096 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
1097 HASHING1(NullCheck, true, obj()->subst())
1098 };
1101 BASE(StateSplit, Instruction)
1102 private:
1103 ValueStack* _state;
1105 protected:
1106 static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);
1108 public:
1109 // creation
1110 StateSplit(ValueType* type, ValueStack* state_before = NULL)
1111 : Instruction(type, state_before)
1112 , _state(NULL)
1113 {
1114 pin(PinStateSplitConstructor);
1115 }
1117 // accessors
1118 ValueStack* state() const { return _state; }
1119 IRScope* scope() const; // the state's scope
1121 // manipulation
1122 void set_state(ValueStack* state) { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }
1124 // generic
1125 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
1126 virtual void state_values_do(ValueVisitor* f);
1127 };
1130 LEAF(Invoke, StateSplit)
1131 private:
1132 Bytecodes::Code _code;
1133 Value _recv;
1134 Values* _args;
1135 BasicTypeList* _signature;
1136 int _vtable_index;
1137 ciMethod* _target;
1139 public:
1140 // creation
1141 Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1142 int vtable_index, ciMethod* target, ValueStack* state_before);
1144 // accessors
1145 Bytecodes::Code code() const { return _code; }
1146 Value receiver() const { return _recv; }
1147 bool has_receiver() const { return receiver() != NULL; }
1148 int number_of_arguments() const { return _args->length(); }
1149 Value argument_at(int i) const { return _args->at(i); }
1150 int vtable_index() const { return _vtable_index; }
1151 BasicTypeList* signature() const { return _signature; }
1152 ciMethod* target() const { return _target; }
1154 ciType* declared_type() const;
1156 // Returns false if target is not loaded
1157 bool target_is_final() const { return check_flag(TargetIsFinalFlag); }
1158 bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }
1159 // Returns false if target is not loaded
1160 bool target_is_strictfp() const { return check_flag(TargetIsStrictfpFlag); }
1162 // JSR 292 support
1163 bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }
1165 virtual bool needs_exception_state() const { return false; }
1167 // generic
1168 virtual bool can_trap() const { return true; }
1169 virtual void input_values_do(ValueVisitor* f) {
1170 StateSplit::input_values_do(f);
1171 if (has_receiver()) f->visit(&_recv);
1172 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1173 }
1174 virtual void state_values_do(ValueVisitor *f);
1175 };
1178 LEAF(NewInstance, StateSplit)
1179 private:
1180 ciInstanceKlass* _klass;
1182 public:
1183 // creation
1184 NewInstance(ciInstanceKlass* klass, ValueStack* state_before)
1185 : StateSplit(instanceType, state_before)
1186 , _klass(klass)
1187 {}
1189 // accessors
1190 ciInstanceKlass* klass() const { return _klass; }
1192 virtual bool needs_exception_state() const { return false; }
1194 // generic
1195 virtual bool can_trap() const { return true; }
1196 ciType* exact_type() const;
1197 ciType* declared_type() const;
1198 };
1201 BASE(NewArray, StateSplit)
1202 private:
1203 Value _length;
1205 public:
1206 // creation
1207 NewArray(Value length, ValueStack* state_before)
1208 : StateSplit(objectType, state_before)
1209 , _length(length)
1210 {
1211 // Do not ASSERT_VALUES since length is NULL for NewMultiArray
1212 }
1214 // accessors
1215 Value length() const { return _length; }
1217 virtual bool needs_exception_state() const { return false; }
1219 ciType* declared_type() const;
1221 // generic
1222 virtual bool can_trap() const { return true; }
1223 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_length); }
1224 };
1227 LEAF(NewTypeArray, NewArray)
1228 private:
1229 BasicType _elt_type;
1231 public:
1232 // creation
1233 NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)
1234 : NewArray(length, state_before)
1235 , _elt_type(elt_type)
1236 {}
1238 // accessors
1239 BasicType elt_type() const { return _elt_type; }
1240 ciType* exact_type() const;
1241 };
1244 LEAF(NewObjectArray, NewArray)
1245 private:
1246 ciKlass* _klass;
1248 public:
1249 // creation
1250 NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}
1252 // accessors
1253 ciKlass* klass() const { return _klass; }
1254 ciType* exact_type() const;
1255 };
1258 LEAF(NewMultiArray, NewArray)
1259 private:
1260 ciKlass* _klass;
1261 Values* _dims;
1263 public:
1264 // creation
1265 NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
1266 ASSERT_VALUES
1267 }
1269 // accessors
1270 ciKlass* klass() const { return _klass; }
1271 Values* dims() const { return _dims; }
1272 int rank() const { return dims()->length(); }
1274 // generic
1275 virtual void input_values_do(ValueVisitor* f) {
1276 // NOTE: we do not call NewArray::input_values_do since "length"
1277 // is meaningless for a multi-dimensional array; passing the
1278 // zeroth element down to NewArray as its length is a bad idea
1279 // since there will be a copy in the "dims" array which doesn't
1280 // get updated, and the value must not be traversed twice. Was bug
1281 // - kbr 4/10/2001
1282 StateSplit::input_values_do(f);
1283 for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1284 }
1285 };
1288 BASE(TypeCheck, StateSplit)
1289 private:
1290 ciKlass* _klass;
1291 Value _obj;
1293 ciMethod* _profiled_method;
1294 int _profiled_bci;
1296 public:
1297 // creation
1298 TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1299 : StateSplit(type, state_before), _klass(klass), _obj(obj),
1300 _profiled_method(NULL), _profiled_bci(0) {
1301 ASSERT_VALUES
1302 set_direct_compare(false);
1303 }
1305 // accessors
1306 ciKlass* klass() const { return _klass; }
1307 Value obj() const { return _obj; }
1308 bool is_loaded() const { return klass() != NULL; }
1309 bool direct_compare() const { return check_flag(DirectCompareFlag); }
1311 // manipulation
1312 void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }
1314 // generic
1315 virtual bool can_trap() const { return true; }
1316 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1318 // Helpers for methodDataOop profiling
1319 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1320 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1321 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1322 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1323 ciMethod* profiled_method() const { return _profiled_method; }
1324 int profiled_bci() const { return _profiled_bci; }
1325 };
1328 LEAF(CheckCast, TypeCheck)
1329 public:
1330 // creation
1331 CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1332 : TypeCheck(klass, obj, objectType, state_before) {}
1334 void set_incompatible_class_change_check() {
1335 set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1336 }
1337 bool is_incompatible_class_change_check() const {
1338 return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1339 }
1341 ciType* declared_type() const;
1342 ciType* exact_type() const;
1343 };
1346 LEAF(InstanceOf, TypeCheck)
1347 public:
1348 // creation
1349 InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}
1351 virtual bool needs_exception_state() const { return false; }
1352 };
1355 BASE(AccessMonitor, StateSplit)
1356 private:
1357 Value _obj;
1358 int _monitor_no;
1360 public:
1361 // creation
1362 AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)
1363 : StateSplit(illegalType, state_before)
1364 , _obj(obj)
1365 , _monitor_no(monitor_no)
1366 {
1367 set_needs_null_check(true);
1368 ASSERT_VALUES
1369 }
1371 // accessors
1372 Value obj() const { return _obj; }
1373 int monitor_no() const { return _monitor_no; }
1375 // generic
1376 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1377 };
1380 LEAF(MonitorEnter, AccessMonitor)
1381 public:
1382 // creation
1383 MonitorEnter(Value obj, int monitor_no, ValueStack* state_before)
1384 : AccessMonitor(obj, monitor_no, state_before)
1385 {
1386 ASSERT_VALUES
1387 }
1389 // generic
1390 virtual bool can_trap() const { return true; }
1391 };
1394 LEAF(MonitorExit, AccessMonitor)
1395 public:
1396 // creation
1397 MonitorExit(Value obj, int monitor_no)
1398 : AccessMonitor(obj, monitor_no, NULL)
1399 {
1400 ASSERT_VALUES
1401 }
1402 };
1405 LEAF(Intrinsic, StateSplit)
1406 private:
1407 vmIntrinsics::ID _id;
1408 Values* _args;
1409 Value _recv;
1410 int _nonnull_state; // mask identifying which args are nonnull
1412 public:
1413 // preserves_state can be set to true for Intrinsics
1414 // which are guaranteed to preserve register state across any slow
1415 // cases; setting it to true does not mean that the Intrinsic can
1416 // not trap, only that if we continue execution in the same basic
1417 // block after the Intrinsic, all of the registers are intact. This
1418 // allows load elimination and common expression elimination to be
1419 // performed across the Intrinsic. The default value is false.
1420 Intrinsic(ValueType* type,
1421 vmIntrinsics::ID id,
1422 Values* args,
1423 bool has_receiver,
1424 ValueStack* state_before,
1425 bool preserves_state,
1426 bool cantrap = true)
1427 : StateSplit(type, state_before)
1428 , _id(id)
1429 , _args(args)
1430 , _recv(NULL)
1431 , _nonnull_state(AllBits)
1432 {
1433 assert(args != NULL, "args must exist");
1434 ASSERT_VALUES
1435 set_flag(PreservesStateFlag, preserves_state);
1436 set_flag(CanTrapFlag, cantrap);
1437 if (has_receiver) {
1438 _recv = argument_at(0);
1439 }
1440 set_needs_null_check(has_receiver);
1442 // some intrinsics can't trap, so don't force them to be pinned
1443 if (!can_trap()) {
1444 unpin(PinStateSplitConstructor);
1445 }
1446 }
1448 // accessors
1449 vmIntrinsics::ID id() const { return _id; }
1450 int number_of_arguments() const { return _args->length(); }
1451 Value argument_at(int i) const { return _args->at(i); }
1453 bool has_receiver() const { return (_recv != NULL); }
1454 Value receiver() const { assert(has_receiver(), "must have receiver"); return _recv; }
1455 bool preserves_state() const { return check_flag(PreservesStateFlag); }
1457 bool arg_needs_null_check(int i) {
1458 if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
1459 return is_set_nth_bit(_nonnull_state, i);
1460 }
1461 return true;
1462 }
1464 void set_arg_needs_null_check(int i, bool check) {
1465 if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
1466 if (check) {
1467 _nonnull_state |= nth_bit(i);
1468 } else {
1469 _nonnull_state &= ~(nth_bit(i));
1470 }
1471 }
1472 }
1474 // generic
1475 virtual bool can_trap() const { return check_flag(CanTrapFlag); }
1476 virtual void input_values_do(ValueVisitor* f) {
1477 StateSplit::input_values_do(f);
1478 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1479 }
1480 };
1483 class LIR_List;
1485 LEAF(BlockBegin, StateSplit)
1486 private:
1487 int _block_id; // the unique block id
1488 int _bci; // start-bci of block
1489 int _depth_first_number; // number of this block in a depth-first ordering
1490 int _linear_scan_number; // number of this block in linear-scan ordering
1491 int _loop_depth; // the loop nesting level of this block
1492 int _loop_index; // number of the innermost loop of this block
1493 int _flags; // the flags associated with this block
1495 // fields used by BlockListBuilder
1496 int _total_preds; // number of predecessors found by BlockListBuilder
1497 BitMap _stores_to_locals; // bit is set when a local variable is stored in the block
1499 // SSA specific fields: (factor out later)
1500 BlockList _successors; // the successors of this block
1501 BlockList _predecessors; // the predecessors of this block
1502 BlockBegin* _dominator; // the dominator of this block
1503 // SSA specific ends
1504 BlockEnd* _end; // the last instruction of this block
1505 BlockList _exception_handlers; // the exception handlers potentially invoked by this block
1506 ValueStackStack* _exception_states; // only for xhandler entries: states of all instructions that have an edge to this xhandler
1507 int _exception_handler_pco; // if this block is the start of an exception handler,
1508 // this records the PC offset in the assembly code of the
1509 // first instruction in this block
1510 Label _label; // the label associated with this block
1511 LIR_List* _lir; // the low level intermediate representation for this block
1513 BitMap _live_in; // set of live LIR_Opr registers at entry to this block
1514 BitMap _live_out; // set of live LIR_Opr registers at exit from this block
1515 BitMap _live_gen; // set of registers used before any redefinition in this block
1516 BitMap _live_kill; // set of registers defined in this block
1518 BitMap _fpu_register_usage;
1519 intArray* _fpu_stack_state; // For x86 FPU code generation with UseLinearScan
1520 int _first_lir_instruction_id; // ID of first LIR instruction in this block
1521 int _last_lir_instruction_id; // ID of last LIR instruction in this block
1523 void iterate_preorder (boolArray& mark, BlockClosure* closure);
1524 void iterate_postorder(boolArray& mark, BlockClosure* closure);
1526 friend class SuxAndWeightAdjuster;
1528 public:
1529 void* operator new(size_t size) {
1530 Compilation* c = Compilation::current();
1531 void* res = c->arena()->Amalloc(size);
1532 ((BlockBegin*)res)->_id = c->get_next_id();
1533 ((BlockBegin*)res)->_block_id = c->get_next_block_id();
1534 return res;
1535 }
1537 // initialization/counting
1538 static int number_of_blocks() {
1539 return Compilation::current()->number_of_blocks();
1540 }
1542 // creation
1543 BlockBegin(int bci)
1544 : StateSplit(illegalType)
1545 , _bci(bci)
1546 , _depth_first_number(-1)
1547 , _linear_scan_number(-1)
1548 , _loop_depth(0)
1549 , _flags(0)
1550 , _dominator(NULL)
1551 , _end(NULL)
1552 , _predecessors(2)
1553 , _successors(2)
1554 , _exception_handlers(1)
1555 , _exception_states(NULL)
1556 , _exception_handler_pco(-1)
1557 , _lir(NULL)
1558 , _loop_index(-1)
1559 , _live_in()
1560 , _live_out()
1561 , _live_gen()
1562 , _live_kill()
1563 , _fpu_register_usage()
1564 , _fpu_stack_state(NULL)
1565 , _first_lir_instruction_id(-1)
1566 , _last_lir_instruction_id(-1)
1567 , _total_preds(0)
1568 , _stores_to_locals()
1569 {
1570 #ifndef PRODUCT
1571 set_printable_bci(bci);
1572 #endif
1573 }
1575 // accessors
1576 int block_id() const { return _block_id; }
1577 int bci() const { return _bci; }
1578 BlockList* successors() { return &_successors; }
1579 BlockBegin* dominator() const { return _dominator; }
1580 int loop_depth() const { return _loop_depth; }
1581 int depth_first_number() const { return _depth_first_number; }
1582 int linear_scan_number() const { return _linear_scan_number; }
1583 BlockEnd* end() const { return _end; }
1584 Label* label() { return &_label; }
1585 LIR_List* lir() const { return _lir; }
1586 int exception_handler_pco() const { return _exception_handler_pco; }
1587 BitMap& live_in() { return _live_in; }
1588 BitMap& live_out() { return _live_out; }
1589 BitMap& live_gen() { return _live_gen; }
1590 BitMap& live_kill() { return _live_kill; }
1591 BitMap& fpu_register_usage() { return _fpu_register_usage; }
1592 intArray* fpu_stack_state() const { return _fpu_stack_state; }
1593 int first_lir_instruction_id() const { return _first_lir_instruction_id; }
1594 int last_lir_instruction_id() const { return _last_lir_instruction_id; }
1595 int total_preds() const { return _total_preds; }
1596 BitMap& stores_to_locals() { return _stores_to_locals; }
1598 // manipulation
1599 void set_dominator(BlockBegin* dom) { _dominator = dom; }
1600 void set_loop_depth(int d) { _loop_depth = d; }
1601 void set_depth_first_number(int dfn) { _depth_first_number = dfn; }
1602 void set_linear_scan_number(int lsn) { _linear_scan_number = lsn; }
1603 void set_end(BlockEnd* end);
1604 void clear_end();
1605 void disconnect_from_graph();
1606 static void disconnect_edge(BlockBegin* from, BlockBegin* to);
1607 BlockBegin* insert_block_between(BlockBegin* sux);
1608 void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1609 void set_lir(LIR_List* lir) { _lir = lir; }
1610 void set_exception_handler_pco(int pco) { _exception_handler_pco = pco; }
1611 void set_live_in (BitMap map) { _live_in = map; }
1612 void set_live_out (BitMap map) { _live_out = map; }
1613 void set_live_gen (BitMap map) { _live_gen = map; }
1614 void set_live_kill (BitMap map) { _live_kill = map; }
1615 void set_fpu_register_usage(BitMap map) { _fpu_register_usage = map; }
1616 void set_fpu_stack_state(intArray* state) { _fpu_stack_state = state; }
1617 void set_first_lir_instruction_id(int id) { _first_lir_instruction_id = id; }
1618 void set_last_lir_instruction_id(int id) { _last_lir_instruction_id = id; }
1619 void increment_total_preds(int n = 1) { _total_preds += n; }
1620 void init_stores_to_locals(int locals_count) { _stores_to_locals = BitMap(locals_count); _stores_to_locals.clear(); }
1622 // generic
1623 virtual void state_values_do(ValueVisitor* f);
1625 // successors and predecessors
1626 int number_of_sux() const;
1627 BlockBegin* sux_at(int i) const;
1628 void add_successor(BlockBegin* sux);
1629 void remove_successor(BlockBegin* pred);
1630 bool is_successor(BlockBegin* sux) const { return _successors.contains(sux); }
1632 void add_predecessor(BlockBegin* pred);
1633 void remove_predecessor(BlockBegin* pred);
1634 bool is_predecessor(BlockBegin* pred) const { return _predecessors.contains(pred); }
1635 int number_of_preds() const { return _predecessors.length(); }
1636 BlockBegin* pred_at(int i) const { return _predecessors[i]; }
1638 // exception handlers potentially invoked by this block
1639 void add_exception_handler(BlockBegin* b);
1640 bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }
1641 int number_of_exception_handlers() const { return _exception_handlers.length(); }
1642 BlockBegin* exception_handler_at(int i) const { return _exception_handlers.at(i); }
1644 // states of the instructions that have an edge to this exception handler
1645 int number_of_exception_states() { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); }
1646 ValueStack* exception_state_at(int idx) const { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }
1647 int add_exception_state(ValueStack* state);
1649 // flags
1650 enum Flag {
1651 no_flag = 0,
1652 std_entry_flag = 1 << 0,
1653 osr_entry_flag = 1 << 1,
1654 exception_entry_flag = 1 << 2,
1655 subroutine_entry_flag = 1 << 3,
1656 backward_branch_target_flag = 1 << 4,
1657 is_on_work_list_flag = 1 << 5,
1658 was_visited_flag = 1 << 6,
1659 parser_loop_header_flag = 1 << 7, // set by parser to identify blocks where phi functions can not be created on demand
1660 critical_edge_split_flag = 1 << 8, // set for all blocks that are introduced when critical edges are split
1661 linear_scan_loop_header_flag = 1 << 9, // set during loop-detection for LinearScan
1662 linear_scan_loop_end_flag = 1 << 10 // set during loop-detection for LinearScan
1663 };
1665 void set(Flag f) { _flags |= f; }
1666 void clear(Flag f) { _flags &= ~f; }
1667 bool is_set(Flag f) const { return (_flags & f) != 0; }
1668 bool is_entry_block() const {
1669 const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;
1670 return (_flags & entry_mask) != 0;
1671 }
1673 // iteration
1674 void iterate_preorder (BlockClosure* closure);
1675 void iterate_postorder (BlockClosure* closure);
1677 void block_values_do(ValueVisitor* f);
1679 // loops
1680 void set_loop_index(int ix) { _loop_index = ix; }
1681 int loop_index() const { return _loop_index; }
1683 // merging
1684 bool try_merge(ValueStack* state); // try to merge states at block begin
1685 void merge(ValueStack* state) { bool b = try_merge(state); assert(b, "merge failed"); }
1687 // debugging
1688 void print_block() PRODUCT_RETURN;
1689 void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;
1690 };
1693 BASE(BlockEnd, StateSplit)
1694 private:
1695 BlockBegin* _begin;
1696 BlockList* _sux;
1698 protected:
1699 BlockList* sux() const { return _sux; }
1701 void set_sux(BlockList* sux) {
1702 #ifdef ASSERT
1703 assert(sux != NULL, "sux must exist");
1704 for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist");
1705 #endif
1706 _sux = sux;
1707 }
1709 public:
1710 // creation
1711 BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)
1712 : StateSplit(type, state_before)
1713 , _begin(NULL)
1714 , _sux(NULL)
1715 {
1716 set_flag(IsSafepointFlag, is_safepoint);
1717 }
1719 // accessors
1720 bool is_safepoint() const { return check_flag(IsSafepointFlag); }
1721 BlockBegin* begin() const { return _begin; }
1723 // manipulation
1724 void set_begin(BlockBegin* begin);
1726 // successors
1727 int number_of_sux() const { return _sux != NULL ? _sux->length() : 0; }
1728 BlockBegin* sux_at(int i) const { return _sux->at(i); }
1729 BlockBegin* default_sux() const { return sux_at(number_of_sux() - 1); }
1730 BlockBegin** addr_sux_at(int i) const { return _sux->adr_at(i); }
1731 int sux_index(BlockBegin* sux) const { return _sux->find(sux); }
1732 void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1733 };
1736 LEAF(Goto, BlockEnd)
1737 public:
1738 enum Direction {
1739 none, // Just a regular goto
1740 taken, not_taken // Goto produced from If
1741 };
1742 private:
1743 ciMethod* _profiled_method;
1744 int _profiled_bci;
1745 Direction _direction;
1746 public:
1747 // creation
1748 Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false)
1749 : BlockEnd(illegalType, state_before, is_safepoint)
1750 , _direction(none)
1751 , _profiled_method(NULL)
1752 , _profiled_bci(0) {
1753 BlockList* s = new BlockList(1);
1754 s->append(sux);
1755 set_sux(s);
1756 }
1758 Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint)
1759 , _direction(none)
1760 , _profiled_method(NULL)
1761 , _profiled_bci(0) {
1762 BlockList* s = new BlockList(1);
1763 s->append(sux);
1764 set_sux(s);
1765 }
1767 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1768 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
1769 int profiled_bci() const { return _profiled_bci; }
1770 Direction direction() const { return _direction; }
1772 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1773 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1774 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1775 void set_direction(Direction d) { _direction = d; }
1776 };
1779 LEAF(If, BlockEnd)
1780 private:
1781 Value _x;
1782 Condition _cond;
1783 Value _y;
1784 ciMethod* _profiled_method;
1785 int _profiled_bci; // Canonicalizer may alter bci of If node
1786 bool _swapped; // Is the order reversed with respect to the original If in the
1787 // bytecode stream?
1788 public:
1789 // creation
1790 // unordered_is_true is valid for float/double compares only
1791 If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)
1792 : BlockEnd(illegalType, state_before, is_safepoint)
1793 , _x(x)
1794 , _cond(cond)
1795 , _y(y)
1796 , _profiled_method(NULL)
1797 , _profiled_bci(0)
1798 , _swapped(false)
1799 {
1800 ASSERT_VALUES
1801 set_flag(UnorderedIsTrueFlag, unordered_is_true);
1802 assert(x->type()->tag() == y->type()->tag(), "types must match");
1803 BlockList* s = new BlockList(2);
1804 s->append(tsux);
1805 s->append(fsux);
1806 set_sux(s);
1807 }
1809 // accessors
1810 Value x() const { return _x; }
1811 Condition cond() const { return _cond; }
1812 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
1813 Value y() const { return _y; }
1814 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
1815 BlockBegin* tsux() const { return sux_for(true); }
1816 BlockBegin* fsux() const { return sux_for(false); }
1817 BlockBegin* usux() const { return sux_for(unordered_is_true()); }
1818 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1819 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
1820 int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered
1821 bool is_swapped() const { return _swapped; }
1823 // manipulation
1824 void swap_operands() {
1825 Value t = _x; _x = _y; _y = t;
1826 _cond = mirror(_cond);
1827 }
1829 void swap_sux() {
1830 assert(number_of_sux() == 2, "wrong number of successors");
1831 BlockList* s = sux();
1832 BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
1833 _cond = negate(_cond);
1834 set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));
1835 }
1837 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1838 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1839 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1840 void set_swapped(bool value) { _swapped = value; }
1841 // generic
1842 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
1843 };
1846 LEAF(IfInstanceOf, BlockEnd)
1847 private:
1848 ciKlass* _klass;
1849 Value _obj;
1850 bool _test_is_instance; // jump if instance
1851 int _instanceof_bci;
1853 public:
1854 IfInstanceOf(ciKlass* klass, Value obj, bool test_is_instance, int instanceof_bci, BlockBegin* tsux, BlockBegin* fsux)
1855 : BlockEnd(illegalType, NULL, false) // temporary set to false
1856 , _klass(klass)
1857 , _obj(obj)
1858 , _test_is_instance(test_is_instance)
1859 , _instanceof_bci(instanceof_bci)
1860 {
1861 ASSERT_VALUES
1862 assert(instanceof_bci >= 0, "illegal bci");
1863 BlockList* s = new BlockList(2);
1864 s->append(tsux);
1865 s->append(fsux);
1866 set_sux(s);
1867 }
1869 // accessors
1870 //
1871 // Note 1: If test_is_instance() is true, IfInstanceOf tests if obj *is* an
1872 // instance of klass; otherwise it tests if it is *not* and instance
1873 // of klass.
1874 //
1875 // Note 2: IfInstanceOf instructions are created by combining an InstanceOf
1876 // and an If instruction. The IfInstanceOf bci() corresponds to the
1877 // bci that the If would have had; the (this->) instanceof_bci() is
1878 // the bci of the original InstanceOf instruction.
1879 ciKlass* klass() const { return _klass; }
1880 Value obj() const { return _obj; }
1881 int instanceof_bci() const { return _instanceof_bci; }
1882 bool test_is_instance() const { return _test_is_instance; }
1883 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
1884 BlockBegin* tsux() const { return sux_for(true); }
1885 BlockBegin* fsux() const { return sux_for(false); }
1887 // manipulation
1888 void swap_sux() {
1889 assert(number_of_sux() == 2, "wrong number of successors");
1890 BlockList* s = sux();
1891 BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
1892 _test_is_instance = !_test_is_instance;
1893 }
1895 // generic
1896 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_obj); }
1897 };
1900 BASE(Switch, BlockEnd)
1901 private:
1902 Value _tag;
1904 public:
1905 // creation
1906 Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
1907 : BlockEnd(illegalType, state_before, is_safepoint)
1908 , _tag(tag) {
1909 ASSERT_VALUES
1910 set_sux(sux);
1911 }
1913 // accessors
1914 Value tag() const { return _tag; }
1915 int length() const { return number_of_sux() - 1; }
1917 virtual bool needs_exception_state() const { return false; }
1919 // generic
1920 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_tag); }
1921 };
1924 LEAF(TableSwitch, Switch)
1925 private:
1926 int _lo_key;
1928 public:
1929 // creation
1930 TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)
1931 : Switch(tag, sux, state_before, is_safepoint)
1932 , _lo_key(lo_key) {}
1934 // accessors
1935 int lo_key() const { return _lo_key; }
1936 int hi_key() const { return _lo_key + length() - 1; }
1937 };
1940 LEAF(LookupSwitch, Switch)
1941 private:
1942 intArray* _keys;
1944 public:
1945 // creation
1946 LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)
1947 : Switch(tag, sux, state_before, is_safepoint)
1948 , _keys(keys) {
1949 assert(keys != NULL, "keys must exist");
1950 assert(keys->length() == length(), "sux & keys have incompatible lengths");
1951 }
1953 // accessors
1954 int key_at(int i) const { return _keys->at(i); }
1955 };
1958 LEAF(Return, BlockEnd)
1959 private:
1960 Value _result;
1962 public:
1963 // creation
1964 Return(Value result) :
1965 BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true),
1966 _result(result) {}
1968 // accessors
1969 Value result() const { return _result; }
1970 bool has_result() const { return result() != NULL; }
1972 // generic
1973 virtual void input_values_do(ValueVisitor* f) {
1974 BlockEnd::input_values_do(f);
1975 if (has_result()) f->visit(&_result);
1976 }
1977 };
1980 LEAF(Throw, BlockEnd)
1981 private:
1982 Value _exception;
1984 public:
1985 // creation
1986 Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {
1987 ASSERT_VALUES
1988 }
1990 // accessors
1991 Value exception() const { return _exception; }
1993 // generic
1994 virtual bool can_trap() const { return true; }
1995 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_exception); }
1996 };
1999 LEAF(Base, BlockEnd)
2000 public:
2001 // creation
2002 Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, NULL, false) {
2003 assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged");
2004 assert(osr_entry == NULL || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged");
2005 BlockList* s = new BlockList(2);
2006 if (osr_entry != NULL) s->append(osr_entry);
2007 s->append(std_entry); // must be default sux!
2008 set_sux(s);
2009 }
2011 // accessors
2012 BlockBegin* std_entry() const { return default_sux(); }
2013 BlockBegin* osr_entry() const { return number_of_sux() < 2 ? NULL : sux_at(0); }
2014 };
2017 LEAF(OsrEntry, Instruction)
2018 public:
2019 // creation
2020 #ifdef _LP64
2021 OsrEntry() : Instruction(longType) { pin(); }
2022 #else
2023 OsrEntry() : Instruction(intType) { pin(); }
2024 #endif
2026 // generic
2027 virtual void input_values_do(ValueVisitor* f) { }
2028 };
2031 // Models the incoming exception at a catch site
2032 LEAF(ExceptionObject, Instruction)
2033 public:
2034 // creation
2035 ExceptionObject() : Instruction(objectType) {
2036 pin();
2037 }
2039 // generic
2040 virtual void input_values_do(ValueVisitor* f) { }
2041 };
2044 // Models needed rounding for floating-point values on Intel.
2045 // Currently only used to represent rounding of double-precision
2046 // values stored into local variables, but could be used to model
2047 // intermediate rounding of single-precision values as well.
2048 LEAF(RoundFP, Instruction)
2049 private:
2050 Value _input; // floating-point value to be rounded
2052 public:
2053 RoundFP(Value input)
2054 : Instruction(input->type()) // Note: should not be used for constants
2055 , _input(input)
2056 {
2057 ASSERT_VALUES
2058 }
2060 // accessors
2061 Value input() const { return _input; }
2063 // generic
2064 virtual void input_values_do(ValueVisitor* f) { f->visit(&_input); }
2065 };
2068 BASE(UnsafeOp, Instruction)
2069 private:
2070 BasicType _basic_type; // ValueType can not express byte-sized integers
2072 protected:
2073 // creation
2074 UnsafeOp(BasicType basic_type, bool is_put)
2075 : Instruction(is_put ? voidType : as_ValueType(basic_type))
2076 , _basic_type(basic_type)
2077 {
2078 //Note: Unsafe ops are not not guaranteed to throw NPE.
2079 // Convservatively, Unsafe operations must be pinned though we could be
2080 // looser about this if we wanted to..
2081 pin();
2082 }
2084 public:
2085 // accessors
2086 BasicType basic_type() { return _basic_type; }
2088 // generic
2089 virtual void input_values_do(ValueVisitor* f) { }
2090 };
2093 BASE(UnsafeRawOp, UnsafeOp)
2094 private:
2095 Value _base; // Base address (a Java long)
2096 Value _index; // Index if computed by optimizer; initialized to NULL
2097 int _log2_scale; // Scale factor: 0, 1, 2, or 3.
2098 // Indicates log2 of number of bytes (1, 2, 4, or 8)
2099 // to scale index by.
2101 protected:
2102 UnsafeRawOp(BasicType basic_type, Value addr, bool is_put)
2103 : UnsafeOp(basic_type, is_put)
2104 , _base(addr)
2105 , _index(NULL)
2106 , _log2_scale(0)
2107 {
2108 // Can not use ASSERT_VALUES because index may be NULL
2109 assert(addr != NULL && addr->type()->is_long(), "just checking");
2110 }
2112 UnsafeRawOp(BasicType basic_type, Value base, Value index, int log2_scale, bool is_put)
2113 : UnsafeOp(basic_type, is_put)
2114 , _base(base)
2115 , _index(index)
2116 , _log2_scale(log2_scale)
2117 {
2118 }
2120 public:
2121 // accessors
2122 Value base() { return _base; }
2123 Value index() { return _index; }
2124 bool has_index() { return (_index != NULL); }
2125 int log2_scale() { return _log2_scale; }
2127 // setters
2128 void set_base (Value base) { _base = base; }
2129 void set_index(Value index) { _index = index; }
2130 void set_log2_scale(int log2_scale) { _log2_scale = log2_scale; }
2132 // generic
2133 virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f);
2134 f->visit(&_base);
2135 if (has_index()) f->visit(&_index); }
2136 };
2139 LEAF(UnsafeGetRaw, UnsafeRawOp)
2140 private:
2141 bool _may_be_unaligned, _is_wide; // For OSREntry
2143 public:
2144 UnsafeGetRaw(BasicType basic_type, Value addr, bool may_be_unaligned, bool is_wide = false)
2145 : UnsafeRawOp(basic_type, addr, false) {
2146 _may_be_unaligned = may_be_unaligned;
2147 _is_wide = is_wide;
2148 }
2150 UnsafeGetRaw(BasicType basic_type, Value base, Value index, int log2_scale, bool may_be_unaligned, bool is_wide = false)
2151 : UnsafeRawOp(basic_type, base, index, log2_scale, false) {
2152 _may_be_unaligned = may_be_unaligned;
2153 _is_wide = is_wide;
2154 }
2156 bool may_be_unaligned() { return _may_be_unaligned; }
2157 bool is_wide() { return _is_wide; }
2158 };
2161 LEAF(UnsafePutRaw, UnsafeRawOp)
2162 private:
2163 Value _value; // Value to be stored
2165 public:
2166 UnsafePutRaw(BasicType basic_type, Value addr, Value value)
2167 : UnsafeRawOp(basic_type, addr, true)
2168 , _value(value)
2169 {
2170 assert(value != NULL, "just checking");
2171 ASSERT_VALUES
2172 }
2174 UnsafePutRaw(BasicType basic_type, Value base, Value index, int log2_scale, Value value)
2175 : UnsafeRawOp(basic_type, base, index, log2_scale, true)
2176 , _value(value)
2177 {
2178 assert(value != NULL, "just checking");
2179 ASSERT_VALUES
2180 }
2182 // accessors
2183 Value value() { return _value; }
2185 // generic
2186 virtual void input_values_do(ValueVisitor* f) { UnsafeRawOp::input_values_do(f);
2187 f->visit(&_value); }
2188 };
2191 BASE(UnsafeObjectOp, UnsafeOp)
2192 private:
2193 Value _object; // Object to be fetched from or mutated
2194 Value _offset; // Offset within object
2195 bool _is_volatile; // true if volatile - dl/JSR166
2196 public:
2197 UnsafeObjectOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile)
2198 : UnsafeOp(basic_type, is_put), _object(object), _offset(offset), _is_volatile(is_volatile)
2199 {
2200 }
2202 // accessors
2203 Value object() { return _object; }
2204 Value offset() { return _offset; }
2205 bool is_volatile() { return _is_volatile; }
2206 // generic
2207 virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f);
2208 f->visit(&_object);
2209 f->visit(&_offset); }
2210 };
2213 LEAF(UnsafeGetObject, UnsafeObjectOp)
2214 public:
2215 UnsafeGetObject(BasicType basic_type, Value object, Value offset, bool is_volatile)
2216 : UnsafeObjectOp(basic_type, object, offset, false, is_volatile)
2217 {
2218 ASSERT_VALUES
2219 }
2220 };
2223 LEAF(UnsafePutObject, UnsafeObjectOp)
2224 private:
2225 Value _value; // Value to be stored
2226 public:
2227 UnsafePutObject(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile)
2228 : UnsafeObjectOp(basic_type, object, offset, true, is_volatile)
2229 , _value(value)
2230 {
2231 ASSERT_VALUES
2232 }
2234 // accessors
2235 Value value() { return _value; }
2237 // generic
2238 virtual void input_values_do(ValueVisitor* f) { UnsafeObjectOp::input_values_do(f);
2239 f->visit(&_value); }
2240 };
2243 BASE(UnsafePrefetch, UnsafeObjectOp)
2244 public:
2245 UnsafePrefetch(Value object, Value offset)
2246 : UnsafeObjectOp(T_VOID, object, offset, false, false)
2247 {
2248 }
2249 };
2252 LEAF(UnsafePrefetchRead, UnsafePrefetch)
2253 public:
2254 UnsafePrefetchRead(Value object, Value offset)
2255 : UnsafePrefetch(object, offset)
2256 {
2257 ASSERT_VALUES
2258 }
2259 };
2262 LEAF(UnsafePrefetchWrite, UnsafePrefetch)
2263 public:
2264 UnsafePrefetchWrite(Value object, Value offset)
2265 : UnsafePrefetch(object, offset)
2266 {
2267 ASSERT_VALUES
2268 }
2269 };
2271 LEAF(ProfileCall, Instruction)
2272 private:
2273 ciMethod* _method;
2274 int _bci_of_invoke;
2275 Value _recv;
2276 ciKlass* _known_holder;
2278 public:
2279 ProfileCall(ciMethod* method, int bci, Value recv, ciKlass* known_holder)
2280 : Instruction(voidType)
2281 , _method(method)
2282 , _bci_of_invoke(bci)
2283 , _recv(recv)
2284 , _known_holder(known_holder)
2285 {
2286 // The ProfileCall has side-effects and must occur precisely where located
2287 pin();
2288 }
2290 ciMethod* method() { return _method; }
2291 int bci_of_invoke() { return _bci_of_invoke; }
2292 Value recv() { return _recv; }
2293 ciKlass* known_holder() { return _known_holder; }
2295 virtual void input_values_do(ValueVisitor* f) { if (_recv != NULL) f->visit(&_recv); }
2296 };
2299 // Call some C runtime function that doesn't safepoint,
2300 // optionally passing the current thread as the first argument.
2301 LEAF(RuntimeCall, Instruction)
2302 private:
2303 const char* _entry_name;
2304 address _entry;
2305 Values* _args;
2306 bool _pass_thread; // Pass the JavaThread* as an implicit first argument
2308 public:
2309 RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2310 : Instruction(type)
2311 , _entry(entry)
2312 , _args(args)
2313 , _entry_name(entry_name)
2314 , _pass_thread(pass_thread) {
2315 ASSERT_VALUES
2316 pin();
2317 }
2319 const char* entry_name() const { return _entry_name; }
2320 address entry() const { return _entry; }
2321 int number_of_arguments() const { return _args->length(); }
2322 Value argument_at(int i) const { return _args->at(i); }
2323 bool pass_thread() const { return _pass_thread; }
2325 virtual void input_values_do(ValueVisitor* f) {
2326 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
2327 }
2328 };
2330 // Use to trip invocation counter of an inlined method
2332 LEAF(ProfileInvoke, Instruction)
2333 private:
2334 ciMethod* _inlinee;
2335 ValueStack* _state;
2337 public:
2338 ProfileInvoke(ciMethod* inlinee, ValueStack* state)
2339 : Instruction(voidType)
2340 , _inlinee(inlinee)
2341 , _state(state)
2342 {
2343 // The ProfileInvoke has side-effects and must occur precisely where located QQQ???
2344 pin();
2345 }
2347 ciMethod* inlinee() { return _inlinee; }
2348 ValueStack* state() { return _state; }
2349 virtual void input_values_do(ValueVisitor*) {}
2350 virtual void state_values_do(ValueVisitor*);
2351 };
2353 class BlockPair: public CompilationResourceObj {
2354 private:
2355 BlockBegin* _from;
2356 BlockBegin* _to;
2357 public:
2358 BlockPair(BlockBegin* from, BlockBegin* to): _from(from), _to(to) {}
2359 BlockBegin* from() const { return _from; }
2360 BlockBegin* to() const { return _to; }
2361 bool is_same(BlockBegin* from, BlockBegin* to) const { return _from == from && _to == to; }
2362 bool is_same(BlockPair* p) const { return _from == p->from() && _to == p->to(); }
2363 void set_to(BlockBegin* b) { _to = b; }
2364 void set_from(BlockBegin* b) { _from = b; }
2365 };
2368 define_array(BlockPairArray, BlockPair*)
2369 define_stack(BlockPairList, BlockPairArray)
2372 inline int BlockBegin::number_of_sux() const { assert(_end == NULL || _end->number_of_sux() == _successors.length(), "mismatch"); return _successors.length(); }
2373 inline BlockBegin* BlockBegin::sux_at(int i) const { assert(_end == NULL || _end->sux_at(i) == _successors.at(i), "mismatch"); return _successors.at(i); }
2374 inline void BlockBegin::add_successor(BlockBegin* sux) { assert(_end == NULL, "Would create mismatch with successors of BlockEnd"); _successors.append(sux); }
2376 #undef ASSERT_VALUES
2378 #endif // SHARE_VM_C1_C1_INSTRUCTION_HPP