#ifdef TARGET_ARCH_x86
# include "c1_FpuStackSim_x86.hpp"
#endif
#ifdef TARGET_ARCH_aarch64
# include "c1_FpuStackSim_aarch64.hpp"
#endif
#ifdef TARGET_ARCH_sparc
# include "c1_FpuStackSim_sparc.hpp"
#endif
#ifdef TARGET_ARCH_arm
# include "c1_FpuStackSim_arm.hpp"
#endif
#ifdef TARGET_ARCH_ppc
# include "c1_FpuStackSim_ppc.hpp"
#endif
#endif // SHARE_VM_C1_C1_FPUSTACKSIM_HPP
C:\hotspot-69087d08d473\src\share\vm/c1/c1_FrameMap.cpp
#include "precompiled.hpp"
#include "c1/c1_FrameMap.hpp"
#include "c1/c1_LIR.hpp"
#include "runtime/sharedRuntime.hpp"
#ifdef TARGET_ARCH_x86
# include "vmreg_x86.inline.hpp"
#endif
#ifdef TARGET_ARCH_aarch64
# include "vmreg_aarch64.inline.hpp"
#endif
#ifdef TARGET_ARCH_sparc
# include "vmreg_sparc.inline.hpp"
#endif
#ifdef TARGET_ARCH_zero
# include "vmreg_zero.inline.hpp"
#endif
#ifdef TARGET_ARCH_arm
# include "vmreg_arm.inline.hpp"
#endif
#ifdef TARGET_ARCH_ppc
# include "vmreg_ppc.inline.hpp"
#endif
BasicTypeArray* FrameMap::signature_type_array_for(const ciMethod* method) {
ciSignature* sig = method->signature();
BasicTypeList* sta = new BasicTypeList(method->arg_size());
if (!method->is_static()) sta->append(T_OBJECT);
for (int i = 0; i < sig->count(); i++) {
ciType* type = sig->type_at(i);
BasicType t = type->basic_type();
if (t == T_ARRAY) {
t = T_OBJECT;
}
sta->append(t);
}
return sta;
}
CallingConvention* FrameMap::java_calling_convention(const BasicTypeArray* signature, bool outgoing) {
int i;
int sizeargs = 0;
for (i = 0; i < signature->length(); i++) {
sizeargs += type2size[signature->at(i)];
}
BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
int sig_index = 0;
for (i = 0; i < sizeargs; i++, sig_index++) {
sig_bt[i] = signature->at(sig_index);
if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
sig_bt[i + 1] = T_VOID;
i++;
}
}
intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, outgoing);
LIR_OprList* args = new LIR_OprList(signature->length());
for (i = 0; i < sizeargs;) {
BasicType t = sig_bt[i];
assert(t != T_VOID, "should be skipping these");
LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
args->append(opr);
if (opr->is_address()) {
LIR_Address* addr = opr->as_address_ptr();
assert(addr->disp() == (int)addr->disp(), "out of range value");
out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);
}
i += type2size[t];
}
assert(args->length() == signature->length(), "size mismatch");
out_preserve += SharedRuntime::out_preserve_stack_slots();
if (outgoing) {
update_reserved_argument_area_size(out_preserve * BytesPerWord);
}
return new CallingConvention(args, out_preserve);
}
CallingConvention* FrameMap::c_calling_convention(const BasicTypeArray* signature) {
int i;
int sizeargs = 0;
for (i = 0; i < signature->length(); i++) {
sizeargs += type2size[signature->at(i)];
}
BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
int sig_index = 0;
for (i = 0; i < sizeargs; i++, sig_index++) {
sig_bt[i] = signature->at(sig_index);
if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
sig_bt[i + 1] = T_VOID;
i++;
}
}
intptr_t out_preserve = SharedRuntime::c_calling_convention(sig_bt, regs, NULL, sizeargs);
LIR_OprList* args = new LIR_OprList(signature->length());
for (i = 0; i < sizeargs;) {
BasicType t = sig_bt[i];
assert(t != T_VOID, "should be skipping these");
bool outgoing = true;
LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
assert(type2size[opr->type()] == type2size[t], "type mismatch");
args->append(opr);
if (opr->is_address()) {
LIR_Address* addr = opr->as_address_ptr();
out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);
}
i += type2size[t];
}
assert(args->length() == signature->length(), "size mismatch");
out_preserve += SharedRuntime::out_preserve_stack_slots();
update_reserved_argument_area_size(out_preserve * BytesPerWord);
return new CallingConvention(args, out_preserve);
}
bool FrameMap::_init_done = false;
Register FrameMap::_cpu_rnr2reg [FrameMap::nof_cpu_regs];
int FrameMap::_cpu_reg2rnr [FrameMap::nof_cpu_regs];
FrameMap::FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size) {
assert(_init_done, "should already be completed");
_framesize = -1;
_num_spills = -1;
assert(monitors >= 0, "not set");
_num_monitors = monitors;
assert(reserved_argument_area_size >= 0, "not set");
_reserved_argument_area_size = MAX2(4, reserved_argument_area_size) * BytesPerWord;
_argcount = method->arg_size();
_argument_locations = new intArray(_argcount, -1);
_incoming_arguments = java_calling_convention(signature_type_array_for(method), false);
_oop_map_arg_count = _incoming_arguments->reserved_stack_slots();
int java_index = 0;
for (int i = 0; i < _incoming_arguments->length(); i++) {
LIR_Opr opr = _incoming_arguments->at(i);
if (opr->is_address()) {
LIR_Address* address = opr->as_address_ptr();
_argument_locations->at_put(java_index, address->disp() - STACK_BIAS);
_incoming_arguments->args()->at_put(i, LIR_OprFact::stack(java_index, as_BasicType(as_ValueType(address->type()))));
}
java_index += type2size[opr->type()];
}
}
bool FrameMap::finalize_frame(int nof_slots) {
assert(nof_slots >= 0, "must be positive");
assert(_num_spills == -1, "can only be set once");
_num_spills = nof_slots;
assert(_framesize == -1, "should only be calculated once");
_framesize = round_to(in_bytes(sp_offset_for_monitor_base(0)) +
_num_monitors * sizeof(BasicObjectLock) +
sizeof(intptr_t) + // offset of deopt orig pc
frame_pad_in_bytes,
StackAlignmentInBytes) / 4;
int java_index = 0;
for (int i = 0; i < _incoming_arguments->length(); i++) {
LIR_Opr opr = _incoming_arguments->at(i);
if (opr->is_stack()) {
_argument_locations->at_put(java_index, in_bytes(framesize_in_bytes()) +
_argument_locations->at(java_index));
}
java_index += type2size[opr->type()];
}
return validate_frame();
}
VMReg FrameMap::sp_offset2vmreg(ByteSize offset) const {
int offset_in_bytes = in_bytes(offset);
assert(offset_in_bytes % 4 == 0, "must be multiple of 4 bytes");
assert(offset_in_bytes / 4 < framesize() + oop_map_arg_count(), "out of range");
return VMRegImpl::stack2reg(offset_in_bytes / 4);
}
bool FrameMap::location_for_sp_offset(ByteSize byte_offset_from_sp,
Location::Type loc_type,
Location* loc) const {
int offset = in_bytes(byte_offset_from_sp);
assert(offset >= 0, "incorrect offset");
if (!Location::legal_offset_in_bytes(offset)) {
return false;
}
Location tmp_loc = Location::new_stk_loc(loc_type, offset);
return true;
}
bool FrameMap::locations_for_slot (int index, Location::Type loc_type,
Location* loc, Location* second) const {
ByteSize offset_from_sp = sp_offset_for_slot(index);
if (!location_for_sp_offset(offset_from_sp, loc_type, loc)) {
return false;
}
if (second != NULL) {
offset_from_sp = offset_from_sp + in_ByteSize(4);
return location_for_sp_offset(offset_from_sp, loc_type, second);
}
return true;
}
ByteSize FrameMap::sp_offset_for_slot(const int index) const {
if (index < argcount()) {
int offset = _argument_locations->at(index);
assert(offset != -1, "not a memory argument");
assert(offset >= framesize() * 4, "argument inside of frame");
return in_ByteSize(offset);
}
ByteSize offset = sp_offset_for_spill(index - argcount());
assert(in_bytes(offset) < framesize() * 4, "spill outside of frame");
return offset;
}
ByteSize FrameMap::sp_offset_for_double_slot(const int index) const {
ByteSize offset = sp_offset_for_slot(index);
if (index >= argcount()) {
assert(in_bytes(offset) + 4 < framesize() * 4, "spill outside of frame");
}
return offset;
}
ByteSize FrameMap::sp_offset_for_spill(const int index) const {
assert(index >= 0 && index < _num_spills, "out of range");
int offset = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
index * spill_slot_size_in_bytes;
return in_ByteSize(offset);
}
ByteSize FrameMap::sp_offset_for_monitor_base(const int index) const {
int end_of_spills = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
_num_spills * spill_slot_size_in_bytes;
int offset = (int) round_to(end_of_spills, HeapWordSize) + index * sizeof(BasicObjectLock);
return in_ByteSize(offset);
}
ByteSize FrameMap::sp_offset_for_monitor_lock(int index) const {
check_monitor_index(index);
return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::lock_offset_in_bytes());;
}
ByteSize FrameMap::sp_offset_for_monitor_object(int index) const {
check_monitor_index(index);
return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::obj_offset_in_bytes());
}
VMReg FrameMap::regname(LIR_Opr opr) const {
if (opr->is_single_cpu()) {
assert(!opr->is_virtual(), "should not see virtual registers here");
return opr->as_register()->as_VMReg();
} else if (opr->is_single_stack()) {
return sp_offset2vmreg(sp_offset_for_slot(opr->single_stack_ix()));
} else if (opr->is_address()) {
LIR_Address* addr = opr->as_address_ptr();
assert(addr->base() == stack_pointer(), "sp based addressing only");
return sp_offset2vmreg(in_ByteSize(addr->index()->as_jint()));
}
ShouldNotReachHere();
return VMRegImpl::Bad();
}
C:\hotspot-69087d08d473\src\share\vm/c1/c1_FrameMap.hpp
#ifndef SHARE_VM_C1_C1_FRAMEMAP_HPP
#define SHARE_VM_C1_C1_FRAMEMAP_HPP
#include "asm/assembler.hpp"
#include "c1/c1_Defs.hpp"
#include "c1/c1_LIR.hpp"
#include "code/vmreg.hpp"
#include "memory/allocation.hpp"
#include "runtime/frame.hpp"
#include "runtime/synchronizer.hpp"
#include "utilities/globalDefinitions.hpp"
class ciMethod;
class CallingConvention;
class BasicTypeArray;
class BasicTypeList;
class LIR_OprDesc;
typedef LIR_OprDesc* LIR_Opr;
class FrameMap : public CompilationResourceObj {
public:
enum {
nof_cpu_regs = pd_nof_cpu_regs_frame_map,
nof_fpu_regs = pd_nof_fpu_regs_frame_map,
nof_cpu_regs_reg_alloc = pd_nof_cpu_regs_reg_alloc,
nof_fpu_regs_reg_alloc = pd_nof_fpu_regs_reg_alloc,
max_nof_caller_save_cpu_regs = pd_nof_caller_save_cpu_regs_frame_map,
nof_caller_save_fpu_regs = pd_nof_caller_save_fpu_regs_frame_map,
spill_slot_size_in_bytes = 4
};
#ifdef TARGET_ARCH_x86
# include "c1_FrameMap_x86.hpp"
#endif
#ifdef TARGET_ARCH_aarch64
# include "c1_FrameMap_aarch64.hpp"
#endif
#ifdef TARGET_ARCH_sparc
# include "c1_FrameMap_sparc.hpp"
#endif
#ifdef TARGET_ARCH_arm
# include "c1_FrameMap_arm.hpp"
#endif
#ifdef TARGET_ARCH_ppc
# include "c1_FrameMap_ppc.hpp"
#endif
friend class LIR_OprDesc;
private:
static bool _init_done;
static Register _cpu_rnr2reg [nof_cpu_regs];
static int _cpu_reg2rnr [nof_cpu_regs];
static LIR_Opr _caller_save_cpu_regs [max_nof_caller_save_cpu_regs];
static LIR_Opr _caller_save_fpu_regs [nof_caller_save_fpu_regs];
int _framesize;
int _argcount;
int _num_monitors;
int _num_spills;
int _reserved_argument_area_size;
int _oop_map_arg_count;
CallingConvention* _incoming_arguments;
intArray* _argument_locations;
void check_spill_index (int spill_index) const { assert(spill_index >= 0, "bad index"); }
void check_monitor_index (int monitor_index) const { assert(monitor_index >= 0 &&
monitor_index < _num_monitors, "bad index"); }
static Register cpu_rnr2reg (int rnr) {
assert(_init_done, "tables not initialized");
debug_only(cpu_range_check(rnr);)
return _cpu_rnr2reg[rnr];
}
static int cpu_reg2rnr (Register reg) {
assert(_init_done, "tables not initialized");
debug_only(cpu_range_check(reg->encoding());)
return _cpu_reg2rnr[reg->encoding()];
}
static void map_register(int rnr, Register reg) {
debug_only(cpu_range_check(rnr);)
debug_only(cpu_range_check(reg->encoding());)
_cpu_rnr2reg[rnr] = reg;
_cpu_reg2rnr[reg->encoding()] = rnr;
}
void update_reserved_argument_area_size (int size) {
assert(size >= 0, "check");
_reserved_argument_area_size = MAX2(_reserved_argument_area_size, size);
}
protected:
#ifndef PRODUCT
static void cpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_cpu_regs, "cpu register number is too big"); }
static void fpu_range_check (int rnr) { assert(0 <= rnr && rnr < nof_fpu_regs, "fpu register number is too big"); }
#endif
ByteSize sp_offset_for_monitor_base(const int idx) const;
Address make_new_address(ByteSize sp_offset) const;
ByteSize sp_offset_for_slot(const int idx) const;
ByteSize sp_offset_for_double_slot(const int idx) const;
ByteSize sp_offset_for_spill(const int idx) const;
ByteSize sp_offset_for_monitor_lock(int monitor_index) const;
ByteSize sp_offset_for_monitor_object(int monitor_index) const;
VMReg sp_offset2vmreg(ByteSize offset) const;
bool validate_frame();
static LIR_Opr map_to_opr(BasicType type, VMRegPair* reg, bool incoming);
public:
static LIR_Opr stack_pointer();
static LIR_Opr method_handle_invoke_SP_save_opr();
static BasicTypeArray* signature_type_array_for(const ciMethod* method);
CallingConvention* c_calling_convention(const BasicTypeArray* signature);
CallingConvention* java_calling_convention(const BasicTypeArray* signature, bool outgoing);
ByteSize sp_offset_for_orig_pc() { return sp_offset_for_monitor_base(_num_monitors); }
static LIR_Opr as_opr(Register r) {
return LIR_OprFact::single_cpu(cpu_reg2rnr(r));
}
static LIR_Opr as_oop_opr(Register r) {
return LIR_OprFact::single_cpu_oop(cpu_reg2rnr(r));
}
static LIR_Opr as_metadata_opr(Register r) {
return LIR_OprFact::single_cpu_metadata(cpu_reg2rnr(r));
}
static LIR_Opr as_address_opr(Register r) {
return LIR_OprFact::single_cpu_address(cpu_reg2rnr(r));
}
FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size);
bool finalize_frame(int nof_slots);
int reserved_argument_area_size () const { return _reserved_argument_area_size; }
int framesize () const { assert(_framesize != -1, "hasn't been calculated"); return _framesize; }
ByteSize framesize_in_bytes () const { return in_ByteSize(framesize() * 4); }
int num_monitors () const { return _num_monitors; }
int num_spills () const { assert(_num_spills >= 0, "not set"); return _num_spills; }
int argcount () const { assert(_argcount >= 0, "not set"); return _argcount; }
int oop_map_arg_count() const { return _oop_map_arg_count; }
CallingConvention* incoming_arguments() const { return _incoming_arguments; }
Address address_for_slot(int index, int sp_adjust = 0) const {
return make_new_address(sp_offset_for_slot(index) + in_ByteSize(sp_adjust));
}
Address address_for_double_slot(int index, int sp_adjust = 0) const {
return make_new_address(sp_offset_for_double_slot(index) + in_ByteSize(sp_adjust));
}
Address address_for_monitor_lock(int monitor_index) const {
return make_new_address(sp_offset_for_monitor_lock(monitor_index));
}
Address address_for_monitor_object(int monitor_index) const {
return make_new_address(sp_offset_for_monitor_object(monitor_index));
}
bool location_for_sp_offset(ByteSize byte_offset_from_sp,
Location::Type loc_type, Location* loc) const;
bool location_for_monitor_lock (int monitor_index, Location* loc) const {
return location_for_sp_offset(sp_offset_for_monitor_lock(monitor_index), Location::normal, loc);
}
bool location_for_monitor_object(int monitor_index, Location* loc) const {
return location_for_sp_offset(sp_offset_for_monitor_object(monitor_index), Location::oop, loc);
}
bool locations_for_slot (int index, Location::Type loc_type,
Location* loc, Location* second = NULL) const;
VMReg slot_regname(int index) const {
return sp_offset2vmreg(sp_offset_for_slot(index));
}
VMReg monitor_object_regname(int monitor_index) const {
return sp_offset2vmreg(sp_offset_for_monitor_object(monitor_index));
}
VMReg regname(LIR_Opr opr) const;
static LIR_Opr caller_save_cpu_reg_at(int i) {
assert(i >= 0 && i < max_nof_caller_save_cpu_regs, "out of bounds");
return _caller_save_cpu_regs[i];
}
static LIR_Opr caller_save_fpu_reg_at(int i) {
assert(i >= 0 && i < nof_caller_save_fpu_regs, "out of bounds");
return _caller_save_fpu_regs[i];
}
static void initialize();
};
class CallingConvention: public ResourceObj {
private:
LIR_OprList* _args;
int _reserved_stack_slots;
public:
CallingConvention (LIR_OprList* args, int reserved_stack_slots)
: _args(args)
, _reserved_stack_slots(reserved_stack_slots) {}
LIR_OprList* args() { return _args; }
LIR_Opr at(int i) const { return _args->at(i); }
int length() const { return _args->length(); }
int reserved_stack_slots() const { return _reserved_stack_slots; }
#ifndef PRODUCT
void print () const {
for (int i = 0; i < length(); i++) {
at(i)->print();
}
}
#endif // PRODUCT
};
#endif // SHARE_VM_C1_C1_FRAMEMAP_HPP
C:\hotspot-69087d08d473\src\share\vm/c1/c1_globals.cpp
#include "precompiled.hpp"
#include "c1/c1_globals.hpp"
C1_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PD_DEVELOPER_FLAG, MATERIALIZE_PRODUCT_FLAG, MATERIALIZE_PD_PRODUCT_FLAG, MATERIALIZE_DIAGNOSTIC_FLAG, MATERIALIZE_NOTPRODUCT_FLAG)
C:\hotspot-69087d08d473\src\share\vm/c1/c1_globals.hpp
#ifndef SHARE_VM_C1_C1_GLOBALS_HPP
#define SHARE_VM_C1_C1_GLOBALS_HPP
#include "runtime/globals.hpp"
#ifdef TARGET_ARCH_x86
# include "c1_globals_x86.hpp"
#endif
#ifdef TARGET_ARCH_aarch64
# include "c1_globals_aarch64.hpp"
#endif
#ifdef TARGET_ARCH_sparc
# include "c1_globals_sparc.hpp"
#endif
#ifdef TARGET_ARCH_arm
# include "c1_globals_arm.hpp"
#endif
#ifdef TARGET_ARCH_ppc
# include "c1_globals_ppc.hpp"
#endif
#ifdef TARGET_OS_FAMILY_linux
# include "c1_globals_linux.hpp"
#endif
#ifdef TARGET_OS_FAMILY_solaris
# include "c1_globals_solaris.hpp"
#endif
#ifdef TARGET_OS_FAMILY_windows
# include "c1_globals_windows.hpp"
#endif
#ifdef TARGET_OS_FAMILY_aix
# include "c1_globals_aix.hpp"
#endif
#ifdef TARGET_OS_FAMILY_bsd
# include "c1_globals_bsd.hpp"
#endif
#define C1_FLAGS(develop, develop_pd, product, product_pd, diagnostic, notproduct) \
\
notproduct(bool, PrintC1Statistics, false, \
"Print Compiler1 statistics" ) \
\
notproduct(bool, PrintInitialBlockList, false, \
"Print block list of BlockListBuilder") \
\
notproduct(bool, PrintCFG, false, \
"Print control flow graph after each change") \
\
notproduct(bool, PrintCFG0, false, \
"Print control flow graph after construction") \
\
notproduct(bool, PrintCFG1, false, \
"Print control flow graph after optimizations") \
\
notproduct(bool, PrintCFG2, false, \
"Print control flow graph before code generation") \
\
notproduct(bool, PrintIRDuringConstruction, false, \
"Print IR as it's being constructed (helpful for debugging frontend)")\
\
notproduct(bool, PrintPhiFunctions, false, \
"Print phi functions when they are created and simplified") \
\
notproduct(bool, PrintIR, false, \
"Print full intermediate representation after each change") \
\
notproduct(bool, PrintIR0, false, \
"Print full intermediate representation after construction") \
\
notproduct(bool, PrintIR1, false, \
"Print full intermediate representation after optimizations") \
\
notproduct(bool, PrintIR2, false, \
"Print full intermediate representation before code generation") \
\
notproduct(bool, PrintSimpleStubs, false, \
"Print SimpleStubs") \
\
\
develop(bool, UseC1Optimizations, true, \
"Turn on C1 optimizations") \
\
develop(bool, SelectivePhiFunctions, true, \
"create phi functions at loop headers only when necessary") \
\
develop(bool, OptimizeIfOps, true, \
"Optimize multiple IfOps") \
\
develop(bool, DoCEE, true, \
"Do Conditional Expression Elimination to simplify CFG") \
\
develop(bool, PrintCEE, false, \
"Print Conditional Expression Elimination") \
\
develop(bool, UseLocalValueNumbering, true, \
"Use Local Value Numbering (embedded in GraphBuilder)") \
\
develop(bool, UseGlobalValueNumbering, true, \
"Use Global Value Numbering (separate phase)") \
\
product(bool, UseLoopInvariantCodeMotion, true, \
"Simple loop invariant code motion for short loops during GVN") \
\
develop(bool, TracePredicateFailedTraps, false, \
"trace runtime traps caused by predicate failure") \
\
develop(bool, StressLoopInvariantCodeMotion, false, \
"stress loop invariant code motion") \
\
develop(bool, TraceRangeCheckElimination, false, \
"Trace Range Check Elimination") \
\
develop(bool, AssertRangeCheckElimination, false, \
"Assert Range Check Elimination") \
\
develop(bool, StressRangeCheckElimination, false, \
"stress Range Check Elimination") \
\
develop(bool, PrintValueNumbering, false, \
"Print Value Numbering") \
\
product(intx, ValueMapInitialSize, 11, \
"Initial size of a value map") \
\
product(intx, ValueMapMaxLoopSize, 8, \
"maximum size of a loop optimized by global value numbering") \
\
develop(bool, EliminateBlocks, true, \
"Eliminate unneccessary basic blocks") \
\
develop(bool, PrintBlockElimination, false, \
"Print basic block elimination") \
\
develop(bool, EliminateNullChecks, true, \
"Eliminate unneccessary null checks") \
\
develop(bool, PrintNullCheckElimination, false, \
"Print null check elimination") \
\
develop(bool, EliminateFieldAccess, true, \
"Optimize field loads and stores") \
\
develop(bool, InlineMethodsWithExceptionHandlers, true, \
"Inline methods containing exception handlers " \
"(NOTE: does not work with current backend)") \
\
product(bool, InlineSynchronizedMethods, true, \
"Inline synchronized methods") \
\
develop(bool, InlineNIOCheckIndex, true, \
"Intrinsify java.nio.Buffer.checkIndex") \
\
develop(bool, CanonicalizeNodes, true, \
"Canonicalize graph nodes") \
\
develop(bool, PrintCanonicalization, false, \
"Print graph node canonicalization") \
\
develop(bool, UseTableRanges, true, \
"Faster versions of lookup table using ranges") \
\
develop_pd(bool, RoundFPResults, \
"Indicates whether rounding is needed for floating point results")\
\
develop(intx, NestedInliningSizeRatio, 90, \
"Percentage of prev. allowed inline size in recursive inlining") \
\
notproduct(bool, PrintIRWithLIR, false, \
"Print IR instructions with generated LIR") \
\
notproduct(bool, PrintLIRWithAssembly, false, \
"Show LIR instruction with generated assembly") \
\
develop(bool, CommentedAssembly, trueInDebug, \
"Show extra info in PrintNMethods output") \
\
develop(bool, LIRTracePeephole, false, \
"Trace peephole optimizer") \
\
develop(bool, LIRTraceExecution, false, \
"add LIR code which logs the execution of blocks") \
\
product_pd(bool, LIRFillDelaySlots, \
"fill delays on on SPARC with LIR") \
\
develop_pd(bool, CSEArrayLength, \
"Create separate nodes for length in array accesses") \
\
develop_pd(bool, TwoOperandLIRForm, \
"true if LIR requires src1 and dst to match in binary LIR ops") \
\
develop(intx, TraceLinearScanLevel, 0, \
"Debug levels for the linear scan allocator") \
\
develop(bool, StressLinearScan, false, \
"scramble block order used by LinearScan (stress test)") \
\
product(bool, TimeLinearScan, false, \
"detailed timing of LinearScan phases") \
\
develop(bool, TimeEachLinearScan, false, \
"print detailed timing of each LinearScan run") \
\
develop(bool, CountLinearScan, false, \
"collect statistic counters during LinearScan") \
\
\
develop(bool, C1Breakpoint, false, \
"Sets a breakpoint at entry of each compiled method") \
\
develop(bool, ImplicitDiv0Checks, true, \
"Use implicit division by zero checks") \
\
develop(bool, PinAllInstructions, false, \
"All instructions are pinned") \
\
develop(bool, UseFastNewInstance, true, \
"Use fast inlined instance allocation") \
\
develop(bool, UseFastNewTypeArray, true, \
"Use fast inlined type array allocation") \
\
develop(bool, UseFastNewObjectArray, true, \
"Use fast inlined object array allocation") \
\
develop(bool, UseFastLocking, true, \
"Use fast inlined locking code") \
\
develop(bool, UseSlowPath, false, \
"For debugging: test slow cases by always using them") \
\
develop(bool, GenerateArrayStoreCheck, true, \
"Generates code for array store checks") \
\
develop(bool, DeoptC1, true, \
"Use deoptimization in C1") \
\
develop(bool, PrintBailouts, false, \
"Print bailout and its reason") \
\
develop(bool, TracePatching, false, \
"Trace patching of field access on uninitialized classes") \
\
develop(bool, PatchALot, false, \
"Marks all fields as having unloaded classes") \
\
develop(bool, PrintNotLoaded, false, \
"Prints where classes are not loaded during code generation") \
\
develop(bool, PrintLIR, false, \
"print low-level IR") \
\
develop(bool, BailoutAfterHIR, false, \
"bailout of compilation after building of HIR") \
\
develop(bool, BailoutAfterLIR, false, \
"bailout of compilation after building of LIR") \
\
develop(bool, BailoutOnExceptionHandlers, false, \
"bailout of compilation for methods with exception handlers") \
\
develop(bool, InstallMethods, true, \
"Install methods at the end of successful compilations") \
\
develop(intx, NMethodSizeLimit, (64*K)*wordSize, \
"Maximum size of a compiled method.") \
\
develop(bool, TraceFPUStack, false, \
"Trace emulation of the FPU stack (intel only)") \
\
develop(bool, TraceFPURegisterUsage, false, \
"Trace usage of FPU registers at start of blocks (intel only)") \
\
develop(bool, OptimizeUnsafes, true, \
"Optimize raw unsafe ops") \
\
develop(bool, PrintUnsafeOptimization, false, \
"Print optimization of raw unsafe ops") \
\
develop(intx, InstructionCountCutoff, 37000, \
"If GraphBuilder adds this many instructions, bails out") \
\
product_pd(intx, SafepointPollOffset, \
"Offset added to polling address (Intel only)") \
\
develop(bool, ComputeExactFPURegisterUsage, true, \
"Compute additional live set for fpu registers to simplify fpu stack merge (Intel only)") \
\
product(bool, C1ProfileCalls, true, \
"Profile calls when generating code for updating MDOs") \
\
product(bool, C1ProfileVirtualCalls, true, \
"Profile virtual calls when generating code for updating MDOs") \
\
product(bool, C1ProfileInlinedCalls, true, \
"Profile inlined calls when generating code for updating MDOs") \
\
product(bool, C1ProfileBranches, true, \
"Profile branches when generating code for updating MDOs") \
\
product(bool, C1ProfileCheckcasts, true, \
"Profile checkcasts when generating code for updating MDOs") \
\
product(bool, C1OptimizeVirtualCallProfiling, true, \
"Use CHA and exact type results at call sites when updating MDOs")\
\
product(bool, C1UpdateMethodData, trueInTiered, \
"Update MethodData*s in Tier1-generated code") \
\
develop(bool, PrintCFGToFile, false, \
"print control flow graph to a separate file during compilation") \
\
diagnostic(bool, C1PatchInvokeDynamic, true, \
"Patch invokedynamic appendix not known at compile time") \
\
C1_FLAGS(DECLARE_DEVELOPER_FLAG, DECLARE_PD_DEVELOPER_FLAG, DECLARE_PRODUCT_FLAG, DECLARE_PD_PRODUCT_FLAG, DECLARE_DIAGNOSTIC_FLAG, DECLARE_NOTPRODUCT_FLAG)
#endif // SHARE_VM_C1_C1_GLOBALS_HPP
C:\hotspot-69087d08d473\src\share\vm/c1/c1_GraphBuilder.cpp
#include "precompiled.hpp"
#include "c1/c1_CFGPrinter.hpp"
#include "c1/c1_Canonicalizer.hpp"
#include "c1/c1_Compilation.hpp"
#include "c1/c1_GraphBuilder.hpp"
#include "c1/c1_InstructionPrinter.hpp"
#include "ci/ciCallSite.hpp"
#include "ci/ciField.hpp"
#include "ci/ciKlass.hpp"
#include "ci/ciMemberName.hpp"
#include "compiler/compileBroker.hpp"
#include "interpreter/bytecode.hpp"
#include "jfr/jfrEvents.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/compilationPolicy.hpp"
#include "utilities/bitMap.inline.hpp"
class BlockListBuilder VALUE_OBJ_CLASS_SPEC {
private:
Compilation* _compilation;
IRScope* _scope;
BlockList _blocks; // internal list of all blocks
BlockList* _bci2block; // mapping from bci to blocks for GraphBuilder
BitMap _active; // for iteration of control flow graph
BitMap _visited; // for iteration of control flow graph
intArray _loop_map; // caches the information if a block is contained in a loop
int _next_loop_index; // next free loop number
int _next_block_number; // for reverse postorder numbering of blocks
Compilation* compilation() const { return _compilation; }
IRScope* scope() const { return _scope; }
ciMethod* method() const { return scope()->method(); }
XHandlers* xhandlers() const { return scope()->xhandlers(); }
void bailout(const char* msg) const { compilation()->bailout(msg); }
bool bailed_out() const { return compilation()->bailed_out(); }
BlockBegin* make_block_at(int bci, BlockBegin* predecessor);
void handle_exceptions(BlockBegin* current, int cur_bci);
void handle_jsr(BlockBegin* current, int sr_bci, int next_bci);
void store_one(BlockBegin* current, int local);
void store_two(BlockBegin* current, int local);
void set_entries(int osr_bci);
void set_leaders();
void make_loop_header(BlockBegin* block);
void mark_loops();
int mark_loops(BlockBegin* b, bool in_subroutine);
#ifndef PRODUCT
void print();
#endif
public:
BlockListBuilder(Compilation* compilation, IRScope* scope, int osr_bci);
BlockList* bci2block() const { return _bci2block; }
};
BlockListBuilder::BlockListBuilder(Compilation* compilation, IRScope* scope, int osr_bci)
: _compilation(compilation)
, _scope(scope)
, _blocks(16)
, _bci2block(new BlockList(scope->method()->code_size(), NULL))
, _next_block_number(0)
, _active() // size not known yet
, _visited() // size not known yet
, _next_loop_index(0)
, _loop_map() // size not known yet
{
set_entries(osr_bci);
set_leaders();
CHECK_BAILOUT();
mark_loops();
NOT_PRODUCT(if (PrintInitialBlockList) print());
#ifndef PRODUCT
if (PrintCFGToFile) {
stringStream title;
title.print("BlockListBuilder ");
scope->method()->print_name(&title);
CFGPrinter::print_cfg(_bci2block, title.as_string(), false, false);
}
#endif
}
void BlockListBuilder::set_entries(int osr_bci) {
BlockBegin* std_entry = make_block_at(0, NULL);
if (scope()->caller() == NULL) {
std_entry->set(BlockBegin::std_entry_flag);
}
if (osr_bci != -1) {
BlockBegin* osr_entry = make_block_at(osr_bci, NULL);
osr_entry->set(BlockBegin::osr_entry_flag);
}
XHandlers* list = xhandlers();
const int n = list->length();
for (int i = 0; i < n; i++) {
XHandler* h = list->handler_at(i);
BlockBegin* entry = make_block_at(h->handler_bci(), NULL);
entry->set(BlockBegin::exception_entry_flag);
h->set_entry_block(entry);
}
}
BlockBegin* BlockListBuilder::make_block_at(int cur_bci, BlockBegin* predecessor) {
assert(method()->bci_block_start().at(cur_bci), "wrong block starts of MethodLivenessAnalyzer");
BlockBegin* block = _bci2block->at(cur_bci);
if (block == NULL) {
block = new BlockBegin(cur_bci);
block->init_stores_to_locals(method()->max_locals());
_bci2block->at_put(cur_bci, block);
_blocks.append(block);
assert(predecessor == NULL || predecessor->bci() < cur_bci, "targets for backward branches must already exist");
}
if (predecessor != NULL) {
if (block->is_set(BlockBegin::exception_entry_flag)) {
BAILOUT_("Exception handler can be reached by both normal and exceptional control flow", block);
}
predecessor->add_successor(block);
block->increment_total_preds();
}
return block;
}
inline void BlockListBuilder::store_one(BlockBegin* current, int local) {
current->stores_to_locals().set_bit(local);
}
inline void BlockListBuilder::store_two(BlockBegin* current, int local) {
store_one(current, local);
store_one(current, local + 1);
}
void BlockListBuilder::handle_exceptions(BlockBegin* current, int cur_bci) {
XHandlers* list = xhandlers();
const int n = list->length();
for (int i = 0; i < n; i++) {
XHandler* h = list->handler_at(i);
if (h->covers(cur_bci)) {
BlockBegin* entry = h->entry_block();
assert(entry != NULL && entry == _bci2block->at(h->handler_bci()), "entry must be set");
assert(entry->is_set(BlockBegin::exception_entry_flag), "flag must be set");
if (!current->is_successor(entry)) {
current->add_successor(entry);
entry->increment_total_preds();
}
if (h->catch_type() == 0) break;
}
}
}
void BlockListBuilder::handle_jsr(BlockBegin* current, int sr_bci, int next_bci) {
make_block_at(next_bci, current);
BlockBegin* sr_block = make_block_at(sr_bci, current);
if (!sr_block->is_set(BlockBegin::subroutine_entry_flag)) {
sr_block->set(BlockBegin::subroutine_entry_flag);
}
}
void BlockListBuilder::set_leaders() {
bool has_xhandlers = xhandlers()->has_handlers();
BlockBegin* current = NULL;
BitMap bci_block_start = method()->bci_block_start();
ciBytecodeStream s(method());
while (s.next() != ciBytecodeStream::EOBC()) {
int cur_bci = s.cur_bci();
if (bci_block_start.at(cur_bci)) {
current = make_block_at(cur_bci, current);
}
assert(current != NULL, "must have current block");
if (has_xhandlers && GraphBuilder::can_trap(method(), s.cur_bc())) {
handle_exceptions(current, cur_bci);
}
switch (s.cur_bc()) {
case Bytecodes::_iinc: store_one(current, s.get_index()); break;
case Bytecodes::_istore: store_one(current, s.get_index()); break;
case Bytecodes::_lstore: store_two(current, s.get_index()); break;
case Bytecodes::_fstore: store_one(current, s.get_index()); break;
case Bytecodes::_dstore: store_two(current, s.get_index()); break;
case Bytecodes::_astore: store_one(current, s.get_index()); break;
case Bytecodes::_istore_0: store_one(current, 0); break;
case Bytecodes::_istore_1: store_one(current, 1); break;
case Bytecodes::_istore_2: store_one(current, 2); break;
case Bytecodes::_istore_3: store_one(current, 3); break;
case Bytecodes::_lstore_0: store_two(current, 0); break;
case Bytecodes::_lstore_1: store_two(current, 1); break;
case Bytecodes::_lstore_2: store_two(current, 2); break;
case Bytecodes::_lstore_3: store_two(current, 3); break;
case Bytecodes::_fstore_0: store_one(current, 0); break;
case Bytecodes::_fstore_1: store_one(current, 1); break;
case Bytecodes::_fstore_2: store_one(current, 2); break;
case Bytecodes::_fstore_3: store_one(current, 3); break;
case Bytecodes::_dstore_0: store_two(current, 0); break;
case Bytecodes::_dstore_1: store_two(current, 1); break;
case Bytecodes::_dstore_2: store_two(current, 2); break;
case Bytecodes::_dstore_3: store_two(current, 3); break;
case Bytecodes::_astore_0: store_one(current, 0); break;
case Bytecodes::_astore_1: store_one(current, 1); break;
case Bytecodes::_astore_2: store_one(current, 2); break;
case Bytecodes::_astore_3: store_one(current, 3); break;
case Bytecodes::_athrow: // fall through
case Bytecodes::_ret: // fall through
case Bytecodes::_ireturn: // fall through
case Bytecodes::_lreturn: // fall through
case Bytecodes::_freturn: // fall through
case Bytecodes::_dreturn: // fall through
case Bytecodes::_areturn: // fall through
case Bytecodes::_return:
current = NULL;
break;
case Bytecodes::_ifeq: // fall through
case Bytecodes::_ifne: // fall through
case Bytecodes::_iflt: // fall through
case Bytecodes::_ifge: // fall through
case Bytecodes::_ifgt: // fall through
case Bytecodes::_ifle: // fall through
case Bytecodes::_if_icmpeq: // fall through
case Bytecodes::_if_icmpne: // fall through
case Bytecodes::_if_icmplt: // fall through
case Bytecodes::_if_icmpge: // fall through
case Bytecodes::_if_icmpgt: // fall through
case Bytecodes::_if_icmple: // fall through
case Bytecodes::_if_acmpeq: // fall through
case Bytecodes::_if_acmpne: // fall through
case Bytecodes::_ifnull: // fall through
case Bytecodes::_ifnonnull:
make_block_at(s.next_bci(), current);
make_block_at(s.get_dest(), current);
current = NULL;
break;
case Bytecodes::_goto:
make_block_at(s.get_dest(), current);
current = NULL;
break;
case Bytecodes::_goto_w:
make_block_at(s.get_far_dest(), current);
current = NULL;
break;
case Bytecodes::_jsr:
handle_jsr(current, s.get_dest(), s.next_bci());
current = NULL;
break;
case Bytecodes::_jsr_w:
handle_jsr(current, s.get_far_dest(), s.next_bci());
current = NULL;
break;
case Bytecodes::_tableswitch: {
Bytecode_tableswitch sw(&s);
int l = sw.length();
for (int i = 0; i < l; i++) {
make_block_at(cur_bci + sw.dest_offset_at(i), current);
}
make_block_at(cur_bci + sw.default_offset(), current);
current = NULL;
break;
}
case Bytecodes::_lookupswitch: {
Bytecode_lookupswitch sw(&s);
int l = sw.number_of_pairs();
for (int i = 0; i < l; i++) {
make_block_at(cur_bci + sw.pair_at(i).offset(), current);
}
make_block_at(cur_bci + sw.default_offset(), current);
current = NULL;
break;
}
}
}
}
void BlockListBuilder::mark_loops() {
ResourceMark rm;
_active = BitMap(BlockBegin::number_of_blocks()); _active.clear();
_visited = BitMap(BlockBegin::number_of_blocks()); _visited.clear();
_loop_map = intArray(BlockBegin::number_of_blocks(), 0);
_next_loop_index = 0;
_next_block_number = _blocks.length();
mark_loops(_bci2block->at(0), false);
assert(_next_block_number >= 0, "invalid block numbers");
}
void BlockListBuilder::make_loop_header(BlockBegin* block) {
if (block->is_set(BlockBegin::exception_entry_flag)) {
return;
}
if (!block->is_set(BlockBegin::parser_loop_header_flag)) {
block->set(BlockBegin::parser_loop_header_flag);
assert(_loop_map.at(block->block_id()) == 0, "must not be set yet");
assert(0 <= _next_loop_index && _next_loop_index < BitsPerInt, "_next_loop_index is used as a bit-index in integer");
_loop_map.at_put(block->block_id(), 1 << _next_loop_index);
if (_next_loop_index < 31) _next_loop_index++;
} else {
assert(is_power_of_2((unsigned int)_loop_map.at(block->block_id())), "exactly one bit must be set");
}
}
int BlockListBuilder::mark_loops(BlockBegin* block, bool in_subroutine) {
int block_id = block->block_id();
if (_visited.at(block_id)) {
if (_active.at(block_id)) {
make_loop_header(block);
}
return _loop_map.at(block_id);
}
if (block->is_set(BlockBegin::subroutine_entry_flag)) {
in_subroutine = true;
}
_visited.set_bit(block_id);
_active.set_bit(block_id);
intptr_t loop_state = 0;
for (int i = block->number_of_sux() - 1; i >= 0; i--) {
loop_state |= mark_loops(block->sux_at(i), in_subroutine);
}
_active.clear_bit(block_id);
block->set_depth_first_number(_next_block_number);
_next_block_number--;
if (loop_state != 0 || in_subroutine ) {
scope()->requires_phi_function().set_union(block->stores_to_locals());
}
if (block->is_set(BlockBegin::parser_loop_header_flag)) {
int header_loop_state = _loop_map.at(block_id);
assert(is_power_of_2((unsigned)header_loop_state), "exactly one bit must be set");
if (header_loop_state >= 0) {
clear_bits(loop_state, header_loop_state);
}
}
_loop_map.at_put(block_id, loop_state);
return loop_state;
}
#ifndef PRODUCT
int compare_depth_first(BlockBegin** a, BlockBegin** b) {
return (*a)->depth_first_number() - (*b)->depth_first_number();
}
void BlockListBuilder::print() {
tty->print("----- initial block list of BlockListBuilder for method ");
method()->print_short_name();
tty->cr();
_blocks.sort(compare_depth_first);
for (int i = 0; i < _blocks.length(); i++) {
BlockBegin* cur = _blocks.at(i);
tty->print("%4d: B%-4d bci: %-4d preds: %-4d ", cur->depth_first_number(), cur->block_id(), cur->bci(), cur->total_preds());
tty->print(cur->is_set(BlockBegin::std_entry_flag) ? " std" : " ");
tty->print(cur->is_set(BlockBegin::osr_entry_flag) ? " osr" : " ");
tty->print(cur->is_set(BlockBegin::exception_entry_flag) ? " ex" : " ");
tty->print(cur->is_set(BlockBegin::subroutine_entry_flag) ? " sr" : " ");
tty->print(cur->is_set(BlockBegin::parser_loop_header_flag) ? " lh" : " ");
if (cur->number_of_sux() > 0) {
tty->print(" sux: ");
for (int j = 0; j < cur->number_of_sux(); j++) {
BlockBegin* sux = cur->sux_at(j);
tty->print("B%d ", sux->block_id());
}
}
tty->cr();
}
}
#endif
class FieldBuffer: public CompilationResourceObj {
private:
GrowableArray<Value> _values;
public:
FieldBuffer() {}
void kill() {
_values.trunc_to(0);
}
Value at(ciField* field) {
assert(field->holder()->is_loaded(), "must be a loaded field");
int offset = field->offset();
if (offset < _values.length()) {
return _values.at(offset);
} else {
return NULL;
}
}
void at_put(ciField* field, Value value) {
assert(field->holder()->is_loaded(), "must be a loaded field");
int offset = field->offset();
_values.at_put_grow(offset, value, NULL);
}
};
class MemoryBuffer: public CompilationResourceObj {
private:
FieldBuffer _values;
GrowableArray<Value> _objects;
GrowableArray<Value> _newobjects;
GrowableArray<FieldBuffer*> _fields;
public:
MemoryBuffer() {}
StoreField* store(StoreField* st) {
if (!EliminateFieldAccess) {
return st;
}
Value object = st->obj();
Value value = st->value();
ciField* field = st->field();
if (field->holder()->is_loaded()) {
int offset = field->offset();
int index = _newobjects.find(object);
if (index != -1) {
FieldBuffer* buf = _fields.at(index);
if (buf->at(field) == NULL && is_default_value(value)) {
#ifndef PRODUCT
if (PrintIRDuringConstruction && Verbose) {
tty->print_cr("Eliminated store for object %d:", index);
st->print_line();
}
#endif
return NULL;
} else {
buf->at_put(field, value);
}
} else {
_objects.at_put_grow(offset, object, NULL);
_values.at_put(field, value);
}
store_value(value);
} else {
kill();
}
return st;
}
bool is_default_value(Value value) {
Constant* con = value->as_Constant();
if (con) {
switch (con->type()->tag()) {
case intTag: return con->type()->as_IntConstant()->value() == 0;
case longTag: return con->type()->as_LongConstant()->value() == 0;
case floatTag: return jint_cast(con->type()->as_FloatConstant()->value()) == 0;
case doubleTag: return jlong_cast(con->type()->as_DoubleConstant()->value()) == jlong_cast(0);
case objectTag: return con->type() == objectNull;
default: ShouldNotReachHere();
}
}
return false;
}
Value load(LoadField* load) {
if (!EliminateFieldAccess) {
return load;
}
if (RoundFPResults && UseSSE < 2 && load->type()->is_float_kind()) {
return load;
}
ciField* field = load->field();
Value object = load->obj();
if (field->holder()->is_loaded() && !field->is_volatile()) {
int offset = field->offset();
Value result = NULL;
int index = _newobjects.find(object);
if (index != -1) {
result = _fields.at(index)->at(field);
} else if (_objects.at_grow(offset, NULL) == object) {
result = _values.at(field);
}
if (result != NULL) {
#ifndef PRODUCT
if (PrintIRDuringConstruction && Verbose) {
tty->print_cr("Eliminated load: ");
load->print_line();
}
#endif
assert(result->type()->tag() == load->type()->tag(), "wrong types");
return result;
}
}
return load;
}
void new_instance(NewInstance* object) {
int index = _newobjects.length();
_newobjects.append(object);
if (_fields.at_grow(index, NULL) == NULL) {
_fields.at_put(index, new FieldBuffer());
} else {
_fields.at(index)->kill();
}
}
void store_value(Value value) {
int index = _newobjects.find(value);
if (index != -1) {
_newobjects.remove_at(index);
_fields.append(_fields.at(index));
_fields.remove_at(index);
}
}
void kill() {
_newobjects.trunc_to(0);
_objects.trunc_to(0);
_values.kill();
}
};
GraphBuilder::ScopeData::ScopeData(ScopeData* parent)
: _parent(parent)
, _bci2block(NULL)
, _scope(NULL)
, _has_handler(false)
, _stream(NULL)
, _work_list(NULL)
, _parsing_jsr(false)
, _jsr_xhandlers(NULL)
, _caller_stack_size(-1)
, _continuation(NULL)
, _num_returns(0)
, _cleanup_block(NULL)
, _cleanup_return_prev(NULL)
, _cleanup_state(NULL)
{
if (parent != NULL) {
_max_inline_size = (intx) ((float) NestedInliningSizeRatio * (float) parent->max_inline_size() / 100.0f);
} else {
_max_inline_size = MaxInlineSize;
}
if (_max_inline_size < MaxTrivialSize) {
_max_inline_size = MaxTrivialSize;
}
}
void GraphBuilder::kill_all() {
if (UseLocalValueNumbering) {
vmap()->kill_all();
}
_memory->kill();
}
BlockBegin* GraphBuilder::ScopeData::block_at(int bci) {
if (parsing_jsr()) {
BlockBegin* block = bci2block()->at(bci);
if (block != NULL && block == parent()->bci2block()->at(bci)) {
BlockBegin* new_block = new BlockBegin(block->bci());
#ifndef PRODUCT
if (PrintInitialBlockList) {
tty->print_cr("CFG: cloned block %d (bci %d) as block %d for jsr",
block->block_id(), block->bci(), new_block->block_id());
}
#endif
new_block->set_depth_first_number(block->depth_first_number());
if (block->is_set(BlockBegin::parser_loop_header_flag)) new_block->set(BlockBegin::parser_loop_header_flag);
if (block->is_set(BlockBegin::subroutine_entry_flag)) new_block->set(BlockBegin::subroutine_entry_flag);
if (block->is_set(BlockBegin::exception_entry_flag)) new_block->set(BlockBegin::exception_entry_flag);
if (block->is_set(BlockBegin::was_visited_flag)) new_block->set(BlockBegin::was_visited_flag);
bci2block()->at_put(bci, new_block);
block = new_block;
}
return block;
} else {
return bci2block()->at(bci);
}
}
XHandlers* GraphBuilder::ScopeData::xhandlers() const {
if (_jsr_xhandlers == NULL) {
assert(!parsing_jsr(), "");
return scope()->xhandlers();
}
assert(parsing_jsr(), "");
return _jsr_xhandlers;
}
void GraphBuilder::ScopeData::set_scope(IRScope* scope) {
_scope = scope;
bool parent_has_handler = false;
if (parent() != NULL) {
parent_has_handler = parent()->has_handler();
}
_has_handler = parent_has_handler || scope->xhandlers()->has_handlers();
}
void GraphBuilder::ScopeData::set_inline_cleanup_info(BlockBegin* block,
Instruction* return_prev,
ValueStack* return_state) {
_cleanup_block = block;
_cleanup_return_prev = return_prev;
_cleanup_state = return_state;
}
void GraphBuilder::ScopeData::add_to_work_list(BlockBegin* block) {
if (_work_list == NULL) {
_work_list = new BlockList();
}
if (!block->is_set(BlockBegin::is_on_work_list_flag)) {
if (parsing_jsr()) {
if (block == jsr_continuation()) {
return;
}
} else {
if (block == continuation()) {
return;
}
}
block->set(BlockBegin::is_on_work_list_flag);
_work_list->push(block);
sort_top_into_worklist(_work_list, block);
}
}
void GraphBuilder::sort_top_into_worklist(BlockList* worklist, BlockBegin* top) {
assert(worklist->top() == top, "");
const int dfn = top->depth_first_number();
assert(dfn != -1, "unknown depth first number");
int i = worklist->length()-2;
while (i >= 0) {
BlockBegin* b = worklist->at(i);
if (b->depth_first_number() < dfn) {
worklist->at_put(i+1, b);
} else {
break;
}
i --;
}
if (i >= -1) worklist->at_put(i + 1, top);
}
BlockBegin* GraphBuilder::ScopeData::remove_from_work_list() {
if (is_work_list_empty()) {
return NULL;
}
return _work_list->pop();
}
bool GraphBuilder::ScopeData::is_work_list_empty() const {
return (_work_list == NULL || _work_list->length() == 0);
}
void GraphBuilder::ScopeData::setup_jsr_xhandlers() {
assert(parsing_jsr(), "");
XHandlers* handlers = new XHandlers(scope()->xhandlers());
const int n = handlers->length();
for (int i = 0; i < n; i++) {
XHandler* h = handlers->handler_at(i);
assert(h->handler_bci() != SynchronizationEntryBCI, "must be real");
h->set_entry_block(block_at(h->handler_bci()));
}
_jsr_xhandlers = handlers;
}
int GraphBuilder::ScopeData::num_returns() {
if (parsing_jsr()) {
return parent()->num_returns();
}
return _num_returns;
}
void GraphBuilder::ScopeData::incr_num_returns() {
if (parsing_jsr()) {
parent()->incr_num_returns();
} else {
++_num_returns;
}
}
#define INLINE_BAILOUT(msg) { inline_bailout(msg); return false; }
void GraphBuilder::load_constant() {
ciConstant con = stream()->get_constant();
if (con.basic_type() == T_ILLEGAL) {
BAILOUT("could not resolve a constant");
} else {
ValueType* t = illegalType;
ValueStack* patch_state = NULL;
switch (con.basic_type()) {
case T_BOOLEAN: t = new IntConstant (con.as_boolean()); break;
case T_BYTE : t = new IntConstant (con.as_byte ()); break;
case T_CHAR : t = new IntConstant (con.as_char ()); break;
case T_SHORT : t = new IntConstant (con.as_short ()); break;
case T_INT : t = new IntConstant (con.as_int ()); break;
case T_LONG : t = new LongConstant (con.as_long ()); break;
case T_FLOAT : t = new FloatConstant (con.as_float ()); break;
case T_DOUBLE : t = new DoubleConstant (con.as_double ()); break;
case T_ARRAY : t = new ArrayConstant (con.as_object ()->as_array ()); break;
case T_OBJECT :
{
ciObject* obj = con.as_object();
if (!obj->is_loaded()
|| (PatchALot && obj->klass() != ciEnv::current()->String_klass())) {
patch_state = copy_state_before();
t = new ObjectConstant(obj);
} else {
assert(obj->is_instance(), "must be java_mirror of klass");
t = new InstanceConstant(obj->as_instance());
}
break;
}
default : ShouldNotReachHere();
}
Value x;
if (patch_state != NULL) {
x = new Constant(t, patch_state);
} else {
x = new Constant(t);
}
push(t, append(x));
}
}
void GraphBuilder::load_local(ValueType* type, int index) {
Value x = state()->local_at(index);
assert(x != NULL && !x->type()->is_illegal(), "access of illegal local variable");
push(type, x);
}
void GraphBuilder::store_local(ValueType* type, int index) {
Value x = pop(type);
store_local(state(), x, index);
}
void GraphBuilder::store_local(ValueStack* state, Value x, int index) {
if (parsing_jsr()) {
if (x->type()->is_address()) {
scope_data()->set_jsr_return_address_local(index);
for (ScopeData* cur_scope_data = scope_data()->parent();
cur_scope_data != NULL && cur_scope_data->parsing_jsr() && cur_scope_data->scope() == scope();
cur_scope_data = cur_scope_data->parent()) {
if (cur_scope_data->jsr_return_address_local() == index) {
BAILOUT("subroutine overwrites return address from previous subroutine");
}
}
} else if (index == scope_data()->jsr_return_address_local()) {
scope_data()->set_jsr_return_address_local(-1);
}
}
state->store_local(index, round_fp(x));
}
void GraphBuilder::load_indexed(BasicType type) {
ValueStack* state_before = copy_state_indexed_access();
compilation()->set_has_access_indexed(true);
Value index = ipop();
Value array = apop();
Value length = NULL;
if (CSEArrayLength ||
(array->as_AccessField() && array->as_AccessField()->field()->is_constant()) ||
(array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) {
length = append(new ArrayLength(array, state_before));
}
push(as_ValueType(type), append(new LoadIndexed(array, index, length, type, state_before)));
}
void GraphBuilder::store_indexed(BasicType type) {
ValueStack* state_before = copy_state_indexed_access();
compilation()->set_has_access_indexed(true);
Value value = pop(as_ValueType(type));
Value index = ipop();
Value array = apop();
Value length = NULL;
if (CSEArrayLength ||
(array->as_AccessField() && array->as_AccessField()->field()->is_constant()) ||
(array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) {
length = append(new ArrayLength(array, state_before));
}
ciType* array_type = array->declared_type();
bool check_boolean = false;
if (array_type != NULL) {
if (array_type->is_loaded() &&
array_type->as_array_klass()->element_type()->basic_type() == T_BOOLEAN) {
assert(type == T_BYTE, "boolean store uses bastore");
Value mask = append(new Constant(new IntConstant(1)));
value = append(new LogicOp(Bytecodes::_iand, value, mask));
}
} else if (type == T_BYTE) {
check_boolean = true;
}
StoreIndexed* result = new StoreIndexed(array, index, length, type, value, state_before, check_boolean);
append(result);
_memory->store_value(value);
if (type == T_OBJECT && is_profiling()) {
compilation()->set_would_profile(true);
if (profile_checkcasts()) {
result->set_profiled_method(method());
result->set_profiled_bci(bci());
result->set_should_profile(true);
}
}
}
void GraphBuilder::stack_op(Bytecodes::Code code) {
switch (code) {
case Bytecodes::_pop:
{ state()->raw_pop();
}
break;
case Bytecodes::_pop2:
{ state()->raw_pop();
state()->raw_pop();
}
break;
case Bytecodes::_dup:
{ Value w = state()->raw_pop();
state()->raw_push(w);
state()->raw_push(w);
}
break;
case Bytecodes::_dup_x1:
{ Value w1 = state()->raw_pop();
Value w2 = state()->raw_pop();
state()->raw_push(w1);
state()->raw_push(w2);
state()->raw_push(w1);
}
break;
case Bytecodes::_dup_x2:
{ Value w1 = state()->raw_pop();
Value w2 = state()->raw_pop();
Value w3 = state()->raw_pop();
state()->raw_push(w1);
state()->raw_push(w3);
state()->raw_push(w2);
state()->raw_push(w1);
}
break;
case Bytecodes::_dup2:
{ Value w1 = state()->raw_pop();
Value w2 = state()->raw_pop();
state()->raw_push(w2);
state()->raw_push(w1);
state()->raw_push(w2);
state()->raw_push(w1);
}
break;
case Bytecodes::_dup2_x1:
{ Value w1 = state()->raw_pop();
Value w2 = state()->raw_pop();
Value w3 = state()->raw_pop();
state()->raw_push(w2);
state()->raw_push(w1);
state()->raw_push(w3);
state()->raw_push(w2);
state()->raw_push(w1);
}
break;
case Bytecodes::_dup2_x2:
{ Value w1 = state()->raw_pop();
Value w2 = state()->raw_pop();
Value w3 = state()->raw_pop();
Value w4 = state()->raw_pop();
state()->raw_push(w2);
state()->raw_push(w1);
state()->raw_push(w4);
state()->raw_push(w3);
state()->raw_push(w2);
state()->raw_push(w1);
}
break;
case Bytecodes::_swap:
{ Value w1 = state()->raw_pop();
Value w2 = state()->raw_pop();
state()->raw_push(w1);
state()->raw_push(w2);
}
break;
default:
ShouldNotReachHere();
break;
}
}
void GraphBuilder::arithmetic_op(ValueType* type, Bytecodes::Code code, ValueStack* state_before) {
Value y = pop(type);
Value x = pop(type);
Value res = new ArithmeticOp(code, x, y, method()->is_strict(), state_before);
res = append(res);
if (method()->is_strict()) {
res = round_fp(res);
}
push(type, res);
}
void GraphBuilder::negate_op(ValueType* type) {
push(type, append(new NegateOp(pop(type))));
}
void GraphBuilder::shift_op(ValueType* type, Bytecodes::Code code) {
Value s = ipop();
Value x = pop(type);
if (CanonicalizeNodes && code == Bytecodes::_iushr) {
IntConstant* s1 = s->type()->as_IntConstant();
if (s1 != NULL) {
ShiftOp* l = x->as_ShiftOp();
if (l != NULL && l->op() == Bytecodes::_ishl) {
IntConstant* s0 = l->y()->type()->as_IntConstant();
if (s0 != NULL) {
const int s0c = s0->value() & 0x1F; // only the low 5 bits are significant for shifts
const int s1c = s1->value() & 0x1F; // only the low 5 bits are significant for shifts
if (s0c == s1c) {
if (s0c == 0) {
ipush(l->x());
} else {
assert(0 < s0c && s0c < BitsPerInt, "adjust code below to handle corner cases");
const int m = (1 << (BitsPerInt - s0c)) - 1;
Value s = append(new Constant(new IntConstant(m)));
ipush(append(new LogicOp(Bytecodes::_iand, l->x(), s)));
}
return;
}
}
}
}
}
push(type, append(new ShiftOp(code, x, s)));
}
void GraphBuilder::logic_op(ValueType* type, Bytecodes::Code code) {
Value y = pop(type);
Value x = pop(type);
push(type, append(new LogicOp(code, x, y)));
}
void GraphBuilder::compare_op(ValueType* type, Bytecodes::Code code) {
ValueStack* state_before = copy_state_before();
Value y = pop(type);
Value x = pop(type);
ipush(append(new CompareOp(code, x, y, state_before)));
}
void GraphBuilder::convert(Bytecodes::Code op, BasicType from, BasicType to) {
push(as_ValueType(to), append(new Convert(op, pop(as_ValueType(from)), as_ValueType(to))));
}
void GraphBuilder::increment() {
int index = stream()->get_index();
int delta = stream()->is_wide() ? (signed short)Bytes::get_Java_u2(stream()->cur_bcp() + 4) : (signed char)(stream()->cur_bcp()[2]);
load_local(intType, index);
ipush(append(new Constant(new IntConstant(delta))));
arithmetic_op(intType, Bytecodes::_iadd);
store_local(intType, index);
}
void GraphBuilder::_goto(int from_bci, int to_bci) {
Goto *x = new Goto(block_at(to_bci), to_bci <= from_bci);
if (is_profiling()) {
compilation()->set_would_profile(true);
x->set_profiled_bci(bci());
if (profile_branches()) {
x->set_profiled_method(method());
x->set_should_profile(true);
}
}
append(x);
}
void GraphBuilder::if_node(Value x, If::Condition cond, Value y, ValueStack* state_before) {
BlockBegin* tsux = block_at(stream()->get_dest());
BlockBegin* fsux = block_at(stream()->next_bci());
bool is_bb = tsux->bci() < stream()->cur_bci() || fsux->bci() < stream()->cur_bci();
Instruction *i = append(new If(x, cond, false, y, tsux, fsux, (is_bb || compilation()->is_optimistic()) ? state_before : NULL, is_bb));
assert(i->as_Goto() == NULL ||
(i->as_Goto()->sux_at(0) == tsux && i->as_Goto()->is_safepoint() == tsux->bci() < stream()->cur_bci()) ||
(i->as_Goto()->sux_at(0) == fsux && i->as_Goto()->is_safepoint() == fsux->bci() < stream()->cur_bci()),
"safepoint state of Goto returned by canonicalizer incorrect");
if (is_profiling()) {
If* if_node = i->as_If();
if (if_node != NULL) {
compilation()->set_would_profile(true);
if_node->set_profiled_bci(bci());
if (profile_branches()) {
if_node->set_profiled_method(method());
if_node->set_should_profile(true);
if (if_node->tsux() == fsux) {
if_node->set_swapped(true);
}
}
return;
}
Goto *goto_node = i->as_Goto();
if (goto_node != NULL) {
compilation()->set_would_profile(true);
goto_node->set_profiled_bci(bci());
if (profile_branches()) {
goto_node->set_profiled_method(method());
goto_node->set_should_profile(true);
if (goto_node->default_sux() == tsux) {
goto_node->set_direction(Goto::taken);
} else if (goto_node->default_sux() == fsux) {
goto_node->set_direction(Goto::not_taken);
} else {
ShouldNotReachHere();
}
}
return;
}
}
}
void GraphBuilder::if_zero(ValueType* type, If::Condition cond) {
Value y = append(new Constant(intZero));
ValueStack* state_before = copy_state_before();
Value x = ipop();
if_node(x, cond, y, state_before);
}
void GraphBuilder::if_null(ValueType* type, If::Condition cond) {
Value y = append(new Constant(objectNull));
ValueStack* state_before = copy_state_before();
Value x = apop();
if_node(x, cond, y, state_before);
}
void GraphBuilder::if_same(ValueType* type, If::Condition cond) {
ValueStack* state_before = copy_state_before();
Value y = pop(type);
Value x = pop(type);
if_node(x, cond, y, state_before);
}
void GraphBuilder::jsr(int dest) {
for (ScopeData* cur_scope_data = scope_data();
cur_scope_data != NULL && cur_scope_data->parsing_jsr() && cur_scope_data->scope() == scope();
cur_scope_data = cur_scope_data->parent()) {
if (cur_scope_data->jsr_entry_bci() == dest) {
BAILOUT("too-complicated jsr/ret structure");
}
}
push(addressType, append(new Constant(new AddressConstant(next_bci()))));
if (!try_inline_jsr(dest)) {
return; // bailed out while parsing and inlining subroutine
}
}
void GraphBuilder::ret(int local_index) {
if (!parsing_jsr()) BAILOUT("ret encountered while not parsing subroutine");
if (local_index != scope_data()->jsr_return_address_local()) {
BAILOUT("can not handle complicated jsr/ret constructs");
}
append(new Goto(scope_data()->jsr_continuation(), false));
}
void GraphBuilder::table_switch() {
Bytecode_tableswitch sw(stream());
const int l = sw.length();
if (CanonicalizeNodes && l == 1) {
Value key = append(new Constant(new IntConstant(sw.low_key())));
BlockBegin* tsux = block_at(bci() + sw.dest_offset_at(0));
BlockBegin* fsux = block_at(bci() + sw.default_offset());
bool is_bb = tsux->bci() < bci() || fsux->bci() < bci();
ValueStack* state_before = copy_state_if_bb(is_bb);
append(new If(ipop(), If::eql, true, key, tsux, fsux, state_before, is_bb));
} else {
BlockList* sux = new BlockList(l + 1, NULL);
int i;
bool has_bb = false;
for (i = 0; i < l; i++) {
sux->at_put(i, block_at(bci() + sw.dest_offset_at(i)));
if (sw.dest_offset_at(i) < 0) has_bb = true;
}
if (sw.default_offset() < 0) has_bb = true;
sux->at_put(i, block_at(bci() + sw.default_offset()));
ValueStack* state_before = copy_state_if_bb(has_bb);
Instruction* res = append(new TableSwitch(ipop(), sux, sw.low_key(), state_before, has_bb));
#ifdef ASSERT
if (res->as_Goto()) {
for (i = 0; i < l; i++) {
if (sux->at(i) == res->as_Goto()->sux_at(0)) {
assert(res->as_Goto()->is_safepoint() == sw.dest_offset_at(i) < 0, "safepoint state of Goto returned by canonicalizer incorrect");
}
}
}
#endif
}
}
void GraphBuilder::lookup_switch() {
Bytecode_lookupswitch sw(stream());
const int l = sw.number_of_pairs();
if (CanonicalizeNodes && l == 1) {
LookupswitchPair pair = sw.pair_at(0);
Value key = append(new Constant(new IntConstant(pair.match())));
BlockBegin* tsux = block_at(bci() + pair.offset());
BlockBegin* fsux = block_at(bci() + sw.default_offset());
bool is_bb = tsux->bci() < bci() || fsux->bci() < bci();
ValueStack* state_before = copy_state_if_bb(is_bb);;
append(new If(ipop(), If::eql, true, key, tsux, fsux, state_before, is_bb));
} else {
BlockList* sux = new BlockList(l + 1, NULL);
intArray* keys = new intArray(l, 0);
int i;
bool has_bb = false;
for (i = 0; i < l; i++) {
LookupswitchPair pair = sw.pair_at(i);
if (pair.offset() < 0) has_bb = true;
sux->at_put(i, block_at(bci() + pair.offset()));
keys->at_put(i, pair.match());
}
if (sw.default_offset() < 0) has_bb = true;
sux->at_put(i, block_at(bci() + sw.default_offset()));
ValueStack* state_before = copy_state_if_bb(has_bb);
Instruction* res = append(new LookupSwitch(ipop(), sux, keys, state_before, has_bb));
#ifdef ASSERT
if (res->as_Goto()) {
for (i = 0; i < l; i++) {
if (sux->at(i) == res->as_Goto()->sux_at(0)) {
assert(res->as_Goto()->is_safepoint() == sw.pair_at(i).offset() < 0, "safepoint state of Goto returned by canonicalizer incorrect");
}
}
}
#endif
}
}
void GraphBuilder::call_register_finalizer() {
Value receiver = state()->local_at(0);
assert(receiver != NULL, "must have a receiver");
ciType* declared_type = receiver->declared_type();
ciType* exact_type = receiver->exact_type();
if (exact_type == NULL &&
receiver->as_Local() &&
receiver->as_Local()->java_index() == 0) {
ciInstanceKlass* ik = compilation()->method()->holder();
if (ik->is_final()) {
exact_type = ik;
} else if (UseCHA && !(ik->has_subklass() || ik->is_interface())) {
compilation()->dependency_recorder()->assert_leaf_type(ik);
exact_type = ik;
} else {
declared_type = ik;
}
}
bool needs_check = true;
if (exact_type != NULL) {
needs_check = exact_type->as_instance_klass()->has_finalizer();
} else if (declared_type != NULL) {
ciInstanceKlass* ik = declared_type->as_instance_klass();
if (!Dependencies::has_finalizable_subclass(ik)) {
compilation()->dependency_recorder()->assert_has_no_finalizable_subclasses(ik);
needs_check = false;
}
}
if (needs_check) {
ValueStack* state_before = copy_state_for_exception();
load_local(objectType, 0);
append_split(new Intrinsic(voidType, vmIntrinsics::_Object_init,
state()->pop_arguments(1),
true, state_before, true));
}
}
void GraphBuilder::method_return(Value x) {
if (RegisterFinalizersAtInit &&
method()->intrinsic_id() == vmIntrinsics::_Object_init) {
call_register_finalizer();
}
bool need_mem_bar = false;
if (method()->name() == ciSymbol::object_initializer_name() &&
scope()->wrote_final()) {
need_mem_bar = true;
}
BasicType bt = method()->return_type()->basic_type();
switch (bt) {
case T_BYTE:
{
Value shift = append(new Constant(new IntConstant(24)));
x = append(new ShiftOp(Bytecodes::_ishl, x, shift));
x = append(new ShiftOp(Bytecodes::_ishr, x, shift));
break;
}
case T_SHORT:
{
Value shift = append(new Constant(new IntConstant(16)));
x = append(new ShiftOp(Bytecodes::_ishl, x, shift));
x = append(new ShiftOp(Bytecodes::_ishr, x, shift));
break;
}
case T_CHAR:
{
Value mask = append(new Constant(new IntConstant(0xFFFF)));
x = append(new LogicOp(Bytecodes::_iand, x, mask));
break;
}
case T_BOOLEAN:
{
Value mask = append(new Constant(new IntConstant(1)));
x = append(new LogicOp(Bytecodes::_iand, x, mask));
break;
}
}
if (continuation() != NULL) {
int invoke_bci = state()->caller_state()->bci();
if (x != NULL) {
ciMethod* caller = state()->scope()->caller()->method();
Bytecodes::Code invoke_raw_bc = caller->raw_code_at_bci(invoke_bci);
if (invoke_raw_bc == Bytecodes::_invokehandle || invoke_raw_bc == Bytecodes::_invokedynamic) {
ciType* declared_ret_type = caller->get_declared_signature_at_bci(invoke_bci)->return_type();
if (declared_ret_type->is_klass() && x->exact_type() == NULL &&
x->declared_type() != declared_ret_type && declared_ret_type != compilation()->env()->Object_klass()) {
x = append(new TypeCast(declared_ret_type->as_klass(), x, copy_state_before()));
}
}
}
assert(!method()->is_synchronized() || InlineSynchronizedMethods, "can not inline synchronized methods yet");
if (compilation()->env()->dtrace_method_probes()) {
Values* args = new Values(1);
args->push(append(new Constant(new MethodConstant(method()))));
append(new RuntimeCall(voidType, "dtrace_method_exit", CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), args));
}
if (method()->is_synchronized()) {
assert(state()->locks_size() == 1, "receiver must be locked here");
monitorexit(state()->lock_at(0), SynchronizationEntryBCI);
}
if (need_mem_bar) {
append(new MemBar(lir_membar_storestore));
}
set_state(state()->caller_state()->copy_for_parsing());
if (x != NULL) {
state()->push(x->type(), x);
if (profile_return() && x->type()->is_object_kind()) {
ciMethod* caller = state()->scope()->method();
ciMethodData* md = caller->method_data_or_null();
ciProfileData* data = md->bci_to_data(invoke_bci);
if (data != NULL && (data->is_CallTypeData() || data->is_VirtualCallTypeData())) {
bool has_return = data->is_CallTypeData() ? ((ciCallTypeData*)data)->has_return() : ((ciVirtualCallTypeData*)data)->has_return();
if (has_return) {
profile_return_type(x, method(), caller, invoke_bci);
}
}
}
}
Goto* goto_callee = new Goto(continuation(), false);
if (num_returns() == 0) {
set_inline_cleanup_info();
}
append_with_bci(goto_callee, scope_data()->continuation()->bci());
incr_num_returns();
return;
}
state()->truncate_stack(0);
if (method()->is_synchronized()) {
Value receiver;
if (!method()->is_static()) {
receiver = _initial_state->local_at(0);
} else {
receiver = append(new Constant(new ClassConstant(method()->holder())));
}
append_split(new MonitorExit(receiver, state()->unlock()));
}
if (need_mem_bar) {
append(new MemBar(lir_membar_storestore));
}
append(new Return(x));
}
void GraphBuilder::access_field(Bytecodes::Code code) {
bool will_link;
ciField* field = stream()->get_field(will_link);
ciInstanceKlass* holder = field->holder();
BasicType field_type = field->type()->basic_type();
ValueType* type = as_ValueType(field_type);
const bool needs_patching = !holder->is_loaded() ||
!field->will_link(method()->holder(), code) ||
PatchALot;
ValueStack* state_before = NULL;
if (!holder->is_initialized() || needs_patching) {
state_before = copy_state_before();
}
Value obj = NULL;
if (code == Bytecodes::_getstatic || code == Bytecodes::_putstatic) {
if (state_before != NULL) {
obj = new Constant(new InstanceConstant(holder->java_mirror()), state_before);
} else {
obj = new Constant(new InstanceConstant(holder->java_mirror()));
}
}
if (field->is_final() && (code == Bytecodes::_putfield)) {
scope()->set_wrote_final();
}
const int offset = !needs_patching ? field->offset() : -1;
switch (code) {
case Bytecodes::_getstatic: {
Instruction* constant = NULL;
if (field->is_constant() && !PatchALot) {
ciConstant field_val = field->constant_value();
BasicType field_type = field_val.basic_type();
switch (field_type) {
case T_ARRAY:
case T_OBJECT:
if (field_val.as_object()->should_be_constant()) {
constant = new Constant(as_ValueType(field_val));
}
break;
default:
constant = new Constant(as_ValueType(field_val));
}
}
if (constant != NULL) {
push(type, append(constant));
} else {
if (state_before == NULL) {
state_before = copy_state_for_exception();
}
push(type, append(new LoadField(append(obj), offset, field, true,
state_before, needs_patching)));
}
break;
}
case Bytecodes::_putstatic:
{ Value val = pop(type);
if (state_before == NULL) {
state_before = copy_state_for_exception();
}
if (field->type()->basic_type() == T_BOOLEAN) {
Value mask = append(new Constant(new IntConstant(1)));
val = append(new LogicOp(Bytecodes::_iand, val, mask));
}
append(new StoreField(append(obj), offset, field, val, true, state_before, needs_patching));
}
break;
case Bytecodes::_getfield: {
Instruction* constant = NULL;
obj = apop();
ObjectType* obj_type = obj->type()->as_ObjectType();
if (obj_type->is_constant() && !PatchALot) {
ciObject* const_oop = obj_type->constant_value();
if (!const_oop->is_null_object() && const_oop->is_loaded()) {
if (field->is_constant()) {
ciConstant field_val = field->constant_value_of(const_oop);
BasicType field_type = field_val.basic_type();
switch (field_type) {
case T_ARRAY:
case T_OBJECT:
if (field_val.as_object()->should_be_constant()) {
constant = new Constant(as_ValueType(field_val));
}
break;
default:
constant = new Constant(as_ValueType(field_val));
}
if (FoldStableValues && field->is_stable() && field_val.is_null_or_zero()) {
constant = NULL;
}
} else {
if (const_oop->is_call_site()) {
ciCallSite* call_site = const_oop->as_call_site();
if (field->is_call_site_target()) {
ciMethodHandle* target = call_site->get_target();
if (target != NULL) { // just in case
ciConstant field_val(T_OBJECT, target);
constant = new Constant(as_ValueType(field_val));
if (!call_site->is_constant_call_site()) {
dependency_recorder()->assert_call_site_target_value(call_site, target);
}
}
}
}
}
}
}
if (constant != NULL) {
push(type, append(constant));
} else {
if (state_before == NULL) {
state_before = copy_state_for_exception();
}
LoadField* load = new LoadField(obj, offset, field, false, state_before, needs_patching);
Value replacement = !needs_patching ? _memory->load(load) : load;
if (replacement != load) {
assert(replacement->is_linked() || !replacement->can_be_linked(), "should already by linked");
BasicType bt = field->type()->basic_type();
switch (bt) {
case T_BOOLEAN:
case T_BYTE:
replacement = append(new Convert(Bytecodes::_i2b, replacement, as_ValueType(bt)));
break;
case T_CHAR:
replacement = append(new Convert(Bytecodes::_i2c, replacement, as_ValueType(bt)));
break;
case T_SHORT:
replacement = append(new Convert(Bytecodes::_i2s, replacement, as_ValueType(bt)));
break;
default:
break;
}
push(type, replacement);
} else {
push(type, append(load));
}
}
break;
}
case Bytecodes::_putfield: {
Value val = pop(type);
obj = apop();
if (state_before == NULL) {
state_before = copy_state_for_exception();
}
if (field->type()->basic_type() == T_BOOLEAN) {
Value mask = append(new Constant(new IntConstant(1)));
val = append(new LogicOp(Bytecodes::_iand, val, mask));
}
StoreField* store = new StoreField(obj, offset, field, val, false, state_before, needs_patching);
if (!needs_patching) store = _memory->store(store);
if (store != NULL) {
append(store);
}
break;
}
default:
ShouldNotReachHere();
break;
}
}
Dependencies* GraphBuilder::dependency_recorder() const {
assert(DeoptC1, "need debug information");
return compilation()->dependency_recorder();
}
Values* GraphBuilder::args_list_for_profiling(ciMethod* target, int& start, bool may_have_receiver) {
int n = 0;
bool has_receiver = may_have_receiver && Bytecodes::has_receiver(method()->java_code_at_bci(bci()));
start = has_receiver ? 1 : 0;
if (profile_arguments()) {
ciProfileData* data = method()->method_data()->bci_to_data(bci());
if (data != NULL && (data->is_CallTypeData() || data->is_VirtualCallTypeData())) {
n = data->is_CallTypeData() ? data->as_CallTypeData()->number_of_arguments() : data->as_VirtualCallTypeData()->number_of_arguments();
}
}
if (profile_parameters() && target != NULL) {
if (target->method_data() != NULL && target->method_data()->parameters_type_data() != NULL) {
n = MAX2(n, target->method_data()->parameters_type_data()->number_of_parameters() - start);
}
}
if (n > 0) {
return new Values(n);
}
return NULL;
}
void GraphBuilder::check_args_for_profiling(Values* obj_args, int expected) {
#ifdef ASSERT
bool ignored_will_link;
ciSignature* declared_signature = NULL;
ciMethod* real_target = method()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
assert(expected == obj_args->length() || real_target->is_method_handle_intrinsic(), "missed on arg?");
#endif
}
Values* GraphBuilder::collect_args_for_profiling(Values* args, ciMethod* target, bool may_have_receiver) {
int start = 0;
Values* obj_args = args_list_for_profiling(target, start, may_have_receiver);
if (obj_args == NULL) {
return NULL;
}
int s = obj_args->size();
for (int i = start, j = 0; j < s && i < args->length(); i++) {
if (args->at(i)->type()->is_object_kind()) {
obj_args->push(args->at(i));
j++;
}
}
check_args_for_profiling(obj_args, s);
return obj_args;
}
void GraphBuilder::invoke(Bytecodes::Code code) {
bool will_link;
ciSignature* declared_signature = NULL;
ciMethod* target = stream()->get_method(will_link, &declared_signature);
ciKlass* holder = stream()->get_declared_method_holder();
const Bytecodes::Code bc_raw = stream()->cur_bc_raw();
assert(declared_signature != NULL, "cannot be null");
if (!C1PatchInvokeDynamic && Bytecodes::has_optional_appendix(bc_raw) && !will_link) {
BAILOUT("unlinked call site (C1PatchInvokeDynamic is off)");
}
{
const bool is_invokestatic = bc_raw == Bytecodes::_invokestatic;
const bool allow_static =
is_invokestatic ||
bc_raw == Bytecodes::_invokehandle ||
bc_raw == Bytecodes::_invokedynamic;
if (target->is_loaded()) {
if (( target->is_static() && !allow_static) ||
(!target->is_static() && is_invokestatic)) {
BAILOUT("will cause link error");
}
}
}
ciInstanceKlass* klass = target->holder();
ciInstanceKlass* calling_klass = method()->holder();
ciInstanceKlass* callee_holder = ciEnv::get_instance_klass_for_declared_method_holder(holder);
ciInstanceKlass* actual_recv = callee_holder;
CompileLog* log = compilation()->log();
if (log != NULL)
log->elem("call method='%d' instr='%s'",
log->identify(target),
Bytecodes::name(code));
if (bc_raw == Bytecodes::_invokespecial && !target->is_object_initializer()) {
ciInstanceKlass* sender_klass =
calling_klass->is_anonymous() ? calling_klass->host_klass() :
calling_klass;
if (sender_klass->is_interface()) {
int index = state()->stack_size() - (target->arg_size_no_receiver() + 1);
Value receiver = state()->stack_at(index);
CheckCast* c = new CheckCast(sender_klass, receiver, copy_state_before());
c->set_invokespecial_receiver_check();
state()->stack_at_put(index, append_split(c));
}
}
if (target->is_loaded() && !target->is_abstract() && target->can_be_statically_bound()) {
switch (bc_raw) {
case Bytecodes::_invokevirtual:
code = Bytecodes::_invokespecial;
break;
case Bytecodes::_invokehandle:
code = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokespecial;
break;
}
} else {
if (bc_raw == Bytecodes::_invokehandle) {
assert(!will_link, "should come here only for unlinked call");
code = Bytecodes::_invokespecial;
}
}
bool patch_for_appendix = false;
int patching_appendix_arg = 0;
if (C1PatchInvokeDynamic &&
(Bytecodes::has_optional_appendix(bc_raw) && (!will_link || PatchALot))) {
Value arg = append(new Constant(new ObjectConstant(compilation()->env()->unloaded_ciinstance()), copy_state_before()));
apush(arg);
patch_for_appendix = true;
patching_appendix_arg = (will_link && stream()->has_appendix()) ? 0 : 1;
} else if (stream()->has_appendix()) {
ciObject* appendix = stream()->get_appendix();
Value arg = append(new Constant(new ObjectConstant(appendix)));
apush(arg);
}
ciMethod* cha_monomorphic_target = NULL;
ciMethod* exact_target = NULL;
Value better_receiver = NULL;
if (UseCHA && DeoptC1 && klass->is_loaded() && target->is_loaded() &&
!(// %%% FIXME: Are both of these relevant?
target->is_method_handle_intrinsic() ||
target->is_compiled_lambda_form()) &&
!patch_for_appendix) {
Value receiver = NULL;
ciInstanceKlass* receiver_klass = NULL;
bool type_is_exact = false;
if (will_link && !target->is_static()) {
int index = state()->stack_size() - (target->arg_size_no_receiver() + 1);
receiver = state()->stack_at(index);
ciType* type = receiver->exact_type();
if (type != NULL && type->is_loaded() &&
type->is_instance_klass() && !type->as_instance_klass()->is_interface()) {
receiver_klass = (ciInstanceKlass*) type;
type_is_exact = true;
}
if (type == NULL) {
type = receiver->declared_type();
if (type != NULL && type->is_loaded() &&
type->is_instance_klass() && !type->as_instance_klass()->is_interface()) {
receiver_klass = (ciInstanceKlass*) type;
if (receiver_klass->is_leaf_type() && !receiver_klass->is_final()) {
dependency_recorder()->assert_leaf_type(receiver_klass);
type_is_exact = true;
}
}
}
}
if (receiver_klass != NULL && type_is_exact &&
receiver_klass->is_loaded() && code != Bytecodes::_invokespecial) {
exact_target = target->resolve_invoke(calling_klass, receiver_klass);
if (exact_target != NULL) {
target = exact_target;
code = Bytecodes::_invokespecial;
}
}
if (receiver_klass != NULL &&
receiver_klass->is_subtype_of(actual_recv) &&
actual_recv->is_initialized()) {
actual_recv = receiver_klass;
}
if ((code == Bytecodes::_invokevirtual && callee_holder->is_initialized()) ||
(code == Bytecodes::_invokeinterface && callee_holder->is_initialized() && !actual_recv->is_interface())) {
cha_monomorphic_target = target->find_monomorphic_target(calling_klass, callee_holder, actual_recv);
} else if (code == Bytecodes::_invokeinterface && callee_holder->is_loaded() && receiver != NULL) {
ciInstanceKlass* singleton = NULL;
if (target->holder()->nof_implementors() == 1) {
singleton = target->holder()->implementor();
assert(singleton != NULL && singleton != target->holder(),
"just checking");
assert(holder->is_interface(), "invokeinterface to non interface?");
ciInstanceKlass* decl_interface = (ciInstanceKlass*)holder;
if (!holder->is_loaded() || decl_interface->nof_implementors() != 1 || decl_interface->has_default_methods()) {
singleton = NULL;
}
}
if (singleton) {
cha_monomorphic_target = target->find_monomorphic_target(calling_klass, target->holder(), singleton);
if (cha_monomorphic_target != NULL) {
klass = cha_monomorphic_target->holder();
actual_recv = target->holder();
CheckCast* c = new CheckCast(klass, receiver, copy_state_for_exception());
c->set_incompatible_class_change_check();
c->set_direct_compare(klass->is_final());
better_receiver = append_split(c);
}
}
}
}
if (cha_monomorphic_target != NULL) {
if (cha_monomorphic_target->is_abstract()) {
cha_monomorphic_target = NULL;
}
}
if (cha_monomorphic_target != NULL) {
if (!(target->is_final_method())) {
dependency_recorder()->assert_unique_concrete_method(actual_recv, cha_monomorphic_target);
}
code = Bytecodes::_invokespecial;
}
if (!PatchALot && Inline && klass->is_loaded() &&
(klass->is_initialized() || klass->is_interface() && target->holder()->is_initialized())
&& target->is_loaded()
&& !patch_for_appendix) {
assert(target->is_loaded(), "callee must be known");
if (code == Bytecodes::_invokestatic ||
code == Bytecodes::_invokespecial ||
code == Bytecodes::_invokevirtual && target->is_final_method() ||
code == Bytecodes::_invokedynamic) {
ciMethod* inline_target = (cha_monomorphic_target != NULL) ? cha_monomorphic_target : target;
bool success = try_inline(inline_target, (cha_monomorphic_target != NULL) || (exact_target != NULL), code, better_receiver);
CHECK_BAILOUT();
clear_inline_bailout();
if (success) {
if (compilation()->env()->jvmti_can_hotswap_or_post_breakpoint()) {
dependency_recorder()->assert_evol_method(inline_target);
}
return;
}
} else {
print_inlining(target, "no static binding", /*success*/ false);
}
} else {
print_inlining(target, "not inlineable", /*success*/ false);
}
CHECK_BAILOUT();
bool is_loaded = target->is_loaded();
ValueType* result_type = as_ValueType(declared_signature->return_type());
ValueStack* state_before = copy_state_exhandling();
const bool has_receiver =
code == Bytecodes::_invokespecial ||
code == Bytecodes::_invokevirtual ||
code == Bytecodes::_invokeinterface;
Values* args = state()->pop_arguments(target->arg_size_no_receiver() + patching_appendix_arg);
Value recv = has_receiver ? apop() : NULL;
int vtable_index = Method::invalid_vtable_index;
#ifdef SPARC
if (!UseInlineCaches && is_loaded && code == Bytecodes::_invokevirtual
&& !target->can_be_statically_bound()) {
vtable_index = target->resolve_vtable_index(calling_klass, holder);
}
#endif
if (recv != NULL &&
(code == Bytecodes::_invokespecial ||
!is_loaded || target->is_final())) {
null_check(recv);
}
if (is_profiling()) {
if (recv != NULL && profile_calls()) {
null_check(recv);
}
compilation()->set_would_profile(true);
if (profile_calls()) {
assert(cha_monomorphic_target == NULL || exact_target == NULL, "both can not be set");
ciKlass* target_klass = NULL;
if (cha_monomorphic_target != NULL) {
target_klass = cha_monomorphic_target->holder();
} else if (exact_target != NULL) {
target_klass = exact_target->holder();
}
profile_call(target, recv, target_klass, collect_args_for_profiling(args, NULL, false), false);
}
}
Invoke* result = new Invoke(code, result_type, recv, args, vtable_index, target, state_before);
append_split(result);
if (result_type != voidType) {
if (method()->is_strict()) {
push(result_type, round_fp(result));
} else {
push(result_type, result);
}
}
if (profile_return() && result_type->is_object_kind()) {
profile_return_type(result, target);
}
}
void GraphBuilder::new_instance(int klass_index) {
ValueStack* state_before = copy_state_exhandling();
bool will_link;
ciKlass* klass = stream()->get_klass(will_link);
assert(klass->is_instance_klass(), "must be an instance klass");
NewInstance* new_instance = new NewInstance(klass->as_instance_klass(), state_before, stream()->is_unresolved_klass());
_memory->new_instance(new_instance);
apush(append_split(new_instance));
}
void GraphBuilder::new_type_array() {
ValueStack* state_before = copy_state_exhandling();
apush(append_split(new NewTypeArray(ipop(), (BasicType)stream()->get_index(), state_before)));
}
void GraphBuilder::new_object_array() {
bool will_link;
ciKlass* klass = stream()->get_klass(will_link);
ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
NewArray* n = new NewObjectArray(klass, ipop(), state_before);
apush(append_split(n));
}
bool GraphBuilder::direct_compare(ciKlass* k) {
if (k->is_loaded() && k->is_instance_klass() && !UseSlowPath) {
ciInstanceKlass* ik = k->as_instance_klass();
if (ik->is_final()) {
return true;
} else {
if (DeoptC1 && UseCHA && !(ik->has_subklass() || ik->is_interface())) {
dependency_recorder()->assert_leaf_type(ik);
return true;
}
}
}
return false;
}
void GraphBuilder::check_cast(int klass_index) {
bool will_link;
ciKlass* klass = stream()->get_klass(will_link);
ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_for_exception();
CheckCast* c = new CheckCast(klass, apop(), state_before);
apush(append_split(c));
c->set_direct_compare(direct_compare(klass));
if (is_profiling()) {
compilation()->set_would_profile(true);
if (profile_checkcasts()) {
c->set_profiled_method(method());
c->set_profiled_bci(bci());
c->set_should_profile(true);
}
}
}
void GraphBuilder::instance_of(int klass_index) {
bool will_link;
ciKlass* klass = stream()->get_klass(will_link);
ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
InstanceOf* i = new InstanceOf(klass, apop(), state_before);
ipush(append_split(i));
i->set_direct_compare(direct_compare(klass));
if (is_profiling()) {
compilation()->set_would_profile(true);
if (profile_checkcasts()) {
i->set_profiled_method(method());
i->set_profiled_bci(bci());
i->set_should_profile(true);
}
}
}
void GraphBuilder::monitorenter(Value x, int bci) {
ValueStack* state_before = copy_state_for_exception_with_bci(bci);
append_with_bci(new MonitorEnter(x, state()->lock(x), state_before), bci);
kill_all();
}
void GraphBuilder::monitorexit(Value x, int bci) {
append_with_bci(new MonitorExit(x, state()->unlock()), bci);
kill_all();
}
void GraphBuilder::new_multi_array(int dimensions) {
bool will_link;
ciKlass* klass = stream()->get_klass(will_link);
ValueStack* state_before = !klass->is_loaded() || PatchALot ? copy_state_before() : copy_state_exhandling();
Values* dims = new Values(dimensions, NULL);
int i = dimensions;
while (i-- > 0) dims->at_put(i, ipop());
NewArray* n = new NewMultiArray(klass, dims, state_before);
apush(append_split(n));
}
void GraphBuilder::throw_op(int bci) {
ValueStack* state_before = copy_state_before_with_bci(bci);
Throw* t = new Throw(apop(), state_before);
state()->truncate_stack(0);
append_with_bci(t, bci);
}
Value GraphBuilder::round_fp(Value fp_value) {
if (RoundFPResults && UseSSE < 2) {
if (fp_value->type()->tag() == doubleTag &&
fp_value->as_Constant() == NULL &&
fp_value->as_Local() == NULL && // method parameters need no rounding
fp_value->as_RoundFP() == NULL) {
return append(new RoundFP(fp_value));
}
}
return fp_value;
}
Instruction* GraphBuilder::append_with_bci(Instruction* instr, int bci) {
Canonicalizer canon(compilation(), instr, bci);
Instruction* i1 = canon.canonical();
if (i1->is_linked() || !i1->can_be_linked()) {
return i1;
}
if (UseLocalValueNumbering) {
Instruction* i2 = vmap()->find_insert(i1);
if (i2 != i1) {
assert(i2->is_linked(), "should already be linked");
return i2;
}
ValueNumberingEffects vne(vmap());
i1->visit(&vne);
}
assert(i1->next() == NULL, "shouldn't already be linked");
_last = _last->set_next(i1, canon.bci());
if (++_instruction_count >= InstructionCountCutoff && !bailed_out()) {
bailout("Method and/or inlining is too large");
}
#ifndef PRODUCT
if (PrintIRDuringConstruction) {
InstructionPrinter ip;
ip.print_line(i1);
if (Verbose) {
state()->print();
}
}
#endif
StateSplit* s = i1->as_StateSplit();
if (s != NULL) {
if (EliminateFieldAccess) {
Intrinsic* intrinsic = s->as_Intrinsic();
if (s->as_Invoke() != NULL || (intrinsic && !intrinsic->preserves_state())) {
_memory->kill();
}
}
s->set_state(state()->copy(ValueStack::StateAfter, canon.bci()));
}
if (i1->can_trap()) {
i1->set_exception_handlers(handle_exception(i1));
assert(i1->exception_state() != NULL || !i1->needs_exception_state() || bailed_out(), "handle_exception must set exception state");
}
return i1;
}
Instruction* GraphBuilder::append(Instruction* instr) {
assert(instr->as_StateSplit() == NULL || instr->as_BlockEnd() != NULL, "wrong append used");
return append_with_bci(instr, bci());
}
Instruction* GraphBuilder::append_split(StateSplit* instr) {
return append_with_bci(instr, bci());
}
void GraphBuilder::null_check(Value value) {
if (value->as_NewArray() != NULL || value->as_NewInstance() != NULL) {
return;
} else {
Constant* con = value->as_Constant();
if (con) {
ObjectType* c = con->type()->as_ObjectType();
if (c && c->is_loaded()) {
ObjectConstant* oc = c->as_ObjectConstant();
if (!oc || !oc->value()->is_null_object()) {
return;
}
}
}
}
append(new NullCheck(value, copy_state_for_exception()));
}
XHandlers* GraphBuilder::handle_exception(Instruction* instruction) {
if (!has_handler() && (!instruction->needs_exception_state() || instruction->exception_state() != NULL)) {
assert(instruction->exception_state() == NULL
|| instruction->exception_state()->kind() == ValueStack::EmptyExceptionState
|| (instruction->exception_state()->kind() == ValueStack::ExceptionState && _compilation->env()->should_retain_local_variables()),
"exception_state should be of exception kind");
return new XHandlers();
}
XHandlers* exception_handlers = new XHandlers();
ScopeData* cur_scope_data = scope_data();
ValueStack* cur_state = instruction->state_before();
ValueStack* prev_state = NULL;
int scope_count = 0;
assert(cur_state != NULL, "state_before must be set");
do {
int cur_bci = cur_state->bci();
assert(cur_scope_data->scope() == cur_state->scope(), "scopes do not match");
assert(cur_bci == SynchronizationEntryBCI || cur_bci == cur_scope_data->stream()->cur_bci(), "invalid bci");
XHandlers* list = cur_scope_data->xhandlers();
const int n = list->length();
for (int i = 0; i < n; i++) {
XHandler* h = list->handler_at(i);
if (h->covers(cur_bci)) {
compilation()->set_has_exception_handlers(true);
BlockBegin* entry = h->entry_block();
if (entry == block()) {
BAILOUT_("exception handler covers itself", exception_handlers);
}
assert(entry->bci() == h->handler_bci(), "must match");
assert(entry->bci() == -1 || entry == cur_scope_data->block_at(entry->bci()), "blocks must correspond");
assert(entry->state() == NULL || cur_state->total_locks_size() == entry->state()->total_locks_size(), "locks do not match");
if (cur_state->stack_size() != 0) {
cur_state = cur_state->copy(ValueStack::ExceptionState, cur_state->bci());
}
if (instruction->exception_state() == NULL) {
instruction->set_exception_state(cur_state);
}
if (!entry->try_merge(cur_state)) {
BAILOUT_("error while joining with exception handler, prob. due to complicated jsr/rets", exception_handlers);
}
int phi_operand = entry->add_exception_state(cur_state);
_block->add_exception_handler(entry);
if (!entry->is_predecessor(_block)) {
entry->add_predecessor(_block);
}
XHandler* new_xhandler = new XHandler(h);
new_xhandler->set_phi_operand(phi_operand);
new_xhandler->set_scope_count(scope_count);
exception_handlers->append(new_xhandler);
assert(!entry->is_set(BlockBegin::was_visited_flag), "entry must not be visited yet");
cur_scope_data->add_to_work_list(entry);
if (h->catch_type() == 0) {
return exception_handlers;
}
}
}
if (exception_handlers->length() == 0) {
if (_compilation->env()->should_retain_local_variables()) {
cur_state = cur_state->copy(ValueStack::ExceptionState, cur_state->bci());
} else {
cur_state = cur_state->copy(ValueStack::EmptyExceptionState, cur_state->bci());
}
if (prev_state != NULL) {
prev_state->set_caller_state(cur_state);
}
if (instruction->exception_state() == NULL) {
instruction->set_exception_state(cur_state);
}
}
while (cur_scope_data->parsing_jsr()) {
cur_scope_data = cur_scope_data->parent();
}
assert(cur_scope_data->scope() == cur_state->scope(), "scopes do not match");
assert(cur_state->locks_size() == 0 || cur_state->locks_size() == 1, "unlocking must be done in a catchall exception handler");
prev_state = cur_state;
cur_state = cur_state->caller_state();
cur_scope_data = cur_scope_data->parent();
scope_count++;
} while (cur_scope_data != NULL);
return exception_handlers;
}
class PhiSimplifier : public BlockClosure {
private:
bool _has_substitutions;
Value simplify(Value v);
public:
PhiSimplifier(BlockBegin* start) : _has_substitutions(false) {
start->iterate_preorder(this);
if (_has_substitutions) {
SubstitutionResolver sr(start);
}
}
void block_do(BlockBegin* b);
bool has_substitutions() const { return _has_substitutions; }
};
Value PhiSimplifier::simplify(Value v) {
Phi* phi = v->as_Phi();
if (phi == NULL) {
return v;
} else if (v->has_subst()) {
return simplify(v->subst());
} else if (phi->is_set(Phi::cannot_simplify)) {
return phi;
} else if (phi->is_set(Phi::visited)) {
return phi;
} else if (phi->type()->is_illegal()) {
return phi;
} else {
phi->set(Phi::visited);
Value subst = NULL;
int opd_count = phi->operand_count();
for (int i = 0; i < opd_count; i++) {
Value opd = phi->operand_at(i);
assert(opd != NULL, "Operand must exist!");
if (opd->type()->is_illegal()) {
phi->make_illegal();
phi->clear(Phi::visited);
return phi;
}
Value new_opd = simplify(opd);
assert(new_opd != NULL, "Simplified operand must exist!");
if (new_opd != phi && new_opd != subst) {
if (subst == NULL) {
subst = new_opd;
} else {
phi->set(Phi::cannot_simplify);
phi->clear(Phi::visited);
return phi;
}
}
}
assert(subst != NULL, "illegal phi function");
_has_substitutions = true;
phi->clear(Phi::visited);
phi->set_subst(subst);
#ifndef PRODUCT
if (PrintPhiFunctions) {
tty->print_cr("simplified phi function %c%d to %c%d (Block B%d)", phi->type()->tchar(), phi->id(), subst->type()->tchar(), subst->id(), phi->block()->block_id());
}
#endif
return subst;
}
}
void PhiSimplifier::block_do(BlockBegin* b) {
for_each_phi_fun(b, phi,
simplify(phi);
);
#ifdef ASSERT
for_each_phi_fun(b, phi,
assert(phi->operand_count() != 1 || phi->subst() != phi, "missed trivial simplification");
);
ValueStack* state = b->state()->caller_state();
for_each_state_value(state, value,
Phi* phi = value->as_Phi();
assert(phi == NULL || phi->block() != b, "must not have phi function to simplify in caller state");
);
#endif
}
void GraphBuilder::eliminate_redundant_phis(BlockBegin* start) {
PhiSimplifier simplifier(start);
}
void GraphBuilder::connect_to_end(BlockBegin* beg) {
kill_all();
_block = beg;
_state = beg->state()->copy_for_parsing();
_last = beg;
iterate_bytecodes_for_block(beg->bci());
}
BlockEnd* GraphBuilder::iterate_bytecodes_for_block(int bci) {
#ifndef PRODUCT
if (PrintIRDuringConstruction) {
tty->cr();
InstructionPrinter ip;
ip.print_instr(_block); tty->cr();
ip.print_stack(_block->state()); tty->cr();
ip.print_inline_level(_block);
ip.print_head();
tty->print_cr("locals size: %d stack size: %d", state()->locals_size(), state()->stack_size());
}
#endif
_skip_block = false;
assert(state() != NULL, "ValueStack missing!");
CompileLog* log = compilation()->log();
ciBytecodeStream s(method());
s.reset_to_bci(bci);
int prev_bci = bci;
scope_data()->set_stream(&s);
Bytecodes::Code code = Bytecodes::_illegal;
bool push_exception = false;
if (block()->is_set(BlockBegin::exception_entry_flag) && block()->next() == NULL) {
push_exception = true;
}
while (!bailed_out() && last()->as_BlockEnd() == NULL &&
(code = stream()->next()) != ciBytecodeStream::EOBC() &&
(block_at(s.cur_bci()) == NULL || block_at(s.cur_bci()) == block())) {
assert(state()->kind() == ValueStack::Parsing, "invalid state kind");
if (log != NULL)
log->set_context("bc code='%d' bci='%d'", (int)code, s.cur_bci());
if (compilation()->is_osr_compile()
&& scope()->is_top_scope()
&& parsing_jsr()
&& s.cur_bci() == compilation()->osr_bci()) {
bailout("OSR not supported while a jsr is active");
}
if (push_exception) {
apush(append(new ExceptionObject()));
push_exception = false;
}
switch (code) {
case Bytecodes::_nop : /* nothing to do */ break;
case Bytecodes::_aconst_null : apush(append(new Constant(objectNull ))); break;
case Bytecodes::_iconst_m1 : ipush(append(new Constant(new IntConstant (-1)))); break;
case Bytecodes::_iconst_0 : ipush(append(new Constant(intZero ))); break;
case Bytecodes::_iconst_1 : ipush(append(new Constant(intOne ))); break;
case Bytecodes::_iconst_2 : ipush(append(new Constant(new IntConstant ( 2)))); break;
case Bytecodes::_iconst_3 : ipush(append(new Constant(new IntConstant ( 3)))); break;
case Bytecodes::_iconst_4 : ipush(append(new Constant(new IntConstant ( 4)))); break;
case Bytecodes::_iconst_5 : ipush(append(new Constant(new IntConstant ( 5)))); break;
case Bytecodes::_lconst_0 : lpush(append(new Constant(new LongConstant ( 0)))); break;
case Bytecodes::_lconst_1 : lpush(append(new Constant(new LongConstant ( 1)))); break;
case Bytecodes::_fconst_0 : fpush(append(new Constant(new FloatConstant ( 0)))); break;
case Bytecodes::_fconst_1 : fpush(append(new Constant(new FloatConstant ( 1)))); break;
case Bytecodes::_fconst_2 : fpush(append(new Constant(new FloatConstant ( 2)))); break;
case Bytecodes::_dconst_0 : dpush(append(new Constant(new DoubleConstant( 0)))); break;
case Bytecodes::_dconst_1 : dpush(append(new Constant(new DoubleConstant( 1)))); break;
case Bytecodes::_bipush : ipush(append(new Constant(new IntConstant(((signed char*)s.cur_bcp())[1])))); break;
case Bytecodes::_sipush : ipush(append(new Constant(new IntConstant((short)Bytes::get_Java_u2(s.cur_bcp()+1))))); break;
case Bytecodes::_ldc : // fall through
case Bytecodes::_ldc_w : // fall through
case Bytecodes::_ldc2_w : load_constant(); break;
case Bytecodes::_iload : load_local(intType , s.get_index()); break;
case Bytecodes::_lload : load_local(longType , s.get_index()); break;
case Bytecodes::_fload : load_local(floatType , s.get_index()); break;
case Bytecodes::_dload : load_local(doubleType , s.get_index()); break;
case Bytecodes::_aload : load_local(instanceType, s.get_index()); break;
case Bytecodes::_iload_0 : load_local(intType , 0); break;
case Bytecodes::_iload_1 : load_local(intType , 1); break;
case Bytecodes::_iload_2 : load_local(intType , 2); break;
case Bytecodes::_iload_3 : load_local(intType , 3); break;
case Bytecodes::_lload_0 : load_local(longType , 0); break;
case Bytecodes::_lload_1 : load_local(longType , 1); break;
case Bytecodes::_lload_2 : load_local(longType , 2); break;
case Bytecodes::_lload_3 : load_local(longType , 3); break;
case Bytecodes::_fload_0 : load_local(floatType , 0); break;
case Bytecodes::_fload_1 : load_local(floatType , 1); break;
case Bytecodes::_fload_2 : load_local(floatType , 2); break;
case Bytecodes::_fload_3 : load_local(floatType , 3); break;
case Bytecodes::_dload_0 : load_local(doubleType, 0); break;
case Bytecodes::_dload_1 : load_local(doubleType, 1); break;
case Bytecodes::_dload_2 : load_local(doubleType, 2); break;
case Bytecodes::_dload_3 : load_local(doubleType, 3); break;
case Bytecodes::_aload_0 : load_local(objectType, 0); break;
case Bytecodes::_aload_1 : load_local(objectType, 1); break;
case Bytecodes::_aload_2 : load_local(objectType, 2); break;
case Bytecodes::_aload_3 : load_local(objectType, 3); break;
case Bytecodes::_iaload : load_indexed(T_INT ); break;
case Bytecodes::_laload : load_indexed(T_LONG ); break;
case Bytecodes::_faload : load_indexed(T_FLOAT ); break;
case Bytecodes::_daload : load_indexed(T_DOUBLE); break;
case Bytecodes::_aaload : load_indexed(T_OBJECT); break;
case Bytecodes::_baload : load_indexed(T_BYTE ); break;
case Bytecodes::_caload : load_indexed(T_CHAR ); break;
case Bytecodes::_saload : load_indexed(T_SHORT ); break;
case Bytecodes::_istore : store_local(intType , s.get_index()); break;
case Bytecodes::_lstore : store_local(longType , s.get_index()); break;
case Bytecodes::_fstore : store_local(floatType , s.get_index()); break;
case Bytecodes::_dstore : store_local(doubleType, s.get_index()); break;
case Bytecodes::_astore : store_local(objectType, s.get_index()); break;
case Bytecodes::_istore_0 : store_local(intType , 0); break;
case Bytecodes::_istore_1 : store_local(intType , 1); break;
case Bytecodes::_istore_2 : store_local(intType , 2); break;
case Bytecodes::_istore_3 : store_local(intType , 3); break;
case Bytecodes::_lstore_0 : store_local(longType , 0); break;
case Bytecodes::_lstore_1 : store_local(longType , 1); break;
case Bytecodes::_lstore_2 : store_local(longType , 2); break;
case Bytecodes::_lstore_3 : store_local(longType , 3); break;
case Bytecodes::_fstore_0 : store_local(floatType , 0); break;
case Bytecodes::_fstore_1 : store_local(floatType , 1); break;
case Bytecodes::_fstore_2 : store_local(floatType , 2); break;
case Bytecodes::_fstore_3 : store_local(floatType , 3); break;
case Bytecodes::_dstore_0 : store_local(doubleType, 0); break;
case Bytecodes::_dstore_1 : store_local(doubleType, 1); break;
case Bytecodes::_dstore_2 : store_local(doubleType, 2); break;
case Bytecodes::_dstore_3 : store_local(doubleType, 3); break;
case Bytecodes::_astore_0 : store_local(objectType, 0); break;
case Bytecodes::_astore_1 : store_local(objectType, 1); break;
case Bytecodes::_astore_2 : store_local(objectType, 2); break;
case Bytecodes::_astore_3 : store_local(objectType, 3); break;
case Bytecodes::_iastore : store_indexed(T_INT ); break;
case Bytecodes::_lastore : store_indexed(T_LONG ); break;
case Bytecodes::_fastore : store_indexed(T_FLOAT ); break;
case Bytecodes::_dastore : store_indexed(T_DOUBLE); break;
case Bytecodes::_aastore : store_indexed(T_OBJECT); break;
case Bytecodes::_bastore : store_indexed(T_BYTE ); break;
case Bytecodes::_castore : store_indexed(T_CHAR ); break;
case Bytecodes::_sastore : store_indexed(T_SHORT ); break;
case Bytecodes::_pop : // fall through
case Bytecodes::_pop2 : // fall through
case Bytecodes::_dup : // fall through
case Bytecodes::_dup_x1 : // fall through
case Bytecodes::_dup_x2 : // fall through
case Bytecodes::_dup2 : // fall through
case Bytecodes::_dup2_x1 : // fall through
case Bytecodes::_dup2_x2 : // fall through
case Bytecodes::_swap : stack_op(code); break;
case Bytecodes::_iadd : arithmetic_op(intType , code); break;
case Bytecodes::_ladd : arithmetic_op(longType , code); break;
case Bytecodes::_fadd : arithmetic_op(floatType , code); break;
case Bytecodes::_dadd : arithmetic_op(doubleType, code); break;
case Bytecodes::_isub : arithmetic_op(intType , code); break;
case Bytecodes::_lsub : arithmetic_op(longType , code); break;
case Bytecodes::_fsub : arithmetic_op(floatType , code); break;
case Bytecodes::_dsub : arithmetic_op(doubleType, code); break;
case Bytecodes::_imul : arithmetic_op(intType , code); break;
case Bytecodes::_lmul : arithmetic_op(longType , code); break;
case Bytecodes::_fmul : arithmetic_op(floatType , code); break;
case Bytecodes::_dmul : arithmetic_op(doubleType, code); break;
case Bytecodes::_idiv : arithmetic_op(intType , code, copy_state_for_exception()); break;
case Bytecodes::_ldiv : arithmetic_op(longType , code, copy_state_for_exception()); break;
case Bytecodes::_fdiv : arithmetic_op(floatType , code); break;
case Bytecodes::_ddiv : arithmetic_op(doubleType, code); break;
case Bytecodes::_irem : arithmetic_op(intType , code, copy_state_for_exception()); break;
case Bytecodes::_lrem : arithmetic_op(longType , code, copy_state_for_exception()); break;
case Bytecodes::_frem : arithmetic_op(floatType , code); break;
case Bytecodes::_drem : arithmetic_op(doubleType, code); break;
case Bytecodes::_ineg : negate_op(intType ); break;
case Bytecodes::_lneg : negate_op(longType ); break;
case Bytecodes::_fneg : negate_op(floatType ); break;
case Bytecodes::_dneg : negate_op(doubleType); break;
case Bytecodes::_ishl : shift_op(intType , code); break;
case Bytecodes::_lshl : shift_op(longType, code); break;
case Bytecodes::_ishr : shift_op(intType , code); break;
case Bytecodes::_lshr : shift_op(longType, code); break;
case Bytecodes::_iushr : shift_op(intType , code); break;
case Bytecodes::_lushr : shift_op(longType, code); break;
case Bytecodes::_iand : logic_op(intType , code); break;
case Bytecodes::_land : logic_op(longType, code); break;
case Bytecodes::_ior : logic_op(intType , code); break;
case Bytecodes::_lor : logic_op(longType, code); break;
case Bytecodes::_ixor : logic_op(intType , code); break;
case Bytecodes::_lxor : logic_op(longType, code); break;
case Bytecodes::_iinc : increment(); break;
case Bytecodes::_i2l : convert(code, T_INT , T_LONG ); break;
case Bytecodes::_i2f : convert(code, T_INT , T_FLOAT ); break;
case Bytecodes::_i2d : convert(code, T_INT , T_DOUBLE); break;
case Bytecodes::_l2i : convert(code, T_LONG , T_INT ); break;
case Bytecodes::_l2f : convert(code, T_LONG , T_FLOAT ); break;
case Bytecodes::_l2d : convert(code, T_LONG , T_DOUBLE); break;
case Bytecodes::_f2i : convert(code, T_FLOAT , T_INT ); break;
case Bytecodes::_f2l : convert(code, T_FLOAT , T_LONG ); break;
case Bytecodes::_f2d : convert(code, T_FLOAT , T_DOUBLE); break;
case Bytecodes::_d2i : convert(code, T_DOUBLE, T_INT ); break;
case Bytecodes::_d2l : convert(code, T_DOUBLE, T_LONG ); break;
case Bytecodes::_d2f : convert(code, T_DOUBLE, T_FLOAT ); break;
case Bytecodes::_i2b : convert(code, T_INT , T_BYTE ); break;
case Bytecodes::_i2c : convert(code, T_INT , T_CHAR ); break;
case Bytecodes::_i2s : convert(code, T_INT , T_SHORT ); break;
case Bytecodes::_lcmp : compare_op(longType , code); break;
case Bytecodes::_fcmpl : compare_op(floatType , code); break;
case Bytecodes::_fcmpg : compare_op(floatType , code); break;
case Bytecodes::_dcmpl : compare_op(doubleType, code); break;
case Bytecodes::_dcmpg : compare_op(doubleType, code); break;
case Bytecodes::_ifeq : if_zero(intType , If::eql); break;
case Bytecodes::_ifne : if_zero(intType , If::neq); break;
case Bytecodes::_iflt : if_zero(intType , If::lss); break;
case Bytecodes::_ifge : if_zero(intType , If::geq); break;
case Bytecodes::_ifgt : if_zero(intType , If::gtr); break;
case Bytecodes::_ifle : if_zero(intType , If::leq); break;
case Bytecodes::_if_icmpeq : if_same(intType , If::eql); break;
case Bytecodes::_if_icmpne : if_same(intType , If::neq); break;
case Bytecodes::_if_icmplt : if_same(intType , If::lss); break;
case Bytecodes::_if_icmpge : if_same(intType , If::geq); break;
case Bytecodes::_if_icmpgt : if_same(intType , If::gtr); break;
case Bytecodes::_if_icmple : if_same(intType , If::leq); break;
case Bytecodes::_if_acmpeq : if_same(objectType, If::eql); break;
case Bytecodes::_if_acmpne : if_same(objectType, If::neq); break;
case Bytecodes::_goto : _goto(s.cur_bci(), s.get_dest()); break;
case Bytecodes::_jsr : jsr(s.get_dest()); break;
case Bytecodes::_ret : ret(s.get_index()); break;
case Bytecodes::_tableswitch : table_switch(); break;
case Bytecodes::_lookupswitch : lookup_switch(); break;
case Bytecodes::_ireturn : method_return(ipop()); break;
case Bytecodes::_lreturn : method_return(lpop()); break;
case Bytecodes::_freturn : method_return(fpop()); break;
case Bytecodes::_dreturn : method_return(dpop()); break;
case Bytecodes::_areturn : method_return(apop()); break;
case Bytecodes::_return : method_return(NULL ); break;
case Bytecodes::_getstatic : // fall through
case Bytecodes::_putstatic : // fall through
case Bytecodes::_getfield : // fall through
case Bytecodes::_putfield : access_field(code); break;
case Bytecodes::_invokevirtual : // fall through
case Bytecodes::_invokespecial : // fall through
case Bytecodes::_invokestatic : // fall through
case Bytecodes::_invokedynamic : // fall through
case Bytecodes::_invokeinterface: invoke(code); break;
case Bytecodes::_new : new_instance(s.get_index_u2()); break;
case Bytecodes::_newarray : new_type_array(); break;
case Bytecodes::_anewarray : new_object_array(); break;
case Bytecodes::_arraylength : { ValueStack* state_before = copy_state_for_exception(); ipush(append(new ArrayLength(apop(), state_before))); break; }
case Bytecodes::_athrow : throw_op(s.cur_bci()); break;
case Bytecodes::_checkcast : check_cast(s.get_index_u2()); break;
case Bytecodes::_instanceof : instance_of(s.get_index_u2()); break;
case Bytecodes::_monitorenter : monitorenter(apop(), s.cur_bci()); break;
case Bytecodes::_monitorexit : monitorexit (apop(), s.cur_bci()); break;
case Bytecodes::_wide : ShouldNotReachHere(); break;
case Bytecodes::_multianewarray : new_multi_array(s.cur_bcp()[3]); break;
case Bytecodes::_ifnull : if_null(objectType, If::eql); break;
case Bytecodes::_ifnonnull : if_null(objectType, If::neq); break;
case Bytecodes::_goto_w : _goto(s.cur_bci(), s.get_far_dest()); break;
case Bytecodes::_jsr_w : jsr(s.get_far_dest()); break;
case Bytecodes::_breakpoint : BAILOUT_("concurrent setting of breakpoint", NULL);
default : ShouldNotReachHere(); break;
}
if (log != NULL)
log->clear_context(); // skip marker if nothing was printed
prev_bci = s.cur_bci();
}
CHECK_BAILOUT_(NULL);
if (_skip_block) {
_skip_block = false;
assert(_last && _last->as_BlockEnd(), "");
return _last->as_BlockEnd();
}
BlockEnd* end = last()->as_BlockEnd();
if (end == NULL) {
end = new Goto(block_at(s.cur_bci()), false);
append(end);
}
assert(end == last()->as_BlockEnd(), "inconsistency");
assert(end->state() != NULL, "state must already be present");
assert(end->as_Return() == NULL || end->as_Throw() == NULL || end->state()->stack_size() == 0, "stack not needed for return and throw");
block()->set_end(end);
for (int i = end->number_of_sux() - 1; i >= 0; i--) {
BlockBegin* sux = end->sux_at(i);
assert(sux->is_predecessor(block()), "predecessor missing");
if (!sux->try_merge(end->state())) BAILOUT_("block join failed", NULL);
scope_data()->add_to_work_list(end->sux_at(i));
}
scope_data()->set_stream(NULL);
return end;
}
void GraphBuilder::iterate_all_blocks(bool start_in_current_block_for_inlining) {
do {
if (start_in_current_block_for_inlining && !bailed_out()) {
iterate_bytecodes_for_block(0);
start_in_current_block_for_inlining = false;
} else {
BlockBegin* b;
while ((b = scope_data()->remove_from_work_list()) != NULL) {
if (!b->is_set(BlockBegin::was_visited_flag)) {
if (b->is_set(BlockBegin::osr_entry_flag)) {
setup_osr_entry_block();
b->clear(BlockBegin::osr_entry_flag);
}
b->set(BlockBegin::was_visited_flag);
connect_to_end(b);
}
}
}
} while (!bailed_out() && !scope_data()->is_work_list_empty());
}
bool GraphBuilder::_can_trap [Bytecodes::number_of_java_codes];
void GraphBuilder::initialize() {
Bytecodes::Code can_trap_list[] =
{ Bytecodes::_ldc
, Bytecodes::_ldc_w
, Bytecodes::_ldc2_w
, Bytecodes::_iaload
, Bytecodes::_laload
, Bytecodes::_faload
, Bytecodes::_daload
, Bytecodes::_aaload
, Bytecodes::_baload
, Bytecodes::_caload
, Bytecodes::_saload
, Bytecodes::_iastore
, Bytecodes::_lastore
, Bytecodes::_fastore
, Bytecodes::_dastore
, Bytecodes::_aastore
, Bytecodes::_bastore
, Bytecodes::_castore
, Bytecodes::_sastore
, Bytecodes::_idiv
, Bytecodes::_ldiv
, Bytecodes::_irem
, Bytecodes::_lrem
, Bytecodes::_getstatic
, Bytecodes::_putstatic
, Bytecodes::_getfield
, Bytecodes::_putfield
, Bytecodes::_invokevirtual
, Bytecodes::_invokespecial
, Bytecodes::_invokestatic
, Bytecodes::_invokedynamic
, Bytecodes::_invokeinterface
, Bytecodes::_new
, Bytecodes::_newarray
, Bytecodes::_anewarray
, Bytecodes::_arraylength
, Bytecodes::_athrow
, Bytecodes::_checkcast
, Bytecodes::_instanceof
, Bytecodes::_monitorenter
, Bytecodes::_multianewarray
};
for (int i = 0; i < Bytecodes::number_of_java_codes; i++) {
_can_trap[i] = false;
}
for (uint j = 0; j < ARRAY_SIZE(can_trap_list); j++) {
_can_trap[can_trap_list[j]] = true;
}
}
BlockBegin* GraphBuilder::header_block(BlockBegin* entry, BlockBegin::Flag f, ValueStack* state) {
assert(entry->is_set(f), "entry/flag mismatch");
BlockBegin* h = new BlockBegin(entry->bci());
h->set_depth_first_number(0);
Value l = h;
BlockEnd* g = new Goto(entry, false);
l->set_next(g, entry->bci());
h->set_end(g);
h->set(f);
ValueStack* s = state->copy(ValueStack::StateAfter, entry->bci()); // can use copy since stack is empty (=> no phis)
assert(s->stack_is_empty(), "must have empty stack at entry point");
g->set_state(s);
return h;
}
BlockBegin* GraphBuilder::setup_start_block(int osr_bci, BlockBegin* std_entry, BlockBegin* osr_entry, ValueStack* state) {
BlockBegin* start = new BlockBegin(0);
BlockBegin* new_header_block;
if (std_entry->number_of_preds() > 0 || count_invocations() || count_backedges()) {
new_header_block = header_block(std_entry, BlockBegin::std_entry_flag, state);
} else {
new_header_block = std_entry;
}
Base* base =
new Base(
new_header_block,
osr_entry
);
start->set_next(base, 0);
start->set_end(base);
start->set_state(state->copy(ValueStack::StateAfter, std_entry->bci()));
base->set_state(state->copy(ValueStack::StateAfter, std_entry->bci()));
if (base->std_entry()->state() == NULL) {
base->std_entry()->merge(state);
}
assert(base->std_entry()->state() != NULL, "");
return start;
}
void GraphBuilder::setup_osr_entry_block() {
assert(compilation()->is_osr_compile(), "only for osrs");
int osr_bci = compilation()->osr_bci();
ciBytecodeStream s(method());
s.reset_to_bci(osr_bci);
s.next();
scope_data()->set_stream(&s);
_osr_entry = new BlockBegin(osr_bci);
_osr_entry->set(BlockBegin::osr_entry_flag);
_osr_entry->set_depth_first_number(0);
BlockBegin* target = bci2block()->at(osr_bci);
assert(target != NULL && target->is_set(BlockBegin::osr_entry_flag), "must be there");
ValueStack* state = target->state()->copy();
_osr_entry->set_state(state);
kill_all();
_block = _osr_entry;
_state = _osr_entry->state()->copy();
assert(_state->bci() == osr_bci, "mismatch");
_last = _osr_entry;
Value e = append(new OsrEntry());
e->set_needs_null_check(false);
int index;
Value local;
const BitMap live_oops = method()->live_local_oops_at_bci(osr_bci);
int locals_offset = BytesPerWord * (method()->max_locals() - 1);
for_each_local_value(state, index, local) {
int offset = locals_offset - (index + local->type()->size() - 1) * BytesPerWord;
Value get;
if (local->type()->is_object_kind() && !live_oops.at(index)) {
get = append(new Constant(objectNull));
} else {
get = append(new UnsafeGetRaw(as_BasicType(local->type()), e,
append(new Constant(new IntConstant(offset))),
0,
true /*unaligned*/, true /*wide*/));
}
_state->store_local(index, get);
}
assert(state->caller_state() == NULL, "should be top scope");
state->clear_locals();
Goto* g = new Goto(target, false);
append(g);
_osr_entry->set_end(g);
target->merge(_osr_entry->end()->state());
scope_data()->set_stream(NULL);
}
ValueStack* GraphBuilder::state_at_entry() {
ValueStack* state = new ValueStack(scope(), NULL);
int idx = 0;
if (!method()->is_static()) {
state->store_local(idx, new Local(method()->holder(), objectType, idx));
idx = 1;
}
ciSignature* sig = method()->signature();
for (int i = 0; i < sig->count(); i++) {
ciType* type = sig->type_at(i);
BasicType basic_type = type->basic_type();
if (basic_type == T_ARRAY) basic_type = T_OBJECT;
ValueType* vt = as_ValueType(basic_type);
state->store_local(idx, new Local(type, vt, idx));
idx += type->size();
}
if (method()->is_synchronized()) {
state->lock(NULL);
}
return state;
}
GraphBuilder::GraphBuilder(Compilation* compilation, IRScope* scope)
: _scope_data(NULL)
, _instruction_count(0)
, _osr_entry(NULL)
, _memory(new MemoryBuffer())
, _compilation(compilation)
, _inline_bailout_msg(NULL)
{
int osr_bci = compilation->osr_bci();
BlockListBuilder blm(compilation, scope, osr_bci);
CHECK_BAILOUT();
BlockList* bci2block = blm.bci2block();
BlockBegin* start_block = bci2block->at(0);
push_root_scope(scope, bci2block, start_block);
_initial_state = state_at_entry();
start_block->merge(_initial_state);
_vmap = new ValueMap();
switch (scope->method()->intrinsic_id()) {
case vmIntrinsics::_dabs : // fall through
case vmIntrinsics::_dsqrt : // fall through
case vmIntrinsics::_dsin : // fall through
case vmIntrinsics::_dcos : // fall through
case vmIntrinsics::_dtan : // fall through
case vmIntrinsics::_dlog : // fall through
case vmIntrinsics::_dlog10 : // fall through
case vmIntrinsics::_dexp : // fall through
case vmIntrinsics::_dpow : // fall through
{
ciBytecodeStream s(scope->method());
s.reset_to_bci(0);
scope_data()->set_stream(&s);
s.next();
_block = start_block;
_state = start_block->state()->copy_for_parsing();
_last = start_block;
load_local(doubleType, 0);
if (scope->method()->intrinsic_id() == vmIntrinsics::_dpow) {
load_local(doubleType, 2);
}
bool result = try_inline_intrinsics(scope->method());
if (!result) BAILOUT("failed to inline intrinsic");
method_return(dpop());
BlockEnd* end = last()->as_BlockEnd();
block()->set_end(end);
break;
}
case vmIntrinsics::_Reference_get:
{
{
ciBytecodeStream s(scope->method());
s.reset_to_bci(0);
scope_data()->set_stream(&s);
s.next();
_block = start_block;
_state = start_block->state()->copy_for_parsing();
_last = start_block;
load_local(objectType, 0);
bool result = try_inline_intrinsics(scope->method());
if (!result) BAILOUT("failed to inline intrinsic");
method_return(apop());
BlockEnd* end = last()->as_BlockEnd();
block()->set_end(end);
break;
}
}
default:
scope_data()->add_to_work_list(start_block);
iterate_all_blocks();
break;
}
CHECK_BAILOUT();
_start = setup_start_block(osr_bci, start_block, _osr_entry, _initial_state);
eliminate_redundant_phis(_start);
NOT_PRODUCT(if (PrintValueNumbering && Verbose) print_stats());
if (osr_bci != -1) {
BlockBegin* osr_block = blm.bci2block()->at(osr_bci);
if (!osr_block->is_set(BlockBegin::was_visited_flag)) {
BAILOUT("osr entry must have been visited for osr compile");
}
if (!osr_block->state()->stack_is_empty()) {
BAILOUT("stack not empty at OSR entry point");
}
}
#ifndef PRODUCT
if (PrintCompilation && Verbose) tty->print_cr("Created %d Instructions", _instruction_count);
#endif
}
ValueStack* GraphBuilder::copy_state_before() {
return copy_state_before_with_bci(bci());
}
ValueStack* GraphBuilder::copy_state_exhandling() {
return copy_state_exhandling_with_bci(bci());
}
ValueStack* GraphBuilder::copy_state_for_exception() {
return copy_state_for_exception_with_bci(bci());
}
ValueStack* GraphBuilder::copy_state_before_with_bci(int bci) {
return state()->copy(ValueStack::StateBefore, bci);
}
ValueStack* GraphBuilder::copy_state_exhandling_with_bci(int bci) {
if (!has_handler()) return NULL;
return state()->copy(ValueStack::StateBefore, bci);
}
ValueStack* GraphBuilder::copy_state_for_exception_with_bci(int bci) {
ValueStack* s = copy_state_exhandling_with_bci(bci);
if (s == NULL) {
if (_compilation->env()->should_retain_local_variables()) {
s = state()->copy(ValueStack::ExceptionState, bci);
} else {
s = state()->copy(ValueStack::EmptyExceptionState, bci);
}
}
return s;
}
int GraphBuilder::recursive_inline_level(ciMethod* cur_callee) const {
int recur_level = 0;
for (IRScope* s = scope(); s != NULL; s = s->caller()) {
if (s->method() == cur_callee) {
++recur_level;
}
}
return recur_level;
}
bool GraphBuilder::try_inline(ciMethod* callee, bool holder_known, Bytecodes::Code bc, Value receiver) {
const char* msg = NULL;
clear_inline_bailout();
msg = should_not_inline(callee);
if (msg != NULL) {
print_inlining(callee, msg, /*success*/ false);
return false;
}
if (callee->is_method_handle_intrinsic()) {
return try_method_handle_inline(callee);
}
if (callee->intrinsic_id() != vmIntrinsics::_none) {
if (try_inline_intrinsics(callee)) {
print_inlining(callee, "intrinsic");
return true;
}
}
msg = check_can_parse(callee);
if (msg != NULL) {
print_inlining(callee, msg, /*success*/ false);
return false;
}
if (bc == Bytecodes::_illegal) {
bc = code();
}
if (try_inline_full(callee, holder_known, bc, receiver))
return true;
if (!bailed_out())
print_inlining(callee, _inline_bailout_msg, /*success*/ false);
return false;
}
const char* GraphBuilder::check_can_parse(ciMethod* callee) const {
if ( callee->is_native()) return "native method";
if ( callee->is_abstract()) return "abstract method";
if (!callee->can_be_compiled()) return "not compilable (disabled)";
return NULL;
}
const char* GraphBuilder::should_not_inline(ciMethod* callee) const {
if ( callee->should_exclude()) return "excluded by CompilerOracle";
if ( callee->should_not_inline()) return "disallowed by CompilerOracle";
if ( callee->dont_inline()) return "don't inline by annotation";
return NULL;
}
bool GraphBuilder::try_inline_intrinsics(ciMethod* callee) {
if (callee->is_synchronized()) {
return false;
}
vmIntrinsics::ID id = callee->intrinsic_id();
if (!InlineNatives && id != vmIntrinsics::_Reference_get) {
INLINE_BAILOUT("intrinsic method inlining disabled");
}
bool preserves_state = false;
bool cantrap = true;
switch (id) {
case vmIntrinsics::_arraycopy:
if (!InlineArrayCopy) return false;
break;
#ifdef JFR_HAVE_INTRINSICS
#if defined(_LP64) || !defined(TRACE_ID_CLASS_SHIFT)
case vmIntrinsics::_getClassId:
preserves_state = false;
cantrap = false;
break;
#endif
case vmIntrinsics::_getEventWriter:
preserves_state = false;
cantrap = true;
break;
case vmIntrinsics::_counterTime:
preserves_state = true;
cantrap = false;
break;
#endif
case vmIntrinsics::_currentTimeMillis:
case vmIntrinsics::_nanoTime:
preserves_state = true;
cantrap = false;
break;
case vmIntrinsics::_floatToRawIntBits :
case vmIntrinsics::_intBitsToFloat :
case vmIntrinsics::_doubleToRawLongBits :
case vmIntrinsics::_longBitsToDouble :
if (!InlineMathNatives) return false;
preserves_state = true;
cantrap = false;
break;
case vmIntrinsics::_getClass :
case vmIntrinsics::_isInstance :
if (!InlineClassNatives) return false;
preserves_state = true;
break;
case vmIntrinsics::_currentThread :
if (!InlineThreadNatives) return false;
preserves_state = true;
cantrap = false;
break;
case vmIntrinsics::_dabs : // fall through
case vmIntrinsics::_dsqrt : // fall through
case vmIntrinsics::_dsin : // fall through
case vmIntrinsics::_dcos : // fall through
case vmIntrinsics::_dtan : // fall through
case vmIntrinsics::_dlog : // fall through
case vmIntrinsics::_dlog10 : // fall through
case vmIntrinsics::_dexp : // fall through
case vmIntrinsics::_dpow : // fall through
if (!InlineMathNatives) return false;
cantrap = false;
preserves_state = true;
break;
case vmIntrinsics::_getObject : return append_unsafe_get_obj(callee, T_OBJECT, false);
case vmIntrinsics::_getBoolean: return append_unsafe_get_obj(callee, T_BOOLEAN, false);
case vmIntrinsics::_getByte : return append_unsafe_get_obj(callee, T_BYTE, false);
case vmIntrinsics::_getShort : return append_unsafe_get_obj(callee, T_SHORT, false);
case vmIntrinsics::_getChar : return append_unsafe_get_obj(callee, T_CHAR, false);
case vmIntrinsics::_getInt : return append_unsafe_get_obj(callee, T_INT, false);
case vmIntrinsics::_getLong : return append_unsafe_get_obj(callee, T_LONG, false);
case vmIntrinsics::_getFloat : return append_unsafe_get_obj(callee, T_FLOAT, false);
case vmIntrinsics::_getDouble : return append_unsafe_get_obj(callee, T_DOUBLE, false);
case vmIntrinsics::_putObject : return append_unsafe_put_obj(callee, T_OBJECT, false);
case vmIntrinsics::_putBoolean: return append_unsafe_put_obj(callee, T_BOOLEAN, false);
case vmIntrinsics::_putByte : return append_unsafe_put_obj(callee, T_BYTE, false);
case vmIntrinsics::_putShort : return append_unsafe_put_obj(callee, T_SHORT, false);
case vmIntrinsics::_putChar : return append_unsafe_put_obj(callee, T_CHAR, false);
case vmIntrinsics::_putInt : return append_unsafe_put_obj(callee, T_INT, false);
case vmIntrinsics::_putLong : return append_unsafe_put_obj(callee, T_LONG, false);
case vmIntrinsics::_putFloat : return append_unsafe_put_obj(callee, T_FLOAT, false);
case vmIntrinsics::_putDouble : return append_unsafe_put_obj(callee, T_DOUBLE, false);
case vmIntrinsics::_getObjectVolatile : return append_unsafe_get_obj(callee, T_OBJECT, true);
case vmIntrinsics::_getBooleanVolatile: return append_unsafe_get_obj(callee, T_BOOLEAN, true);
case vmIntrinsics::_getByteVolatile : return append_unsafe_get_obj(callee, T_BYTE, true);
case vmIntrinsics::_getShortVolatile : return append_unsafe_get_obj(callee, T_SHORT, true);
case vmIntrinsics::_getCharVolatile : return append_unsafe_get_obj(callee, T_CHAR, true);
case vmIntrinsics::_getIntVolatile : return append_unsafe_get_obj(callee, T_INT, true);
case vmIntrinsics::_getLongVolatile : return append_unsafe_get_obj(callee, T_LONG, true);
case vmIntrinsics::_getFloatVolatile : return append_unsafe_get_obj(callee, T_FLOAT, true);
case vmIntrinsics::_getDoubleVolatile : return append_unsafe_get_obj(callee, T_DOUBLE, true);
case vmIntrinsics::_putObjectVolatile : return append_unsafe_put_obj(callee, T_OBJECT, true);
case vmIntrinsics::_putBooleanVolatile: return append_unsafe_put_obj(callee, T_BOOLEAN, true);
case vmIntrinsics::_putByteVolatile : return append_unsafe_put_obj(callee, T_BYTE, true);
case vmIntrinsics::_putShortVolatile : return append_unsafe_put_obj(callee, T_SHORT, true);
case vmIntrinsics::_putCharVolatile : return append_unsafe_put_obj(callee, T_CHAR, true);
case vmIntrinsics::_putIntVolatile : return append_unsafe_put_obj(callee, T_INT, true);
case vmIntrinsics::_putLongVolatile : return append_unsafe_put_obj(callee, T_LONG, true);
case vmIntrinsics::_putFloatVolatile : return append_unsafe_put_obj(callee, T_FLOAT, true);
case vmIntrinsics::_putDoubleVolatile : return append_unsafe_put_obj(callee, T_DOUBLE, true);
case vmIntrinsics::_getByte_raw : return append_unsafe_get_raw(callee, T_BYTE);
case vmIntrinsics::_getShort_raw : return append_unsafe_get_raw(callee, T_SHORT);
case vmIntrinsics::_getChar_raw : return append_unsafe_get_raw(callee, T_CHAR);
case vmIntrinsics::_getInt_raw : return append_unsafe_get_raw(callee, T_INT);
case vmIntrinsics::_getLong_raw : return append_unsafe_get_raw(callee, T_LONG);
case vmIntrinsics::_getFloat_raw : return append_unsafe_get_raw(callee, T_FLOAT);
case vmIntrinsics::_getDouble_raw : return append_unsafe_get_raw(callee, T_DOUBLE);
case vmIntrinsics::_putByte_raw : return append_unsafe_put_raw(callee, T_BYTE);
case vmIntrinsics::_putShort_raw : return append_unsafe_put_raw(callee, T_SHORT);
case vmIntrinsics::_putChar_raw : return append_unsafe_put_raw(callee, T_CHAR);
case vmIntrinsics::_putInt_raw : return append_unsafe_put_raw(callee, T_INT);
case vmIntrinsics::_putLong_raw : return append_unsafe_put_raw(callee, T_LONG);
case vmIntrinsics::_putFloat_raw : return append_unsafe_put_raw(callee, T_FLOAT);
case vmIntrinsics::_putDouble_raw : return append_unsafe_put_raw(callee, T_DOUBLE);
case vmIntrinsics::_prefetchRead : return append_unsafe_prefetch(callee, false, false);
case vmIntrinsics::_prefetchWrite : return append_unsafe_prefetch(callee, false, true);
case vmIntrinsics::_prefetchReadStatic : return append_unsafe_prefetch(callee, true, false);
case vmIntrinsics::_prefetchWriteStatic : return append_unsafe_prefetch(callee, true, true);
case vmIntrinsics::_checkIndex :
if (!InlineNIOCheckIndex) return false;
preserves_state = true;
break;
case vmIntrinsics::_putOrderedObject : return append_unsafe_put_obj(callee, T_OBJECT, true);
case vmIntrinsics::_putOrderedInt : return append_unsafe_put_obj(callee, T_INT, true);
case vmIntrinsics::_putOrderedLong : return append_unsafe_put_obj(callee, T_LONG, true);
case vmIntrinsics::_compareAndSwapLong:
if (!VM_Version::supports_cx8()) return false;
case vmIntrinsics::_compareAndSwapInt:
case vmIntrinsics::_compareAndSwapObject:
append_unsafe_CAS(callee);
return true;
case vmIntrinsics::_getAndAddInt:
if (!VM_Version::supports_atomic_getadd4()) {
return false;
}
return append_unsafe_get_and_set_obj(callee, true);
case vmIntrinsics::_getAndAddLong:
if (!VM_Version::supports_atomic_getadd8()) {
return false;
}
return append_unsafe_get_and_set_obj(callee, true);
case vmIntrinsics::_getAndSetInt:
if (!VM_Version::supports_atomic_getset4()) {
return false;
}
return append_unsafe_get_and_set_obj(callee, false);
case vmIntrinsics::_getAndSetLong:
if (!VM_Version::supports_atomic_getset8()) {
return false;
}
return append_unsafe_get_and_set_obj(callee, false);
case vmIntrinsics::_getAndSetObject:
#ifdef _LP64
if (!UseCompressedOops && !VM_Version::supports_atomic_getset8()) {
return false;
}
if (UseCompressedOops && !VM_Version::supports_atomic_getset4()) {
return false;
}
#else
if (!VM_Version::supports_atomic_getset4()) {
return false;
}
#endif
return append_unsafe_get_and_set_obj(callee, false);
case vmIntrinsics::_Reference_get:
preserves_state = true;
break;
case vmIntrinsics::_updateCRC32:
case vmIntrinsics::_updateBytesCRC32:
case vmIntrinsics::_updateByteBufferCRC32:
if (!UseCRC32Intrinsics) return false;
cantrap = false;
preserves_state = true;
break;
case vmIntrinsics::_loadFence :
case vmIntrinsics::_storeFence:
case vmIntrinsics::_fullFence :
break;
default : return false; // do not inline
}
const bool has_receiver = !callee->is_static();
ValueType* result_type = as_ValueType(callee->return_type());
ValueStack* state_before = copy_state_for_exception();
Values* args = state()->pop_arguments(callee->arg_size());
if (is_profiling()) {
if (callee != method()) {
compilation()->set_would_profile(true);
if (profile_calls()) {
Value recv = NULL;
if (has_receiver) {
recv = args->at(0);
null_check(recv);
}
profile_call(callee, recv, NULL, collect_args_for_profiling(args, callee, true), true);
}
}
}
Intrinsic* result = new Intrinsic(result_type, id, args, has_receiver, state_before,
preserves_state, cantrap);
Value value = append_split(result);
if (result_type != voidType) push(result_type, value);
if (callee != method() && profile_return() && result_type->is_object_kind()) {
profile_return_type(result, callee);
}
return true;
}
bool GraphBuilder::try_inline_jsr(int jsr_dest_bci) {
BlockBegin* cont = block_at(next_bci());
assert(cont != NULL, "continuation must exist (BlockListBuilder starts a new block after a jsr");
push_scope_for_jsr(cont, jsr_dest_bci);
scope_data()->set_stream(scope_data()->parent()->stream());
BlockBegin* jsr_start_block = block_at(jsr_dest_bci);
assert(jsr_start_block != NULL, "jsr start block must exist");
assert(!jsr_start_block->is_set(BlockBegin::was_visited_flag), "should not have visited jsr yet");
Goto* goto_sub = new Goto(jsr_start_block, false);
assert(jsr_start_block->state() == NULL, "should have fresh jsr starting block");
jsr_start_block->set_state(copy_state_before_with_bci(jsr_dest_bci));
append(goto_sub);
_block->set_end(goto_sub);
_last = _block = jsr_start_block;
scope_data()->set_stream(NULL);
scope_data()->add_to_work_list(jsr_start_block);
iterate_all_blocks();
CHECK_BAILOUT_(false);
if (cont->state() != NULL) {
if (!cont->is_set(BlockBegin::was_visited_flag)) {
scope_data()->parent()->add_to_work_list(cont);
}
}
assert(jsr_continuation() == cont, "continuation must not have changed");
assert(!jsr_continuation()->is_set(BlockBegin::was_visited_flag) ||
jsr_continuation()->is_set(BlockBegin::parser_loop_header_flag),
"continuation can only be visited in case of backward branches");
assert(_last && _last->as_BlockEnd(), "block must have end");
_skip_block = true;
pop_scope_for_jsr();
return true;
}
void GraphBuilder::inline_sync_entry(Value lock, BlockBegin* sync_handler) {
assert(lock != NULL && sync_handler != NULL, "lock or handler missing");
monitorenter(lock, SynchronizationEntryBCI);
assert(_last->as_MonitorEnter() != NULL, "monitor enter expected");
_last->set_needs_null_check(false);
sync_handler->set(BlockBegin::exception_entry_flag);
sync_handler->set(BlockBegin::is_on_work_list_flag);
ciExceptionHandler* desc = new ciExceptionHandler(method()->holder(), 0, method()->code_size(), -1, 0);
XHandler* h = new XHandler(desc);
h->set_entry_block(sync_handler);
scope_data()->xhandlers()->append(h);
scope_data()->set_has_handler();
}
void GraphBuilder::fill_sync_handler(Value lock, BlockBegin* sync_handler, bool default_handler) {
BlockBegin* orig_block = _block;
ValueStack* orig_state = _state;
Instruction* orig_last = _last;
_last = _block = sync_handler;
_state = sync_handler->state()->copy();
assert(sync_handler != NULL, "handler missing");
assert(!sync_handler->is_set(BlockBegin::was_visited_flag), "is visited here");
assert(lock != NULL || default_handler, "lock or handler missing");
XHandler* h = scope_data()->xhandlers()->remove_last();
assert(h->entry_block() == sync_handler, "corrupt list of handlers");
block()->set(BlockBegin::was_visited_flag);
Value exception = append_with_bci(new ExceptionObject(), SynchronizationEntryBCI);
assert(exception->is_pinned(), "must be");
int bci = SynchronizationEntryBCI;
if (compilation()->env()->dtrace_method_probes()) {
Values* args = new Values(1);
args->push(append_with_bci(new Constant(new MethodConstant(method())), bci));
append_with_bci(new RuntimeCall(voidType, "dtrace_method_exit", CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), args), bci);
}
if (lock) {
assert(state()->locks_size() > 0 && state()->lock_at(state()->locks_size() - 1) == lock, "lock is missing");
if (!lock->is_linked()) {
lock = append_with_bci(lock, bci);
}
monitorexit(lock, bci);
if (!default_handler) {
pop_scope();
bci = _state->caller_state()->bci();
_state = _state->caller_state()->copy_for_parsing();
}
}
apush(exception);
throw_op(bci);
BlockEnd* end = last()->as_BlockEnd();
block()->set_end(end);
_block = orig_block;
_state = orig_state;
_last = orig_last;
}
bool GraphBuilder::try_inline_full(ciMethod* callee, bool holder_known, Bytecodes::Code bc, Value receiver) {
assert(!callee->is_native(), "callee must not be native");
if (CompilationPolicy::policy()->should_not_inline(compilation()->env(), callee)) {
INLINE_BAILOUT("inlining prohibited by policy");
}
if (callee->has_exception_handlers() &&
!InlineMethodsWithExceptionHandlers) INLINE_BAILOUT("callee has exception handlers");
if (callee->is_synchronized() &&
!InlineSynchronizedMethods ) INLINE_BAILOUT("callee is synchronized");
if (!callee->holder()->is_initialized()) INLINE_BAILOUT("callee's klass not initialized yet");
if (!callee->has_balanced_monitors()) INLINE_BAILOUT("callee's monitors do not match");
if (callee->has_jsrs() ) INLINE_BAILOUT("jsrs not handled properly by inliner yet");
if (strict_fp_requires_explicit_rounding && UseSSE < 2 && method()->is_strict() != callee->is_strict()) {
INLINE_BAILOUT("caller and callee have different strict fp requirements");
}
if (is_profiling() && !callee->ensure_method_data()) {
INLINE_BAILOUT("mdo allocation failed");
}
if (callee->force_inline() || callee->should_inline()) {
if (inline_level() > MaxForceInlineLevel ) INLINE_BAILOUT("MaxForceInlineLevel");
if (recursive_inline_level(callee) > MaxRecursiveInlineLevel) INLINE_BAILOUT("recursive inlining too deep");
const char* msg = "";
if (callee->force_inline()) msg = "force inline by annotation";
if (callee->should_inline()) msg = "force inline by CompileOracle";
print_inlining(callee, msg);
} else {
if (inline_level() > MaxInlineLevel ) INLINE_BAILOUT("inlining too deep");
if (recursive_inline_level(callee) > MaxRecursiveInlineLevel) INLINE_BAILOUT("recursive inlining too deep");
if (callee->code_size_for_inlining() > max_inline_size() ) INLINE_BAILOUT("callee is too large");
if (callee->name() == ciSymbol::object_initializer_name() &&
callee->holder()->is_subclass_of(ciEnv::current()->Throwable_klass())) {
IRScope* top = scope();
while (top->caller() != NULL) {
top = top->caller();
}
if (!top->method()->holder()->is_subclass_of(ciEnv::current()->Throwable_klass())) {
INLINE_BAILOUT("don't inline Throwable constructors");
}
}
if (compilation()->env()->num_inlined_bytecodes() > DesiredMethodLimit) {
INLINE_BAILOUT("total inlining greater than DesiredMethodLimit");
}
print_inlining(callee);
}
BlockBegin* orig_block = block();
const bool is_invokedynamic = bc == Bytecodes::_invokedynamic;
const bool has_receiver = (bc != Bytecodes::_invokestatic && !is_invokedynamic);
const int args_base = state()->stack_size() - callee->arg_size();
assert(args_base >= 0, "stack underflow during inlining");
Value recv = NULL;
if (has_receiver) {
assert(!callee->is_static(), "callee must not be static");
assert(callee->arg_size() > 0, "must have at least a receiver");
recv = state()->stack_at(args_base);
null_check(recv);
}
if (is_profiling()) {
compilation()->set_would_profile(true);
if (profile_calls()) {
int start = 0;
Values* obj_args = args_list_for_profiling(callee, start, has_receiver);
if (obj_args != NULL) {
int s = obj_args->size();
for (int i = args_base+start, j = 0; j < obj_args->size() && i < state()->stack_size(); ) {
Value v = state()->stack_at_inc(i);
if (v->type()->is_object_kind()) {
obj_args->push(v);
j++;
}
}
check_args_for_profiling(obj_args, s);
}
profile_call(callee, recv, holder_known ? callee->holder() : NULL, obj_args, true);
}
}
BlockBegin* cont = block_at(next_bci());
bool continuation_existed = true;
if (cont == NULL) {
cont = new BlockBegin(next_bci());
cont->set_depth_first_number(0);
#ifndef PRODUCT
if (PrintInitialBlockList) {
tty->print_cr("CFG: created block %d (bci %d) as continuation for inline at bci %d",
cont->block_id(), cont->bci(), bci());
}
#endif
continuation_existed = false;
}
int continuation_preds = cont->number_of_preds();
push_scope(callee, cont);
if (bailed_out())
return false;
scope_data()->set_stream(scope_data()->parent()->stream());
ValueStack* callee_state = state();
ValueStack* caller_state = state()->caller_state();
for (int i = args_base; i < caller_state->stack_size(); ) {
const int arg_no = i - args_base;
Value arg = caller_state->stack_at_inc(i);
store_local(callee_state, arg, arg_no);
}
caller_state->truncate_stack(args_base);
assert(callee_state->stack_size() == 0, "callee stack must be empty");
Value lock = NULL;
BlockBegin* sync_handler = NULL;
if (callee->is_synchronized()) {
lock = callee->is_static() ? append(new Constant(new InstanceConstant(callee->holder()->java_mirror())))
: state()->local_at(0);
sync_handler = new BlockBegin(SynchronizationEntryBCI);
inline_sync_entry(lock, sync_handler);
}
if (compilation()->env()->dtrace_method_probes()) {
Values* args = new Values(1);
args->push(append(new Constant(new MethodConstant(method()))));
append(new RuntimeCall(voidType, "dtrace_method_entry", CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), args));
}
if (profile_inlined_calls()) {
profile_invocation(callee, copy_state_before_with_bci(SynchronizationEntryBCI));
}
BlockBegin* callee_start_block = block_at(0);
if (callee_start_block != NULL) {
assert(callee_start_block->is_set(BlockBegin::parser_loop_header_flag), "must be loop header");
Goto* goto_callee = new Goto(callee_start_block, false);
append_with_bci(goto_callee, 0);
_block->set_end(goto_callee);
callee_start_block->merge(callee_state);
_last = _block = callee_start_block;
scope_data()->add_to_work_list(callee_start_block);
}
scope_data()->set_stream(NULL);
CompileLog* log = compilation()->log();
if (log != NULL) log->head("parse method='%d'", log->identify(callee));
iterate_all_blocks(callee_start_block == NULL);
if (log != NULL) log->done("parse");
if (bailed_out())
return false;
assert(continuation_existed ||
!continuation()->is_set(BlockBegin::was_visited_flag),
"continuation should not have been parsed yet if we created it");
if (num_returns() == 1
&& block() == orig_block
&& block() == inline_cleanup_block()) {
_last = inline_cleanup_return_prev();
_state = inline_cleanup_state();
} else if (continuation_preds == cont->number_of_preds()) {
assert(cont == continuation(), "");
assert(_last && _last->as_BlockEnd(), "");
_skip_block = true;
} else {
if (!continuation()->is_set(BlockBegin::was_visited_flag)) {
assert(_last && _last->as_BlockEnd(), "");
scope_data()->parent()->add_to_work_list(continuation());
_skip_block = true;
}
}
if (callee->is_synchronized() && sync_handler->state() != NULL) {
fill_sync_handler(lock, sync_handler);
} else {
pop_scope();
}
compilation()->notice_inlined_method(callee);
return true;
}
bool GraphBuilder::try_method_handle_inline(ciMethod* callee) {
ValueStack* state_before = state()->copy_for_parsing();
vmIntrinsics::ID iid = callee->intrinsic_id();
switch (iid) {
case vmIntrinsics::_invokeBasic:
{
const int args_base = state()->stack_size() - callee->arg_size();
ValueType* type = state()->stack_at(args_base)->type();
if (type->is_constant()) {
ciMethod* target = type->as_ObjectType()->constant_value()->as_method_handle()->get_vmtarget();
if (target->is_static() || target->can_be_statically_bound()) {
Bytecodes::Code bc = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual;
if (try_inline(target, /*holder_known*/ true, bc)) {
return true;
}
} else {
print_inlining(target, "not static or statically bindable", /*success*/ false);
}
} else {
print_inlining(callee, "receiver not constant", /*success*/ false);
}
}
break;
case vmIntrinsics::_linkToVirtual:
case vmIntrinsics::_linkToStatic:
case vmIntrinsics::_linkToSpecial:
case vmIntrinsics::_linkToInterface:
{
const int args_base = state()->stack_size() - callee->arg_size();
ValueType* type = apop()->type();
if (type->is_constant()) {
ciMethod* target = type->as_ObjectType()->constant_value()->as_member_name()->get_vmtarget();
if (target->is_method_handle_intrinsic()) {
if (try_method_handle_inline(target)) {
return true;
}
} else {
ciSignature* signature = target->signature();
const int receiver_skip = target->is_static() ? 0 : 1;
if (!target->is_static()) {
ciKlass* tk = signature->accessing_klass();
Value obj = state()->stack_at(args_base);
if (obj->exact_type() == NULL &&
obj->declared_type() != tk && tk != compilation()->env()->Object_klass()) {
TypeCast* c = new TypeCast(tk, obj, state_before);
append(c);
state()->stack_at_put(args_base, c);
}
}
for (int i = 0, j = 0; i < signature->count(); i++) {
ciType* t = signature->type_at(i);
if (t->is_klass()) {
ciKlass* tk = t->as_klass();
Value obj = state()->stack_at(args_base + receiver_skip + j);
if (obj->exact_type() == NULL &&
obj->declared_type() != tk && tk != compilation()->env()->Object_klass()) {
TypeCast* c = new TypeCast(t, obj, state_before);
append(c);
state()->stack_at_put(args_base + receiver_skip + j, c);
}
}
j += t->size(); // long and double take two slots
}
if (target->is_static() || target->can_be_statically_bound()) {
Bytecodes::Code bc = target->is_static() ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual;
if (try_inline(target, /*holder_known*/ true, bc)) {
return true;
}
} else {
print_inlining(target, "not static or statically bindable", /*success*/ false);
}
}
} else {
print_inlining(callee, "MemberName not constant", /*success*/ false);
}
}
break;
default:
fatal(err_msg("unexpected intrinsic %d: %s", iid, vmIntrinsics::name_at(iid)));
break;
}
set_state(state_before);
return false;
}
void GraphBuilder::inline_bailout(const char* msg) {
assert(msg != NULL, "inline bailout msg must exist");
_inline_bailout_msg = msg;
}
void GraphBuilder::clear_inline_bailout() {
_inline_bailout_msg = NULL;
}
void GraphBuilder::push_root_scope(IRScope* scope, BlockList* bci2block, BlockBegin* start) {
ScopeData* data = new ScopeData(NULL);
data->set_scope(scope);
data->set_bci2block(bci2block);
_scope_data = data;
_block = start;
}
void GraphBuilder::push_scope(ciMethod* callee, BlockBegin* continuation) {
IRScope* callee_scope = new IRScope(compilation(), scope(), bci(), callee, -1, false);
scope()->add_callee(callee_scope);
BlockListBuilder blb(compilation(), callee_scope, -1);
CHECK_BAILOUT();
if (!blb.bci2block()->at(0)->is_set(BlockBegin::parser_loop_header_flag)) {
blb.bci2block()->at_put(0, NULL);
}
set_state(new ValueStack(callee_scope, state()->copy(ValueStack::CallerState, bci())));
ScopeData* data = new ScopeData(scope_data());
data->set_scope(callee_scope);
data->set_bci2block(blb.bci2block());
data->set_continuation(continuation);
_scope_data = data;
}
void GraphBuilder::push_scope_for_jsr(BlockBegin* jsr_continuation, int jsr_dest_bci) {
ScopeData* data = new ScopeData(scope_data());
data->set_parsing_jsr();
data->set_jsr_entry_bci(jsr_dest_bci);
data->set_jsr_return_address_local(-1);
BlockList* new_bci2block = new BlockList(bci2block()->length());
new_bci2block->push_all(bci2block());
data->set_bci2block(new_bci2block);
data->set_scope(scope());
data->setup_jsr_xhandlers();
data->set_continuation(continuation());
data->set_jsr_continuation(jsr_continuation);
_scope_data = data;
}
void GraphBuilder::pop_scope() {
int number_of_locks = scope()->number_of_locks();
_scope_data = scope_data()->parent();
scope()->set_min_number_of_locks(number_of_locks);
}
void GraphBuilder::pop_scope_for_jsr() {
_scope_data = scope_data()->parent();
}
bool GraphBuilder::append_unsafe_get_obj(ciMethod* callee, BasicType t, bool is_volatile) {
if (InlineUnsafeOps) {
Values* args = state()->pop_arguments(callee->arg_size());
null_check(args->at(0));
Instruction* offset = args->at(2);
#ifndef _LP64
offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT)));
#endif
Instruction* op = append(new UnsafeGetObject(t, args->at(1), offset, is_volatile));
push(op->type(), op);
compilation()->set_has_unsafe_access(true);
}
return InlineUnsafeOps;
}
bool GraphBuilder::append_unsafe_put_obj(ciMethod* callee, BasicType t, bool is_volatile) {
if (InlineUnsafeOps) {
Values* args = state()->pop_arguments(callee->arg_size());
null_check(args->at(0));
Instruction* offset = args->at(2);
#ifndef _LP64
offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT)));
#endif
Value val = args->at(3);
if (t == T_BOOLEAN) {
Value mask = append(new Constant(new IntConstant(1)));
val = append(new LogicOp(Bytecodes::_iand, val, mask));
}
Instruction* op = append(new UnsafePutObject(t, args->at(1), offset, val, is_volatile));
compilation()->set_has_unsafe_access(true);
kill_all();
}
return InlineUnsafeOps;
}
bool GraphBuilder::append_unsafe_get_raw(ciMethod* callee, BasicType t) {
if (InlineUnsafeOps) {
Values* args = state()->pop_arguments(callee->arg_size());
null_check(args->at(0));
Instruction* op = append(new UnsafeGetRaw(t, args->at(1), false));
push(op->type(), op);
compilation()->set_has_unsafe_access(true);
}
return InlineUnsafeOps;
}
bool GraphBuilder::append_unsafe_put_raw(ciMethod* callee, BasicType t) {
if (InlineUnsafeOps) {
Values* args = state()->pop_arguments(callee->arg_size());
null_check(args->at(0));
Instruction* op = append(new UnsafePutRaw(t, args->at(1), args->at(2)));
compilation()->set_has_unsafe_access(true);
}
return InlineUnsafeOps;
}
bool GraphBuilder::append_unsafe_prefetch(ciMethod* callee, bool is_static, bool is_store) {
if (InlineUnsafeOps) {
Values* args = state()->pop_arguments(callee->arg_size());
int obj_arg_index = 1; // Assume non-static case
if (is_static) {
obj_arg_index = 0;
} else {
null_check(args->at(0));
}
Instruction* offset = args->at(obj_arg_index + 1);
#ifndef _LP64
offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT)));
#endif
Instruction* op = is_store ? append(new UnsafePrefetchWrite(args->at(obj_arg_index), offset))
: append(new UnsafePrefetchRead (args->at(obj_arg_index), offset));
compilation()->set_has_unsafe_access(true);
}
return InlineUnsafeOps;
}
void GraphBuilder::append_unsafe_CAS(ciMethod* callee) {
ValueStack* state_before = copy_state_for_exception();
ValueType* result_type = as_ValueType(callee->return_type());
assert(result_type->is_int(), "int result");
Values* args = state()->pop_arguments(callee->arg_size());
Value newval = args->pop();
Value cmpval = args->pop();
Value offset = args->pop();
Value src = args->pop();
Value unsafe_obj = args->pop();
null_check(unsafe_obj);
#ifndef _LP64
offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT)));
#endif
args->push(src);
args->push(offset);
args->push(cmpval);
args->push(newval);
bool preserves_state = false;
Intrinsic* result = new Intrinsic(result_type, callee->intrinsic_id(), args, false, state_before, preserves_state);
append_split(result);
push(result_type, result);
compilation()->set_has_unsafe_access(true);
}
static void post_inlining_event(EventCompilerInlining* event,
int compile_id,
const char* msg,
bool success,
int bci,
ciMethod* caller,
ciMethod* callee) {
assert(caller != NULL, "invariant");
assert(callee != NULL, "invariant");
assert(event != NULL, "invariant");
assert(event->should_commit(), "invariant");
JfrStructCalleeMethod callee_struct;
callee_struct.set_type(callee->holder()->name()->as_utf8());
callee_struct.set_name(callee->name()->as_utf8());
callee_struct.set_descriptor(callee->signature()->as_symbol()->as_utf8());
event->set_compileId(compile_id);
event->set_message(msg);
event->set_succeeded(success);
event->set_bci(bci);
event->set_caller(caller->get_Method());
event->set_callee(callee_struct);
event->commit();
}
void GraphBuilder::print_inlining(ciMethod* callee, const char* msg, bool success) {
CompileLog* log = compilation()->log();
if (log != NULL) {
if (success) {
if (msg != NULL)
log->inline_success(msg);
else
log->inline_success("receiver is statically known");
} else {
if (msg != NULL)
log->inline_fail(msg);
else
log->inline_fail("reason unknown");
}
}
EventCompilerInlining event;
if (event.should_commit()) {
post_inlining_event(&event, compilation()->env()->task()->compile_id(), msg, success, bci(), method(), callee);
}
if (!PrintInlining && !compilation()->method()->has_option("PrintInlining")) {
return;
}
CompileTask::print_inlining(callee, scope()->level(), bci(), msg);
if (success && CIPrintMethodCodes) {
callee->print_codes();
}
}
bool GraphBuilder::append_unsafe_get_and_set_obj(ciMethod* callee, bool is_add) {
if (InlineUnsafeOps) {
Values* args = state()->pop_arguments(callee->arg_size());
BasicType t = callee->return_type()->basic_type();
null_check(args->at(0));
Instruction* offset = args->at(2);
#ifndef _LP64
offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT)));
#endif
Instruction* op = append(new UnsafeGetAndSetObject(t, args->at(1), offset, args->at(3), is_add));
compilation()->set_has_unsafe_access(true);
kill_all();
push(op->type(), op);
}
return InlineUnsafeOps;
}
#ifndef PRODUCT
void GraphBuilder::print_stats() {
vmap()->print();
}
#endif // PRODUCT
void GraphBuilder::profile_call(ciMethod* callee, Value recv, ciKlass* known_holder, Values* obj_args, bool inlined) {
assert(known_holder == NULL || (known_holder->is_instance_klass() &&
(!known_holder->is_interface() ||
((ciInstanceKlass*)known_holder)->has_default_methods())), "should be default method");
if (known_holder != NULL) {
if (known_holder->exact_klass() == NULL) {
known_holder = compilation()->cha_exact_type(known_holder);
}
}
append(new ProfileCall(method(), bci(), callee, recv, known_holder, obj_args, inlined));
}
void GraphBuilder::profile_return_type(Value ret, ciMethod* callee, ciMethod* m, int invoke_bci) {
assert((m == NULL) == (invoke_bci < 0), "invalid method and invalid bci together");
if (m == NULL) {
m = method();
}
if (invoke_bci < 0) {
invoke_bci = bci();
}
ciMethodData* md = m->method_data_or_null();
ciProfileData* data = md->bci_to_data(invoke_bci);
if (data != NULL && (data->is_CallTypeData() || data->is_VirtualCallTypeData())) {
append(new ProfileReturnType(m , invoke_bci, callee, ret));
}
}
void GraphBuilder::profile_invocation(ciMethod* callee, ValueStack* state) {
append(new ProfileInvoke(callee, state));
}
C:\hotspot-69087d08d473\src\share\vm/c1/c1_GraphBuilder.hpp
#ifndef SHARE_VM_C1_C1_GRAPHBUILDER_HPP
#define SHARE_VM_C1_C1_GRAPHBUILDER_HPP
#include "c1/c1_IR.hpp"
#include "c1/c1_Instruction.hpp"
#include "c1/c1_ValueMap.hpp"
#include "c1/c1_ValueStack.hpp"
#include "ci/ciMethodData.hpp"
#include "ci/ciStreams.hpp"
#include "compiler/compileLog.hpp"
class MemoryBuffer;
class GraphBuilder VALUE_OBJ_CLASS_SPEC {
private:
class ScopeData: public CompilationResourceObj {
private:
ScopeData* _parent;
BlockList* _bci2block;
IRScope* _scope;
bool _has_handler;
ciBytecodeStream* _stream;
BlockList* _work_list;
intx _max_inline_size;
int _caller_stack_size;
BlockBegin* _continuation;
bool _parsing_jsr;
int _jsr_entry_bci;
int _jsr_ret_addr_local;
BlockBegin* _jsr_continuation;
XHandlers* _jsr_xhandlers;
int _num_returns;
BlockBegin* _cleanup_block; // The block to which the return was added
Instruction* _cleanup_return_prev; // Instruction before return instruction
ValueStack* _cleanup_state; // State of that block (not yet pinned)
public:
ScopeData(ScopeData* parent);
ScopeData* parent() const { return _parent; }
BlockList* bci2block() const { return _bci2block; }
void set_bci2block(BlockList* bci2block) { _bci2block = bci2block; }
BlockBegin* block_at(int bci);
IRScope* scope() const { return _scope; }
void set_scope(IRScope* scope);
bool has_handler() const { return _has_handler; }
void set_has_handler() { _has_handler = true; }
XHandlers* xhandlers() const;
void add_to_work_list(BlockBegin* block);
BlockBegin* remove_from_work_list();
bool is_work_list_empty() const;
ciBytecodeStream* stream() { return _stream; }
void set_stream(ciBytecodeStream* stream) { _stream = stream; }
intx max_inline_size() const { return _max_inline_size; }
BlockBegin* continuation() const { return _continuation; }
void set_continuation(BlockBegin* cont) { _continuation = cont; }
bool parsing_jsr() const { return _parsing_jsr; }
void set_parsing_jsr() { _parsing_jsr = true; }
int jsr_entry_bci() const { return _jsr_entry_bci; }
void set_jsr_entry_bci(int bci) { _jsr_entry_bci = bci; }
void set_jsr_return_address_local(int local_no){ _jsr_ret_addr_local = local_no; }
int jsr_return_address_local() const { return _jsr_ret_addr_local; }
void setup_jsr_xhandlers();
BlockBegin* jsr_continuation() const { return _jsr_continuation; }
void set_jsr_continuation(BlockBegin* cont) { _jsr_continuation = cont; }
int num_returns();
void incr_num_returns();
void set_inline_cleanup_info(BlockBegin* block,
Instruction* return_prev,
ValueStack* return_state);
BlockBegin* inline_cleanup_block() const { return _cleanup_block; }
Instruction* inline_cleanup_return_prev() const{ return _cleanup_return_prev; }
ValueStack* inline_cleanup_state() const { return _cleanup_state; }
};
static bool _can_trap[Bytecodes::number_of_java_codes];
ScopeData* _scope_data; // Per-scope data; used for inlining
Compilation* _compilation; // the current compilation
ValueMap* _vmap; // the map of values encountered (for CSE)
MemoryBuffer* _memory;
const char* _inline_bailout_msg; // non-null if most recent inline attempt failed
int _instruction_count; // for bailing out in pathological jsr/ret cases
BlockBegin* _start; // the start block
BlockBegin* _osr_entry; // the osr entry block block
ValueStack* _initial_state; // The state for the start block
BlockBegin* _block; // the current block
ValueStack* _state; // the current execution state
Instruction* _last; // the last instruction added
bool _skip_block; // skip processing of the rest of this block
ScopeData* scope_data() const { return _scope_data; }
Compilation* compilation() const { return _compilation; }
BlockList* bci2block() const { return scope_data()->bci2block(); }
ValueMap* vmap() const { assert(UseLocalValueNumbering, "should not access otherwise"); return _vmap; }
bool has_handler() const { return scope_data()->has_handler(); }
BlockBegin* block() const { return _block; }
ValueStack* state() const { return _state; }
void set_state(ValueStack* state) { _state = state; }
IRScope* scope() const { return scope_data()->scope(); }
ciMethod* method() const { return scope()->method(); }
ciBytecodeStream* stream() const { return scope_data()->stream(); }
Instruction* last() const { return _last; }
Bytecodes::Code code() const { return stream()->cur_bc(); }
int bci() const { return stream()->cur_bci(); }
int next_bci() const { return stream()->next_bci(); }
void bailout(const char* msg) const { compilation()->bailout(msg); }
bool bailed_out() const { return compilation()->bailed_out(); }
void ipush(Value t) const { state()->ipush(t); }
void lpush(Value t) const { state()->lpush(t); }
void fpush(Value t) const { state()->fpush(t); }
void dpush(Value t) const { state()->dpush(t); }
void apush(Value t) const { state()->apush(t); }
void push(ValueType* type, Value t) const { state()-> push(type, t); }
Value ipop() { return state()->ipop(); }
Value lpop() { return state()->lpop(); }
Value fpop() { return state()->fpop(); }
Value dpop() { return state()->dpop(); }
Value apop() { return state()->apop(); }
Value pop(ValueType* type) { return state()-> pop(type); }
void load_constant();
void load_local(ValueType* type, int index);
void store_local(ValueType* type, int index);
void store_local(ValueStack* state, Value value, int index);
void load_indexed (BasicType type);
void store_indexed(BasicType type);
void stack_op(Bytecodes::Code code);
void arithmetic_op(ValueType* type, Bytecodes::Code code, ValueStack* state_before = NULL);
void negate_op(ValueType* type);
void shift_op(ValueType* type, Bytecodes::Code code);
void logic_op(ValueType* type, Bytecodes::Code code);
void compare_op(ValueType* type, Bytecodes::Code code);
void convert(Bytecodes::Code op, BasicType from, BasicType to);
void increment();
void _goto(int from_bci, int to_bci);
void if_node(Value x, If::Condition cond, Value y, ValueStack* stack_before);
void if_zero(ValueType* type, If::Condition cond);
void if_null(ValueType* type, If::Condition cond);
void if_same(ValueType* type, If::Condition cond);
void jsr(int dest);
void ret(int local_index);
void table_switch();
void lookup_switch();
void method_return(Value x);
void call_register_finalizer();
void access_field(Bytecodes::Code code);
void invoke(Bytecodes::Code code);
void new_instance(int klass_index);
void new_type_array();
void new_object_array();
void check_cast(int klass_index);
void instance_of(int klass_index);
void monitorenter(Value x, int bci);
void monitorexit(Value x, int bci);
void new_multi_array(int dimensions);
void throw_op(int bci);
Value round_fp(Value fp_value);
Instruction* append_with_bci(Instruction* instr, int bci);
Instruction* append(Instruction* instr);
Instruction* append_split(StateSplit* instr);
BlockBegin* block_at(int bci) { return scope_data()->block_at(bci); }
XHandlers* handle_exception(Instruction* instruction);
void connect_to_end(BlockBegin* beg);
void null_check(Value value);
void eliminate_redundant_phis(BlockBegin* start);
BlockEnd* iterate_bytecodes_for_block(int bci);
void iterate_all_blocks(bool start_in_current_block_for_inlining = false);
Dependencies* dependency_recorder() const; // = compilation()->dependencies()
bool direct_compare(ciKlass* k);
void kill_all();
ValueStack* copy_state_before_with_bci(int bci);
ValueStack* copy_state_before();
ValueStack* copy_state_exhandling_with_bci(int bci);
ValueStack* copy_state_exhandling();
ValueStack* copy_state_for_exception_with_bci(int bci);
ValueStack* copy_state_for_exception();
ValueStack* copy_state_if_bb(bool is_bb) { return (is_bb || compilation()->is_optimistic()) ? copy_state_before() : NULL; }
ValueStack* copy_state_indexed_access() { return compilation()->is_optimistic() ? copy_state_before() : copy_state_for_exception(); }
bool parsing_jsr() const { return scope_data()->parsing_jsr(); }
BlockBegin* continuation() const { return scope_data()->continuation(); }
BlockBegin* jsr_continuation() const { return scope_data()->jsr_continuation(); }
void set_continuation(BlockBegin* continuation) { scope_data()->set_continuation(continuation); }
void set_inline_cleanup_info(BlockBegin* block,
Instruction* return_prev,
ValueStack* return_state) { scope_data()->set_inline_cleanup_info(block,
return_prev,
return_state); }
void set_inline_cleanup_info() {
set_inline_cleanup_info(_block, _last, _state);
}
BlockBegin* inline_cleanup_block() const { return scope_data()->inline_cleanup_block(); }
Instruction* inline_cleanup_return_prev() const { return scope_data()->inline_cleanup_return_prev(); }
ValueStack* inline_cleanup_state() const { return scope_data()->inline_cleanup_state(); }
void restore_inline_cleanup_info() {
_block = inline_cleanup_block();
_last = inline_cleanup_return_prev();
_state = inline_cleanup_state();
}
void incr_num_returns() { scope_data()->incr_num_returns(); }
int num_returns() const { return scope_data()->num_returns(); }
intx max_inline_size() const { return scope_data()->max_inline_size(); }
int inline_level() const { return scope()->level(); }
int recursive_inline_level(ciMethod* callee) const;
void inline_sync_entry(Value lock, BlockBegin* sync_handler);
void fill_sync_handler(Value lock, BlockBegin* sync_handler, bool default_handler = false);
bool try_inline( ciMethod* callee, bool holder_known, Bytecodes::Code bc = Bytecodes::_illegal, Value receiver = NULL);
bool try_inline_intrinsics(ciMethod* callee);
bool try_inline_full( ciMethod* callee, bool holder_known, Bytecodes::Code bc = Bytecodes::_illegal, Value receiver = NULL);
bool try_inline_jsr(int jsr_dest_bci);
const char* check_can_parse(ciMethod* callee) const;
const char* should_not_inline(ciMethod* callee) const;
bool try_method_handle_inline(ciMethod* callee);
void inline_bailout(const char* msg);
BlockBegin* header_block(BlockBegin* entry, BlockBegin::Flag f, ValueStack* state);
BlockBegin* setup_start_block(int osr_bci, BlockBegin* std_entry, BlockBegin* osr_entry, ValueStack* init_state);
void setup_osr_entry_block();
void clear_inline_bailout();
ValueStack* state_at_entry();
void push_root_scope(IRScope* scope, BlockList* bci2block, BlockBegin* start);
void push_scope(ciMethod* callee, BlockBegin* continuation);
void push_scope_for_jsr(BlockBegin* jsr_continuation, int jsr_dest_bci);
void pop_scope();
void pop_scope_for_jsr();
bool append_unsafe_get_obj(ciMethod* callee, BasicType t, bool is_volatile);
bool append_unsafe_put_obj(ciMethod* callee, BasicType t, bool is_volatile);
bool append_unsafe_get_raw(ciMethod* callee, BasicType t);
bool append_unsafe_put_raw(ciMethod* callee, BasicType t);
bool append_unsafe_prefetch(ciMethod* callee, bool is_store, bool is_static);
void append_unsafe_CAS(ciMethod* callee);
bool append_unsafe_get_and_set_obj(ciMethod* callee, bool is_add);
void print_inlining(ciMethod* callee, const char* msg = NULL, bool success = true);
void profile_call(ciMethod* callee, Value recv, ciKlass* predicted_holder, Values* obj_args, bool inlined);
void profile_return_type(Value ret, ciMethod* callee, ciMethod* m = NULL, int bci = -1);
void profile_invocation(ciMethod* inlinee, ValueStack* state);
bool is_profiling() { return _compilation->is_profiling(); }
bool count_invocations() { return _compilation->count_invocations(); }
bool count_backedges() { return _compilation->count_backedges(); }
bool profile_branches() { return _compilation->profile_branches(); }
bool profile_calls() { return _compilation->profile_calls(); }
bool profile_inlined_calls() { return _compilation->profile_inlined_calls(); }
bool profile_checkcasts() { return _compilation->profile_checkcasts(); }
bool profile_parameters() { return _compilation->profile_parameters(); }
bool profile_arguments() { return _compilation->profile_arguments(); }
bool profile_return() { return _compilation->profile_return(); }
Values* args_list_for_profiling(ciMethod* target, int& start, bool may_have_receiver);
Values* collect_args_for_profiling(Values* args, ciMethod* target, bool may_have_receiver);
void check_args_for_profiling(Values* obj_args, int expected);
public:
NOT_PRODUCT(void print_stats();)
static void initialize();
static bool can_trap(ciMethod* method, Bytecodes::Code code) {
assert(0 <= code && code < Bytecodes::number_of_java_codes, "illegal bytecode");
if (_can_trap[code]) return true;
return code == Bytecodes::_return && method->intrinsic_id() == vmIntrinsics::_Object_init;
}
GraphBuilder(Compilation* compilation, IRScope* scope);
static void sort_top_into_worklist(BlockList* worklist, BlockBegin* top);
BlockBegin* start() const { return _start; }
};
#endif // SHARE_VM_C1_C1_GRAPHBUILDER_HPP
C:\hotspot-69087d08d473\src\share\vm/c1/c1_Instruction.cpp
#include "precompiled.hpp"
#include "c1/c1_IR.hpp"
#include "c1/c1_Instruction.hpp"
#include "c1/c1_InstructionPrinter.hpp"
#include "c1/c1_ValueStack.hpp"
#include "ci/ciObjArrayKlass.hpp"
#include "ci/ciTypeArrayKlass.hpp"
int Instruction::dominator_depth() {
int result = -1;
if (block()) {
result = block()->dominator_depth();
}
assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
return result;
}
Instruction::Condition Instruction::mirror(Condition cond) {
switch (cond) {
case eql: return eql;
case neq: return neq;
case lss: return gtr;
case leq: return geq;
case gtr: return lss;
case geq: return leq;
case aeq: return beq;
case beq: return aeq;
}
ShouldNotReachHere();
return eql;
}
Instruction::Condition Instruction::negate(Condition cond) {
switch (cond) {
case eql: return neq;
case neq: return eql;
case lss: return geq;
case leq: return gtr;
case gtr: return leq;
case geq: return lss;
case aeq: assert(false, "Above equal cannot be negated");
case beq: assert(false, "Below equal cannot be negated");
}
ShouldNotReachHere();
return eql;
}
void Instruction::update_exception_state(ValueStack* state) {
if (state != NULL && (state->kind() == ValueStack::EmptyExceptionState || state->kind() == ValueStack::ExceptionState)) {
assert(state->kind() == ValueStack::EmptyExceptionState || Compilation::current()->env()->should_retain_local_variables(), "unexpected state kind");
_exception_state = state;
} else {
_exception_state = NULL;
}
}
Instruction* Instruction::prev() {
Instruction* p = NULL;
Instruction* q = block();
while (q != this) {
assert(q != NULL, "this is not in the block's instruction list");
p = q; q = q->next();
}
return p;
}
void Instruction::state_values_do(ValueVisitor* f) {
if (state_before() != NULL) {
state_before()->values_do(f);
}
if (exception_state() != NULL){
exception_state()->values_do(f);
}
}
ciType* Instruction::exact_type() const {
ciType* t = declared_type();
if (t != NULL && t->is_klass()) {
return t->as_klass()->exact_klass();
}
return NULL;
}
#ifndef PRODUCT
void Instruction::check_state(ValueStack* state) {
if (state != NULL) {
state->verify();
}
}
void Instruction::print() {
InstructionPrinter ip;
print(ip);
}
void Instruction::print_line() {
InstructionPrinter ip;
ip.print_line(this);
}
void Instruction::print(InstructionPrinter& ip) {
ip.print_head();
ip.print_line(this);
tty->cr();
}
#endif // PRODUCT
bool AccessIndexed::compute_needs_range_check() {
if (length()) {
Constant* clength = length()->as_Constant();
Constant* cindex = index()->as_Constant();
if (clength && cindex) {
IntConstant* l = clength->type()->as_IntConstant();
IntConstant* i = cindex->type()->as_IntConstant();
if (l && i && i->value() < l->value() && i->value() >= 0) {
return false;
}
}
}
if (!this->check_flag(NeedsRangeCheckFlag)) {
return false;
}
return true;
}
ciType* Constant::exact_type() const {
if (type()->is_object() && type()->as_ObjectType()->is_loaded()) {
return type()->as_ObjectType()->exact_type();
}
return NULL;
}
ciType* LoadIndexed::exact_type() const {
ciType* array_type = array()->exact_type();
if (array_type != NULL) {
assert(array_type->is_array_klass(), "what else?");
ciArrayKlass* ak = (ciArrayKlass*)array_type;
if (ak->element_type()->is_instance_klass()) {
ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
if (ik->is_loaded() && ik->is_final()) {
return ik;
}
}
}
return Instruction::exact_type();
}
ciType* LoadIndexed::declared_type() const {
ciType* array_type = array()->declared_type();
if (array_type == NULL || !array_type->is_loaded()) {
return NULL;
}
assert(array_type->is_array_klass(), "what else?");
ciArrayKlass* ak = (ciArrayKlass*)array_type;
return ak->element_type();
}
ciType* LoadField::declared_type() const {
return field()->type();
}
ciType* NewTypeArray::exact_type() const {
return ciTypeArrayKlass::make(elt_type());
}
ciType* NewObjectArray::exact_type() const {
return ciObjArrayKlass::make(klass());
}
ciType* NewArray::declared_type() const {
return exact_type();
}
ciType* NewInstance::exact_type() const {
return klass();
}
ciType* NewInstance::declared_type() const {
return exact_type();
}
ciType* CheckCast::declared_type() const {
return klass();
}
bool ArithmeticOp::is_commutative() const {
switch (op()) {
case Bytecodes::_iadd: // fall through
case Bytecodes::_ladd: // fall through
case Bytecodes::_fadd: // fall through
case Bytecodes::_dadd: // fall through
case Bytecodes::_imul: // fall through
case Bytecodes::_lmul: // fall through
case Bytecodes::_fmul: // fall through
case Bytecodes::_dmul: return true;
}
return false;
}
bool ArithmeticOp::can_trap() const {
switch (op()) {
case Bytecodes::_idiv: // fall through
case Bytecodes::_ldiv: // fall through
case Bytecodes::_irem: // fall through
case Bytecodes::_lrem: return true;
}
return false;
}
bool LogicOp::is_commutative() const {
#ifdef ASSERT
switch (op()) {
case Bytecodes::_iand: // fall through
case Bytecodes::_land: // fall through
case Bytecodes::_ior : // fall through
case Bytecodes::_lor : // fall through
case Bytecodes::_ixor: // fall through
case Bytecodes::_lxor: break;
default : ShouldNotReachHere();
}
#endif
return true;
}
bool IfOp::is_commutative() const {
return cond() == eql || cond() == neq;
}
void StateSplit::substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block) {
NOT_PRODUCT(bool assigned = false;)
for (int i = 0; i < list.length(); i++) {
BlockBegin** b = list.adr_at(i);
if (*b == old_block) {
NOT_PRODUCT(assigned = true;)
}
}
assert(assigned == true, "should have assigned at least once");
}
IRScope* StateSplit::scope() const {
return _state->scope();
}
void StateSplit::state_values_do(ValueVisitor* f) {
Instruction::state_values_do(f);
if (state() != NULL) state()->values_do(f);
}
void BlockBegin::state_values_do(ValueVisitor* f) {
StateSplit::state_values_do(f);
if (is_set(BlockBegin::exception_entry_flag)) {
for (int i = 0; i < number_of_exception_states(); i++) {
exception_state_at(i)->values_do(f);
}
}
}
Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
int vtable_index, ciMethod* target, ValueStack* state_before)
: StateSplit(result_type, state_before)
, _code(code)
, _recv(recv)
, _args(args)
, _vtable_index(vtable_index)
, _target(target)
{
set_flag(TargetIsLoadedFlag, target->is_loaded());
set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method());
set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());
assert(args != NULL, "args must exist");
#ifdef ASSERT
AssertValues assert_value;
values_do(&assert_value);
#endif
_signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
if (has_receiver()) {
_signature->append(as_BasicType(receiver()->type()));
}
for (int i = 0; i < number_of_arguments(); i++) {
ValueType* t = argument_at(i)->type();
BasicType bt = as_BasicType(t);
_signature->append(bt);
}
}
void Invoke::state_values_do(ValueVisitor* f) {
StateSplit::state_values_do(f);
if (state_before() != NULL) state_before()->values_do(f);
if (state() != NULL) state()->values_do(f);
}
ciType* Invoke::declared_type() const {
ciSignature* declared_signature = state()->scope()->method()->get_declared_signature_at_bci(state()->bci());
ciType *t = declared_signature->return_type();
assert(t->basic_type() != T_VOID, "need return value of void method?");
return t;
}
intx Constant::hash() const {
if (state_before() == NULL) {
switch (type()->tag()) {
case intTag:
return HASH2(name(), type()->as_IntConstant()->value());
case addressTag:
return HASH2(name(), type()->as_AddressConstant()->value());
case longTag:
{
jlong temp = type()->as_LongConstant()->value();
return HASH3(name(), high(temp), low(temp));
}
case floatTag:
return HASH2(name(), jint_cast(type()->as_FloatConstant()->value()));
case doubleTag:
{
jlong temp = jlong_cast(type()->as_DoubleConstant()->value());
return HASH3(name(), high(temp), low(temp));
}
case objectTag:
assert(type()->as_ObjectType()->is_loaded(), "can't handle unloaded values");
return HASH2(name(), type()->as_ObjectType()->constant_value());
case metaDataTag:
assert(type()->as_MetadataType()->is_loaded(), "can't handle unloaded values");
return HASH2(name(), type()->as_MetadataType()->constant_value());
default:
ShouldNotReachHere();
}
}
return 0;
}
bool Constant::is_equal(Value v) const {
if (v->as_Constant() == NULL) return false;
switch (type()->tag()) {
case intTag:
{
IntConstant* t1 = type()->as_IntConstant();
IntConstant* t2 = v->type()->as_IntConstant();
return (t1 != NULL && t2 != NULL &&
t1->value() == t2->value());
}
case longTag:
{
LongConstant* t1 = type()->as_LongConstant();
LongConstant* t2 = v->type()->as_LongConstant();
return (t1 != NULL && t2 != NULL &&
t1->value() == t2->value());
}
case floatTag:
{
FloatConstant* t1 = type()->as_FloatConstant();
FloatConstant* t2 = v->type()->as_FloatConstant();
return (t1 != NULL && t2 != NULL &&
jint_cast(t1->value()) == jint_cast(t2->value()));
}
case doubleTag:
{
DoubleConstant* t1 = type()->as_DoubleConstant();
DoubleConstant* t2 = v->type()->as_DoubleConstant();
return (t1 != NULL && t2 != NULL &&
jlong_cast(t1->value()) == jlong_cast(t2->value()));
}
case objectTag:
{
ObjectType* t1 = type()->as_ObjectType();
ObjectType* t2 = v->type()->as_ObjectType();
return (t1 != NULL && t2 != NULL &&
t1->is_loaded() && t2->is_loaded() &&
t1->constant_value() == t2->constant_value());
}
case metaDataTag:
{
MetadataType* t1 = type()->as_MetadataType();
MetadataType* t2 = v->type()->as_MetadataType();
return (t1 != NULL && t2 != NULL &&
t1->is_loaded() && t2->is_loaded() &&
t1->constant_value() == t2->constant_value());
}
}
return false;
}
Constant::CompareResult Constant::compare(Instruction::Condition cond, Value right) const {
Constant* rc = right->as_Constant();
if (rc == NULL) return not_comparable;
ValueType* lt = type();
ValueType* rt = rc->type();
if (lt->base() != rt->base()) return not_comparable;
switch (lt->tag()) {
case intTag: {
int x = lt->as_IntConstant()->value();
int y = rt->as_IntConstant()->value();
switch (cond) {
case If::eql: return x == y ? cond_true : cond_false;
case If::neq: return x != y ? cond_true : cond_false;
case If::lss: return x < y ? cond_true : cond_false;
case If::leq: return x <= y ? cond_true : cond_false;
case If::gtr: return x > y ? cond_true : cond_false;
case If::geq: return x >= y ? cond_true : cond_false;
}
break;
}
case longTag: {
jlong x = lt->as_LongConstant()->value();
jlong y = rt->as_LongConstant()->value();
switch (cond) {
case If::eql: return x == y ? cond_true : cond_false;
case If::neq: return x != y ? cond_true : cond_false;
case If::lss: return x < y ? cond_true : cond_false;
case If::leq: return x <= y ? cond_true : cond_false;
case If::gtr: return x > y ? cond_true : cond_false;
case If::geq: return x >= y ? cond_true : cond_false;
}
break;
}
case objectTag: {
ciObject* xvalue = lt->as_ObjectType()->constant_value();
ciObject* yvalue = rt->as_ObjectType()->constant_value();
assert(xvalue != NULL && yvalue != NULL, "not constants");
if (xvalue->is_loaded() && yvalue->is_loaded()) {
switch (cond) {
case If::eql: return xvalue == yvalue ? cond_true : cond_false;
case If::neq: return xvalue != yvalue ? cond_true : cond_false;
}
}
break;
}
case metaDataTag: {
ciMetadata* xvalue = lt->as_MetadataType()->constant_value();
ciMetadata* yvalue = rt->as_MetadataType()->constant_value();
assert(xvalue != NULL && yvalue != NULL, "not constants");
if (xvalue->is_loaded() && yvalue->is_loaded()) {
switch (cond) {
case If::eql: return xvalue == yvalue ? cond_true : cond_false;
case If::neq: return xvalue != yvalue ? cond_true : cond_false;
}
}
break;
}
}
return not_comparable;
}
void BlockBegin::set_end(BlockEnd* end) {
assert(end != NULL, "should not reset block end to NULL");
if (end == _end) {
return;
}
clear_end();
_end = end;
_successors.clear();
for (int i = 0; i < end->number_of_sux(); i++) {
BlockBegin* sux = end->sux_at(i);
_successors.append(sux);
sux->_predecessors.append(this);
}
_end->set_begin(this);
}
void BlockBegin::clear_end() {
if (_end != NULL) {
_end->set_begin(NULL);
for (int i = 0; i < _successors.length(); i++) {
_successors.at(i)->remove_predecessor(this);
}
_end = NULL;
}
}
void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) {
#ifndef PRODUCT
if (PrintIR && Verbose) {
tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id());
}
#endif
for (int s = 0; s < from->number_of_sux();) {
BlockBegin* sux = from->sux_at(s);
if (sux == to) {
int index = sux->_predecessors.index_of(from);
if (index >= 0) {
sux->_predecessors.remove_at(index);
}
from->_successors.remove_at(s);
} else {
s++;
}
}
}
void BlockBegin::disconnect_from_graph() {
for (int p = 0; p < number_of_preds(); p++) {
pred_at(p)->remove_successor(this);
}
for (int s = 0; s < number_of_sux(); s++) {
sux_at(s)->remove_predecessor(this);
}
}
void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
for (int i = 0; i < number_of_sux(); i++) {
if (sux_at(i) == old_sux) {
new_sux->remove_predecessor(old_sux);
new_sux->add_predecessor(this);
}
}
old_sux->remove_predecessor(this);
end()->substitute_sux(old_sux, new_sux);
}
BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) {
int bci = sux->bci();
BlockBegin* new_sux = new BlockBegin(bci);
new_sux->set(critical_edge_split_flag);
Goto* e = new Goto(sux, false);
new_sux->set_next(e, bci);
new_sux->set_end(e);
ValueStack* s = end()->state();
new_sux->set_state(s->copy(s->kind(), bci));
e->set_state(s->copy(s->kind(), bci));
assert(new_sux->state()->locals_size() == s->locals_size(), "local size mismatch!");
assert(new_sux->state()->stack_size() == s->stack_size(), "stack size mismatch!");
assert(new_sux->state()->locks_size() == s->locks_size(), "locks size mismatch!");
end()->substitute_sux(sux, new_sux);
sux->remove_predecessor(new_sux);
bool assigned = false;
BlockList& list = sux->_predecessors;
for (int i = 0; i < list.length(); i++) {
BlockBegin** b = list.adr_at(i);
if (*b == this) {
if (assigned) {
list.remove_at(i);
i--;
} else {
assigned = true;
}
new_sux->add_predecessor(this);
}
}
assert(assigned == true, "should have assigned at least once");
return new_sux;
}
void BlockBegin::remove_successor(BlockBegin* pred) {
int idx;
while ((idx = _successors.index_of(pred)) >= 0) {
_successors.remove_at(idx);
}
}
void BlockBegin::add_predecessor(BlockBegin* pred) {
_predecessors.append(pred);
}
void BlockBegin::remove_predecessor(BlockBegin* pred) {
int idx;
while ((idx = _predecessors.index_of(pred)) >= 0) {
_predecessors.remove_at(idx);
}
}
void BlockBegin::add_exception_handler(BlockBegin* b) {
assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist");
if (!_exception_handlers.contains(b)) _exception_handlers.append(b);
}
int BlockBegin::add_exception_state(ValueStack* state) {
assert(is_set(exception_entry_flag), "only for xhandlers");
if (_exception_states == NULL) {
_exception_states = new ValueStackStack(4);
}
_exception_states->append(state);
return _exception_states->length() - 1;
}
void BlockBegin::iterate_preorder(boolArray& mark, BlockClosure* closure) {
if (!mark.at(block_id())) {
mark.at_put(block_id(), true);
closure->block_do(this);
BlockEnd* e = end(); // must do this after block_do because block_do may change it!
{ for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); }
{ for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_preorder(mark, closure); }
}
}
void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) {
if (!mark.at(block_id())) {
mark.at_put(block_id(), true);
BlockEnd* e = end();
{ for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); }
{ for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_postorder(mark, closure); }
closure->block_do(this);
}
}
void BlockBegin::iterate_preorder(BlockClosure* closure) {
boolArray mark(number_of_blocks(), false);
iterate_preorder(mark, closure);
}
void BlockBegin::iterate_postorder(BlockClosure* closure) {
boolArray mark(number_of_blocks(), false);
iterate_postorder(mark, closure);
}
void BlockBegin::block_values_do(ValueVisitor* f) {
for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f);
}
#ifndef PRODUCT
#define TRACE_PHI(code) if (PrintPhiFunctions) { code; }
#else
#define TRACE_PHI(coce)
#endif
bool BlockBegin::try_merge(ValueStack* new_state) {
TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id()));
int index;
Value new_value, existing_value;
ValueStack* existing_state = state();
if (existing_state == NULL) {
TRACE_PHI(tty->print_cr("first call of try_merge for this block"));
if (is_set(BlockBegin::was_visited_flag)) {
return false; // BAILOUT in caller
}
new_state = new_state->copy(ValueStack::BlockBeginState, bci());
MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());
if (liveness.is_valid()) {
assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");
for_each_local_value(new_state, index, new_value) {
if (!liveness.at(index) || new_value->type()->is_illegal()) {
new_state->invalidate_local(index);
TRACE_PHI(tty->print_cr("invalidating dead local %d", index));
}
}
}
if (is_set(BlockBegin::parser_loop_header_flag)) {
TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));
for_each_stack_value(new_state, index, new_value) {
new_state->setup_phi_for_stack(this, index);
TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", new_state->stack_at(index)->type()->tchar(), new_state->stack_at(index)->id(), index));
}
BitMap requires_phi_function = new_state->scope()->requires_phi_function();
for_each_local_value(new_state, index, new_value) {
bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1));
if (requires_phi || !SelectivePhiFunctions) {
new_state->setup_phi_for_local(this, index);
TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", new_state->local_at(index)->type()->tchar(), new_state->local_at(index)->id(), index));
}
}
}
set_state(new_state);
} else if (existing_state->is_same(new_state)) {
TRACE_PHI(tty->print_cr("exisiting state found"));
assert(existing_state->scope() == new_state->scope(), "not matching");
assert(existing_state->locals_size() == new_state->locals_size(), "not matching");
assert(existing_state->stack_size() == new_state->stack_size(), "not matching");
if (is_set(BlockBegin::was_visited_flag)) {
TRACE_PHI(tty->print_cr("loop header block, phis must be present"));
if (!is_set(BlockBegin::parser_loop_header_flag)) {
return false; // BAILOUT in caller
}
for_each_local_value(existing_state, index, existing_value) {
Value new_value = new_state->local_at(index);
if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
return false; // BAILOUT in caller
}
}
#ifdef ASSERT
for_each_stack_value(existing_state, index, existing_value) {
assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");
}
for_each_local_value(existing_state, index, existing_value) {
assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required");
}
#endif
} else {
TRACE_PHI(tty->print_cr("creating phi functions on demand"));
for_each_stack_value(existing_state, index, existing_value) {
Value new_value = new_state->stack_at(index);
Phi* existing_phi = existing_value->as_Phi();
if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
existing_state->setup_phi_for_stack(this, index);
TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", existing_state->stack_at(index)->type()->tchar(), existing_state->stack_at(index)->id(), index));
}
}
for_each_local_value(existing_state, index, existing_value) {
Value new_value = new_state->local_at(index);
Phi* existing_phi = existing_value->as_Phi();
if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
existing_state->invalidate_local(index);
TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
} else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
existing_state->setup_phi_for_local(this, index);
TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", existing_state->local_at(index)->type()->tchar(), existing_state->local_at(index)->id(), index));
}
}
}
assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal");
} else {
assert(false, "stack or locks not matching (invalid bytecodes)");
return false;
}
TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id()));
return true;
}
#ifndef PRODUCT
void BlockBegin::print_block() {
InstructionPrinter ip;
print_block(ip, false);
}
void BlockBegin::print_block(InstructionPrinter& ip, bool live_only) {
ip.print_instr(this); tty->cr();
ip.print_stack(this->state()); tty->cr();
ip.print_inline_level(this);
ip.print_head();
for (Instruction* n = next(); n != NULL; n = n->next()) {
if (!live_only || n->is_pinned() || n->use_count() > 0) {
ip.print_line(n);
}
}
tty->cr();
}
#endif // PRODUCT
void BlockList::iterate_forward (BlockClosure* closure) {
const int l = length();
for (int i = 0; i < l; i++) closure->block_do(at(i));
}
void BlockList::iterate_backward(BlockClosure* closure) {
for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i));
}
void BlockList::blocks_do(void f(BlockBegin*)) {
for (int i = length() - 1; i >= 0; i--) f(at(i));
}
void BlockList::values_do(ValueVisitor* f) {
for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f);
}
#ifndef PRODUCT
void BlockList::print(bool cfg_only, bool live_only) {
InstructionPrinter ip;
for (int i = 0; i < length(); i++) {
BlockBegin* block = at(i);
if (cfg_only) {
ip.print_instr(block); tty->cr();
} else {
block->print_block(ip, live_only);
}
}
}
#endif // PRODUCT
void BlockEnd::set_begin(BlockBegin* begin) {
BlockList* sux = NULL;
if (begin != NULL) {
sux = begin->successors();
} else if (this->begin() != NULL) {
BlockList* sux = new BlockList(this->begin()->number_of_sux());
for (int i = 0; i < this->begin()->number_of_sux(); i++) {
sux->append(this->begin()->sux_at(i));
}
}
_sux = sux;
}
void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
substitute(*_sux, old_sux, new_sux);
}
Value Phi::operand_at(int i) const {
ValueStack* state;
if (_block->is_set(BlockBegin::exception_entry_flag)) {
state = _block->exception_state_at(i);
} else {
state = _block->pred_at(i)->end()->state();
}
assert(state != NULL, "");
if (is_local()) {
return state->local_at(local_index());
} else {
return state->stack_at(stack_index());
}
}
int Phi::operand_count() const {
if (_block->is_set(BlockBegin::exception_entry_flag)) {
return _block->number_of_exception_states();
} else {
return _block->number_of_preds();
}
}
#ifdef ASSERT
Assert::Assert(Value x, Condition cond, bool unordered_is_true, Value y) : Instruction(illegalType)
, _x(x)
, _cond(cond)
, _y(y)
{
set_flag(UnorderedIsTrueFlag, unordered_is_true);
assert(x->type()->tag() == y->type()->tag(), "types must match");
pin();
stringStream strStream;
Compilation::current()->method()->print_name(&strStream);
stringStream strStream1;
InstructionPrinter ip1(1, &strStream1);
ip1.print_instr(x);
stringStream strStream2;
InstructionPrinter ip2(1, &strStream2);
ip2.print_instr(y);
stringStream ss;
ss.print("Assertion %s %s %s in method %s", strStream1.as_string(), ip2.cond_name(cond), strStream2.as_string(), strStream.as_string());
_message = ss.as_string();
}
#endif
void RangeCheckPredicate::check_state() {
assert(state()->kind() != ValueStack::EmptyExceptionState && state()->kind() != ValueStack::ExceptionState, "will deopt with empty state");
}
void ProfileInvoke::state_values_do(ValueVisitor* f) {
if (state() != NULL) state()->values_do(f);
}
C:\hotspot-69087d08d473\src\share\vm/c1/c1_Instruction.hpp
#ifndef SHARE_VM_C1_C1_INSTRUCTION_HPP
#define SHARE_VM_C1_C1_INSTRUCTION_HPP
#include "c1/c1_Compilation.hpp"
#include "c1/c1_LIR.hpp"
#include "c1/c1_ValueType.hpp"
#include "ci/ciField.hpp"
class ciField;
class ValueStack;
class InstructionPrinter;
class IRScope;
class LIR_OprDesc;
typedef LIR_OprDesc* LIR_Opr;
class Instruction;
class Phi;
class Local;
class Constant;
class AccessField;
class LoadField;
class StoreField;
class AccessArray;
class ArrayLength;
class AccessIndexed;
class LoadIndexed;
class StoreIndexed;
class NegateOp;
class Op2;
class ArithmeticOp;
class ShiftOp;
class LogicOp;
class CompareOp;
class IfOp;
class Convert;
class NullCheck;
class TypeCast;
class OsrEntry;
class ExceptionObject;
class StateSplit;
class Invoke;
class NewInstance;
class NewArray;
class NewTypeArray;
class NewObjectArray;
class NewMultiArray;
class TypeCheck;
class CheckCast;
class InstanceOf;
class AccessMonitor;
class MonitorEnter;
class MonitorExit;
class Intrinsic;
class BlockBegin;
class BlockEnd;
class Goto;
class If;
class IfInstanceOf;
class Switch;
class TableSwitch;
class LookupSwitch;
class Return;
class Throw;
class Base;
class RoundFP;
class UnsafeOp;
class UnsafeRawOp;
class UnsafeGetRaw;
class UnsafePutRaw;
class UnsafeObjectOp;
class UnsafeGetObject;
class UnsafePutObject;
class UnsafeGetAndSetObject;
class UnsafePrefetch;
class UnsafePrefetchRead;
class UnsafePrefetchWrite;
class ProfileCall;
class ProfileReturnType;
class ProfileInvoke;
class RuntimeCall;
class MemBar;
class RangeCheckPredicate;
#ifdef ASSERT
class Assert;
#endif
typedef Instruction* Value;
define_array(ValueArray, Value)
define_stack(Values, ValueArray)
define_array(ValueStackArray, ValueStack*)
define_stack(ValueStackStack, ValueStackArray)
class BlockClosure: public CompilationResourceObj {
public:
virtual void block_do(BlockBegin* block) = 0;
};
class ValueVisitor: public StackObj {
public:
virtual void visit(Value* v) = 0;
};
define_array(BlockBeginArray, BlockBegin*)
define_stack(_BlockList, BlockBeginArray)
class BlockList: public _BlockList {
public:
BlockList(): _BlockList() {}
BlockList(const int size): _BlockList(size) {}
BlockList(const int size, BlockBegin* init): _BlockList(size, init) {}
void iterate_forward(BlockClosure* closure);
void iterate_backward(BlockClosure* closure);
void blocks_do(void f(BlockBegin*));
void values_do(ValueVisitor* f);
void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN;
};
class InstructionVisitor: public StackObj {
public:
virtual void do_Phi (Phi* x) = 0;
virtual void do_Local (Local* x) = 0;
virtual void do_Constant (Constant* x) = 0;
virtual void do_LoadField (LoadField* x) = 0;
virtual void do_StoreField (StoreField* x) = 0;
virtual void do_ArrayLength (ArrayLength* x) = 0;
virtual void do_LoadIndexed (LoadIndexed* x) = 0;
virtual void do_StoreIndexed (StoreIndexed* x) = 0;
virtual void do_NegateOp (NegateOp* x) = 0;
virtual void do_ArithmeticOp (ArithmeticOp* x) = 0;
virtual void do_ShiftOp (ShiftOp* x) = 0;
virtual void do_LogicOp (LogicOp* x) = 0;
virtual void do_CompareOp (CompareOp* x) = 0;
virtual void do_IfOp (IfOp* x) = 0;
virtual void do_Convert (Convert* x) = 0;
virtual void do_NullCheck (NullCheck* x) = 0;
virtual void do_TypeCast (TypeCast* x) = 0;
virtual void do_Invoke (Invoke* x) = 0;
virtual void do_NewInstance (NewInstance* x) = 0;
virtual void do_NewTypeArray (NewTypeArray* x) = 0;
virtual void do_NewObjectArray (NewObjectArray* x) = 0;
virtual void do_NewMultiArray (NewMultiArray* x) = 0;
virtual void do_CheckCast (CheckCast* x) = 0;
virtual void do_InstanceOf (InstanceOf* x) = 0;
virtual void do_MonitorEnter (MonitorEnter* x) = 0;
virtual void do_MonitorExit (MonitorExit* x) = 0;
virtual void do_Intrinsic (Intrinsic* x) = 0;
virtual void do_BlockBegin (BlockBegin* x) = 0;
virtual void do_Goto (Goto* x) = 0;
virtual void do_If (If* x) = 0;
virtual void do_IfInstanceOf (IfInstanceOf* x) = 0;
virtual void do_TableSwitch (TableSwitch* x) = 0;
virtual void do_LookupSwitch (LookupSwitch* x) = 0;
virtual void do_Return (Return* x) = 0;
virtual void do_Throw (Throw* x) = 0;
virtual void do_Base (Base* x) = 0;
virtual void do_OsrEntry (OsrEntry* x) = 0;
virtual void do_ExceptionObject(ExceptionObject* x) = 0;
virtual void do_RoundFP (RoundFP* x) = 0;
virtual void do_UnsafeGetRaw (UnsafeGetRaw* x) = 0;
virtual void do_UnsafePutRaw (UnsafePutRaw* x) = 0;
virtual void do_UnsafeGetObject(UnsafeGetObject* x) = 0;
virtual void do_UnsafePutObject(UnsafePutObject* x) = 0;
virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) = 0;
virtual void do_UnsafePrefetchRead (UnsafePrefetchRead* x) = 0;
virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) = 0;
virtual void do_ProfileCall (ProfileCall* x) = 0;
virtual void do_ProfileReturnType (ProfileReturnType* x) = 0;
virtual void do_ProfileInvoke (ProfileInvoke* x) = 0;
virtual void do_RuntimeCall (RuntimeCall* x) = 0;
virtual void do_MemBar (MemBar* x) = 0;
virtual void do_RangeCheckPredicate(RangeCheckPredicate* x) = 0;
#ifdef ASSERT
virtual void do_Assert (Assert* x) = 0;
#endif
};
#define HASH1(x1 ) ((intx)(x1))
#define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2))
#define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3))
#define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))
#define HASHING1(class_name, enabled, f1) \
virtual intx hash() const { \
return (enabled) ? HASH2(name(), f1) : 0; \
} \
virtual bool is_equal(Value v) const { \
if (!(enabled) ) return false; \
class_name* _v = v->as_##class_name(); \
if (_v == NULL ) return false; \
if (f1 != _v->f1) return false; \
return true; \
} \
#define HASHING2(class_name, enabled, f1, f2) \
virtual intx hash() const { \
return (enabled) ? HASH3(name(), f1, f2) : 0; \
} \
virtual bool is_equal(Value v) const { \
if (!(enabled) ) return false; \
class_name* _v = v->as_##class_name(); \
if (_v == NULL ) return false; \
if (f1 != _v->f1) return false; \
if (f2 != _v->f2) return false; \
return true; \
} \
#define HASHING3(class_name, enabled, f1, f2, f3) \
virtual intx hash() const { \
return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
} \
virtual bool is_equal(Value v) const { \
if (!(enabled) ) return false; \
class_name* _v = v->as_##class_name(); \
if (_v == NULL ) return false; \
if (f1 != _v->f1) return false; \
if (f2 != _v->f2) return false; \
if (f3 != _v->f3) return false; \
return true; \
} \
class Instruction: public CompilationResourceObj {
private:
int _id; // the unique instruction id
#ifndef PRODUCT
int _printable_bci; // the bci of the instruction for printing
#endif
int _use_count; // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1
int _pin_state; // set of PinReason describing the reason for pinning
ValueType* _type; // the instruction value type
Instruction* _next; // the next instruction if any (NULL for BlockEnd instructions)
Instruction* _subst; // the substitution instruction if any
LIR_Opr _operand; // LIR specific information
unsigned int _flags; // Flag bits
ValueStack* _state_before; // Copy of state with input operands still on stack (or NULL)
ValueStack* _exception_state; // Copy of state for exception handling
XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction
friend class UseCountComputer;
friend class BlockBegin;
void update_exception_state(ValueStack* state);
protected:
BlockBegin* _block; // Block that contains this instruction
void set_type(ValueType* type) {
assert(type != NULL, "type must exist");
_type = type;
}
class ArgsNonNullState {
private:
int _nonnull_state; // mask identifying which args are nonnull
public:
ArgsNonNullState()
: _nonnull_state(AllBits) {}
bool arg_needs_null_check(int i) const {
if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
return is_set_nth_bit(_nonnull_state, i);
}
return true;
}
void set_arg_needs_null_check(int i, bool check) {
if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) {
if (check) {
_nonnull_state |= nth_bit(i);
} else {
_nonnull_state &= ~(nth_bit(i));
}
}
}
};
public:
void* operator new(size_t size) throw() {
Compilation* c = Compilation::current();
void* res = c->arena()->Amalloc(size);
((Instruction*)res)->_id = c->get_next_id();
return res;
}
static const int no_bci = -99;
enum InstructionFlag {
NeedsNullCheckFlag = 0,
CanTrapFlag,
DirectCompareFlag,
IsEliminatedFlag,
IsSafepointFlag,
IsStaticFlag,
IsStrictfpFlag,
NeedsStoreCheckFlag,
NeedsWriteBarrierFlag,
PreservesStateFlag,
TargetIsFinalFlag,
TargetIsLoadedFlag,
TargetIsStrictfpFlag,
UnorderedIsTrueFlag,
NeedsPatchingFlag,
ThrowIncompatibleClassChangeErrorFlag,
InvokeSpecialReceiverCheckFlag,
ProfileMDOFlag,
IsLinkedInBlockFlag,
NeedsRangeCheckFlag,
InWorkListFlag,
DeoptimizeOnException,
InstructionLastFlag
};
public:
bool check_flag(InstructionFlag id) const { return (_flags & (1 << id)) != 0; }
void set_flag(InstructionFlag id, bool f) { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); };
enum Condition {
eql, neq, lss, leq, gtr, geq, aeq, beq
};
enum PinReason {
PinUnknown = 1 << 0
, PinExplicitNullCheck = 1 << 3
, PinStackForStateSplit= 1 << 12
, PinStateSplitConstructor= 1 << 13
, PinGlobalValueNumbering= 1 << 14
};
static Condition mirror(Condition cond);
static Condition negate(Condition cond);
static int number_of_instructions() {
return Compilation::current()->number_of_instructions();
}
Instruction(ValueType* type, ValueStack* state_before = NULL, bool type_is_constant = false)
: _use_count(0)
#ifndef PRODUCT
, _printable_bci(-99)
#endif
, _pin_state(0)
, _type(type)
, _next(NULL)
, _block(NULL)
, _subst(NULL)
, _flags(0)
, _operand(LIR_OprFact::illegalOpr)
, _state_before(state_before)
, _exception_handlers(NULL)
{
check_state(state_before);
assert(type != NULL && (!type->is_constant() || type_is_constant), "type must exist");
update_exception_state(_state_before);
}
int id() const { return _id; }
#ifndef PRODUCT
bool has_printable_bci() const { return _printable_bci != -99; }
int printable_bci() const { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
void set_printable_bci(int bci) { _printable_bci = bci; }
#endif
int dominator_depth();
int use_count() const { return _use_count; }
int pin_state() const { return _pin_state; }
bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; }
ValueType* type() const { return _type; }
BlockBegin *block() const { return _block; }
Instruction* prev(); // use carefully, expensive operation
Instruction* next() const { return _next; }
bool has_subst() const { return _subst != NULL; }
Instruction* subst() { return _subst == NULL ? this : _subst->subst(); }
LIR_Opr operand() const { return _operand; }
void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); }
bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); }
bool is_linked() const { return check_flag(IsLinkedInBlockFlag); }
bool can_be_linked() { return as_Local() == NULL && as_Phi() == NULL; }
bool has_uses() const { return use_count() > 0; }
ValueStack* state_before() const { return _state_before; }
ValueStack* exception_state() const { return _exception_state; }
virtual bool needs_exception_state() const { return true; }
XHandlers* exception_handlers() const { return _exception_handlers; }
void pin(PinReason reason) { _pin_state |= reason; }
void pin() { _pin_state |= PinUnknown; }
void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
Instruction* set_next(Instruction* next) {
assert(next->has_printable_bci(), "_printable_bci should have been set");
assert(next != NULL, "must not be NULL");
assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");
assert(next->can_be_linked(), "shouldn't link these instructions into list");
BlockBegin *block = this->block();
next->_block = block;
next->set_flag(Instruction::IsLinkedInBlockFlag, true);
_next = next;
return next;
}
Instruction* set_next(Instruction* next, int bci) {
#ifndef PRODUCT
next->set_printable_bci(bci);
#endif
return set_next(next);
}
void fixup_block_pointers() {
Instruction *cur = next()->next(); // next()'s block is set in set_next
while (cur && cur->_block != block()) {
cur->_block = block();
cur = cur->next();
}
}
Instruction *insert_after(Instruction *i) {
Instruction* n = _next;
set_next(i);
i->set_next(n);
return _next;
}
Instruction *insert_after_same_bci(Instruction *i) {
#ifndef PRODUCT
i->set_printable_bci(printable_bci());
#endif
return insert_after(i);
}
void set_subst(Instruction* subst) {
assert(subst == NULL ||
type()->base() == subst->type()->base() ||
subst->type()->base() == illegalType, "type can't change");
_subst = subst;
}
void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
void set_exception_state(ValueStack* s) { check_state(s); _exception_state = s; }
void set_state_before(ValueStack* s) { check_state(s); _state_before = s; }
void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
void clear_operand() { _operand = LIR_OprFact::illegalOpr; }
virtual Instruction* as_Instruction() { return this; } // to satisfy HASHING1 macro
virtual Phi* as_Phi() { return NULL; }
virtual Local* as_Local() { return NULL; }
virtual Constant* as_Constant() { return NULL; }
virtual AccessField* as_AccessField() { return NULL; }
virtual LoadField* as_LoadField() { return NULL; }
virtual StoreField* as_StoreField() { return NULL; }
virtual AccessArray* as_AccessArray() { return NULL; }
virtual ArrayLength* as_ArrayLength() { return NULL; }
virtual AccessIndexed* as_AccessIndexed() { return NULL; }
virtual LoadIndexed* as_LoadIndexed() { return NULL; }
virtual StoreIndexed* as_StoreIndexed() { return NULL; }
virtual NegateOp* as_NegateOp() { return NULL; }
virtual Op2* as_Op2() { return NULL; }
virtual ArithmeticOp* as_ArithmeticOp() { return NULL; }
virtual ShiftOp* as_ShiftOp() { return NULL; }
virtual LogicOp* as_LogicOp() { return NULL; }
virtual CompareOp* as_CompareOp() { return NULL; }
virtual IfOp* as_IfOp() { return NULL; }
virtual Convert* as_Convert() { return NULL; }
virtual NullCheck* as_NullCheck() { return NULL; }
virtual OsrEntry* as_OsrEntry() { return NULL; }
virtual StateSplit* as_StateSplit() { return NULL; }
virtual Invoke* as_Invoke() { return NULL; }
virtual NewInstance* as_NewInstance() { return NULL; }
virtual NewArray* as_NewArray() { return NULL; }
virtual NewTypeArray* as_NewTypeArray() { return NULL; }
virtual NewObjectArray* as_NewObjectArray() { return NULL; }
virtual NewMultiArray* as_NewMultiArray() { return NULL; }
virtual TypeCheck* as_TypeCheck() { return NULL; }
virtual CheckCast* as_CheckCast() { return NULL; }
virtual InstanceOf* as_InstanceOf() { return NULL; }
virtual TypeCast* as_TypeCast() { return NULL; }
virtual AccessMonitor* as_AccessMonitor() { return NULL; }
virtual MonitorEnter* as_MonitorEnter() { return NULL; }
virtual MonitorExit* as_MonitorExit() { return NULL; }
virtual Intrinsic* as_Intrinsic() { return NULL; }
virtual BlockBegin* as_BlockBegin() { return NULL; }
virtual BlockEnd* as_BlockEnd() { return NULL; }
virtual Goto* as_Goto() { return NULL; }
virtual If* as_If() { return NULL; }
virtual IfInstanceOf* as_IfInstanceOf() { return NULL; }
virtual TableSwitch* as_TableSwitch() { return NULL; }
virtual LookupSwitch* as_LookupSwitch() { return NULL; }
virtual Return* as_Return() { return NULL; }
virtual Throw* as_Throw() { return NULL; }
virtual Base* as_Base() { return NULL; }
virtual RoundFP* as_RoundFP() { return NULL; }
virtual ExceptionObject* as_ExceptionObject() { return NULL; }
virtual UnsafeOp* as_UnsafeOp() { return NULL; }
virtual ProfileInvoke* as_ProfileInvoke() { return NULL; }
virtual RangeCheckPredicate* as_RangeCheckPredicate() { return NULL; }
#ifdef ASSERT
virtual Assert* as_Assert() { return NULL; }
#endif
virtual void visit(InstructionVisitor* v) = 0;
virtual bool can_trap() const { return false; }
virtual void input_values_do(ValueVisitor* f) = 0;
virtual void state_values_do(ValueVisitor* f);
virtual void other_values_do(ValueVisitor* f) { /* usually no other - override on demand */ }
void values_do(ValueVisitor* f) { input_values_do(f); state_values_do(f); other_values_do(f); }
virtual ciType* exact_type() const;
virtual ciType* declared_type() const { return NULL; }
virtual const char* name() const = 0;
HASHING1(Instruction, false, id()) // hashing disabled by default
static void check_state(ValueStack* state) PRODUCT_RETURN;
void print() PRODUCT_RETURN;
void print_line() PRODUCT_RETURN;
void print(InstructionPrinter& ip) PRODUCT_RETURN;
};
#define BASE(class_name, super_class_name) \
class class_name: public super_class_name { \
public: \
virtual class_name* as_##class_name() { return this; } \
#define LEAF(class_name, super_class_name) \
BASE(class_name, super_class_name) \
public: \
virtual const char* name() const { return #class_name; } \
virtual void visit(InstructionVisitor* v) { v->do_##class_name(this); } \
#ifdef ASSERT
class AssertValues: public ValueVisitor {
void visit(Value* x) { assert((*x) != NULL, "value must exist"); }
};
#define ASSERT_VALUES { AssertValues assert_value; values_do(&assert_value); }
#else
#define ASSERT_VALUES
#endif // ASSERT
LEAF(Phi, Instruction)
private:
int _pf_flags; // the flags of the phi function
int _index; // to value on operand stack (index < 0) or to local
public:
Phi(ValueType* type, BlockBegin* b, int index)
: Instruction(type->base())
, _pf_flags(0)
, _index(index)
{
_block = b;
NOT_PRODUCT(set_printable_bci(Value(b)->printable_bci()));
if (type->is_illegal()) {
make_illegal();
}
}
enum Flag {
no_flag = 0,
visited = 1 << 0,
cannot_simplify = 1 << 1
};
bool is_local() const { return _index >= 0; }
bool is_on_stack() const { return !is_local(); }
int local_index() const { assert(is_local(), ""); return _index; }
int stack_index() const { assert(is_on_stack(), ""); return -(_index+1); }
Value operand_at(int i) const;
int operand_count() const;
void set(Flag f) { _pf_flags |= f; }
void clear(Flag f) { _pf_flags &= ~f; }
bool is_set(Flag f) const { return (_pf_flags & f) != 0; }
void make_illegal() {
set(cannot_simplify);
set_type(illegalType);
}
bool is_illegal() const {
return type()->is_illegal();
}
virtual void input_values_do(ValueVisitor* f) {
}
};
LEAF(Local, Instruction)
private:
int _java_index; // the local index within the method to which the local belongs
ciType* _declared_type;
public:
Local(ciType* declared, ValueType* type, int index)
: Instruction(type)
, _java_index(index)
, _declared_type(declared)
{
NOT_PRODUCT(set_printable_bci(-1));
}
int java_index() const { return _java_index; }
virtual ciType* declared_type() const { return _declared_type; }
virtual void input_values_do(ValueVisitor* f) { /* no values */ }
};
LEAF(Constant, Instruction)
public:
Constant(ValueType* type):
Instruction(type, NULL, /*type_is_constant*/ true)
{
assert(type->is_constant(), "must be a constant");
}
Constant(ValueType* type, ValueStack* state_before):
Instruction(type, state_before, /*type_is_constant*/ true)
{
assert(state_before != NULL, "only used for constants which need patching");
assert(type->is_constant(), "must be a constant");
pin();
}
virtual bool can_trap() const { return state_before() != NULL; }
virtual void input_values_do(ValueVisitor* f) { /* no values */ }
virtual intx hash() const;
virtual bool is_equal(Value v) const;
virtual ciType* exact_type() const;
enum CompareResult { not_comparable = -1, cond_false, cond_true };
virtual CompareResult compare(Instruction::Condition condition, Value right) const;
BlockBegin* compare(Instruction::Condition cond, Value right,
BlockBegin* true_sux, BlockBegin* false_sux) const {
switch (compare(cond, right)) {
case not_comparable:
return NULL;
case cond_false:
return false_sux;
case cond_true:
return true_sux;
default:
ShouldNotReachHere();
return NULL;
}
}
};
BASE(AccessField, Instruction)
private:
Value _obj;
int _offset;
ciField* _field;
NullCheck* _explicit_null_check; // For explicit null check elimination
public:
AccessField(Value obj, int offset, ciField* field, bool is_static,
ValueStack* state_before, bool needs_patching)
: Instruction(as_ValueType(field->type()->basic_type()), state_before)
, _obj(obj)
, _offset(offset)
, _field(field)
, _explicit_null_check(NULL)
{
set_needs_null_check(!is_static);
set_flag(IsStaticFlag, is_static);
set_flag(NeedsPatchingFlag, needs_patching);
ASSERT_VALUES
pin();
}
Value obj() const { return _obj; }
int offset() const { return _offset; }
ciField* field() const { return _field; }
BasicType field_type() const { return _field->type()->basic_type(); }
bool is_static() const { return check_flag(IsStaticFlag); }
NullCheck* explicit_null_check() const { return _explicit_null_check; }
bool needs_patching() const { return check_flag(NeedsPatchingFlag); }
bool is_init_point() const { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); }
void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
virtual bool can_trap() const { return needs_null_check() || needs_patching(); }
virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
};
LEAF(LoadField, AccessField)
public:
LoadField(Value obj, int offset, ciField* field, bool is_static,
ValueStack* state_before, bool needs_patching)
: AccessField(obj, offset, field, is_static, state_before, needs_patching)
{}
ciType* declared_type() const;
HASHING2(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset()) // cannot be eliminated if needs patching or if volatile
};
LEAF(StoreField, AccessField)
private:
Value _value;
public:
StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
ValueStack* state_before, bool needs_patching)
: AccessField(obj, offset, field, is_static, state_before, needs_patching)
, _value(value)
{
set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
ASSERT_VALUES
pin();
}
Value value() const { return _value; }
bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); }
};
BASE(AccessArray, Instruction)
private:
Value _array;
public:
AccessArray(ValueType* type, Value array, ValueStack* state_before)
: Instruction(type, state_before)
, _array(array)
{
set_needs_null_check(true);
ASSERT_VALUES
pin(); // instruction with side effect (null exception or range check throwing)
}
Value array() const { return _array; }
virtual bool can_trap() const { return needs_null_check(); }
virtual void input_values_do(ValueVisitor* f) { f->visit(&_array); }
};
LEAF(ArrayLength, AccessArray)
private:
NullCheck* _explicit_null_check; // For explicit null check elimination
public:
ArrayLength(Value array, ValueStack* state_before)
: AccessArray(intType, array, state_before)
, _explicit_null_check(NULL) {}
NullCheck* explicit_null_check() const { return _explicit_null_check; }
void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
HASHING1(ArrayLength, true, array()->subst())
};
BASE(AccessIndexed, AccessArray)
private:
Value _index;
Value _length;
BasicType _elt_type;
public:
AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
: AccessArray(as_ValueType(elt_type), array, state_before)
, _index(index)
, _length(length)
, _elt_type(elt_type)
{
set_flag(Instruction::NeedsRangeCheckFlag, true);
ASSERT_VALUES
}
Value index() const { return _index; }
Value length() const { return _length; }
BasicType elt_type() const { return _elt_type; }
void clear_length() { _length = NULL; }
bool compute_needs_range_check();
virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }
};
LEAF(LoadIndexed, AccessIndexed)
private:
NullCheck* _explicit_null_check; // For explicit null check elimination
public:
LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
: AccessIndexed(array, index, length, elt_type, state_before)
, _explicit_null_check(NULL) {}
NullCheck* explicit_null_check() const { return _explicit_null_check; }
void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
ciType* exact_type() const;
ciType* declared_type() const;
HASHING2(LoadIndexed, true, array()->subst(), index()->subst())
};
LEAF(StoreIndexed, AccessIndexed)
private:
Value _value;
ciMethod* _profiled_method;
int _profiled_bci;
bool _check_boolean;
public:
StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before, bool check_boolean)
: AccessIndexed(array, index, length, elt_type, state_before)
, _value(value), _profiled_method(NULL), _profiled_bci(0), _check_boolean(check_boolean)
{
set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
ASSERT_VALUES
pin();
}
Value value() const { return _value; }
bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
bool needs_store_check() const { return check_flag(NeedsStoreCheckFlag); }
bool check_boolean() const { return _check_boolean; }
void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
void set_profiled_method(ciMethod* method) { _profiled_method = method; }
void set_profiled_bci(int bci) { _profiled_bci = bci; }
bool should_profile() const { return check_flag(ProfileMDOFlag); }
ciMethod* profiled_method() const { return _profiled_method; }
int profiled_bci() const { return _profiled_bci; }
virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); }
};
LEAF(NegateOp, Instruction)
private:
Value _x;
public:
NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
ASSERT_VALUES
}
Value x() const { return _x; }
virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); }
};
BASE(Op2, Instruction)
private:
Bytecodes::Code _op;
Value _x;
Value _y;
public:
Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = NULL)
: Instruction(type, state_before)
, _op(op)
, _x(x)
, _y(y)
{
ASSERT_VALUES
}
Bytecodes::Code op() const { return _op; }
Value x() const { return _x; }
Value y() const { return _y; }
void swap_operands() {
assert(is_commutative(), "operation must be commutative");
Value t = _x; _x = _y; _y = t;
}
virtual bool is_commutative() const { return false; }
virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); }
};
LEAF(ArithmeticOp, Op2)
public:
ArithmeticOp(Bytecodes::Code op, Value x, Value y, bool is_strictfp, ValueStack* state_before)
: Op2(x->type()->meet(y->type()), op, x, y, state_before)
{
set_flag(IsStrictfpFlag, is_strictfp);
if (can_trap()) pin();
}
bool is_strictfp() const { return check_flag(IsStrictfpFlag); }
virtual bool is_commutative() const;
virtual bool can_trap() const;
HASHING3(Op2, true, op(), x()->subst(), y()->subst())
};
LEAF(ShiftOp, Op2)
public:
ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}
HASHING3(Op2, true, op(), x()->subst(), y()->subst())
};
LEAF(LogicOp, Op2)
public:
LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}
virtual bool is_commutative() const;
HASHING3(Op2, true, op(), x()->subst(), y()->subst())
};
LEAF(CompareOp, Op2)
public:
CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
: Op2(intType, op, x, y, state_before)
{}
HASHING3(Op2, true, op(), x()->subst(), y()->subst())
};
LEAF(IfOp, Op2)
private:
Value _tval;
Value _fval;
public:
IfOp(Value x, Condition cond, Value y, Value tval, Value fval)
: Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
, _tval(tval)
, _fval(fval)
{
ASSERT_VALUES
assert(tval->type()->tag() == fval->type()->tag(), "types must match");
}
virtual bool is_commutative() const;
Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }
Condition cond() const { return (Condition)Op2::op(); }
Value tval() const { return _tval; }
Value fval() const { return _fval; }
virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
};
LEAF(Convert, Instruction)
private:
Bytecodes::Code _op;
Value _value;
public:
Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
ASSERT_VALUES
}
Bytecodes::Code op() const { return _op; }
Value value() const { return _value; }
virtual void input_values_do(ValueVisitor* f) { f->visit(&_value); }
HASHING2(Convert, true, op(), value()->subst())
};
LEAF(NullCheck, Instruction)
private:
Value _obj;
public:
NullCheck(Value obj, ValueStack* state_before)
: Instruction(obj->type()->base(), state_before)
, _obj(obj)
{
ASSERT_VALUES
set_can_trap(true);
assert(_obj->type()->is_object(), "null check must be applied to objects only");
pin(Instruction::PinExplicitNullCheck);
}
Value obj() const { return _obj; }
void set_can_trap(bool can_trap) { set_flag(CanTrapFlag, can_trap); }
virtual bool can_trap() const { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }
virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
HASHING1(NullCheck, true, obj()->subst())
};
LEAF(TypeCast, Instruction)
private:
ciType* _declared_type;
Value _obj;
public:
TypeCast(ciType* type, Value obj, ValueStack* state_before)
: Instruction(obj->type(), state_before, obj->type()->is_constant()),
_declared_type(type),
_obj(obj) {}
ciType* declared_type() const { return _declared_type; }
Value obj() const { return _obj; }
virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
};
BASE(StateSplit, Instruction)
private:
ValueStack* _state;
protected:
static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);
public:
StateSplit(ValueType* type, ValueStack* state_before = NULL)
: Instruction(type, state_before)
, _state(NULL)
{
pin(PinStateSplitConstructor);
}
ValueStack* state() const { return _state; }
IRScope* scope() const; // the state's scope
void set_state(ValueStack* state) { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }
virtual void input_values_do(ValueVisitor* f) { /* no values */ }
virtual void state_values_do(ValueVisitor* f);
};
LEAF(Invoke, StateSplit)
private:
Bytecodes::Code _code;
Value _recv;
Values* _args;
BasicTypeList* _signature;
int _vtable_index;
ciMethod* _target;
public:
Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
int vtable_index, ciMethod* target, ValueStack* state_before);
Bytecodes::Code code() const { return _code; }
Value receiver() const { return _recv; }
bool has_receiver() const { return receiver() != NULL; }
int number_of_arguments() const { return _args->length(); }
Value argument_at(int i) const { return _args->at(i); }
int vtable_index() const { return _vtable_index; }
BasicTypeList* signature() const { return _signature; }
ciMethod* target() const { return _target; }
ciType* declared_type() const;
bool target_is_final() const { return check_flag(TargetIsFinalFlag); }
bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }
bool target_is_strictfp() const { return check_flag(TargetIsStrictfpFlag); }
bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }
bool is_method_handle_intrinsic() const { return target()->is_method_handle_intrinsic(); }
virtual bool needs_exception_state() const { return false; }
virtual bool can_trap() const { return true; }
virtual void input_values_do(ValueVisitor* f) {
StateSplit::input_values_do(f);
if (has_receiver()) f->visit(&_recv);
for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
}
virtual void state_values_do(ValueVisitor *f);
};
LEAF(NewInstance, StateSplit)
private:
ciInstanceKlass* _klass;
bool _is_unresolved;
public:
NewInstance(ciInstanceKlass* klass, ValueStack* state_before, bool is_unresolved)
: StateSplit(instanceType, state_before)
, _klass(klass), _is_unresolved(is_unresolved)
{}
ciInstanceKlass* klass() const { return _klass; }
bool is_unresolved() const { return _is_unresolved; }
virtual bool needs_exception_state() const { return false; }
virtual bool can_trap() const { return true; }
ciType* exact_type() const;
ciType* declared_type() const;
};
BASE(NewArray, StateSplit)
private:
Value _length;
public:
NewArray(Value length, ValueStack* state_before)
: StateSplit(objectType, state_before)
, _length(length)
{
}
Value length() const { return _length; }
virtual bool needs_exception_state() const { return false; }
ciType* exact_type() const { return NULL; }
ciType* declared_type() const;
virtual bool can_trap() const { return true; }
virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_length); }
};
LEAF(NewTypeArray, NewArray)
private:
BasicType _elt_type;
public:
NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)
: NewArray(length, state_before)
, _elt_type(elt_type)
{}
BasicType elt_type() const { return _elt_type; }
ciType* exact_type() const;
};
LEAF(NewObjectArray, NewArray)
private:
ciKlass* _klass;
public:
NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}
ciKlass* klass() const { return _klass; }
ciType* exact_type() const;
};
LEAF(NewMultiArray, NewArray)
private:
ciKlass* _klass;
Values* _dims;
public:
NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
ASSERT_VALUES
}
ciKlass* klass() const { return _klass; }
Values* dims() const { return _dims; }
int rank() const { return dims()->length(); }
virtual void input_values_do(ValueVisitor* f) {
StateSplit::input_values_do(f);
for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
}
};
BASE(TypeCheck, StateSplit)
private:
ciKlass* _klass;
Value _obj;
ciMethod* _profiled_method;
int _profiled_bci;
public:
TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
: StateSplit(type, state_before), _klass(klass), _obj(obj),
_profiled_method(NULL), _profiled_bci(0) {
ASSERT_VALUES
set_direct_compare(false);
}
ciKlass* klass() const { return _klass; }
Value obj() const { return _obj; }
bool is_loaded() const { return klass() != NULL; }
bool direct_compare() const { return check_flag(DirectCompareFlag); }
void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }
virtual bool can_trap() const { return true; }
virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
void set_profiled_method(ciMethod* method) { _profiled_method = method; }
void set_profiled_bci(int bci) { _profiled_bci = bci; }
bool should_profile() const { return check_flag(ProfileMDOFlag); }
ciMethod* profiled_method() const { return _profiled_method; }
int profiled_bci() const { return _profiled_bci; }
};
LEAF(CheckCast, TypeCheck)
public:
CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
: TypeCheck(klass, obj, objectType, state_before) {}
void set_incompatible_class_change_check() {
set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
}
bool is_incompatible_class_change_check() const {
return check_flag(ThrowIncompatibleClassChangeErrorFlag);
}
void set_invokespecial_receiver_check() {
set_flag(InvokeSpecialReceiverCheckFlag, true);
}
bool is_invokespecial_receiver_check() const {
return check_flag(InvokeSpecialReceiverCheckFlag);
}
virtual bool needs_exception_state() const {
return !is_invokespecial_receiver_check();
}
ciType* declared_type() const;
};
LEAF(InstanceOf, TypeCheck)
public:
InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}
virtual bool needs_exception_state() const { return false; }
};
BASE(AccessMonitor, StateSplit)
private:
Value _obj;
int _monitor_no;
public:
AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)
: StateSplit(illegalType, state_before)
, _obj(obj)
, _monitor_no(monitor_no)
{
set_needs_null_check(true);
ASSERT_VALUES
}
Value obj() const { return _obj; }
int monitor_no() const { return _monitor_no; }
virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
};
LEAF(MonitorEnter, AccessMonitor)
public:
MonitorEnter(Value obj, int monitor_no, ValueStack* state_before)
: AccessMonitor(obj, monitor_no, state_before)
{
ASSERT_VALUES
}
virtual bool can_trap() const { return true; }
};
LEAF(MonitorExit, AccessMonitor)
public:
MonitorExit(Value obj, int monitor_no)
: AccessMonitor(obj, monitor_no, NULL)
{
ASSERT_VALUES
}
};
LEAF(Intrinsic, StateSplit)
private:
vmIntrinsics::ID _id;
Values* _args;
Value _recv;
ArgsNonNullState _nonnull_state;
public:
Intrinsic(ValueType* type,
vmIntrinsics::ID id,
Values* args,
bool has_receiver,
ValueStack* state_before,
bool preserves_state,
bool cantrap = true)
: StateSplit(type, state_before)
, _id(id)
, _args(args)
, _recv(NULL)
{
assert(args != NULL, "args must exist");
ASSERT_VALUES
set_flag(PreservesStateFlag, preserves_state);
set_flag(CanTrapFlag, cantrap);
if (has_receiver) {
_recv = argument_at(0);
}
set_needs_null_check(has_receiver);
if (!can_trap() && !vmIntrinsics::should_be_pinned(_id)) {
unpin(PinStateSplitConstructor);
}
}
vmIntrinsics::ID id() const { return _id; }
int number_of_arguments() const { return _args->length(); }
Value argument_at(int i) const { return _args->at(i); }
bool has_receiver() const { return (_recv != NULL); }
Value receiver() const { assert(has_receiver(), "must have receiver"); return _recv; }
bool preserves_state() const { return check_flag(PreservesStateFlag); }
bool arg_needs_null_check(int i) const {
return _nonnull_state.arg_needs_null_check(i);
}
void set_arg_needs_null_check(int i, bool check) {
_nonnull_state.set_arg_needs_null_check(i, check);
}
virtual bool can_trap() const { return check_flag(CanTrapFlag); }
virtual void input_values_do(ValueVisitor* f) {
StateSplit::input_values_do(f);
for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
}
};
class LIR_List;
LEAF(BlockBegin, StateSplit)
private:
int _block_id; // the unique block id
int _bci; // start-bci of block
int _depth_first_number; // number of this block in a depth-first ordering
int _linear_scan_number; // number of this block in linear-scan ordering
int _dominator_depth;
int _loop_depth; // the loop nesting level of this block
int _loop_index; // number of the innermost loop of this block
int _flags; // the flags associated with this block
int _total_preds; // number of predecessors found by BlockListBuilder
BitMap _stores_to_locals; // bit is set when a local variable is stored in the block
BlockList _successors; // the successors of this block
BlockList _predecessors; // the predecessors of this block
BlockList _dominates; // list of blocks that are dominated by this block
BlockBegin* _dominator; // the dominator of this block
BlockEnd* _end; // the last instruction of this block
BlockList _exception_handlers; // the exception handlers potentially invoked by this block
ValueStackStack* _exception_states; // only for xhandler entries: states of all instructions that have an edge to this xhandler
int _exception_handler_pco; // if this block is the start of an exception handler,
Label _label; // the label associated with this block
LIR_List* _lir; // the low level intermediate representation for this block
BitMap _live_in; // set of live LIR_Opr registers at entry to this block
BitMap _live_out; // set of live LIR_Opr registers at exit from this block
BitMap _live_gen; // set of registers used before any redefinition in this block
BitMap _live_kill; // set of registers defined in this block
BitMap _fpu_register_usage;
intArray* _fpu_stack_state; // For x86 FPU code generation with UseLinearScan
int _first_lir_instruction_id; // ID of first LIR instruction in this block
int _last_lir_instruction_id; // ID of last LIR instruction in this block
void iterate_preorder (boolArray& mark, BlockClosure* closure);
void iterate_postorder(boolArray& mark, BlockClosure* closure);
friend class SuxAndWeightAdjuster;
public:
void* operator new(size_t size) throw() {
Compilation* c = Compilation::current();
void* res = c->arena()->Amalloc(size);
((BlockBegin*)res)->_id = c->get_next_id();
((BlockBegin*)res)->_block_id = c->get_next_block_id();
return res;
}
static int number_of_blocks() {
return Compilation::current()->number_of_blocks();
}
BlockBegin(int bci)
: StateSplit(illegalType)
, _bci(bci)
, _depth_first_number(-1)
, _linear_scan_number(-1)
, _loop_depth(0)
, _flags(0)
, _dominator_depth(-1)
, _dominator(NULL)
, _end(NULL)
, _predecessors(2)
, _successors(2)
, _dominates(2)
, _exception_handlers(1)
, _exception_states(NULL)
, _exception_handler_pco(-1)
, _lir(NULL)
, _loop_index(-1)
, _live_in()
, _live_out()
, _live_gen()
, _live_kill()
, _fpu_register_usage()
, _fpu_stack_state(NULL)
, _first_lir_instruction_id(-1)
, _last_lir_instruction_id(-1)
, _total_preds(0)
, _stores_to_locals()
{
_block = this;
#ifndef PRODUCT
set_printable_bci(bci);
#endif
}
int block_id() const { return _block_id; }
int bci() const { return _bci; }
BlockList* successors() { return &_successors; }
BlockList* dominates() { return &_dominates; }
BlockBegin* dominator() const { return _dominator; }
int loop_depth() const { return _loop_depth; }
int dominator_depth() const { return _dominator_depth; }
int depth_first_number() const { return _depth_first_number; }
int linear_scan_number() const { return _linear_scan_number; }
BlockEnd* end() const { return _end; }
Label* label() { return &_label; }
LIR_List* lir() const { return _lir; }
int exception_handler_pco() const { return _exception_handler_pco; }
BitMap& live_in() { return _live_in; }
BitMap& live_out() { return _live_out; }
BitMap& live_gen() { return _live_gen; }
BitMap& live_kill() { return _live_kill; }
BitMap& fpu_register_usage() { return _fpu_register_usage; }
intArray* fpu_stack_state() const { return _fpu_stack_state; }
int first_lir_instruction_id() const { return _first_lir_instruction_id; }
int last_lir_instruction_id() const { return _last_lir_instruction_id; }
int total_preds() const { return _total_preds; }
BitMap& stores_to_locals() { return _stores_to_locals; }
void set_dominator(BlockBegin* dom) { _dominator = dom; }
void set_loop_depth(int d) { _loop_depth = d; }
void set_dominator_depth(int d) { _dominator_depth = d; }
void set_depth_first_number(int dfn) { _depth_first_number = dfn; }
void set_linear_scan_number(int lsn) { _linear_scan_number = lsn; }
void set_end(BlockEnd* end);
void clear_end();
void disconnect_from_graph();
static void disconnect_edge(BlockBegin* from, BlockBegin* to);
BlockBegin* insert_block_between(BlockBegin* sux);
void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
void set_lir(LIR_List* lir) { _lir = lir; }
void set_exception_handler_pco(int pco) { _exception_handler_pco = pco; }
void set_live_in (BitMap map) { _live_in = map; }
void set_live_out (BitMap map) { _live_out = map; }
void set_live_gen (BitMap map) { _live_gen = map; }
void set_live_kill (BitMap map) { _live_kill = map; }
void set_fpu_register_usage(BitMap map) { _fpu_register_usage = map; }
void set_fpu_stack_state(intArray* state) { _fpu_stack_state = state; }
void set_first_lir_instruction_id(int id) { _first_lir_instruction_id = id; }
void set_last_lir_instruction_id(int id) { _last_lir_instruction_id = id; }
void increment_total_preds(int n = 1) { _total_preds += n; }
void init_stores_to_locals(int locals_count) { _stores_to_locals = BitMap(locals_count); _stores_to_locals.clear(); }
virtual void state_values_do(ValueVisitor* f);
int number_of_sux() const;
BlockBegin* sux_at(int i) const;
void add_successor(BlockBegin* sux);
void remove_successor(BlockBegin* pred);
bool is_successor(BlockBegin* sux) const { return _successors.contains(sux); }
void add_predecessor(BlockBegin* pred);
void remove_predecessor(BlockBegin* pred);
bool is_predecessor(BlockBegin* pred) const { return _predecessors.contains(pred); }
int number_of_preds() const { return _predecessors.length(); }
BlockBegin* pred_at(int i) const { return _predecessors[i]; }
void add_exception_handler(BlockBegin* b);
bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }
int number_of_exception_handlers() const { return _exception_handlers.length(); }
BlockBegin* exception_handler_at(int i) const { return _exception_handlers.at(i); }
int number_of_exception_states() { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); }
ValueStack* exception_state_at(int idx) const { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }
int add_exception_state(ValueStack* state);
enum Flag {
no_flag = 0,
std_entry_flag = 1 << 0,
osr_entry_flag = 1 << 1,
exception_entry_flag = 1 << 2,
subroutine_entry_flag = 1 << 3,
backward_branch_target_flag = 1 << 4,
is_on_work_list_flag = 1 << 5,
was_visited_flag = 1 << 6,
parser_loop_header_flag = 1 << 7, // set by parser to identify blocks where phi functions can not be created on demand
critical_edge_split_flag = 1 << 8, // set for all blocks that are introduced when critical edges are split
linear_scan_loop_header_flag = 1 << 9, // set during loop-detection for LinearScan
linear_scan_loop_end_flag = 1 << 10, // set during loop-detection for LinearScan
donot_eliminate_range_checks = 1 << 11 // Should be try to eliminate range checks in this block
};
void set(Flag f) { _flags |= f; }
void clear(Flag f) { _flags &= ~f; }
bool is_set(Flag f) const { return (_flags & f) != 0; }
bool is_entry_block() const {
const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;
return (_flags & entry_mask) != 0;
}
void iterate_preorder (BlockClosure* closure);
void iterate_postorder (BlockClosure* closure);
void block_values_do(ValueVisitor* f);
void set_loop_index(int ix) { _loop_index = ix; }
int loop_index() const { return _loop_index; }
bool try_merge(ValueStack* state); // try to merge states at block begin
void merge(ValueStack* state) { bool b = try_merge(state); assert(b, "merge failed"); }
void print_block() PRODUCT_RETURN;
void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;
};
BASE(BlockEnd, StateSplit)
private:
BlockList* _sux;
protected:
BlockList* sux() const { return _sux; }
void set_sux(BlockList* sux) {
#ifdef ASSERT
assert(sux != NULL, "sux must exist");
for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist");
#endif
_sux = sux;
}
public:
BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)
: StateSplit(type, state_before)
, _sux(NULL)
{
set_flag(IsSafepointFlag, is_safepoint);
}
bool is_safepoint() const { return check_flag(IsSafepointFlag); }
BlockBegin* begin() const { return _block; }
void set_begin(BlockBegin* begin);
int number_of_sux() const { return _sux != NULL ? _sux->length() : 0; }
BlockBegin* sux_at(int i) const { return _sux->at(i); }
BlockBegin* default_sux() const { return sux_at(number_of_sux() - 1); }
BlockBegin** addr_sux_at(int i) const { return _sux->adr_at(i); }
int sux_index(BlockBegin* sux) const { return _sux->find(sux); }
void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
};
LEAF(Goto, BlockEnd)
public:
enum Direction {
none, // Just a regular goto
taken, not_taken // Goto produced from If
};
private:
ciMethod* _profiled_method;
int _profiled_bci;
Direction _direction;
public:
Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false)
: BlockEnd(illegalType, state_before, is_safepoint)
, _direction(none)
, _profiled_method(NULL)
, _profiled_bci(0) {
BlockList* s = new BlockList(1);
s->append(sux);
set_sux(s);
}
Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint)
, _direction(none)
, _profiled_method(NULL)
, _profiled_bci(0) {
BlockList* s = new BlockList(1);
s->append(sux);
set_sux(s);
}
bool should_profile() const { return check_flag(ProfileMDOFlag); }
ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
int profiled_bci() const { return _profiled_bci; }
Direction direction() const { return _direction; }
void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
void set_profiled_method(ciMethod* method) { _profiled_method = method; }
void set_profiled_bci(int bci) { _profiled_bci = bci; }
void set_direction(Direction d) { _direction = d; }
};
#ifdef ASSERT
LEAF(Assert, Instruction)
private:
Value _x;
Condition _cond;
Value _y;
char *_message;
public:
Assert(Value x, Condition cond, bool unordered_is_true, Value y);
Value x() const { return _x; }
Condition cond() const { return _cond; }
bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
Value y() const { return _y; }
const char *message() const { return _message; }
virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); }
};
#endif
LEAF(RangeCheckPredicate, StateSplit)
private:
Value _x;
Condition _cond;
Value _y;
void check_state();
public:
RangeCheckPredicate(Value x, Condition cond, bool unordered_is_true, Value y, ValueStack* state) : StateSplit(illegalType)
, _x(x)
, _cond(cond)
, _y(y)
{
ASSERT_VALUES
set_flag(UnorderedIsTrueFlag, unordered_is_true);
assert(x->type()->tag() == y->type()->tag(), "types must match");
this->set_state(state);
check_state();
}
RangeCheckPredicate(ValueStack* state) : StateSplit(illegalType)
{
this->set_state(state);
_x = _y = NULL;
check_state();
}
Value x() const { return _x; }
Condition cond() const { return _cond; }
bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
Value y() const { return _y; }
void always_fail() { _x = _y = NULL; }
virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_x); f->visit(&_y); }
HASHING3(RangeCheckPredicate, true, x()->subst(), y()->subst(), cond())
};
LEAF(If, BlockEnd)
private:
Value _x;
Condition _cond;
Value _y;
ciMethod* _profiled_method;
int _profiled_bci; // Canonicalizer may alter bci of If node
bool _swapped; // Is the order reversed with respect to the original If in the
public:
If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)
: BlockEnd(illegalType, state_before, is_safepoint)
, _x(x)
, _cond(cond)
, _y(y)
, _profiled_method(NULL)
, _profiled_bci(0)
, _swapped(false)
{
ASSERT_VALUES
set_flag(UnorderedIsTrueFlag, unordered_is_true);
assert(x->type()->tag() == y->type()->tag(), "types must match");
BlockList* s = new BlockList(2);
s->append(tsux);
s->append(fsux);
set_sux(s);
}
Value x() const { return _x; }
Condition cond() const { return _cond; }
bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
Value y() const { return _y; }
BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
BlockBegin* tsux() const { return sux_for(true); }
BlockBegin* fsux() const { return sux_for(false); }
BlockBegin* usux() const { return sux_for(unordered_is_true()); }
bool should_profile() const { return check_flag(ProfileMDOFlag); }
ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered
bool is_swapped() const { return _swapped; }
void swap_operands() {
Value t = _x; _x = _y; _y = t;
_cond = mirror(_cond);
}
void swap_sux() {
assert(number_of_sux() == 2, "wrong number of successors");
BlockList* s = sux();
BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
_cond = negate(_cond);
set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));
}
void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
void set_profiled_method(ciMethod* method) { _profiled_method = method; }
void set_profiled_bci(int bci) { _profiled_bci = bci; }
void set_swapped(bool value) { _swapped = value; }
virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
};
LEAF(IfInstanceOf, BlockEnd)
private:
ciKlass* _klass;
Value _obj;
bool _test_is_instance; // jump if instance
int _instanceof_bci;
public:
IfInstanceOf(ciKlass* klass, Value obj, bool test_is_instance, int instanceof_bci, BlockBegin* tsux, BlockBegin* fsux)
: BlockEnd(illegalType, NULL, false) // temporary set to false
, _klass(klass)
, _obj(obj)
, _test_is_instance(test_is_instance)
, _instanceof_bci(instanceof_bci)
{
ASSERT_VALUES
assert(instanceof_bci >= 0, "illegal bci");
BlockList* s = new BlockList(2);
s->append(tsux);
s->append(fsux);
set_sux(s);
}
ciKlass* klass() const { return _klass; }
Value obj() const { return _obj; }
int instanceof_bci() const { return _instanceof_bci; }
bool test_is_instance() const { return _test_is_instance; }
BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
BlockBegin* tsux() const { return sux_for(true); }
BlockBegin* fsux() const { return sux_for(false); }
void swap_sux() {
assert(number_of_sux() == 2, "wrong number of successors");
BlockList* s = sux();
BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
_test_is_instance = !_test_is_instance;
}
virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_obj); }
};
BASE(Switch, BlockEnd)
private:
Value _tag;
public:
Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
: BlockEnd(illegalType, state_before, is_safepoint)
, _tag(tag) {
ASSERT_VALUES
set_sux(sux);
}
Value tag() const { return _tag; }
int length() const { return number_of_sux() - 1; }
virtual bool needs_exception_state() const { return false; }
virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_tag); }
};
LEAF(TableSwitch, Switch)
private:
int _lo_key;
public:
TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)
: Switch(tag, sux, state_before, is_safepoint)
, _lo_key(lo_key) { assert(_lo_key <= hi_key(), "integer overflow"); }
int lo_key() const { return _lo_key; }
int hi_key() const { return _lo_key + (length() - 1); }
};
LEAF(LookupSwitch, Switch)
private:
intArray* _keys;
public:
LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)
: Switch(tag, sux, state_before, is_safepoint)
, _keys(keys) {
assert(keys != NULL, "keys must exist");
assert(keys->length() == length(), "sux & keys have incompatible lengths");
}
int key_at(int i) const { return _keys->at(i); }
};
LEAF(Return, BlockEnd)
private:
Value _result;
public:
Return(Value result) :
BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true),
_result(result) {}
Value result() const { return _result; }
bool has_result() const { return result() != NULL; }
virtual void input_values_do(ValueVisitor* f) {
BlockEnd::input_values_do(f);
if (has_result()) f->visit(&_result);
}
};
LEAF(Throw, BlockEnd)
private:
Value _exception;
public:
Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {
ASSERT_VALUES
}
Value exception() const { return _exception; }
virtual bool can_trap() const { return true; }
virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_exception); }
};
LEAF(Base, BlockEnd)
sssssssss4
最新推荐文章于 2024-08-02 17:52:30 发布