Fri, 11 Mar 2011 22:34:57 -0800
7012648: move JSR 292 to package java.lang.invoke and adjust names
Summary: package and class renaming only; delete unused methods and classes
Reviewed-by: twisti
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 public:
625 // creation
626 Local(ValueType* type, int index)
627 : Instruction(type)
628 , _java_index(index)
629 {}
631 // accessors
632 int java_index() const { return _java_index; }
634 // generic
635 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
636 };
639 LEAF(Constant, Instruction)
640 public:
641 // creation
642 Constant(ValueType* type):
643 Instruction(type, NULL, true)
644 {
645 assert(type->is_constant(), "must be a constant");
646 }
648 Constant(ValueType* type, ValueStack* state_before):
649 Instruction(type, state_before, true)
650 {
651 assert(state_before != NULL, "only used for constants which need patching");
652 assert(type->is_constant(), "must be a constant");
653 // since it's patching it needs to be pinned
654 pin();
655 }
657 virtual bool can_trap() const { return state_before() != NULL; }
658 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
660 virtual intx hash() const;
661 virtual bool is_equal(Value v) const;
664 enum CompareResult { not_comparable = -1, cond_false, cond_true };
666 virtual CompareResult compare(Instruction::Condition condition, Value right) const;
667 BlockBegin* compare(Instruction::Condition cond, Value right,
668 BlockBegin* true_sux, BlockBegin* false_sux) const {
669 switch (compare(cond, right)) {
670 case not_comparable:
671 return NULL;
672 case cond_false:
673 return false_sux;
674 case cond_true:
675 return true_sux;
676 default:
677 ShouldNotReachHere();
678 return NULL;
679 }
680 }
681 };
684 BASE(AccessField, Instruction)
685 private:
686 Value _obj;
687 int _offset;
688 ciField* _field;
689 NullCheck* _explicit_null_check; // For explicit null check elimination
691 public:
692 // creation
693 AccessField(Value obj, int offset, ciField* field, bool is_static,
694 ValueStack* state_before, bool needs_patching)
695 : Instruction(as_ValueType(field->type()->basic_type()), state_before)
696 , _obj(obj)
697 , _offset(offset)
698 , _field(field)
699 , _explicit_null_check(NULL)
700 {
701 set_needs_null_check(!is_static);
702 set_flag(IsStaticFlag, is_static);
703 set_flag(NeedsPatchingFlag, needs_patching);
704 ASSERT_VALUES
705 // pin of all instructions with memory access
706 pin();
707 }
709 // accessors
710 Value obj() const { return _obj; }
711 int offset() const { return _offset; }
712 ciField* field() const { return _field; }
713 BasicType field_type() const { return _field->type()->basic_type(); }
714 bool is_static() const { return check_flag(IsStaticFlag); }
715 NullCheck* explicit_null_check() const { return _explicit_null_check; }
716 bool needs_patching() const { return check_flag(NeedsPatchingFlag); }
718 // Unresolved getstatic and putstatic can cause initialization.
719 // Technically it occurs at the Constant that materializes the base
720 // of the static fields but it's simpler to model it here.
721 bool is_init_point() const { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); }
723 // manipulation
725 // Under certain circumstances, if a previous NullCheck instruction
726 // proved the target object non-null, we can eliminate the explicit
727 // null check and do an implicit one, simply specifying the debug
728 // information from the NullCheck. This field should only be consulted
729 // if needs_null_check() is true.
730 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
732 // generic
733 virtual bool can_trap() const { return needs_null_check() || needs_patching(); }
734 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
735 };
738 LEAF(LoadField, AccessField)
739 public:
740 // creation
741 LoadField(Value obj, int offset, ciField* field, bool is_static,
742 ValueStack* state_before, bool needs_patching)
743 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
744 {}
746 ciType* declared_type() const;
747 ciType* exact_type() const;
749 // generic
750 HASHING2(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset()) // cannot be eliminated if needs patching or if volatile
751 };
754 LEAF(StoreField, AccessField)
755 private:
756 Value _value;
758 public:
759 // creation
760 StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
761 ValueStack* state_before, bool needs_patching)
762 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
763 , _value(value)
764 {
765 set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
766 ASSERT_VALUES
767 pin();
768 }
770 // accessors
771 Value value() const { return _value; }
772 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
774 // generic
775 virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); }
776 };
779 BASE(AccessArray, Instruction)
780 private:
781 Value _array;
783 public:
784 // creation
785 AccessArray(ValueType* type, Value array, ValueStack* state_before)
786 : Instruction(type, state_before)
787 , _array(array)
788 {
789 set_needs_null_check(true);
790 ASSERT_VALUES
791 pin(); // instruction with side effect (null exception or range check throwing)
792 }
794 Value array() const { return _array; }
796 // generic
797 virtual bool can_trap() const { return needs_null_check(); }
798 virtual void input_values_do(ValueVisitor* f) { f->visit(&_array); }
799 };
802 LEAF(ArrayLength, AccessArray)
803 private:
804 NullCheck* _explicit_null_check; // For explicit null check elimination
806 public:
807 // creation
808 ArrayLength(Value array, ValueStack* state_before)
809 : AccessArray(intType, array, state_before)
810 , _explicit_null_check(NULL) {}
812 // accessors
813 NullCheck* explicit_null_check() const { return _explicit_null_check; }
815 // setters
816 // See LoadField::set_explicit_null_check for documentation
817 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
819 // generic
820 HASHING1(ArrayLength, true, array()->subst())
821 };
824 BASE(AccessIndexed, AccessArray)
825 private:
826 Value _index;
827 Value _length;
828 BasicType _elt_type;
830 public:
831 // creation
832 AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
833 : AccessArray(as_ValueType(elt_type), array, state_before)
834 , _index(index)
835 , _length(length)
836 , _elt_type(elt_type)
837 {
838 ASSERT_VALUES
839 }
841 // accessors
842 Value index() const { return _index; }
843 Value length() const { return _length; }
844 BasicType elt_type() const { return _elt_type; }
846 // perform elimination of range checks involving constants
847 bool compute_needs_range_check();
849 // generic
850 virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }
851 };
854 LEAF(LoadIndexed, AccessIndexed)
855 private:
856 NullCheck* _explicit_null_check; // For explicit null check elimination
858 public:
859 // creation
860 LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
861 : AccessIndexed(array, index, length, elt_type, state_before)
862 , _explicit_null_check(NULL) {}
864 // accessors
865 NullCheck* explicit_null_check() const { return _explicit_null_check; }
867 // setters
868 // See LoadField::set_explicit_null_check for documentation
869 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
871 ciType* exact_type() const;
872 ciType* declared_type() const;
874 // generic
875 HASHING2(LoadIndexed, true, array()->subst(), index()->subst())
876 };
879 LEAF(StoreIndexed, AccessIndexed)
880 private:
881 Value _value;
883 ciMethod* _profiled_method;
884 int _profiled_bci;
885 public:
886 // creation
887 StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before)
888 : AccessIndexed(array, index, length, elt_type, state_before)
889 , _value(value), _profiled_method(NULL), _profiled_bci(0)
890 {
891 set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
892 set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
893 ASSERT_VALUES
894 pin();
895 }
897 // accessors
898 Value value() const { return _value; }
899 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
900 bool needs_store_check() const { return check_flag(NeedsStoreCheckFlag); }
901 // Helpers for methodDataOop profiling
902 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
903 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
904 void set_profiled_bci(int bci) { _profiled_bci = bci; }
905 bool should_profile() const { return check_flag(ProfileMDOFlag); }
906 ciMethod* profiled_method() const { return _profiled_method; }
907 int profiled_bci() const { return _profiled_bci; }
908 // generic
909 virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); }
910 };
913 LEAF(NegateOp, Instruction)
914 private:
915 Value _x;
917 public:
918 // creation
919 NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
920 ASSERT_VALUES
921 }
923 // accessors
924 Value x() const { return _x; }
926 // generic
927 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); }
928 };
931 BASE(Op2, Instruction)
932 private:
933 Bytecodes::Code _op;
934 Value _x;
935 Value _y;
937 public:
938 // creation
939 Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = NULL)
940 : Instruction(type, state_before)
941 , _op(op)
942 , _x(x)
943 , _y(y)
944 {
945 ASSERT_VALUES
946 }
948 // accessors
949 Bytecodes::Code op() const { return _op; }
950 Value x() const { return _x; }
951 Value y() const { return _y; }
953 // manipulators
954 void swap_operands() {
955 assert(is_commutative(), "operation must be commutative");
956 Value t = _x; _x = _y; _y = t;
957 }
959 // generic
960 virtual bool is_commutative() const { return false; }
961 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); }
962 };
965 LEAF(ArithmeticOp, Op2)
966 public:
967 // creation
968 ArithmeticOp(Bytecodes::Code op, Value x, Value y, bool is_strictfp, ValueStack* state_before)
969 : Op2(x->type()->meet(y->type()), op, x, y, state_before)
970 {
971 set_flag(IsStrictfpFlag, is_strictfp);
972 if (can_trap()) pin();
973 }
975 // accessors
976 bool is_strictfp() const { return check_flag(IsStrictfpFlag); }
978 // generic
979 virtual bool is_commutative() const;
980 virtual bool can_trap() const;
981 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
982 };
985 LEAF(ShiftOp, Op2)
986 public:
987 // creation
988 ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}
990 // generic
991 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
992 };
995 LEAF(LogicOp, Op2)
996 public:
997 // creation
998 LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}
1000 // generic
1001 virtual bool is_commutative() const;
1002 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1003 };
1006 LEAF(CompareOp, Op2)
1007 public:
1008 // creation
1009 CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1010 : Op2(intType, op, x, y, state_before)
1011 {}
1013 // generic
1014 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1015 };
1018 LEAF(IfOp, Op2)
1019 private:
1020 Value _tval;
1021 Value _fval;
1023 public:
1024 // creation
1025 IfOp(Value x, Condition cond, Value y, Value tval, Value fval)
1026 : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1027 , _tval(tval)
1028 , _fval(fval)
1029 {
1030 ASSERT_VALUES
1031 assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1032 }
1034 // accessors
1035 virtual bool is_commutative() const;
1036 Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }
1037 Condition cond() const { return (Condition)Op2::op(); }
1038 Value tval() const { return _tval; }
1039 Value fval() const { return _fval; }
1041 // generic
1042 virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1043 };
1046 LEAF(Convert, Instruction)
1047 private:
1048 Bytecodes::Code _op;
1049 Value _value;
1051 public:
1052 // creation
1053 Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1054 ASSERT_VALUES
1055 }
1057 // accessors
1058 Bytecodes::Code op() const { return _op; }
1059 Value value() const { return _value; }
1061 // generic
1062 virtual void input_values_do(ValueVisitor* f) { f->visit(&_value); }
1063 HASHING2(Convert, true, op(), value()->subst())
1064 };
1067 LEAF(NullCheck, Instruction)
1068 private:
1069 Value _obj;
1071 public:
1072 // creation
1073 NullCheck(Value obj, ValueStack* state_before)
1074 : Instruction(obj->type()->base(), state_before)
1075 , _obj(obj)
1076 {
1077 ASSERT_VALUES
1078 set_can_trap(true);
1079 assert(_obj->type()->is_object(), "null check must be applied to objects only");
1080 pin(Instruction::PinExplicitNullCheck);
1081 }
1083 // accessors
1084 Value obj() const { return _obj; }
1086 // setters
1087 void set_can_trap(bool can_trap) { set_flag(CanTrapFlag, can_trap); }
1089 // generic
1090 virtual bool can_trap() const { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }
1091 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
1092 HASHING1(NullCheck, true, obj()->subst())
1093 };
1096 BASE(StateSplit, Instruction)
1097 private:
1098 ValueStack* _state;
1100 protected:
1101 static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);
1103 public:
1104 // creation
1105 StateSplit(ValueType* type, ValueStack* state_before = NULL)
1106 : Instruction(type, state_before)
1107 , _state(NULL)
1108 {
1109 pin(PinStateSplitConstructor);
1110 }
1112 // accessors
1113 ValueStack* state() const { return _state; }
1114 IRScope* scope() const; // the state's scope
1116 // manipulation
1117 void set_state(ValueStack* state) { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }
1119 // generic
1120 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
1121 virtual void state_values_do(ValueVisitor* f);
1122 };
1125 LEAF(Invoke, StateSplit)
1126 private:
1127 Bytecodes::Code _code;
1128 Value _recv;
1129 Values* _args;
1130 BasicTypeList* _signature;
1131 int _vtable_index;
1132 ciMethod* _target;
1134 public:
1135 // creation
1136 Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1137 int vtable_index, ciMethod* target, ValueStack* state_before);
1139 // accessors
1140 Bytecodes::Code code() const { return _code; }
1141 Value receiver() const { return _recv; }
1142 bool has_receiver() const { return receiver() != NULL; }
1143 int number_of_arguments() const { return _args->length(); }
1144 Value argument_at(int i) const { return _args->at(i); }
1145 int vtable_index() const { return _vtable_index; }
1146 BasicTypeList* signature() const { return _signature; }
1147 ciMethod* target() const { return _target; }
1149 // Returns false if target is not loaded
1150 bool target_is_final() const { return check_flag(TargetIsFinalFlag); }
1151 bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }
1152 // Returns false if target is not loaded
1153 bool target_is_strictfp() const { return check_flag(TargetIsStrictfpFlag); }
1155 // JSR 292 support
1156 bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }
1158 virtual bool needs_exception_state() const { return false; }
1160 // generic
1161 virtual bool can_trap() const { return true; }
1162 virtual void input_values_do(ValueVisitor* f) {
1163 StateSplit::input_values_do(f);
1164 if (has_receiver()) f->visit(&_recv);
1165 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1166 }
1167 virtual void state_values_do(ValueVisitor *f);
1168 };
1171 LEAF(NewInstance, StateSplit)
1172 private:
1173 ciInstanceKlass* _klass;
1175 public:
1176 // creation
1177 NewInstance(ciInstanceKlass* klass, ValueStack* state_before)
1178 : StateSplit(instanceType, state_before)
1179 , _klass(klass)
1180 {}
1182 // accessors
1183 ciInstanceKlass* klass() const { return _klass; }
1185 virtual bool needs_exception_state() const { return false; }
1187 // generic
1188 virtual bool can_trap() const { return true; }
1189 ciType* exact_type() const;
1190 };
1193 BASE(NewArray, StateSplit)
1194 private:
1195 Value _length;
1197 public:
1198 // creation
1199 NewArray(Value length, ValueStack* state_before)
1200 : StateSplit(objectType, state_before)
1201 , _length(length)
1202 {
1203 // Do not ASSERT_VALUES since length is NULL for NewMultiArray
1204 }
1206 // accessors
1207 Value length() const { return _length; }
1209 virtual bool needs_exception_state() const { return false; }
1211 // generic
1212 virtual bool can_trap() const { return true; }
1213 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_length); }
1214 };
1217 LEAF(NewTypeArray, NewArray)
1218 private:
1219 BasicType _elt_type;
1221 public:
1222 // creation
1223 NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)
1224 : NewArray(length, state_before)
1225 , _elt_type(elt_type)
1226 {}
1228 // accessors
1229 BasicType elt_type() const { return _elt_type; }
1230 ciType* exact_type() const;
1231 };
1234 LEAF(NewObjectArray, NewArray)
1235 private:
1236 ciKlass* _klass;
1238 public:
1239 // creation
1240 NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}
1242 // accessors
1243 ciKlass* klass() const { return _klass; }
1244 ciType* exact_type() const;
1245 };
1248 LEAF(NewMultiArray, NewArray)
1249 private:
1250 ciKlass* _klass;
1251 Values* _dims;
1253 public:
1254 // creation
1255 NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
1256 ASSERT_VALUES
1257 }
1259 // accessors
1260 ciKlass* klass() const { return _klass; }
1261 Values* dims() const { return _dims; }
1262 int rank() const { return dims()->length(); }
1264 // generic
1265 virtual void input_values_do(ValueVisitor* f) {
1266 // NOTE: we do not call NewArray::input_values_do since "length"
1267 // is meaningless for a multi-dimensional array; passing the
1268 // zeroth element down to NewArray as its length is a bad idea
1269 // since there will be a copy in the "dims" array which doesn't
1270 // get updated, and the value must not be traversed twice. Was bug
1271 // - kbr 4/10/2001
1272 StateSplit::input_values_do(f);
1273 for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1274 }
1275 };
1278 BASE(TypeCheck, StateSplit)
1279 private:
1280 ciKlass* _klass;
1281 Value _obj;
1283 ciMethod* _profiled_method;
1284 int _profiled_bci;
1286 public:
1287 // creation
1288 TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1289 : StateSplit(type, state_before), _klass(klass), _obj(obj),
1290 _profiled_method(NULL), _profiled_bci(0) {
1291 ASSERT_VALUES
1292 set_direct_compare(false);
1293 }
1295 // accessors
1296 ciKlass* klass() const { return _klass; }
1297 Value obj() const { return _obj; }
1298 bool is_loaded() const { return klass() != NULL; }
1299 bool direct_compare() const { return check_flag(DirectCompareFlag); }
1301 // manipulation
1302 void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }
1304 // generic
1305 virtual bool can_trap() const { return true; }
1306 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1308 // Helpers for methodDataOop profiling
1309 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1310 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1311 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1312 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1313 ciMethod* profiled_method() const { return _profiled_method; }
1314 int profiled_bci() const { return _profiled_bci; }
1315 };
1318 LEAF(CheckCast, TypeCheck)
1319 public:
1320 // creation
1321 CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1322 : TypeCheck(klass, obj, objectType, state_before) {}
1324 void set_incompatible_class_change_check() {
1325 set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1326 }
1327 bool is_incompatible_class_change_check() const {
1328 return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1329 }
1331 ciType* declared_type() const;
1332 ciType* exact_type() const;
1333 };
1336 LEAF(InstanceOf, TypeCheck)
1337 public:
1338 // creation
1339 InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}
1341 virtual bool needs_exception_state() const { return false; }
1342 };
1345 BASE(AccessMonitor, StateSplit)
1346 private:
1347 Value _obj;
1348 int _monitor_no;
1350 public:
1351 // creation
1352 AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)
1353 : StateSplit(illegalType, state_before)
1354 , _obj(obj)
1355 , _monitor_no(monitor_no)
1356 {
1357 set_needs_null_check(true);
1358 ASSERT_VALUES
1359 }
1361 // accessors
1362 Value obj() const { return _obj; }
1363 int monitor_no() const { return _monitor_no; }
1365 // generic
1366 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1367 };
1370 LEAF(MonitorEnter, AccessMonitor)
1371 public:
1372 // creation
1373 MonitorEnter(Value obj, int monitor_no, ValueStack* state_before)
1374 : AccessMonitor(obj, monitor_no, state_before)
1375 {
1376 ASSERT_VALUES
1377 }
1379 // generic
1380 virtual bool can_trap() const { return true; }
1381 };
1384 LEAF(MonitorExit, AccessMonitor)
1385 public:
1386 // creation
1387 MonitorExit(Value obj, int monitor_no)
1388 : AccessMonitor(obj, monitor_no, NULL)
1389 {
1390 ASSERT_VALUES
1391 }
1392 };
1395 LEAF(Intrinsic, StateSplit)
1396 private:
1397 vmIntrinsics::ID _id;
1398 Values* _args;
1399 Value _recv;
1401 public:
1402 // preserves_state can be set to true for Intrinsics
1403 // which are guaranteed to preserve register state across any slow
1404 // cases; setting it to true does not mean that the Intrinsic can
1405 // not trap, only that if we continue execution in the same basic
1406 // block after the Intrinsic, all of the registers are intact. This
1407 // allows load elimination and common expression elimination to be
1408 // performed across the Intrinsic. The default value is false.
1409 Intrinsic(ValueType* type,
1410 vmIntrinsics::ID id,
1411 Values* args,
1412 bool has_receiver,
1413 ValueStack* state_before,
1414 bool preserves_state,
1415 bool cantrap = true)
1416 : StateSplit(type, state_before)
1417 , _id(id)
1418 , _args(args)
1419 , _recv(NULL)
1420 {
1421 assert(args != NULL, "args must exist");
1422 ASSERT_VALUES
1423 set_flag(PreservesStateFlag, preserves_state);
1424 set_flag(CanTrapFlag, cantrap);
1425 if (has_receiver) {
1426 _recv = argument_at(0);
1427 }
1428 set_needs_null_check(has_receiver);
1430 // some intrinsics can't trap, so don't force them to be pinned
1431 if (!can_trap()) {
1432 unpin(PinStateSplitConstructor);
1433 }
1434 }
1436 // accessors
1437 vmIntrinsics::ID id() const { return _id; }
1438 int number_of_arguments() const { return _args->length(); }
1439 Value argument_at(int i) const { return _args->at(i); }
1441 bool has_receiver() const { return (_recv != NULL); }
1442 Value receiver() const { assert(has_receiver(), "must have receiver"); return _recv; }
1443 bool preserves_state() const { return check_flag(PreservesStateFlag); }
1445 // generic
1446 virtual bool can_trap() const { return check_flag(CanTrapFlag); }
1447 virtual void input_values_do(ValueVisitor* f) {
1448 StateSplit::input_values_do(f);
1449 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1450 }
1451 };
1454 class LIR_List;
1456 LEAF(BlockBegin, StateSplit)
1457 private:
1458 int _block_id; // the unique block id
1459 int _bci; // start-bci of block
1460 int _depth_first_number; // number of this block in a depth-first ordering
1461 int _linear_scan_number; // number of this block in linear-scan ordering
1462 int _loop_depth; // the loop nesting level of this block
1463 int _loop_index; // number of the innermost loop of this block
1464 int _flags; // the flags associated with this block
1466 // fields used by BlockListBuilder
1467 int _total_preds; // number of predecessors found by BlockListBuilder
1468 BitMap _stores_to_locals; // bit is set when a local variable is stored in the block
1470 // SSA specific fields: (factor out later)
1471 BlockList _successors; // the successors of this block
1472 BlockList _predecessors; // the predecessors of this block
1473 BlockBegin* _dominator; // the dominator of this block
1474 // SSA specific ends
1475 BlockEnd* _end; // the last instruction of this block
1476 BlockList _exception_handlers; // the exception handlers potentially invoked by this block
1477 ValueStackStack* _exception_states; // only for xhandler entries: states of all instructions that have an edge to this xhandler
1478 int _exception_handler_pco; // if this block is the start of an exception handler,
1479 // this records the PC offset in the assembly code of the
1480 // first instruction in this block
1481 Label _label; // the label associated with this block
1482 LIR_List* _lir; // the low level intermediate representation for this block
1484 BitMap _live_in; // set of live LIR_Opr registers at entry to this block
1485 BitMap _live_out; // set of live LIR_Opr registers at exit from this block
1486 BitMap _live_gen; // set of registers used before any redefinition in this block
1487 BitMap _live_kill; // set of registers defined in this block
1489 BitMap _fpu_register_usage;
1490 intArray* _fpu_stack_state; // For x86 FPU code generation with UseLinearScan
1491 int _first_lir_instruction_id; // ID of first LIR instruction in this block
1492 int _last_lir_instruction_id; // ID of last LIR instruction in this block
1494 void iterate_preorder (boolArray& mark, BlockClosure* closure);
1495 void iterate_postorder(boolArray& mark, BlockClosure* closure);
1497 friend class SuxAndWeightAdjuster;
1499 public:
1500 void* operator new(size_t size) {
1501 Compilation* c = Compilation::current();
1502 void* res = c->arena()->Amalloc(size);
1503 ((BlockBegin*)res)->_id = c->get_next_id();
1504 ((BlockBegin*)res)->_block_id = c->get_next_block_id();
1505 return res;
1506 }
1508 // initialization/counting
1509 static int number_of_blocks() {
1510 return Compilation::current()->number_of_blocks();
1511 }
1513 // creation
1514 BlockBegin(int bci)
1515 : StateSplit(illegalType)
1516 , _bci(bci)
1517 , _depth_first_number(-1)
1518 , _linear_scan_number(-1)
1519 , _loop_depth(0)
1520 , _flags(0)
1521 , _dominator(NULL)
1522 , _end(NULL)
1523 , _predecessors(2)
1524 , _successors(2)
1525 , _exception_handlers(1)
1526 , _exception_states(NULL)
1527 , _exception_handler_pco(-1)
1528 , _lir(NULL)
1529 , _loop_index(-1)
1530 , _live_in()
1531 , _live_out()
1532 , _live_gen()
1533 , _live_kill()
1534 , _fpu_register_usage()
1535 , _fpu_stack_state(NULL)
1536 , _first_lir_instruction_id(-1)
1537 , _last_lir_instruction_id(-1)
1538 , _total_preds(0)
1539 , _stores_to_locals()
1540 {
1541 #ifndef PRODUCT
1542 set_printable_bci(bci);
1543 #endif
1544 }
1546 // accessors
1547 int block_id() const { return _block_id; }
1548 int bci() const { return _bci; }
1549 BlockList* successors() { return &_successors; }
1550 BlockBegin* dominator() const { return _dominator; }
1551 int loop_depth() const { return _loop_depth; }
1552 int depth_first_number() const { return _depth_first_number; }
1553 int linear_scan_number() const { return _linear_scan_number; }
1554 BlockEnd* end() const { return _end; }
1555 Label* label() { return &_label; }
1556 LIR_List* lir() const { return _lir; }
1557 int exception_handler_pco() const { return _exception_handler_pco; }
1558 BitMap& live_in() { return _live_in; }
1559 BitMap& live_out() { return _live_out; }
1560 BitMap& live_gen() { return _live_gen; }
1561 BitMap& live_kill() { return _live_kill; }
1562 BitMap& fpu_register_usage() { return _fpu_register_usage; }
1563 intArray* fpu_stack_state() const { return _fpu_stack_state; }
1564 int first_lir_instruction_id() const { return _first_lir_instruction_id; }
1565 int last_lir_instruction_id() const { return _last_lir_instruction_id; }
1566 int total_preds() const { return _total_preds; }
1567 BitMap& stores_to_locals() { return _stores_to_locals; }
1569 // manipulation
1570 void set_dominator(BlockBegin* dom) { _dominator = dom; }
1571 void set_loop_depth(int d) { _loop_depth = d; }
1572 void set_depth_first_number(int dfn) { _depth_first_number = dfn; }
1573 void set_linear_scan_number(int lsn) { _linear_scan_number = lsn; }
1574 void set_end(BlockEnd* end);
1575 void disconnect_from_graph();
1576 static void disconnect_edge(BlockBegin* from, BlockBegin* to);
1577 BlockBegin* insert_block_between(BlockBegin* sux);
1578 void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1579 void set_lir(LIR_List* lir) { _lir = lir; }
1580 void set_exception_handler_pco(int pco) { _exception_handler_pco = pco; }
1581 void set_live_in (BitMap map) { _live_in = map; }
1582 void set_live_out (BitMap map) { _live_out = map; }
1583 void set_live_gen (BitMap map) { _live_gen = map; }
1584 void set_live_kill (BitMap map) { _live_kill = map; }
1585 void set_fpu_register_usage(BitMap map) { _fpu_register_usage = map; }
1586 void set_fpu_stack_state(intArray* state) { _fpu_stack_state = state; }
1587 void set_first_lir_instruction_id(int id) { _first_lir_instruction_id = id; }
1588 void set_last_lir_instruction_id(int id) { _last_lir_instruction_id = id; }
1589 void increment_total_preds(int n = 1) { _total_preds += n; }
1590 void init_stores_to_locals(int locals_count) { _stores_to_locals = BitMap(locals_count); _stores_to_locals.clear(); }
1592 // generic
1593 virtual void state_values_do(ValueVisitor* f);
1595 // successors and predecessors
1596 int number_of_sux() const;
1597 BlockBegin* sux_at(int i) const;
1598 void add_successor(BlockBegin* sux);
1599 void remove_successor(BlockBegin* pred);
1600 bool is_successor(BlockBegin* sux) const { return _successors.contains(sux); }
1602 void add_predecessor(BlockBegin* pred);
1603 void remove_predecessor(BlockBegin* pred);
1604 bool is_predecessor(BlockBegin* pred) const { return _predecessors.contains(pred); }
1605 int number_of_preds() const { return _predecessors.length(); }
1606 BlockBegin* pred_at(int i) const { return _predecessors[i]; }
1608 // exception handlers potentially invoked by this block
1609 void add_exception_handler(BlockBegin* b);
1610 bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }
1611 int number_of_exception_handlers() const { return _exception_handlers.length(); }
1612 BlockBegin* exception_handler_at(int i) const { return _exception_handlers.at(i); }
1614 // states of the instructions that have an edge to this exception handler
1615 int number_of_exception_states() { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); }
1616 ValueStack* exception_state_at(int idx) const { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }
1617 int add_exception_state(ValueStack* state);
1619 // flags
1620 enum Flag {
1621 no_flag = 0,
1622 std_entry_flag = 1 << 0,
1623 osr_entry_flag = 1 << 1,
1624 exception_entry_flag = 1 << 2,
1625 subroutine_entry_flag = 1 << 3,
1626 backward_branch_target_flag = 1 << 4,
1627 is_on_work_list_flag = 1 << 5,
1628 was_visited_flag = 1 << 6,
1629 parser_loop_header_flag = 1 << 7, // set by parser to identify blocks where phi functions can not be created on demand
1630 critical_edge_split_flag = 1 << 8, // set for all blocks that are introduced when critical edges are split
1631 linear_scan_loop_header_flag = 1 << 9, // set during loop-detection for LinearScan
1632 linear_scan_loop_end_flag = 1 << 10 // set during loop-detection for LinearScan
1633 };
1635 void set(Flag f) { _flags |= f; }
1636 void clear(Flag f) { _flags &= ~f; }
1637 bool is_set(Flag f) const { return (_flags & f) != 0; }
1638 bool is_entry_block() const {
1639 const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;
1640 return (_flags & entry_mask) != 0;
1641 }
1643 // iteration
1644 void iterate_preorder (BlockClosure* closure);
1645 void iterate_postorder (BlockClosure* closure);
1647 void block_values_do(ValueVisitor* f);
1649 // loops
1650 void set_loop_index(int ix) { _loop_index = ix; }
1651 int loop_index() const { return _loop_index; }
1653 // merging
1654 bool try_merge(ValueStack* state); // try to merge states at block begin
1655 void merge(ValueStack* state) { bool b = try_merge(state); assert(b, "merge failed"); }
1657 // debugging
1658 void print_block() PRODUCT_RETURN;
1659 void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;
1660 };
1663 BASE(BlockEnd, StateSplit)
1664 private:
1665 BlockBegin* _begin;
1666 BlockList* _sux;
1668 protected:
1669 BlockList* sux() const { return _sux; }
1671 void set_sux(BlockList* sux) {
1672 #ifdef ASSERT
1673 assert(sux != NULL, "sux must exist");
1674 for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist");
1675 #endif
1676 _sux = sux;
1677 }
1679 public:
1680 // creation
1681 BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)
1682 : StateSplit(type, state_before)
1683 , _begin(NULL)
1684 , _sux(NULL)
1685 {
1686 set_flag(IsSafepointFlag, is_safepoint);
1687 }
1689 // accessors
1690 bool is_safepoint() const { return check_flag(IsSafepointFlag); }
1691 BlockBegin* begin() const { return _begin; }
1693 // manipulation
1694 void set_begin(BlockBegin* begin);
1696 // successors
1697 int number_of_sux() const { return _sux != NULL ? _sux->length() : 0; }
1698 BlockBegin* sux_at(int i) const { return _sux->at(i); }
1699 BlockBegin* default_sux() const { return sux_at(number_of_sux() - 1); }
1700 BlockBegin** addr_sux_at(int i) const { return _sux->adr_at(i); }
1701 int sux_index(BlockBegin* sux) const { return _sux->find(sux); }
1702 void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1703 };
1706 LEAF(Goto, BlockEnd)
1707 public:
1708 enum Direction {
1709 none, // Just a regular goto
1710 taken, not_taken // Goto produced from If
1711 };
1712 private:
1713 ciMethod* _profiled_method;
1714 int _profiled_bci;
1715 Direction _direction;
1716 public:
1717 // creation
1718 Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false)
1719 : BlockEnd(illegalType, state_before, is_safepoint)
1720 , _direction(none)
1721 , _profiled_method(NULL)
1722 , _profiled_bci(0) {
1723 BlockList* s = new BlockList(1);
1724 s->append(sux);
1725 set_sux(s);
1726 }
1728 Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint)
1729 , _direction(none)
1730 , _profiled_method(NULL)
1731 , _profiled_bci(0) {
1732 BlockList* s = new BlockList(1);
1733 s->append(sux);
1734 set_sux(s);
1735 }
1737 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1738 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
1739 int profiled_bci() const { return _profiled_bci; }
1740 Direction direction() const { return _direction; }
1742 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1743 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1744 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1745 void set_direction(Direction d) { _direction = d; }
1746 };
1749 LEAF(If, BlockEnd)
1750 private:
1751 Value _x;
1752 Condition _cond;
1753 Value _y;
1754 ciMethod* _profiled_method;
1755 int _profiled_bci; // Canonicalizer may alter bci of If node
1756 bool _swapped; // Is the order reversed with respect to the original If in the
1757 // bytecode stream?
1758 public:
1759 // creation
1760 // unordered_is_true is valid for float/double compares only
1761 If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)
1762 : BlockEnd(illegalType, state_before, is_safepoint)
1763 , _x(x)
1764 , _cond(cond)
1765 , _y(y)
1766 , _profiled_method(NULL)
1767 , _profiled_bci(0)
1768 , _swapped(false)
1769 {
1770 ASSERT_VALUES
1771 set_flag(UnorderedIsTrueFlag, unordered_is_true);
1772 assert(x->type()->tag() == y->type()->tag(), "types must match");
1773 BlockList* s = new BlockList(2);
1774 s->append(tsux);
1775 s->append(fsux);
1776 set_sux(s);
1777 }
1779 // accessors
1780 Value x() const { return _x; }
1781 Condition cond() const { return _cond; }
1782 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
1783 Value y() const { return _y; }
1784 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
1785 BlockBegin* tsux() const { return sux_for(true); }
1786 BlockBegin* fsux() const { return sux_for(false); }
1787 BlockBegin* usux() const { return sux_for(unordered_is_true()); }
1788 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1789 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
1790 int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered
1791 bool is_swapped() const { return _swapped; }
1793 // manipulation
1794 void swap_operands() {
1795 Value t = _x; _x = _y; _y = t;
1796 _cond = mirror(_cond);
1797 }
1799 void swap_sux() {
1800 assert(number_of_sux() == 2, "wrong number of successors");
1801 BlockList* s = sux();
1802 BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
1803 _cond = negate(_cond);
1804 set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));
1805 }
1807 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1808 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1809 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1810 void set_swapped(bool value) { _swapped = value; }
1811 // generic
1812 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
1813 };
1816 LEAF(IfInstanceOf, BlockEnd)
1817 private:
1818 ciKlass* _klass;
1819 Value _obj;
1820 bool _test_is_instance; // jump if instance
1821 int _instanceof_bci;
1823 public:
1824 IfInstanceOf(ciKlass* klass, Value obj, bool test_is_instance, int instanceof_bci, BlockBegin* tsux, BlockBegin* fsux)
1825 : BlockEnd(illegalType, NULL, false) // temporary set to false
1826 , _klass(klass)
1827 , _obj(obj)
1828 , _test_is_instance(test_is_instance)
1829 , _instanceof_bci(instanceof_bci)
1830 {
1831 ASSERT_VALUES
1832 assert(instanceof_bci >= 0, "illegal bci");
1833 BlockList* s = new BlockList(2);
1834 s->append(tsux);
1835 s->append(fsux);
1836 set_sux(s);
1837 }
1839 // accessors
1840 //
1841 // Note 1: If test_is_instance() is true, IfInstanceOf tests if obj *is* an
1842 // instance of klass; otherwise it tests if it is *not* and instance
1843 // of klass.
1844 //
1845 // Note 2: IfInstanceOf instructions are created by combining an InstanceOf
1846 // and an If instruction. The IfInstanceOf bci() corresponds to the
1847 // bci that the If would have had; the (this->) instanceof_bci() is
1848 // the bci of the original InstanceOf instruction.
1849 ciKlass* klass() const { return _klass; }
1850 Value obj() const { return _obj; }
1851 int instanceof_bci() const { return _instanceof_bci; }
1852 bool test_is_instance() const { return _test_is_instance; }
1853 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
1854 BlockBegin* tsux() const { return sux_for(true); }
1855 BlockBegin* fsux() const { return sux_for(false); }
1857 // manipulation
1858 void swap_sux() {
1859 assert(number_of_sux() == 2, "wrong number of successors");
1860 BlockList* s = sux();
1861 BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
1862 _test_is_instance = !_test_is_instance;
1863 }
1865 // generic
1866 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_obj); }
1867 };
1870 BASE(Switch, BlockEnd)
1871 private:
1872 Value _tag;
1874 public:
1875 // creation
1876 Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
1877 : BlockEnd(illegalType, state_before, is_safepoint)
1878 , _tag(tag) {
1879 ASSERT_VALUES
1880 set_sux(sux);
1881 }
1883 // accessors
1884 Value tag() const { return _tag; }
1885 int length() const { return number_of_sux() - 1; }
1887 virtual bool needs_exception_state() const { return false; }
1889 // generic
1890 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_tag); }
1891 };
1894 LEAF(TableSwitch, Switch)
1895 private:
1896 int _lo_key;
1898 public:
1899 // creation
1900 TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)
1901 : Switch(tag, sux, state_before, is_safepoint)
1902 , _lo_key(lo_key) {}
1904 // accessors
1905 int lo_key() const { return _lo_key; }
1906 int hi_key() const { return _lo_key + length() - 1; }
1907 };
1910 LEAF(LookupSwitch, Switch)
1911 private:
1912 intArray* _keys;
1914 public:
1915 // creation
1916 LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)
1917 : Switch(tag, sux, state_before, is_safepoint)
1918 , _keys(keys) {
1919 assert(keys != NULL, "keys must exist");
1920 assert(keys->length() == length(), "sux & keys have incompatible lengths");
1921 }
1923 // accessors
1924 int key_at(int i) const { return _keys->at(i); }
1925 };
1928 LEAF(Return, BlockEnd)
1929 private:
1930 Value _result;
1932 public:
1933 // creation
1934 Return(Value result) :
1935 BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true),
1936 _result(result) {}
1938 // accessors
1939 Value result() const { return _result; }
1940 bool has_result() const { return result() != NULL; }
1942 // generic
1943 virtual void input_values_do(ValueVisitor* f) {
1944 BlockEnd::input_values_do(f);
1945 if (has_result()) f->visit(&_result);
1946 }
1947 };
1950 LEAF(Throw, BlockEnd)
1951 private:
1952 Value _exception;
1954 public:
1955 // creation
1956 Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {
1957 ASSERT_VALUES
1958 }
1960 // accessors
1961 Value exception() const { return _exception; }
1963 // generic
1964 virtual bool can_trap() const { return true; }
1965 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_exception); }
1966 };
1969 LEAF(Base, BlockEnd)
1970 public:
1971 // creation
1972 Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, NULL, false) {
1973 assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged");
1974 assert(osr_entry == NULL || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged");
1975 BlockList* s = new BlockList(2);
1976 if (osr_entry != NULL) s->append(osr_entry);
1977 s->append(std_entry); // must be default sux!
1978 set_sux(s);
1979 }
1981 // accessors
1982 BlockBegin* std_entry() const { return default_sux(); }
1983 BlockBegin* osr_entry() const { return number_of_sux() < 2 ? NULL : sux_at(0); }
1984 };
1987 LEAF(OsrEntry, Instruction)
1988 public:
1989 // creation
1990 #ifdef _LP64
1991 OsrEntry() : Instruction(longType) { pin(); }
1992 #else
1993 OsrEntry() : Instruction(intType) { pin(); }
1994 #endif
1996 // generic
1997 virtual void input_values_do(ValueVisitor* f) { }
1998 };
2001 // Models the incoming exception at a catch site
2002 LEAF(ExceptionObject, Instruction)
2003 public:
2004 // creation
2005 ExceptionObject() : Instruction(objectType) {
2006 pin();
2007 }
2009 // generic
2010 virtual void input_values_do(ValueVisitor* f) { }
2011 };
2014 // Models needed rounding for floating-point values on Intel.
2015 // Currently only used to represent rounding of double-precision
2016 // values stored into local variables, but could be used to model
2017 // intermediate rounding of single-precision values as well.
2018 LEAF(RoundFP, Instruction)
2019 private:
2020 Value _input; // floating-point value to be rounded
2022 public:
2023 RoundFP(Value input)
2024 : Instruction(input->type()) // Note: should not be used for constants
2025 , _input(input)
2026 {
2027 ASSERT_VALUES
2028 }
2030 // accessors
2031 Value input() const { return _input; }
2033 // generic
2034 virtual void input_values_do(ValueVisitor* f) { f->visit(&_input); }
2035 };
2038 BASE(UnsafeOp, Instruction)
2039 private:
2040 BasicType _basic_type; // ValueType can not express byte-sized integers
2042 protected:
2043 // creation
2044 UnsafeOp(BasicType basic_type, bool is_put)
2045 : Instruction(is_put ? voidType : as_ValueType(basic_type))
2046 , _basic_type(basic_type)
2047 {
2048 //Note: Unsafe ops are not not guaranteed to throw NPE.
2049 // Convservatively, Unsafe operations must be pinned though we could be
2050 // looser about this if we wanted to..
2051 pin();
2052 }
2054 public:
2055 // accessors
2056 BasicType basic_type() { return _basic_type; }
2058 // generic
2059 virtual void input_values_do(ValueVisitor* f) { }
2060 };
2063 BASE(UnsafeRawOp, UnsafeOp)
2064 private:
2065 Value _base; // Base address (a Java long)
2066 Value _index; // Index if computed by optimizer; initialized to NULL
2067 int _log2_scale; // Scale factor: 0, 1, 2, or 3.
2068 // Indicates log2 of number of bytes (1, 2, 4, or 8)
2069 // to scale index by.
2071 protected:
2072 UnsafeRawOp(BasicType basic_type, Value addr, bool is_put)
2073 : UnsafeOp(basic_type, is_put)
2074 , _base(addr)
2075 , _index(NULL)
2076 , _log2_scale(0)
2077 {
2078 // Can not use ASSERT_VALUES because index may be NULL
2079 assert(addr != NULL && addr->type()->is_long(), "just checking");
2080 }
2082 UnsafeRawOp(BasicType basic_type, Value base, Value index, int log2_scale, bool is_put)
2083 : UnsafeOp(basic_type, is_put)
2084 , _base(base)
2085 , _index(index)
2086 , _log2_scale(log2_scale)
2087 {
2088 }
2090 public:
2091 // accessors
2092 Value base() { return _base; }
2093 Value index() { return _index; }
2094 bool has_index() { return (_index != NULL); }
2095 int log2_scale() { return _log2_scale; }
2097 // setters
2098 void set_base (Value base) { _base = base; }
2099 void set_index(Value index) { _index = index; }
2100 void set_log2_scale(int log2_scale) { _log2_scale = log2_scale; }
2102 // generic
2103 virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f);
2104 f->visit(&_base);
2105 if (has_index()) f->visit(&_index); }
2106 };
2109 LEAF(UnsafeGetRaw, UnsafeRawOp)
2110 private:
2111 bool _may_be_unaligned, _is_wide; // For OSREntry
2113 public:
2114 UnsafeGetRaw(BasicType basic_type, Value addr, bool may_be_unaligned, bool is_wide = false)
2115 : UnsafeRawOp(basic_type, addr, false) {
2116 _may_be_unaligned = may_be_unaligned;
2117 _is_wide = is_wide;
2118 }
2120 UnsafeGetRaw(BasicType basic_type, Value base, Value index, int log2_scale, bool may_be_unaligned, bool is_wide = false)
2121 : UnsafeRawOp(basic_type, base, index, log2_scale, false) {
2122 _may_be_unaligned = may_be_unaligned;
2123 _is_wide = is_wide;
2124 }
2126 bool may_be_unaligned() { return _may_be_unaligned; }
2127 bool is_wide() { return _is_wide; }
2128 };
2131 LEAF(UnsafePutRaw, UnsafeRawOp)
2132 private:
2133 Value _value; // Value to be stored
2135 public:
2136 UnsafePutRaw(BasicType basic_type, Value addr, Value value)
2137 : UnsafeRawOp(basic_type, addr, true)
2138 , _value(value)
2139 {
2140 assert(value != NULL, "just checking");
2141 ASSERT_VALUES
2142 }
2144 UnsafePutRaw(BasicType basic_type, Value base, Value index, int log2_scale, Value value)
2145 : UnsafeRawOp(basic_type, base, index, log2_scale, true)
2146 , _value(value)
2147 {
2148 assert(value != NULL, "just checking");
2149 ASSERT_VALUES
2150 }
2152 // accessors
2153 Value value() { return _value; }
2155 // generic
2156 virtual void input_values_do(ValueVisitor* f) { UnsafeRawOp::input_values_do(f);
2157 f->visit(&_value); }
2158 };
2161 BASE(UnsafeObjectOp, UnsafeOp)
2162 private:
2163 Value _object; // Object to be fetched from or mutated
2164 Value _offset; // Offset within object
2165 bool _is_volatile; // true if volatile - dl/JSR166
2166 public:
2167 UnsafeObjectOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile)
2168 : UnsafeOp(basic_type, is_put), _object(object), _offset(offset), _is_volatile(is_volatile)
2169 {
2170 }
2172 // accessors
2173 Value object() { return _object; }
2174 Value offset() { return _offset; }
2175 bool is_volatile() { return _is_volatile; }
2176 // generic
2177 virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f);
2178 f->visit(&_object);
2179 f->visit(&_offset); }
2180 };
2183 LEAF(UnsafeGetObject, UnsafeObjectOp)
2184 public:
2185 UnsafeGetObject(BasicType basic_type, Value object, Value offset, bool is_volatile)
2186 : UnsafeObjectOp(basic_type, object, offset, false, is_volatile)
2187 {
2188 ASSERT_VALUES
2189 }
2190 };
2193 LEAF(UnsafePutObject, UnsafeObjectOp)
2194 private:
2195 Value _value; // Value to be stored
2196 public:
2197 UnsafePutObject(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile)
2198 : UnsafeObjectOp(basic_type, object, offset, true, is_volatile)
2199 , _value(value)
2200 {
2201 ASSERT_VALUES
2202 }
2204 // accessors
2205 Value value() { return _value; }
2207 // generic
2208 virtual void input_values_do(ValueVisitor* f) { UnsafeObjectOp::input_values_do(f);
2209 f->visit(&_value); }
2210 };
2213 BASE(UnsafePrefetch, UnsafeObjectOp)
2214 public:
2215 UnsafePrefetch(Value object, Value offset)
2216 : UnsafeObjectOp(T_VOID, object, offset, false, false)
2217 {
2218 }
2219 };
2222 LEAF(UnsafePrefetchRead, UnsafePrefetch)
2223 public:
2224 UnsafePrefetchRead(Value object, Value offset)
2225 : UnsafePrefetch(object, offset)
2226 {
2227 ASSERT_VALUES
2228 }
2229 };
2232 LEAF(UnsafePrefetchWrite, UnsafePrefetch)
2233 public:
2234 UnsafePrefetchWrite(Value object, Value offset)
2235 : UnsafePrefetch(object, offset)
2236 {
2237 ASSERT_VALUES
2238 }
2239 };
2241 LEAF(ProfileCall, Instruction)
2242 private:
2243 ciMethod* _method;
2244 int _bci_of_invoke;
2245 Value _recv;
2246 ciKlass* _known_holder;
2248 public:
2249 ProfileCall(ciMethod* method, int bci, Value recv, ciKlass* known_holder)
2250 : Instruction(voidType)
2251 , _method(method)
2252 , _bci_of_invoke(bci)
2253 , _recv(recv)
2254 , _known_holder(known_holder)
2255 {
2256 // The ProfileCall has side-effects and must occur precisely where located
2257 pin();
2258 }
2260 ciMethod* method() { return _method; }
2261 int bci_of_invoke() { return _bci_of_invoke; }
2262 Value recv() { return _recv; }
2263 ciKlass* known_holder() { return _known_holder; }
2265 virtual void input_values_do(ValueVisitor* f) { if (_recv != NULL) f->visit(&_recv); }
2266 };
2269 // Call some C runtime function that doesn't safepoint,
2270 // optionally passing the current thread as the first argument.
2271 LEAF(RuntimeCall, Instruction)
2272 private:
2273 const char* _entry_name;
2274 address _entry;
2275 Values* _args;
2276 bool _pass_thread; // Pass the JavaThread* as an implicit first argument
2278 public:
2279 RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)
2280 : Instruction(type)
2281 , _entry(entry)
2282 , _args(args)
2283 , _entry_name(entry_name)
2284 , _pass_thread(pass_thread) {
2285 ASSERT_VALUES
2286 pin();
2287 }
2289 const char* entry_name() const { return _entry_name; }
2290 address entry() const { return _entry; }
2291 int number_of_arguments() const { return _args->length(); }
2292 Value argument_at(int i) const { return _args->at(i); }
2293 bool pass_thread() const { return _pass_thread; }
2295 virtual void input_values_do(ValueVisitor* f) {
2296 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
2297 }
2298 };
2300 // Use to trip invocation counter of an inlined method
2302 LEAF(ProfileInvoke, Instruction)
2303 private:
2304 ciMethod* _inlinee;
2305 ValueStack* _state;
2307 public:
2308 ProfileInvoke(ciMethod* inlinee, ValueStack* state)
2309 : Instruction(voidType)
2310 , _inlinee(inlinee)
2311 , _state(state)
2312 {
2313 // The ProfileInvoke has side-effects and must occur precisely where located QQQ???
2314 pin();
2315 }
2317 ciMethod* inlinee() { return _inlinee; }
2318 ValueStack* state() { return _state; }
2319 virtual void input_values_do(ValueVisitor*) {}
2320 virtual void state_values_do(ValueVisitor*);
2321 };
2323 class BlockPair: public CompilationResourceObj {
2324 private:
2325 BlockBegin* _from;
2326 BlockBegin* _to;
2327 public:
2328 BlockPair(BlockBegin* from, BlockBegin* to): _from(from), _to(to) {}
2329 BlockBegin* from() const { return _from; }
2330 BlockBegin* to() const { return _to; }
2331 bool is_same(BlockBegin* from, BlockBegin* to) const { return _from == from && _to == to; }
2332 bool is_same(BlockPair* p) const { return _from == p->from() && _to == p->to(); }
2333 void set_to(BlockBegin* b) { _to = b; }
2334 void set_from(BlockBegin* b) { _from = b; }
2335 };
2338 define_array(BlockPairArray, BlockPair*)
2339 define_stack(BlockPairList, BlockPairArray)
2342 inline int BlockBegin::number_of_sux() const { assert(_end == NULL || _end->number_of_sux() == _successors.length(), "mismatch"); return _successors.length(); }
2343 inline BlockBegin* BlockBegin::sux_at(int i) const { assert(_end == NULL || _end->sux_at(i) == _successors.at(i), "mismatch"); return _successors.at(i); }
2344 inline void BlockBegin::add_successor(BlockBegin* sux) { assert(_end == NULL, "Would create mismatch with successors of BlockEnd"); _successors.append(sux); }
2346 #undef ASSERT_VALUES
2348 #endif // SHARE_VM_C1_C1_INSTRUCTION_HPP