aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_C1_C1_INSTRUCTION_HPP aoqi@0: #define SHARE_VM_C1_C1_INSTRUCTION_HPP aoqi@0: aoqi@0: #include "c1/c1_Compilation.hpp" aoqi@0: #include "c1/c1_LIR.hpp" aoqi@0: #include "c1/c1_ValueType.hpp" aoqi@0: #include "ci/ciField.hpp" aoqi@0: aoqi@0: // Predefined classes aoqi@0: class ciField; aoqi@0: class ValueStack; aoqi@0: class InstructionPrinter; aoqi@0: class IRScope; aoqi@0: class LIR_OprDesc; aoqi@0: typedef LIR_OprDesc* LIR_Opr; aoqi@0: aoqi@0: aoqi@0: // Instruction class hierarchy aoqi@0: // aoqi@0: // All leaf classes in the class hierarchy are concrete classes aoqi@0: // (i.e., are instantiated). All other classes are abstract and aoqi@0: // serve factoring. aoqi@0: aoqi@0: class Instruction; aoqi@0: class Phi; aoqi@0: class Local; aoqi@0: class Constant; aoqi@0: class AccessField; aoqi@0: class LoadField; aoqi@0: class StoreField; aoqi@0: class AccessArray; aoqi@0: class ArrayLength; aoqi@0: class AccessIndexed; aoqi@0: class LoadIndexed; aoqi@0: class StoreIndexed; aoqi@0: class NegateOp; aoqi@0: class Op2; aoqi@0: class ArithmeticOp; aoqi@0: class ShiftOp; aoqi@0: class LogicOp; aoqi@0: class CompareOp; aoqi@0: class IfOp; aoqi@0: class Convert; aoqi@0: class NullCheck; aoqi@0: class TypeCast; aoqi@0: class OsrEntry; aoqi@0: class ExceptionObject; aoqi@0: class StateSplit; aoqi@0: class Invoke; aoqi@0: class NewInstance; aoqi@0: class NewArray; aoqi@0: class NewTypeArray; aoqi@0: class NewObjectArray; aoqi@0: class NewMultiArray; aoqi@0: class TypeCheck; aoqi@0: class CheckCast; aoqi@0: class InstanceOf; aoqi@0: class AccessMonitor; aoqi@0: class MonitorEnter; aoqi@0: class MonitorExit; aoqi@0: class Intrinsic; aoqi@0: class BlockBegin; aoqi@0: class BlockEnd; aoqi@0: class Goto; aoqi@0: class If; aoqi@0: class IfInstanceOf; aoqi@0: class Switch; aoqi@0: class TableSwitch; aoqi@0: class LookupSwitch; aoqi@0: class Return; aoqi@0: class Throw; aoqi@0: class Base; aoqi@0: class RoundFP; aoqi@0: class UnsafeOp; aoqi@0: class UnsafeRawOp; aoqi@0: class UnsafeGetRaw; aoqi@0: class UnsafePutRaw; aoqi@0: class UnsafeObjectOp; aoqi@0: class UnsafeGetObject; aoqi@0: class UnsafePutObject; aoqi@0: class UnsafeGetAndSetObject; aoqi@0: class UnsafePrefetch; aoqi@0: class UnsafePrefetchRead; aoqi@0: class UnsafePrefetchWrite; aoqi@0: class ProfileCall; aoqi@0: class ProfileReturnType; aoqi@0: class ProfileInvoke; aoqi@0: class RuntimeCall; aoqi@0: class MemBar; aoqi@0: class RangeCheckPredicate; aoqi@0: #ifdef ASSERT aoqi@0: class Assert; aoqi@0: #endif aoqi@0: aoqi@0: // A Value is a reference to the instruction creating the value aoqi@0: typedef Instruction* Value; aoqi@0: define_array(ValueArray, Value) aoqi@0: define_stack(Values, ValueArray) aoqi@0: aoqi@0: define_array(ValueStackArray, ValueStack*) aoqi@0: define_stack(ValueStackStack, ValueStackArray) aoqi@0: aoqi@0: // BlockClosure is the base class for block traversal/iteration. aoqi@0: aoqi@0: class BlockClosure: public CompilationResourceObj { aoqi@0: public: aoqi@0: virtual void block_do(BlockBegin* block) = 0; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // A simple closure class for visiting the values of an Instruction aoqi@0: class ValueVisitor: public StackObj { aoqi@0: public: aoqi@0: virtual void visit(Value* v) = 0; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // Some array and list classes aoqi@0: define_array(BlockBeginArray, BlockBegin*) aoqi@0: define_stack(_BlockList, BlockBeginArray) aoqi@0: aoqi@0: class BlockList: public _BlockList { aoqi@0: public: aoqi@0: BlockList(): _BlockList() {} aoqi@0: BlockList(const int size): _BlockList(size) {} aoqi@0: BlockList(const int size, BlockBegin* init): _BlockList(size, init) {} aoqi@0: aoqi@0: void iterate_forward(BlockClosure* closure); aoqi@0: void iterate_backward(BlockClosure* closure); aoqi@0: void blocks_do(void f(BlockBegin*)); aoqi@0: void values_do(ValueVisitor* f); aoqi@0: void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // InstructionVisitors provide type-based dispatch for instructions. aoqi@0: // For each concrete Instruction class X, a virtual function do_X is aoqi@0: // provided. Functionality that needs to be implemented for all classes aoqi@0: // (e.g., printing, code generation) is factored out into a specialised aoqi@0: // visitor instead of added to the Instruction classes itself. aoqi@0: aoqi@0: class InstructionVisitor: public StackObj { aoqi@0: public: aoqi@0: virtual void do_Phi (Phi* x) = 0; aoqi@0: virtual void do_Local (Local* x) = 0; aoqi@0: virtual void do_Constant (Constant* x) = 0; aoqi@0: virtual void do_LoadField (LoadField* x) = 0; aoqi@0: virtual void do_StoreField (StoreField* x) = 0; aoqi@0: virtual void do_ArrayLength (ArrayLength* x) = 0; aoqi@0: virtual void do_LoadIndexed (LoadIndexed* x) = 0; aoqi@0: virtual void do_StoreIndexed (StoreIndexed* x) = 0; aoqi@0: virtual void do_NegateOp (NegateOp* x) = 0; aoqi@0: virtual void do_ArithmeticOp (ArithmeticOp* x) = 0; aoqi@0: virtual void do_ShiftOp (ShiftOp* x) = 0; aoqi@0: virtual void do_LogicOp (LogicOp* x) = 0; aoqi@0: virtual void do_CompareOp (CompareOp* x) = 0; aoqi@0: virtual void do_IfOp (IfOp* x) = 0; aoqi@0: virtual void do_Convert (Convert* x) = 0; aoqi@0: virtual void do_NullCheck (NullCheck* x) = 0; aoqi@0: virtual void do_TypeCast (TypeCast* x) = 0; aoqi@0: virtual void do_Invoke (Invoke* x) = 0; aoqi@0: virtual void do_NewInstance (NewInstance* x) = 0; aoqi@0: virtual void do_NewTypeArray (NewTypeArray* x) = 0; aoqi@0: virtual void do_NewObjectArray (NewObjectArray* x) = 0; aoqi@0: virtual void do_NewMultiArray (NewMultiArray* x) = 0; aoqi@0: virtual void do_CheckCast (CheckCast* x) = 0; aoqi@0: virtual void do_InstanceOf (InstanceOf* x) = 0; aoqi@0: virtual void do_MonitorEnter (MonitorEnter* x) = 0; aoqi@0: virtual void do_MonitorExit (MonitorExit* x) = 0; aoqi@0: virtual void do_Intrinsic (Intrinsic* x) = 0; aoqi@0: virtual void do_BlockBegin (BlockBegin* x) = 0; aoqi@0: virtual void do_Goto (Goto* x) = 0; aoqi@0: virtual void do_If (If* x) = 0; aoqi@0: virtual void do_IfInstanceOf (IfInstanceOf* x) = 0; aoqi@0: virtual void do_TableSwitch (TableSwitch* x) = 0; aoqi@0: virtual void do_LookupSwitch (LookupSwitch* x) = 0; aoqi@0: virtual void do_Return (Return* x) = 0; aoqi@0: virtual void do_Throw (Throw* x) = 0; aoqi@0: virtual void do_Base (Base* x) = 0; aoqi@0: virtual void do_OsrEntry (OsrEntry* x) = 0; aoqi@0: virtual void do_ExceptionObject(ExceptionObject* x) = 0; aoqi@0: virtual void do_RoundFP (RoundFP* x) = 0; aoqi@0: virtual void do_UnsafeGetRaw (UnsafeGetRaw* x) = 0; aoqi@0: virtual void do_UnsafePutRaw (UnsafePutRaw* x) = 0; aoqi@0: virtual void do_UnsafeGetObject(UnsafeGetObject* x) = 0; aoqi@0: virtual void do_UnsafePutObject(UnsafePutObject* x) = 0; aoqi@0: virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) = 0; aoqi@0: virtual void do_UnsafePrefetchRead (UnsafePrefetchRead* x) = 0; aoqi@0: virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) = 0; aoqi@0: virtual void do_ProfileCall (ProfileCall* x) = 0; aoqi@0: virtual void do_ProfileReturnType (ProfileReturnType* x) = 0; aoqi@0: virtual void do_ProfileInvoke (ProfileInvoke* x) = 0; aoqi@0: virtual void do_RuntimeCall (RuntimeCall* x) = 0; aoqi@0: virtual void do_MemBar (MemBar* x) = 0; aoqi@0: virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0; aoqi@0: #ifdef ASSERT aoqi@0: virtual void do_Assert (Assert* x) = 0; aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // Hashing support aoqi@0: // aoqi@0: // Note: This hash functions affect the performance aoqi@0: // of ValueMap - make changes carefully! aoqi@0: aoqi@0: #define HASH1(x1 ) ((intx)(x1)) aoqi@0: #define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2)) aoqi@0: #define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3)) aoqi@0: #define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4)) aoqi@0: aoqi@0: aoqi@0: // The following macros are used to implement instruction-specific hashing. aoqi@0: // By default, each instruction implements hash() and is_equal(Value), used aoqi@0: // for value numbering/common subexpression elimination. The default imple- aoqi@0: // mentation disables value numbering. Each instruction which can be value- aoqi@0: // numbered, should define corresponding hash() and is_equal(Value) functions aoqi@0: // via the macros below. The f arguments specify all the values/op codes, etc. aoqi@0: // that need to be identical for two instructions to be identical. aoqi@0: // aoqi@0: // Note: The default implementation of hash() returns 0 in order to indicate aoqi@0: // that the instruction should not be considered for value numbering. aoqi@0: // The currently used hash functions do not guarantee that never a 0 aoqi@0: // is produced. While this is still correct, it may be a performance aoqi@0: // bug (no value numbering for that node). However, this situation is aoqi@0: // so unlikely, that we are not going to handle it specially. aoqi@0: aoqi@0: #define HASHING1(class_name, enabled, f1) \ aoqi@0: virtual intx hash() const { \ aoqi@0: return (enabled) ? HASH2(name(), f1) : 0; \ aoqi@0: } \ aoqi@0: virtual bool is_equal(Value v) const { \ aoqi@0: if (!(enabled) ) return false; \ aoqi@0: class_name* _v = v->as_##class_name(); \ aoqi@0: if (_v == NULL ) return false; \ aoqi@0: if (f1 != _v->f1) return false; \ aoqi@0: return true; \ aoqi@0: } \ aoqi@0: aoqi@0: aoqi@0: #define HASHING2(class_name, enabled, f1, f2) \ aoqi@0: virtual intx hash() const { \ aoqi@0: return (enabled) ? HASH3(name(), f1, f2) : 0; \ aoqi@0: } \ aoqi@0: virtual bool is_equal(Value v) const { \ aoqi@0: if (!(enabled) ) return false; \ aoqi@0: class_name* _v = v->as_##class_name(); \ aoqi@0: if (_v == NULL ) return false; \ aoqi@0: if (f1 != _v->f1) return false; \ aoqi@0: if (f2 != _v->f2) return false; \ aoqi@0: return true; \ aoqi@0: } \ aoqi@0: aoqi@0: aoqi@0: #define HASHING3(class_name, enabled, f1, f2, f3) \ aoqi@0: virtual intx hash() const { \ aoqi@0: return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \ aoqi@0: } \ aoqi@0: virtual bool is_equal(Value v) const { \ aoqi@0: if (!(enabled) ) return false; \ aoqi@0: class_name* _v = v->as_##class_name(); \ aoqi@0: if (_v == NULL ) return false; \ aoqi@0: if (f1 != _v->f1) return false; \ aoqi@0: if (f2 != _v->f2) return false; \ aoqi@0: if (f3 != _v->f3) return false; \ aoqi@0: return true; \ aoqi@0: } \ aoqi@0: aoqi@0: aoqi@0: // The mother of all instructions... aoqi@0: aoqi@0: class Instruction: public CompilationResourceObj { aoqi@0: private: aoqi@0: int _id; // the unique instruction id aoqi@0: #ifndef PRODUCT aoqi@0: int _printable_bci; // the bci of the instruction for printing aoqi@0: #endif aoqi@0: int _use_count; // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1 aoqi@0: int _pin_state; // set of PinReason describing the reason for pinning aoqi@0: ValueType* _type; // the instruction value type aoqi@0: Instruction* _next; // the next instruction if any (NULL for BlockEnd instructions) aoqi@0: Instruction* _subst; // the substitution instruction if any aoqi@0: LIR_Opr _operand; // LIR specific information aoqi@0: unsigned int _flags; // Flag bits aoqi@0: aoqi@0: ValueStack* _state_before; // Copy of state with input operands still on stack (or NULL) aoqi@0: ValueStack* _exception_state; // Copy of state for exception handling aoqi@0: XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction aoqi@0: aoqi@0: friend class UseCountComputer; aoqi@0: friend class BlockBegin; aoqi@0: aoqi@0: void update_exception_state(ValueStack* state); aoqi@0: aoqi@0: protected: aoqi@0: BlockBegin* _block; // Block that contains this instruction aoqi@0: aoqi@0: void set_type(ValueType* type) { aoqi@0: assert(type != NULL, "type must exist"); aoqi@0: _type = type; aoqi@0: } aoqi@0: aoqi@0: // Helper class to keep track of which arguments need a null check aoqi@0: class ArgsNonNullState { aoqi@0: private: aoqi@0: int _nonnull_state; // mask identifying which args are nonnull aoqi@0: public: aoqi@0: ArgsNonNullState() aoqi@0: : _nonnull_state(AllBits) {} aoqi@0: aoqi@0: // Does argument number i needs a null check? aoqi@0: bool arg_needs_null_check(int i) const { aoqi@0: // No data is kept for arguments starting at position 33 so aoqi@0: // conservatively assume that they need a null check. aoqi@0: if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) { aoqi@0: return is_set_nth_bit(_nonnull_state, i); aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: // Set whether argument number i needs a null check or not aoqi@0: void set_arg_needs_null_check(int i, bool check) { aoqi@0: if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) { aoqi@0: if (check) { aoqi@0: _nonnull_state |= nth_bit(i); aoqi@0: } else { aoqi@0: _nonnull_state &= ~(nth_bit(i)); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: public: aoqi@0: void* operator new(size_t size) throw() { aoqi@0: Compilation* c = Compilation::current(); aoqi@0: void* res = c->arena()->Amalloc(size); aoqi@0: ((Instruction*)res)->_id = c->get_next_id(); aoqi@0: return res; aoqi@0: } aoqi@0: aoqi@0: static const int no_bci = -99; aoqi@0: aoqi@0: enum InstructionFlag { aoqi@0: NeedsNullCheckFlag = 0, aoqi@0: CanTrapFlag, aoqi@0: DirectCompareFlag, aoqi@0: IsEliminatedFlag, aoqi@0: IsSafepointFlag, aoqi@0: IsStaticFlag, aoqi@0: IsStrictfpFlag, aoqi@0: NeedsStoreCheckFlag, aoqi@0: NeedsWriteBarrierFlag, aoqi@0: PreservesStateFlag, aoqi@0: TargetIsFinalFlag, aoqi@0: TargetIsLoadedFlag, aoqi@0: TargetIsStrictfpFlag, aoqi@0: UnorderedIsTrueFlag, aoqi@0: NeedsPatchingFlag, aoqi@0: ThrowIncompatibleClassChangeErrorFlag, aoqi@0: ProfileMDOFlag, aoqi@0: IsLinkedInBlockFlag, aoqi@0: NeedsRangeCheckFlag, aoqi@0: InWorkListFlag, aoqi@0: DeoptimizeOnException, aoqi@0: InstructionLastFlag aoqi@0: }; aoqi@0: aoqi@0: public: aoqi@0: bool check_flag(InstructionFlag id) const { return (_flags & (1 << id)) != 0; } aoqi@0: void set_flag(InstructionFlag id, bool f) { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); }; aoqi@0: aoqi@0: // 'globally' used condition values aoqi@0: enum Condition { aoqi@0: eql, neq, lss, leq, gtr, geq, aeq, beq aoqi@0: }; aoqi@0: aoqi@0: // Instructions may be pinned for many reasons and under certain conditions aoqi@0: // with enough knowledge it's possible to safely unpin them. aoqi@0: enum PinReason { aoqi@0: PinUnknown = 1 << 0 aoqi@0: , PinExplicitNullCheck = 1 << 3 aoqi@0: , PinStackForStateSplit= 1 << 12 aoqi@0: , PinStateSplitConstructor= 1 << 13 aoqi@0: , PinGlobalValueNumbering= 1 << 14 aoqi@0: }; aoqi@0: aoqi@0: static Condition mirror(Condition cond); aoqi@0: static Condition negate(Condition cond); aoqi@0: aoqi@0: // initialization aoqi@0: static int number_of_instructions() { aoqi@0: return Compilation::current()->number_of_instructions(); aoqi@0: } aoqi@0: aoqi@0: // creation aoqi@0: Instruction(ValueType* type, ValueStack* state_before = NULL, bool type_is_constant = false) aoqi@0: : _use_count(0) aoqi@0: #ifndef PRODUCT aoqi@0: , _printable_bci(-99) aoqi@0: #endif aoqi@0: , _pin_state(0) aoqi@0: , _type(type) aoqi@0: , _next(NULL) aoqi@0: , _block(NULL) aoqi@0: , _subst(NULL) aoqi@0: , _flags(0) aoqi@0: , _operand(LIR_OprFact::illegalOpr) aoqi@0: , _state_before(state_before) aoqi@0: , _exception_handlers(NULL) aoqi@0: { aoqi@0: check_state(state_before); aoqi@0: assert(type != NULL && (!type->is_constant() || type_is_constant), "type must exist"); aoqi@0: update_exception_state(_state_before); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: int id() const { return _id; } aoqi@0: #ifndef PRODUCT aoqi@0: bool has_printable_bci() const { return _printable_bci != -99; } aoqi@0: int printable_bci() const { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; } aoqi@0: void set_printable_bci(int bci) { _printable_bci = bci; } aoqi@0: #endif aoqi@0: int dominator_depth(); aoqi@0: int use_count() const { return _use_count; } aoqi@0: int pin_state() const { return _pin_state; } aoqi@0: bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; } aoqi@0: ValueType* type() const { return _type; } aoqi@0: BlockBegin *block() const { return _block; } aoqi@0: Instruction* prev(); // use carefully, expensive operation aoqi@0: Instruction* next() const { return _next; } aoqi@0: bool has_subst() const { return _subst != NULL; } aoqi@0: Instruction* subst() { return _subst == NULL ? this : _subst->subst(); } aoqi@0: LIR_Opr operand() const { return _operand; } aoqi@0: aoqi@0: void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); } aoqi@0: bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); } aoqi@0: bool is_linked() const { return check_flag(IsLinkedInBlockFlag); } aoqi@0: bool can_be_linked() { return as_Local() == NULL && as_Phi() == NULL; } aoqi@0: aoqi@0: bool has_uses() const { return use_count() > 0; } aoqi@0: ValueStack* state_before() const { return _state_before; } aoqi@0: ValueStack* exception_state() const { return _exception_state; } aoqi@0: virtual bool needs_exception_state() const { return true; } aoqi@0: XHandlers* exception_handlers() const { return _exception_handlers; } aoqi@0: aoqi@0: // manipulation aoqi@0: void pin(PinReason reason) { _pin_state |= reason; } aoqi@0: void pin() { _pin_state |= PinUnknown; } aoqi@0: // DANGEROUS: only used by EliminateStores aoqi@0: void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; } aoqi@0: aoqi@0: Instruction* set_next(Instruction* next) { aoqi@0: assert(next->has_printable_bci(), "_printable_bci should have been set"); aoqi@0: assert(next != NULL, "must not be NULL"); aoqi@0: assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next"); aoqi@0: assert(next->can_be_linked(), "shouldn't link these instructions into list"); aoqi@0: aoqi@0: BlockBegin *block = this->block(); aoqi@0: next->_block = block; aoqi@0: aoqi@0: next->set_flag(Instruction::IsLinkedInBlockFlag, true); aoqi@0: _next = next; aoqi@0: return next; aoqi@0: } aoqi@0: aoqi@0: Instruction* set_next(Instruction* next, int bci) { aoqi@0: #ifndef PRODUCT aoqi@0: next->set_printable_bci(bci); aoqi@0: #endif aoqi@0: return set_next(next); aoqi@0: } aoqi@0: aoqi@0: // when blocks are merged aoqi@0: void fixup_block_pointers() { aoqi@0: Instruction *cur = next()->next(); // next()'s block is set in set_next aoqi@0: while (cur && cur->_block != block()) { aoqi@0: cur->_block = block(); aoqi@0: cur = cur->next(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: Instruction *insert_after(Instruction *i) { aoqi@0: Instruction* n = _next; aoqi@0: set_next(i); aoqi@0: i->set_next(n); aoqi@0: return _next; aoqi@0: } aoqi@0: aoqi@0: Instruction *insert_after_same_bci(Instruction *i) { aoqi@0: #ifndef PRODUCT aoqi@0: i->set_printable_bci(printable_bci()); aoqi@0: #endif aoqi@0: return insert_after(i); aoqi@0: } aoqi@0: aoqi@0: void set_subst(Instruction* subst) { aoqi@0: assert(subst == NULL || aoqi@0: type()->base() == subst->type()->base() || aoqi@0: subst->type()->base() == illegalType, "type can't change"); aoqi@0: _subst = subst; aoqi@0: } aoqi@0: void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; } aoqi@0: void set_exception_state(ValueStack* s) { check_state(s); _exception_state = s; } aoqi@0: void set_state_before(ValueStack* s) { check_state(s); _state_before = s; } aoqi@0: aoqi@0: // machine-specifics aoqi@0: void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; } aoqi@0: void clear_operand() { _operand = LIR_OprFact::illegalOpr; } aoqi@0: aoqi@0: // generic aoqi@0: virtual Instruction* as_Instruction() { return this; } // to satisfy HASHING1 macro aoqi@0: virtual Phi* as_Phi() { return NULL; } aoqi@0: virtual Local* as_Local() { return NULL; } aoqi@0: virtual Constant* as_Constant() { return NULL; } aoqi@0: virtual AccessField* as_AccessField() { return NULL; } aoqi@0: virtual LoadField* as_LoadField() { return NULL; } aoqi@0: virtual StoreField* as_StoreField() { return NULL; } aoqi@0: virtual AccessArray* as_AccessArray() { return NULL; } aoqi@0: virtual ArrayLength* as_ArrayLength() { return NULL; } aoqi@0: virtual AccessIndexed* as_AccessIndexed() { return NULL; } aoqi@0: virtual LoadIndexed* as_LoadIndexed() { return NULL; } aoqi@0: virtual StoreIndexed* as_StoreIndexed() { return NULL; } aoqi@0: virtual NegateOp* as_NegateOp() { return NULL; } aoqi@0: virtual Op2* as_Op2() { return NULL; } aoqi@0: virtual ArithmeticOp* as_ArithmeticOp() { return NULL; } aoqi@0: virtual ShiftOp* as_ShiftOp() { return NULL; } aoqi@0: virtual LogicOp* as_LogicOp() { return NULL; } aoqi@0: virtual CompareOp* as_CompareOp() { return NULL; } aoqi@0: virtual IfOp* as_IfOp() { return NULL; } aoqi@0: virtual Convert* as_Convert() { return NULL; } aoqi@0: virtual NullCheck* as_NullCheck() { return NULL; } aoqi@0: virtual OsrEntry* as_OsrEntry() { return NULL; } aoqi@0: virtual StateSplit* as_StateSplit() { return NULL; } aoqi@0: virtual Invoke* as_Invoke() { return NULL; } aoqi@0: virtual NewInstance* as_NewInstance() { return NULL; } aoqi@0: virtual NewArray* as_NewArray() { return NULL; } aoqi@0: virtual NewTypeArray* as_NewTypeArray() { return NULL; } aoqi@0: virtual NewObjectArray* as_NewObjectArray() { return NULL; } aoqi@0: virtual NewMultiArray* as_NewMultiArray() { return NULL; } aoqi@0: virtual TypeCheck* as_TypeCheck() { return NULL; } aoqi@0: virtual CheckCast* as_CheckCast() { return NULL; } aoqi@0: virtual InstanceOf* as_InstanceOf() { return NULL; } aoqi@0: virtual TypeCast* as_TypeCast() { return NULL; } aoqi@0: virtual AccessMonitor* as_AccessMonitor() { return NULL; } aoqi@0: virtual MonitorEnter* as_MonitorEnter() { return NULL; } aoqi@0: virtual MonitorExit* as_MonitorExit() { return NULL; } aoqi@0: virtual Intrinsic* as_Intrinsic() { return NULL; } aoqi@0: virtual BlockBegin* as_BlockBegin() { return NULL; } aoqi@0: virtual BlockEnd* as_BlockEnd() { return NULL; } aoqi@0: virtual Goto* as_Goto() { return NULL; } aoqi@0: virtual If* as_If() { return NULL; } aoqi@0: virtual IfInstanceOf* as_IfInstanceOf() { return NULL; } aoqi@0: virtual TableSwitch* as_TableSwitch() { return NULL; } aoqi@0: virtual LookupSwitch* as_LookupSwitch() { return NULL; } aoqi@0: virtual Return* as_Return() { return NULL; } aoqi@0: virtual Throw* as_Throw() { return NULL; } aoqi@0: virtual Base* as_Base() { return NULL; } aoqi@0: virtual RoundFP* as_RoundFP() { return NULL; } aoqi@0: virtual ExceptionObject* as_ExceptionObject() { return NULL; } aoqi@0: virtual UnsafeOp* as_UnsafeOp() { return NULL; } aoqi@0: virtual ProfileInvoke* as_ProfileInvoke() { return NULL; } aoqi@0: virtual RangeCheckPredicate* as_RangeCheckPredicate() { return NULL; } aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: virtual Assert* as_Assert() { return NULL; } aoqi@0: #endif aoqi@0: aoqi@0: virtual void visit(InstructionVisitor* v) = 0; aoqi@0: aoqi@0: virtual bool can_trap() const { return false; } aoqi@0: aoqi@0: virtual void input_values_do(ValueVisitor* f) = 0; aoqi@0: virtual void state_values_do(ValueVisitor* f); aoqi@0: virtual void other_values_do(ValueVisitor* f) { /* usually no other - override on demand */ } aoqi@0: void values_do(ValueVisitor* f) { input_values_do(f); state_values_do(f); other_values_do(f); } aoqi@0: aoqi@0: virtual ciType* exact_type() const; aoqi@0: virtual ciType* declared_type() const { return NULL; } aoqi@0: aoqi@0: // hashing aoqi@0: virtual const char* name() const = 0; aoqi@0: HASHING1(Instruction, false, id()) // hashing disabled by default aoqi@0: aoqi@0: // debugging aoqi@0: static void check_state(ValueStack* state) PRODUCT_RETURN; aoqi@0: void print() PRODUCT_RETURN; aoqi@0: void print_line() PRODUCT_RETURN; aoqi@0: void print(InstructionPrinter& ip) PRODUCT_RETURN; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // The following macros are used to define base (i.e., non-leaf) aoqi@0: // and leaf instruction classes. They define class-name related aoqi@0: // generic functionality in one place. aoqi@0: aoqi@0: #define BASE(class_name, super_class_name) \ aoqi@0: class class_name: public super_class_name { \ aoqi@0: public: \ aoqi@0: virtual class_name* as_##class_name() { return this; } \ aoqi@0: aoqi@0: aoqi@0: #define LEAF(class_name, super_class_name) \ aoqi@0: BASE(class_name, super_class_name) \ aoqi@0: public: \ aoqi@0: virtual const char* name() const { return #class_name; } \ aoqi@0: virtual void visit(InstructionVisitor* v) { v->do_##class_name(this); } \ aoqi@0: aoqi@0: aoqi@0: // Debugging support aoqi@0: aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: class AssertValues: public ValueVisitor { aoqi@0: void visit(Value* x) { assert((*x) != NULL, "value must exist"); } aoqi@0: }; aoqi@0: #define ASSERT_VALUES { AssertValues assert_value; values_do(&assert_value); } aoqi@0: #else aoqi@0: #define ASSERT_VALUES aoqi@0: #endif // ASSERT aoqi@0: aoqi@0: aoqi@0: // A Phi is a phi function in the sense of SSA form. It stands for aoqi@0: // the value of a local variable at the beginning of a join block. aoqi@0: // A Phi consists of n operands, one for every incoming branch. aoqi@0: aoqi@0: LEAF(Phi, Instruction) aoqi@0: private: aoqi@0: int _pf_flags; // the flags of the phi function aoqi@0: int _index; // to value on operand stack (index < 0) or to local aoqi@0: public: aoqi@0: // creation aoqi@0: Phi(ValueType* type, BlockBegin* b, int index) aoqi@0: : Instruction(type->base()) aoqi@0: , _pf_flags(0) aoqi@0: , _index(index) aoqi@0: { aoqi@0: _block = b; aoqi@0: NOT_PRODUCT(set_printable_bci(Value(b)->printable_bci())); aoqi@0: if (type->is_illegal()) { aoqi@0: make_illegal(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // flags aoqi@0: enum Flag { aoqi@0: no_flag = 0, aoqi@0: visited = 1 << 0, aoqi@0: cannot_simplify = 1 << 1 aoqi@0: }; aoqi@0: aoqi@0: // accessors aoqi@0: bool is_local() const { return _index >= 0; } aoqi@0: bool is_on_stack() const { return !is_local(); } aoqi@0: int local_index() const { assert(is_local(), ""); return _index; } aoqi@0: int stack_index() const { assert(is_on_stack(), ""); return -(_index+1); } aoqi@0: aoqi@0: Value operand_at(int i) const; aoqi@0: int operand_count() const; aoqi@0: aoqi@0: void set(Flag f) { _pf_flags |= f; } aoqi@0: void clear(Flag f) { _pf_flags &= ~f; } aoqi@0: bool is_set(Flag f) const { return (_pf_flags & f) != 0; } aoqi@0: aoqi@0: // Invalidates phis corresponding to merges of locals of two different types aoqi@0: // (these should never be referenced, otherwise the bytecodes are illegal) aoqi@0: void make_illegal() { aoqi@0: set(cannot_simplify); aoqi@0: set_type(illegalType); aoqi@0: } aoqi@0: aoqi@0: bool is_illegal() const { aoqi@0: return type()->is_illegal(); aoqi@0: } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // A local is a placeholder for an incoming argument to a function call. aoqi@0: LEAF(Local, Instruction) aoqi@0: private: aoqi@0: int _java_index; // the local index within the method to which the local belongs aoqi@0: ciType* _declared_type; aoqi@0: public: aoqi@0: // creation aoqi@0: Local(ciType* declared, ValueType* type, int index) aoqi@0: : Instruction(type) aoqi@0: , _java_index(index) aoqi@0: , _declared_type(declared) aoqi@0: { aoqi@0: NOT_PRODUCT(set_printable_bci(-1)); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: int java_index() const { return _java_index; } aoqi@0: aoqi@0: virtual ciType* declared_type() const { return _declared_type; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { /* no values */ } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(Constant, Instruction) aoqi@0: public: aoqi@0: // creation aoqi@0: Constant(ValueType* type): aoqi@0: Instruction(type, NULL, /*type_is_constant*/ true) aoqi@0: { aoqi@0: assert(type->is_constant(), "must be a constant"); aoqi@0: } aoqi@0: aoqi@0: Constant(ValueType* type, ValueStack* state_before): aoqi@0: Instruction(type, state_before, /*type_is_constant*/ true) aoqi@0: { aoqi@0: assert(state_before != NULL, "only used for constants which need patching"); aoqi@0: assert(type->is_constant(), "must be a constant"); aoqi@0: // since it's patching it needs to be pinned aoqi@0: pin(); aoqi@0: } aoqi@0: aoqi@0: // generic aoqi@0: virtual bool can_trap() const { return state_before() != NULL; } aoqi@0: virtual void input_values_do(ValueVisitor* f) { /* no values */ } aoqi@0: aoqi@0: virtual intx hash() const; aoqi@0: virtual bool is_equal(Value v) const; aoqi@0: aoqi@0: virtual ciType* exact_type() const; aoqi@0: aoqi@0: enum CompareResult { not_comparable = -1, cond_false, cond_true }; aoqi@0: aoqi@0: virtual CompareResult compare(Instruction::Condition condition, Value right) const; aoqi@0: BlockBegin* compare(Instruction::Condition cond, Value right, aoqi@0: BlockBegin* true_sux, BlockBegin* false_sux) const { aoqi@0: switch (compare(cond, right)) { aoqi@0: case not_comparable: aoqi@0: return NULL; aoqi@0: case cond_false: aoqi@0: return false_sux; aoqi@0: case cond_true: aoqi@0: return true_sux; aoqi@0: default: aoqi@0: ShouldNotReachHere(); aoqi@0: return NULL; aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(AccessField, Instruction) aoqi@0: private: aoqi@0: Value _obj; aoqi@0: int _offset; aoqi@0: ciField* _field; aoqi@0: NullCheck* _explicit_null_check; // For explicit null check elimination aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: AccessField(Value obj, int offset, ciField* field, bool is_static, aoqi@0: ValueStack* state_before, bool needs_patching) aoqi@0: : Instruction(as_ValueType(field->type()->basic_type()), state_before) aoqi@0: , _obj(obj) aoqi@0: , _offset(offset) aoqi@0: , _field(field) aoqi@0: , _explicit_null_check(NULL) aoqi@0: { aoqi@0: set_needs_null_check(!is_static); aoqi@0: set_flag(IsStaticFlag, is_static); aoqi@0: set_flag(NeedsPatchingFlag, needs_patching); aoqi@0: ASSERT_VALUES aoqi@0: // pin of all instructions with memory access aoqi@0: pin(); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value obj() const { return _obj; } aoqi@0: int offset() const { return _offset; } aoqi@0: ciField* field() const { return _field; } aoqi@0: BasicType field_type() const { return _field->type()->basic_type(); } aoqi@0: bool is_static() const { return check_flag(IsStaticFlag); } aoqi@0: NullCheck* explicit_null_check() const { return _explicit_null_check; } aoqi@0: bool needs_patching() const { return check_flag(NeedsPatchingFlag); } aoqi@0: aoqi@0: // Unresolved getstatic and putstatic can cause initialization. aoqi@0: // Technically it occurs at the Constant that materializes the base aoqi@0: // of the static fields but it's simpler to model it here. aoqi@0: bool is_init_point() const { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); } aoqi@0: aoqi@0: // manipulation aoqi@0: aoqi@0: // Under certain circumstances, if a previous NullCheck instruction aoqi@0: // proved the target object non-null, we can eliminate the explicit aoqi@0: // null check and do an implicit one, simply specifying the debug aoqi@0: // information from the NullCheck. This field should only be consulted aoqi@0: // if needs_null_check() is true. aoqi@0: void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; } aoqi@0: aoqi@0: // generic aoqi@0: virtual bool can_trap() const { return needs_null_check() || needs_patching(); } aoqi@0: virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(LoadField, AccessField) aoqi@0: public: aoqi@0: // creation aoqi@0: LoadField(Value obj, int offset, ciField* field, bool is_static, aoqi@0: ValueStack* state_before, bool needs_patching) aoqi@0: : AccessField(obj, offset, field, is_static, state_before, needs_patching) aoqi@0: {} aoqi@0: aoqi@0: ciType* declared_type() const; aoqi@0: aoqi@0: // generic aoqi@0: HASHING2(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset()) // cannot be eliminated if needs patching or if volatile aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(StoreField, AccessField) aoqi@0: private: aoqi@0: Value _value; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: StoreField(Value obj, int offset, ciField* field, Value value, bool is_static, aoqi@0: ValueStack* state_before, bool needs_patching) aoqi@0: : AccessField(obj, offset, field, is_static, state_before, needs_patching) aoqi@0: , _value(value) aoqi@0: { aoqi@0: set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object()); aoqi@0: ASSERT_VALUES aoqi@0: pin(); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value value() const { return _value; } aoqi@0: bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(AccessArray, Instruction) aoqi@0: private: aoqi@0: Value _array; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: AccessArray(ValueType* type, Value array, ValueStack* state_before) aoqi@0: : Instruction(type, state_before) aoqi@0: , _array(array) aoqi@0: { aoqi@0: set_needs_null_check(true); aoqi@0: ASSERT_VALUES aoqi@0: pin(); // instruction with side effect (null exception or range check throwing) aoqi@0: } aoqi@0: aoqi@0: Value array() const { return _array; } aoqi@0: aoqi@0: // generic aoqi@0: virtual bool can_trap() const { return needs_null_check(); } aoqi@0: virtual void input_values_do(ValueVisitor* f) { f->visit(&_array); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(ArrayLength, AccessArray) aoqi@0: private: aoqi@0: NullCheck* _explicit_null_check; // For explicit null check elimination aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: ArrayLength(Value array, ValueStack* state_before) aoqi@0: : AccessArray(intType, array, state_before) aoqi@0: , _explicit_null_check(NULL) {} aoqi@0: aoqi@0: // accessors aoqi@0: NullCheck* explicit_null_check() const { return _explicit_null_check; } aoqi@0: aoqi@0: // setters aoqi@0: // See LoadField::set_explicit_null_check for documentation aoqi@0: void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; } aoqi@0: aoqi@0: // generic aoqi@0: HASHING1(ArrayLength, true, array()->subst()) aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(AccessIndexed, AccessArray) aoqi@0: private: aoqi@0: Value _index; aoqi@0: Value _length; aoqi@0: BasicType _elt_type; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before) aoqi@0: : AccessArray(as_ValueType(elt_type), array, state_before) aoqi@0: , _index(index) aoqi@0: , _length(length) aoqi@0: , _elt_type(elt_type) aoqi@0: { aoqi@0: set_flag(Instruction::NeedsRangeCheckFlag, true); aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value index() const { return _index; } aoqi@0: Value length() const { return _length; } aoqi@0: BasicType elt_type() const { return _elt_type; } aoqi@0: aoqi@0: void clear_length() { _length = NULL; } aoqi@0: // perform elimination of range checks involving constants aoqi@0: bool compute_needs_range_check(); aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(LoadIndexed, AccessIndexed) aoqi@0: private: aoqi@0: NullCheck* _explicit_null_check; // For explicit null check elimination aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before) aoqi@0: : AccessIndexed(array, index, length, elt_type, state_before) aoqi@0: , _explicit_null_check(NULL) {} aoqi@0: aoqi@0: // accessors aoqi@0: NullCheck* explicit_null_check() const { return _explicit_null_check; } aoqi@0: aoqi@0: // setters aoqi@0: // See LoadField::set_explicit_null_check for documentation aoqi@0: void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; } aoqi@0: aoqi@0: ciType* exact_type() const; aoqi@0: ciType* declared_type() const; aoqi@0: aoqi@0: // generic aoqi@0: HASHING2(LoadIndexed, true, array()->subst(), index()->subst()) aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(StoreIndexed, AccessIndexed) aoqi@0: private: aoqi@0: Value _value; aoqi@0: aoqi@0: ciMethod* _profiled_method; aoqi@0: int _profiled_bci; aoqi@0: public: aoqi@0: // creation aoqi@0: StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before) aoqi@0: : AccessIndexed(array, index, length, elt_type, state_before) aoqi@0: , _value(value), _profiled_method(NULL), _profiled_bci(0) aoqi@0: { aoqi@0: set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object())); aoqi@0: set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object())); aoqi@0: ASSERT_VALUES aoqi@0: pin(); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value value() const { return _value; } aoqi@0: bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); } aoqi@0: bool needs_store_check() const { return check_flag(NeedsStoreCheckFlag); } aoqi@0: // Helpers for MethodData* profiling aoqi@0: void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); } aoqi@0: void set_profiled_method(ciMethod* method) { _profiled_method = method; } aoqi@0: void set_profiled_bci(int bci) { _profiled_bci = bci; } aoqi@0: bool should_profile() const { return check_flag(ProfileMDOFlag); } aoqi@0: ciMethod* profiled_method() const { return _profiled_method; } aoqi@0: int profiled_bci() const { return _profiled_bci; } aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(NegateOp, Instruction) aoqi@0: private: aoqi@0: Value _x; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: NegateOp(Value x) : Instruction(x->type()->base()), _x(x) { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value x() const { return _x; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(Op2, Instruction) aoqi@0: private: aoqi@0: Bytecodes::Code _op; aoqi@0: Value _x; aoqi@0: Value _y; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = NULL) aoqi@0: : Instruction(type, state_before) aoqi@0: , _op(op) aoqi@0: , _x(x) aoqi@0: , _y(y) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Bytecodes::Code op() const { return _op; } aoqi@0: Value x() const { return _x; } aoqi@0: Value y() const { return _y; } aoqi@0: aoqi@0: // manipulators aoqi@0: void swap_operands() { aoqi@0: assert(is_commutative(), "operation must be commutative"); aoqi@0: Value t = _x; _x = _y; _y = t; aoqi@0: } aoqi@0: aoqi@0: // generic aoqi@0: virtual bool is_commutative() const { return false; } aoqi@0: virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(ArithmeticOp, Op2) aoqi@0: public: aoqi@0: // creation aoqi@0: ArithmeticOp(Bytecodes::Code op, Value x, Value y, bool is_strictfp, ValueStack* state_before) aoqi@0: : Op2(x->type()->meet(y->type()), op, x, y, state_before) aoqi@0: { aoqi@0: set_flag(IsStrictfpFlag, is_strictfp); aoqi@0: if (can_trap()) pin(); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: bool is_strictfp() const { return check_flag(IsStrictfpFlag); } aoqi@0: aoqi@0: // generic aoqi@0: virtual bool is_commutative() const; aoqi@0: virtual bool can_trap() const; aoqi@0: HASHING3(Op2, true, op(), x()->subst(), y()->subst()) aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(ShiftOp, Op2) aoqi@0: public: aoqi@0: // creation aoqi@0: ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {} aoqi@0: aoqi@0: // generic aoqi@0: HASHING3(Op2, true, op(), x()->subst(), y()->subst()) aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(LogicOp, Op2) aoqi@0: public: aoqi@0: // creation aoqi@0: LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {} aoqi@0: aoqi@0: // generic aoqi@0: virtual bool is_commutative() const; aoqi@0: HASHING3(Op2, true, op(), x()->subst(), y()->subst()) aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(CompareOp, Op2) aoqi@0: public: aoqi@0: // creation aoqi@0: CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before) aoqi@0: : Op2(intType, op, x, y, state_before) aoqi@0: {} aoqi@0: aoqi@0: // generic aoqi@0: HASHING3(Op2, true, op(), x()->subst(), y()->subst()) aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(IfOp, Op2) aoqi@0: private: aoqi@0: Value _tval; aoqi@0: Value _fval; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: IfOp(Value x, Condition cond, Value y, Value tval, Value fval) aoqi@0: : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y) aoqi@0: , _tval(tval) aoqi@0: , _fval(fval) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: assert(tval->type()->tag() == fval->type()->tag(), "types must match"); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: virtual bool is_commutative() const; aoqi@0: Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; } aoqi@0: Condition cond() const { return (Condition)Op2::op(); } aoqi@0: Value tval() const { return _tval; } aoqi@0: Value fval() const { return _fval; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(Convert, Instruction) aoqi@0: private: aoqi@0: Bytecodes::Code _op; aoqi@0: Value _value; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Bytecodes::Code op() const { return _op; } aoqi@0: Value value() const { return _value; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { f->visit(&_value); } aoqi@0: HASHING2(Convert, true, op(), value()->subst()) aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(NullCheck, Instruction) aoqi@0: private: aoqi@0: Value _obj; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: NullCheck(Value obj, ValueStack* state_before) aoqi@0: : Instruction(obj->type()->base(), state_before) aoqi@0: , _obj(obj) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: set_can_trap(true); aoqi@0: assert(_obj->type()->is_object(), "null check must be applied to objects only"); aoqi@0: pin(Instruction::PinExplicitNullCheck); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value obj() const { return _obj; } aoqi@0: aoqi@0: // setters aoqi@0: void set_can_trap(bool can_trap) { set_flag(CanTrapFlag, can_trap); } aoqi@0: aoqi@0: // generic aoqi@0: virtual bool can_trap() const { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ } aoqi@0: virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); } aoqi@0: HASHING1(NullCheck, true, obj()->subst()) aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // This node is supposed to cast the type of another node to a more precise aoqi@0: // declared type. aoqi@0: LEAF(TypeCast, Instruction) aoqi@0: private: aoqi@0: ciType* _declared_type; aoqi@0: Value _obj; aoqi@0: aoqi@0: public: aoqi@0: // The type of this node is the same type as the object type (and it might be constant). aoqi@0: TypeCast(ciType* type, Value obj, ValueStack* state_before) aoqi@0: : Instruction(obj->type(), state_before, obj->type()->is_constant()), aoqi@0: _declared_type(type), aoqi@0: _obj(obj) {} aoqi@0: aoqi@0: // accessors aoqi@0: ciType* declared_type() const { return _declared_type; } aoqi@0: Value obj() const { return _obj; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(StateSplit, Instruction) aoqi@0: private: aoqi@0: ValueStack* _state; aoqi@0: aoqi@0: protected: aoqi@0: static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block); aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: StateSplit(ValueType* type, ValueStack* state_before = NULL) aoqi@0: : Instruction(type, state_before) aoqi@0: , _state(NULL) aoqi@0: { aoqi@0: pin(PinStateSplitConstructor); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: ValueStack* state() const { return _state; } aoqi@0: IRScope* scope() const; // the state's scope aoqi@0: aoqi@0: // manipulation aoqi@0: void set_state(ValueStack* state) { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { /* no values */ } aoqi@0: virtual void state_values_do(ValueVisitor* f); aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(Invoke, StateSplit) aoqi@0: private: aoqi@0: Bytecodes::Code _code; aoqi@0: Value _recv; aoqi@0: Values* _args; aoqi@0: BasicTypeList* _signature; aoqi@0: int _vtable_index; aoqi@0: ciMethod* _target; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args, aoqi@0: int vtable_index, ciMethod* target, ValueStack* state_before); aoqi@0: aoqi@0: // accessors aoqi@0: Bytecodes::Code code() const { return _code; } aoqi@0: Value receiver() const { return _recv; } aoqi@0: bool has_receiver() const { return receiver() != NULL; } aoqi@0: int number_of_arguments() const { return _args->length(); } aoqi@0: Value argument_at(int i) const { return _args->at(i); } aoqi@0: int vtable_index() const { return _vtable_index; } aoqi@0: BasicTypeList* signature() const { return _signature; } aoqi@0: ciMethod* target() const { return _target; } aoqi@0: aoqi@0: ciType* declared_type() const; aoqi@0: aoqi@0: // Returns false if target is not loaded aoqi@0: bool target_is_final() const { return check_flag(TargetIsFinalFlag); } aoqi@0: bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); } aoqi@0: // Returns false if target is not loaded aoqi@0: bool target_is_strictfp() const { return check_flag(TargetIsStrictfpFlag); } aoqi@0: aoqi@0: // JSR 292 support aoqi@0: bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; } aoqi@0: bool is_method_handle_intrinsic() const { return target()->is_method_handle_intrinsic(); } aoqi@0: aoqi@0: virtual bool needs_exception_state() const { return false; } aoqi@0: aoqi@0: // generic aoqi@0: virtual bool can_trap() const { return true; } aoqi@0: virtual void input_values_do(ValueVisitor* f) { aoqi@0: StateSplit::input_values_do(f); aoqi@0: if (has_receiver()) f->visit(&_recv); aoqi@0: for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i)); aoqi@0: } aoqi@0: virtual void state_values_do(ValueVisitor *f); aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(NewInstance, StateSplit) aoqi@0: private: aoqi@0: ciInstanceKlass* _klass; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: NewInstance(ciInstanceKlass* klass, ValueStack* state_before) aoqi@0: : StateSplit(instanceType, state_before) aoqi@0: , _klass(klass) aoqi@0: {} aoqi@0: aoqi@0: // accessors aoqi@0: ciInstanceKlass* klass() const { return _klass; } aoqi@0: aoqi@0: virtual bool needs_exception_state() const { return false; } aoqi@0: aoqi@0: // generic aoqi@0: virtual bool can_trap() const { return true; } aoqi@0: ciType* exact_type() const; aoqi@0: ciType* declared_type() const; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(NewArray, StateSplit) aoqi@0: private: aoqi@0: Value _length; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: NewArray(Value length, ValueStack* state_before) aoqi@0: : StateSplit(objectType, state_before) aoqi@0: , _length(length) aoqi@0: { aoqi@0: // Do not ASSERT_VALUES since length is NULL for NewMultiArray aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value length() const { return _length; } aoqi@0: aoqi@0: virtual bool needs_exception_state() const { return false; } aoqi@0: aoqi@0: ciType* exact_type() const { return NULL; } aoqi@0: ciType* declared_type() const; aoqi@0: aoqi@0: // generic aoqi@0: virtual bool can_trap() const { return true; } aoqi@0: virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_length); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(NewTypeArray, NewArray) aoqi@0: private: aoqi@0: BasicType _elt_type; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before) aoqi@0: : NewArray(length, state_before) aoqi@0: , _elt_type(elt_type) aoqi@0: {} aoqi@0: aoqi@0: // accessors aoqi@0: BasicType elt_type() const { return _elt_type; } aoqi@0: ciType* exact_type() const; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(NewObjectArray, NewArray) aoqi@0: private: aoqi@0: ciKlass* _klass; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {} aoqi@0: aoqi@0: // accessors aoqi@0: ciKlass* klass() const { return _klass; } aoqi@0: ciType* exact_type() const; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(NewMultiArray, NewArray) aoqi@0: private: aoqi@0: ciKlass* _klass; aoqi@0: Values* _dims; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: ciKlass* klass() const { return _klass; } aoqi@0: Values* dims() const { return _dims; } aoqi@0: int rank() const { return dims()->length(); } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { aoqi@0: // NOTE: we do not call NewArray::input_values_do since "length" aoqi@0: // is meaningless for a multi-dimensional array; passing the aoqi@0: // zeroth element down to NewArray as its length is a bad idea aoqi@0: // since there will be a copy in the "dims" array which doesn't aoqi@0: // get updated, and the value must not be traversed twice. Was bug aoqi@0: // - kbr 4/10/2001 aoqi@0: StateSplit::input_values_do(f); aoqi@0: for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i)); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(TypeCheck, StateSplit) aoqi@0: private: aoqi@0: ciKlass* _klass; aoqi@0: Value _obj; aoqi@0: aoqi@0: ciMethod* _profiled_method; aoqi@0: int _profiled_bci; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before) aoqi@0: : StateSplit(type, state_before), _klass(klass), _obj(obj), aoqi@0: _profiled_method(NULL), _profiled_bci(0) { aoqi@0: ASSERT_VALUES aoqi@0: set_direct_compare(false); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: ciKlass* klass() const { return _klass; } aoqi@0: Value obj() const { return _obj; } aoqi@0: bool is_loaded() const { return klass() != NULL; } aoqi@0: bool direct_compare() const { return check_flag(DirectCompareFlag); } aoqi@0: aoqi@0: // manipulation aoqi@0: void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); } aoqi@0: aoqi@0: // generic aoqi@0: virtual bool can_trap() const { return true; } aoqi@0: virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); } aoqi@0: aoqi@0: // Helpers for MethodData* profiling aoqi@0: void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); } aoqi@0: void set_profiled_method(ciMethod* method) { _profiled_method = method; } aoqi@0: void set_profiled_bci(int bci) { _profiled_bci = bci; } aoqi@0: bool should_profile() const { return check_flag(ProfileMDOFlag); } aoqi@0: ciMethod* profiled_method() const { return _profiled_method; } aoqi@0: int profiled_bci() const { return _profiled_bci; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(CheckCast, TypeCheck) aoqi@0: public: aoqi@0: // creation aoqi@0: CheckCast(ciKlass* klass, Value obj, ValueStack* state_before) aoqi@0: : TypeCheck(klass, obj, objectType, state_before) {} aoqi@0: aoqi@0: void set_incompatible_class_change_check() { aoqi@0: set_flag(ThrowIncompatibleClassChangeErrorFlag, true); aoqi@0: } aoqi@0: bool is_incompatible_class_change_check() const { aoqi@0: return check_flag(ThrowIncompatibleClassChangeErrorFlag); aoqi@0: } aoqi@0: aoqi@0: ciType* declared_type() const; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(InstanceOf, TypeCheck) aoqi@0: public: aoqi@0: // creation aoqi@0: InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {} aoqi@0: aoqi@0: virtual bool needs_exception_state() const { return false; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(AccessMonitor, StateSplit) aoqi@0: private: aoqi@0: Value _obj; aoqi@0: int _monitor_no; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL) aoqi@0: : StateSplit(illegalType, state_before) aoqi@0: , _obj(obj) aoqi@0: , _monitor_no(monitor_no) aoqi@0: { aoqi@0: set_needs_null_check(true); aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value obj() const { return _obj; } aoqi@0: int monitor_no() const { return _monitor_no; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(MonitorEnter, AccessMonitor) aoqi@0: public: aoqi@0: // creation aoqi@0: MonitorEnter(Value obj, int monitor_no, ValueStack* state_before) aoqi@0: : AccessMonitor(obj, monitor_no, state_before) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: // generic aoqi@0: virtual bool can_trap() const { return true; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(MonitorExit, AccessMonitor) aoqi@0: public: aoqi@0: // creation aoqi@0: MonitorExit(Value obj, int monitor_no) aoqi@0: : AccessMonitor(obj, monitor_no, NULL) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(Intrinsic, StateSplit) aoqi@0: private: aoqi@0: vmIntrinsics::ID _id; aoqi@0: Values* _args; aoqi@0: Value _recv; aoqi@0: ArgsNonNullState _nonnull_state; aoqi@0: aoqi@0: public: aoqi@0: // preserves_state can be set to true for Intrinsics aoqi@0: // which are guaranteed to preserve register state across any slow aoqi@0: // cases; setting it to true does not mean that the Intrinsic can aoqi@0: // not trap, only that if we continue execution in the same basic aoqi@0: // block after the Intrinsic, all of the registers are intact. This aoqi@0: // allows load elimination and common expression elimination to be aoqi@0: // performed across the Intrinsic. The default value is false. aoqi@0: Intrinsic(ValueType* type, aoqi@0: vmIntrinsics::ID id, aoqi@0: Values* args, aoqi@0: bool has_receiver, aoqi@0: ValueStack* state_before, aoqi@0: bool preserves_state, aoqi@0: bool cantrap = true) aoqi@0: : StateSplit(type, state_before) aoqi@0: , _id(id) aoqi@0: , _args(args) aoqi@0: , _recv(NULL) aoqi@0: { aoqi@0: assert(args != NULL, "args must exist"); aoqi@0: ASSERT_VALUES aoqi@0: set_flag(PreservesStateFlag, preserves_state); aoqi@0: set_flag(CanTrapFlag, cantrap); aoqi@0: if (has_receiver) { aoqi@0: _recv = argument_at(0); aoqi@0: } aoqi@0: set_needs_null_check(has_receiver); aoqi@0: aoqi@0: // some intrinsics can't trap, so don't force them to be pinned aoqi@0: if (!can_trap()) { aoqi@0: unpin(PinStateSplitConstructor); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: vmIntrinsics::ID id() const { return _id; } aoqi@0: int number_of_arguments() const { return _args->length(); } aoqi@0: Value argument_at(int i) const { return _args->at(i); } aoqi@0: aoqi@0: bool has_receiver() const { return (_recv != NULL); } aoqi@0: Value receiver() const { assert(has_receiver(), "must have receiver"); return _recv; } aoqi@0: bool preserves_state() const { return check_flag(PreservesStateFlag); } aoqi@0: aoqi@0: bool arg_needs_null_check(int i) const { aoqi@0: return _nonnull_state.arg_needs_null_check(i); aoqi@0: } aoqi@0: aoqi@0: void set_arg_needs_null_check(int i, bool check) { aoqi@0: _nonnull_state.set_arg_needs_null_check(i, check); aoqi@0: } aoqi@0: aoqi@0: // generic aoqi@0: virtual bool can_trap() const { return check_flag(CanTrapFlag); } aoqi@0: virtual void input_values_do(ValueVisitor* f) { aoqi@0: StateSplit::input_values_do(f); aoqi@0: for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i)); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: class LIR_List; aoqi@0: aoqi@0: LEAF(BlockBegin, StateSplit) aoqi@0: private: aoqi@0: int _block_id; // the unique block id aoqi@0: int _bci; // start-bci of block aoqi@0: int _depth_first_number; // number of this block in a depth-first ordering aoqi@0: int _linear_scan_number; // number of this block in linear-scan ordering aoqi@0: int _dominator_depth; aoqi@0: int _loop_depth; // the loop nesting level of this block aoqi@0: int _loop_index; // number of the innermost loop of this block aoqi@0: int _flags; // the flags associated with this block aoqi@0: aoqi@0: // fields used by BlockListBuilder aoqi@0: int _total_preds; // number of predecessors found by BlockListBuilder aoqi@0: BitMap _stores_to_locals; // bit is set when a local variable is stored in the block aoqi@0: aoqi@0: // SSA specific fields: (factor out later) aoqi@0: BlockList _successors; // the successors of this block aoqi@0: BlockList _predecessors; // the predecessors of this block aoqi@0: BlockList _dominates; // list of blocks that are dominated by this block aoqi@0: BlockBegin* _dominator; // the dominator of this block aoqi@0: // SSA specific ends aoqi@0: BlockEnd* _end; // the last instruction of this block aoqi@0: BlockList _exception_handlers; // the exception handlers potentially invoked by this block aoqi@0: ValueStackStack* _exception_states; // only for xhandler entries: states of all instructions that have an edge to this xhandler aoqi@0: int _exception_handler_pco; // if this block is the start of an exception handler, aoqi@0: // this records the PC offset in the assembly code of the aoqi@0: // first instruction in this block aoqi@0: Label _label; // the label associated with this block aoqi@0: LIR_List* _lir; // the low level intermediate representation for this block aoqi@0: aoqi@0: BitMap _live_in; // set of live LIR_Opr registers at entry to this block aoqi@0: BitMap _live_out; // set of live LIR_Opr registers at exit from this block aoqi@0: BitMap _live_gen; // set of registers used before any redefinition in this block aoqi@0: BitMap _live_kill; // set of registers defined in this block aoqi@0: aoqi@0: BitMap _fpu_register_usage; aoqi@0: intArray* _fpu_stack_state; // For x86 FPU code generation with UseLinearScan aoqi@0: int _first_lir_instruction_id; // ID of first LIR instruction in this block aoqi@0: int _last_lir_instruction_id; // ID of last LIR instruction in this block aoqi@0: aoqi@0: void iterate_preorder (boolArray& mark, BlockClosure* closure); aoqi@0: void iterate_postorder(boolArray& mark, BlockClosure* closure); aoqi@0: aoqi@0: friend class SuxAndWeightAdjuster; aoqi@0: aoqi@0: public: aoqi@0: void* operator new(size_t size) throw() { aoqi@0: Compilation* c = Compilation::current(); aoqi@0: void* res = c->arena()->Amalloc(size); aoqi@0: ((BlockBegin*)res)->_id = c->get_next_id(); aoqi@0: ((BlockBegin*)res)->_block_id = c->get_next_block_id(); aoqi@0: return res; aoqi@0: } aoqi@0: aoqi@0: // initialization/counting aoqi@0: static int number_of_blocks() { aoqi@0: return Compilation::current()->number_of_blocks(); aoqi@0: } aoqi@0: aoqi@0: // creation aoqi@0: BlockBegin(int bci) aoqi@0: : StateSplit(illegalType) aoqi@0: , _bci(bci) aoqi@0: , _depth_first_number(-1) aoqi@0: , _linear_scan_number(-1) aoqi@0: , _loop_depth(0) aoqi@0: , _flags(0) aoqi@0: , _dominator_depth(-1) aoqi@0: , _dominator(NULL) aoqi@0: , _end(NULL) aoqi@0: , _predecessors(2) aoqi@0: , _successors(2) aoqi@0: , _dominates(2) aoqi@0: , _exception_handlers(1) aoqi@0: , _exception_states(NULL) aoqi@0: , _exception_handler_pco(-1) aoqi@0: , _lir(NULL) aoqi@0: , _loop_index(-1) aoqi@0: , _live_in() aoqi@0: , _live_out() aoqi@0: , _live_gen() aoqi@0: , _live_kill() aoqi@0: , _fpu_register_usage() aoqi@0: , _fpu_stack_state(NULL) aoqi@0: , _first_lir_instruction_id(-1) aoqi@0: , _last_lir_instruction_id(-1) aoqi@0: , _total_preds(0) aoqi@0: , _stores_to_locals() aoqi@0: { aoqi@0: _block = this; aoqi@0: #ifndef PRODUCT aoqi@0: set_printable_bci(bci); aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: int block_id() const { return _block_id; } aoqi@0: int bci() const { return _bci; } aoqi@0: BlockList* successors() { return &_successors; } aoqi@0: BlockList* dominates() { return &_dominates; } aoqi@0: BlockBegin* dominator() const { return _dominator; } aoqi@0: int loop_depth() const { return _loop_depth; } aoqi@0: int dominator_depth() const { return _dominator_depth; } aoqi@0: int depth_first_number() const { return _depth_first_number; } aoqi@0: int linear_scan_number() const { return _linear_scan_number; } aoqi@0: BlockEnd* end() const { return _end; } aoqi@0: Label* label() { return &_label; } aoqi@0: LIR_List* lir() const { return _lir; } aoqi@0: int exception_handler_pco() const { return _exception_handler_pco; } aoqi@0: BitMap& live_in() { return _live_in; } aoqi@0: BitMap& live_out() { return _live_out; } aoqi@0: BitMap& live_gen() { return _live_gen; } aoqi@0: BitMap& live_kill() { return _live_kill; } aoqi@0: BitMap& fpu_register_usage() { return _fpu_register_usage; } aoqi@0: intArray* fpu_stack_state() const { return _fpu_stack_state; } aoqi@0: int first_lir_instruction_id() const { return _first_lir_instruction_id; } aoqi@0: int last_lir_instruction_id() const { return _last_lir_instruction_id; } aoqi@0: int total_preds() const { return _total_preds; } aoqi@0: BitMap& stores_to_locals() { return _stores_to_locals; } aoqi@0: aoqi@0: // manipulation aoqi@0: void set_dominator(BlockBegin* dom) { _dominator = dom; } aoqi@0: void set_loop_depth(int d) { _loop_depth = d; } aoqi@0: void set_dominator_depth(int d) { _dominator_depth = d; } aoqi@0: void set_depth_first_number(int dfn) { _depth_first_number = dfn; } aoqi@0: void set_linear_scan_number(int lsn) { _linear_scan_number = lsn; } aoqi@0: void set_end(BlockEnd* end); aoqi@0: void clear_end(); aoqi@0: void disconnect_from_graph(); aoqi@0: static void disconnect_edge(BlockBegin* from, BlockBegin* to); aoqi@0: BlockBegin* insert_block_between(BlockBegin* sux); aoqi@0: void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux); aoqi@0: void set_lir(LIR_List* lir) { _lir = lir; } aoqi@0: void set_exception_handler_pco(int pco) { _exception_handler_pco = pco; } aoqi@0: void set_live_in (BitMap map) { _live_in = map; } aoqi@0: void set_live_out (BitMap map) { _live_out = map; } aoqi@0: void set_live_gen (BitMap map) { _live_gen = map; } aoqi@0: void set_live_kill (BitMap map) { _live_kill = map; } aoqi@0: void set_fpu_register_usage(BitMap map) { _fpu_register_usage = map; } aoqi@0: void set_fpu_stack_state(intArray* state) { _fpu_stack_state = state; } aoqi@0: void set_first_lir_instruction_id(int id) { _first_lir_instruction_id = id; } aoqi@0: void set_last_lir_instruction_id(int id) { _last_lir_instruction_id = id; } aoqi@0: void increment_total_preds(int n = 1) { _total_preds += n; } aoqi@0: void init_stores_to_locals(int locals_count) { _stores_to_locals = BitMap(locals_count); _stores_to_locals.clear(); } aoqi@0: aoqi@0: // generic aoqi@0: virtual void state_values_do(ValueVisitor* f); aoqi@0: aoqi@0: // successors and predecessors aoqi@0: int number_of_sux() const; aoqi@0: BlockBegin* sux_at(int i) const; aoqi@0: void add_successor(BlockBegin* sux); aoqi@0: void remove_successor(BlockBegin* pred); aoqi@0: bool is_successor(BlockBegin* sux) const { return _successors.contains(sux); } aoqi@0: aoqi@0: void add_predecessor(BlockBegin* pred); aoqi@0: void remove_predecessor(BlockBegin* pred); aoqi@0: bool is_predecessor(BlockBegin* pred) const { return _predecessors.contains(pred); } aoqi@0: int number_of_preds() const { return _predecessors.length(); } aoqi@0: BlockBegin* pred_at(int i) const { return _predecessors[i]; } aoqi@0: aoqi@0: // exception handlers potentially invoked by this block aoqi@0: void add_exception_handler(BlockBegin* b); aoqi@0: bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); } aoqi@0: int number_of_exception_handlers() const { return _exception_handlers.length(); } aoqi@0: BlockBegin* exception_handler_at(int i) const { return _exception_handlers.at(i); } aoqi@0: aoqi@0: // states of the instructions that have an edge to this exception handler aoqi@0: int number_of_exception_states() { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); } aoqi@0: ValueStack* exception_state_at(int idx) const { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); } aoqi@0: int add_exception_state(ValueStack* state); aoqi@0: aoqi@0: // flags aoqi@0: enum Flag { aoqi@0: no_flag = 0, aoqi@0: std_entry_flag = 1 << 0, aoqi@0: osr_entry_flag = 1 << 1, aoqi@0: exception_entry_flag = 1 << 2, aoqi@0: subroutine_entry_flag = 1 << 3, aoqi@0: backward_branch_target_flag = 1 << 4, aoqi@0: is_on_work_list_flag = 1 << 5, aoqi@0: was_visited_flag = 1 << 6, aoqi@0: parser_loop_header_flag = 1 << 7, // set by parser to identify blocks where phi functions can not be created on demand aoqi@0: critical_edge_split_flag = 1 << 8, // set for all blocks that are introduced when critical edges are split aoqi@0: linear_scan_loop_header_flag = 1 << 9, // set during loop-detection for LinearScan aoqi@0: linear_scan_loop_end_flag = 1 << 10, // set during loop-detection for LinearScan aoqi@0: donot_eliminate_range_checks = 1 << 11 // Should be try to eliminate range checks in this block aoqi@0: }; aoqi@0: aoqi@0: void set(Flag f) { _flags |= f; } aoqi@0: void clear(Flag f) { _flags &= ~f; } aoqi@0: bool is_set(Flag f) const { return (_flags & f) != 0; } aoqi@0: bool is_entry_block() const { aoqi@0: const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag; aoqi@0: return (_flags & entry_mask) != 0; aoqi@0: } aoqi@0: aoqi@0: // iteration aoqi@0: void iterate_preorder (BlockClosure* closure); aoqi@0: void iterate_postorder (BlockClosure* closure); aoqi@0: aoqi@0: void block_values_do(ValueVisitor* f); aoqi@0: aoqi@0: // loops aoqi@0: void set_loop_index(int ix) { _loop_index = ix; } aoqi@0: int loop_index() const { return _loop_index; } aoqi@0: aoqi@0: // merging aoqi@0: bool try_merge(ValueStack* state); // try to merge states at block begin aoqi@0: void merge(ValueStack* state) { bool b = try_merge(state); assert(b, "merge failed"); } aoqi@0: aoqi@0: // debugging aoqi@0: void print_block() PRODUCT_RETURN; aoqi@0: void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(BlockEnd, StateSplit) aoqi@0: private: aoqi@0: BlockList* _sux; aoqi@0: aoqi@0: protected: aoqi@0: BlockList* sux() const { return _sux; } aoqi@0: aoqi@0: void set_sux(BlockList* sux) { aoqi@0: #ifdef ASSERT aoqi@0: assert(sux != NULL, "sux must exist"); aoqi@0: for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist"); aoqi@0: #endif aoqi@0: _sux = sux; aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint) aoqi@0: : StateSplit(type, state_before) aoqi@0: , _sux(NULL) aoqi@0: { aoqi@0: set_flag(IsSafepointFlag, is_safepoint); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: bool is_safepoint() const { return check_flag(IsSafepointFlag); } aoqi@0: // For compatibility with old code, for new code use block() aoqi@0: BlockBegin* begin() const { return _block; } aoqi@0: aoqi@0: // manipulation aoqi@0: void set_begin(BlockBegin* begin); aoqi@0: aoqi@0: // successors aoqi@0: int number_of_sux() const { return _sux != NULL ? _sux->length() : 0; } aoqi@0: BlockBegin* sux_at(int i) const { return _sux->at(i); } aoqi@0: BlockBegin* default_sux() const { return sux_at(number_of_sux() - 1); } aoqi@0: BlockBegin** addr_sux_at(int i) const { return _sux->adr_at(i); } aoqi@0: int sux_index(BlockBegin* sux) const { return _sux->find(sux); } aoqi@0: void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux); aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(Goto, BlockEnd) aoqi@0: public: aoqi@0: enum Direction { aoqi@0: none, // Just a regular goto aoqi@0: taken, not_taken // Goto produced from If aoqi@0: }; aoqi@0: private: aoqi@0: ciMethod* _profiled_method; aoqi@0: int _profiled_bci; aoqi@0: Direction _direction; aoqi@0: public: aoqi@0: // creation aoqi@0: Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false) aoqi@0: : BlockEnd(illegalType, state_before, is_safepoint) aoqi@0: , _direction(none) aoqi@0: , _profiled_method(NULL) aoqi@0: , _profiled_bci(0) { aoqi@0: BlockList* s = new BlockList(1); aoqi@0: s->append(sux); aoqi@0: set_sux(s); aoqi@0: } aoqi@0: aoqi@0: Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint) aoqi@0: , _direction(none) aoqi@0: , _profiled_method(NULL) aoqi@0: , _profiled_bci(0) { aoqi@0: BlockList* s = new BlockList(1); aoqi@0: s->append(sux); aoqi@0: set_sux(s); aoqi@0: } aoqi@0: aoqi@0: bool should_profile() const { return check_flag(ProfileMDOFlag); } aoqi@0: ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches aoqi@0: int profiled_bci() const { return _profiled_bci; } aoqi@0: Direction direction() const { return _direction; } aoqi@0: aoqi@0: void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); } aoqi@0: void set_profiled_method(ciMethod* method) { _profiled_method = method; } aoqi@0: void set_profiled_bci(int bci) { _profiled_bci = bci; } aoqi@0: void set_direction(Direction d) { _direction = d; } aoqi@0: }; aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: LEAF(Assert, Instruction) aoqi@0: private: aoqi@0: Value _x; aoqi@0: Condition _cond; aoqi@0: Value _y; aoqi@0: char *_message; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: // unordered_is_true is valid for float/double compares only aoqi@0: Assert(Value x, Condition cond, bool unordered_is_true, Value y); aoqi@0: aoqi@0: // accessors aoqi@0: Value x() const { return _x; } aoqi@0: Condition cond() const { return _cond; } aoqi@0: bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); } aoqi@0: Value y() const { return _y; } aoqi@0: const char *message() const { return _message; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); } aoqi@0: }; aoqi@0: #endif aoqi@0: aoqi@0: LEAF(RangeCheckPredicate, StateSplit) aoqi@0: private: aoqi@0: Value _x; aoqi@0: Condition _cond; aoqi@0: Value _y; aoqi@0: aoqi@0: void check_state(); aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: // unordered_is_true is valid for float/double compares only aoqi@0: RangeCheckPredicate(Value x, Condition cond, bool unordered_is_true, Value y, ValueStack* state) : StateSplit(illegalType) aoqi@0: , _x(x) aoqi@0: , _cond(cond) aoqi@0: , _y(y) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: set_flag(UnorderedIsTrueFlag, unordered_is_true); aoqi@0: assert(x->type()->tag() == y->type()->tag(), "types must match"); aoqi@0: this->set_state(state); aoqi@0: check_state(); aoqi@0: } aoqi@0: aoqi@0: // Always deoptimize aoqi@0: RangeCheckPredicate(ValueStack* state) : StateSplit(illegalType) aoqi@0: { aoqi@0: this->set_state(state); aoqi@0: _x = _y = NULL; aoqi@0: check_state(); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value x() const { return _x; } aoqi@0: Condition cond() const { return _cond; } aoqi@0: bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); } aoqi@0: Value y() const { return _y; } aoqi@0: aoqi@0: void always_fail() { _x = _y = NULL; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); } aoqi@0: HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond()) aoqi@0: }; aoqi@0: aoqi@0: LEAF(If, BlockEnd) aoqi@0: private: aoqi@0: Value _x; aoqi@0: Condition _cond; aoqi@0: Value _y; aoqi@0: ciMethod* _profiled_method; aoqi@0: int _profiled_bci; // Canonicalizer may alter bci of If node aoqi@0: bool _swapped; // Is the order reversed with respect to the original If in the aoqi@0: // bytecode stream? aoqi@0: public: aoqi@0: // creation aoqi@0: // unordered_is_true is valid for float/double compares only aoqi@0: If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint) aoqi@0: : BlockEnd(illegalType, state_before, is_safepoint) aoqi@0: , _x(x) aoqi@0: , _cond(cond) aoqi@0: , _y(y) aoqi@0: , _profiled_method(NULL) aoqi@0: , _profiled_bci(0) aoqi@0: , _swapped(false) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: set_flag(UnorderedIsTrueFlag, unordered_is_true); aoqi@0: assert(x->type()->tag() == y->type()->tag(), "types must match"); aoqi@0: BlockList* s = new BlockList(2); aoqi@0: s->append(tsux); aoqi@0: s->append(fsux); aoqi@0: set_sux(s); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value x() const { return _x; } aoqi@0: Condition cond() const { return _cond; } aoqi@0: bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); } aoqi@0: Value y() const { return _y; } aoqi@0: BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); } aoqi@0: BlockBegin* tsux() const { return sux_for(true); } aoqi@0: BlockBegin* fsux() const { return sux_for(false); } aoqi@0: BlockBegin* usux() const { return sux_for(unordered_is_true()); } aoqi@0: bool should_profile() const { return check_flag(ProfileMDOFlag); } aoqi@0: ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches aoqi@0: int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered aoqi@0: bool is_swapped() const { return _swapped; } aoqi@0: aoqi@0: // manipulation aoqi@0: void swap_operands() { aoqi@0: Value t = _x; _x = _y; _y = t; aoqi@0: _cond = mirror(_cond); aoqi@0: } aoqi@0: aoqi@0: void swap_sux() { aoqi@0: assert(number_of_sux() == 2, "wrong number of successors"); aoqi@0: BlockList* s = sux(); aoqi@0: BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t); aoqi@0: _cond = negate(_cond); aoqi@0: set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag)); aoqi@0: } aoqi@0: aoqi@0: void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); } aoqi@0: void set_profiled_method(ciMethod* method) { _profiled_method = method; } aoqi@0: void set_profiled_bci(int bci) { _profiled_bci = bci; } aoqi@0: void set_swapped(bool value) { _swapped = value; } aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(IfInstanceOf, BlockEnd) aoqi@0: private: aoqi@0: ciKlass* _klass; aoqi@0: Value _obj; aoqi@0: bool _test_is_instance; // jump if instance aoqi@0: int _instanceof_bci; aoqi@0: aoqi@0: public: aoqi@0: IfInstanceOf(ciKlass* klass, Value obj, bool test_is_instance, int instanceof_bci, BlockBegin* tsux, BlockBegin* fsux) aoqi@0: : BlockEnd(illegalType, NULL, false) // temporary set to false aoqi@0: , _klass(klass) aoqi@0: , _obj(obj) aoqi@0: , _test_is_instance(test_is_instance) aoqi@0: , _instanceof_bci(instanceof_bci) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: assert(instanceof_bci >= 0, "illegal bci"); aoqi@0: BlockList* s = new BlockList(2); aoqi@0: s->append(tsux); aoqi@0: s->append(fsux); aoqi@0: set_sux(s); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: // aoqi@0: // Note 1: If test_is_instance() is true, IfInstanceOf tests if obj *is* an aoqi@0: // instance of klass; otherwise it tests if it is *not* and instance aoqi@0: // of klass. aoqi@0: // aoqi@0: // Note 2: IfInstanceOf instructions are created by combining an InstanceOf aoqi@0: // and an If instruction. The IfInstanceOf bci() corresponds to the aoqi@0: // bci that the If would have had; the (this->) instanceof_bci() is aoqi@0: // the bci of the original InstanceOf instruction. aoqi@0: ciKlass* klass() const { return _klass; } aoqi@0: Value obj() const { return _obj; } aoqi@0: int instanceof_bci() const { return _instanceof_bci; } aoqi@0: bool test_is_instance() const { return _test_is_instance; } aoqi@0: BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); } aoqi@0: BlockBegin* tsux() const { return sux_for(true); } aoqi@0: BlockBegin* fsux() const { return sux_for(false); } aoqi@0: aoqi@0: // manipulation aoqi@0: void swap_sux() { aoqi@0: assert(number_of_sux() == 2, "wrong number of successors"); aoqi@0: BlockList* s = sux(); aoqi@0: BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t); aoqi@0: _test_is_instance = !_test_is_instance; aoqi@0: } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_obj); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(Switch, BlockEnd) aoqi@0: private: aoqi@0: Value _tag; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint) aoqi@0: : BlockEnd(illegalType, state_before, is_safepoint) aoqi@0: , _tag(tag) { aoqi@0: ASSERT_VALUES aoqi@0: set_sux(sux); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value tag() const { return _tag; } aoqi@0: int length() const { return number_of_sux() - 1; } aoqi@0: aoqi@0: virtual bool needs_exception_state() const { return false; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_tag); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(TableSwitch, Switch) aoqi@0: private: aoqi@0: int _lo_key; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint) aoqi@0: : Switch(tag, sux, state_before, is_safepoint) aoqi@0: , _lo_key(lo_key) {} aoqi@0: aoqi@0: // accessors aoqi@0: int lo_key() const { return _lo_key; } aoqi@0: int hi_key() const { return _lo_key + length() - 1; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(LookupSwitch, Switch) aoqi@0: private: aoqi@0: intArray* _keys; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint) aoqi@0: : Switch(tag, sux, state_before, is_safepoint) aoqi@0: , _keys(keys) { aoqi@0: assert(keys != NULL, "keys must exist"); aoqi@0: assert(keys->length() == length(), "sux & keys have incompatible lengths"); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: int key_at(int i) const { return _keys->at(i); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(Return, BlockEnd) aoqi@0: private: aoqi@0: Value _result; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: Return(Value result) : aoqi@0: BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true), aoqi@0: _result(result) {} aoqi@0: aoqi@0: // accessors aoqi@0: Value result() const { return _result; } aoqi@0: bool has_result() const { return result() != NULL; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { aoqi@0: BlockEnd::input_values_do(f); aoqi@0: if (has_result()) f->visit(&_result); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(Throw, BlockEnd) aoqi@0: private: aoqi@0: Value _exception; aoqi@0: aoqi@0: public: aoqi@0: // creation aoqi@0: Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value exception() const { return _exception; } aoqi@0: aoqi@0: // generic aoqi@0: virtual bool can_trap() const { return true; } aoqi@0: virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_exception); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(Base, BlockEnd) aoqi@0: public: aoqi@0: // creation aoqi@0: Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, NULL, false) { aoqi@0: assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged"); aoqi@0: assert(osr_entry == NULL || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged"); aoqi@0: BlockList* s = new BlockList(2); aoqi@0: if (osr_entry != NULL) s->append(osr_entry); aoqi@0: s->append(std_entry); // must be default sux! aoqi@0: set_sux(s); aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: BlockBegin* std_entry() const { return default_sux(); } aoqi@0: BlockBegin* osr_entry() const { return number_of_sux() < 2 ? NULL : sux_at(0); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(OsrEntry, Instruction) aoqi@0: public: aoqi@0: // creation aoqi@0: #ifdef _LP64 aoqi@0: OsrEntry() : Instruction(longType) { pin(); } aoqi@0: #else aoqi@0: OsrEntry() : Instruction(intType) { pin(); } aoqi@0: #endif aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // Models the incoming exception at a catch site aoqi@0: LEAF(ExceptionObject, Instruction) aoqi@0: public: aoqi@0: // creation aoqi@0: ExceptionObject() : Instruction(objectType) { aoqi@0: pin(); aoqi@0: } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // Models needed rounding for floating-point values on Intel. aoqi@0: // Currently only used to represent rounding of double-precision aoqi@0: // values stored into local variables, but could be used to model aoqi@0: // intermediate rounding of single-precision values as well. aoqi@0: LEAF(RoundFP, Instruction) aoqi@0: private: aoqi@0: Value _input; // floating-point value to be rounded aoqi@0: aoqi@0: public: aoqi@0: RoundFP(Value input) aoqi@0: : Instruction(input->type()) // Note: should not be used for constants aoqi@0: , _input(input) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value input() const { return _input; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { f->visit(&_input); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(UnsafeOp, Instruction) aoqi@0: private: aoqi@0: BasicType _basic_type; // ValueType can not express byte-sized integers aoqi@0: aoqi@0: protected: aoqi@0: // creation aoqi@0: UnsafeOp(BasicType basic_type, bool is_put) aoqi@0: : Instruction(is_put ? voidType : as_ValueType(basic_type)) aoqi@0: , _basic_type(basic_type) aoqi@0: { aoqi@0: //Note: Unsafe ops are not not guaranteed to throw NPE. aoqi@0: // Convservatively, Unsafe operations must be pinned though we could be aoqi@0: // looser about this if we wanted to.. aoqi@0: pin(); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: // accessors aoqi@0: BasicType basic_type() { return _basic_type; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(UnsafeRawOp, UnsafeOp) aoqi@0: private: aoqi@0: Value _base; // Base address (a Java long) aoqi@0: Value _index; // Index if computed by optimizer; initialized to NULL aoqi@0: int _log2_scale; // Scale factor: 0, 1, 2, or 3. aoqi@0: // Indicates log2 of number of bytes (1, 2, 4, or 8) aoqi@0: // to scale index by. aoqi@0: aoqi@0: protected: aoqi@0: UnsafeRawOp(BasicType basic_type, Value addr, bool is_put) aoqi@0: : UnsafeOp(basic_type, is_put) aoqi@0: , _base(addr) aoqi@0: , _index(NULL) aoqi@0: , _log2_scale(0) aoqi@0: { aoqi@0: // Can not use ASSERT_VALUES because index may be NULL aoqi@0: assert(addr != NULL && addr->type()->is_long(), "just checking"); aoqi@0: } aoqi@0: aoqi@0: UnsafeRawOp(BasicType basic_type, Value base, Value index, int log2_scale, bool is_put) aoqi@0: : UnsafeOp(basic_type, is_put) aoqi@0: , _base(base) aoqi@0: , _index(index) aoqi@0: , _log2_scale(log2_scale) aoqi@0: { aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: // accessors aoqi@0: Value base() { return _base; } aoqi@0: Value index() { return _index; } aoqi@0: bool has_index() { return (_index != NULL); } aoqi@0: int log2_scale() { return _log2_scale; } aoqi@0: aoqi@0: // setters aoqi@0: void set_base (Value base) { _base = base; } aoqi@0: void set_index(Value index) { _index = index; } aoqi@0: void set_log2_scale(int log2_scale) { _log2_scale = log2_scale; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f); aoqi@0: f->visit(&_base); aoqi@0: if (has_index()) f->visit(&_index); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(UnsafeGetRaw, UnsafeRawOp) aoqi@0: private: aoqi@0: bool _may_be_unaligned, _is_wide; // For OSREntry aoqi@0: aoqi@0: public: aoqi@0: UnsafeGetRaw(BasicType basic_type, Value addr, bool may_be_unaligned, bool is_wide = false) aoqi@0: : UnsafeRawOp(basic_type, addr, false) { aoqi@0: _may_be_unaligned = may_be_unaligned; aoqi@0: _is_wide = is_wide; aoqi@0: } aoqi@0: aoqi@0: UnsafeGetRaw(BasicType basic_type, Value base, Value index, int log2_scale, bool may_be_unaligned, bool is_wide = false) aoqi@0: : UnsafeRawOp(basic_type, base, index, log2_scale, false) { aoqi@0: _may_be_unaligned = may_be_unaligned; aoqi@0: _is_wide = is_wide; aoqi@0: } aoqi@0: aoqi@0: bool may_be_unaligned() { return _may_be_unaligned; } aoqi@0: bool is_wide() { return _is_wide; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(UnsafePutRaw, UnsafeRawOp) aoqi@0: private: aoqi@0: Value _value; // Value to be stored aoqi@0: aoqi@0: public: aoqi@0: UnsafePutRaw(BasicType basic_type, Value addr, Value value) aoqi@0: : UnsafeRawOp(basic_type, addr, true) aoqi@0: , _value(value) aoqi@0: { aoqi@0: assert(value != NULL, "just checking"); aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: UnsafePutRaw(BasicType basic_type, Value base, Value index, int log2_scale, Value value) aoqi@0: : UnsafeRawOp(basic_type, base, index, log2_scale, true) aoqi@0: , _value(value) aoqi@0: { aoqi@0: assert(value != NULL, "just checking"); aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value value() { return _value; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { UnsafeRawOp::input_values_do(f); aoqi@0: f->visit(&_value); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: BASE(UnsafeObjectOp, UnsafeOp) aoqi@0: private: aoqi@0: Value _object; // Object to be fetched from or mutated aoqi@0: Value _offset; // Offset within object aoqi@0: bool _is_volatile; // true if volatile - dl/JSR166 aoqi@0: public: aoqi@0: UnsafeObjectOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile) aoqi@0: : UnsafeOp(basic_type, is_put), _object(object), _offset(offset), _is_volatile(is_volatile) aoqi@0: { aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value object() { return _object; } aoqi@0: Value offset() { return _offset; } aoqi@0: bool is_volatile() { return _is_volatile; } aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f); aoqi@0: f->visit(&_object); aoqi@0: f->visit(&_offset); } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(UnsafeGetObject, UnsafeObjectOp) aoqi@0: public: aoqi@0: UnsafeGetObject(BasicType basic_type, Value object, Value offset, bool is_volatile) aoqi@0: : UnsafeObjectOp(basic_type, object, offset, false, is_volatile) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(UnsafePutObject, UnsafeObjectOp) aoqi@0: private: aoqi@0: Value _value; // Value to be stored aoqi@0: public: aoqi@0: UnsafePutObject(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile) aoqi@0: : UnsafeObjectOp(basic_type, object, offset, true, is_volatile) aoqi@0: , _value(value) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: Value value() { return _value; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { UnsafeObjectOp::input_values_do(f); aoqi@0: f->visit(&_value); } aoqi@0: }; aoqi@0: aoqi@0: LEAF(UnsafeGetAndSetObject, UnsafeObjectOp) aoqi@0: private: aoqi@0: Value _value; // Value to be stored aoqi@0: bool _is_add; aoqi@0: public: aoqi@0: UnsafeGetAndSetObject(BasicType basic_type, Value object, Value offset, Value value, bool is_add) aoqi@0: : UnsafeObjectOp(basic_type, object, offset, false, false) aoqi@0: , _value(value) aoqi@0: , _is_add(is_add) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: aoqi@0: // accessors aoqi@0: bool is_add() const { return _is_add; } aoqi@0: Value value() { return _value; } aoqi@0: aoqi@0: // generic aoqi@0: virtual void input_values_do(ValueVisitor* f) { UnsafeObjectOp::input_values_do(f); aoqi@0: f->visit(&_value); } aoqi@0: }; aoqi@0: aoqi@0: BASE(UnsafePrefetch, UnsafeObjectOp) aoqi@0: public: aoqi@0: UnsafePrefetch(Value object, Value offset) aoqi@0: : UnsafeObjectOp(T_VOID, object, offset, false, false) aoqi@0: { aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(UnsafePrefetchRead, UnsafePrefetch) aoqi@0: public: aoqi@0: UnsafePrefetchRead(Value object, Value offset) aoqi@0: : UnsafePrefetch(object, offset) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: LEAF(UnsafePrefetchWrite, UnsafePrefetch) aoqi@0: public: aoqi@0: UnsafePrefetchWrite(Value object, Value offset) aoqi@0: : UnsafePrefetch(object, offset) aoqi@0: { aoqi@0: ASSERT_VALUES aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: LEAF(ProfileCall, Instruction) aoqi@0: private: aoqi@0: ciMethod* _method; aoqi@0: int _bci_of_invoke; aoqi@0: ciMethod* _callee; // the method that is called at the given bci aoqi@0: Value _recv; aoqi@0: ciKlass* _known_holder; aoqi@0: Values* _obj_args; // arguments for type profiling aoqi@0: ArgsNonNullState _nonnull_state; // Do we know whether some arguments are never null? aoqi@0: bool _inlined; // Are we profiling a call that is inlined aoqi@0: aoqi@0: public: aoqi@0: ProfileCall(ciMethod* method, int bci, ciMethod* callee, Value recv, ciKlass* known_holder, Values* obj_args, bool inlined) aoqi@0: : Instruction(voidType) aoqi@0: , _method(method) aoqi@0: , _bci_of_invoke(bci) aoqi@0: , _callee(callee) aoqi@0: , _recv(recv) aoqi@0: , _known_holder(known_holder) aoqi@0: , _obj_args(obj_args) aoqi@0: , _inlined(inlined) aoqi@0: { aoqi@0: // The ProfileCall has side-effects and must occur precisely where located aoqi@0: pin(); aoqi@0: } aoqi@0: aoqi@0: ciMethod* method() const { return _method; } aoqi@0: int bci_of_invoke() const { return _bci_of_invoke; } aoqi@0: ciMethod* callee() const { return _callee; } aoqi@0: Value recv() const { return _recv; } aoqi@0: ciKlass* known_holder() const { return _known_holder; } aoqi@0: int nb_profiled_args() const { return _obj_args == NULL ? 0 : _obj_args->length(); } aoqi@0: Value profiled_arg_at(int i) const { return _obj_args->at(i); } aoqi@0: bool arg_needs_null_check(int i) const { aoqi@0: return _nonnull_state.arg_needs_null_check(i); aoqi@0: } aoqi@0: bool inlined() const { return _inlined; } aoqi@0: aoqi@0: void set_arg_needs_null_check(int i, bool check) { aoqi@0: _nonnull_state.set_arg_needs_null_check(i, check); aoqi@0: } aoqi@0: aoqi@0: virtual void input_values_do(ValueVisitor* f) { aoqi@0: if (_recv != NULL) { aoqi@0: f->visit(&_recv); aoqi@0: } aoqi@0: for (int i = 0; i < nb_profiled_args(); i++) { aoqi@0: f->visit(_obj_args->adr_at(i)); aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: LEAF(ProfileReturnType, Instruction) aoqi@0: private: aoqi@0: ciMethod* _method; aoqi@0: ciMethod* _callee; aoqi@0: int _bci_of_invoke; aoqi@0: Value _ret; aoqi@0: aoqi@0: public: aoqi@0: ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret) aoqi@0: : Instruction(voidType) aoqi@0: , _method(method) aoqi@0: , _callee(callee) aoqi@0: , _bci_of_invoke(bci) aoqi@0: , _ret(ret) aoqi@0: { aoqi@0: set_needs_null_check(true); aoqi@0: // The ProfileType has side-effects and must occur precisely where located aoqi@0: pin(); aoqi@0: } aoqi@0: aoqi@0: ciMethod* method() const { return _method; } aoqi@0: ciMethod* callee() const { return _callee; } aoqi@0: int bci_of_invoke() const { return _bci_of_invoke; } aoqi@0: Value ret() const { return _ret; } aoqi@0: aoqi@0: virtual void input_values_do(ValueVisitor* f) { aoqi@0: if (_ret != NULL) { aoqi@0: f->visit(&_ret); aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: // Call some C runtime function that doesn't safepoint, aoqi@0: // optionally passing the current thread as the first argument. aoqi@0: LEAF(RuntimeCall, Instruction) aoqi@0: private: aoqi@0: const char* _entry_name; aoqi@0: address _entry; aoqi@0: Values* _args; aoqi@0: bool _pass_thread; // Pass the JavaThread* as an implicit first argument aoqi@0: aoqi@0: public: aoqi@0: RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true) aoqi@0: : Instruction(type) aoqi@0: , _entry(entry) aoqi@0: , _args(args) aoqi@0: , _entry_name(entry_name) aoqi@0: , _pass_thread(pass_thread) { aoqi@0: ASSERT_VALUES aoqi@0: pin(); aoqi@0: } aoqi@0: aoqi@0: const char* entry_name() const { return _entry_name; } aoqi@0: address entry() const { return _entry; } aoqi@0: int number_of_arguments() const { return _args->length(); } aoqi@0: Value argument_at(int i) const { return _args->at(i); } aoqi@0: bool pass_thread() const { return _pass_thread; } aoqi@0: aoqi@0: virtual void input_values_do(ValueVisitor* f) { aoqi@0: for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i)); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: // Use to trip invocation counter of an inlined method aoqi@0: aoqi@0: LEAF(ProfileInvoke, Instruction) aoqi@0: private: aoqi@0: ciMethod* _inlinee; aoqi@0: ValueStack* _state; aoqi@0: aoqi@0: public: aoqi@0: ProfileInvoke(ciMethod* inlinee, ValueStack* state) aoqi@0: : Instruction(voidType) aoqi@0: , _inlinee(inlinee) aoqi@0: , _state(state) aoqi@0: { aoqi@0: // The ProfileInvoke has side-effects and must occur precisely where located QQQ??? aoqi@0: pin(); aoqi@0: } aoqi@0: aoqi@0: ciMethod* inlinee() { return _inlinee; } aoqi@0: ValueStack* state() { return _state; } aoqi@0: virtual void input_values_do(ValueVisitor*) {} aoqi@0: virtual void state_values_do(ValueVisitor*); aoqi@0: }; aoqi@0: aoqi@0: LEAF(MemBar, Instruction) aoqi@0: private: aoqi@0: LIR_Code _code; aoqi@0: aoqi@0: public: aoqi@0: MemBar(LIR_Code code) aoqi@0: : Instruction(voidType) aoqi@0: , _code(code) aoqi@0: { aoqi@0: pin(); aoqi@0: } aoqi@0: aoqi@0: LIR_Code code() { return _code; } aoqi@0: aoqi@0: virtual void input_values_do(ValueVisitor*) {} aoqi@0: }; aoqi@0: aoqi@0: class BlockPair: public CompilationResourceObj { aoqi@0: private: aoqi@0: BlockBegin* _from; aoqi@0: BlockBegin* _to; aoqi@0: public: aoqi@0: BlockPair(BlockBegin* from, BlockBegin* to): _from(from), _to(to) {} aoqi@0: BlockBegin* from() const { return _from; } aoqi@0: BlockBegin* to() const { return _to; } aoqi@0: bool is_same(BlockBegin* from, BlockBegin* to) const { return _from == from && _to == to; } aoqi@0: bool is_same(BlockPair* p) const { return _from == p->from() && _to == p->to(); } aoqi@0: void set_to(BlockBegin* b) { _to = b; } aoqi@0: void set_from(BlockBegin* b) { _from = b; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: define_array(BlockPairArray, BlockPair*) aoqi@0: define_stack(BlockPairList, BlockPairArray) aoqi@0: aoqi@0: aoqi@0: inline int BlockBegin::number_of_sux() const { assert(_end == NULL || _end->number_of_sux() == _successors.length(), "mismatch"); return _successors.length(); } aoqi@0: inline BlockBegin* BlockBegin::sux_at(int i) const { assert(_end == NULL || _end->sux_at(i) == _successors.at(i), "mismatch"); return _successors.at(i); } aoqi@0: inline void BlockBegin::add_successor(BlockBegin* sux) { assert(_end == NULL, "Would create mismatch with successors of BlockEnd"); _successors.append(sux); } aoqi@0: aoqi@0: #undef ASSERT_VALUES aoqi@0: aoqi@0: #endif // SHARE_VM_C1_C1_INSTRUCTION_HPP