Tue, 21 Feb 2012 13:14:55 -0500
7120481: storeStore barrier in constructor with final field
Summary: Issue storestore barrier before constructor return if the constructor write final field.
Reviewed-by: dholmes, jrose, roland, coleenp
Contributed-by: Jiangli Zhou <jiangli.zhou@oracle.com>
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;
110 class MemBar;
112 // A Value is a reference to the instruction creating the value
113 typedef Instruction* Value;
114 define_array(ValueArray, Value)
115 define_stack(Values, ValueArray)
117 define_array(ValueStackArray, ValueStack*)
118 define_stack(ValueStackStack, ValueStackArray)
120 // BlockClosure is the base class for block traversal/iteration.
122 class BlockClosure: public CompilationResourceObj {
123 public:
124 virtual void block_do(BlockBegin* block) = 0;
125 };
128 // A simple closure class for visiting the values of an Instruction
129 class ValueVisitor: public StackObj {
130 public:
131 virtual void visit(Value* v) = 0;
132 };
135 // Some array and list classes
136 define_array(BlockBeginArray, BlockBegin*)
137 define_stack(_BlockList, BlockBeginArray)
139 class BlockList: public _BlockList {
140 public:
141 BlockList(): _BlockList() {}
142 BlockList(const int size): _BlockList(size) {}
143 BlockList(const int size, BlockBegin* init): _BlockList(size, init) {}
145 void iterate_forward(BlockClosure* closure);
146 void iterate_backward(BlockClosure* closure);
147 void blocks_do(void f(BlockBegin*));
148 void values_do(ValueVisitor* f);
149 void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN;
150 };
153 // InstructionVisitors provide type-based dispatch for instructions.
154 // For each concrete Instruction class X, a virtual function do_X is
155 // provided. Functionality that needs to be implemented for all classes
156 // (e.g., printing, code generation) is factored out into a specialised
157 // visitor instead of added to the Instruction classes itself.
159 class InstructionVisitor: public StackObj {
160 public:
161 virtual void do_Phi (Phi* x) = 0;
162 virtual void do_Local (Local* x) = 0;
163 virtual void do_Constant (Constant* x) = 0;
164 virtual void do_LoadField (LoadField* x) = 0;
165 virtual void do_StoreField (StoreField* x) = 0;
166 virtual void do_ArrayLength (ArrayLength* x) = 0;
167 virtual void do_LoadIndexed (LoadIndexed* x) = 0;
168 virtual void do_StoreIndexed (StoreIndexed* x) = 0;
169 virtual void do_NegateOp (NegateOp* x) = 0;
170 virtual void do_ArithmeticOp (ArithmeticOp* x) = 0;
171 virtual void do_ShiftOp (ShiftOp* x) = 0;
172 virtual void do_LogicOp (LogicOp* x) = 0;
173 virtual void do_CompareOp (CompareOp* x) = 0;
174 virtual void do_IfOp (IfOp* x) = 0;
175 virtual void do_Convert (Convert* x) = 0;
176 virtual void do_NullCheck (NullCheck* x) = 0;
177 virtual void do_Invoke (Invoke* x) = 0;
178 virtual void do_NewInstance (NewInstance* x) = 0;
179 virtual void do_NewTypeArray (NewTypeArray* x) = 0;
180 virtual void do_NewObjectArray (NewObjectArray* x) = 0;
181 virtual void do_NewMultiArray (NewMultiArray* x) = 0;
182 virtual void do_CheckCast (CheckCast* x) = 0;
183 virtual void do_InstanceOf (InstanceOf* x) = 0;
184 virtual void do_MonitorEnter (MonitorEnter* x) = 0;
185 virtual void do_MonitorExit (MonitorExit* x) = 0;
186 virtual void do_Intrinsic (Intrinsic* x) = 0;
187 virtual void do_BlockBegin (BlockBegin* x) = 0;
188 virtual void do_Goto (Goto* x) = 0;
189 virtual void do_If (If* x) = 0;
190 virtual void do_IfInstanceOf (IfInstanceOf* x) = 0;
191 virtual void do_TableSwitch (TableSwitch* x) = 0;
192 virtual void do_LookupSwitch (LookupSwitch* x) = 0;
193 virtual void do_Return (Return* x) = 0;
194 virtual void do_Throw (Throw* x) = 0;
195 virtual void do_Base (Base* x) = 0;
196 virtual void do_OsrEntry (OsrEntry* x) = 0;
197 virtual void do_ExceptionObject(ExceptionObject* x) = 0;
198 virtual void do_RoundFP (RoundFP* x) = 0;
199 virtual void do_UnsafeGetRaw (UnsafeGetRaw* x) = 0;
200 virtual void do_UnsafePutRaw (UnsafePutRaw* x) = 0;
201 virtual void do_UnsafeGetObject(UnsafeGetObject* x) = 0;
202 virtual void do_UnsafePutObject(UnsafePutObject* x) = 0;
203 virtual void do_UnsafePrefetchRead (UnsafePrefetchRead* x) = 0;
204 virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) = 0;
205 virtual void do_ProfileCall (ProfileCall* x) = 0;
206 virtual void do_ProfileInvoke (ProfileInvoke* x) = 0;
207 virtual void do_RuntimeCall (RuntimeCall* x) = 0;
208 virtual void do_MemBar (MemBar* x) = 0;
209 };
212 // Hashing support
213 //
214 // Note: This hash functions affect the performance
215 // of ValueMap - make changes carefully!
217 #define HASH1(x1 ) ((intx)(x1))
218 #define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2))
219 #define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3))
220 #define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))
223 // The following macros are used to implement instruction-specific hashing.
224 // By default, each instruction implements hash() and is_equal(Value), used
225 // for value numbering/common subexpression elimination. The default imple-
226 // mentation disables value numbering. Each instruction which can be value-
227 // numbered, should define corresponding hash() and is_equal(Value) functions
228 // via the macros below. The f arguments specify all the values/op codes, etc.
229 // that need to be identical for two instructions to be identical.
230 //
231 // Note: The default implementation of hash() returns 0 in order to indicate
232 // that the instruction should not be considered for value numbering.
233 // The currently used hash functions do not guarantee that never a 0
234 // is produced. While this is still correct, it may be a performance
235 // bug (no value numbering for that node). However, this situation is
236 // so unlikely, that we are not going to handle it specially.
238 #define HASHING1(class_name, enabled, f1) \
239 virtual intx hash() const { \
240 return (enabled) ? HASH2(name(), f1) : 0; \
241 } \
242 virtual bool is_equal(Value v) const { \
243 if (!(enabled) ) return false; \
244 class_name* _v = v->as_##class_name(); \
245 if (_v == NULL ) return false; \
246 if (f1 != _v->f1) return false; \
247 return true; \
248 } \
251 #define HASHING2(class_name, enabled, f1, f2) \
252 virtual intx hash() const { \
253 return (enabled) ? HASH3(name(), f1, f2) : 0; \
254 } \
255 virtual bool is_equal(Value v) const { \
256 if (!(enabled) ) return false; \
257 class_name* _v = v->as_##class_name(); \
258 if (_v == NULL ) return false; \
259 if (f1 != _v->f1) return false; \
260 if (f2 != _v->f2) return false; \
261 return true; \
262 } \
265 #define HASHING3(class_name, enabled, f1, f2, f3) \
266 virtual intx hash() const { \
267 return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
268 } \
269 virtual bool is_equal(Value v) const { \
270 if (!(enabled) ) return false; \
271 class_name* _v = v->as_##class_name(); \
272 if (_v == NULL ) return false; \
273 if (f1 != _v->f1) return false; \
274 if (f2 != _v->f2) return false; \
275 if (f3 != _v->f3) return false; \
276 return true; \
277 } \
280 // The mother of all instructions...
282 class Instruction: public CompilationResourceObj {
283 private:
284 int _id; // the unique instruction id
285 #ifndef PRODUCT
286 int _printable_bci; // the bci of the instruction for printing
287 #endif
288 int _use_count; // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1
289 int _pin_state; // set of PinReason describing the reason for pinning
290 ValueType* _type; // the instruction value type
291 Instruction* _next; // the next instruction if any (NULL for BlockEnd instructions)
292 Instruction* _subst; // the substitution instruction if any
293 LIR_Opr _operand; // LIR specific information
294 unsigned int _flags; // Flag bits
296 ValueStack* _state_before; // Copy of state with input operands still on stack (or NULL)
297 ValueStack* _exception_state; // Copy of state for exception handling
298 XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction
300 friend class UseCountComputer;
301 friend class BlockBegin;
303 void update_exception_state(ValueStack* state);
305 bool has_printable_bci() const { return NOT_PRODUCT(_printable_bci != -99) PRODUCT_ONLY(false); }
307 protected:
308 void set_type(ValueType* type) {
309 assert(type != NULL, "type must exist");
310 _type = type;
311 }
313 public:
314 void* operator new(size_t size) {
315 Compilation* c = Compilation::current();
316 void* res = c->arena()->Amalloc(size);
317 ((Instruction*)res)->_id = c->get_next_id();
318 return res;
319 }
321 static const int no_bci = -99;
323 enum InstructionFlag {
324 NeedsNullCheckFlag = 0,
325 CanTrapFlag,
326 DirectCompareFlag,
327 IsEliminatedFlag,
328 IsSafepointFlag,
329 IsStaticFlag,
330 IsStrictfpFlag,
331 NeedsStoreCheckFlag,
332 NeedsWriteBarrierFlag,
333 PreservesStateFlag,
334 TargetIsFinalFlag,
335 TargetIsLoadedFlag,
336 TargetIsStrictfpFlag,
337 UnorderedIsTrueFlag,
338 NeedsPatchingFlag,
339 ThrowIncompatibleClassChangeErrorFlag,
340 ProfileMDOFlag,
341 IsLinkedInBlockFlag,
342 InstructionLastFlag
343 };
345 public:
346 bool check_flag(InstructionFlag id) const { return (_flags & (1 << id)) != 0; }
347 void set_flag(InstructionFlag id, bool f) { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); };
349 // 'globally' used condition values
350 enum Condition {
351 eql, neq, lss, leq, gtr, geq
352 };
354 // Instructions may be pinned for many reasons and under certain conditions
355 // with enough knowledge it's possible to safely unpin them.
356 enum PinReason {
357 PinUnknown = 1 << 0
358 , PinExplicitNullCheck = 1 << 3
359 , PinStackForStateSplit= 1 << 12
360 , PinStateSplitConstructor= 1 << 13
361 , PinGlobalValueNumbering= 1 << 14
362 };
364 static Condition mirror(Condition cond);
365 static Condition negate(Condition cond);
367 // initialization
368 static int number_of_instructions() {
369 return Compilation::current()->number_of_instructions();
370 }
372 // creation
373 Instruction(ValueType* type, ValueStack* state_before = NULL, bool type_is_constant = false)
374 : _use_count(0)
375 #ifndef PRODUCT
376 , _printable_bci(-99)
377 #endif
378 , _pin_state(0)
379 , _type(type)
380 , _next(NULL)
381 , _subst(NULL)
382 , _flags(0)
383 , _operand(LIR_OprFact::illegalOpr)
384 , _state_before(state_before)
385 , _exception_handlers(NULL)
386 {
387 check_state(state_before);
388 assert(type != NULL && (!type->is_constant() || type_is_constant), "type must exist");
389 update_exception_state(_state_before);
390 }
392 // accessors
393 int id() const { return _id; }
394 #ifndef PRODUCT
395 int printable_bci() const { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
396 void set_printable_bci(int bci) { NOT_PRODUCT(_printable_bci = bci;) }
397 #endif
398 int use_count() const { return _use_count; }
399 int pin_state() const { return _pin_state; }
400 bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; }
401 ValueType* type() const { return _type; }
402 Instruction* prev(BlockBegin* block); // use carefully, expensive operation
403 Instruction* next() const { return _next; }
404 bool has_subst() const { return _subst != NULL; }
405 Instruction* subst() { return _subst == NULL ? this : _subst->subst(); }
406 LIR_Opr operand() const { return _operand; }
408 void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); }
409 bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); }
410 bool is_linked() const { return check_flag(IsLinkedInBlockFlag); }
411 bool can_be_linked() { return as_Local() == NULL && as_Phi() == NULL; }
413 bool has_uses() const { return use_count() > 0; }
414 ValueStack* state_before() const { return _state_before; }
415 ValueStack* exception_state() const { return _exception_state; }
416 virtual bool needs_exception_state() const { return true; }
417 XHandlers* exception_handlers() const { return _exception_handlers; }
419 // manipulation
420 void pin(PinReason reason) { _pin_state |= reason; }
421 void pin() { _pin_state |= PinUnknown; }
422 // DANGEROUS: only used by EliminateStores
423 void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
425 Instruction* set_next(Instruction* next) {
426 assert(next->has_printable_bci(), "_printable_bci should have been set");
427 assert(next != NULL, "must not be NULL");
428 assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");
429 assert(next->can_be_linked(), "shouldn't link these instructions into list");
431 next->set_flag(Instruction::IsLinkedInBlockFlag, true);
432 _next = next;
433 return next;
434 }
436 Instruction* set_next(Instruction* next, int bci) {
437 #ifndef PRODUCT
438 next->set_printable_bci(bci);
439 #endif
440 return set_next(next);
441 }
443 void set_subst(Instruction* subst) {
444 assert(subst == NULL ||
445 type()->base() == subst->type()->base() ||
446 subst->type()->base() == illegalType, "type can't change");
447 _subst = subst;
448 }
449 void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
450 void set_exception_state(ValueStack* s) { check_state(s); _exception_state = s; }
452 // machine-specifics
453 void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
454 void clear_operand() { _operand = LIR_OprFact::illegalOpr; }
456 // generic
457 virtual Instruction* as_Instruction() { return this; } // to satisfy HASHING1 macro
458 virtual Phi* as_Phi() { return NULL; }
459 virtual Local* as_Local() { return NULL; }
460 virtual Constant* as_Constant() { return NULL; }
461 virtual AccessField* as_AccessField() { return NULL; }
462 virtual LoadField* as_LoadField() { return NULL; }
463 virtual StoreField* as_StoreField() { return NULL; }
464 virtual AccessArray* as_AccessArray() { return NULL; }
465 virtual ArrayLength* as_ArrayLength() { return NULL; }
466 virtual AccessIndexed* as_AccessIndexed() { return NULL; }
467 virtual LoadIndexed* as_LoadIndexed() { return NULL; }
468 virtual StoreIndexed* as_StoreIndexed() { return NULL; }
469 virtual NegateOp* as_NegateOp() { return NULL; }
470 virtual Op2* as_Op2() { return NULL; }
471 virtual ArithmeticOp* as_ArithmeticOp() { return NULL; }
472 virtual ShiftOp* as_ShiftOp() { return NULL; }
473 virtual LogicOp* as_LogicOp() { return NULL; }
474 virtual CompareOp* as_CompareOp() { return NULL; }
475 virtual IfOp* as_IfOp() { return NULL; }
476 virtual Convert* as_Convert() { return NULL; }
477 virtual NullCheck* as_NullCheck() { return NULL; }
478 virtual OsrEntry* as_OsrEntry() { return NULL; }
479 virtual StateSplit* as_StateSplit() { return NULL; }
480 virtual Invoke* as_Invoke() { return NULL; }
481 virtual NewInstance* as_NewInstance() { return NULL; }
482 virtual NewArray* as_NewArray() { return NULL; }
483 virtual NewTypeArray* as_NewTypeArray() { return NULL; }
484 virtual NewObjectArray* as_NewObjectArray() { return NULL; }
485 virtual NewMultiArray* as_NewMultiArray() { return NULL; }
486 virtual TypeCheck* as_TypeCheck() { return NULL; }
487 virtual CheckCast* as_CheckCast() { return NULL; }
488 virtual InstanceOf* as_InstanceOf() { return NULL; }
489 virtual AccessMonitor* as_AccessMonitor() { return NULL; }
490 virtual MonitorEnter* as_MonitorEnter() { return NULL; }
491 virtual MonitorExit* as_MonitorExit() { return NULL; }
492 virtual Intrinsic* as_Intrinsic() { return NULL; }
493 virtual BlockBegin* as_BlockBegin() { return NULL; }
494 virtual BlockEnd* as_BlockEnd() { return NULL; }
495 virtual Goto* as_Goto() { return NULL; }
496 virtual If* as_If() { return NULL; }
497 virtual IfInstanceOf* as_IfInstanceOf() { return NULL; }
498 virtual TableSwitch* as_TableSwitch() { return NULL; }
499 virtual LookupSwitch* as_LookupSwitch() { return NULL; }
500 virtual Return* as_Return() { return NULL; }
501 virtual Throw* as_Throw() { return NULL; }
502 virtual Base* as_Base() { return NULL; }
503 virtual RoundFP* as_RoundFP() { return NULL; }
504 virtual ExceptionObject* as_ExceptionObject() { return NULL; }
505 virtual UnsafeOp* as_UnsafeOp() { return NULL; }
506 virtual ProfileInvoke* as_ProfileInvoke() { return NULL; }
508 virtual void visit(InstructionVisitor* v) = 0;
510 virtual bool can_trap() const { return false; }
512 virtual void input_values_do(ValueVisitor* f) = 0;
513 virtual void state_values_do(ValueVisitor* f);
514 virtual void other_values_do(ValueVisitor* f) { /* usually no other - override on demand */ }
515 void values_do(ValueVisitor* f) { input_values_do(f); state_values_do(f); other_values_do(f); }
517 virtual ciType* exact_type() const { return NULL; }
518 virtual ciType* declared_type() const { return NULL; }
520 // hashing
521 virtual const char* name() const = 0;
522 HASHING1(Instruction, false, id()) // hashing disabled by default
524 // debugging
525 static void check_state(ValueStack* state) PRODUCT_RETURN;
526 void print() PRODUCT_RETURN;
527 void print_line() PRODUCT_RETURN;
528 void print(InstructionPrinter& ip) PRODUCT_RETURN;
529 };
532 // The following macros are used to define base (i.e., non-leaf)
533 // and leaf instruction classes. They define class-name related
534 // generic functionality in one place.
536 #define BASE(class_name, super_class_name) \
537 class class_name: public super_class_name { \
538 public: \
539 virtual class_name* as_##class_name() { return this; } \
542 #define LEAF(class_name, super_class_name) \
543 BASE(class_name, super_class_name) \
544 public: \
545 virtual const char* name() const { return #class_name; } \
546 virtual void visit(InstructionVisitor* v) { v->do_##class_name(this); } \
549 // Debugging support
552 #ifdef ASSERT
553 class AssertValues: public ValueVisitor {
554 void visit(Value* x) { assert((*x) != NULL, "value must exist"); }
555 };
556 #define ASSERT_VALUES { AssertValues assert_value; values_do(&assert_value); }
557 #else
558 #define ASSERT_VALUES
559 #endif // ASSERT
562 // A Phi is a phi function in the sense of SSA form. It stands for
563 // the value of a local variable at the beginning of a join block.
564 // A Phi consists of n operands, one for every incoming branch.
566 LEAF(Phi, Instruction)
567 private:
568 BlockBegin* _block; // the block to which the phi function belongs
569 int _pf_flags; // the flags of the phi function
570 int _index; // to value on operand stack (index < 0) or to local
571 public:
572 // creation
573 Phi(ValueType* type, BlockBegin* b, int index)
574 : Instruction(type->base())
575 , _pf_flags(0)
576 , _block(b)
577 , _index(index)
578 {
579 if (type->is_illegal()) {
580 make_illegal();
581 }
582 }
584 // flags
585 enum Flag {
586 no_flag = 0,
587 visited = 1 << 0,
588 cannot_simplify = 1 << 1
589 };
591 // accessors
592 bool is_local() const { return _index >= 0; }
593 bool is_on_stack() const { return !is_local(); }
594 int local_index() const { assert(is_local(), ""); return _index; }
595 int stack_index() const { assert(is_on_stack(), ""); return -(_index+1); }
597 Value operand_at(int i) const;
598 int operand_count() const;
600 BlockBegin* block() const { return _block; }
602 void set(Flag f) { _pf_flags |= f; }
603 void clear(Flag f) { _pf_flags &= ~f; }
604 bool is_set(Flag f) const { return (_pf_flags & f) != 0; }
606 // Invalidates phis corresponding to merges of locals of two different types
607 // (these should never be referenced, otherwise the bytecodes are illegal)
608 void make_illegal() {
609 set(cannot_simplify);
610 set_type(illegalType);
611 }
613 bool is_illegal() const {
614 return type()->is_illegal();
615 }
617 // generic
618 virtual void input_values_do(ValueVisitor* f) {
619 }
620 };
623 // A local is a placeholder for an incoming argument to a function call.
624 LEAF(Local, Instruction)
625 private:
626 int _java_index; // the local index within the method to which the local belongs
627 ciType* _declared_type;
628 public:
629 // creation
630 Local(ciType* declared, ValueType* type, int index)
631 : Instruction(type)
632 , _java_index(index)
633 , _declared_type(declared)
634 {}
636 // accessors
637 int java_index() const { return _java_index; }
639 ciType* declared_type() const { return _declared_type; }
640 ciType* exact_type() const;
642 // generic
643 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
644 };
647 LEAF(Constant, Instruction)
648 public:
649 // creation
650 Constant(ValueType* type):
651 Instruction(type, NULL, true)
652 {
653 assert(type->is_constant(), "must be a constant");
654 }
656 Constant(ValueType* type, ValueStack* state_before):
657 Instruction(type, state_before, true)
658 {
659 assert(state_before != NULL, "only used for constants which need patching");
660 assert(type->is_constant(), "must be a constant");
661 // since it's patching it needs to be pinned
662 pin();
663 }
665 virtual bool can_trap() const { return state_before() != NULL; }
666 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
668 virtual intx hash() const;
669 virtual bool is_equal(Value v) const;
672 enum CompareResult { not_comparable = -1, cond_false, cond_true };
674 virtual CompareResult compare(Instruction::Condition condition, Value right) const;
675 BlockBegin* compare(Instruction::Condition cond, Value right,
676 BlockBegin* true_sux, BlockBegin* false_sux) const {
677 switch (compare(cond, right)) {
678 case not_comparable:
679 return NULL;
680 case cond_false:
681 return false_sux;
682 case cond_true:
683 return true_sux;
684 default:
685 ShouldNotReachHere();
686 return NULL;
687 }
688 }
689 };
692 BASE(AccessField, Instruction)
693 private:
694 Value _obj;
695 int _offset;
696 ciField* _field;
697 NullCheck* _explicit_null_check; // For explicit null check elimination
699 public:
700 // creation
701 AccessField(Value obj, int offset, ciField* field, bool is_static,
702 ValueStack* state_before, bool needs_patching)
703 : Instruction(as_ValueType(field->type()->basic_type()), state_before)
704 , _obj(obj)
705 , _offset(offset)
706 , _field(field)
707 , _explicit_null_check(NULL)
708 {
709 set_needs_null_check(!is_static);
710 set_flag(IsStaticFlag, is_static);
711 set_flag(NeedsPatchingFlag, needs_patching);
712 ASSERT_VALUES
713 // pin of all instructions with memory access
714 pin();
715 }
717 // accessors
718 Value obj() const { return _obj; }
719 int offset() const { return _offset; }
720 ciField* field() const { return _field; }
721 BasicType field_type() const { return _field->type()->basic_type(); }
722 bool is_static() const { return check_flag(IsStaticFlag); }
723 NullCheck* explicit_null_check() const { return _explicit_null_check; }
724 bool needs_patching() const { return check_flag(NeedsPatchingFlag); }
726 // Unresolved getstatic and putstatic can cause initialization.
727 // Technically it occurs at the Constant that materializes the base
728 // of the static fields but it's simpler to model it here.
729 bool is_init_point() const { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); }
731 // manipulation
733 // Under certain circumstances, if a previous NullCheck instruction
734 // proved the target object non-null, we can eliminate the explicit
735 // null check and do an implicit one, simply specifying the debug
736 // information from the NullCheck. This field should only be consulted
737 // if needs_null_check() is true.
738 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
740 // generic
741 virtual bool can_trap() const { return needs_null_check() || needs_patching(); }
742 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
743 };
746 LEAF(LoadField, AccessField)
747 public:
748 // creation
749 LoadField(Value obj, int offset, ciField* field, bool is_static,
750 ValueStack* state_before, bool needs_patching)
751 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
752 {}
754 ciType* declared_type() const;
755 ciType* exact_type() const;
757 // generic
758 HASHING2(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset()) // cannot be eliminated if needs patching or if volatile
759 };
762 LEAF(StoreField, AccessField)
763 private:
764 Value _value;
766 public:
767 // creation
768 StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
769 ValueStack* state_before, bool needs_patching)
770 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
771 , _value(value)
772 {
773 set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
774 ASSERT_VALUES
775 pin();
776 }
778 // accessors
779 Value value() const { return _value; }
780 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
782 // generic
783 virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); }
784 };
787 BASE(AccessArray, Instruction)
788 private:
789 Value _array;
791 public:
792 // creation
793 AccessArray(ValueType* type, Value array, ValueStack* state_before)
794 : Instruction(type, state_before)
795 , _array(array)
796 {
797 set_needs_null_check(true);
798 ASSERT_VALUES
799 pin(); // instruction with side effect (null exception or range check throwing)
800 }
802 Value array() const { return _array; }
804 // generic
805 virtual bool can_trap() const { return needs_null_check(); }
806 virtual void input_values_do(ValueVisitor* f) { f->visit(&_array); }
807 };
810 LEAF(ArrayLength, AccessArray)
811 private:
812 NullCheck* _explicit_null_check; // For explicit null check elimination
814 public:
815 // creation
816 ArrayLength(Value array, ValueStack* state_before)
817 : AccessArray(intType, array, state_before)
818 , _explicit_null_check(NULL) {}
820 // accessors
821 NullCheck* explicit_null_check() const { return _explicit_null_check; }
823 // setters
824 // See LoadField::set_explicit_null_check for documentation
825 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
827 // generic
828 HASHING1(ArrayLength, true, array()->subst())
829 };
832 BASE(AccessIndexed, AccessArray)
833 private:
834 Value _index;
835 Value _length;
836 BasicType _elt_type;
838 public:
839 // creation
840 AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
841 : AccessArray(as_ValueType(elt_type), array, state_before)
842 , _index(index)
843 , _length(length)
844 , _elt_type(elt_type)
845 {
846 ASSERT_VALUES
847 }
849 // accessors
850 Value index() const { return _index; }
851 Value length() const { return _length; }
852 BasicType elt_type() const { return _elt_type; }
854 // perform elimination of range checks involving constants
855 bool compute_needs_range_check();
857 // generic
858 virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }
859 };
862 LEAF(LoadIndexed, AccessIndexed)
863 private:
864 NullCheck* _explicit_null_check; // For explicit null check elimination
866 public:
867 // creation
868 LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
869 : AccessIndexed(array, index, length, elt_type, state_before)
870 , _explicit_null_check(NULL) {}
872 // accessors
873 NullCheck* explicit_null_check() const { return _explicit_null_check; }
875 // setters
876 // See LoadField::set_explicit_null_check for documentation
877 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
879 ciType* exact_type() const;
880 ciType* declared_type() const;
882 // generic
883 HASHING2(LoadIndexed, true, array()->subst(), index()->subst())
884 };
887 LEAF(StoreIndexed, AccessIndexed)
888 private:
889 Value _value;
891 ciMethod* _profiled_method;
892 int _profiled_bci;
893 public:
894 // creation
895 StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before)
896 : AccessIndexed(array, index, length, elt_type, state_before)
897 , _value(value), _profiled_method(NULL), _profiled_bci(0)
898 {
899 set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
900 set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
901 ASSERT_VALUES
902 pin();
903 }
905 // accessors
906 Value value() const { return _value; }
907 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
908 bool needs_store_check() const { return check_flag(NeedsStoreCheckFlag); }
909 // Helpers for methodDataOop profiling
910 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
911 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
912 void set_profiled_bci(int bci) { _profiled_bci = bci; }
913 bool should_profile() const { return check_flag(ProfileMDOFlag); }
914 ciMethod* profiled_method() const { return _profiled_method; }
915 int profiled_bci() const { return _profiled_bci; }
916 // generic
917 virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); }
918 };
921 LEAF(NegateOp, Instruction)
922 private:
923 Value _x;
925 public:
926 // creation
927 NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
928 ASSERT_VALUES
929 }
931 // accessors
932 Value x() const { return _x; }
934 // generic
935 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); }
936 };
939 BASE(Op2, Instruction)
940 private:
941 Bytecodes::Code _op;
942 Value _x;
943 Value _y;
945 public:
946 // creation
947 Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = NULL)
948 : Instruction(type, state_before)
949 , _op(op)
950 , _x(x)
951 , _y(y)
952 {
953 ASSERT_VALUES
954 }
956 // accessors
957 Bytecodes::Code op() const { return _op; }
958 Value x() const { return _x; }
959 Value y() const { return _y; }
961 // manipulators
962 void swap_operands() {
963 assert(is_commutative(), "operation must be commutative");
964 Value t = _x; _x = _y; _y = t;
965 }
967 // generic
968 virtual bool is_commutative() const { return false; }
969 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); }
970 };
973 LEAF(ArithmeticOp, Op2)
974 public:
975 // creation
976 ArithmeticOp(Bytecodes::Code op, Value x, Value y, bool is_strictfp, ValueStack* state_before)
977 : Op2(x->type()->meet(y->type()), op, x, y, state_before)
978 {
979 set_flag(IsStrictfpFlag, is_strictfp);
980 if (can_trap()) pin();
981 }
983 // accessors
984 bool is_strictfp() const { return check_flag(IsStrictfpFlag); }
986 // generic
987 virtual bool is_commutative() const;
988 virtual bool can_trap() const;
989 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
990 };
993 LEAF(ShiftOp, Op2)
994 public:
995 // creation
996 ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}
998 // generic
999 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1000 };
1003 LEAF(LogicOp, Op2)
1004 public:
1005 // creation
1006 LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}
1008 // generic
1009 virtual bool is_commutative() const;
1010 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1011 };
1014 LEAF(CompareOp, Op2)
1015 public:
1016 // creation
1017 CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1018 : Op2(intType, op, x, y, state_before)
1019 {}
1021 // generic
1022 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1023 };
1026 LEAF(IfOp, Op2)
1027 private:
1028 Value _tval;
1029 Value _fval;
1031 public:
1032 // creation
1033 IfOp(Value x, Condition cond, Value y, Value tval, Value fval)
1034 : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1035 , _tval(tval)
1036 , _fval(fval)
1037 {
1038 ASSERT_VALUES
1039 assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1040 }
1042 // accessors
1043 virtual bool is_commutative() const;
1044 Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }
1045 Condition cond() const { return (Condition)Op2::op(); }
1046 Value tval() const { return _tval; }
1047 Value fval() const { return _fval; }
1049 // generic
1050 virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1051 };
1054 LEAF(Convert, Instruction)
1055 private:
1056 Bytecodes::Code _op;
1057 Value _value;
1059 public:
1060 // creation
1061 Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1062 ASSERT_VALUES
1063 }
1065 // accessors
1066 Bytecodes::Code op() const { return _op; }
1067 Value value() const { return _value; }
1069 // generic
1070 virtual void input_values_do(ValueVisitor* f) { f->visit(&_value); }
1071 HASHING2(Convert, true, op(), value()->subst())
1072 };
1075 LEAF(NullCheck, Instruction)
1076 private:
1077 Value _obj;
1079 public:
1080 // creation
1081 NullCheck(Value obj, ValueStack* state_before)
1082 : Instruction(obj->type()->base(), state_before)
1083 , _obj(obj)
1084 {
1085 ASSERT_VALUES
1086 set_can_trap(true);
1087 assert(_obj->type()->is_object(), "null check must be applied to objects only");
1088 pin(Instruction::PinExplicitNullCheck);
1089 }
1091 // accessors
1092 Value obj() const { return _obj; }
1094 // setters
1095 void set_can_trap(bool can_trap) { set_flag(CanTrapFlag, can_trap); }
1097 // generic
1098 virtual bool can_trap() const { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }
1099 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
1100 HASHING1(NullCheck, true, obj()->subst())
1101 };
1104 BASE(StateSplit, Instruction)
1105 private:
1106 ValueStack* _state;
1108 protected:
1109 static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);
1111 public:
1112 // creation
1113 StateSplit(ValueType* type, ValueStack* state_before = NULL)
1114 : Instruction(type, state_before)
1115 , _state(NULL)
1116 {
1117 pin(PinStateSplitConstructor);
1118 }
1120 // accessors
1121 ValueStack* state() const { return _state; }
1122 IRScope* scope() const; // the state's scope
1124 // manipulation
1125 void set_state(ValueStack* state) { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }
1127 // generic
1128 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
1129 virtual void state_values_do(ValueVisitor* f);
1130 };
1133 LEAF(Invoke, StateSplit)
1134 private:
1135 Bytecodes::Code _code;
1136 Value _recv;
1137 Values* _args;
1138 BasicTypeList* _signature;
1139 int _vtable_index;
1140 ciMethod* _target;
1142 public:
1143 // creation
1144 Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1145 int vtable_index, ciMethod* target, ValueStack* state_before);
1147 // accessors
1148 Bytecodes::Code code() const { return _code; }
1149 Value receiver() const { return _recv; }
1150 bool has_receiver() const { return receiver() != NULL; }
1151 int number_of_arguments() const { return _args->length(); }
1152 Value argument_at(int i) const { return _args->at(i); }
1153 int vtable_index() const { return _vtable_index; }
1154 BasicTypeList* signature() const { return _signature; }
1155 ciMethod* target() const { return _target; }
1157 ciType* declared_type() const;
1159 // Returns false if target is not loaded
1160 bool target_is_final() const { return check_flag(TargetIsFinalFlag); }
1161 bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }
1162 // Returns false if target is not loaded
1163 bool target_is_strictfp() const { return check_flag(TargetIsStrictfpFlag); }
1165 // JSR 292 support
1166 bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }
1168 virtual bool needs_exception_state() const { return false; }
1170 // generic
1171 virtual bool can_trap() const { return true; }
1172 virtual void input_values_do(ValueVisitor* f) {
1173 StateSplit::input_values_do(f);
1174 if (has_receiver()) f->visit(&_recv);
1175 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1176 }
1177 virtual void state_values_do(ValueVisitor *f);
1178 };
1181 LEAF(NewInstance, StateSplit)
1182 private:
1183 ciInstanceKlass* _klass;
1185 public:
1186 // creation
1187 NewInstance(ciInstanceKlass* klass, ValueStack* state_before)
1188 : StateSplit(instanceType, state_before)
1189 , _klass(klass)
1190 {}
1192 // accessors
1193 ciInstanceKlass* klass() const { return _klass; }
1195 virtual bool needs_exception_state() const { return false; }
1197 // generic
1198 virtual bool can_trap() const { return true; }
1199 ciType* exact_type() const;
1200 ciType* declared_type() const;
1201 };
1204 BASE(NewArray, StateSplit)
1205 private:
1206 Value _length;
1208 public:
1209 // creation
1210 NewArray(Value length, ValueStack* state_before)
1211 : StateSplit(objectType, state_before)
1212 , _length(length)
1213 {
1214 // Do not ASSERT_VALUES since length is NULL for NewMultiArray
1215 }
1217 // accessors
1218 Value length() const { return _length; }
1220 virtual bool needs_exception_state() const { return false; }
1222 ciType* declared_type() const;
1224 // generic
1225 virtual bool can_trap() const { return true; }
1226 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_length); }
1227 };
1230 LEAF(NewTypeArray, NewArray)
1231 private:
1232 BasicType _elt_type;
1234 public:
1235 // creation
1236 NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)
1237 : NewArray(length, state_before)
1238 , _elt_type(elt_type)
1239 {}
1241 // accessors
1242 BasicType elt_type() const { return _elt_type; }
1243 ciType* exact_type() const;
1244 };
1247 LEAF(NewObjectArray, NewArray)
1248 private:
1249 ciKlass* _klass;
1251 public:
1252 // creation
1253 NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}
1255 // accessors
1256 ciKlass* klass() const { return _klass; }
1257 ciType* exact_type() const;
1258 };
1261 LEAF(NewMultiArray, NewArray)
1262 private:
1263 ciKlass* _klass;
1264 Values* _dims;
1266 public:
1267 // creation
1268 NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
1269 ASSERT_VALUES
1270 }
1272 // accessors
1273 ciKlass* klass() const { return _klass; }
1274 Values* dims() const { return _dims; }
1275 int rank() const { return dims()->length(); }
1277 // generic
1278 virtual void input_values_do(ValueVisitor* f) {
1279 // NOTE: we do not call NewArray::input_values_do since "length"
1280 // is meaningless for a multi-dimensional array; passing the
1281 // zeroth element down to NewArray as its length is a bad idea
1282 // since there will be a copy in the "dims" array which doesn't
1283 // get updated, and the value must not be traversed twice. Was bug
1284 // - kbr 4/10/2001
1285 StateSplit::input_values_do(f);
1286 for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1287 }
1288 };
1291 BASE(TypeCheck, StateSplit)
1292 private:
1293 ciKlass* _klass;
1294 Value _obj;
1296 ciMethod* _profiled_method;
1297 int _profiled_bci;
1299 public:
1300 // creation
1301 TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1302 : StateSplit(type, state_before), _klass(klass), _obj(obj),
1303 _profiled_method(NULL), _profiled_bci(0) {
1304 ASSERT_VALUES
1305 set_direct_compare(false);
1306 }
1308 // accessors
1309 ciKlass* klass() const { return _klass; }
1310 Value obj() const { return _obj; }
1311 bool is_loaded() const { return klass() != NULL; }
1312 bool direct_compare() const { return check_flag(DirectCompareFlag); }
1314 // manipulation
1315 void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }
1317 // generic
1318 virtual bool can_trap() const { return true; }
1319 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1321 // Helpers for methodDataOop profiling
1322 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1323 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1324 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1325 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1326 ciMethod* profiled_method() const { return _profiled_method; }
1327 int profiled_bci() const { return _profiled_bci; }
1328 };
1331 LEAF(CheckCast, TypeCheck)
1332 public:
1333 // creation
1334 CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1335 : TypeCheck(klass, obj, objectType, state_before) {}
1337 void set_incompatible_class_change_check() {
1338 set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1339 }
1340 bool is_incompatible_class_change_check() const {
1341 return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1342 }
1344 ciType* declared_type() const;
1345 ciType* exact_type() const;
1346 };
1349 LEAF(InstanceOf, TypeCheck)
1350 public:
1351 // creation
1352 InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}
1354 virtual bool needs_exception_state() const { return false; }
1355 };
1358 BASE(AccessMonitor, StateSplit)
1359 private:
1360 Value _obj;
1361 int _monitor_no;
1363 public:
1364 // creation
1365 AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)
1366 : StateSplit(illegalType, state_before)
1367 , _obj(obj)
1368 , _monitor_no(monitor_no)
1369 {
1370 set_needs_null_check(true);
1371 ASSERT_VALUES
1372 }
1374 // accessors
1375 Value obj() const { return _obj; }
1376 int monitor_no() const { return _monitor_no; }
1378 // generic
1379 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1380 };
1383 LEAF(MonitorEnter, AccessMonitor)
1384 public:
1385 // creation
1386 MonitorEnter(Value obj, int monitor_no, ValueStack* state_before)
1387 : AccessMonitor(obj, monitor_no, state_before)
1388 {
1389 ASSERT_VALUES
1390 }
1392 // generic
1393 virtual bool can_trap() const { return true; }
1394 };
1397 LEAF(MonitorExit, AccessMonitor)
1398 public:
1399 // creation
1400 MonitorExit(Value obj, int monitor_no)
1401 : AccessMonitor(obj, monitor_no, NULL)
1402 {
1403 ASSERT_VALUES
1404 }
1405 };
1408 LEAF(Intrinsic, StateSplit)
1409 private:
1410 vmIntrinsics::ID _id;
1411 Values* _args;
1412 Value _recv;
1413 int _nonnull_state; // mask identifying which args are nonnull
1415 public:
1416 // preserves_state can be set to true for Intrinsics
1417 // which are guaranteed to preserve register state across any slow
1418 // cases; setting it to true does not mean that the Intrinsic can
1419 // not trap, only that if we continue execution in the same basic
1420 // block after the Intrinsic, all of the registers are intact. This
1421 // allows load elimination and common expression elimination to be
1422 // performed across the Intrinsic. The default value is false.
1423 Intrinsic(ValueType* type,
1424 vmIntrinsics::ID id,
1425 Values* args,
1426 bool has_receiver,
1427 ValueStack* state_before,
1428 bool preserves_state,
1429 bool cantrap = true)
1430 : StateSplit(type, state_before)
1431 , _id(id)
1432 , _args(args)
1433 , _recv(NULL)
1434 , _nonnull_state(AllBits)
1435 {
1436 assert(args != NULL, "args must exist");
1437 ASSERT_VALUES
1438 set_flag(PreservesStateFlag, preserves_state);
1439 set_flag(CanTrapFlag, cantrap);
1440 if (has_receiver) {
1441 _recv = argument_at(0);
1442 }
1443 set_needs_null_check(has_receiver);
1445 // some intrinsics can't trap, so don't force them to be pinned
1446 if (!can_trap()) {
1447 unpin(PinStateSplitConstructor);
1448 }
1449 }
1451 // accessors
1452 vmIntrinsics::ID id() const { return _id; }
1453 int number_of_arguments() const { return _args->length(); }
1454 Value argument_at(int i) const { return _args->at(i); }
1456 bool has_receiver() const { return (_recv != NULL); }
1457 Value receiver() const { assert(has_receiver(), "must have receiver"); return _recv; }
1458 bool preserves_state() const { return check_flag(PreservesStateFlag); }
1460 bool arg_needs_null_check(int i) {
1461 if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
1462 return is_set_nth_bit(_nonnull_state, i);
1463 }
1464 return true;
1465 }
1467 void set_arg_needs_null_check(int i, bool check) {
1468 if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
1469 if (check) {
1470 _nonnull_state |= nth_bit(i);
1471 } else {
1472 _nonnull_state &= ~(nth_bit(i));
1473 }
1474 }
1475 }
1477 // generic
1478 virtual bool can_trap() const { return check_flag(CanTrapFlag); }
1479 virtual void input_values_do(ValueVisitor* f) {
1480 StateSplit::input_values_do(f);
1481 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1482 }
1483 };
1486 class LIR_List;
1488 LEAF(BlockBegin, StateSplit)
1489 private:
1490 int _block_id; // the unique block id
1491 int _bci; // start-bci of block
1492 int _depth_first_number; // number of this block in a depth-first ordering
1493 int _linear_scan_number; // number of this block in linear-scan ordering
1494 int _loop_depth; // the loop nesting level of this block
1495 int _loop_index; // number of the innermost loop of this block
1496 int _flags; // the flags associated with this block
1498 // fields used by BlockListBuilder
1499 int _total_preds; // number of predecessors found by BlockListBuilder
1500 BitMap _stores_to_locals; // bit is set when a local variable is stored in the block
1502 // SSA specific fields: (factor out later)
1503 BlockList _successors; // the successors of this block
1504 BlockList _predecessors; // the predecessors of this block
1505 BlockBegin* _dominator; // the dominator of this block
1506 // SSA specific ends
1507 BlockEnd* _end; // the last instruction of this block
1508 BlockList _exception_handlers; // the exception handlers potentially invoked by this block
1509 ValueStackStack* _exception_states; // only for xhandler entries: states of all instructions that have an edge to this xhandler
1510 int _exception_handler_pco; // if this block is the start of an exception handler,
1511 // this records the PC offset in the assembly code of the
1512 // first instruction in this block
1513 Label _label; // the label associated with this block
1514 LIR_List* _lir; // the low level intermediate representation for this block
1516 BitMap _live_in; // set of live LIR_Opr registers at entry to this block
1517 BitMap _live_out; // set of live LIR_Opr registers at exit from this block
1518 BitMap _live_gen; // set of registers used before any redefinition in this block
1519 BitMap _live_kill; // set of registers defined in this block
1521 BitMap _fpu_register_usage;
1522 intArray* _fpu_stack_state; // For x86 FPU code generation with UseLinearScan
1523 int _first_lir_instruction_id; // ID of first LIR instruction in this block
1524 int _last_lir_instruction_id; // ID of last LIR instruction in this block
1526 void iterate_preorder (boolArray& mark, BlockClosure* closure);
1527 void iterate_postorder(boolArray& mark, BlockClosure* closure);
1529 friend class SuxAndWeightAdjuster;
1531 public:
1532 void* operator new(size_t size) {
1533 Compilation* c = Compilation::current();
1534 void* res = c->arena()->Amalloc(size);
1535 ((BlockBegin*)res)->_id = c->get_next_id();
1536 ((BlockBegin*)res)->_block_id = c->get_next_block_id();
1537 return res;
1538 }
1540 // initialization/counting
1541 static int number_of_blocks() {
1542 return Compilation::current()->number_of_blocks();
1543 }
1545 // creation
1546 BlockBegin(int bci)
1547 : StateSplit(illegalType)
1548 , _bci(bci)
1549 , _depth_first_number(-1)
1550 , _linear_scan_number(-1)
1551 , _loop_depth(0)
1552 , _flags(0)
1553 , _dominator(NULL)
1554 , _end(NULL)
1555 , _predecessors(2)
1556 , _successors(2)
1557 , _exception_handlers(1)
1558 , _exception_states(NULL)
1559 , _exception_handler_pco(-1)
1560 , _lir(NULL)
1561 , _loop_index(-1)
1562 , _live_in()
1563 , _live_out()
1564 , _live_gen()
1565 , _live_kill()
1566 , _fpu_register_usage()
1567 , _fpu_stack_state(NULL)
1568 , _first_lir_instruction_id(-1)
1569 , _last_lir_instruction_id(-1)
1570 , _total_preds(0)
1571 , _stores_to_locals()
1572 {
1573 #ifndef PRODUCT
1574 set_printable_bci(bci);
1575 #endif
1576 }
1578 // accessors
1579 int block_id() const { return _block_id; }
1580 int bci() const { return _bci; }
1581 BlockList* successors() { return &_successors; }
1582 BlockBegin* dominator() const { return _dominator; }
1583 int loop_depth() const { return _loop_depth; }
1584 int depth_first_number() const { return _depth_first_number; }
1585 int linear_scan_number() const { return _linear_scan_number; }
1586 BlockEnd* end() const { return _end; }
1587 Label* label() { return &_label; }
1588 LIR_List* lir() const { return _lir; }
1589 int exception_handler_pco() const { return _exception_handler_pco; }
1590 BitMap& live_in() { return _live_in; }
1591 BitMap& live_out() { return _live_out; }
1592 BitMap& live_gen() { return _live_gen; }
1593 BitMap& live_kill() { return _live_kill; }
1594 BitMap& fpu_register_usage() { return _fpu_register_usage; }
1595 intArray* fpu_stack_state() const { return _fpu_stack_state; }
1596 int first_lir_instruction_id() const { return _first_lir_instruction_id; }
1597 int last_lir_instruction_id() const { return _last_lir_instruction_id; }
1598 int total_preds() const { return _total_preds; }
1599 BitMap& stores_to_locals() { return _stores_to_locals; }
1601 // manipulation
1602 void set_dominator(BlockBegin* dom) { _dominator = dom; }
1603 void set_loop_depth(int d) { _loop_depth = d; }
1604 void set_depth_first_number(int dfn) { _depth_first_number = dfn; }
1605 void set_linear_scan_number(int lsn) { _linear_scan_number = lsn; }
1606 void set_end(BlockEnd* end);
1607 void clear_end();
1608 void disconnect_from_graph();
1609 static void disconnect_edge(BlockBegin* from, BlockBegin* to);
1610 BlockBegin* insert_block_between(BlockBegin* sux);
1611 void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1612 void set_lir(LIR_List* lir) { _lir = lir; }
1613 void set_exception_handler_pco(int pco) { _exception_handler_pco = pco; }
1614 void set_live_in (BitMap map) { _live_in = map; }
1615 void set_live_out (BitMap map) { _live_out = map; }
1616 void set_live_gen (BitMap map) { _live_gen = map; }
1617 void set_live_kill (BitMap map) { _live_kill = map; }
1618 void set_fpu_register_usage(BitMap map) { _fpu_register_usage = map; }
1619 void set_fpu_stack_state(intArray* state) { _fpu_stack_state = state; }
1620 void set_first_lir_instruction_id(int id) { _first_lir_instruction_id = id; }
1621 void set_last_lir_instruction_id(int id) { _last_lir_instruction_id = id; }
1622 void increment_total_preds(int n = 1) { _total_preds += n; }
1623 void init_stores_to_locals(int locals_count) { _stores_to_locals = BitMap(locals_count); _stores_to_locals.clear(); }
1625 // generic
1626 virtual void state_values_do(ValueVisitor* f);
1628 // successors and predecessors
1629 int number_of_sux() const;
1630 BlockBegin* sux_at(int i) const;
1631 void add_successor(BlockBegin* sux);
1632 void remove_successor(BlockBegin* pred);
1633 bool is_successor(BlockBegin* sux) const { return _successors.contains(sux); }
1635 void add_predecessor(BlockBegin* pred);
1636 void remove_predecessor(BlockBegin* pred);
1637 bool is_predecessor(BlockBegin* pred) const { return _predecessors.contains(pred); }
1638 int number_of_preds() const { return _predecessors.length(); }
1639 BlockBegin* pred_at(int i) const { return _predecessors[i]; }
1641 // exception handlers potentially invoked by this block
1642 void add_exception_handler(BlockBegin* b);
1643 bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }
1644 int number_of_exception_handlers() const { return _exception_handlers.length(); }
1645 BlockBegin* exception_handler_at(int i) const { return _exception_handlers.at(i); }
1647 // states of the instructions that have an edge to this exception handler
1648 int number_of_exception_states() { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); }
1649 ValueStack* exception_state_at(int idx) const { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }
1650 int add_exception_state(ValueStack* state);
1652 // flags
1653 enum Flag {
1654 no_flag = 0,
1655 std_entry_flag = 1 << 0,
1656 osr_entry_flag = 1 << 1,
1657 exception_entry_flag = 1 << 2,
1658 subroutine_entry_flag = 1 << 3,
1659 backward_branch_target_flag = 1 << 4,
1660 is_on_work_list_flag = 1 << 5,
1661 was_visited_flag = 1 << 6,
1662 parser_loop_header_flag = 1 << 7, // set by parser to identify blocks where phi functions can not be created on demand
1663 critical_edge_split_flag = 1 << 8, // set for all blocks that are introduced when critical edges are split
1664 linear_scan_loop_header_flag = 1 << 9, // set during loop-detection for LinearScan
1665 linear_scan_loop_end_flag = 1 << 10 // set during loop-detection for LinearScan
1666 };
1668 void set(Flag f) { _flags |= f; }
1669 void clear(Flag f) { _flags &= ~f; }
1670 bool is_set(Flag f) const { return (_flags & f) != 0; }
1671 bool is_entry_block() const {
1672 const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;
1673 return (_flags & entry_mask) != 0;
1674 }
1676 // iteration
1677 void iterate_preorder (BlockClosure* closure);
1678 void iterate_postorder (BlockClosure* closure);
1680 void block_values_do(ValueVisitor* f);
1682 // loops
1683 void set_loop_index(int ix) { _loop_index = ix; }
1684 int loop_index() const { return _loop_index; }
1686 // merging
1687 bool try_merge(ValueStack* state); // try to merge states at block begin
1688 void merge(ValueStack* state) { bool b = try_merge(state); assert(b, "merge failed"); }
1690 // debugging
1691 void print_block() PRODUCT_RETURN;
1692 void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;
1693 };
1696 BASE(BlockEnd, StateSplit)
1697 private:
1698 BlockBegin* _begin;
1699 BlockList* _sux;
1701 protected:
1702 BlockList* sux() const { return _sux; }
1704 void set_sux(BlockList* sux) {
1705 #ifdef ASSERT
1706 assert(sux != NULL, "sux must exist");
1707 for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist");
1708 #endif
1709 _sux = sux;
1710 }
1712 public:
1713 // creation
1714 BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)
1715 : StateSplit(type, state_before)
1716 , _begin(NULL)
1717 , _sux(NULL)
1718 {
1719 set_flag(IsSafepointFlag, is_safepoint);
1720 }
1722 // accessors
1723 bool is_safepoint() const { return check_flag(IsSafepointFlag); }
1724 BlockBegin* begin() const { return _begin; }
1726 // manipulation
1727 void set_begin(BlockBegin* begin);
1729 // successors
1730 int number_of_sux() const { return _sux != NULL ? _sux->length() : 0; }
1731 BlockBegin* sux_at(int i) const { return _sux->at(i); }
1732 BlockBegin* default_sux() const { return sux_at(number_of_sux() - 1); }
1733 BlockBegin** addr_sux_at(int i) const { return _sux->adr_at(i); }
1734 int sux_index(BlockBegin* sux) const { return _sux->find(sux); }
1735 void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1736 };
1739 LEAF(Goto, BlockEnd)
1740 public:
1741 enum Direction {
1742 none, // Just a regular goto
1743 taken, not_taken // Goto produced from If
1744 };
1745 private:
1746 ciMethod* _profiled_method;
1747 int _profiled_bci;
1748 Direction _direction;
1749 public:
1750 // creation
1751 Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false)
1752 : BlockEnd(illegalType, state_before, is_safepoint)
1753 , _direction(none)
1754 , _profiled_method(NULL)
1755 , _profiled_bci(0) {
1756 BlockList* s = new BlockList(1);
1757 s->append(sux);
1758 set_sux(s);
1759 }
1761 Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint)
1762 , _direction(none)
1763 , _profiled_method(NULL)
1764 , _profiled_bci(0) {
1765 BlockList* s = new BlockList(1);
1766 s->append(sux);
1767 set_sux(s);
1768 }
1770 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1771 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
1772 int profiled_bci() const { return _profiled_bci; }
1773 Direction direction() const { return _direction; }
1775 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1776 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1777 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1778 void set_direction(Direction d) { _direction = d; }
1779 };
1782 LEAF(If, BlockEnd)
1783 private:
1784 Value _x;
1785 Condition _cond;
1786 Value _y;
1787 ciMethod* _profiled_method;
1788 int _profiled_bci; // Canonicalizer may alter bci of If node
1789 bool _swapped; // Is the order reversed with respect to the original If in the
1790 // bytecode stream?
1791 public:
1792 // creation
1793 // unordered_is_true is valid for float/double compares only
1794 If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)
1795 : BlockEnd(illegalType, state_before, is_safepoint)
1796 , _x(x)
1797 , _cond(cond)
1798 , _y(y)
1799 , _profiled_method(NULL)
1800 , _profiled_bci(0)
1801 , _swapped(false)
1802 {
1803 ASSERT_VALUES
1804 set_flag(UnorderedIsTrueFlag, unordered_is_true);
1805 assert(x->type()->tag() == y->type()->tag(), "types must match");
1806 BlockList* s = new BlockList(2);
1807 s->append(tsux);
1808 s->append(fsux);
1809 set_sux(s);
1810 }
1812 // accessors
1813 Value x() const { return _x; }
1814 Condition cond() const { return _cond; }
1815 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
1816 Value y() const { return _y; }
1817 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
1818 BlockBegin* tsux() const { return sux_for(true); }
1819 BlockBegin* fsux() const { return sux_for(false); }
1820 BlockBegin* usux() const { return sux_for(unordered_is_true()); }
1821 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1822 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
1823 int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered
1824 bool is_swapped() const { return _swapped; }
1826 // manipulation
1827 void swap_operands() {
1828 Value t = _x; _x = _y; _y = t;
1829 _cond = mirror(_cond);
1830 }
1832 void swap_sux() {
1833 assert(number_of_sux() == 2, "wrong number of successors");
1834 BlockList* s = sux();
1835 BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
1836 _cond = negate(_cond);
1837 set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));
1838 }
1840 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1841 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1842 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1843 void set_swapped(bool value) { _swapped = value; }
1844 // generic
1845 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
1846 };
1849 LEAF(IfInstanceOf, BlockEnd)
1850 private:
1851 ciKlass* _klass;
1852 Value _obj;
1853 bool _test_is_instance; // jump if instance
1854 int _instanceof_bci;
1856 public:
1857 IfInstanceOf(ciKlass* klass, Value obj, bool test_is_instance, int instanceof_bci, BlockBegin* tsux, BlockBegin* fsux)
1858 : BlockEnd(illegalType, NULL, false) // temporary set to false
1859 , _klass(klass)
1860 , _obj(obj)
1861 , _test_is_instance(test_is_instance)
1862 , _instanceof_bci(instanceof_bci)
1863 {
1864 ASSERT_VALUES
1865 assert(instanceof_bci >= 0, "illegal bci");
1866 BlockList* s = new BlockList(2);
1867 s->append(tsux);
1868 s->append(fsux);
1869 set_sux(s);
1870 }
1872 // accessors
1873 //
1874 // Note 1: If test_is_instance() is true, IfInstanceOf tests if obj *is* an
1875 // instance of klass; otherwise it tests if it is *not* and instance
1876 // of klass.
1877 //
1878 // Note 2: IfInstanceOf instructions are created by combining an InstanceOf
1879 // and an If instruction. The IfInstanceOf bci() corresponds to the
1880 // bci that the If would have had; the (this->) instanceof_bci() is
1881 // the bci of the original InstanceOf instruction.
1882 ciKlass* klass() const { return _klass; }
1883 Value obj() const { return _obj; }
1884 int instanceof_bci() const { return _instanceof_bci; }
1885 bool test_is_instance() const { return _test_is_instance; }
1886 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
1887 BlockBegin* tsux() const { return sux_for(true); }
1888 BlockBegin* fsux() const { return sux_for(false); }
1890 // manipulation
1891 void swap_sux() {
1892 assert(number_of_sux() == 2, "wrong number of successors");
1893 BlockList* s = sux();
1894 BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
1895 _test_is_instance = !_test_is_instance;
1896 }
1898 // generic
1899 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_obj); }
1900 };
1903 BASE(Switch, BlockEnd)
1904 private:
1905 Value _tag;
1907 public:
1908 // creation
1909 Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
1910 : BlockEnd(illegalType, state_before, is_safepoint)
1911 , _tag(tag) {
1912 ASSERT_VALUES
1913 set_sux(sux);
1914 }
1916 // accessors
1917 Value tag() const { return _tag; }
1918 int length() const { return number_of_sux() - 1; }
1920 virtual bool needs_exception_state() const { return false; }
1922 // generic
1923 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_tag); }
1924 };
1927 LEAF(TableSwitch, Switch)
1928 private:
1929 int _lo_key;
1931 public:
1932 // creation
1933 TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)
1934 : Switch(tag, sux, state_before, is_safepoint)
1935 , _lo_key(lo_key) {}
1937 // accessors
1938 int lo_key() const { return _lo_key; }
1939 int hi_key() const { return _lo_key + length() - 1; }
1940 };
1943 LEAF(LookupSwitch, Switch)
1944 private:
1945 intArray* _keys;
1947 public:
1948 // creation
1949 LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)
1950 : Switch(tag, sux, state_before, is_safepoint)
1951 , _keys(keys) {
1952 assert(keys != NULL, "keys must exist");
1953 assert(keys->length() == length(), "sux & keys have incompatible lengths");
1954 }
1956 // accessors
1957 int key_at(int i) const { return _keys->at(i); }
1958 };
1961 LEAF(Return, BlockEnd)
1962 private:
1963 Value _result;
1965 public:
1966 // creation
1967 Return(Value result) :
1968 BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true),
1969 _result(result) {}
1971 // accessors
1972 Value result() const { return _result; }
1973 bool has_result() const { return result() != NULL; }
1975 // generic
1976 virtual void input_values_do(ValueVisitor* f) {
1977 BlockEnd::input_values_do(f);
1978 if (has_result()) f->visit(&_result);
1979 }
1980 };
1983 LEAF(Throw, BlockEnd)
1984 private:
1985 Value _exception;
1987 public:
1988 // creation
1989 Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {
1990 ASSERT_VALUES
1991 }
1993 // accessors
1994 Value exception() const { return _exception; }
1996 // generic
1997 virtual bool can_trap() const { return true; }
1998 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_exception); }
1999 };
2002 LEAF(Base, BlockEnd)
2003 public:
2004 // creation
2005 Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, NULL, false) {
2006 assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged");
2007 assert(osr_entry == NULL || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged");
2008 BlockList* s = new BlockList(2);
2009 if (osr_entry != NULL) s->append(osr_entry);
2010 s->append(std_entry); // must be default sux!
2011 set_sux(s);
2012 }
2014 // accessors
2015 BlockBegin* std_entry() const { return default_sux(); }
2016 BlockBegin* osr_entry() const { return number_of_sux() < 2 ? NULL : sux_at(0); }
2017 };
2020 LEAF(OsrEntry, Instruction)
2021 public:
2022 // creation
2023 #ifdef _LP64
2024 OsrEntry() : Instruction(longType) { pin(); }
2025 #else
2026 OsrEntry() : Instruction(intType) { pin(); }
2027 #endif
2029 // generic
2030 virtual void input_values_do(ValueVisitor* f) { }
2031 };
2034 // Models the incoming exception at a catch site
2035 LEAF(ExceptionObject, Instruction)
2036 public:
2037 // creation
2038 ExceptionObject() : Instruction(objectType) {
2039 pin();
2040 }
2042 // generic
2043 virtual void input_values_do(ValueVisitor* f) { }
2044 };
2047 // Models needed rounding for floating-point values on Intel.
2048 // Currently only used to represent rounding of double-precision
2049 // values stored into local variables, but could be used to model
2050 // intermediate rounding of single-precision values as well.
2051 LEAF(RoundFP, Instruction)
2052 private:
2053 Value _input; // floating-point value to be rounded
2055 public:
2056 RoundFP(Value input)
2057 : Instruction(input->type()) // Note: should not be used for constants
2058 , _input(input)
2059 {
2060 ASSERT_VALUES
2061 }
2063 // accessors
2064 Value input() const { return _input; }
2066 // generic
2067 virtual void input_values_do(ValueVisitor* f) { f->visit(&_input); }
2068 };
2071 BASE(UnsafeOp, Instruction)
2072 private:
2073 BasicType _basic_type; // ValueType can not express byte-sized integers
2075 protected:
2076 // creation
2077 UnsafeOp(BasicType basic_type, bool is_put)
2078 : Instruction(is_put ? voidType : as_ValueType(basic_type))
2079 , _basic_type(basic_type)
2080 {
2081 //Note: Unsafe ops are not not guaranteed to throw NPE.
2082 // Convservatively, Unsafe operations must be pinned though we could be
2083 // looser about this if we wanted to..
2084 pin();
2085 }
2087 public:
2088 // accessors
2089 BasicType basic_type() { return _basic_type; }
2091 // generic
2092 virtual void input_values_do(ValueVisitor* f) { }
2093 };
2096 BASE(UnsafeRawOp, UnsafeOp)
2097 private:
2098 Value _base; // Base address (a Java long)
2099 Value _index; // Index if computed by optimizer; initialized to NULL
2100 int _log2_scale; // Scale factor: 0, 1, 2, or 3.
2101 // Indicates log2 of number of bytes (1, 2, 4, or 8)
2102 // to scale index by.
2104 protected:
2105 UnsafeRawOp(BasicType basic_type, Value addr, bool is_put)
2106 : UnsafeOp(basic_type, is_put)
2107 , _base(addr)
2108 , _index(NULL)
2109 , _log2_scale(0)
2110 {
2111 // Can not use ASSERT_VALUES because index may be NULL
2112 assert(addr != NULL && addr->type()->is_long(), "just checking");
2113 }
2115 UnsafeRawOp(BasicType basic_type, Value base, Value index, int log2_scale, bool is_put)
2116 : UnsafeOp(basic_type, is_put)
2117 , _base(base)
2118 , _index(index)
2119 , _log2_scale(log2_scale)
2120 {
2121 }
2123 public:
2124 // accessors
2125 Value base() { return _base; }
2126 Value index() { return _index; }
2127 bool has_index() { return (_index != NULL); }
2128 int log2_scale() { return _log2_scale; }
2130 // setters
2131 void set_base (Value base) { _base = base; }
2132 void set_index(Value index) { _index = index; }
2133 void set_log2_scale(int log2_scale) { _log2_scale = log2_scale; }
2135 // generic
2136 virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f);
2137 f->visit(&_base);
2138 if (has_index()) f->visit(&_index); }
2139 };
2142 LEAF(UnsafeGetRaw, UnsafeRawOp)
2143 private:
2144 bool _may_be_unaligned, _is_wide; // For OSREntry
2146 public:
2147 UnsafeGetRaw(BasicType basic_type, Value addr, bool may_be_unaligned, bool is_wide = false)
2148 : UnsafeRawOp(basic_type, addr, false) {
2149 _may_be_unaligned = may_be_unaligned;
2150 _is_wide = is_wide;
2151 }
2153 UnsafeGetRaw(BasicType basic_type, Value base, Value index, int log2_scale, bool may_be_unaligned, bool is_wide = false)
2154 : UnsafeRawOp(basic_type, base, index, log2_scale, false) {
2155 _may_be_unaligned = may_be_unaligned;
2156 _is_wide = is_wide;
2157 }
2159 bool may_be_unaligned() { return _may_be_unaligned; }
2160 bool is_wide() { return _is_wide; }
2161 };
2164 LEAF(UnsafePutRaw, UnsafeRawOp)
2165 private:
2166 Value _value; // Value to be stored
2168 public:
2169 UnsafePutRaw(BasicType basic_type, Value addr, Value value)
2170 : UnsafeRawOp(basic_type, addr, true)
2171 , _value(value)
2172 {
2173 assert(value != NULL, "just checking");
2174 ASSERT_VALUES
2175 }
2177 UnsafePutRaw(BasicType basic_type, Value base, Value index, int log2_scale, Value value)
2178 : UnsafeRawOp(basic_type, base, index, log2_scale, true)
2179 , _value(value)
2180 {
2181 assert(value != NULL, "just checking");
2182 ASSERT_VALUES
2183 }
2185 // accessors
2186 Value value() { return _value; }
2188 // generic
2189 virtual void input_values_do(ValueVisitor* f) { UnsafeRawOp::input_values_do(f);
2190 f->visit(&_value); }
2191 };
2194 BASE(UnsafeObjectOp, UnsafeOp)
2195 private:
2196 Value _object; // Object to be fetched from or mutated
2197 Value _offset; // Offset within object
2198 bool _is_volatile; // true if volatile - dl/JSR166
2199 public:
2200 UnsafeObjectOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile)
2201 : UnsafeOp(basic_type, is_put), _object(object), _offset(offset), _is_volatile(is_volatile)
2202 {
2203 }
2205 // accessors
2206 Value object() { return _object; }
2207 Value offset() { return _offset; }
2208 bool is_volatile() { return _is_volatile; }
2209 // generic
2210 virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f);
2211 f->visit(&_object);
2212 f->visit(&_offset); }
2213 };
2216 LEAF(UnsafeGetObject, UnsafeObjectOp)
2217 public:
2218 UnsafeGetObject(BasicType basic_type, Value object, Value offset, bool is_volatile)
2219 : UnsafeObjectOp(basic_type, object, offset, false, is_volatile)
2220 {
2221 ASSERT_VALUES
2222 }
2223 };
2226 LEAF(UnsafePutObject, UnsafeObjectOp)
2227 private:
2228 Value _value; // Value to be stored
2229 public:
2230 UnsafePutObject(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile)
2231 : UnsafeObjectOp(basic_type, object, offset, true, is_volatile)
2232 , _value(value)
2233 {
2234 ASSERT_VALUES
2235 }
2237 // accessors
2238 Value value() { return _value; }
2240 // generic
2241 virtual void input_values_do(ValueVisitor* f) { UnsafeObjectOp::input_values_do(f);
2242 f->visit(&_value); }
2243 };
2246 BASE(UnsafePrefetch, UnsafeObjectOp)
2247 public:
2248 UnsafePrefetch(Value object, Value offset)
2249 : UnsafeObjectOp(T_VOID, object, offset, false, false)
2250 {
2251 }
2252 };
2255 LEAF(UnsafePrefetchRead, UnsafePrefetch)
2256 public:
2257 UnsafePrefetchRead(Value object, Value offset)
2258 : UnsafePrefetch(object, offset)
2259 {
2260 ASSERT_VALUES
2261 }
2262 };
2265 LEAF(UnsafePrefetchWrite, UnsafePrefetch)
2266 public:
2267 UnsafePrefetchWrite(Value object, Value offset)
2268 : UnsafePrefetch(object, offset)
2269 {
2270 ASSERT_VALUES
2271 }
2272 };
2274 LEAF(ProfileCall, Instruction)
2275 private:
2276 ciMethod* _method;
2277 int _bci_of_invoke;
2278 Value _recv;
2279 ciKlass* _known_holder;
2281 public:
2282 ProfileCall(ciMethod* method, int bci, Value recv, ciKlass* known_holder)
2283 : Instruction(voidType)
2284 , _method(method)
2285 , _bci_of_invoke(bci)
2286 , _recv(recv)
2287 , _known_holder(known_holder)
2288 {
2289 // The ProfileCall has side-effects and must occur precisely where located
2290 pin();
2291 }
2293 ciMethod* method() { return _method; }
2294 int bci_of_invoke() { return _bci_of_invoke; }
2295 Value recv() { return _recv; }
2296 ciKlass* known_holder() { return _known_holder; }
2298 virtual void input_values_do(ValueVisitor* f) { if (_recv != NULL) f->visit(&_recv); }
2299 };
2302 // Call some C runtime function that doesn't safepoint,
2303 // optionally passing the current thread as the first argument.
2304 LEAF(RuntimeCall, Instruction)
2305 private:
2306 const char* _entry_name;
2307 address _entry;
2308 Values* _args;
2309 bool _pass_thread; // Pass the JavaThread* as an implicit first argument
2311 public:
2312 RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2313 : Instruction(type)
2314 , _entry(entry)
2315 , _args(args)
2316 , _entry_name(entry_name)
2317 , _pass_thread(pass_thread) {
2318 ASSERT_VALUES
2319 pin();
2320 }
2322 const char* entry_name() const { return _entry_name; }
2323 address entry() const { return _entry; }
2324 int number_of_arguments() const { return _args->length(); }
2325 Value argument_at(int i) const { return _args->at(i); }
2326 bool pass_thread() const { return _pass_thread; }
2328 virtual void input_values_do(ValueVisitor* f) {
2329 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
2330 }
2331 };
2333 // Use to trip invocation counter of an inlined method
2335 LEAF(ProfileInvoke, Instruction)
2336 private:
2337 ciMethod* _inlinee;
2338 ValueStack* _state;
2340 public:
2341 ProfileInvoke(ciMethod* inlinee, ValueStack* state)
2342 : Instruction(voidType)
2343 , _inlinee(inlinee)
2344 , _state(state)
2345 {
2346 // The ProfileInvoke has side-effects and must occur precisely where located QQQ???
2347 pin();
2348 }
2350 ciMethod* inlinee() { return _inlinee; }
2351 ValueStack* state() { return _state; }
2352 virtual void input_values_do(ValueVisitor*) {}
2353 virtual void state_values_do(ValueVisitor*);
2354 };
2356 LEAF(MemBar, Instruction)
2357 private:
2358 LIR_Code _code;
2360 public:
2361 MemBar(LIR_Code code)
2362 : Instruction(voidType)
2363 , _code(code)
2364 {
2365 pin();
2366 }
2368 LIR_Code code() { return _code; }
2370 virtual void input_values_do(ValueVisitor*) {}
2371 };
2373 class BlockPair: public CompilationResourceObj {
2374 private:
2375 BlockBegin* _from;
2376 BlockBegin* _to;
2377 public:
2378 BlockPair(BlockBegin* from, BlockBegin* to): _from(from), _to(to) {}
2379 BlockBegin* from() const { return _from; }
2380 BlockBegin* to() const { return _to; }
2381 bool is_same(BlockBegin* from, BlockBegin* to) const { return _from == from && _to == to; }
2382 bool is_same(BlockPair* p) const { return _from == p->from() && _to == p->to(); }
2383 void set_to(BlockBegin* b) { _to = b; }
2384 void set_from(BlockBegin* b) { _from = b; }
2385 };
2388 define_array(BlockPairArray, BlockPair*)
2389 define_stack(BlockPairList, BlockPairArray)
2392 inline int BlockBegin::number_of_sux() const { assert(_end == NULL || _end->number_of_sux() == _successors.length(), "mismatch"); return _successors.length(); }
2393 inline BlockBegin* BlockBegin::sux_at(int i) const { assert(_end == NULL || _end->sux_at(i) == _successors.at(i), "mismatch"); return _successors.at(i); }
2394 inline void BlockBegin::add_successor(BlockBegin* sux) { assert(_end == NULL, "Would create mismatch with successors of BlockEnd"); _successors.append(sux); }
2396 #undef ASSERT_VALUES
2398 #endif // SHARE_VM_C1_C1_INSTRUCTION_HPP