Path: blob/master/src/hotspot/share/c1/c1_Instruction.hpp
40930 views
/*1* Copyright (c) 1999, 2021, 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_C1_C1_INSTRUCTION_HPP25#define SHARE_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 Switch;90class TableSwitch;91class LookupSwitch;92class Return;93class Throw;94class Base;95class RoundFP;96class UnsafeOp;97class UnsafeRawOp;98class UnsafeGetRaw;99class UnsafePutRaw;100class UnsafeObjectOp;101class UnsafeGetObject;102class UnsafePutObject;103class UnsafeGetAndSetObject;104class ProfileCall;105class ProfileReturnType;106class ProfileInvoke;107class RuntimeCall;108class MemBar;109class RangeCheckPredicate;110#ifdef ASSERT111class Assert;112#endif113114// A Value is a reference to the instruction creating the value115typedef Instruction* Value;116typedef GrowableArray<Value> Values;117typedef GrowableArray<ValueStack*> ValueStackStack;118119// BlockClosure is the base class for block traversal/iteration.120121class BlockClosure: public CompilationResourceObj {122public:123virtual void block_do(BlockBegin* block) = 0;124};125126127// A simple closure class for visiting the values of an Instruction128class ValueVisitor: public StackObj {129public:130virtual void visit(Value* v) = 0;131};132133134// Some array and list classes135typedef GrowableArray<BlockBegin*> BlockBeginArray;136137class BlockList: public GrowableArray<BlockBegin*> {138public:139BlockList(): GrowableArray<BlockBegin*>() {}140BlockList(const int size): GrowableArray<BlockBegin*>(size) {}141BlockList(const int size, BlockBegin* init): GrowableArray<BlockBegin*>(size, size, init) {}142143void iterate_forward(BlockClosure* closure);144void iterate_backward(BlockClosure* closure);145void blocks_do(void f(BlockBegin*));146void values_do(ValueVisitor* f);147void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN;148};149150151// InstructionVisitors provide type-based dispatch for instructions.152// For each concrete Instruction class X, a virtual function do_X is153// provided. Functionality that needs to be implemented for all classes154// (e.g., printing, code generation) is factored out into a specialised155// visitor instead of added to the Instruction classes itself.156157class InstructionVisitor: public StackObj {158public:159virtual void do_Phi (Phi* x) = 0;160virtual void do_Local (Local* x) = 0;161virtual void do_Constant (Constant* x) = 0;162virtual void do_LoadField (LoadField* x) = 0;163virtual void do_StoreField (StoreField* x) = 0;164virtual void do_ArrayLength (ArrayLength* x) = 0;165virtual void do_LoadIndexed (LoadIndexed* x) = 0;166virtual void do_StoreIndexed (StoreIndexed* x) = 0;167virtual void do_NegateOp (NegateOp* x) = 0;168virtual void do_ArithmeticOp (ArithmeticOp* x) = 0;169virtual void do_ShiftOp (ShiftOp* x) = 0;170virtual void do_LogicOp (LogicOp* x) = 0;171virtual void do_CompareOp (CompareOp* x) = 0;172virtual void do_IfOp (IfOp* x) = 0;173virtual void do_Convert (Convert* x) = 0;174virtual void do_NullCheck (NullCheck* x) = 0;175virtual void do_TypeCast (TypeCast* x) = 0;176virtual void do_Invoke (Invoke* x) = 0;177virtual void do_NewInstance (NewInstance* x) = 0;178virtual void do_NewTypeArray (NewTypeArray* x) = 0;179virtual void do_NewObjectArray (NewObjectArray* x) = 0;180virtual void do_NewMultiArray (NewMultiArray* x) = 0;181virtual void do_CheckCast (CheckCast* x) = 0;182virtual void do_InstanceOf (InstanceOf* x) = 0;183virtual void do_MonitorEnter (MonitorEnter* x) = 0;184virtual void do_MonitorExit (MonitorExit* x) = 0;185virtual void do_Intrinsic (Intrinsic* x) = 0;186virtual void do_BlockBegin (BlockBegin* x) = 0;187virtual void do_Goto (Goto* x) = 0;188virtual void do_If (If* x) = 0;189virtual void do_TableSwitch (TableSwitch* x) = 0;190virtual void do_LookupSwitch (LookupSwitch* x) = 0;191virtual void do_Return (Return* x) = 0;192virtual void do_Throw (Throw* x) = 0;193virtual void do_Base (Base* x) = 0;194virtual void do_OsrEntry (OsrEntry* x) = 0;195virtual void do_ExceptionObject(ExceptionObject* x) = 0;196virtual void do_RoundFP (RoundFP* x) = 0;197virtual void do_UnsafeGetRaw (UnsafeGetRaw* x) = 0;198virtual void do_UnsafePutRaw (UnsafePutRaw* x) = 0;199virtual void do_UnsafeGetObject(UnsafeGetObject* x) = 0;200virtual void do_UnsafePutObject(UnsafePutObject* x) = 0;201virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) = 0;202virtual void do_ProfileCall (ProfileCall* x) = 0;203virtual void do_ProfileReturnType (ProfileReturnType* x) = 0;204virtual void do_ProfileInvoke (ProfileInvoke* x) = 0;205virtual void do_RuntimeCall (RuntimeCall* x) = 0;206virtual void do_MemBar (MemBar* x) = 0;207virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0;208#ifdef ASSERT209virtual void do_Assert (Assert* x) = 0;210#endif211};212213214// Hashing support215//216// Note: This hash functions affect the performance217// of ValueMap - make changes carefully!218219#define HASH1(x1 ) ((intx)(x1))220#define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2))221#define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3))222#define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))223224225// The following macros are used to implement instruction-specific hashing.226// By default, each instruction implements hash() and is_equal(Value), used227// for value numbering/common subexpression elimination. The default imple-228// mentation disables value numbering. Each instruction which can be value-229// numbered, should define corresponding hash() and is_equal(Value) functions230// via the macros below. The f arguments specify all the values/op codes, etc.231// that need to be identical for two instructions to be identical.232//233// Note: The default implementation of hash() returns 0 in order to indicate234// that the instruction should not be considered for value numbering.235// The currently used hash functions do not guarantee that never a 0236// is produced. While this is still correct, it may be a performance237// bug (no value numbering for that node). However, this situation is238// so unlikely, that we are not going to handle it specially.239240#define HASHING1(class_name, enabled, f1) \241virtual intx hash() const { \242return (enabled) ? HASH2(name(), f1) : 0; \243} \244virtual bool is_equal(Value v) const { \245if (!(enabled) ) return false; \246class_name* _v = v->as_##class_name(); \247if (_v == NULL ) return false; \248if (f1 != _v->f1) return false; \249return true; \250} \251252253#define HASHING2(class_name, enabled, f1, f2) \254virtual intx hash() const { \255return (enabled) ? HASH3(name(), f1, f2) : 0; \256} \257virtual bool is_equal(Value v) const { \258if (!(enabled) ) return false; \259class_name* _v = v->as_##class_name(); \260if (_v == NULL ) return false; \261if (f1 != _v->f1) return false; \262if (f2 != _v->f2) return false; \263return true; \264} \265266267#define HASHING3(class_name, enabled, f1, f2, f3) \268virtual intx hash() const { \269return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \270} \271virtual bool is_equal(Value v) const { \272if (!(enabled) ) return false; \273class_name* _v = v->as_##class_name(); \274if (_v == NULL ) return false; \275if (f1 != _v->f1) return false; \276if (f2 != _v->f2) return false; \277if (f3 != _v->f3) return false; \278return true; \279} \280281282// The mother of all instructions...283284class Instruction: public CompilationResourceObj {285private:286int _id; // the unique instruction id287#ifndef PRODUCT288int _printable_bci; // the bci of the instruction for printing289#endif290int _use_count; // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1291int _pin_state; // set of PinReason describing the reason for pinning292ValueType* _type; // the instruction value type293Instruction* _next; // the next instruction if any (NULL for BlockEnd instructions)294Instruction* _subst; // the substitution instruction if any295LIR_Opr _operand; // LIR specific information296unsigned int _flags; // Flag bits297298ValueStack* _state_before; // Copy of state with input operands still on stack (or NULL)299ValueStack* _exception_state; // Copy of state for exception handling300XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction301302friend class UseCountComputer;303304void update_exception_state(ValueStack* state);305306protected:307BlockBegin* _block; // Block that contains this instruction308309void set_type(ValueType* type) {310assert(type != NULL, "type must exist");311_type = type;312}313314// Helper class to keep track of which arguments need a null check315class ArgsNonNullState {316private:317int _nonnull_state; // mask identifying which args are nonnull318public:319ArgsNonNullState()320: _nonnull_state(AllBits) {}321322// Does argument number i needs a null check?323bool arg_needs_null_check(int i) const {324// No data is kept for arguments starting at position 33 so325// conservatively assume that they need a null check.326if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {327return is_set_nth_bit(_nonnull_state, i);328}329return true;330}331332// Set whether argument number i needs a null check or not333void set_arg_needs_null_check(int i, bool check) {334if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {335if (check) {336_nonnull_state |= nth_bit(i);337} else {338_nonnull_state &= ~(nth_bit(i));339}340}341}342};343344public:345void* operator new(size_t size) throw() {346Compilation* c = Compilation::current();347void* res = c->arena()->Amalloc(size);348return res;349}350351static const int no_bci = -99;352353enum InstructionFlag {354NeedsNullCheckFlag = 0,355CanTrapFlag,356DirectCompareFlag,357IsEliminatedFlag,358IsSafepointFlag,359IsStaticFlag,360NeedsStoreCheckFlag,361NeedsWriteBarrierFlag,362PreservesStateFlag,363TargetIsFinalFlag,364TargetIsLoadedFlag,365UnorderedIsTrueFlag,366NeedsPatchingFlag,367ThrowIncompatibleClassChangeErrorFlag,368InvokeSpecialReceiverCheckFlag,369ProfileMDOFlag,370IsLinkedInBlockFlag,371NeedsRangeCheckFlag,372InWorkListFlag,373DeoptimizeOnException,374InstructionLastFlag375};376377public:378bool check_flag(InstructionFlag id) const { return (_flags & (1 << id)) != 0; }379void set_flag(InstructionFlag id, bool f) { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); };380381// 'globally' used condition values382enum Condition {383eql, neq, lss, leq, gtr, geq, aeq, beq384};385386// Instructions may be pinned for many reasons and under certain conditions387// with enough knowledge it's possible to safely unpin them.388enum PinReason {389PinUnknown = 1 << 0390, PinExplicitNullCheck = 1 << 3391, PinStackForStateSplit= 1 << 12392, PinStateSplitConstructor= 1 << 13393, PinGlobalValueNumbering= 1 << 14394};395396static Condition mirror(Condition cond);397static Condition negate(Condition cond);398399// initialization400static int number_of_instructions() {401return Compilation::current()->number_of_instructions();402}403404// creation405Instruction(ValueType* type, ValueStack* state_before = NULL, bool type_is_constant = false)406: _id(Compilation::current()->get_next_id()),407#ifndef PRODUCT408_printable_bci(-99),409#endif410_use_count(0)411, _pin_state(0)412, _type(type)413, _next(NULL)414, _subst(NULL)415, _operand(LIR_OprFact::illegalOpr)416, _flags(0)417, _state_before(state_before)418, _exception_handlers(NULL)419, _block(NULL)420{421check_state(state_before);422assert(type != NULL && (!type->is_constant() || type_is_constant), "type must exist");423update_exception_state(_state_before);424}425426// accessors427int id() const { return _id; }428#ifndef PRODUCT429bool has_printable_bci() const { return _printable_bci != -99; }430int printable_bci() const { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }431void set_printable_bci(int bci) { _printable_bci = bci; }432#endif433int dominator_depth();434int use_count() const { return _use_count; }435int pin_state() const { return _pin_state; }436bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; }437ValueType* type() const { return _type; }438BlockBegin *block() const { return _block; }439Instruction* prev(); // use carefully, expensive operation440Instruction* next() const { return _next; }441bool has_subst() const { return _subst != NULL; }442Instruction* subst() { return _subst == NULL ? this : _subst->subst(); }443LIR_Opr operand() const { return _operand; }444445void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); }446bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); }447bool is_linked() const { return check_flag(IsLinkedInBlockFlag); }448bool can_be_linked() { return as_Local() == NULL && as_Phi() == NULL; }449450bool is_null_obj() { return as_Constant() != NULL && type()->as_ObjectType()->constant_value()->is_null_object(); }451452bool has_uses() const { return use_count() > 0; }453ValueStack* state_before() const { return _state_before; }454ValueStack* exception_state() const { return _exception_state; }455virtual bool needs_exception_state() const { return true; }456XHandlers* exception_handlers() const { return _exception_handlers; }457458// manipulation459void pin(PinReason reason) { _pin_state |= reason; }460void pin() { _pin_state |= PinUnknown; }461// DANGEROUS: only used by EliminateStores462void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }463464Instruction* set_next(Instruction* next) {465assert(next->has_printable_bci(), "_printable_bci should have been set");466assert(next != NULL, "must not be NULL");467assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");468assert(next->can_be_linked(), "shouldn't link these instructions into list");469470BlockBegin *block = this->block();471next->_block = block;472473next->set_flag(Instruction::IsLinkedInBlockFlag, true);474_next = next;475return next;476}477478Instruction* set_next(Instruction* next, int bci) {479#ifndef PRODUCT480next->set_printable_bci(bci);481#endif482return set_next(next);483}484485// when blocks are merged486void fixup_block_pointers() {487Instruction *cur = next()->next(); // next()'s block is set in set_next488while (cur && cur->_block != block()) {489cur->_block = block();490cur = cur->next();491}492}493494Instruction *insert_after(Instruction *i) {495Instruction* n = _next;496set_next(i);497i->set_next(n);498return _next;499}500501Instruction *insert_after_same_bci(Instruction *i) {502#ifndef PRODUCT503i->set_printable_bci(printable_bci());504#endif505return insert_after(i);506}507508void set_subst(Instruction* subst) {509assert(subst == NULL ||510type()->base() == subst->type()->base() ||511subst->type()->base() == illegalType, "type can't change");512_subst = subst;513}514void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }515void set_exception_state(ValueStack* s) { check_state(s); _exception_state = s; }516void set_state_before(ValueStack* s) { check_state(s); _state_before = s; }517518// machine-specifics519void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }520void clear_operand() { _operand = LIR_OprFact::illegalOpr; }521522// generic523virtual Instruction* as_Instruction() { return this; } // to satisfy HASHING1 macro524virtual Phi* as_Phi() { return NULL; }525virtual Local* as_Local() { return NULL; }526virtual Constant* as_Constant() { return NULL; }527virtual AccessField* as_AccessField() { return NULL; }528virtual LoadField* as_LoadField() { return NULL; }529virtual StoreField* as_StoreField() { return NULL; }530virtual AccessArray* as_AccessArray() { return NULL; }531virtual ArrayLength* as_ArrayLength() { return NULL; }532virtual AccessIndexed* as_AccessIndexed() { return NULL; }533virtual LoadIndexed* as_LoadIndexed() { return NULL; }534virtual StoreIndexed* as_StoreIndexed() { return NULL; }535virtual NegateOp* as_NegateOp() { return NULL; }536virtual Op2* as_Op2() { return NULL; }537virtual ArithmeticOp* as_ArithmeticOp() { return NULL; }538virtual ShiftOp* as_ShiftOp() { return NULL; }539virtual LogicOp* as_LogicOp() { return NULL; }540virtual CompareOp* as_CompareOp() { return NULL; }541virtual IfOp* as_IfOp() { return NULL; }542virtual Convert* as_Convert() { return NULL; }543virtual NullCheck* as_NullCheck() { return NULL; }544virtual OsrEntry* as_OsrEntry() { return NULL; }545virtual StateSplit* as_StateSplit() { return NULL; }546virtual Invoke* as_Invoke() { return NULL; }547virtual NewInstance* as_NewInstance() { return NULL; }548virtual NewArray* as_NewArray() { return NULL; }549virtual NewTypeArray* as_NewTypeArray() { return NULL; }550virtual NewObjectArray* as_NewObjectArray() { return NULL; }551virtual NewMultiArray* as_NewMultiArray() { return NULL; }552virtual TypeCheck* as_TypeCheck() { return NULL; }553virtual CheckCast* as_CheckCast() { return NULL; }554virtual InstanceOf* as_InstanceOf() { return NULL; }555virtual TypeCast* as_TypeCast() { return NULL; }556virtual AccessMonitor* as_AccessMonitor() { return NULL; }557virtual MonitorEnter* as_MonitorEnter() { return NULL; }558virtual MonitorExit* as_MonitorExit() { return NULL; }559virtual Intrinsic* as_Intrinsic() { return NULL; }560virtual BlockBegin* as_BlockBegin() { return NULL; }561virtual BlockEnd* as_BlockEnd() { return NULL; }562virtual Goto* as_Goto() { return NULL; }563virtual If* as_If() { return NULL; }564virtual TableSwitch* as_TableSwitch() { return NULL; }565virtual LookupSwitch* as_LookupSwitch() { return NULL; }566virtual Return* as_Return() { return NULL; }567virtual Throw* as_Throw() { return NULL; }568virtual Base* as_Base() { return NULL; }569virtual RoundFP* as_RoundFP() { return NULL; }570virtual ExceptionObject* as_ExceptionObject() { return NULL; }571virtual UnsafeOp* as_UnsafeOp() { return NULL; }572virtual ProfileInvoke* as_ProfileInvoke() { return NULL; }573virtual RangeCheckPredicate* as_RangeCheckPredicate() { return NULL; }574575#ifdef ASSERT576virtual Assert* as_Assert() { return NULL; }577#endif578579virtual void visit(InstructionVisitor* v) = 0;580581virtual bool can_trap() const { return false; }582583virtual void input_values_do(ValueVisitor* f) = 0;584virtual void state_values_do(ValueVisitor* f);585virtual void other_values_do(ValueVisitor* f) { /* usually no other - override on demand */ }586void values_do(ValueVisitor* f) { input_values_do(f); state_values_do(f); other_values_do(f); }587588virtual ciType* exact_type() const;589virtual ciType* declared_type() const { return NULL; }590591// hashing592virtual const char* name() const = 0;593HASHING1(Instruction, false, id()) // hashing disabled by default594595// debugging596static void check_state(ValueStack* state) PRODUCT_RETURN;597void print() PRODUCT_RETURN;598void print_line() PRODUCT_RETURN;599void print(InstructionPrinter& ip) PRODUCT_RETURN;600};601602603// The following macros are used to define base (i.e., non-leaf)604// and leaf instruction classes. They define class-name related605// generic functionality in one place.606607#define BASE(class_name, super_class_name) \608class class_name: public super_class_name { \609public: \610virtual class_name* as_##class_name() { return this; } \611612613#define LEAF(class_name, super_class_name) \614BASE(class_name, super_class_name) \615public: \616virtual const char* name() const { return #class_name; } \617virtual void visit(InstructionVisitor* v) { v->do_##class_name(this); } \618619620// Debugging support621622623#ifdef ASSERT624class AssertValues: public ValueVisitor {625void visit(Value* x) { assert((*x) != NULL, "value must exist"); }626};627#define ASSERT_VALUES { AssertValues assert_value; values_do(&assert_value); }628#else629#define ASSERT_VALUES630#endif // ASSERT631632633// A Phi is a phi function in the sense of SSA form. It stands for634// the value of a local variable at the beginning of a join block.635// A Phi consists of n operands, one for every incoming branch.636637LEAF(Phi, Instruction)638private:639int _pf_flags; // the flags of the phi function640int _index; // to value on operand stack (index < 0) or to local641public:642// creation643Phi(ValueType* type, BlockBegin* b, int index)644: Instruction(type->base())645, _pf_flags(0)646, _index(index)647{648_block = b;649NOT_PRODUCT(set_printable_bci(Value(b)->printable_bci()));650if (type->is_illegal()) {651make_illegal();652}653}654655// flags656enum Flag {657no_flag = 0,658visited = 1 << 0,659cannot_simplify = 1 << 1660};661662// accessors663bool is_local() const { return _index >= 0; }664bool is_on_stack() const { return !is_local(); }665int local_index() const { assert(is_local(), ""); return _index; }666int stack_index() const { assert(is_on_stack(), ""); return -(_index+1); }667668Value operand_at(int i) const;669int operand_count() const;670671void set(Flag f) { _pf_flags |= f; }672void clear(Flag f) { _pf_flags &= ~f; }673bool is_set(Flag f) const { return (_pf_flags & f) != 0; }674675// Invalidates phis corresponding to merges of locals of two different types676// (these should never be referenced, otherwise the bytecodes are illegal)677void make_illegal() {678set(cannot_simplify);679set_type(illegalType);680}681682bool is_illegal() const {683return type()->is_illegal();684}685686// generic687virtual void input_values_do(ValueVisitor* f) {688}689};690691692// A local is a placeholder for an incoming argument to a function call.693LEAF(Local, Instruction)694private:695int _java_index; // the local index within the method to which the local belongs696bool _is_receiver; // if local variable holds the receiver: "this" for non-static methods697ciType* _declared_type;698public:699// creation700Local(ciType* declared, ValueType* type, int index, bool receiver)701: Instruction(type)702, _java_index(index)703, _is_receiver(receiver)704, _declared_type(declared)705{706NOT_PRODUCT(set_printable_bci(-1));707}708709// accessors710int java_index() const { return _java_index; }711bool is_receiver() const { return _is_receiver; }712713virtual ciType* declared_type() const { return _declared_type; }714715// generic716virtual void input_values_do(ValueVisitor* f) { /* no values */ }717};718719720LEAF(Constant, Instruction)721public:722// creation723Constant(ValueType* type):724Instruction(type, NULL, /*type_is_constant*/ true)725{726assert(type->is_constant(), "must be a constant");727}728729Constant(ValueType* type, ValueStack* state_before):730Instruction(type, state_before, /*type_is_constant*/ true)731{732assert(state_before != NULL, "only used for constants which need patching");733assert(type->is_constant(), "must be a constant");734// since it's patching it needs to be pinned735pin();736}737738// generic739virtual bool can_trap() const { return state_before() != NULL; }740virtual void input_values_do(ValueVisitor* f) { /* no values */ }741742virtual intx hash() const;743virtual bool is_equal(Value v) const;744745virtual ciType* exact_type() const;746747enum CompareResult { not_comparable = -1, cond_false, cond_true };748749virtual CompareResult compare(Instruction::Condition condition, Value right) const;750BlockBegin* compare(Instruction::Condition cond, Value right,751BlockBegin* true_sux, BlockBegin* false_sux) const {752switch (compare(cond, right)) {753case not_comparable:754return NULL;755case cond_false:756return false_sux;757case cond_true:758return true_sux;759default:760ShouldNotReachHere();761return NULL;762}763}764};765766767BASE(AccessField, Instruction)768private:769Value _obj;770int _offset;771ciField* _field;772NullCheck* _explicit_null_check; // For explicit null check elimination773774public:775// creation776AccessField(Value obj, int offset, ciField* field, bool is_static,777ValueStack* state_before, bool needs_patching)778: Instruction(as_ValueType(field->type()->basic_type()), state_before)779, _obj(obj)780, _offset(offset)781, _field(field)782, _explicit_null_check(NULL)783{784set_needs_null_check(!is_static);785set_flag(IsStaticFlag, is_static);786set_flag(NeedsPatchingFlag, needs_patching);787ASSERT_VALUES788// pin of all instructions with memory access789pin();790}791792// accessors793Value obj() const { return _obj; }794int offset() const { return _offset; }795ciField* field() const { return _field; }796BasicType field_type() const { return _field->type()->basic_type(); }797bool is_static() const { return check_flag(IsStaticFlag); }798NullCheck* explicit_null_check() const { return _explicit_null_check; }799bool needs_patching() const { return check_flag(NeedsPatchingFlag); }800801// Unresolved getstatic and putstatic can cause initialization.802// Technically it occurs at the Constant that materializes the base803// of the static fields but it's simpler to model it here.804bool is_init_point() const { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); }805806// manipulation807808// Under certain circumstances, if a previous NullCheck instruction809// proved the target object non-null, we can eliminate the explicit810// null check and do an implicit one, simply specifying the debug811// information from the NullCheck. This field should only be consulted812// if needs_null_check() is true.813void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }814815// generic816virtual bool can_trap() const { return needs_null_check() || needs_patching(); }817virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }818};819820821LEAF(LoadField, AccessField)822public:823// creation824LoadField(Value obj, int offset, ciField* field, bool is_static,825ValueStack* state_before, bool needs_patching)826: AccessField(obj, offset, field, is_static, state_before, needs_patching)827{}828829ciType* declared_type() const;830831// generic; cannot be eliminated if needs patching or if volatile.832HASHING3(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset(), declared_type())833};834835836LEAF(StoreField, AccessField)837private:838Value _value;839840public:841// creation842StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,843ValueStack* state_before, bool needs_patching)844: AccessField(obj, offset, field, is_static, state_before, needs_patching)845, _value(value)846{847set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());848ASSERT_VALUES849pin();850}851852// accessors853Value value() const { return _value; }854bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }855856// generic857virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); }858};859860861BASE(AccessArray, Instruction)862private:863Value _array;864865public:866// creation867AccessArray(ValueType* type, Value array, ValueStack* state_before)868: Instruction(type, state_before)869, _array(array)870{871set_needs_null_check(true);872ASSERT_VALUES873pin(); // instruction with side effect (null exception or range check throwing)874}875876Value array() const { return _array; }877878// generic879virtual bool can_trap() const { return needs_null_check(); }880virtual void input_values_do(ValueVisitor* f) { f->visit(&_array); }881};882883884LEAF(ArrayLength, AccessArray)885private:886NullCheck* _explicit_null_check; // For explicit null check elimination887888public:889// creation890ArrayLength(Value array, ValueStack* state_before)891: AccessArray(intType, array, state_before)892, _explicit_null_check(NULL) {}893894// accessors895NullCheck* explicit_null_check() const { return _explicit_null_check; }896897// setters898// See LoadField::set_explicit_null_check for documentation899void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }900901// generic902HASHING1(ArrayLength, true, array()->subst())903};904905906BASE(AccessIndexed, AccessArray)907private:908Value _index;909Value _length;910BasicType _elt_type;911bool _mismatched;912913public:914// creation915AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched)916: AccessArray(as_ValueType(elt_type), array, state_before)917, _index(index)918, _length(length)919, _elt_type(elt_type)920, _mismatched(mismatched)921{922set_flag(Instruction::NeedsRangeCheckFlag, true);923ASSERT_VALUES924}925926// accessors927Value index() const { return _index; }928Value length() const { return _length; }929BasicType elt_type() const { return _elt_type; }930bool mismatched() const { return _mismatched; }931932void clear_length() { _length = NULL; }933// perform elimination of range checks involving constants934bool compute_needs_range_check();935936// generic937virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }938};939940941LEAF(LoadIndexed, AccessIndexed)942private:943NullCheck* _explicit_null_check; // For explicit null check elimination944945public:946// creation947LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before, bool mismatched = false)948: AccessIndexed(array, index, length, elt_type, state_before, mismatched)949, _explicit_null_check(NULL) {}950951// accessors952NullCheck* explicit_null_check() const { return _explicit_null_check; }953954// setters955// See LoadField::set_explicit_null_check for documentation956void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }957958ciType* exact_type() const;959ciType* declared_type() const;960961// generic;962HASHING3(LoadIndexed, true, type()->tag(), array()->subst(), index()->subst())963};964965966LEAF(StoreIndexed, AccessIndexed)967private:968Value _value;969970ciMethod* _profiled_method;971int _profiled_bci;972bool _check_boolean;973974public:975// creation976StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before,977bool check_boolean, bool mismatched = false)978: AccessIndexed(array, index, length, elt_type, state_before, mismatched)979, _value(value), _profiled_method(NULL), _profiled_bci(0), _check_boolean(check_boolean)980{981set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));982set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));983ASSERT_VALUES984pin();985}986987// accessors988Value value() const { return _value; }989bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }990bool needs_store_check() const { return check_flag(NeedsStoreCheckFlag); }991bool check_boolean() const { return _check_boolean; }992// Helpers for MethodData* profiling993void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }994void set_profiled_method(ciMethod* method) { _profiled_method = method; }995void set_profiled_bci(int bci) { _profiled_bci = bci; }996bool should_profile() const { return check_flag(ProfileMDOFlag); }997ciMethod* profiled_method() const { return _profiled_method; }998int profiled_bci() const { return _profiled_bci; }999// generic1000virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); }1001};100210031004LEAF(NegateOp, Instruction)1005private:1006Value _x;10071008public:1009// creation1010NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {1011ASSERT_VALUES1012}10131014// accessors1015Value x() const { return _x; }10161017// generic1018virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); }1019};102010211022BASE(Op2, Instruction)1023private:1024Bytecodes::Code _op;1025Value _x;1026Value _y;10271028public:1029// creation1030Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = NULL)1031: Instruction(type, state_before)1032, _op(op)1033, _x(x)1034, _y(y)1035{1036ASSERT_VALUES1037}10381039// accessors1040Bytecodes::Code op() const { return _op; }1041Value x() const { return _x; }1042Value y() const { return _y; }10431044// manipulators1045void swap_operands() {1046assert(is_commutative(), "operation must be commutative");1047Value t = _x; _x = _y; _y = t;1048}10491050// generic1051virtual bool is_commutative() const { return false; }1052virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); }1053};105410551056LEAF(ArithmeticOp, Op2)1057public:1058// creation1059ArithmeticOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)1060: Op2(x->type()->meet(y->type()), op, x, y, state_before)1061{1062if (can_trap()) pin();1063}10641065// generic1066virtual bool is_commutative() const;1067virtual bool can_trap() const;1068HASHING3(Op2, true, op(), x()->subst(), y()->subst())1069};107010711072LEAF(ShiftOp, Op2)1073public:1074// creation1075ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}10761077// generic1078HASHING3(Op2, true, op(), x()->subst(), y()->subst())1079};108010811082LEAF(LogicOp, Op2)1083public:1084// creation1085LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}10861087// generic1088virtual bool is_commutative() const;1089HASHING3(Op2, true, op(), x()->subst(), y()->subst())1090};109110921093LEAF(CompareOp, Op2)1094public:1095// creation1096CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)1097: Op2(intType, op, x, y, state_before)1098{}10991100// generic1101HASHING3(Op2, true, op(), x()->subst(), y()->subst())1102};110311041105LEAF(IfOp, Op2)1106private:1107Value _tval;1108Value _fval;11091110public:1111// creation1112IfOp(Value x, Condition cond, Value y, Value tval, Value fval)1113: Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)1114, _tval(tval)1115, _fval(fval)1116{1117ASSERT_VALUES1118assert(tval->type()->tag() == fval->type()->tag(), "types must match");1119}11201121// accessors1122virtual bool is_commutative() const;1123Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }1124Condition cond() const { return (Condition)Op2::op(); }1125Value tval() const { return _tval; }1126Value fval() const { return _fval; }11271128// generic1129virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }1130};113111321133LEAF(Convert, Instruction)1134private:1135Bytecodes::Code _op;1136Value _value;11371138public:1139// creation1140Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {1141ASSERT_VALUES1142}11431144// accessors1145Bytecodes::Code op() const { return _op; }1146Value value() const { return _value; }11471148// generic1149virtual void input_values_do(ValueVisitor* f) { f->visit(&_value); }1150HASHING2(Convert, true, op(), value()->subst())1151};115211531154LEAF(NullCheck, Instruction)1155private:1156Value _obj;11571158public:1159// creation1160NullCheck(Value obj, ValueStack* state_before)1161: Instruction(obj->type()->base(), state_before)1162, _obj(obj)1163{1164ASSERT_VALUES1165set_can_trap(true);1166assert(_obj->type()->is_object(), "null check must be applied to objects only");1167pin(Instruction::PinExplicitNullCheck);1168}11691170// accessors1171Value obj() const { return _obj; }11721173// setters1174void set_can_trap(bool can_trap) { set_flag(CanTrapFlag, can_trap); }11751176// generic1177virtual bool can_trap() const { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }1178virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }1179HASHING1(NullCheck, true, obj()->subst())1180};118111821183// This node is supposed to cast the type of another node to a more precise1184// declared type.1185LEAF(TypeCast, Instruction)1186private:1187ciType* _declared_type;1188Value _obj;11891190public:1191// The type of this node is the same type as the object type (and it might be constant).1192TypeCast(ciType* type, Value obj, ValueStack* state_before)1193: Instruction(obj->type(), state_before, obj->type()->is_constant()),1194_declared_type(type),1195_obj(obj) {}11961197// accessors1198ciType* declared_type() const { return _declared_type; }1199Value obj() const { return _obj; }12001201// generic1202virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }1203};120412051206BASE(StateSplit, Instruction)1207private:1208ValueStack* _state;12091210protected:1211static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);12121213public:1214// creation1215StateSplit(ValueType* type, ValueStack* state_before = NULL)1216: Instruction(type, state_before)1217, _state(NULL)1218{1219pin(PinStateSplitConstructor);1220}12211222// accessors1223ValueStack* state() const { return _state; }1224IRScope* scope() const; // the state's scope12251226// manipulation1227void set_state(ValueStack* state) { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }12281229// generic1230virtual void input_values_do(ValueVisitor* f) { /* no values */ }1231virtual void state_values_do(ValueVisitor* f);1232};123312341235LEAF(Invoke, StateSplit)1236private:1237Bytecodes::Code _code;1238Value _recv;1239Values* _args;1240BasicTypeList* _signature;1241ciMethod* _target;12421243public:1244// creation1245Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,1246ciMethod* target, ValueStack* state_before);12471248// accessors1249Bytecodes::Code code() const { return _code; }1250Value receiver() const { return _recv; }1251bool has_receiver() const { return receiver() != NULL; }1252int number_of_arguments() const { return _args->length(); }1253Value argument_at(int i) const { return _args->at(i); }1254BasicTypeList* signature() const { return _signature; }1255ciMethod* target() const { return _target; }12561257ciType* declared_type() const;12581259// Returns false if target is not loaded1260bool target_is_final() const { return check_flag(TargetIsFinalFlag); }1261bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }12621263// JSR 292 support1264bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }1265bool is_method_handle_intrinsic() const { return target()->is_method_handle_intrinsic(); }12661267virtual bool needs_exception_state() const { return false; }12681269// generic1270virtual bool can_trap() const { return true; }1271virtual void input_values_do(ValueVisitor* f) {1272StateSplit::input_values_do(f);1273if (has_receiver()) f->visit(&_recv);1274for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));1275}1276virtual void state_values_do(ValueVisitor *f);1277};127812791280LEAF(NewInstance, StateSplit)1281private:1282ciInstanceKlass* _klass;1283bool _is_unresolved;12841285public:1286// creation1287NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved)1288: StateSplit(instanceType, state_before)1289, _klass(klass), _is_unresolved(is_unresolved)1290{}12911292// accessors1293ciInstanceKlass* klass() const { return _klass; }1294bool is_unresolved() const { return _is_unresolved; }12951296virtual bool needs_exception_state() const { return false; }12971298// generic1299virtual bool can_trap() const { return true; }1300ciType* exact_type() const;1301ciType* declared_type() const;1302};130313041305BASE(NewArray, StateSplit)1306private:1307Value _length;13081309public:1310// creation1311NewArray(Value length, ValueStack* state_before)1312: StateSplit(objectType, state_before)1313, _length(length)1314{1315// Do not ASSERT_VALUES since length is NULL for NewMultiArray1316}13171318// accessors1319Value length() const { return _length; }13201321virtual bool needs_exception_state() const { return false; }13221323ciType* exact_type() const { return NULL; }1324ciType* declared_type() const;13251326// generic1327virtual bool can_trap() const { return true; }1328virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_length); }1329};133013311332LEAF(NewTypeArray, NewArray)1333private:1334BasicType _elt_type;13351336public:1337// creation1338NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)1339: NewArray(length, state_before)1340, _elt_type(elt_type)1341{}13421343// accessors1344BasicType elt_type() const { return _elt_type; }1345ciType* exact_type() const;1346};134713481349LEAF(NewObjectArray, NewArray)1350private:1351ciKlass* _klass;13521353public:1354// creation1355NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}13561357// accessors1358ciKlass* klass() const { return _klass; }1359ciType* exact_type() const;1360};136113621363LEAF(NewMultiArray, NewArray)1364private:1365ciKlass* _klass;1366Values* _dims;13671368public:1369// creation1370NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {1371ASSERT_VALUES1372}13731374// accessors1375ciKlass* klass() const { return _klass; }1376Values* dims() const { return _dims; }1377int rank() const { return dims()->length(); }13781379// generic1380virtual void input_values_do(ValueVisitor* f) {1381// NOTE: we do not call NewArray::input_values_do since "length"1382// is meaningless for a multi-dimensional array; passing the1383// zeroth element down to NewArray as its length is a bad idea1384// since there will be a copy in the "dims" array which doesn't1385// get updated, and the value must not be traversed twice. Was bug1386// - kbr 4/10/20011387StateSplit::input_values_do(f);1388for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));1389}1390};139113921393BASE(TypeCheck, StateSplit)1394private:1395ciKlass* _klass;1396Value _obj;13971398ciMethod* _profiled_method;1399int _profiled_bci;14001401public:1402// creation1403TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)1404: StateSplit(type, state_before), _klass(klass), _obj(obj),1405_profiled_method(NULL), _profiled_bci(0) {1406ASSERT_VALUES1407set_direct_compare(false);1408}14091410// accessors1411ciKlass* klass() const { return _klass; }1412Value obj() const { return _obj; }1413bool is_loaded() const { return klass() != NULL; }1414bool direct_compare() const { return check_flag(DirectCompareFlag); }14151416// manipulation1417void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }14181419// generic1420virtual bool can_trap() const { return true; }1421virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }14221423// Helpers for MethodData* profiling1424void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }1425void set_profiled_method(ciMethod* method) { _profiled_method = method; }1426void set_profiled_bci(int bci) { _profiled_bci = bci; }1427bool should_profile() const { return check_flag(ProfileMDOFlag); }1428ciMethod* profiled_method() const { return _profiled_method; }1429int profiled_bci() const { return _profiled_bci; }1430};143114321433LEAF(CheckCast, TypeCheck)1434public:1435// creation1436CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)1437: TypeCheck(klass, obj, objectType, state_before) {}14381439void set_incompatible_class_change_check() {1440set_flag(ThrowIncompatibleClassChangeErrorFlag, true);1441}1442bool is_incompatible_class_change_check() const {1443return check_flag(ThrowIncompatibleClassChangeErrorFlag);1444}1445void set_invokespecial_receiver_check() {1446set_flag(InvokeSpecialReceiverCheckFlag, true);1447}1448bool is_invokespecial_receiver_check() const {1449return check_flag(InvokeSpecialReceiverCheckFlag);1450}14511452virtual bool needs_exception_state() const {1453return !is_invokespecial_receiver_check();1454}14551456ciType* declared_type() const;1457};145814591460LEAF(InstanceOf, TypeCheck)1461public:1462// creation1463InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}14641465virtual bool needs_exception_state() const { return false; }1466};146714681469BASE(AccessMonitor, StateSplit)1470private:1471Value _obj;1472int _monitor_no;14731474public:1475// creation1476AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)1477: StateSplit(illegalType, state_before)1478, _obj(obj)1479, _monitor_no(monitor_no)1480{1481set_needs_null_check(true);1482ASSERT_VALUES1483}14841485// accessors1486Value obj() const { return _obj; }1487int monitor_no() const { return _monitor_no; }14881489// generic1490virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }1491};149214931494LEAF(MonitorEnter, AccessMonitor)1495public:1496// creation1497MonitorEnter(Value obj, int monitor_no, ValueStack* state_before)1498: AccessMonitor(obj, monitor_no, state_before)1499{1500ASSERT_VALUES1501}15021503// generic1504virtual bool can_trap() const { return true; }1505};150615071508LEAF(MonitorExit, AccessMonitor)1509public:1510// creation1511MonitorExit(Value obj, int monitor_no)1512: AccessMonitor(obj, monitor_no, NULL)1513{1514ASSERT_VALUES1515}1516};151715181519LEAF(Intrinsic, StateSplit)1520private:1521vmIntrinsics::ID _id;1522Values* _args;1523Value _recv;1524ArgsNonNullState _nonnull_state;15251526public:1527// preserves_state can be set to true for Intrinsics1528// which are guaranteed to preserve register state across any slow1529// cases; setting it to true does not mean that the Intrinsic can1530// not trap, only that if we continue execution in the same basic1531// block after the Intrinsic, all of the registers are intact. This1532// allows load elimination and common expression elimination to be1533// performed across the Intrinsic. The default value is false.1534Intrinsic(ValueType* type,1535vmIntrinsics::ID id,1536Values* args,1537bool has_receiver,1538ValueStack* state_before,1539bool preserves_state,1540bool cantrap = true)1541: StateSplit(type, state_before)1542, _id(id)1543, _args(args)1544, _recv(NULL)1545{1546assert(args != NULL, "args must exist");1547ASSERT_VALUES1548set_flag(PreservesStateFlag, preserves_state);1549set_flag(CanTrapFlag, cantrap);1550if (has_receiver) {1551_recv = argument_at(0);1552}1553set_needs_null_check(has_receiver);15541555// some intrinsics can't trap, so don't force them to be pinned1556if (!can_trap() && !vmIntrinsics::should_be_pinned(_id)) {1557unpin(PinStateSplitConstructor);1558}1559}15601561// accessors1562vmIntrinsics::ID id() const { return _id; }1563int number_of_arguments() const { return _args->length(); }1564Value argument_at(int i) const { return _args->at(i); }15651566bool has_receiver() const { return (_recv != NULL); }1567Value receiver() const { assert(has_receiver(), "must have receiver"); return _recv; }1568bool preserves_state() const { return check_flag(PreservesStateFlag); }15691570bool arg_needs_null_check(int i) const {1571return _nonnull_state.arg_needs_null_check(i);1572}15731574void set_arg_needs_null_check(int i, bool check) {1575_nonnull_state.set_arg_needs_null_check(i, check);1576}15771578// generic1579virtual bool can_trap() const { return check_flag(CanTrapFlag); }1580virtual void input_values_do(ValueVisitor* f) {1581StateSplit::input_values_do(f);1582for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));1583}1584};158515861587class LIR_List;15881589LEAF(BlockBegin, StateSplit)1590private:1591int _block_id; // the unique block id1592int _bci; // start-bci of block1593int _depth_first_number; // number of this block in a depth-first ordering1594int _linear_scan_number; // number of this block in linear-scan ordering1595int _dominator_depth;1596int _loop_depth; // the loop nesting level of this block1597int _loop_index; // number of the innermost loop of this block1598int _flags; // the flags associated with this block15991600// fields used by BlockListBuilder1601int _total_preds; // number of predecessors found by BlockListBuilder1602ResourceBitMap _stores_to_locals; // bit is set when a local variable is stored in the block16031604// SSA specific fields: (factor out later)1605BlockList _successors; // the successors of this block1606BlockList _predecessors; // the predecessors of this block1607BlockList _dominates; // list of blocks that are dominated by this block1608BlockBegin* _dominator; // the dominator of this block1609// SSA specific ends1610BlockEnd* _end; // the last instruction of this block1611BlockList _exception_handlers; // the exception handlers potentially invoked by this block1612ValueStackStack* _exception_states; // only for xhandler entries: states of all instructions that have an edge to this xhandler1613int _exception_handler_pco; // if this block is the start of an exception handler,1614// this records the PC offset in the assembly code of the1615// first instruction in this block1616Label _label; // the label associated with this block1617LIR_List* _lir; // the low level intermediate representation for this block16181619ResourceBitMap _live_in; // set of live LIR_Opr registers at entry to this block1620ResourceBitMap _live_out; // set of live LIR_Opr registers at exit from this block1621ResourceBitMap _live_gen; // set of registers used before any redefinition in this block1622ResourceBitMap _live_kill; // set of registers defined in this block16231624ResourceBitMap _fpu_register_usage;1625intArray* _fpu_stack_state; // For x86 FPU code generation with UseLinearScan1626int _first_lir_instruction_id; // ID of first LIR instruction in this block1627int _last_lir_instruction_id; // ID of last LIR instruction in this block16281629void iterate_preorder (boolArray& mark, BlockClosure* closure);1630void iterate_postorder(boolArray& mark, BlockClosure* closure);16311632friend class SuxAndWeightAdjuster;16331634public:1635void* operator new(size_t size) throw() {1636Compilation* c = Compilation::current();1637void* res = c->arena()->Amalloc(size);1638return res;1639}16401641// initialization/counting1642static int number_of_blocks() {1643return Compilation::current()->number_of_blocks();1644}16451646// creation1647BlockBegin(int bci)1648: StateSplit(illegalType)1649, _block_id(Compilation::current()->get_next_block_id())1650, _bci(bci)1651, _depth_first_number(-1)1652, _linear_scan_number(-1)1653, _dominator_depth(-1)1654, _loop_depth(0)1655, _loop_index(-1)1656, _flags(0)1657, _total_preds(0)1658, _stores_to_locals()1659, _successors(2)1660, _predecessors(2)1661, _dominates(2)1662, _dominator(NULL)1663, _end(NULL)1664, _exception_handlers(1)1665, _exception_states(NULL)1666, _exception_handler_pco(-1)1667, _lir(NULL)1668, _live_in()1669, _live_out()1670, _live_gen()1671, _live_kill()1672, _fpu_register_usage()1673, _fpu_stack_state(NULL)1674, _first_lir_instruction_id(-1)1675, _last_lir_instruction_id(-1)1676{1677_block = this;1678#ifndef PRODUCT1679set_printable_bci(bci);1680#endif1681}16821683// accessors1684int block_id() const { return _block_id; }1685int bci() const { return _bci; }1686BlockList* successors() { return &_successors; }1687BlockList* dominates() { return &_dominates; }1688BlockBegin* dominator() const { return _dominator; }1689int loop_depth() const { return _loop_depth; }1690int dominator_depth() const { return _dominator_depth; }1691int depth_first_number() const { return _depth_first_number; }1692int linear_scan_number() const { return _linear_scan_number; }1693BlockEnd* end() const { return _end; }1694Label* label() { return &_label; }1695LIR_List* lir() const { return _lir; }1696int exception_handler_pco() const { return _exception_handler_pco; }1697ResourceBitMap& live_in() { return _live_in; }1698ResourceBitMap& live_out() { return _live_out; }1699ResourceBitMap& live_gen() { return _live_gen; }1700ResourceBitMap& live_kill() { return _live_kill; }1701ResourceBitMap& fpu_register_usage() { return _fpu_register_usage; }1702intArray* fpu_stack_state() const { return _fpu_stack_state; }1703int first_lir_instruction_id() const { return _first_lir_instruction_id; }1704int last_lir_instruction_id() const { return _last_lir_instruction_id; }1705int total_preds() const { return _total_preds; }1706BitMap& stores_to_locals() { return _stores_to_locals; }17071708// manipulation1709void set_dominator(BlockBegin* dom) { _dominator = dom; }1710void set_loop_depth(int d) { _loop_depth = d; }1711void set_dominator_depth(int d) { _dominator_depth = d; }1712void set_depth_first_number(int dfn) { _depth_first_number = dfn; }1713void set_linear_scan_number(int lsn) { _linear_scan_number = lsn; }1714void set_end(BlockEnd* end);1715void clear_end();1716void disconnect_from_graph();1717static void disconnect_edge(BlockBegin* from, BlockBegin* to);1718BlockBegin* insert_block_between(BlockBegin* sux);1719void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);1720void set_lir(LIR_List* lir) { _lir = lir; }1721void set_exception_handler_pco(int pco) { _exception_handler_pco = pco; }1722void set_live_in (const ResourceBitMap& map) { _live_in = map; }1723void set_live_out (const ResourceBitMap& map) { _live_out = map; }1724void set_live_gen (const ResourceBitMap& map) { _live_gen = map; }1725void set_live_kill(const ResourceBitMap& map) { _live_kill = map; }1726void set_fpu_register_usage(const ResourceBitMap& map) { _fpu_register_usage = map; }1727void set_fpu_stack_state(intArray* state) { _fpu_stack_state = state; }1728void set_first_lir_instruction_id(int id) { _first_lir_instruction_id = id; }1729void set_last_lir_instruction_id(int id) { _last_lir_instruction_id = id; }1730void increment_total_preds(int n = 1) { _total_preds += n; }1731void init_stores_to_locals(int locals_count) { _stores_to_locals.initialize(locals_count); }17321733// generic1734virtual void state_values_do(ValueVisitor* f);17351736// successors and predecessors1737int number_of_sux() const;1738BlockBegin* sux_at(int i) const;1739void add_successor(BlockBegin* sux);1740void remove_successor(BlockBegin* pred);1741bool is_successor(BlockBegin* sux) const { return _successors.contains(sux); }17421743void add_predecessor(BlockBegin* pred);1744void remove_predecessor(BlockBegin* pred);1745bool is_predecessor(BlockBegin* pred) const { return _predecessors.contains(pred); }1746int number_of_preds() const { return _predecessors.length(); }1747BlockBegin* pred_at(int i) const { return _predecessors.at(i); }17481749// exception handlers potentially invoked by this block1750void add_exception_handler(BlockBegin* b);1751bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }1752int number_of_exception_handlers() const { return _exception_handlers.length(); }1753BlockBegin* exception_handler_at(int i) const { return _exception_handlers.at(i); }17541755// states of the instructions that have an edge to this exception handler1756int number_of_exception_states() { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); }1757ValueStack* exception_state_at(int idx) const { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }1758int add_exception_state(ValueStack* state);17591760// flags1761enum Flag {1762no_flag = 0,1763std_entry_flag = 1 << 0,1764osr_entry_flag = 1 << 1,1765exception_entry_flag = 1 << 2,1766subroutine_entry_flag = 1 << 3,1767backward_branch_target_flag = 1 << 4,1768is_on_work_list_flag = 1 << 5,1769was_visited_flag = 1 << 6,1770parser_loop_header_flag = 1 << 7, // set by parser to identify blocks where phi functions can not be created on demand1771critical_edge_split_flag = 1 << 8, // set for all blocks that are introduced when critical edges are split1772linear_scan_loop_header_flag = 1 << 9, // set during loop-detection for LinearScan1773linear_scan_loop_end_flag = 1 << 10, // set during loop-detection for LinearScan1774donot_eliminate_range_checks = 1 << 11 // Should be try to eliminate range checks in this block1775};17761777void set(Flag f) { _flags |= f; }1778void clear(Flag f) { _flags &= ~f; }1779bool is_set(Flag f) const { return (_flags & f) != 0; }1780bool is_entry_block() const {1781const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;1782return (_flags & entry_mask) != 0;1783}17841785// iteration1786void iterate_preorder (BlockClosure* closure);1787void iterate_postorder (BlockClosure* closure);17881789void block_values_do(ValueVisitor* f);17901791// loops1792void set_loop_index(int ix) { _loop_index = ix; }1793int loop_index() const { return _loop_index; }17941795// merging1796bool try_merge(ValueStack* state); // try to merge states at block begin1797void merge(ValueStack* state) { bool b = try_merge(state); assert(b, "merge failed"); }17981799// debugging1800void print_block() PRODUCT_RETURN;1801void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;1802};180318041805BASE(BlockEnd, StateSplit)1806private:1807BlockList* _sux;18081809protected:1810BlockList* sux() const { return _sux; }18111812void set_sux(BlockList* sux) {1813#ifdef ASSERT1814assert(sux != NULL, "sux must exist");1815for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist");1816#endif1817_sux = sux;1818}18191820public:1821// creation1822BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)1823: StateSplit(type, state_before)1824, _sux(NULL)1825{1826set_flag(IsSafepointFlag, is_safepoint);1827}18281829// accessors1830bool is_safepoint() const { return check_flag(IsSafepointFlag); }1831// For compatibility with old code, for new code use block()1832BlockBegin* begin() const { return _block; }18331834// manipulation1835void set_begin(BlockBegin* begin);18361837// successors1838int number_of_sux() const { return _sux != NULL ? _sux->length() : 0; }1839BlockBegin* sux_at(int i) const { return _sux->at(i); }1840BlockBegin* default_sux() const { return sux_at(number_of_sux() - 1); }1841BlockBegin** addr_sux_at(int i) const { return _sux->adr_at(i); }1842int sux_index(BlockBegin* sux) const { return _sux->find(sux); }1843void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);1844};184518461847LEAF(Goto, BlockEnd)1848public:1849enum Direction {1850none, // Just a regular goto1851taken, not_taken // Goto produced from If1852};1853private:1854ciMethod* _profiled_method;1855int _profiled_bci;1856Direction _direction;1857public:1858// creation1859Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false)1860: BlockEnd(illegalType, state_before, is_safepoint)1861, _profiled_method(NULL)1862, _profiled_bci(0)1863, _direction(none) {1864BlockList* s = new BlockList(1);1865s->append(sux);1866set_sux(s);1867}18681869Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint)1870, _profiled_method(NULL)1871, _profiled_bci(0)1872, _direction(none) {1873BlockList* s = new BlockList(1);1874s->append(sux);1875set_sux(s);1876}18771878bool should_profile() const { return check_flag(ProfileMDOFlag); }1879ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches1880int profiled_bci() const { return _profiled_bci; }1881Direction direction() const { return _direction; }18821883void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }1884void set_profiled_method(ciMethod* method) { _profiled_method = method; }1885void set_profiled_bci(int bci) { _profiled_bci = bci; }1886void set_direction(Direction d) { _direction = d; }1887};18881889#ifdef ASSERT1890LEAF(Assert, Instruction)1891private:1892Value _x;1893Condition _cond;1894Value _y;1895char *_message;18961897public:1898// creation1899// unordered_is_true is valid for float/double compares only1900Assert(Value x, Condition cond, bool unordered_is_true, Value y);19011902// accessors1903Value x() const { return _x; }1904Condition cond() const { return _cond; }1905bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }1906Value y() const { return _y; }1907const char *message() const { return _message; }19081909// generic1910virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); }1911};1912#endif19131914LEAF(RangeCheckPredicate, StateSplit)1915private:1916Value _x;1917Condition _cond;1918Value _y;19191920void check_state();19211922public:1923// creation1924// unordered_is_true is valid for float/double compares only1925RangeCheckPredicate(Value x, Condition cond, bool unordered_is_true, Value y, ValueStack* state) : StateSplit(illegalType)1926, _x(x)1927, _cond(cond)1928, _y(y)1929{1930ASSERT_VALUES1931set_flag(UnorderedIsTrueFlag, unordered_is_true);1932assert(x->type()->tag() == y->type()->tag(), "types must match");1933this->set_state(state);1934check_state();1935}19361937// Always deoptimize1938RangeCheckPredicate(ValueStack* state) : StateSplit(illegalType)1939{1940this->set_state(state);1941_x = _y = NULL;1942check_state();1943}19441945// accessors1946Value x() const { return _x; }1947Condition cond() const { return _cond; }1948bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }1949Value y() const { return _y; }19501951void always_fail() { _x = _y = NULL; }19521953// generic1954virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }1955HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())1956};19571958LEAF(If, BlockEnd)1959private:1960Value _x;1961Condition _cond;1962Value _y;1963ciMethod* _profiled_method;1964int _profiled_bci; // Canonicalizer may alter bci of If node1965bool _swapped; // Is the order reversed with respect to the original If in the1966// bytecode stream?1967public:1968// creation1969// unordered_is_true is valid for float/double compares only1970If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)1971: BlockEnd(illegalType, state_before, is_safepoint)1972, _x(x)1973, _cond(cond)1974, _y(y)1975, _profiled_method(NULL)1976, _profiled_bci(0)1977, _swapped(false)1978{1979ASSERT_VALUES1980set_flag(UnorderedIsTrueFlag, unordered_is_true);1981assert(x->type()->tag() == y->type()->tag(), "types must match");1982BlockList* s = new BlockList(2);1983s->append(tsux);1984s->append(fsux);1985set_sux(s);1986}19871988// accessors1989Value x() const { return _x; }1990Condition cond() const { return _cond; }1991bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }1992Value y() const { return _y; }1993BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }1994BlockBegin* tsux() const { return sux_for(true); }1995BlockBegin* fsux() const { return sux_for(false); }1996BlockBegin* usux() const { return sux_for(unordered_is_true()); }1997bool should_profile() const { return check_flag(ProfileMDOFlag); }1998ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches1999int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered2000bool is_swapped() const { return _swapped; }20012002// manipulation2003void swap_operands() {2004Value t = _x; _x = _y; _y = t;2005_cond = mirror(_cond);2006}20072008void swap_sux() {2009assert(number_of_sux() == 2, "wrong number of successors");2010BlockList* s = sux();2011BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);2012_cond = negate(_cond);2013set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));2014}20152016void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }2017void set_profiled_method(ciMethod* method) { _profiled_method = method; }2018void set_profiled_bci(int bci) { _profiled_bci = bci; }2019void set_swapped(bool value) { _swapped = value; }2020// generic2021virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }2022};202320242025BASE(Switch, BlockEnd)2026private:2027Value _tag;20282029public:2030// creation2031Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)2032: BlockEnd(illegalType, state_before, is_safepoint)2033, _tag(tag) {2034ASSERT_VALUES2035set_sux(sux);2036}20372038// accessors2039Value tag() const { return _tag; }2040int length() const { return number_of_sux() - 1; }20412042virtual bool needs_exception_state() const { return false; }20432044// generic2045virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_tag); }2046};204720482049LEAF(TableSwitch, Switch)2050private:2051int _lo_key;20522053public:2054// creation2055TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)2056: Switch(tag, sux, state_before, is_safepoint)2057, _lo_key(lo_key) { assert(_lo_key <= hi_key(), "integer overflow"); }20582059// accessors2060int lo_key() const { return _lo_key; }2061int hi_key() const { return _lo_key + (length() - 1); }2062};206320642065LEAF(LookupSwitch, Switch)2066private:2067intArray* _keys;20682069public:2070// creation2071LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)2072: Switch(tag, sux, state_before, is_safepoint)2073, _keys(keys) {2074assert(keys != NULL, "keys must exist");2075assert(keys->length() == length(), "sux & keys have incompatible lengths");2076}20772078// accessors2079int key_at(int i) const { return _keys->at(i); }2080};208120822083LEAF(Return, BlockEnd)2084private:2085Value _result;20862087public:2088// creation2089Return(Value result) :2090BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true),2091_result(result) {}20922093// accessors2094Value result() const { return _result; }2095bool has_result() const { return result() != NULL; }20962097// generic2098virtual void input_values_do(ValueVisitor* f) {2099BlockEnd::input_values_do(f);2100if (has_result()) f->visit(&_result);2101}2102};210321042105LEAF(Throw, BlockEnd)2106private:2107Value _exception;21082109public:2110// creation2111Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {2112ASSERT_VALUES2113}21142115// accessors2116Value exception() const { return _exception; }21172118// generic2119virtual bool can_trap() const { return true; }2120virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_exception); }2121};212221232124LEAF(Base, BlockEnd)2125public:2126// creation2127Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, NULL, false) {2128assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged");2129assert(osr_entry == NULL || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged");2130BlockList* s = new BlockList(2);2131if (osr_entry != NULL) s->append(osr_entry);2132s->append(std_entry); // must be default sux!2133set_sux(s);2134}21352136// accessors2137BlockBegin* std_entry() const { return default_sux(); }2138BlockBegin* osr_entry() const { return number_of_sux() < 2 ? NULL : sux_at(0); }2139};214021412142LEAF(OsrEntry, Instruction)2143public:2144// creation2145#ifdef _LP642146OsrEntry() : Instruction(longType) { pin(); }2147#else2148OsrEntry() : Instruction(intType) { pin(); }2149#endif21502151// generic2152virtual void input_values_do(ValueVisitor* f) { }2153};215421552156// Models the incoming exception at a catch site2157LEAF(ExceptionObject, Instruction)2158public:2159// creation2160ExceptionObject() : Instruction(objectType) {2161pin();2162}21632164// generic2165virtual void input_values_do(ValueVisitor* f) { }2166};216721682169// Models needed rounding for floating-point values on Intel.2170// Currently only used to represent rounding of double-precision2171// values stored into local variables, but could be used to model2172// intermediate rounding of single-precision values as well.2173LEAF(RoundFP, Instruction)2174private:2175Value _input; // floating-point value to be rounded21762177public:2178RoundFP(Value input)2179: Instruction(input->type()) // Note: should not be used for constants2180, _input(input)2181{2182ASSERT_VALUES2183}21842185// accessors2186Value input() const { return _input; }21872188// generic2189virtual void input_values_do(ValueVisitor* f) { f->visit(&_input); }2190};219121922193BASE(UnsafeOp, Instruction)2194private:2195BasicType _basic_type; // ValueType can not express byte-sized integers21962197protected:2198// creation2199UnsafeOp(BasicType basic_type, bool is_put)2200: Instruction(is_put ? voidType : as_ValueType(basic_type))2201, _basic_type(basic_type)2202{2203//Note: Unsafe ops are not not guaranteed to throw NPE.2204// Convservatively, Unsafe operations must be pinned though we could be2205// looser about this if we wanted to..2206pin();2207}22082209public:2210// accessors2211BasicType basic_type() { return _basic_type; }22122213// generic2214virtual void input_values_do(ValueVisitor* f) { }2215};221622172218BASE(UnsafeRawOp, UnsafeOp)2219private:2220Value _base; // Base address (a Java long)2221Value _index; // Index if computed by optimizer; initialized to NULL2222int _log2_scale; // Scale factor: 0, 1, 2, or 3.2223// Indicates log2 of number of bytes (1, 2, 4, or 8)2224// to scale index by.22252226protected:2227UnsafeRawOp(BasicType basic_type, Value addr, bool is_put)2228: UnsafeOp(basic_type, is_put)2229, _base(addr)2230, _index(NULL)2231, _log2_scale(0)2232{2233// Can not use ASSERT_VALUES because index may be NULL2234assert(addr != NULL && addr->type()->is_long(), "just checking");2235}22362237UnsafeRawOp(BasicType basic_type, Value base, Value index, int log2_scale, bool is_put)2238: UnsafeOp(basic_type, is_put)2239, _base(base)2240, _index(index)2241, _log2_scale(log2_scale)2242{2243}22442245public:2246// accessors2247Value base() { return _base; }2248Value index() { return _index; }2249bool has_index() { return (_index != NULL); }2250int log2_scale() { return _log2_scale; }22512252// setters2253void set_base (Value base) { _base = base; }2254void set_index(Value index) { _index = index; }2255void set_log2_scale(int log2_scale) { _log2_scale = log2_scale; }22562257// generic2258virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f);2259f->visit(&_base);2260if (has_index()) f->visit(&_index); }2261};226222632264LEAF(UnsafeGetRaw, UnsafeRawOp)2265private:2266bool _may_be_unaligned, _is_wide; // For OSREntry22672268public:2269UnsafeGetRaw(BasicType basic_type, Value addr, bool may_be_unaligned, bool is_wide = false)2270: UnsafeRawOp(basic_type, addr, false) {2271_may_be_unaligned = may_be_unaligned;2272_is_wide = is_wide;2273}22742275UnsafeGetRaw(BasicType basic_type, Value base, Value index, int log2_scale, bool may_be_unaligned, bool is_wide = false)2276: UnsafeRawOp(basic_type, base, index, log2_scale, false) {2277_may_be_unaligned = may_be_unaligned;2278_is_wide = is_wide;2279}22802281bool may_be_unaligned() { return _may_be_unaligned; }2282bool is_wide() { return _is_wide; }2283};228422852286LEAF(UnsafePutRaw, UnsafeRawOp)2287private:2288Value _value; // Value to be stored22892290public:2291UnsafePutRaw(BasicType basic_type, Value addr, Value value)2292: UnsafeRawOp(basic_type, addr, true)2293, _value(value)2294{2295assert(value != NULL, "just checking");2296ASSERT_VALUES2297}22982299UnsafePutRaw(BasicType basic_type, Value base, Value index, int log2_scale, Value value)2300: UnsafeRawOp(basic_type, base, index, log2_scale, true)2301, _value(value)2302{2303assert(value != NULL, "just checking");2304ASSERT_VALUES2305}23062307// accessors2308Value value() { return _value; }23092310// generic2311virtual void input_values_do(ValueVisitor* f) { UnsafeRawOp::input_values_do(f);2312f->visit(&_value); }2313};231423152316BASE(UnsafeObjectOp, UnsafeOp)2317private:2318Value _object; // Object to be fetched from or mutated2319Value _offset; // Offset within object2320bool _is_volatile; // true if volatile - dl/JSR1662321public:2322UnsafeObjectOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile)2323: UnsafeOp(basic_type, is_put), _object(object), _offset(offset), _is_volatile(is_volatile)2324{2325}23262327// accessors2328Value object() { return _object; }2329Value offset() { return _offset; }2330bool is_volatile() { return _is_volatile; }2331// generic2332virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f);2333f->visit(&_object);2334f->visit(&_offset); }2335};233623372338LEAF(UnsafeGetObject, UnsafeObjectOp)2339public:2340UnsafeGetObject(BasicType basic_type, Value object, Value offset, bool is_volatile)2341: UnsafeObjectOp(basic_type, object, offset, false, is_volatile)2342{2343ASSERT_VALUES2344}2345};234623472348LEAF(UnsafePutObject, UnsafeObjectOp)2349private:2350Value _value; // Value to be stored2351public:2352UnsafePutObject(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile)2353: UnsafeObjectOp(basic_type, object, offset, true, is_volatile)2354, _value(value)2355{2356ASSERT_VALUES2357}23582359// accessors2360Value value() { return _value; }23612362// generic2363virtual void input_values_do(ValueVisitor* f) { UnsafeObjectOp::input_values_do(f);2364f->visit(&_value); }2365};23662367LEAF(UnsafeGetAndSetObject, UnsafeObjectOp)2368private:2369Value _value; // Value to be stored2370bool _is_add;2371public:2372UnsafeGetAndSetObject(BasicType basic_type, Value object, Value offset, Value value, bool is_add)2373: UnsafeObjectOp(basic_type, object, offset, false, false)2374, _value(value)2375, _is_add(is_add)2376{2377ASSERT_VALUES2378}23792380// accessors2381bool is_add() const { return _is_add; }2382Value value() { return _value; }23832384// generic2385virtual void input_values_do(ValueVisitor* f) { UnsafeObjectOp::input_values_do(f);2386f->visit(&_value); }2387};23882389LEAF(ProfileCall, Instruction)2390private:2391ciMethod* _method;2392int _bci_of_invoke;2393ciMethod* _callee; // the method that is called at the given bci2394Value _recv;2395ciKlass* _known_holder;2396Values* _obj_args; // arguments for type profiling2397ArgsNonNullState _nonnull_state; // Do we know whether some arguments are never null?2398bool _inlined; // Are we profiling a call that is inlined23992400public:2401ProfileCall(ciMethod* method, int bci, ciMethod* callee, Value recv, ciKlass* known_holder, Values* obj_args, bool inlined)2402: Instruction(voidType)2403, _method(method)2404, _bci_of_invoke(bci)2405, _callee(callee)2406, _recv(recv)2407, _known_holder(known_holder)2408, _obj_args(obj_args)2409, _inlined(inlined)2410{2411// The ProfileCall has side-effects and must occur precisely where located2412pin();2413}24142415ciMethod* method() const { return _method; }2416int bci_of_invoke() const { return _bci_of_invoke; }2417ciMethod* callee() const { return _callee; }2418Value recv() const { return _recv; }2419ciKlass* known_holder() const { return _known_holder; }2420int nb_profiled_args() const { return _obj_args == NULL ? 0 : _obj_args->length(); }2421Value profiled_arg_at(int i) const { return _obj_args->at(i); }2422bool arg_needs_null_check(int i) const {2423return _nonnull_state.arg_needs_null_check(i);2424}2425bool inlined() const { return _inlined; }24262427void set_arg_needs_null_check(int i, bool check) {2428_nonnull_state.set_arg_needs_null_check(i, check);2429}24302431virtual void input_values_do(ValueVisitor* f) {2432if (_recv != NULL) {2433f->visit(&_recv);2434}2435for (int i = 0; i < nb_profiled_args(); i++) {2436f->visit(_obj_args->adr_at(i));2437}2438}2439};24402441LEAF(ProfileReturnType, Instruction)2442private:2443ciMethod* _method;2444ciMethod* _callee;2445int _bci_of_invoke;2446Value _ret;24472448public:2449ProfileReturnType(ciMethod* method, int bci, ciMethod* callee, Value ret)2450: Instruction(voidType)2451, _method(method)2452, _callee(callee)2453, _bci_of_invoke(bci)2454, _ret(ret)2455{2456set_needs_null_check(true);2457// The ProfileType has side-effects and must occur precisely where located2458pin();2459}24602461ciMethod* method() const { return _method; }2462ciMethod* callee() const { return _callee; }2463int bci_of_invoke() const { return _bci_of_invoke; }2464Value ret() const { return _ret; }24652466virtual void input_values_do(ValueVisitor* f) {2467if (_ret != NULL) {2468f->visit(&_ret);2469}2470}2471};24722473// Call some C runtime function that doesn't safepoint,2474// optionally passing the current thread as the first argument.2475LEAF(RuntimeCall, Instruction)2476private:2477const char* _entry_name;2478address _entry;2479Values* _args;2480bool _pass_thread; // Pass the JavaThread* as an implicit first argument24812482public:2483RuntimeCall(ValueType* type, const char* entry_name, address entry, Values* args, bool pass_thread = true)2484: Instruction(type)2485, _entry_name(entry_name)2486, _entry(entry)2487, _args(args)2488, _pass_thread(pass_thread) {2489ASSERT_VALUES2490pin();2491}24922493const char* entry_name() const { return _entry_name; }2494address entry() const { return _entry; }2495int number_of_arguments() const { return _args->length(); }2496Value argument_at(int i) const { return _args->at(i); }2497bool pass_thread() const { return _pass_thread; }24982499virtual void input_values_do(ValueVisitor* f) {2500for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));2501}2502};25032504// Use to trip invocation counter of an inlined method25052506LEAF(ProfileInvoke, Instruction)2507private:2508ciMethod* _inlinee;2509ValueStack* _state;25102511public:2512ProfileInvoke(ciMethod* inlinee, ValueStack* state)2513: Instruction(voidType)2514, _inlinee(inlinee)2515, _state(state)2516{2517// The ProfileInvoke has side-effects and must occur precisely where located QQQ???2518pin();2519}25202521ciMethod* inlinee() { return _inlinee; }2522ValueStack* state() { return _state; }2523virtual void input_values_do(ValueVisitor*) {}2524virtual void state_values_do(ValueVisitor*);2525};25262527LEAF(MemBar, Instruction)2528private:2529LIR_Code _code;25302531public:2532MemBar(LIR_Code code)2533: Instruction(voidType)2534, _code(code)2535{2536pin();2537}25382539LIR_Code code() { return _code; }25402541virtual void input_values_do(ValueVisitor*) {}2542};25432544class BlockPair: public CompilationResourceObj {2545private:2546BlockBegin* _from;2547BlockBegin* _to;2548public:2549BlockPair(BlockBegin* from, BlockBegin* to): _from(from), _to(to) {}2550BlockBegin* from() const { return _from; }2551BlockBegin* to() const { return _to; }2552bool is_same(BlockBegin* from, BlockBegin* to) const { return _from == from && _to == to; }2553bool is_same(BlockPair* p) const { return _from == p->from() && _to == p->to(); }2554void set_to(BlockBegin* b) { _to = b; }2555void set_from(BlockBegin* b) { _from = b; }2556};25572558typedef GrowableArray<BlockPair*> BlockPairList;25592560inline int BlockBegin::number_of_sux() const { assert(_end == NULL || _end->number_of_sux() == _successors.length(), "mismatch"); return _successors.length(); }2561inline BlockBegin* BlockBegin::sux_at(int i) const { assert(_end == NULL || _end->sux_at(i) == _successors.at(i), "mismatch"); return _successors.at(i); }2562inline void BlockBegin::add_successor(BlockBegin* sux) { assert(_end == NULL, "Would create mismatch with successors of BlockEnd"); _successors.append(sux); }25632564#undef ASSERT_VALUES25652566#endif // SHARE_C1_C1_INSTRUCTION_HPP256725682569