Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/c1/c1_Instruction.hpp
32285 views
/*1* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_C1_C1_INSTRUCTION_HPP25#define SHARE_VM_C1_C1_INSTRUCTION_HPP2627#include "c1/c1_Compilation.hpp"28#include "c1/c1_LIR.hpp"29#include "c1/c1_ValueType.hpp"30#include "ci/ciField.hpp"3132// Predefined classes33class ciField;34class ValueStack;35class InstructionPrinter;36class IRScope;37class LIR_OprDesc;38typedef LIR_OprDesc* LIR_Opr;394041// Instruction class hierarchy42//43// All leaf classes in the class hierarchy are concrete classes44// (i.e., are instantiated). All other classes are abstract and45// serve factoring.4647class Instruction;48class Phi;49class Local;50class Constant;51class AccessField;52class LoadField;53class StoreField;54class AccessArray;55class ArrayLength;56class AccessIndexed;57class LoadIndexed;58class StoreIndexed;59class NegateOp;60class Op2;61class ArithmeticOp;62class ShiftOp;63class LogicOp;64class CompareOp;65class IfOp;66class Convert;67class NullCheck;68class TypeCast;69class OsrEntry;70class ExceptionObject;71class StateSplit;72class Invoke;73class NewInstance;74class NewArray;75class NewTypeArray;76class NewObjectArray;77class NewMultiArray;78class TypeCheck;79class CheckCast;80class InstanceOf;81class AccessMonitor;82class MonitorEnter;83class MonitorExit;84class Intrinsic;85class BlockBegin;86class BlockEnd;87class Goto;88class If;89class IfInstanceOf;90class Switch;91class TableSwitch;92class LookupSwitch;93class Return;94class Throw;95class Base;96class RoundFP;97class UnsafeOp;98class UnsafeRawOp;99class UnsafeGetRaw;100class UnsafePutRaw;101class UnsafeObjectOp;102class UnsafeGetObject;103class UnsafePutObject;104class UnsafeGetAndSetObject;105class UnsafePrefetch;106class UnsafePrefetchRead;107class UnsafePrefetchWrite;108class ProfileCall;109class ProfileReturnType;110class ProfileInvoke;111class RuntimeCall;112class MemBar;113class RangeCheckPredicate;114#ifdef ASSERT115class Assert;116#endif117118// A Value is a reference to the instruction creating the value119typedef Instruction* Value;120define_array(ValueArray, Value)121define_stack(Values, ValueArray)122123define_array(ValueStackArray, ValueStack*)124define_stack(ValueStackStack, ValueStackArray)125126// BlockClosure is the base class for block traversal/iteration.127128class BlockClosure: public CompilationResourceObj {129public:130virtual void block_do(BlockBegin* block) = 0;131};132133134// A simple closure class for visiting the values of an Instruction135class ValueVisitor: public StackObj {136public:137virtual void visit(Value* v) = 0;138};139140141// Some array and list classes142define_array(BlockBeginArray, BlockBegin*)143define_stack(_BlockList, BlockBeginArray)144145class BlockList: public _BlockList {146public:147BlockList(): _BlockList() {}148BlockList(const int size): _BlockList(size) {}149BlockList(const int size, BlockBegin* init): _BlockList(size, init) {}150151void iterate_forward(BlockClosure* closure);152void iterate_backward(BlockClosure* closure);153void blocks_do(void f(BlockBegin*));154void values_do(ValueVisitor* f);155void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN;156};157158159// InstructionVisitors provide type-based dispatch for instructions.160// For each concrete Instruction class X, a virtual function do_X is161// provided. Functionality that needs to be implemented for all classes162// (e.g., printing, code generation) is factored out into a specialised163// visitor instead of added to the Instruction classes itself.164165class InstructionVisitor: public StackObj {166public:167virtual void do_Phi (Phi* x) = 0;168virtual void do_Local (Local* x) = 0;169virtual void do_Constant (Constant* x) = 0;170virtual void do_LoadField (LoadField* x) = 0;171virtual void do_StoreField (StoreField* x) = 0;172virtual void do_ArrayLength (ArrayLength* x) = 0;173virtual void do_LoadIndexed (LoadIndexed* x) = 0;174virtual void do_StoreIndexed (StoreIndexed* x) = 0;175virtual void do_NegateOp (NegateOp* x) = 0;176virtual void do_ArithmeticOp (ArithmeticOp* x) = 0;177virtual void do_ShiftOp (ShiftOp* x) = 0;178virtual void do_LogicOp (LogicOp* x) = 0;179virtual void do_CompareOp (CompareOp* x) = 0;180virtual void do_IfOp (IfOp* x) = 0;181virtual void do_Convert (Convert* x) = 0;182virtual void do_NullCheck (NullCheck* x) = 0;183virtual void do_TypeCast (TypeCast* x) = 0;184virtual void do_Invoke (Invoke* x) = 0;185virtual void do_NewInstance (NewInstance* x) = 0;186virtual void do_NewTypeArray (NewTypeArray* x) = 0;187virtual void do_NewObjectArray (NewObjectArray* x) = 0;188virtual void do_NewMultiArray (NewMultiArray* x) = 0;189virtual void do_CheckCast (CheckCast* x) = 0;190virtual void do_InstanceOf (InstanceOf* x) = 0;191virtual void do_MonitorEnter (MonitorEnter* x) = 0;192virtual void do_MonitorExit (MonitorExit* x) = 0;193virtual void do_Intrinsic (Intrinsic* x) = 0;194virtual void do_BlockBegin (BlockBegin* x) = 0;195virtual void do_Goto (Goto* x) = 0;196virtual void do_If (If* x) = 0;197virtual void do_IfInstanceOf (IfInstanceOf* x) = 0;198virtual void do_TableSwitch (TableSwitch* x) = 0;199virtual void do_LookupSwitch (LookupSwitch* x) = 0;200virtual void do_Return (Return* x) = 0;201virtual void do_Throw (Throw* x) = 0;202virtual void do_Base (Base* x) = 0;203virtual void do_OsrEntry (OsrEntry* x) = 0;204virtual void do_ExceptionObject(ExceptionObject* x) = 0;205virtual void do_RoundFP (RoundFP* x) = 0;206virtual void do_UnsafeGetRaw (UnsafeGetRaw* x) = 0;207virtual void do_UnsafePutRaw (UnsafePutRaw* x) = 0;208virtual void do_UnsafeGetObject(UnsafeGetObject* x) = 0;209virtual void do_UnsafePutObject(UnsafePutObject* x) = 0;210virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) = 0;211virtual void do_UnsafePrefetchRead (UnsafePrefetchRead* x) = 0;212virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) = 0;213virtual void do_ProfileCall (ProfileCall* x) = 0;214virtual void do_ProfileReturnType (ProfileReturnType* x) = 0;215virtual void do_ProfileInvoke (ProfileInvoke* x) = 0;216virtual void do_RuntimeCall (RuntimeCall* x) = 0;217virtual void do_MemBar (MemBar* x) = 0;218virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0;219#ifdef ASSERT220virtual void do_Assert (Assert* x) = 0;221#endif222};223224225// Hashing support226//227// Note: This hash functions affect the performance228// of ValueMap - make changes carefully!229230#define HASH1(x1 ) ((intx)(x1))231#define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2))232#define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3))233#define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))234235236// The following macros are used to implement instruction-specific hashing.237// By default, each instruction implements hash() and is_equal(Value), used238// for value numbering/common subexpression elimination. The default imple-239// mentation disables value numbering. Each instruction which can be value-240// numbered, should define corresponding hash() and is_equal(Value) functions241// via the macros below. The f arguments specify all the values/op codes, etc.242// that need to be identical for two instructions to be identical.243//244// Note: The default implementation of hash() returns 0 in order to indicate245// that the instruction should not be considered for value numbering.246// The currently used hash functions do not guarantee that never a 0247// is produced. While this is still correct, it may be a performance248// bug (no value numbering for that node). However, this situation is249// so unlikely, that we are not going to handle it specially.250251#define HASHING1(class_name, enabled, f1) \252virtual intx hash() const { \253return (enabled) ? HASH2(name(), f1) : 0; \254} \255virtual bool is_equal(Value v) const { \256if (!(enabled) ) return false; \257class_name* _v = v->as_##class_name(); \258if (_v == NULL ) return false; \259if (f1 != _v->f1) return false; \260return true; \261} \262263264#define HASHING2(class_name, enabled, f1, f2) \265virtual intx hash() const { \266return (enabled) ? HASH3(name(), f1, f2) : 0; \267} \268virtual bool is_equal(Value v) const { \269if (!(enabled) ) return false; \270class_name* _v = v->as_##class_name(); \271if (_v == NULL ) return false; \272if (f1 != _v->f1) return false; \273if (f2 != _v->f2) return false; \274return true; \275} \276277278#define HASHING3(class_name, enabled, f1, f2, f3) \279virtual intx hash() const { \280return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \281} \282virtual bool is_equal(Value v) const { \283if (!(enabled) ) return false; \284class_name* _v = v->as_##class_name(); \285if (_v == NULL ) return false; \286if (f1 != _v->f1) return false; \287if (f2 != _v->f2) return false; \288if (f3 != _v->f3) return false; \289return true; \290} \291292293// The mother of all instructions...294295class Instruction: public CompilationResourceObj {296private:297int _id; // the unique instruction id298#ifndef PRODUCT299int _printable_bci; // the bci of the instruction for printing300#endif301int _use_count; // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1302int _pin_state; // set of PinReason describing the reason for pinning303ValueType* _type; // the instruction value type304Instruction* _next; // the next instruction if any (NULL for BlockEnd instructions)305Instruction* _subst; // the substitution instruction if any306LIR_Opr _operand; // LIR specific information307unsigned int _flags; // Flag bits308309ValueStack* _state_before; // Copy of state with input operands still on stack (or NULL)310ValueStack* _exception_state; // Copy of state for exception handling311XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction312313friend class UseCountComputer;314friend class BlockBegin;315316void update_exception_state(ValueStack* state);317318protected:319BlockBegin* _block; // Block that contains this instruction320321void set_type(ValueType* type) {322assert(type != NULL, "type must exist");323_type = type;324}325326// Helper class to keep track of which arguments need a null check327class ArgsNonNullState {328private:329int _nonnull_state; // mask identifying which args are nonnull330public:331ArgsNonNullState()332: _nonnull_state(AllBits) {}333334// Does argument number i needs a null check?335bool arg_needs_null_check(int i) const {336// No data is kept for arguments starting at position 33 so337// conservatively assume that they need a null check.338if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {339return is_set_nth_bit(_nonnull_state, i);340}341return true;342}343344// Set whether argument number i needs a null check or not345void set_arg_needs_null_check(int i, bool check) {346if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {347if (check) {348_nonnull_state |= nth_bit(i);349} else {350_nonnull_state &= ~(nth_bit(i));351}352}353}354};355356public:357void* operator new(size_t size) throw() {358Compilation* c = Compilation::current();359void* res = c->arena()->Amalloc(size);360((Instruction*)res)->_id = c->get_next_id();361return res;362}363364static const int no_bci = -99;365366enum InstructionFlag {367NeedsNullCheckFlag = 0,368CanTrapFlag,369DirectCompareFlag,370IsEliminatedFlag,371IsSafepointFlag,372IsStaticFlag,373IsStrictfpFlag,374NeedsStoreCheckFlag,375NeedsWriteBarrierFlag,376PreservesStateFlag,377TargetIsFinalFlag,378TargetIsLoadedFlag,379TargetIsStrictfpFlag,380UnorderedIsTrueFlag,381NeedsPatchingFlag,382ThrowIncompatibleClassChangeErrorFlag,383InvokeSpecialReceiverCheckFlag,384ProfileMDOFlag,385IsLinkedInBlockFlag,386NeedsRangeCheckFlag,387InWorkListFlag,388DeoptimizeOnException,389InstructionLastFlag390};391392public:393bool check_flag(InstructionFlag id) const { return (_flags & (1 << id)) != 0; }394void set_flag(InstructionFlag id, bool f) { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); };395396// 'globally' used condition values397enum Condition {398eql, neq, lss, leq, gtr, geq, aeq, beq399};400401// Instructions may be pinned for many reasons and under certain conditions402// with enough knowledge it's possible to safely unpin them.403enum PinReason {404PinUnknown = 1 << 0405, PinExplicitNullCheck = 1 << 3406, PinStackForStateSplit= 1 << 12407, PinStateSplitConstructor= 1 << 13408, PinGlobalValueNumbering= 1 << 14409};410411static Condition mirror(Condition cond);412static Condition negate(Condition cond);413414// initialization415static int number_of_instructions() {416return Compilation::current()->number_of_instructions();417}418419// creation420Instruction(ValueType* type, ValueStack* state_before = NULL, bool type_is_constant = false)421: _use_count(0)422#ifndef PRODUCT423, _printable_bci(-99)424#endif425, _pin_state(0)426, _type(type)427, _next(NULL)428, _block(NULL)429, _subst(NULL)430, _flags(0)431, _operand(LIR_OprFact::illegalOpr)432, _state_before(state_before)433, _exception_handlers(NULL)434{435check_state(state_before);436assert(type != NULL && (!type->is_constant() || type_is_constant), "type must exist");437update_exception_state(_state_before);438}439440// accessors441int id() const { return _id; }442#ifndef PRODUCT443bool has_printable_bci() const { return _printable_bci != -99; }444int printable_bci() const { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }445void set_printable_bci(int bci) { _printable_bci = bci; }446#endif447int dominator_depth();448int use_count() const { return _use_count; }449int pin_state() const { return _pin_state; }450bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; }451ValueType* type() const { return _type; }452BlockBegin *block() const { return _block; }453Instruction* prev(); // use carefully, expensive operation454Instruction* next() const { return _next; }455bool has_subst() const { return _subst != NULL; }456Instruction* subst() { return _subst == NULL ? this : _subst->subst(); }457LIR_Opr operand() const { return _operand; }458459void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); }460bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); }461bool is_linked() const { return check_flag(IsLinkedInBlockFlag); }462bool can_be_linked() { return as_Local() == NULL && as_Phi() == NULL; }463464bool has_uses() const { return use_count() > 0; }465ValueStack* state_before() const { return _state_before; }466ValueStack* exception_state() const { return _exception_state; }467virtual bool needs_exception_state() const { return true; }468XHandlers* exception_handlers() const { return _exception_handlers; }469470// manipulation471void pin(PinReason reason) { _pin_state |= reason; }472void pin() { _pin_state |= PinUnknown; }473// DANGEROUS: only used by EliminateStores474void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }475476Instruction* set_next(Instruction* next) {477assert(next->has_printable_bci(), "_printable_bci should have been set");478assert(next != NULL, "must not be NULL");479assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");480assert(next->can_be_linked(), "shouldn't link these instructions into list");481482BlockBegin *block = this->block();483next->_block = block;484485next->set_flag(Instruction::IsLinkedInBlockFlag, true);486_next = next;487return next;488}489490Instruction* set_next(Instruction* next, int bci) {491#ifndef PRODUCT492next->set_printable_bci(bci);493#endif494return set_next(next);495}496497// when blocks are merged498void fixup_block_pointers() {499Instruction *cur = next()->next(); // next()'s block is set in set_next500while (cur && cur->_block != block()) {501cur->_block = block();502cur = cur->next();503}504}505506Instruction *insert_after(Instruction *i) {507Instruction* n = _next;508set_next(i);509i->set_next(n);510return _next;511}512513Instruction *insert_after_same_bci(Instruction *i) {514#ifndef PRODUCT515i->set_printable_bci(printable_bci());516#endif517return insert_after(i);518}519520void set_subst(Instruction* subst) {521assert(subst == NULL ||522type()->base() == subst->type()->base() ||523subst->type()->base() == illegalType, "type can't change");524_subst = subst;525}526void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }527void set_exception_state(ValueStack* s) { check_state(s); _exception_state = s; }528void set_state_before(ValueStack* s) { check_state(s); _state_before = s; }529530// machine-specifics531void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }532void clear_operand() { _operand = LIR_OprFact::illegalOpr; }533534// generic535virtual Instruction* as_Instruction() { return this; } // to satisfy HASHING1 macro536virtual Phi* as_Phi() { return NULL; }537virtual Local* as_Local() { return NULL; }538virtual Constant* as_Constant() { return NULL; }539virtual AccessField* as_AccessField() { return NULL; }540virtual LoadField* as_LoadField() { return NULL; }541virtual StoreField* as_StoreField() { return NULL; }542virtual AccessArray* as_AccessArray() { return NULL; }543virtual ArrayLength* as_ArrayLength() { return NULL; }544virtual AccessIndexed* as_AccessIndexed() { return NULL; }545virtual LoadIndexed* as_LoadIndexed() { return NULL; }546virtual StoreIndexed* as_StoreIndexed() { return NULL; }547virtual NegateOp* as_NegateOp() { return NULL; }548virtual Op2* as_Op2() { return NULL; }549virtual ArithmeticOp* as_ArithmeticOp() { return NULL; }550virtual ShiftOp* as_ShiftOp() { return NULL; }551virtual LogicOp* as_LogicOp() { return NULL; }552virtual CompareOp* as_CompareOp() { return NULL; }553virtual IfOp* as_IfOp() { return NULL; }554virtual Convert* as_Convert() { return NULL; }555virtual NullCheck* as_NullCheck() { return NULL; }556virtual OsrEntry* as_OsrEntry() { return NULL; }557virtual StateSplit* as_StateSplit() { return NULL; }558virtual Invoke* as_Invoke() { return NULL; }559virtual NewInstance* as_NewInstance() { return NULL; }560virtual NewArray* as_NewArray() { return NULL; }561virtual NewTypeArray* as_NewTypeArray() { return NULL; }562virtual NewObjectArray* as_NewObjectArray() { return NULL; }563virtual NewMultiArray* as_NewMultiArray() { return NULL; }564virtual TypeCheck* as_TypeCheck() { return NULL; }565virtual CheckCast* as_CheckCast() { return NULL; }566virtual InstanceOf* as_InstanceOf() { return NULL; }567virtual TypeCast* as_TypeCast() { return NULL; }568virtual AccessMonitor* as_AccessMonitor() { return NULL; }569virtual MonitorEnter* as_MonitorEnter() { return NULL; }570virtual MonitorExit* as_MonitorExit() { return NULL; }571virtual Intrinsic* as_Intrinsic() { return NULL; }572virtual BlockBegin* as_BlockBegin() { return NULL; }573virtual BlockEnd* as_BlockEnd() { return NULL; }574virtual Goto* as_Goto() { return NULL; }575virtual If* as_If() { return NULL; }576virtual IfInstanceOf* as_IfInstanceOf() { return NULL; }577virtual TableSwitch* as_TableSwitch() { return NULL; }578virtual LookupSwitch* as_LookupSwitch() { return NULL; }579virtual Return* as_Return() { return NULL; }580virtual Throw* as_Throw() { return NULL; }581virtual Base* as_Base() { return NULL; }582virtual RoundFP* as_RoundFP() { return NULL; }583virtual ExceptionObject* as_ExceptionObject() { return NULL; }584virtual UnsafeOp* as_UnsafeOp() { return NULL; }585virtual ProfileInvoke* as_ProfileInvoke() { return NULL; }586virtual RangeCheckPredicate* as_RangeCheckPredicate() { return NULL; }587588#ifdef ASSERT589virtual Assert* as_Assert() { return NULL; }590#endif591592virtual void visit(InstructionVisitor* v) = 0;593594virtual bool can_trap() const { return false; }595596virtual void input_values_do(ValueVisitor* f) = 0;597virtual void state_values_do(ValueVisitor* f);598virtual void other_values_do(ValueVisitor* f) { /* usually no other - override on demand */ }599void values_do(ValueVisitor* f) { input_values_do(f); state_values_do(f); other_values_do(f); }600601virtual ciType* exact_type() const;602virtual ciType* declared_type() const { return NULL; }603604// hashing605virtual const char* name() const = 0;606HASHING1(Instruction, false, id()) // hashing disabled by default607608// debugging609static void check_state(ValueStack* state) PRODUCT_RETURN;610void print() PRODUCT_RETURN;611void print_line() PRODUCT_RETURN;612void print(InstructionPrinter& ip) PRODUCT_RETURN;613};614615616// The following macros are used to define base (i.e., non-leaf)617// and leaf instruction classes. They define class-name related618// generic functionality in one place.619620#define BASE(class_name, super_class_name) \621class class_name: public super_class_name { \622public: \623virtual class_name* as_##class_name() { return this; } \624625626#define LEAF(class_name, super_class_name) \627BASE(class_name, super_class_name) \628public: \629virtual const char* name() const { return #class_name; } \630virtual void visit(InstructionVisitor* v) { v->do_##class_name(this); } \631632633// Debugging support634635636#ifdef ASSERT637class AssertValues: public ValueVisitor {638void visit(Value* x) { assert((*x) != NULL, "value must exist"); }639};640#define ASSERT_VALUES { AssertValues assert_value; values_do(&assert_value); }641#else642#define ASSERT_VALUES643#endif // ASSERT644645646// A Phi is a phi function in the sense of SSA form. It stands for647// the value of a local variable at the beginning of a join block.648// A Phi consists of n operands, one for every incoming branch.649650LEAF(Phi, Instruction)651private:652int _pf_flags; // the flags of the phi function653int _index; // to value on operand stack (index < 0) or to local654public:655// creation656Phi(ValueType* type, BlockBegin* b, int index)657: Instruction(type->base())658, _pf_flags(0)659, _index(index)660{661_block = b;662NOT_PRODUCT(set_printable_bci(Value(b)->printable_bci()));663if (type->is_illegal()) {664make_illegal();665}666}667668// flags669enum Flag {670no_flag = 0,671visited = 1 << 0,672cannot_simplify = 1 << 1673};674675// accessors676bool is_local() const { return _index >= 0; }677bool is_on_stack() const { return !is_local(); }678int local_index() const { assert(is_local(), ""); return _index; }679int stack_index() const { assert(is_on_stack(), ""); return -(_index+1); }680681Value operand_at(int i) const;682int operand_count() const;683684void set(Flag f) { _pf_flags |= f; }685void clear(Flag f) { _pf_flags &= ~f; }686bool is_set(Flag f) const { return (_pf_flags & f) != 0; }687688// Invalidates phis corresponding to merges of locals of two different types689// (these should never be referenced, otherwise the bytecodes are illegal)690void make_illegal() {691set(cannot_simplify);692set_type(illegalType);693}694695bool is_illegal() const {696return type()->is_illegal();697}698699// generic700virtual void input_values_do(ValueVisitor* f) {701}702};703704705// A local is a placeholder for an incoming argument to a function call.706LEAF(Local, Instruction)707private:708int _java_index; // the local index within the method to which the local belongs709ciType* _declared_type;710public:711// creation712Local(ciType* declared, ValueType* type, int index)713: Instruction(type)714, _java_index(index)715, _declared_type(declared)716{717NOT_PRODUCT(set_printable_bci(-1));718}719720// accessors721int java_index() const { return _java_index; }722723virtual ciType* declared_type() const { return _declared_type; }724725// generic726virtual void input_values_do(ValueVisitor* f) { /* no values */ }727};728729730LEAF(Constant, Instruction)731public:732// creation733Constant(ValueType* type):734Instruction(type, NULL, /*type_is_constant*/ true)735{736assert(type->is_constant(), "must be a constant");737}738739Constant(ValueType* type, ValueStack* state_before):740Instruction(type, state_before, /*type_is_constant*/ true)741{742assert(state_before != NULL, "only used for constants which need patching");743assert(type->is_constant(), "must be a constant");744// since it's patching it needs to be pinned745pin();746}747748// generic749virtual bool can_trap() const { return state_before() != NULL; }750virtual void input_values_do(ValueVisitor* f) { /* no values */ }751752virtual intx hash() const;753virtual bool is_equal(Value v) const;754755virtual ciType* exact_type() const;756757enum CompareResult { not_comparable = -1, cond_false, cond_true };758759virtual CompareResult compare(Instruction::Condition condition, Value right) const;760BlockBegin* compare(Instruction::Condition cond, Value right,761BlockBegin* true_sux, BlockBegin* false_sux) const {762switch (compare(cond, right)) {763case not_comparable:764return NULL;765case cond_false:766return false_sux;767case cond_true:768return true_sux;769default:770ShouldNotReachHere();771return NULL;772}773}774};775776777BASE(AccessField, Instruction)778private:779Value _obj;780int _offset;781ciField* _field;782NullCheck* _explicit_null_check; // For explicit null check elimination783784public:785// creation786AccessField(Value obj, int offset, ciField* field, bool is_static,787ValueStack* state_before, bool needs_patching)788: Instruction(as_ValueType(field->type()->basic_type()), state_before)789, _obj(obj)790, _offset(offset)791, _field(field)792, _explicit_null_check(NULL)793{794set_needs_null_check(!is_static);795set_flag(IsStaticFlag, is_static);796set_flag(NeedsPatchingFlag, needs_patching);797ASSERT_VALUES798// pin of all instructions with memory access799pin();800}801802// accessors803Value obj() const { return _obj; }804int offset() const { return _offset; }805ciField* field() const { return _field; }806BasicType field_type() const { return _field->type()->basic_type(); }807bool is_static() const { return check_flag(IsStaticFlag); }808NullCheck* explicit_null_check() const { return _explicit_null_check; }809bool needs_patching() const { return check_flag(NeedsPatchingFlag); }810811// Unresolved getstatic and putstatic can cause initialization.812// Technically it occurs at the Constant that materializes the base813// of the static fields but it's simpler to model it here.814bool is_init_point() const { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); }815816// manipulation817818// Under certain circumstances, if a previous NullCheck instruction819// proved the target object non-null, we can eliminate the explicit820// null check and do an implicit one, simply specifying the debug821// information from the NullCheck. This field should only be consulted822// if needs_null_check() is true.823void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }824825// generic826virtual bool can_trap() const { return needs_null_check() || needs_patching(); }827virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }828};829830831LEAF(LoadField, AccessField)832public:833// creation834LoadField(Value obj, int offset, ciField* field, bool is_static,835ValueStack* state_before, bool needs_patching)836: AccessField(obj, offset, field, is_static, state_before, needs_patching)837{}838839ciType* declared_type() const;840841// generic842HASHING2(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset()) // cannot be eliminated if needs patching or if volatile843};844845846LEAF(StoreField, AccessField)847private:848Value _value;849850public:851// creation852StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,853ValueStack* state_before, bool needs_patching)854: AccessField(obj, offset, field, is_static, state_before, needs_patching)855, _value(value)856{857set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());858ASSERT_VALUES859pin();860}861862// accessors863Value value() const { return _value; }864bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }865866// generic867virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); }868};869870871BASE(AccessArray, Instruction)872private:873Value _array;874875public:876// creation877AccessArray(ValueType* type, Value array, ValueStack* state_before)878: Instruction(type, state_before)879, _array(array)880{881set_needs_null_check(true);882ASSERT_VALUES883pin(); // instruction with side effect (null exception or range check throwing)884}885886Value array() const { return _array; }887888// generic889virtual bool can_trap() const { return needs_null_check(); }890virtual void input_values_do(ValueVisitor* f) { f->visit(&_array); }891};892893894LEAF(ArrayLength, AccessArray)895private:896NullCheck* _explicit_null_check; // For explicit null check elimination897898public:899// creation900ArrayLength(Value array, ValueStack* state_before)901: AccessArray(intType, array, state_before)902, _explicit_null_check(NULL) {}903904// accessors905NullCheck* explicit_null_check() const { return _explicit_null_check; }906907// setters908// See LoadField::set_explicit_null_check for documentation909void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }910911// generic912HASHING1(ArrayLength, true, array()->subst())913};914915916BASE(AccessIndexed, AccessArray)917private:918Value _index;919Value _length;920BasicType _elt_type;921922public:923// creation924AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)925: AccessArray(as_ValueType(elt_type), array, state_before)926, _index(index)927, _length(length)928, _elt_type(elt_type)929{930set_flag(Instruction::NeedsRangeCheckFlag, true);931ASSERT_VALUES932}933934// accessors935Value index() const { return _index; }936Value length() const { return _length; }937BasicType elt_type() const { return _elt_type; }938939void clear_length() { _length = NULL; }940// perform elimination of range checks involving constants941bool compute_needs_range_check();942943// generic944virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }945};946947948LEAF(LoadIndexed, AccessIndexed)949private:950NullCheck* _explicit_null_check; // For explicit null check elimination951952public:953// creation954LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)955: AccessIndexed(array, index, length, elt_type, state_before)956, _explicit_null_check(NULL) {}957958// accessors959NullCheck* explicit_null_check() const { return _explicit_null_check; }960961// setters962// See LoadField::set_explicit_null_check for documentation963void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }964965ciType* exact_type() const;966ciType* declared_type() const;967968// generic969HASHING2(LoadIndexed, true, array()->subst(), index()->subst())970};971972973LEAF(StoreIndexed, AccessIndexed)974private:975Value _value;976977ciMethod* _profiled_method;978int _profiled_bci;979bool _check_boolean;980981public:982// creation983StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before, bool check_boolean)984: AccessIndexed(array, index, length, elt_type, state_before)985, _value(value), _profiled_method(NULL), _profiled_bci(0), _check_boolean(check_boolean)986{987set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));988set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));989ASSERT_VALUES990pin();991}992993// accessors994Value value() const { return _value; }995bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }996bool needs_store_check() const { return check_flag(NeedsStoreCheckFlag); }997bool check_boolean() const { return _check_boolean; }998// Helpers for MethodData* profiling999void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }1000void set_profiled_method(ciMethod* method) { _profiled_method = method; }1001void set_profiled_bci(int bci) { _profiled_bci = bci; }1002bool should_profile() const { return check_flag(ProfileMDOFlag); }1003ciMethod* profiled_method() const { return _profiled_method; }1004int profiled_bci() const { return _profiled_bci; }1005// generic1006virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); }1007};100810091010LEAF(NegateOp, Instruction)1011private:1012Value _x;10131014public:1015// creation1016NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {1017ASSERT_VALUES1018}10191020// accessors1021Value x() const { return _x; }10221023// generic1024virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); }1025};102610271028BASE(Op2, Instruction)1029private:1030Bytecodes::Code _op;1031Value _x;1032Value _y;10331034public:1035// creation1036Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = NULL)1037: Instruction(type, state_before)1038, _op(op)1039, _x(x)1040, _y(y)1041{1042ASSERT_VALUES1043}10441045// accessors1046Bytecodes::Code op() const { return _op; }1047Value x() const { return _x; }1048Value y() const { return _y; }10491050// manipulators1051void swap_operands() {1052assert(is_commutative(), "operation must be commutative");1053Value t = _x; _x = _y; _y = t;1054}10551056// generic1057virtual bool is_commutative() const { return false; }1058virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); }1059};106010611062LEAF(ArithmeticOp, Op2)1063public:1064// creation1065ArithmeticOp(Bytecodes::Code op, Value x, Value y, bool is_strictfp, ValueStack* state_before)1066: Op2(x->type()->meet(y->type()), op, x, y, state_before)1067{1068set_flag(IsStrictfpFlag, is_strictfp);1069if (can_trap()) pin();1070}10711072// accessors1073bool is_strictfp() const { return check_flag(IsStrictfpFlag); }10741075// generic1076virtual bool is_commutative() const;1077virtual bool can_trap() const;1078HASHING3(Op2, true, op(), x()->subst(), y()->subst())1079};108010811082LEAF(ShiftOp, Op2)1083public:1084// creation1085ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}10861087// generic1088HASHING3(Op2, true, op(), x()->subst(), y()->subst())1089};109010911092LEAF(LogicOp, Op2)1093public:1094// creation1095LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}10961097// generic1098virtual bool is_commutative() const;1099HASHING3(Op2, true, op(), x()->subst(), y()->subst())1100};110111021103LEAF(CompareOp, Op2)1104public:1105// creation1106CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)1107: Op2(intType, op, x, y, state_before)1108{}11091110// generic1111HASHING3(Op2, true, op(), x()->subst(), y()->subst())1112};111311141115LEAF(IfOp, Op2)1116private:1117Value _tval;1118Value _fval;11191120public:1121// creation1122IfOp(Value x, Condition cond, Value y, Value tval, Value fval)1123: Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)1124, _tval(tval)1125, _fval(fval)1126{1127ASSERT_VALUES1128assert(tval->type()->tag() == fval->type()->tag(), "types must match");1129}11301131// accessors1132virtual bool is_commutative() const;1133Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }1134Condition cond() const { return (Condition)Op2::op(); }1135Value tval() const { return _tval; }1136Value fval() const { return _fval; }11371138// generic1139virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }1140};114111421143LEAF(Convert, Instruction)1144private:1145Bytecodes::Code _op;1146Value _value;11471148public:1149// creation1150Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {1151ASSERT_VALUES1152}11531154// accessors1155Bytecodes::Code op() const { return _op; }1156Value value() const { return _value; }11571158// generic1159virtual void input_values_do(ValueVisitor* f) { f->visit(&_value); }1160HASHING2(Convert, true, op(), value()->subst())1161};116211631164LEAF(NullCheck, Instruction)1165private:1166Value _obj;11671168public:1169// creation1170NullCheck(Value obj, ValueStack* state_before)1171: Instruction(obj->type()->base(), state_before)1172, _obj(obj)1173{1174ASSERT_VALUES1175set_can_trap(true);1176assert(_obj->type()->is_object(), "null check must be applied to objects only");1177pin(Instruction::PinExplicitNullCheck);1178}11791180// accessors1181Value obj() const { return _obj; }11821183// setters1184void set_can_trap(bool can_trap) { set_flag(CanTrapFlag, can_trap); }11851186// generic1187virtual bool can_trap() const { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }1188virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }1189HASHING1(NullCheck, true, obj()->subst())1190};119111921193// This node is supposed to cast the type of another node to a more precise1194// declared type.1195LEAF(TypeCast, Instruction)1196private:1197ciType* _declared_type;1198Value _obj;11991200public:1201// The type of this node is the same type as the object type (and it might be constant).1202TypeCast(ciType* type, Value obj, ValueStack* state_before)1203: Instruction(obj->type(), state_before, obj->type()->is_constant()),1204_declared_type(type),1205_obj(obj) {}12061207// accessors1208ciType* declared_type() const { return _declared_type; }1209Value obj() const { return _obj; }12101211// generic1212virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }1213};121412151216BASE(StateSplit, Instruction)1217private:1218ValueStack* _state;12191220protected:1221static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);12221223public:1224// creation1225StateSplit(ValueType* type, ValueStack* state_before = NULL)1226: Instruction(type, state_before)1227, _state(NULL)1228{1229pin(PinStateSplitConstructor);1230}12311232// accessors1233ValueStack* state() const { return _state; }1234IRScope* scope() const; // the state's scope12351236// manipulation1237void set_state(ValueStack* state) { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }12381239// generic1240virtual void input_values_do(ValueVisitor* f) { /* no values */ }1241virtual void state_values_do(ValueVisitor* f);1242};124312441245LEAF(Invoke, StateSplit)1246private:1247Bytecodes::Code _code;1248Value _recv;1249Values* _args;1250BasicTypeList* _signature;1251int _vtable_index;1252ciMethod* _target;12531254public:1255// creation1256Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,1257int vtable_index, ciMethod* target, ValueStack* state_before);12581259// accessors1260Bytecodes::Code code() const { return _code; }1261Value receiver() const { return _recv; }1262bool has_receiver() const { return receiver() != NULL; }1263int number_of_arguments() const { return _args->length(); }1264Value argument_at(int i) const { return _args->at(i); }1265int vtable_index() const { return _vtable_index; }1266BasicTypeList* signature() const { return _signature; }1267ciMethod* target() const { return _target; }12681269ciType* declared_type() const;12701271// Returns false if target is not loaded1272bool target_is_final() const { return check_flag(TargetIsFinalFlag); }1273bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }1274// Returns false if target is not loaded1275bool target_is_strictfp() const { return check_flag(TargetIsStrictfpFlag); }12761277// JSR 292 support1278bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }1279bool is_method_handle_intrinsic() const { return target()->is_method_handle_intrinsic(); }12801281virtual bool needs_exception_state() const { return false; }12821283// generic1284virtual bool can_trap() const { return true; }1285virtual void input_values_do(ValueVisitor* f) {1286StateSplit::input_values_do(f);1287if (has_receiver()) f->visit(&_recv);1288for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));1289}1290virtual void state_values_do(ValueVisitor *f);1291};129212931294LEAF(NewInstance, StateSplit)1295private:1296ciInstanceKlass* _klass;1297bool _is_unresolved;12981299public:1300// creation1301NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved)1302: StateSplit(instanceType, state_before)1303, _klass(klass), _is_unresolved(is_unresolved)1304{}13051306// accessors1307ciInstanceKlass* klass() const { return _klass; }1308bool is_unresolved() const { return _is_unresolved; }13091310virtual bool needs_exception_state() const { return false; }13111312// generic1313virtual bool can_trap() const { return true; }1314ciType* exact_type() const;1315ciType* declared_type() const;1316};131713181319BASE(NewArray, StateSplit)1320private:1321Value _length;13221323public:1324// creation1325NewArray(Value length, ValueStack* state_before)1326: StateSplit(objectType, state_before)1327, _length(length)1328{1329// Do not ASSERT_VALUES since length is NULL for NewMultiArray1330}13311332// accessors1333Value length() const { return _length; }13341335virtual bool needs_exception_state() const { return false; }13361337ciType* exact_type() const { return NULL; }1338ciType* declared_type() const;13391340// generic1341virtual bool can_trap() const { return true; }1342virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_length); }1343};134413451346LEAF(NewTypeArray, NewArray)1347private:1348BasicType _elt_type;13491350public:1351// creation1352NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)1353: NewArray(length, state_before)1354, _elt_type(elt_type)1355{}13561357// accessors1358BasicType elt_type() const { return _elt_type; }1359ciType* exact_type() const;1360};136113621363LEAF(NewObjectArray, NewArray)1364private:1365ciKlass* _klass;13661367public:1368// creation1369NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}13701371// accessors1372ciKlass* klass() const { return _klass; }1373ciType* exact_type() const;1374};137513761377LEAF(NewMultiArray, NewArray)1378private:1379ciKlass* _klass;1380Values* _dims;13811382public:1383// creation1384NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {1385ASSERT_VALUES1386}13871388// accessors1389ciKlass* klass() const { return _klass; }1390Values* dims() const { return _dims; }1391int rank() const { return dims()->length(); }13921393// generic1394virtual void input_values_do(ValueVisitor* f) {1395// NOTE: we do not call NewArray::input_values_do since "length"1396// is meaningless for a multi-dimensional array; passing the1397// zeroth element down to NewArray as its length is a bad idea1398// since there will be a copy in the "dims" array which doesn't1399// get updated, and the value must not be traversed twice. Was bug1400// - kbr 4/10/20011401StateSplit::input_values_do(f);1402for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));1403}1404};140514061407BASE(TypeCheck, StateSplit)1408private:1409ciKlass* _klass;1410Value _obj;14111412ciMethod* _profiled_method;1413int _profiled_bci;14141415public:1416// creation1417TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)1418: StateSplit(type, state_before), _klass(klass), _obj(obj),1419_profiled_method(NULL), _profiled_bci(0) {1420ASSERT_VALUES1421set_direct_compare(false);1422}14231424// accessors1425ciKlass* klass() const { return _klass; }1426Value obj() const { return _obj; }1427bool is_loaded() const { return klass() != NULL; }1428bool direct_compare() const { return check_flag(DirectCompareFlag); }14291430// manipulation1431void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }14321433// generic1434virtual bool can_trap() const { return true; }1435virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }14361437// Helpers for MethodData* profiling1438void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }1439void set_profiled_method(ciMethod* method) { _profiled_method = method; }1440void set_profiled_bci(int bci) { _profiled_bci = bci; }1441bool should_profile() const { return check_flag(ProfileMDOFlag); }1442ciMethod* profiled_method() const { return _profiled_method; }1443int profiled_bci() const { return _profiled_bci; }1444};144514461447LEAF(CheckCast, TypeCheck)1448public:1449// creation1450CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)1451: TypeCheck(klass, obj, objectType, state_before) {}14521453void set_incompatible_class_change_check() {1454set_flag(ThrowIncompatibleClassChangeErrorFlag, true);1455}1456bool is_incompatible_class_change_check() const {1457return check_flag(ThrowIncompatibleClassChangeErrorFlag);1458}1459void set_invokespecial_receiver_check() {1460set_flag(InvokeSpecialReceiverCheckFlag, true);1461}1462bool is_invokespecial_receiver_check() const {1463return check_flag(InvokeSpecialReceiverCheckFlag);1464}14651466virtual bool needs_exception_state() const {1467return !is_invokespecial_receiver_check();1468}14691470ciType* declared_type() const;1471};147214731474LEAF(InstanceOf, TypeCheck)1475public:1476// creation1477InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}14781479virtual bool needs_exception_state() const { return false; }1480};148114821483BASE(AccessMonitor, StateSplit)1484private:1485Value _obj;1486int _monitor_no;14871488public:1489// creation1490AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)1491: StateSplit(illegalType, state_before)1492, _obj(obj)1493, _monitor_no(monitor_no)1494{1495set_needs_null_check(true);1496ASSERT_VALUES1497}14981499// accessors1500Value obj() const { return _obj; }1501int monitor_no() const { return _monitor_no; }15021503// generic1504virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }1505};150615071508LEAF(MonitorEnter, AccessMonitor)1509public:1510// creation1511MonitorEnter(Value obj, int monitor_no, ValueStack* state_before)1512: AccessMonitor(obj, monitor_no, state_before)1513{1514ASSERT_VALUES1515}15161517// generic1518virtual bool can_trap() const { return true; }1519};152015211522LEAF(MonitorExit, AccessMonitor)1523public:1524// creation1525MonitorExit(Value obj, int monitor_no)1526: AccessMonitor(obj, monitor_no, NULL)1527{1528ASSERT_VALUES1529}1530};153115321533LEAF(Intrinsic, StateSplit)1534private:1535vmIntrinsics::ID _id;1536Values* _args;1537Value _recv;1538ArgsNonNullState _nonnull_state;15391540public:1541// preserves_state can be set to true for Intrinsics1542// which are guaranteed to preserve register state across any slow1543// cases; setting it to true does not mean that the Intrinsic can1544// not trap, only that if we continue execution in the same basic1545// block after the Intrinsic, all of the registers are intact. This1546// allows load elimination and common expression elimination to be1547// performed across the Intrinsic. The default value is false.1548Intrinsic(ValueType* type,1549vmIntrinsics::ID id,1550Values* args,1551bool has_receiver,1552ValueStack* state_before,1553bool preserves_state,1554bool cantrap = true)1555: StateSplit(type, state_before)1556, _id(id)1557, _args(args)1558, _recv(NULL)1559{1560assert(args != NULL, "args must exist");1561ASSERT_VALUES1562set_flag(PreservesStateFlag, preserves_state);1563set_flag(CanTrapFlag, cantrap);1564if (has_receiver) {1565_recv = argument_at(0);1566}1567set_needs_null_check(has_receiver);15681569// some intrinsics can't trap, so don't force them to be pinned1570if (!can_trap() && !vmIntrinsics::should_be_pinned(_id)) {1571unpin(PinStateSplitConstructor);1572}1573}15741575// accessors1576vmIntrinsics::ID id() const { return _id; }1577int number_of_arguments() const { return _args->length(); }1578Value argument_at(int i) const { return _args->at(i); }15791580bool has_receiver() const { return (_recv != NULL); }1581Value receiver() const { assert(has_receiver(), "must have receiver"); return _recv; }1582bool preserves_state() const { return check_flag(PreservesStateFlag); }15831584bool arg_needs_null_check(int i) const {1585return _nonnull_state.arg_needs_null_check(i);1586}15871588void set_arg_needs_null_check(int i, bool check) {1589_nonnull_state.set_arg_needs_null_check(i, check);1590}15911592// generic1593virtual bool can_trap() const { return check_flag(CanTrapFlag); }1594virtual void input_values_do(ValueVisitor* f) {1595StateSplit::input_values_do(f);1596for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));1597}1598};159916001601class LIR_List;16021603LEAF(BlockBegin, StateSplit)1604private:1605int _block_id; // the unique block id1606int _bci; // start-bci of block1607int _depth_first_number; // number of this block in a depth-first ordering1608int _linear_scan_number; // number of this block in linear-scan ordering1609int _dominator_depth;1610int _loop_depth; // the loop nesting level of this block1611int _loop_index; // number of the innermost loop of this block1612int _flags; // the flags associated with this block16131614// fields used by BlockListBuilder1615int _total_preds; // number of predecessors found by BlockListBuilder1616BitMap _stores_to_locals; // bit is set when a local variable is stored in the block16171618// SSA specific fields: (factor out later)1619BlockList _successors; // the successors of this block1620BlockList _predecessors; // the predecessors of this block1621BlockList _dominates; // list of blocks that are dominated by this block1622BlockBegin* _dominator; // the dominator of this block1623// SSA specific ends1624BlockEnd* _end; // the last instruction of this block1625BlockList _exception_handlers; // the exception handlers potentially invoked by this block1626ValueStackStack* _exception_states; // only for xhandler entries: states of all instructions that have an edge to this xhandler1627int _exception_handler_pco; // if this block is the start of an exception handler,1628// this records the PC offset in the assembly code of the1629// first instruction in this block1630Label _label; // the label associated with this block1631LIR_List* _lir; // the low level intermediate representation for this block16321633BitMap _live_in; // set of live LIR_Opr registers at entry to this block1634BitMap _live_out; // set of live LIR_Opr registers at exit from this block1635BitMap _live_gen; // set of registers used before any redefinition in this block1636BitMap _live_kill; // set of registers defined in this block16371638BitMap _fpu_register_usage;1639intArray* _fpu_stack_state; // For x86 FPU code generation with UseLinearScan1640int _first_lir_instruction_id; // ID of first LIR instruction in this block1641int _last_lir_instruction_id; // ID of last LIR instruction in this block16421643void iterate_preorder (boolArray& mark, BlockClosure* closure);1644void iterate_postorder(boolArray& mark, BlockClosure* closure);16451646friend class SuxAndWeightAdjuster;16471648public:1649void* operator new(size_t size) throw() {1650Compilation* c = Compilation::current();1651void* res = c->arena()->Amalloc(size);1652((BlockBegin*)res)->_id = c->get_next_id();1653((BlockBegin*)res)->_block_id = c->get_next_block_id();1654return res;1655}16561657// initialization/counting1658static int number_of_blocks() {1659return Compilation::current()->number_of_blocks();1660}16611662// creation1663BlockBegin(int bci)1664: StateSplit(illegalType)1665, _bci(bci)1666, _depth_first_number(-1)1667, _linear_scan_number(-1)1668, _loop_depth(0)1669, _flags(0)1670, _dominator_depth(-1)1671, _dominator(NULL)1672, _end(NULL)1673, _predecessors(2)1674, _successors(2)1675, _dominates(2)1676, _exception_handlers(1)1677, _exception_states(NULL)1678, _exception_handler_pco(-1)1679, _lir(NULL)1680, _loop_index(-1)1681, _live_in()1682, _live_out()1683, _live_gen()1684, _live_kill()1685, _fpu_register_usage()1686, _fpu_stack_state(NULL)1687, _first_lir_instruction_id(-1)1688, _last_lir_instruction_id(-1)1689, _total_preds(0)1690, _stores_to_locals()1691{1692_block = this;1693#ifndef PRODUCT1694set_printable_bci(bci);1695#endif1696}16971698// accessors1699int block_id() const { return _block_id; }1700int bci() const { return _bci; }1701BlockList* successors() { return &_successors; }1702BlockList* dominates() { return &_dominates; }1703BlockBegin* dominator() const { return _dominator; }1704int loop_depth() const { return _loop_depth; }1705int dominator_depth() const { return _dominator_depth; }1706int depth_first_number() const { return _depth_first_number; }1707int linear_scan_number() const { return _linear_scan_number; }1708BlockEnd* end() const { return _end; }1709Label* label() { return &_label; }1710LIR_List* lir() const { return _lir; }1711int exception_handler_pco() const { return _exception_handler_pco; }1712BitMap& live_in() { return _live_in; }1713BitMap& live_out() { return _live_out; }1714BitMap& live_gen() { return _live_gen; }1715BitMap& live_kill() { return _live_kill; }1716BitMap& fpu_register_usage() { return _fpu_register_usage; }1717intArray* fpu_stack_state() const { return _fpu_stack_state; }1718int first_lir_instruction_id() const { return _first_lir_instruction_id; }1719int last_lir_instruction_id() const { return _last_lir_instruction_id; }1720int total_preds() const { return _total_preds; }1721BitMap& stores_to_locals() { return _stores_to_locals; }17221723// manipulation1724void set_dominator(BlockBegin* dom) { _dominator = dom; }1725void set_loop_depth(int d) { _loop_depth = d; }1726void set_dominator_depth(int d) { _dominator_depth = d; }1727void set_depth_first_number(int dfn) { _depth_first_number = dfn; }1728void set_linear_scan_number(int lsn) { _linear_scan_number = lsn; }1729void set_end(BlockEnd* end);1730void clear_end();1731void disconnect_from_graph();1732static void disconnect_edge(BlockBegin* from, BlockBegin* to);1733BlockBegin* insert_block_between(BlockBegin* sux);1734void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);1735void set_lir(LIR_List* lir) { _lir = lir; }1736void set_exception_handler_pco(int pco) { _exception_handler_pco = pco; }1737void set_live_in (BitMap map) { _live_in = map; }1738void set_live_out (BitMap map) { _live_out = map; }1739void set_live_gen (BitMap map) { _live_gen = map; }1740void set_live_kill (BitMap map) { _live_kill = map; }1741void set_fpu_register_usage(BitMap map) { _fpu_register_usage = map; }1742void set_fpu_stack_state(intArray* state) { _fpu_stack_state = state; }1743void set_first_lir_instruction_id(int id) { _first_lir_instruction_id = id; }1744void set_last_lir_instruction_id(int id) { _last_lir_instruction_id = id; }1745void increment_total_preds(int n = 1) { _total_preds += n; }1746void init_stores_to_locals(int locals_count) { _stores_to_locals = BitMap(locals_count); _stores_to_locals.clear(); }17471748// generic1749virtual void state_values_do(ValueVisitor* f);17501751// successors and predecessors1752int number_of_sux() const;1753BlockBegin* sux_at(int i) const;1754void add_successor(BlockBegin* sux);1755void remove_successor(BlockBegin* pred);1756bool is_successor(BlockBegin* sux) const { return _successors.contains(sux); }17571758void add_predecessor(BlockBegin* pred);1759void remove_predecessor(BlockBegin* pred);1760bool is_predecessor(BlockBegin* pred) const { return _predecessors.contains(pred); }1761int number_of_preds() const { return _predecessors.length(); }1762BlockBegin* pred_at(int i) const { return _predecessors[i]; }17631764// exception handlers potentially invoked by this block1765void add_exception_handler(BlockBegin* b);1766bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }1767int number_of_exception_handlers() const { return _exception_handlers.length(); }1768BlockBegin* exception_handler_at(int i) const { return _exception_handlers.at(i); }17691770// states of the instructions that have an edge to this exception handler1771int number_of_exception_states() { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); }1772ValueStack* exception_state_at(int idx) const { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }1773int add_exception_state(ValueStack* state);17741775// flags1776enum Flag {1777no_flag = 0,1778std_entry_flag = 1 << 0,1779osr_entry_flag = 1 << 1,1780exception_entry_flag = 1 << 2,1781subroutine_entry_flag = 1 << 3,1782backward_branch_target_flag = 1 << 4,1783is_on_work_list_flag = 1 << 5,1784was_visited_flag = 1 << 6,1785parser_loop_header_flag = 1 << 7, // set by parser to identify blocks where phi functions can not be created on demand1786critical_edge_split_flag = 1 << 8, // set for all blocks that are introduced when critical edges are split1787linear_scan_loop_header_flag = 1 << 9, // set during loop-detection for LinearScan1788linear_scan_loop_end_flag = 1 << 10, // set during loop-detection for LinearScan1789donot_eliminate_range_checks = 1 << 11 // Should be try to eliminate range checks in this block1790};17911792void set(Flag f) { _flags |= f; }1793void clear(Flag f) { _flags &= ~f; }1794bool is_set(Flag f) const { return (_flags & f) != 0; }1795bool is_entry_block() const {1796const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;1797return (_flags & entry_mask) != 0;1798}17991800// iteration1801void iterate_preorder (BlockClosure* closure);1802void iterate_postorder (BlockClosure* closure);18031804void block_values_do(ValueVisitor* f);18051806// loops1807void set_loop_index(int ix) { _loop_index = ix; }1808int loop_index() const { return _loop_index; }18091810// merging1811bool try_merge(ValueStack* state); // try to merge states at block begin1812void merge(ValueStack* state) { bool b = try_merge(state); assert(b, "merge failed"); }18131814// debugging1815void print_block() PRODUCT_RETURN;1816void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;1817};181818191820BASE(BlockEnd, StateSplit)1821private:1822BlockList* _sux;18231824protected:1825BlockList* sux() const { return _sux; }18261827void set_sux(BlockList* sux) {1828#ifdef ASSERT1829assert(sux != NULL, "sux must exist");1830for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist");1831#endif1832_sux = sux;1833}18341835public:1836// creation1837BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)1838: StateSplit(type, state_before)1839, _sux(NULL)1840{1841set_flag(IsSafepointFlag, is_safepoint);1842}18431844// accessors1845bool is_safepoint() const { return check_flag(IsSafepointFlag); }1846// For compatibility with old code, for new code use block()1847BlockBegin* begin() const { return _block; }18481849// manipulation1850void set_begin(BlockBegin* begin);18511852// successors1853int number_of_sux() const { return _sux != NULL ? _sux->length() : 0; }1854BlockBegin* sux_at(int i) const { return _sux->at(i); }1855BlockBegin* default_sux() const { return sux_at(number_of_sux() - 1); }1856BlockBegin** addr_sux_at(int i) const { return _sux->adr_at(i); }1857int sux_index(BlockBegin* sux) const { return _sux->find(sux); }1858void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);1859};186018611862LEAF(Goto, BlockEnd)1863public:1864enum Direction {1865none, // Just a regular goto1866taken, not_taken // Goto produced from If1867};1868private:1869ciMethod* _profiled_method;1870int _profiled_bci;1871Direction _direction;1872public:1873// creation1874Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false)1875: BlockEnd(illegalType, state_before, is_safepoint)1876, _direction(none)1877, _profiled_method(NULL)1878, _profiled_bci(0) {1879BlockList* s = new BlockList(1);1880s->append(sux);1881set_sux(s);1882}18831884Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint)1885, _direction(none)1886, _profiled_method(NULL)1887, _profiled_bci(0) {1888BlockList* s = new BlockList(1);1889s->append(sux);1890set_sux(s);1891}18921893bool should_profile() const { return check_flag(ProfileMDOFlag); }1894ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches1895int profiled_bci() const { return _profiled_bci; }1896Direction direction() const { return _direction; }18971898void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }1899void set_profiled_method(ciMethod* method) { _profiled_method = method; }1900void set_profiled_bci(int bci) { _profiled_bci = bci; }1901void set_direction(Direction d) { _direction = d; }1902};19031904#ifdef ASSERT1905LEAF(Assert, Instruction)1906private:1907Value _x;1908Condition _cond;1909Value _y;1910char *_message;19111912public:1913// creation1914// unordered_is_true is valid for float/double compares only1915Assert(Value x, Condition cond, bool unordered_is_true, Value y);19161917// accessors1918Value x() const { return _x; }1919Condition cond() const { return _cond; }1920bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }1921Value y() const { return _y; }1922const char *message() const { return _message; }19231924// generic1925virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); }1926};1927#endif19281929LEAF(RangeCheckPredicate, StateSplit)1930private:1931Value _x;1932Condition _cond;1933Value _y;19341935void check_state();19361937public:1938// creation1939// unordered_is_true is valid for float/double compares only1940RangeCheckPredicate(Value x, Condition cond, bool unordered_is_true, Value y, ValueStack* state) : StateSplit(illegalType)1941, _x(x)1942, _cond(cond)1943, _y(y)1944{1945ASSERT_VALUES1946set_flag(UnorderedIsTrueFlag, unordered_is_true);1947assert(x->type()->tag() == y->type()->tag(), "types must match");1948this->set_state(state);1949check_state();1950}19511952// Always deoptimize1953RangeCheckPredicate(ValueStack* state) : StateSplit(illegalType)1954{1955this->set_state(state);1956_x = _y = NULL;1957check_state();1958}19591960// accessors1961Value x() const { return _x; }1962Condition cond() const { return _cond; }1963bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }1964Value y() const { return _y; }19651966void always_fail() { _x = _y = NULL; }19671968// generic1969virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }1970HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())1971};19721973LEAF(If, BlockEnd)1974private:1975Value _x;1976Condition _cond;1977Value _y;1978ciMethod* _profiled_method;1979int _profiled_bci; // Canonicalizer may alter bci of If node1980bool _swapped; // Is the order reversed with respect to the original If in the1981// bytecode stream?1982public:1983// creation1984// unordered_is_true is valid for float/double compares only1985If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)1986: BlockEnd(illegalType, state_before, is_safepoint)1987, _x(x)1988, _cond(cond)1989, _y(y)1990, _profiled_method(NULL)1991, _profiled_bci(0)1992, _swapped(false)1993{1994ASSERT_VALUES1995set_flag(UnorderedIsTrueFlag, unordered_is_true);1996assert(x->type()->tag() == y->type()->tag(), "types must match");1997BlockList* s = new BlockList(2);1998s->append(tsux);1999s->append(fsux);2000set_sux(s);2001}20022003// accessors2004Value x() const { return _x; }2005Condition cond() const { return _cond; }2006bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }2007Value y() const { return _y; }2008BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }2009BlockBegin* tsux() const { return sux_for(true); }2010BlockBegin* fsux() const { return sux_for(false); }2011BlockBegin* usux() const { return sux_for(unordered_is_true()); }2012bool should_profile() const { return check_flag(ProfileMDOFlag); }2013ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches2014int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered2015bool is_swapped() const { return _swapped; }20162017// manipulation2018void swap_operands() {2019Value t = _x; _x = _y; _y = t;2020_cond = mirror(_cond);2021}20222023void swap_sux() {2024assert(number_of_sux() == 2, "wrong number of successors");2025BlockList* s = sux();2026BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);2027_cond = negate(_cond);2028set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));2029}20302031void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }2032void set_profiled_method(ciMethod* method) { _profiled_method = method; }2033void set_profiled_bci(int bci) { _profiled_bci = bci; }2034void set_swapped(bool value) { _swapped = value; }2035// generic2036virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }2037};203820392040LEAF(IfInstanceOf, BlockEnd)2041private:2042ciKlass* _klass;2043Value _obj;2044bool _test_is_instance; // jump if instance2045int _instanceof_bci;20462047public:2048IfInstanceOf(ciKlass* klass, Value obj, bool test_is_instance, int instanceof_bci, BlockBegin* tsux, BlockBegin* fsux)2049: BlockEnd(illegalType, NULL, false) // temporary set to false2050, _klass(klass)2051, _obj(obj)2052, _test_is_instance(test_is_instance)2053, _instanceof_bci(instanceof_bci)2054{2055ASSERT_VALUES2056assert(instanceof_bci >= 0, "illegal bci");2057BlockList* s = new BlockList(2);2058s->append(tsux);2059s->append(fsux);2060set_sux(s);2061}20622063// accessors2064//2065// Note 1: If test_is_instance() is true, IfInstanceOf tests if obj *is* an2066// instance of klass; otherwise it tests if it is *not* and instance2067// of klass.2068//2069// Note 2: IfInstanceOf instructions are created by combining an InstanceOf2070// and an If instruction. The IfInstanceOf bci() corresponds to the2071// bci that the If would have had; the (this->) instanceof_bci() is2072// the bci of the original InstanceOf instruction.2073ciKlass* klass() const { return _klass; }2074Value obj() const { return _obj; }2075int instanceof_bci() const { return _instanceof_bci; }2076bool test_is_instance() const { return _test_is_instance; }2077BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }2078BlockBegin* tsux() const { return sux_for(true); }2079BlockBegin* fsux() const { return sux_for(false); }20802081// manipulation2082void swap_sux() {2083assert(number_of_sux() == 2, "wrong number of successors");2084BlockList* s = sux();2085BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);2086_test_is_instance = !_test_is_instance;2087}20882089// generic2090virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_obj); }2091};209220932094BASE(Switch, BlockEnd)2095private:2096Value _tag;20972098public:2099// creation2100Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)2101: BlockEnd(illegalType, state_before, is_safepoint)2102, _tag(tag) {2103ASSERT_VALUES2104set_sux(sux);2105}21062107// accessors2108Value tag() const { return _tag; }2109int length() const { return number_of_sux() - 1; }21102111virtual bool needs_exception_state() const { return false; }21122113// generic2114virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_tag); }2115};211621172118LEAF(TableSwitch, Switch)2119private:2120int _lo_key;21212122public:2123// creation2124TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)2125: Switch(tag, sux, state_before, is_safepoint)2126, _lo_key(lo_key) { assert(_lo_key <= hi_key(), "integer overflow"); }21272128// accessors2129int lo_key() const { return _lo_key; }2130int hi_key() const { return _lo_key + (length() - 1); }2131};213221332134LEAF(LookupSwitch, Switch)2135private:2136intArray* _keys;21372138public:2139// creation2140LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)2141: Switch(tag, sux, state_before, is_safepoint)2142, _keys(keys) {2143assert(keys != NULL, "keys must exist");2144assert(keys->length() == length(), "sux & keys have incompatible lengths");2145}21462147// accessors2148int key_at(int i) const { return _keys->at(i); }2149};215021512152LEAF(Return, BlockEnd)2153private:2154Value _result;21552156public:2157// creation2158Return(Value result) :2159BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true),2160_result(result) {}21612162// accessors2163Value result() const { return _result; }2164bool has_result() const { return result() != NULL; }21652166// generic2167virtual void input_values_do(ValueVisitor* f) {2168BlockEnd::input_values_do(f);2169if (has_result()) f->visit(&_result);2170}2171};217221732174LEAF(Throw, BlockEnd)2175private:2176Value _exception;21772178public:2179// creation2180Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {2181ASSERT_VALUES2182}21832184// accessors2185Value exception() const { return _exception; }21862187// generic2188virtual bool can_trap() const { return true; }2189virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_exception); }2190};219121922193LEAF(Base, BlockEnd)2194public:2195// creation2196Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, NULL, false) {2197assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged");2198assert(osr_entry == NULL || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged");2199BlockList* s = new BlockList(2);2200if (osr_entry != NULL) s->append(osr_entry);2201s->append(std_entry); // must be default sux!2202set_sux(s);2203}22042205// accessors2206BlockBegin* std_entry() const { return default_sux(); }2207BlockBegin* osr_entry() const { return number_of_sux() < 2 ? NULL : sux_at(0); }2208};220922102211LEAF(OsrEntry, Instruction)2212public:2213// creation2214#ifdef _LP642215OsrEntry() : Instruction(longType) { pin(); }2216#else2217OsrEntry() : Instruction(intType) { pin(); }2218#endif22192220// generic2221virtual void input_values_do(ValueVisitor* f) { }2222};222322242225// Models the incoming exception at a catch site2226LEAF(ExceptionObject, Instruction)2227public:2228// creation2229ExceptionObject() : Instruction(objectType) {2230pin();2231}22322233// generic2234virtual void input_values_do(ValueVisitor* f) { }2235};223622372238// Models needed rounding for floating-point values on Intel.2239// Currently only used to represent rounding of double-precision2240// values stored into local variables, but could be used to model2241// intermediate rounding of single-precision values as well.2242LEAF(RoundFP, Instruction)2243private:2244Value _input; // floating-point value to be rounded22452246public:2247RoundFP(Value input)2248: Instruction(input->type()) // Note: should not be used for constants2249, _input(input)2250{2251ASSERT_VALUES2252}22532254// accessors2255Value input() const { return _input; }22562257// generic2258virtual void input_values_do(ValueVisitor* f) { f->visit(&_input); }2259};226022612262BASE(UnsafeOp, Instruction)2263private:2264BasicType _basic_type; // ValueType can not express byte-sized integers22652266protected:2267// creation2268UnsafeOp(BasicType basic_type, bool is_put)2269: Instruction(is_put ? voidType : as_ValueType(basic_type))2270, _basic_type(basic_type)2271{2272//Note: Unsafe ops are not not guaranteed to throw NPE.2273// Convservatively, Unsafe operations must be pinned though we could be2274// looser about this if we wanted to..2275pin();2276}22772278public:2279// accessors2280BasicType basic_type() { return _basic_type; }22812282// generic2283virtual void input_values_do(ValueVisitor* f) { }2284};228522862287BASE(UnsafeRawOp, UnsafeOp)2288private:2289Value _base; // Base address (a Java long)2290Value _index; // Index if computed by optimizer; initialized to NULL2291int _log2_scale; // Scale factor: 0, 1, 2, or 3.2292// Indicates log2 of number of bytes (1, 2, 4, or 8)2293// to scale index by.22942295protected:2296UnsafeRawOp(BasicType basic_type, Value addr, bool is_put)2297: UnsafeOp(basic_type, is_put)2298, _base(addr)2299, _index(NULL)2300, _log2_scale(0)2301{2302// Can not use ASSERT_VALUES because index may be NULL2303assert(addr != NULL && addr->type()->is_long(), "just checking");2304}23052306UnsafeRawOp(BasicType basic_type, Value base, Value index, int log2_scale, bool is_put)2307: UnsafeOp(basic_type, is_put)2308, _base(base)2309, _index(index)2310, _log2_scale(log2_scale)2311{2312}23132314public:2315// accessors2316Value base() { return _base; }2317Value index() { return _index; }2318bool has_index() { return (_index != NULL); }2319int log2_scale() { return _log2_scale; }23202321// setters2322void set_base (Value base) { _base = base; }2323void set_index(Value index) { _index = index; }2324void set_log2_scale(int log2_scale) { _log2_scale = log2_scale; }23252326// generic2327virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f);2328f->visit(&_base);2329if (has_index()) f->visit(&_index); }2330};233123322333LEAF(UnsafeGetRaw, UnsafeRawOp)2334private:2335bool _may_be_unaligned, _is_wide; // For OSREntry23362337public:2338UnsafeGetRaw(BasicType basic_type, Value addr, bool may_be_unaligned, bool is_wide = false)2339: UnsafeRawOp(basic_type, addr, false) {2340_may_be_unaligned = may_be_unaligned;2341_is_wide = is_wide;2342}23432344UnsafeGetRaw(BasicType basic_type, Value base, Value index, int log2_scale, bool may_be_unaligned, bool is_wide = false)2345: UnsafeRawOp(basic_type, base, index, log2_scale, false) {2346_may_be_unaligned = may_be_unaligned;2347_is_wide = is_wide;2348}23492350bool may_be_unaligned() { return _may_be_unaligned; }2351bool is_wide() { return _is_wide; }2352};235323542355LEAF(UnsafePutRaw, UnsafeRawOp)2356private:2357Value _value; // Value to be stored23582359public:2360UnsafePutRaw(BasicType basic_type, Value addr, Value value)2361: UnsafeRawOp(basic_type, addr, true)2362, _value(value)2363{2364assert(value != NULL, "just checking");2365ASSERT_VALUES2366}23672368UnsafePutRaw(BasicType basic_type, Value base, Value index, int log2_scale, Value value)2369: UnsafeRawOp(basic_type, base, index, log2_scale, true)2370, _value(value)2371{2372assert(value != NULL, "just checking");2373ASSERT_VALUES2374}23752376// accessors2377Value value() { return _value; }23782379// generic2380virtual void input_values_do(ValueVisitor* f) { UnsafeRawOp::input_values_do(f);2381f->visit(&_value); }2382};238323842385BASE(UnsafeObjectOp, UnsafeOp)2386private:2387Value _object; // Object to be fetched from or mutated2388Value _offset; // Offset within object2389bool _is_volatile; // true if volatile - dl/JSR1662390public:2391UnsafeObjectOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile)2392: UnsafeOp(basic_type, is_put), _object(object), _offset(offset), _is_volatile(is_volatile)2393{2394}23952396// accessors2397Value object() { return _object; }2398Value offset() { return _offset; }2399bool is_volatile() { return _is_volatile; }2400// generic2401virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f);2402f->visit(&_object);2403f->visit(&_offset); }2404};240524062407LEAF(UnsafeGetObject, UnsafeObjectOp)2408public:2409UnsafeGetObject(BasicType basic_type, Value object, Value offset, bool is_volatile)2410: UnsafeObjectOp(basic_type, object, offset, false, is_volatile)2411{2412ASSERT_VALUES2413}2414};241524162417LEAF(UnsafePutObject, UnsafeObjectOp)2418private:2419Value _value; // Value to be stored2420public:2421UnsafePutObject(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile)2422: UnsafeObjectOp(basic_type, object, offset, true, is_volatile)2423, _value(value)2424{2425ASSERT_VALUES2426}24272428// accessors2429Value value() { return _value; }24302431// generic2432virtual void input_values_do(ValueVisitor* f) { UnsafeObjectOp::input_values_do(f);2433f->visit(&_value); }2434};24352436LEAF(UnsafeGetAndSetObject, UnsafeObjectOp)2437private:2438Value _value; // Value to be stored2439bool _is_add;2440public:2441UnsafeGetAndSetObject(BasicType basic_type, Value object, Value offset, Value value, bool is_add)2442: UnsafeObjectOp(basic_type, object, offset, false, false)2443, _value(value)2444, _is_add(is_add)2445{2446ASSERT_VALUES2447}24482449// accessors2450bool is_add() const { return _is_add; }2451Value value() { return _value; }24522453// generic2454virtual void input_values_do(ValueVisitor* f) { UnsafeObjectOp::input_values_do(f);2455f->visit(&_value); }2456};24572458BASE(UnsafePrefetch, UnsafeObjectOp)2459public:2460UnsafePrefetch(Value object, Value offset)2461: UnsafeObjectOp(T_VOID, object, offset, false, false)2462{2463}2464};246524662467LEAF(UnsafePrefetchRead, UnsafePrefetch)2468public:2469UnsafePrefetchRead(Value object, Value offset)2470: UnsafePrefetch(object, offset)2471{2472ASSERT_VALUES2473}2474};247524762477LEAF(UnsafePrefetchWrite, UnsafePrefetch)2478public:2479UnsafePrefetchWrite(Value object, Value offset)2480: UnsafePrefetch(object, offset)2481{2482ASSERT_VALUES2483}2484};24852486LEAF(ProfileCall, Instruction)2487private:2488ciMethod* _method;2489int _bci_of_invoke;2490ciMethod* _callee; // the method that is called at the given bci2491Value _recv;2492ciKlass* _known_holder;2493Values* _obj_args; // arguments for type profiling2494ArgsNonNullState _nonnull_state; // Do we know whether some arguments are never null?2495bool _inlined; // Are we profiling a call that is inlined24962497public:2498ProfileCall(ciMethod* method, int bci, ciMethod* callee, Value recv, ciKlass* known_holder, Values* obj_args, bool inlined)2499: Instruction(voidType)2500, _method(method)2501, _bci_of_invoke(bci)2502, _callee(callee)2503, _recv(recv)2504, _known_holder(known_holder)2505, _obj_args(obj_args)2506, _inlined(inlined)2507{2508// The ProfileCall has side-effects and must occur precisely where located2509pin();2510}25112512ciMethod* method() const { return _method; }2513int bci_of_invoke() const { return _bci_of_invoke; }2514ciMethod* callee() const { return _callee; }2515Value recv() const { return _recv; }2516ciKlass* known_holder() const { return _known_holder; }2517int nb_profiled_args() const { return _obj_args == NULL ? 0 : _obj_args->length(); }2518Value profiled_arg_at(int i) const { return _obj_args->at(i); }2519bool arg_needs_null_check(int i) const {2520return _nonnull_state.arg_needs_null_check(i);2521}2522bool inlined() const { return _inlined; }25232524void set_arg_needs_null_check(int i, bool check) {2525_nonnull_state.set_arg_needs_null_check(i, check);2526}25272528virtual void input_values_do(ValueVisitor* f) {2529if (_recv != NULL) {2530f->visit(&_recv);2531}2532for (int i = 0; i < nb_profiled_args(); i++) {2533f->visit(_obj_args->adr_at(i));2534}2535}2536};25372538LEAF(ProfileReturnType, Instruction)2539private:2540ciMethod* _method;2541ciMethod* _callee;2542int _bci_of_invoke;2543Value _ret;25442545public:2546ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)2547: Instruction(voidType)2548, _method(method)2549, _callee(callee)2550, _bci_of_invoke(bci)2551, _ret(ret)2552{2553set_needs_null_check(true);2554// The ProfileType has side-effects and must occur precisely where located2555pin();2556}25572558ciMethod* method() const { return _method; }2559ciMethod* callee() const { return _callee; }2560int bci_of_invoke() const { return _bci_of_invoke; }2561Value ret() const { return _ret; }25622563virtual void input_values_do(ValueVisitor* f) {2564if (_ret != NULL) {2565f->visit(&_ret);2566}2567}2568};25692570// Call some C runtime function that doesn't safepoint,2571// optionally passing the current thread as the first argument.2572LEAF(RuntimeCall, Instruction)2573private:2574const char* _entry_name;2575address _entry;2576Values* _args;2577bool _pass_thread; // Pass the JavaThread* as an implicit first argument25782579public:2580RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)2581: Instruction(type)2582, _entry(entry)2583, _args(args)2584, _entry_name(entry_name)2585, _pass_thread(pass_thread) {2586ASSERT_VALUES2587pin();2588}25892590const char* entry_name() const { return _entry_name; }2591address entry() const { return _entry; }2592int number_of_arguments() const { return _args->length(); }2593Value argument_at(int i) const { return _args->at(i); }2594bool pass_thread() const { return _pass_thread; }25952596virtual void input_values_do(ValueVisitor* f) {2597for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));2598}2599};26002601// Use to trip invocation counter of an inlined method26022603LEAF(ProfileInvoke, Instruction)2604private:2605ciMethod* _inlinee;2606ValueStack* _state;26072608public:2609ProfileInvoke(ciMethod* inlinee, ValueStack* state)2610: Instruction(voidType)2611, _inlinee(inlinee)2612, _state(state)2613{2614// The ProfileInvoke has side-effects and must occur precisely where located QQQ???2615pin();2616}26172618ciMethod* inlinee() { return _inlinee; }2619ValueStack* state() { return _state; }2620virtual void input_values_do(ValueVisitor*) {}2621virtual void state_values_do(ValueVisitor*);2622};26232624LEAF(MemBar, Instruction)2625private:2626LIR_Code _code;26272628public:2629MemBar(LIR_Code code)2630: Instruction(voidType)2631, _code(code)2632{2633pin();2634}26352636LIR_Code code() { return _code; }26372638virtual void input_values_do(ValueVisitor*) {}2639};26402641class BlockPair: public CompilationResourceObj {2642private:2643BlockBegin* _from;2644BlockBegin* _to;2645public:2646BlockPair(BlockBegin* from, BlockBegin* to): _from(from), _to(to) {}2647BlockBegin* from() const { return _from; }2648BlockBegin* to() const { return _to; }2649bool is_same(BlockBegin* from, BlockBegin* to) const { return _from == from && _to == to; }2650bool is_same(BlockPair* p) const { return _from == p->from() && _to == p->to(); }2651void set_to(BlockBegin* b) { _to = b; }2652void set_from(BlockBegin* b) { _from = b; }2653};265426552656define_array(BlockPairArray, BlockPair*)2657define_stack(BlockPairList, BlockPairArray)265826592660inline int BlockBegin::number_of_sux() const { assert(_end == NULL || _end->number_of_sux() == _successors.length(), "mismatch"); return _successors.length(); }2661inline BlockBegin* BlockBegin::sux_at(int i) const { assert(_end == NULL || _end->sux_at(i) == _successors.at(i), "mismatch"); return _successors.at(i); }2662inline void BlockBegin::add_successor(BlockBegin* sux) { assert(_end == NULL, "Would create mismatch with successors of BlockEnd"); _successors.append(sux); }26632664#undef ASSERT_VALUES26652666#endif // SHARE_VM_C1_C1_INSTRUCTION_HPP266726682669