提交 77f85fe6 编写于 作者: R roland

6986046: C1 valuestack cleanup

Summary: fixes an historical oddity in C1 with inlining where all of the expression stacks are kept in the topmost ValueStack instead of being in their respective ValueStacks.
Reviewed-by: never
Contributed-by: NChristian Wimmer <cwimmer@uci.edu>
上级 9491724a
...@@ -32,6 +32,7 @@ RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, ...@@ -32,6 +32,7 @@ RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index,
: _throw_index_out_of_bounds_exception(throw_index_out_of_bounds_exception) : _throw_index_out_of_bounds_exception(throw_index_out_of_bounds_exception)
, _index(index) , _index(index)
{ {
assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info); _info = new CodeEmitInfo(info);
} }
......
...@@ -311,7 +311,7 @@ void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) ...@@ -311,7 +311,7 @@ void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp)
void LIRGenerator::do_StoreIndexed(StoreIndexed* x) { void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {
assert(x->is_root(),""); assert(x->is_pinned(),"");
bool needs_range_check = true; bool needs_range_check = true;
bool use_length = x->length() != NULL; bool use_length = x->length() != NULL;
bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT; bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;
...@@ -386,7 +386,7 @@ void LIRGenerator::do_StoreIndexed(StoreIndexed* x) { ...@@ -386,7 +386,7 @@ void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {
void LIRGenerator::do_MonitorEnter(MonitorEnter* x) { void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
assert(x->is_root(),""); assert(x->is_pinned(),"");
LIRItem obj(x->obj(), this); LIRItem obj(x->obj(), this);
obj.load_item(); obj.load_item();
...@@ -398,7 +398,7 @@ void LIRGenerator::do_MonitorEnter(MonitorEnter* x) { ...@@ -398,7 +398,7 @@ void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
CodeEmitInfo* info_for_exception = NULL; CodeEmitInfo* info_for_exception = NULL;
if (x->needs_null_check()) { if (x->needs_null_check()) {
info_for_exception = state_for(x, x->lock_stack_before()); info_for_exception = state_for(x);
} }
// this CodeEmitInfo must not have the xhandlers because here the // this CodeEmitInfo must not have the xhandlers because here the
...@@ -409,7 +409,7 @@ void LIRGenerator::do_MonitorEnter(MonitorEnter* x) { ...@@ -409,7 +409,7 @@ void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
void LIRGenerator::do_MonitorExit(MonitorExit* x) { void LIRGenerator::do_MonitorExit(MonitorExit* x) {
assert(x->is_root(),""); assert(x->is_pinned(),"");
LIRItem obj(x->obj(), this); LIRItem obj(x->obj(), this);
obj.dont_load_item(); obj.dont_load_item();
...@@ -871,10 +871,11 @@ void LIRGenerator::do_NewInstance(NewInstance* x) { ...@@ -871,10 +871,11 @@ void LIRGenerator::do_NewInstance(NewInstance* x) {
// This instruction can be deoptimized in the slow path : use // This instruction can be deoptimized in the slow path : use
// O0 as result register. // O0 as result register.
const LIR_Opr reg = result_register_for(x->type()); const LIR_Opr reg = result_register_for(x->type());
#ifndef PRODUCT
if (PrintNotLoaded && !x->klass()->is_loaded()) { if (PrintNotLoaded && !x->klass()->is_loaded()) {
tty->print_cr(" ###class not loaded at new bci %d", x->bci()); tty->print_cr(" ###class not loaded at new bci %d", x->printable_bci());
} }
#endif
CodeEmitInfo* info = state_for(x, x->state()); CodeEmitInfo* info = state_for(x, x->state());
LIR_Opr tmp1 = FrameMap::G1_oop_opr; LIR_Opr tmp1 = FrameMap::G1_oop_opr;
LIR_Opr tmp2 = FrameMap::G3_oop_opr; LIR_Opr tmp2 = FrameMap::G3_oop_opr;
...@@ -1018,7 +1019,7 @@ void LIRGenerator::do_CheckCast(CheckCast* x) { ...@@ -1018,7 +1019,7 @@ void LIRGenerator::do_CheckCast(CheckCast* x) {
obj.load_item(); obj.load_item();
LIR_Opr out_reg = rlock_result(x); LIR_Opr out_reg = rlock_result(x);
CodeStub* stub; CodeStub* stub;
CodeEmitInfo* info_for_exception = state_for(x, x->state()->copy_locks()); CodeEmitInfo* info_for_exception = state_for(x);
if (x->is_incompatible_class_change_check()) { if (x->is_incompatible_class_change_check()) {
assert(patching_info == NULL, "can't patch this"); assert(patching_info == NULL, "can't patch this");
......
...@@ -83,7 +83,8 @@ RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, ...@@ -83,7 +83,8 @@ RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index,
: _throw_index_out_of_bounds_exception(throw_index_out_of_bounds_exception) : _throw_index_out_of_bounds_exception(throw_index_out_of_bounds_exception)
, _index(index) , _index(index)
{ {
_info = info == NULL ? NULL : new CodeEmitInfo(info); assert(info != NULL, "must have info");
_info = new CodeEmitInfo(info);
} }
......
...@@ -107,7 +107,7 @@ bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const { ...@@ -107,7 +107,7 @@ bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {
return false; return false;
} }
Constant* c = v->as_Constant(); Constant* c = v->as_Constant();
if (c && c->state() == NULL) { if (c && c->state_before() == NULL) {
// constants of any type can be stored directly, except for // constants of any type can be stored directly, except for
// unloaded object constants. // unloaded object constants.
return true; return true;
...@@ -250,7 +250,7 @@ void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) ...@@ -250,7 +250,7 @@ void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp)
void LIRGenerator::do_StoreIndexed(StoreIndexed* x) { void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {
assert(x->is_root(),""); assert(x->is_pinned(),"");
bool needs_range_check = true; bool needs_range_check = true;
bool use_length = x->length() != NULL; bool use_length = x->length() != NULL;
bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT; bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;
...@@ -325,7 +325,7 @@ void LIRGenerator::do_StoreIndexed(StoreIndexed* x) { ...@@ -325,7 +325,7 @@ void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {
void LIRGenerator::do_MonitorEnter(MonitorEnter* x) { void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
assert(x->is_root(),""); assert(x->is_pinned(),"");
LIRItem obj(x->obj(), this); LIRItem obj(x->obj(), this);
obj.load_item(); obj.load_item();
...@@ -341,7 +341,7 @@ void LIRGenerator::do_MonitorEnter(MonitorEnter* x) { ...@@ -341,7 +341,7 @@ void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
CodeEmitInfo* info_for_exception = NULL; CodeEmitInfo* info_for_exception = NULL;
if (x->needs_null_check()) { if (x->needs_null_check()) {
info_for_exception = state_for(x, x->lock_stack_before()); info_for_exception = state_for(x);
} }
// this CodeEmitInfo must not have the xhandlers because here the // this CodeEmitInfo must not have the xhandlers because here the
// object is already locked (xhandlers expect object to be unlocked) // object is already locked (xhandlers expect object to be unlocked)
...@@ -352,7 +352,7 @@ void LIRGenerator::do_MonitorEnter(MonitorEnter* x) { ...@@ -352,7 +352,7 @@ void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
void LIRGenerator::do_MonitorExit(MonitorExit* x) { void LIRGenerator::do_MonitorExit(MonitorExit* x) {
assert(x->is_root(),""); assert(x->is_pinned(),"");
LIRItem obj(x->obj(), this); LIRItem obj(x->obj(), this);
obj.dont_load_item(); obj.dont_load_item();
...@@ -984,9 +984,11 @@ void LIRGenerator::do_Convert(Convert* x) { ...@@ -984,9 +984,11 @@ void LIRGenerator::do_Convert(Convert* x) {
void LIRGenerator::do_NewInstance(NewInstance* x) { void LIRGenerator::do_NewInstance(NewInstance* x) {
#ifndef PRODUCT
if (PrintNotLoaded && !x->klass()->is_loaded()) { if (PrintNotLoaded && !x->klass()->is_loaded()) {
tty->print_cr(" ###class not loaded at new bci %d", x->bci()); tty->print_cr(" ###class not loaded at new bci %d", x->printable_bci());
} }
#endif
CodeEmitInfo* info = state_for(x, x->state()); CodeEmitInfo* info = state_for(x, x->state());
LIR_Opr reg = result_register_for(x->type()); LIR_Opr reg = result_register_for(x->type());
LIR_Opr klass_reg = new_register(objectType); LIR_Opr klass_reg = new_register(objectType);
...@@ -1127,7 +1129,7 @@ void LIRGenerator::do_CheckCast(CheckCast* x) { ...@@ -1127,7 +1129,7 @@ void LIRGenerator::do_CheckCast(CheckCast* x) {
obj.load_item(); obj.load_item();
// info for exceptions // info for exceptions
CodeEmitInfo* info_for_exception = state_for(x, x->state()->copy_locks()); CodeEmitInfo* info_for_exception = state_for(x);
CodeStub* stub; CodeStub* stub;
if (x->is_incompatible_class_change_check()) { if (x->is_incompatible_class_change_check()) {
......
...@@ -174,9 +174,22 @@ void CFGPrinterOutput::print_state(BlockBegin* block) { ...@@ -174,9 +174,22 @@ void CFGPrinterOutput::print_state(BlockBegin* block) {
int index; int index;
Value value; Value value;
for_each_state(state) {
print_begin("locals");
print("size %d", state->locals_size());
print("method \"%s\"", method_name(state->scope()->method()));
for_each_local_value(state, index, value) {
ip.print_phi(index, value, block);
print_operand(value);
output()->cr();
}
print_end("locals");
if (state->stack_size() > 0) { if (state->stack_size() > 0) {
print_begin("stack"); print_begin("stack");
print("size %d", state->stack_size()); print("size %d", state->stack_size());
print("method \"%s\"", method_name(state->scope()->method()));
for_each_stack_value(state, index, value) { for_each_stack_value(state, index, value) {
ip.print_phi(index, value, block); ip.print_phi(index, value, block);
...@@ -190,6 +203,7 @@ void CFGPrinterOutput::print_state(BlockBegin* block) { ...@@ -190,6 +203,7 @@ void CFGPrinterOutput::print_state(BlockBegin* block) {
if (state->locks_size() > 0) { if (state->locks_size() > 0) {
print_begin("locks"); print_begin("locks");
print("size %d", state->locks_size()); print("size %d", state->locks_size());
print("method \"%s\"", method_name(state->scope()->method()));
for_each_lock_value(state, index, value) { for_each_lock_value(state, index, value) {
ip.print_phi(index, value, block); ip.print_phi(index, value, block);
...@@ -198,18 +212,6 @@ void CFGPrinterOutput::print_state(BlockBegin* block) { ...@@ -198,18 +212,6 @@ void CFGPrinterOutput::print_state(BlockBegin* block) {
} }
print_end("locks"); print_end("locks");
} }
for_each_state(state) {
print_begin("locals");
print("size %d", state->locals_size());
print("method \"%s\"", method_name(state->scope()->method()));
for_each_local_value(state, index, value) {
ip.print_phi(index, value, block);
print_operand(value);
output()->cr();
}
print_end("locals");
} }
print_end("states"); print_end("states");
...@@ -230,7 +232,8 @@ void CFGPrinterOutput::print_HIR(Value instr) { ...@@ -230,7 +232,8 @@ void CFGPrinterOutput::print_HIR(Value instr) {
if (instr->is_pinned()) { if (instr->is_pinned()) {
output()->put('.'); output()->put('.');
} }
output()->print("%d %d ", instr->bci(), instr->use_count());
output()->print("%d %d ", instr->printable_bci(), instr->use_count());
print_operand(instr); print_operand(instr);
...@@ -271,7 +274,7 @@ void CFGPrinterOutput::print_block(BlockBegin* block) { ...@@ -271,7 +274,7 @@ void CFGPrinterOutput::print_block(BlockBegin* block) {
print("name \"B%d\"", block->block_id()); print("name \"B%d\"", block->block_id());
print("from_bci %d", block->bci()); print("from_bci %d", block->bci());
print("to_bci %d", (block->end() == NULL ? -1 : block->end()->bci())); print("to_bci %d", (block->end() == NULL ? -1 : block->end()->printable_bci()));
output()->indent(); output()->indent();
output()->print("predecessors "); output()->print("predecessors ");
......
...@@ -205,7 +205,7 @@ void Canonicalizer::do_StoreField (StoreField* x) { ...@@ -205,7 +205,7 @@ void Canonicalizer::do_StoreField (StoreField* x) {
// limit this optimization to current block // limit this optimization to current block
if (value != NULL && in_current_block(conv)) { if (value != NULL && in_current_block(conv)) {
set_canonical(new StoreField(x->obj(), x->offset(), x->field(), value, x->is_static(), set_canonical(new StoreField(x->obj(), x->offset(), x->field(), value, x->is_static(),
x->lock_stack(), x->state_before(), x->is_loaded(), x->is_initialized())); x->state_before(), x->is_loaded(), x->is_initialized()));
return; return;
} }
} }
...@@ -256,7 +256,7 @@ void Canonicalizer::do_StoreIndexed (StoreIndexed* x) { ...@@ -256,7 +256,7 @@ void Canonicalizer::do_StoreIndexed (StoreIndexed* x) {
// limit this optimization to current block // limit this optimization to current block
if (value != NULL && in_current_block(conv)) { if (value != NULL && in_current_block(conv)) {
set_canonical(new StoreIndexed(x->array(), x->index(), x->length(), set_canonical(new StoreIndexed(x->array(), x->index(), x->length(),
x->elt_type(), value, x->lock_stack())); x->elt_type(), value, x->state_before()));
return; return;
} }
} }
...@@ -667,7 +667,7 @@ void Canonicalizer::do_If(If* x) { ...@@ -667,7 +667,7 @@ void Canonicalizer::do_If(If* x) {
} }
} }
set_canonical(canon); set_canonical(canon);
set_bci(cmp->bci()); set_bci(cmp->state_before()->bci());
} }
} }
} else if (l->as_InstanceOf() != NULL) { } else if (l->as_InstanceOf() != NULL) {
...@@ -685,7 +685,7 @@ void Canonicalizer::do_If(If* x) { ...@@ -685,7 +685,7 @@ void Canonicalizer::do_If(If* x) {
set_canonical(new Goto(is_inst_sux, x->state_before(), x->is_safepoint())); set_canonical(new Goto(is_inst_sux, x->state_before(), x->is_safepoint()));
} else { } else {
// successors differ => simplify to: IfInstanceOf // successors differ => simplify to: IfInstanceOf
set_canonical(new IfInstanceOf(inst->klass(), inst->obj(), true, inst->bci(), is_inst_sux, no_inst_sux)); set_canonical(new IfInstanceOf(inst->klass(), inst->obj(), true, inst->state_before()->bci(), is_inst_sux, no_inst_sux));
} }
} }
} else if (rt == objectNull && (l->as_NewInstance() || l->as_NewArray())) { } else if (rt == objectNull && (l->as_NewInstance() || l->as_NewArray())) {
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
* *
*/ */
class BlockBegin;
class CompilationResourceObj; class CompilationResourceObj;
class XHandlers; class XHandlers;
class ExceptionInfo; class ExceptionInfo;
......
此差异已折叠。
...@@ -58,9 +58,6 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC { ...@@ -58,9 +58,6 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC {
// BlockEnds. // BlockEnds.
BlockBegin* _continuation; BlockBegin* _continuation;
// Without return value of inlined method on stack
ValueStack* _continuation_state;
// Was this ScopeData created only for the parsing and inlining of // Was this ScopeData created only for the parsing and inlining of
// a jsr? // a jsr?
bool _parsing_jsr; bool _parsing_jsr;
...@@ -125,14 +122,10 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC { ...@@ -125,14 +122,10 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC {
void set_stream(ciBytecodeStream* stream) { _stream = stream; } void set_stream(ciBytecodeStream* stream) { _stream = stream; }
intx max_inline_size() const { return _max_inline_size; } intx max_inline_size() const { return _max_inline_size; }
int caller_stack_size() const;
BlockBegin* continuation() const { return _continuation; } BlockBegin* continuation() const { return _continuation; }
void set_continuation(BlockBegin* cont) { _continuation = cont; } void set_continuation(BlockBegin* cont) { _continuation = cont; }
ValueStack* continuation_state() const { return _continuation_state; }
void set_continuation_state(ValueStack* s) { _continuation_state = s; }
// Indicates whether this ScopeData was pushed only for the // Indicates whether this ScopeData was pushed only for the
// parsing and inlining of a jsr // parsing and inlining of a jsr
bool parsing_jsr() const { return _parsing_jsr; } bool parsing_jsr() const { return _parsing_jsr; }
...@@ -163,7 +156,6 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC { ...@@ -163,7 +156,6 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC {
// for all GraphBuilders // for all GraphBuilders
static bool _can_trap[Bytecodes::number_of_java_codes]; static bool _can_trap[Bytecodes::number_of_java_codes];
static bool _is_async[Bytecodes::number_of_java_codes];
// for each instance of GraphBuilder // for each instance of GraphBuilder
ScopeData* _scope_data; // Per-scope data; used for inlining ScopeData* _scope_data; // Per-scope data; used for inlining
...@@ -179,7 +171,6 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC { ...@@ -179,7 +171,6 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC {
// for each call to connect_to_end; can also be set by inliner // for each call to connect_to_end; can also be set by inliner
BlockBegin* _block; // the current block BlockBegin* _block; // the current block
ValueStack* _state; // the current execution state ValueStack* _state; // the current execution state
ValueStack* _exception_state; // state that will be used by handle_exception
Instruction* _last; // the last instruction added Instruction* _last; // the last instruction added
bool _skip_block; // skip processing of the rest of this block bool _skip_block; // skip processing of the rest of this block
...@@ -194,8 +185,6 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC { ...@@ -194,8 +185,6 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC {
ValueStack* state() const { return _state; } ValueStack* state() const { return _state; }
void set_state(ValueStack* state) { _state = state; } void set_state(ValueStack* state) { _state = state; }
IRScope* scope() const { return scope_data()->scope(); } IRScope* scope() const { return scope_data()->scope(); }
ValueStack* exception_state() const { return _exception_state; }
void set_exception_state(ValueStack* s) { _exception_state = s; }
ciMethod* method() const { return scope()->method(); } ciMethod* method() const { return scope()->method(); }
ciBytecodeStream* stream() const { return scope_data()->stream(); } ciBytecodeStream* stream() const { return scope_data()->stream(); }
Instruction* last() const { return _last; } Instruction* last() const { return _last; }
...@@ -230,7 +219,7 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC { ...@@ -230,7 +219,7 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC {
void load_indexed (BasicType type); void load_indexed (BasicType type);
void store_indexed(BasicType type); void store_indexed(BasicType type);
void stack_op(Bytecodes::Code code); void stack_op(Bytecodes::Code code);
void arithmetic_op(ValueType* type, Bytecodes::Code code, ValueStack* lock_stack = NULL); void arithmetic_op(ValueType* type, Bytecodes::Code code, ValueStack* state_before = NULL);
void negate_op(ValueType* type); void negate_op(ValueType* type);
void shift_op(ValueType* type, Bytecodes::Code code); void shift_op(ValueType* type, Bytecodes::Code code);
void logic_op(ValueType* type, Bytecodes::Code code); void logic_op(ValueType* type, Bytecodes::Code code);
...@@ -267,12 +256,8 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC { ...@@ -267,12 +256,8 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC {
Instruction* append_split(StateSplit* instr); Instruction* append_split(StateSplit* instr);
// other helpers // other helpers
static bool is_async(Bytecodes::Code code) {
assert(0 <= code && code < Bytecodes::number_of_java_codes, "illegal bytecode");
return _is_async[code];
}
BlockBegin* block_at(int bci) { return scope_data()->block_at(bci); } BlockBegin* block_at(int bci) { return scope_data()->block_at(bci); }
XHandlers* handle_exception(int bci); XHandlers* handle_exception(Instruction* instruction);
void connect_to_end(BlockBegin* beg); void connect_to_end(BlockBegin* beg);
void null_check(Value value); void null_check(Value value);
void eliminate_redundant_phis(BlockBegin* start); void eliminate_redundant_phis(BlockBegin* start);
...@@ -283,7 +268,28 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC { ...@@ -283,7 +268,28 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC {
void kill_all(); void kill_all();
ValueStack* lock_stack(); // use of state copy routines (try to minimize unnecessary state
// object allocations):
// - if the instruction unconditionally needs a full copy of the
// state (for patching for example), then use copy_state_before*
// - if the instruction needs a full copy of the state only for
// handler generation (Instruction::needs_exception_state() returns
// false) then use copy_state_exhandling*
// - if the instruction needs either a full copy of the state for
// handler generation and a least a minimal copy of the state (as
// returned by Instruction::exception_state()) for debug info
// generation (that is when Instruction::needs_exception_state()
// returns true) then use copy_state_for_exception*
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();
// //
// Inlining support // Inlining support
...@@ -292,9 +298,7 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC { ...@@ -292,9 +298,7 @@ class GraphBuilder VALUE_OBJ_CLASS_SPEC {
// accessors // accessors
bool parsing_jsr() const { return scope_data()->parsing_jsr(); } bool parsing_jsr() const { return scope_data()->parsing_jsr(); }
BlockBegin* continuation() const { return scope_data()->continuation(); } BlockBegin* continuation() const { return scope_data()->continuation(); }
ValueStack* continuation_state() const { return scope_data()->continuation_state(); }
BlockBegin* jsr_continuation() const { return scope_data()->jsr_continuation(); } BlockBegin* jsr_continuation() const { return scope_data()->jsr_continuation(); }
int caller_stack_size() const { return scope_data()->caller_stack_size(); }
void set_continuation(BlockBegin* continuation) { scope_data()->set_continuation(continuation); } void set_continuation(BlockBegin* continuation) { scope_data()->set_continuation(continuation); }
void set_inline_cleanup_info(BlockBegin* block, void set_inline_cleanup_info(BlockBegin* block,
Instruction* return_prev, Instruction* return_prev,
......
...@@ -116,24 +116,6 @@ bool XHandler::equals(XHandler* other) const { ...@@ -116,24 +116,6 @@ bool XHandler::equals(XHandler* other) const {
// Implementation of IRScope // Implementation of IRScope
BlockBegin* IRScope::header_block(BlockBegin* entry, BlockBegin::Flag f, ValueStack* state) {
if (entry == NULL) return NULL;
assert(entry->is_set(f), "entry/flag mismatch");
// create header block
BlockBegin* h = new BlockBegin(entry->bci());
BlockEnd* g = new Goto(entry, false);
h->set_next(g, entry->bci());
h->set_end(g);
h->set(f);
// setup header block end state
ValueStack* s = state->copy(); // 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* IRScope::build_graph(Compilation* compilation, int osr_bci) { BlockBegin* IRScope::build_graph(Compilation* compilation, int osr_bci) {
GraphBuilder gm(compilation, this); GraphBuilder gm(compilation, this);
NOT_PRODUCT(if (PrintValueNumbering && Verbose) gm.print_stats()); NOT_PRODUCT(if (PrintValueNumbering && Verbose) gm.print_stats());
...@@ -145,12 +127,9 @@ BlockBegin* IRScope::build_graph(Compilation* compilation, int osr_bci) { ...@@ -145,12 +127,9 @@ BlockBegin* IRScope::build_graph(Compilation* compilation, int osr_bci) {
IRScope::IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph) IRScope::IRScope(Compilation* compilation, IRScope* caller, int caller_bci, ciMethod* method, int osr_bci, bool create_graph)
: _callees(2) : _callees(2)
, _compilation(compilation) , _compilation(compilation)
, _lock_stack_size(-1)
, _requires_phi_function(method->max_locals()) , _requires_phi_function(method->max_locals())
{ {
_caller = caller; _caller = caller;
_caller_bci = caller == NULL ? -1 : caller_bci;
_caller_state = NULL; // Must be set later if needed
_level = caller == NULL ? 0 : caller->level() + 1; _level = caller == NULL ? 0 : caller->level() + 1;
_method = method; _method = method;
_xhandlers = new XHandlers(method); _xhandlers = new XHandlers(method);
...@@ -182,32 +161,6 @@ int IRScope::max_stack() const { ...@@ -182,32 +161,6 @@ int IRScope::max_stack() const {
} }
void IRScope::compute_lock_stack_size() {
if (!InlineMethodsWithExceptionHandlers) {
_lock_stack_size = 0;
return;
}
// Figure out whether we have to preserve expression stack elements
// for parent scopes, and if so, how many
IRScope* cur_scope = this;
while (cur_scope != NULL && !cur_scope->xhandlers()->has_handlers()) {
cur_scope = cur_scope->caller();
}
_lock_stack_size = (cur_scope == NULL ? 0 :
(cur_scope->caller_state() == NULL ? 0 :
cur_scope->caller_state()->stack_size()));
}
int IRScope::top_scope_bci() const {
assert(!is_top_scope(), "no correct answer for top scope possible");
const IRScope* scope = this;
while (!scope->caller()->is_top_scope()) {
scope = scope->caller();
}
return scope->caller_bci();
}
bool IRScopeDebugInfo::should_reexecute() { bool IRScopeDebugInfo::should_reexecute() {
ciMethod* cur_method = scope()->method(); ciMethod* cur_method = scope()->method();
int cur_bci = bci(); int cur_bci = bci();
...@@ -222,37 +175,24 @@ bool IRScopeDebugInfo::should_reexecute() { ...@@ -222,37 +175,24 @@ bool IRScopeDebugInfo::should_reexecute() {
// Implementation of CodeEmitInfo // Implementation of CodeEmitInfo
// Stack must be NON-null // Stack must be NON-null
CodeEmitInfo::CodeEmitInfo(int bci, ValueStack* stack, XHandlers* exception_handlers) CodeEmitInfo::CodeEmitInfo(ValueStack* stack, XHandlers* exception_handlers)
: _scope(stack->scope()) : _scope(stack->scope())
, _bci(bci)
, _scope_debug_info(NULL) , _scope_debug_info(NULL)
, _oop_map(NULL) , _oop_map(NULL)
, _stack(stack) , _stack(stack)
, _exception_handlers(exception_handlers) , _exception_handlers(exception_handlers)
, _next(NULL)
, _id(-1)
, _is_method_handle_invoke(false) { , _is_method_handle_invoke(false) {
assert(_stack != NULL, "must be non null"); assert(_stack != NULL, "must be non null");
assert(_bci == SynchronizationEntryBCI || Bytecodes::is_defined(scope()->method()->java_code_at_bci(_bci)), "make sure bci points at a real bytecode");
} }
CodeEmitInfo::CodeEmitInfo(CodeEmitInfo* info, bool lock_stack_only) CodeEmitInfo::CodeEmitInfo(CodeEmitInfo* info, ValueStack* stack)
: _scope(info->_scope) : _scope(info->_scope)
, _exception_handlers(NULL) , _exception_handlers(NULL)
, _bci(info->_bci)
, _scope_debug_info(NULL) , _scope_debug_info(NULL)
, _oop_map(NULL) , _oop_map(NULL)
, _stack(stack == NULL ? info->_stack : stack)
, _is_method_handle_invoke(info->_is_method_handle_invoke) { , _is_method_handle_invoke(info->_is_method_handle_invoke) {
if (lock_stack_only) {
if (info->_stack != NULL) {
_stack = info->_stack->copy_locks();
} else {
_stack = NULL;
}
} else {
_stack = info->_stack;
}
// deep copy of exception handlers // deep copy of exception handlers
if (info->_exception_handlers != NULL) { if (info->_exception_handlers != NULL) {
...@@ -273,8 +213,6 @@ void CodeEmitInfo::add_register_oop(LIR_Opr opr) { ...@@ -273,8 +213,6 @@ void CodeEmitInfo::add_register_oop(LIR_Opr opr) {
assert(_oop_map != NULL, "oop map must already exist"); assert(_oop_map != NULL, "oop map must already exist");
assert(opr->is_single_cpu(), "should not call otherwise"); assert(opr->is_single_cpu(), "should not call otherwise");
int frame_size = frame_map()->framesize();
int arg_count = frame_map()->oop_map_arg_count();
VMReg name = frame_map()->regname(opr); VMReg name = frame_map()->regname(opr);
_oop_map->set_oop(name); _oop_map->set_oop(name);
} }
...@@ -383,8 +321,7 @@ class UseCountComputer: public ValueVisitor, BlockClosure { ...@@ -383,8 +321,7 @@ class UseCountComputer: public ValueVisitor, BlockClosure {
void visit(Value* n) { void visit(Value* n) {
// Local instructions and Phis for expression stack values at the // Local instructions and Phis for expression stack values at the
// start of basic blocks are not added to the instruction list // start of basic blocks are not added to the instruction list
if ((*n)->bci() == -99 && (*n)->as_Local() == NULL && if (!(*n)->is_linked()&& (*n)->can_be_linked()) {
(*n)->as_Phi() == NULL) {
assert(false, "a node was not appended to the graph"); assert(false, "a node was not appended to the graph");
Compilation::current()->bailout("a node was not appended to the graph"); Compilation::current()->bailout("a node was not appended to the graph");
} }
...@@ -1338,7 +1275,7 @@ void SubstitutionResolver::block_do(BlockBegin* block) { ...@@ -1338,7 +1275,7 @@ void SubstitutionResolver::block_do(BlockBegin* block) {
// need to remove this instruction from the instruction stream // need to remove this instruction from the instruction stream
if (n->subst() != n) { if (n->subst() != n) {
assert(last != NULL, "must have last"); assert(last != NULL, "must have last");
last->set_next(n->next(), n->next()->bci()); last->set_next(n->next());
} else { } else {
last = n; last = n;
} }
......
...@@ -132,8 +132,6 @@ class IRScope: public CompilationResourceObj { ...@@ -132,8 +132,6 @@ class IRScope: public CompilationResourceObj {
// hierarchy // hierarchy
Compilation* _compilation; // the current compilation Compilation* _compilation; // the current compilation
IRScope* _caller; // the caller scope, or NULL IRScope* _caller; // the caller scope, or NULL
int _caller_bci; // the caller bci of the corresponding (inlined) invoke, or < 0
ValueStack* _caller_state; // the caller state, or NULL
int _level; // the inlining level int _level; // the inlining level
ciMethod* _method; // the corresponding method ciMethod* _method; // the corresponding method
IRScopeList _callees; // the inlined method scopes IRScopeList _callees; // the inlined method scopes
...@@ -144,15 +142,9 @@ class IRScope: public CompilationResourceObj { ...@@ -144,15 +142,9 @@ class IRScope: public CompilationResourceObj {
bool _monitor_pairing_ok; // the monitor pairing info bool _monitor_pairing_ok; // the monitor pairing info
BlockBegin* _start; // the start block, successsors are method entries BlockBegin* _start; // the start block, successsors are method entries
// lock stack management
int _lock_stack_size; // number of expression stack elements which, if present,
// must be spilled to the stack because of exception
// handling inside inlined methods
BitMap _requires_phi_function; // bit is set if phi functions at loop headers are necessary for a local variable BitMap _requires_phi_function; // bit is set if phi functions at loop headers are necessary for a local variable
// helper functions // helper functions
BlockBegin* header_block(BlockBegin* entry, BlockBegin::Flag f, ValueStack* state);
BlockBegin* build_graph(Compilation* compilation, int osr_bci); BlockBegin* build_graph(Compilation* compilation, int osr_bci);
public: public:
...@@ -162,33 +154,16 @@ class IRScope: public CompilationResourceObj { ...@@ -162,33 +154,16 @@ class IRScope: public CompilationResourceObj {
// accessors // accessors
Compilation* compilation() const { return _compilation; } Compilation* compilation() const { return _compilation; }
IRScope* caller() const { return _caller; } IRScope* caller() const { return _caller; }
int caller_bci() const { return _caller_bci; }
ValueStack* caller_state() const { return _caller_state; }
int level() const { return _level; } int level() const { return _level; }
ciMethod* method() const { return _method; } ciMethod* method() const { return _method; }
int max_stack() const; // NOTE: expensive int max_stack() const; // NOTE: expensive
int lock_stack_size() const {
assert(_lock_stack_size != -1, "uninitialized");
return _lock_stack_size;
}
BitMap& requires_phi_function() { return _requires_phi_function; } BitMap& requires_phi_function() { return _requires_phi_function; }
// mutators
// Needed because caller state is not ready at time of IRScope construction
void set_caller_state(ValueStack* state) { _caller_state = state; }
// Needed because caller state changes after IRScope construction.
// Computes number of expression stack elements whose state must be
// preserved in the case of an exception; these may be seen by
// caller scopes. Zero when inlining of methods containing exception
// handlers is disabled, otherwise a conservative approximation.
void compute_lock_stack_size();
// hierarchy // hierarchy
bool is_top_scope() const { return _caller == NULL; } bool is_top_scope() const { return _caller == NULL; }
void add_callee(IRScope* callee) { _callees.append(callee); } void add_callee(IRScope* callee) { _callees.append(callee); }
int number_of_callees() const { return _callees.length(); } int number_of_callees() const { return _callees.length(); }
IRScope* callee_no(int i) const { return _callees.at(i); } IRScope* callee_no(int i) const { return _callees.at(i); }
int top_scope_bci() const;
// accessors, graph // accessors, graph
bool is_valid() const { return start() != NULL; } bool is_valid() const { return start() != NULL; }
...@@ -266,9 +241,6 @@ class CodeEmitInfo: public CompilationResourceObj { ...@@ -266,9 +241,6 @@ class CodeEmitInfo: public CompilationResourceObj {
XHandlers* _exception_handlers; XHandlers* _exception_handlers;
OopMap* _oop_map; OopMap* _oop_map;
ValueStack* _stack; // used by deoptimization (contains also monitors ValueStack* _stack; // used by deoptimization (contains also monitors
int _bci;
CodeEmitInfo* _next;
int _id;
bool _is_method_handle_invoke; // true if the associated call site is a MethodHandle call site. bool _is_method_handle_invoke; // true if the associated call site is a MethodHandle call site.
FrameMap* frame_map() const { return scope()->compilation()->frame_map(); } FrameMap* frame_map() const { return scope()->compilation()->frame_map(); }
...@@ -277,23 +249,10 @@ class CodeEmitInfo: public CompilationResourceObj { ...@@ -277,23 +249,10 @@ class CodeEmitInfo: public CompilationResourceObj {
public: public:
// use scope from ValueStack // use scope from ValueStack
CodeEmitInfo(int bci, ValueStack* stack, XHandlers* exception_handlers); CodeEmitInfo(ValueStack* stack, XHandlers* exception_handlers);
// used by natives
CodeEmitInfo(IRScope* scope, int bci)
: _scope(scope)
, _bci(bci)
, _oop_map(NULL)
, _scope_debug_info(NULL)
, _stack(NULL)
, _exception_handlers(NULL)
, _next(NULL)
, _id(-1)
, _is_method_handle_invoke(false) {
}
// make a copy // make a copy
CodeEmitInfo(CodeEmitInfo* info, bool lock_stack_only = false); CodeEmitInfo(CodeEmitInfo* info, ValueStack* stack = NULL);
// accessors // accessors
OopMap* oop_map() { return _oop_map; } OopMap* oop_map() { return _oop_map; }
...@@ -301,17 +260,10 @@ class CodeEmitInfo: public CompilationResourceObj { ...@@ -301,17 +260,10 @@ class CodeEmitInfo: public CompilationResourceObj {
IRScope* scope() const { return _scope; } IRScope* scope() const { return _scope; }
XHandlers* exception_handlers() const { return _exception_handlers; } XHandlers* exception_handlers() const { return _exception_handlers; }
ValueStack* stack() const { return _stack; } ValueStack* stack() const { return _stack; }
int bci() const { return _bci; }
void add_register_oop(LIR_Opr opr); void add_register_oop(LIR_Opr opr);
void record_debug_info(DebugInformationRecorder* recorder, int pc_offset); void record_debug_info(DebugInformationRecorder* recorder, int pc_offset);
CodeEmitInfo* next() const { return _next; }
void set_next(CodeEmitInfo* next) { _next = next; }
int id() const { return _id; }
void set_id(int id) { _id = id; }
bool is_method_handle_invoke() const { return _is_method_handle_invoke; } bool is_method_handle_invoke() const { return _is_method_handle_invoke; }
void set_is_method_handle_invoke(bool x) { _is_method_handle_invoke = x; } void set_is_method_handle_invoke(bool x) { _is_method_handle_invoke = x; }
}; };
......
...@@ -29,13 +29,6 @@ ...@@ -29,13 +29,6 @@
// Implementation of Instruction // Implementation of Instruction
#ifdef ASSERT
void Instruction::create_hi_word() {
assert(type()->is_double_word() && _hi_word == NULL, "only double word has high word");
_hi_word = new HiWord(this);
}
#endif
Instruction::Condition Instruction::mirror(Condition cond) { Instruction::Condition Instruction::mirror(Condition cond) {
switch (cond) { switch (cond) {
case eql: return eql; case eql: return eql;
...@@ -63,6 +56,15 @@ Instruction::Condition Instruction::negate(Condition cond) { ...@@ -63,6 +56,15 @@ Instruction::Condition Instruction::negate(Condition cond) {
return eql; 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()->jvmti_can_access_local_variables(), "unexpected state kind");
_exception_state = state;
} else {
_exception_state = NULL;
}
}
Instruction* Instruction::prev(BlockBegin* block) { Instruction* Instruction::prev(BlockBegin* block) {
Instruction* p = NULL; Instruction* p = NULL;
...@@ -75,7 +77,24 @@ Instruction* Instruction::prev(BlockBegin* block) { ...@@ -75,7 +77,24 @@ Instruction* Instruction::prev(BlockBegin* block) {
} }
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);
}
}
#ifndef PRODUCT #ifndef PRODUCT
void Instruction::check_state(ValueStack* state) {
if (state != NULL) {
state->verify();
}
}
void Instruction::print() { void Instruction::print() {
InstructionPrinter ip; InstructionPrinter ip;
print(ip); print(ip);
...@@ -190,35 +209,6 @@ ciType* CheckCast::exact_type() const { ...@@ -190,35 +209,6 @@ ciType* CheckCast::exact_type() const {
return NULL; return NULL;
} }
void ArithmeticOp::other_values_do(ValueVisitor* f) {
if (lock_stack() != NULL) lock_stack()->values_do(f);
}
void NullCheck::other_values_do(ValueVisitor* f) {
lock_stack()->values_do(f);
}
void AccessArray::other_values_do(ValueVisitor* f) {
if (lock_stack() != NULL) lock_stack()->values_do(f);
}
// Implementation of AccessField
void AccessField::other_values_do(ValueVisitor* f) {
if (state_before() != NULL) state_before()->values_do(f);
if (lock_stack() != NULL) lock_stack()->values_do(f);
}
// Implementation of StoreIndexed
IRScope* StoreIndexed::scope() const {
return lock_stack()->scope();
}
// Implementation of ArithmeticOp // Implementation of ArithmeticOp
bool ArithmeticOp::is_commutative() const { bool ArithmeticOp::is_commutative() const {
...@@ -266,13 +256,6 @@ bool LogicOp::is_commutative() const { ...@@ -266,13 +256,6 @@ bool LogicOp::is_commutative() const {
} }
// Implementation of CompareOp
void CompareOp::other_values_do(ValueVisitor* f) {
if (state_before() != NULL) state_before()->values_do(f);
}
// Implementation of IfOp // Implementation of IfOp
bool IfOp::is_commutative() const { bool IfOp::is_commutative() const {
...@@ -301,6 +284,7 @@ IRScope* StateSplit::scope() const { ...@@ -301,6 +284,7 @@ IRScope* StateSplit::scope() const {
void StateSplit::state_values_do(ValueVisitor* f) { void StateSplit::state_values_do(ValueVisitor* f) {
Instruction::state_values_do(f);
if (state() != NULL) state()->values_do(f); if (state() != NULL) state()->values_do(f);
} }
...@@ -316,30 +300,17 @@ void BlockBegin::state_values_do(ValueVisitor* f) { ...@@ -316,30 +300,17 @@ void BlockBegin::state_values_do(ValueVisitor* f) {
} }
void MonitorEnter::state_values_do(ValueVisitor* f) {
StateSplit::state_values_do(f);
_lock_stack_before->values_do(f);
}
void Intrinsic::state_values_do(ValueVisitor* f) {
StateSplit::state_values_do(f);
if (lock_stack() != NULL) lock_stack()->values_do(f);
}
// Implementation of Invoke // Implementation of Invoke
Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args, Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
int vtable_index, ciMethod* target, ValueStack* state_before) int vtable_index, ciMethod* target, ValueStack* state_before)
: StateSplit(result_type) : StateSplit(result_type, state_before)
, _code(code) , _code(code)
, _recv(recv) , _recv(recv)
, _args(args) , _args(args)
, _vtable_index(vtable_index) , _vtable_index(vtable_index)
, _target(target) , _target(target)
, _state_before(state_before)
{ {
set_flag(TargetIsLoadedFlag, target->is_loaded()); set_flag(TargetIsLoadedFlag, target->is_loaded());
set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method()); set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method());
...@@ -376,7 +347,7 @@ void Invoke::state_values_do(ValueVisitor* f) { ...@@ -376,7 +347,7 @@ void Invoke::state_values_do(ValueVisitor* f) {
// Implementation of Contant // Implementation of Contant
intx Constant::hash() const { intx Constant::hash() const {
if (_state == NULL) { if (state_before() == NULL) {
switch (type()->tag()) { switch (type()->tag()) {
case intTag: case intTag:
return HASH2(name(), type()->as_IntConstant()->value()); return HASH2(name(), type()->as_IntConstant()->value());
...@@ -499,25 +470,6 @@ BlockBegin* Constant::compare(Instruction::Condition cond, Value right, ...@@ -499,25 +470,6 @@ BlockBegin* Constant::compare(Instruction::Condition cond, Value right,
} }
void Constant::other_values_do(ValueVisitor* f) {
if (state() != NULL) state()->values_do(f);
}
// Implementation of NewArray
void NewArray::other_values_do(ValueVisitor* f) {
if (state_before() != NULL) state_before()->values_do(f);
}
// Implementation of TypeCheck
void TypeCheck::other_values_do(ValueVisitor* f) {
if (state_before() != NULL) state_before()->values_do(f);
}
// Implementation of BlockBegin // Implementation of BlockBegin
void BlockBegin::set_end(BlockEnd* end) { void BlockBegin::set_end(BlockEnd* end) {
...@@ -604,23 +556,14 @@ void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) { ...@@ -604,23 +556,14 @@ void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
// of the inserted block, without recomputing the values of the other blocks // of the inserted block, without recomputing the values of the other blocks
// in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless. // in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless.
BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) { BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) {
// Try to make the bci close to a block with a single pred or sux, BlockBegin* new_sux = new BlockBegin(-99);
// since this make the block layout algorithm work better.
int bci = -1;
if (sux->number_of_preds() == 1) {
bci = sux->bci();
} else {
bci = end()->bci();
}
BlockBegin* new_sux = new BlockBegin(bci);
// mark this block (special treatment when block order is computed) // mark this block (special treatment when block order is computed)
new_sux->set(critical_edge_split_flag); new_sux->set(critical_edge_split_flag);
// This goto is not a safepoint. // This goto is not a safepoint.
Goto* e = new Goto(sux, false); Goto* e = new Goto(sux, false);
new_sux->set_next(e, bci); new_sux->set_next(e, end()->state()->bci());
new_sux->set_end(e); new_sux->set_end(e);
// setup states // setup states
ValueStack* s = end()->state(); ValueStack* s = end()->state();
...@@ -763,7 +706,7 @@ bool BlockBegin::try_merge(ValueStack* new_state) { ...@@ -763,7 +706,7 @@ bool BlockBegin::try_merge(ValueStack* new_state) {
} }
// copy state because it is altered // copy state because it is altered
new_state = new_state->copy(); new_state = new_state->copy(ValueStack::BlockBeginState, bci());
// Use method liveness to invalidate dead locals // Use method liveness to invalidate dead locals
MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci()); MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());
...@@ -800,19 +743,9 @@ bool BlockBegin::try_merge(ValueStack* new_state) { ...@@ -800,19 +743,9 @@ bool BlockBegin::try_merge(ValueStack* new_state) {
// initialize state of block // initialize state of block
set_state(new_state); set_state(new_state);
} else if (existing_state->is_same_across_scopes(new_state)) { } else if (existing_state->is_same(new_state)) {
TRACE_PHI(tty->print_cr("exisiting state found")); TRACE_PHI(tty->print_cr("exisiting state found"));
// Inlining may cause the local state not to match up, so walk up
// the new state until we get to the same scope as the
// existing and then start processing from there.
while (existing_state->scope() != new_state->scope()) {
new_state = new_state->caller_state();
assert(new_state != NULL, "could not match up scopes");
assert(false, "check if this is necessary");
}
assert(existing_state->scope() == new_state->scope(), "not matching"); assert(existing_state->scope() == new_state->scope(), "not matching");
assert(existing_state->locals_size() == new_state->locals_size(), "not matching"); assert(existing_state->locals_size() == new_state->locals_size(), "not matching");
assert(existing_state->stack_size() == new_state->stack_size(), "not matching"); assert(existing_state->stack_size() == new_state->stack_size(), "not matching");
...@@ -969,11 +902,6 @@ void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) { ...@@ -969,11 +902,6 @@ void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
} }
void BlockEnd::other_values_do(ValueVisitor* f) {
if (state_before() != NULL) state_before()->values_do(f);
}
// Implementation of Phi // Implementation of Phi
// Normal phi functions take their operands from the last instruction of the // Normal phi functions take their operands from the last instruction of the
...@@ -1006,11 +934,6 @@ int Phi::operand_count() const { ...@@ -1006,11 +934,6 @@ int Phi::operand_count() const {
} }
// Implementation of Throw
void Throw::state_values_do(ValueVisitor* f) {
BlockEnd::state_values_do(f);
}
void ProfileInvoke::state_values_do(ValueVisitor* f) { void ProfileInvoke::state_values_do(ValueVisitor* f) {
if (state() != NULL) state()->values_do(f); if (state() != NULL) state()->values_do(f);
......
此差异已折叠。
...@@ -316,7 +316,7 @@ void InstructionPrinter::print_head() { ...@@ -316,7 +316,7 @@ void InstructionPrinter::print_head() {
void InstructionPrinter::print_line(Instruction* instr) { void InstructionPrinter::print_line(Instruction* instr) {
// print instruction data on one line // print instruction data on one line
if (instr->is_pinned()) output()->put('.'); if (instr->is_pinned()) output()->put('.');
fill_to(bci_pos ); output()->print("%d", instr->bci()); fill_to(bci_pos ); output()->print("%d", instr->printable_bci());
fill_to(use_pos ); output()->print("%d", instr->use_count()); fill_to(use_pos ); output()->print("%d", instr->use_count());
fill_to(temp_pos ); print_temp(instr); fill_to(temp_pos ); print_temp(instr);
fill_to(instr_pos); print_instr(instr); fill_to(instr_pos); print_instr(instr);
...@@ -569,7 +569,7 @@ void InstructionPrinter::do_BlockBegin(BlockBegin* x) { ...@@ -569,7 +569,7 @@ void InstructionPrinter::do_BlockBegin(BlockBegin* x) {
if (printed_flag) output()->print(") "); if (printed_flag) output()->print(") ");
// print block bci range // print block bci range
output()->print("[%d, %d]", x->bci(), (end == NULL ? -1 : end->bci())); output()->print("[%d, %d]", x->bci(), (end == NULL ? -1 : end->printable_bci()));
// print block successors // print block successors
if (end != NULL && end->number_of_sux() > 0) { if (end != NULL && end->number_of_sux() > 0) {
......
...@@ -1520,7 +1520,7 @@ static void print_block(BlockBegin* x) { ...@@ -1520,7 +1520,7 @@ static void print_block(BlockBegin* x) {
if (x->is_set(BlockBegin::linear_scan_loop_end_flag)) tty->print("le "); if (x->is_set(BlockBegin::linear_scan_loop_end_flag)) tty->print("le ");
// print block bci range // print block bci range
tty->print("[%d, %d] ", x->bci(), (end == NULL ? -1 : end->bci())); tty->print("[%d, %d] ", x->bci(), (end == NULL ? -1 : end->printable_bci()));
// print predecessors and successors // print predecessors and successors
if (x->number_of_preds() > 0) { if (x->number_of_preds() > 0) {
...@@ -1576,7 +1576,7 @@ void LIR_Op::print_on(outputStream* out) const { ...@@ -1576,7 +1576,7 @@ void LIR_Op::print_on(outputStream* out) const {
} }
out->print(name()); out->print(" "); out->print(name()); out->print(" ");
print_instr(out); print_instr(out);
if (info() != NULL) out->print(" [bci:%d]", info()->bci()); if (info() != NULL) out->print(" [bci:%d]", info()->stack()->bci());
#ifdef ASSERT #ifdef ASSERT
if (Verbose && _file != NULL) { if (Verbose && _file != NULL) {
out->print(" (%s:%d)", _file, _line); out->print(" (%s:%d)", _file, _line);
...@@ -1781,7 +1781,7 @@ void LIR_OpBranch::print_instr(outputStream* out) const { ...@@ -1781,7 +1781,7 @@ void LIR_OpBranch::print_instr(outputStream* out) const {
out->print("["); out->print("[");
stub()->print_name(out); stub()->print_name(out);
out->print(": 0x%x]", stub()); out->print(": 0x%x]", stub());
if (stub()->info() != NULL) out->print(" [bci:%d]", stub()->info()->bci()); if (stub()->info() != NULL) out->print(" [bci:%d]", stub()->info()->stack()->bci());
} else { } else {
out->print("[label:0x%x] ", label()); out->print("[label:0x%x] ", label());
} }
...@@ -1896,7 +1896,7 @@ void LIR_OpTypeCheck::print_instr(outputStream* out) const { ...@@ -1896,7 +1896,7 @@ void LIR_OpTypeCheck::print_instr(outputStream* out) const {
tmp2()->print(out); out->print(" "); tmp2()->print(out); out->print(" ");
tmp3()->print(out); out->print(" "); tmp3()->print(out); out->print(" ");
result_opr()->print(out); out->print(" "); result_opr()->print(out); out->print(" ");
if (info_for_exception() != NULL) out->print(" [bci:%d]", info_for_exception()->bci()); if (info_for_exception() != NULL) out->print(" [bci:%d]", info_for_exception()->stack()->bci());
} }
......
...@@ -35,7 +35,7 @@ void LIR_Assembler::patching_epilog(PatchingStub* patch, LIR_PatchCode patch_cod ...@@ -35,7 +35,7 @@ void LIR_Assembler::patching_epilog(PatchingStub* patch, LIR_PatchCode patch_cod
append_patching_stub(patch); append_patching_stub(patch);
#ifdef ASSERT #ifdef ASSERT
Bytecodes::Code code = info->scope()->method()->java_code_at_bci(info->bci()); Bytecodes::Code code = info->scope()->method()->java_code_at_bci(info->stack()->bci());
if (patch->id() == PatchingStub::access_field_id) { if (patch->id() == PatchingStub::access_field_id) {
switch (code) { switch (code) {
case Bytecodes::_putstatic: case Bytecodes::_putstatic:
...@@ -221,7 +221,7 @@ void LIR_Assembler::emit_block(BlockBegin* block) { ...@@ -221,7 +221,7 @@ void LIR_Assembler::emit_block(BlockBegin* block) {
#ifndef PRODUCT #ifndef PRODUCT
if (CommentedAssembly) { if (CommentedAssembly) {
stringStream st; stringStream st;
st.print_cr(" block B%d [%d, %d]", block->block_id(), block->bci(), block->end()->bci()); st.print_cr(" block B%d [%d, %d]", block->block_id(), block->bci(), block->end()->printable_bci());
_masm->block_comment(st.as_string()); _masm->block_comment(st.as_string());
} }
#endif #endif
...@@ -312,7 +312,7 @@ void LIR_Assembler::add_call_info(int pc_offset, CodeEmitInfo* cinfo) { ...@@ -312,7 +312,7 @@ void LIR_Assembler::add_call_info(int pc_offset, CodeEmitInfo* cinfo) {
static ValueStack* debug_info(Instruction* ins) { static ValueStack* debug_info(Instruction* ins) {
StateSplit* ss = ins->as_StateSplit(); StateSplit* ss = ins->as_StateSplit();
if (ss != NULL) return ss->state(); if (ss != NULL) return ss->state();
return ins->lock_stack(); return ins->state_before();
} }
void LIR_Assembler::process_debug_info(LIR_Op* op) { void LIR_Assembler::process_debug_info(LIR_Op* op) {
...@@ -327,8 +327,7 @@ void LIR_Assembler::process_debug_info(LIR_Op* op) { ...@@ -327,8 +327,7 @@ void LIR_Assembler::process_debug_info(LIR_Op* op) {
if (vstack == NULL) return; if (vstack == NULL) return;
if (_pending_non_safepoint != NULL) { if (_pending_non_safepoint != NULL) {
// Got some old debug info. Get rid of it. // Got some old debug info. Get rid of it.
if (_pending_non_safepoint->bci() == src->bci() && if (debug_info(_pending_non_safepoint) == vstack) {
debug_info(_pending_non_safepoint) == vstack) {
_pending_non_safepoint_offset = pc_offset; _pending_non_safepoint_offset = pc_offset;
return; return;
} }
...@@ -358,7 +357,7 @@ static ValueStack* nth_oldest(ValueStack* s, int n, int& bci_result) { ...@@ -358,7 +357,7 @@ static ValueStack* nth_oldest(ValueStack* s, int n, int& bci_result) {
ValueStack* tc = t->caller_state(); ValueStack* tc = t->caller_state();
if (tc == NULL) return s; if (tc == NULL) return s;
t = tc; t = tc;
bci_result = s->scope()->caller_bci(); bci_result = tc->bci();
s = s->caller_state(); s = s->caller_state();
} }
} }
...@@ -366,7 +365,7 @@ static ValueStack* nth_oldest(ValueStack* s, int n, int& bci_result) { ...@@ -366,7 +365,7 @@ static ValueStack* nth_oldest(ValueStack* s, int n, int& bci_result) {
void LIR_Assembler::record_non_safepoint_debug_info() { void LIR_Assembler::record_non_safepoint_debug_info() {
int pc_offset = _pending_non_safepoint_offset; int pc_offset = _pending_non_safepoint_offset;
ValueStack* vstack = debug_info(_pending_non_safepoint); ValueStack* vstack = debug_info(_pending_non_safepoint);
int bci = _pending_non_safepoint->bci(); int bci = vstack->bci();
DebugInformationRecorder* debug_info = compilation()->debug_info_recorder(); DebugInformationRecorder* debug_info = compilation()->debug_info_recorder();
assert(debug_info->recording_non_safepoints(), "sanity"); assert(debug_info->recording_non_safepoints(), "sanity");
...@@ -380,7 +379,7 @@ void LIR_Assembler::record_non_safepoint_debug_info() { ...@@ -380,7 +379,7 @@ void LIR_Assembler::record_non_safepoint_debug_info() {
if (s == NULL) break; if (s == NULL) break;
IRScope* scope = s->scope(); IRScope* scope = s->scope();
//Always pass false for reexecute since these ScopeDescs are never used for deopt //Always pass false for reexecute since these ScopeDescs are never used for deopt
debug_info->describe_scope(pc_offset, scope->method(), s_bci, false/*reexecute*/); debug_info->describe_scope(pc_offset, scope->method(), s->bci(), false/*reexecute*/);
} }
debug_info->end_non_safepoint(pc_offset); debug_info->end_non_safepoint(pc_offset);
......
...@@ -386,18 +386,26 @@ void LIRGenerator::walk(Value instr) { ...@@ -386,18 +386,26 @@ void LIRGenerator::walk(Value instr) {
CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ignore_xhandler) { CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ignore_xhandler) {
assert(state != NULL, "state must be defined");
ValueStack* s = state;
for_each_state(s) {
if (s->kind() == ValueStack::EmptyExceptionState) {
assert(s->stack_size() == 0 && s->locals_size() == 0 && (s->locks_size() == 0 || s->locks_size() == 1), "state must be empty");
continue;
}
int index; int index;
Value value; Value value;
for_each_stack_value(state, index, value) { for_each_stack_value(s, index, value) {
assert(value->subst() == value, "missed substition"); assert(value->subst() == value, "missed substitution");
if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) { if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) {
walk(value); walk(value);
assert(value->operand()->is_valid(), "must be evaluated now"); assert(value->operand()->is_valid(), "must be evaluated now");
} }
} }
ValueStack* s = state;
int bci = x->bci(); int bci = s->bci();
for_each_state(s) {
IRScope* scope = s->scope(); IRScope* scope = s->scope();
ciMethod* method = scope->method(); ciMethod* method = scope->method();
...@@ -428,15 +436,14 @@ CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ig ...@@ -428,15 +436,14 @@ CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ig
} }
} }
} }
bci = scope->caller_bci();
} }
return new CodeEmitInfo(x->bci(), state, ignore_xhandler ? NULL : x->exception_handlers()); return new CodeEmitInfo(state, ignore_xhandler ? NULL : x->exception_handlers());
} }
CodeEmitInfo* LIRGenerator::state_for(Instruction* x) { CodeEmitInfo* LIRGenerator::state_for(Instruction* x) {
return state_for(x, x->lock_stack()); return state_for(x, x->exception_state());
} }
...@@ -900,18 +907,14 @@ void LIRGenerator::move_to_phi(ValueStack* cur_state) { ...@@ -900,18 +907,14 @@ void LIRGenerator::move_to_phi(ValueStack* cur_state) {
Value sux_value; Value sux_value;
int index; int index;
assert(cur_state->scope() == sux_state->scope(), "not matching");
assert(cur_state->locals_size() == sux_state->locals_size(), "not matching");
assert(cur_state->stack_size() == sux_state->stack_size(), "not matching");
for_each_stack_value(sux_state, index, sux_value) { for_each_stack_value(sux_state, index, sux_value) {
move_to_phi(&resolver, cur_state->stack_at(index), sux_value); move_to_phi(&resolver, cur_state->stack_at(index), sux_value);
} }
// Inlining may cause the local state not to match up, so walk up
// the caller state until we get to the same scope as the
// successor and then start processing from there.
while (cur_state->scope() != sux_state->scope()) {
cur_state = cur_state->caller_state();
assert(cur_state != NULL, "scopes don't match up");
}
for_each_local_value(sux_state, index, sux_value) { for_each_local_value(sux_state, index, sux_value) {
move_to_phi(&resolver, cur_state->local_at(index), sux_value); move_to_phi(&resolver, cur_state->local_at(index), sux_value);
} }
...@@ -1023,10 +1026,10 @@ void LIRGenerator::do_Phi(Phi* x) { ...@@ -1023,10 +1026,10 @@ void LIRGenerator::do_Phi(Phi* x) {
// Code for a constant is generated lazily unless the constant is frequently used and can't be inlined. // Code for a constant is generated lazily unless the constant is frequently used and can't be inlined.
void LIRGenerator::do_Constant(Constant* x) { void LIRGenerator::do_Constant(Constant* x) {
if (x->state() != NULL) { if (x->state_before() != NULL) {
// Any constant with a ValueStack requires patching so emit the patch here // Any constant with a ValueStack requires patching so emit the patch here
LIR_Opr reg = rlock_result(x); LIR_Opr reg = rlock_result(x);
CodeEmitInfo* info = state_for(x, x->state()); CodeEmitInfo* info = state_for(x, x->state_before());
__ oop2reg_patch(NULL, reg, info); __ oop2reg_patch(NULL, reg, info);
} else if (x->use_count() > 1 && !can_inline_as_constant(x)) { } else if (x->use_count() > 1 && !can_inline_as_constant(x)) {
if (!x->is_pinned()) { if (!x->is_pinned()) {
...@@ -1102,7 +1105,7 @@ void LIRGenerator::do_getClass(Intrinsic* x) { ...@@ -1102,7 +1105,7 @@ void LIRGenerator::do_getClass(Intrinsic* x) {
// need to perform the null check on the rcvr // need to perform the null check on the rcvr
CodeEmitInfo* info = NULL; CodeEmitInfo* info = NULL;
if (x->needs_null_check()) { if (x->needs_null_check()) {
info = state_for(x, x->state()->copy_locks()); info = state_for(x);
} }
__ move(new LIR_Address(rcvr.result(), oopDesc::klass_offset_in_bytes(), T_OBJECT), result, info); __ move(new LIR_Address(rcvr.result(), oopDesc::klass_offset_in_bytes(), T_OBJECT), result, info);
__ move(new LIR_Address(result, Klass::java_mirror_offset_in_bytes() + __ move(new LIR_Address(result, Klass::java_mirror_offset_in_bytes() +
...@@ -1481,7 +1484,7 @@ void LIRGenerator::do_StoreField(StoreField* x) { ...@@ -1481,7 +1484,7 @@ void LIRGenerator::do_StoreField(StoreField* x) {
} else if (x->needs_null_check()) { } else if (x->needs_null_check()) {
NullCheck* nc = x->explicit_null_check(); NullCheck* nc = x->explicit_null_check();
if (nc == NULL) { if (nc == NULL) {
info = state_for(x, x->lock_stack()); info = state_for(x);
} else { } else {
info = state_for(nc); info = state_for(nc);
} }
...@@ -1509,10 +1512,12 @@ void LIRGenerator::do_StoreField(StoreField* x) { ...@@ -1509,10 +1512,12 @@ void LIRGenerator::do_StoreField(StoreField* x) {
set_no_result(x); set_no_result(x);
#ifndef PRODUCT
if (PrintNotLoaded && needs_patching) { if (PrintNotLoaded && needs_patching) {
tty->print_cr(" ###class not loaded at store_%s bci %d", tty->print_cr(" ###class not loaded at store_%s bci %d",
x->is_static() ? "static" : "field", x->bci()); x->is_static() ? "static" : "field", x->printable_bci());
} }
#endif
if (x->needs_null_check() && if (x->needs_null_check() &&
(needs_patching || (needs_patching ||
...@@ -1575,7 +1580,7 @@ void LIRGenerator::do_LoadField(LoadField* x) { ...@@ -1575,7 +1580,7 @@ void LIRGenerator::do_LoadField(LoadField* x) {
} else if (x->needs_null_check()) { } else if (x->needs_null_check()) {
NullCheck* nc = x->explicit_null_check(); NullCheck* nc = x->explicit_null_check();
if (nc == NULL) { if (nc == NULL) {
info = state_for(x, x->lock_stack()); info = state_for(x);
} else { } else {
info = state_for(nc); info = state_for(nc);
} }
...@@ -1585,10 +1590,12 @@ void LIRGenerator::do_LoadField(LoadField* x) { ...@@ -1585,10 +1590,12 @@ void LIRGenerator::do_LoadField(LoadField* x) {
object.load_item(); object.load_item();
#ifndef PRODUCT
if (PrintNotLoaded && needs_patching) { if (PrintNotLoaded && needs_patching) {
tty->print_cr(" ###class not loaded at load_%s bci %d", tty->print_cr(" ###class not loaded at load_%s bci %d",
x->is_static() ? "static" : "field", x->bci()); x->is_static() ? "static" : "field", x->printable_bci());
} }
#endif
if (x->needs_null_check() && if (x->needs_null_check() &&
(needs_patching || (needs_patching ||
...@@ -1781,7 +1788,7 @@ void LIRGenerator::do_Throw(Throw* x) { ...@@ -1781,7 +1788,7 @@ void LIRGenerator::do_Throw(Throw* x) {
if (GenerateCompilerNullChecks && if (GenerateCompilerNullChecks &&
(x->exception()->as_NewInstance() == NULL && x->exception()->as_ExceptionObject() == NULL)) { (x->exception()->as_NewInstance() == NULL && x->exception()->as_ExceptionObject() == NULL)) {
// if the exception object wasn't created using new then it might be null. // if the exception object wasn't created using new then it might be null.
__ null_check(exception_opr, new CodeEmitInfo(info, true)); __ null_check(exception_opr, new CodeEmitInfo(info, x->state()->copy(ValueStack::ExceptionState, x->state()->bci())));
} }
if (compilation()->env()->jvmti_can_post_on_exceptions()) { if (compilation()->env()->jvmti_can_post_on_exceptions()) {
...@@ -2127,7 +2134,6 @@ void LIRGenerator::do_TableSwitch(TableSwitch* x) { ...@@ -2127,7 +2134,6 @@ void LIRGenerator::do_TableSwitch(TableSwitch* x) {
int lo_key = x->lo_key(); int lo_key = x->lo_key();
int hi_key = x->hi_key(); int hi_key = x->hi_key();
int len = x->length(); int len = x->length();
CodeEmitInfo* info = state_for(x, x->state());
LIR_Opr value = tag.result(); LIR_Opr value = tag.result();
if (UseTableRanges) { if (UseTableRanges) {
do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux()); do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux());
...@@ -2186,7 +2192,7 @@ void LIRGenerator::do_Goto(Goto* x) { ...@@ -2186,7 +2192,7 @@ void LIRGenerator::do_Goto(Goto* x) {
// increment backedge counter if needed // increment backedge counter if needed
CodeEmitInfo* info = state_for(x, state); CodeEmitInfo* info = state_for(x, state);
increment_backedge_counter(info, info->bci()); increment_backedge_counter(info, info->stack()->bci());
CodeEmitInfo* safepoint_info = state_for(x, state); CodeEmitInfo* safepoint_info = state_for(x, state);
__ safepoint(safepoint_poll_register(), safepoint_info); __ safepoint(safepoint_poll_register(), safepoint_info);
} }
...@@ -2293,7 +2299,7 @@ void LIRGenerator::do_Base(Base* x) { ...@@ -2293,7 +2299,7 @@ void LIRGenerator::do_Base(Base* x) {
LIR_Opr lock = new_register(T_INT); LIR_Opr lock = new_register(T_INT);
__ load_stack_address_monitor(0, lock); __ load_stack_address_monitor(0, lock);
CodeEmitInfo* info = new CodeEmitInfo(SynchronizationEntryBCI, scope()->start()->state(), NULL); CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), NULL);
CodeStub* slow_path = new MonitorEnterStub(obj, lock, info); CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
// receiver is guaranteed non-NULL so don't need CodeEmitInfo // receiver is guaranteed non-NULL so don't need CodeEmitInfo
...@@ -2303,7 +2309,7 @@ void LIRGenerator::do_Base(Base* x) { ...@@ -2303,7 +2309,7 @@ void LIRGenerator::do_Base(Base* x) {
// increment invocation counters if needed // increment invocation counters if needed
if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting. if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting.
CodeEmitInfo* info = new CodeEmitInfo(InvocationEntryBci, scope()->start()->state(), NULL); CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state(), NULL);
increment_invocation_counter(info); increment_invocation_counter(info);
} }
...@@ -2463,7 +2469,7 @@ void LIRGenerator::do_Invoke(Invoke* x) { ...@@ -2463,7 +2469,7 @@ void LIRGenerator::do_Invoke(Invoke* x) {
break; break;
case Bytecodes::_invokedynamic: { case Bytecodes::_invokedynamic: {
ciBytecodeStream bcs(x->scope()->method()); ciBytecodeStream bcs(x->scope()->method());
bcs.force_bci(x->bci()); bcs.force_bci(x->state()->bci());
assert(bcs.cur_bc() == Bytecodes::_invokedynamic, "wrong stream"); assert(bcs.cur_bc() == Bytecodes::_invokedynamic, "wrong stream");
ciCPCache* cpcache = bcs.get_cpcache(); ciCPCache* cpcache = bcs.get_cpcache();
......
...@@ -2274,8 +2274,8 @@ void assert_equal(IRScopeDebugInfo* d1, IRScopeDebugInfo* d2) { ...@@ -2274,8 +2274,8 @@ void assert_equal(IRScopeDebugInfo* d1, IRScopeDebugInfo* d2) {
} }
void check_stack_depth(CodeEmitInfo* info, int stack_end) { void check_stack_depth(CodeEmitInfo* info, int stack_end) {
if (info->bci() != SynchronizationEntryBCI && !info->scope()->method()->is_native()) { if (info->stack()->bci() != SynchronizationEntryBCI && !info->scope()->method()->is_native()) {
Bytecodes::Code code = info->scope()->method()->java_code_at_bci(info->bci()); Bytecodes::Code code = info->scope()->method()->java_code_at_bci(info->stack()->bci());
switch (code) { switch (code) {
case Bytecodes::_ifnull : // fall through case Bytecodes::_ifnull : // fall through
case Bytecodes::_ifnonnull : // fall through case Bytecodes::_ifnonnull : // fall through
...@@ -2379,7 +2379,7 @@ OopMap* LinearScan::compute_oop_map(IntervalWalker* iw, LIR_Op* op, CodeEmitInfo ...@@ -2379,7 +2379,7 @@ OopMap* LinearScan::compute_oop_map(IntervalWalker* iw, LIR_Op* op, CodeEmitInfo
// add oops from lock stack // add oops from lock stack
assert(info->stack() != NULL, "CodeEmitInfo must always have a stack"); assert(info->stack() != NULL, "CodeEmitInfo must always have a stack");
int locks_count = info->stack()->locks_size(); int locks_count = info->stack()->total_locks_size();
for (int i = 0; i < locks_count; i++) { for (int i = 0; i < locks_count; i++) {
map->set_oop(frame_map()->monitor_object_regname(i)); map->set_oop(frame_map()->monitor_object_regname(i));
} }
...@@ -2762,19 +2762,13 @@ int LinearScan::append_scope_value(int op_id, Value value, GrowableArray<ScopeVa ...@@ -2762,19 +2762,13 @@ int LinearScan::append_scope_value(int op_id, Value value, GrowableArray<ScopeVa
} }
IRScopeDebugInfo* LinearScan::compute_debug_info_for_scope(int op_id, IRScope* cur_scope, ValueStack* cur_state, ValueStack* innermost_state, int cur_bci, int stack_end, int locks_end) { IRScopeDebugInfo* LinearScan::compute_debug_info_for_scope(int op_id, IRScope* cur_scope, ValueStack* cur_state, ValueStack* innermost_state) {
IRScopeDebugInfo* caller_debug_info = NULL; IRScopeDebugInfo* caller_debug_info = NULL;
int stack_begin, locks_begin;
ValueStack* caller_state = cur_scope->caller_state(); ValueStack* caller_state = cur_state->caller_state();
if (caller_state != NULL) { if (caller_state != NULL) {
// process recursively to compute outermost scope first // process recursively to compute outermost scope first
stack_begin = caller_state->stack_size(); caller_debug_info = compute_debug_info_for_scope(op_id, cur_scope->caller(), caller_state, innermost_state);
locks_begin = caller_state->locks_size();
caller_debug_info = compute_debug_info_for_scope(op_id, cur_scope->caller(), caller_state, innermost_state, cur_scope->caller_bci(), stack_begin, locks_begin);
} else {
stack_begin = 0;
locks_begin = 0;
} }
// initialize these to null. // initialize these to null.
...@@ -2785,7 +2779,7 @@ IRScopeDebugInfo* LinearScan::compute_debug_info_for_scope(int op_id, IRScope* c ...@@ -2785,7 +2779,7 @@ IRScopeDebugInfo* LinearScan::compute_debug_info_for_scope(int op_id, IRScope* c
GrowableArray<MonitorValue*>* monitors = NULL; GrowableArray<MonitorValue*>* monitors = NULL;
// describe local variable values // describe local variable values
int nof_locals = cur_scope->method()->max_locals(); int nof_locals = cur_state->locals_size();
if (nof_locals > 0) { if (nof_locals > 0) {
locals = new GrowableArray<ScopeValue*>(nof_locals); locals = new GrowableArray<ScopeValue*>(nof_locals);
...@@ -2800,45 +2794,41 @@ IRScopeDebugInfo* LinearScan::compute_debug_info_for_scope(int op_id, IRScope* c ...@@ -2800,45 +2794,41 @@ IRScopeDebugInfo* LinearScan::compute_debug_info_for_scope(int op_id, IRScope* c
} }
assert(locals->length() == cur_scope->method()->max_locals(), "wrong number of locals"); assert(locals->length() == cur_scope->method()->max_locals(), "wrong number of locals");
assert(locals->length() == cur_state->locals_size(), "wrong number of locals"); assert(locals->length() == cur_state->locals_size(), "wrong number of locals");
} else if (cur_scope->method()->max_locals() > 0) {
assert(cur_state->kind() == ValueStack::EmptyExceptionState, "should be");
nof_locals = cur_scope->method()->max_locals();
locals = new GrowableArray<ScopeValue*>(nof_locals);
for(int i = 0; i < nof_locals; i++) {
locals->append(&_illegal_value);
} }
// describe expression stack
//
// When we inline methods containing exception handlers, the
// "lock_stacks" are changed to preserve expression stack values
// in caller scopes when exception handlers are present. This
// can cause callee stacks to be smaller than caller stacks.
if (stack_end > innermost_state->stack_size()) {
stack_end = innermost_state->stack_size();
} }
// describe expression stack
int nof_stack = cur_state->stack_size();
int nof_stack = stack_end - stack_begin;
if (nof_stack > 0) { if (nof_stack > 0) {
expressions = new GrowableArray<ScopeValue*>(nof_stack); expressions = new GrowableArray<ScopeValue*>(nof_stack);
int pos = stack_begin; int pos = 0;
while (pos < stack_end) { while (pos < nof_stack) {
Value expression = innermost_state->stack_at_inc(pos); Value expression = cur_state->stack_at_inc(pos);
append_scope_value(op_id, expression, expressions); append_scope_value(op_id, expression, expressions);
assert(expressions->length() + stack_begin == pos, "must match"); assert(expressions->length() == pos, "must match");
} }
assert(expressions->length() == cur_state->stack_size(), "wrong number of stack entries");
} }
// describe monitors // describe monitors
assert(locks_begin <= locks_end, "error in scope iteration"); int nof_locks = cur_state->locks_size();
int nof_locks = locks_end - locks_begin;
if (nof_locks > 0) { if (nof_locks > 0) {
int lock_offset = cur_state->caller_state() != NULL ? cur_state->caller_state()->total_locks_size() : 0;
monitors = new GrowableArray<MonitorValue*>(nof_locks); monitors = new GrowableArray<MonitorValue*>(nof_locks);
for (int i = locks_begin; i < locks_end; i++) { for (int i = 0; i < nof_locks; i++) {
monitors->append(location_for_monitor_index(i)); monitors->append(location_for_monitor_index(lock_offset + i));
} }
} }
return new IRScopeDebugInfo(cur_scope, cur_bci, locals, expressions, monitors, caller_debug_info); return new IRScopeDebugInfo(cur_scope, cur_state->bci(), locals, expressions, monitors, caller_debug_info);
} }
...@@ -2850,17 +2840,14 @@ void LinearScan::compute_debug_info(CodeEmitInfo* info, int op_id) { ...@@ -2850,17 +2840,14 @@ void LinearScan::compute_debug_info(CodeEmitInfo* info, int op_id) {
assert(innermost_scope != NULL && innermost_state != NULL, "why is it missing?"); assert(innermost_scope != NULL && innermost_state != NULL, "why is it missing?");
int stack_end = innermost_state->stack_size(); DEBUG_ONLY(check_stack_depth(info, innermost_state->stack_size()));
int locks_end = innermost_state->locks_size();
DEBUG_ONLY(check_stack_depth(info, stack_end));
if (info->_scope_debug_info == NULL) { if (info->_scope_debug_info == NULL) {
// compute debug information // compute debug information
info->_scope_debug_info = compute_debug_info_for_scope(op_id, innermost_scope, innermost_state, innermost_state, info->bci(), stack_end, locks_end); info->_scope_debug_info = compute_debug_info_for_scope(op_id, innermost_scope, innermost_state, innermost_state);
} else { } else {
// debug information already set. Check that it is correct from the current point of view // debug information already set. Check that it is correct from the current point of view
DEBUG_ONLY(assert_equal(info->_scope_debug_info, compute_debug_info_for_scope(op_id, innermost_scope, innermost_state, innermost_state, info->bci(), stack_end, locks_end))); DEBUG_ONLY(assert_equal(info->_scope_debug_info, compute_debug_info_for_scope(op_id, innermost_scope, innermost_state, innermost_state)));
} }
} }
......
...@@ -346,7 +346,7 @@ class LinearScan : public CompilationResourceObj { ...@@ -346,7 +346,7 @@ class LinearScan : public CompilationResourceObj {
int append_scope_value_for_operand(LIR_Opr opr, GrowableArray<ScopeValue*>* scope_values); int append_scope_value_for_operand(LIR_Opr opr, GrowableArray<ScopeValue*>* scope_values);
int append_scope_value(int op_id, Value value, GrowableArray<ScopeValue*>* scope_values); int append_scope_value(int op_id, Value value, GrowableArray<ScopeValue*>* scope_values);
IRScopeDebugInfo* compute_debug_info_for_scope(int op_id, IRScope* cur_scope, ValueStack* cur_state, ValueStack* innermost_state, int cur_bci, int stack_end, int locks_end); IRScopeDebugInfo* compute_debug_info_for_scope(int op_id, IRScope* cur_scope, ValueStack* cur_state, ValueStack* innermost_state);
void compute_debug_info(CodeEmitInfo* info, int op_id); void compute_debug_info(CodeEmitInfo* info, int op_id);
void assign_reg_num(LIR_OpList* instructions, IntervalWalker* iw); void assign_reg_num(LIR_OpList* instructions, IntervalWalker* iw);
......
...@@ -140,25 +140,27 @@ class CE_Eliminator: public BlockClosure { ...@@ -140,25 +140,27 @@ class CE_Eliminator: public BlockClosure {
// with an IfOp followed by a Goto // with an IfOp followed by a Goto
// cut if_ away and get node before // cut if_ away and get node before
Instruction* cur_end = if_->prev(block); Instruction* cur_end = if_->prev(block);
int bci = if_->bci();
// append constants of true- and false-block if necessary // append constants of true- and false-block if necessary
// clone constants because original block must not be destroyed // clone constants because original block must not be destroyed
assert((t_value != f_const && f_value != t_const) || t_const == f_const, "mismatch"); assert((t_value != f_const && f_value != t_const) || t_const == f_const, "mismatch");
if (t_value == t_const) { if (t_value == t_const) {
t_value = new Constant(t_const->type()); t_value = new Constant(t_const->type());
cur_end = cur_end->set_next(t_value, bci); NOT_PRODUCT(t_value->set_printable_bci(if_->printable_bci()));
cur_end = cur_end->set_next(t_value);
} }
if (f_value == f_const) { if (f_value == f_const) {
f_value = new Constant(f_const->type()); f_value = new Constant(f_const->type());
cur_end = cur_end->set_next(f_value, bci); NOT_PRODUCT(f_value->set_printable_bci(if_->printable_bci()));
cur_end = cur_end->set_next(f_value);
} }
// it is very unlikely that the condition can be statically decided // it is very unlikely that the condition can be statically decided
// (this was checked previously by the Canonicalizer), so always // (this was checked previously by the Canonicalizer), so always
// append IfOp // append IfOp
Value result = new IfOp(if_->x(), if_->cond(), if_->y(), t_value, f_value); Value result = new IfOp(if_->x(), if_->cond(), if_->y(), t_value, f_value);
cur_end = cur_end->set_next(result, bci); NOT_PRODUCT(result->set_printable_bci(if_->printable_bci()));
cur_end = cur_end->set_next(result);
// append Goto to successor // append Goto to successor
ValueStack* state_before = if_->is_safepoint() ? if_->state_before() : NULL; ValueStack* state_before = if_->is_safepoint() ? if_->state_before() : NULL;
...@@ -167,16 +169,15 @@ class CE_Eliminator: public BlockClosure { ...@@ -167,16 +169,15 @@ class CE_Eliminator: public BlockClosure {
// prepare state for Goto // prepare state for Goto
ValueStack* goto_state = if_->state(); ValueStack* goto_state = if_->state();
while (sux_state->scope() != goto_state->scope()) { while (sux_state->scope() != goto_state->scope()) {
goto_state = goto_state->pop_scope(); goto_state = goto_state->caller_state();
assert(goto_state != NULL, "states do not match up"); assert(goto_state != NULL, "states do not match up");
} }
goto_state = goto_state->copy(); goto_state = goto_state->copy(ValueStack::StateAfter, goto_state->bci());
goto_state->push(result->type(), result); goto_state->push(result->type(), result);
assert(goto_state->is_same_across_scopes(sux_state), "states must match now"); assert(goto_state->is_same(sux_state), "states must match now");
goto_->set_state(goto_state); goto_->set_state(goto_state);
// Steal the bci for the goto from the sux cur_end = cur_end->set_next(goto_, goto_state->bci());
cur_end = cur_end->set_next(goto_, sux->bci());
// Adjust control flow graph // Adjust control flow graph
BlockBegin::disconnect_edge(block, t_block); BlockBegin::disconnect_edge(block, t_block);
...@@ -251,10 +252,8 @@ class BlockMerger: public BlockClosure { ...@@ -251,10 +252,8 @@ class BlockMerger: public BlockClosure {
// no phi functions must be present at beginning of sux // no phi functions must be present at beginning of sux
ValueStack* sux_state = sux->state(); ValueStack* sux_state = sux->state();
ValueStack* end_state = end->state(); ValueStack* end_state = end->state();
while (end_state->scope() != sux_state->scope()) {
// match up inlining level assert(end_state->scope() == sux_state->scope(), "scopes must match");
end_state = end_state->pop_scope();
}
assert(end_state->stack_size() == sux_state->stack_size(), "stack not equal"); assert(end_state->stack_size() == sux_state->stack_size(), "stack not equal");
assert(end_state->locals_size() == sux_state->locals_size(), "locals not equal"); assert(end_state->locals_size() == sux_state->locals_size(), "locals not equal");
...@@ -273,7 +272,7 @@ class BlockMerger: public BlockClosure { ...@@ -273,7 +272,7 @@ class BlockMerger: public BlockClosure {
Instruction* prev = end->prev(block); Instruction* prev = end->prev(block);
Instruction* next = sux->next(); Instruction* next = sux->next();
assert(prev->as_BlockEnd() == NULL, "must not be a BlockEnd"); assert(prev->as_BlockEnd() == NULL, "must not be a BlockEnd");
prev->set_next(next, next->bci()); prev->set_next(next);
sux->disconnect_from_graph(); sux->disconnect_from_graph();
block->set_end(sux->end()); block->set_end(sux->end());
// add exception handlers of deleted block, if any // add exception handlers of deleted block, if any
...@@ -337,7 +336,8 @@ class BlockMerger: public BlockClosure { ...@@ -337,7 +336,8 @@ class BlockMerger: public BlockClosure {
newif->set_state(if_->state()->copy()); newif->set_state(if_->state()->copy());
assert(prev->next() == if_, "must be guaranteed by above search"); assert(prev->next() == if_, "must be guaranteed by above search");
prev->set_next(newif, if_->bci()); NOT_PRODUCT(newif->set_printable_bci(if_->printable_bci()));
prev->set_next(newif);
block->set_end(newif); block->set_end(newif);
_merge_count++; _merge_count++;
...@@ -705,7 +705,7 @@ void NullCheckEliminator::iterate_one(BlockBegin* block) { ...@@ -705,7 +705,7 @@ void NullCheckEliminator::iterate_one(BlockBegin* block) {
// visiting instructions which are references in other blocks or // visiting instructions which are references in other blocks or
// visiting instructions more than once. // visiting instructions more than once.
mark_visitable(instr); mark_visitable(instr);
if (instr->is_root() || instr->can_trap() || (instr->as_NullCheck() != NULL)) { if (instr->is_pinned() || instr->can_trap() || (instr->as_NullCheck() != NULL)) {
mark_visited(instr); mark_visited(instr);
instr->input_values_do(this); instr->input_values_do(this);
instr->visit(&_visitor); instr->visit(&_visitor);
......
...@@ -28,55 +28,60 @@ ...@@ -28,55 +28,60 @@
// Implementation of ValueStack // Implementation of ValueStack
ValueStack::ValueStack(IRScope* scope, int locals_size, int max_stack_size) ValueStack::ValueStack(IRScope* scope, ValueStack* caller_state)
: _scope(scope) : _scope(scope)
, _locals(locals_size, NULL) , _caller_state(caller_state)
, _stack(max_stack_size) , _bci(-99)
, _lock_stack(false) , _kind(Parsing)
, _locks(1) , _locals(scope->method()->max_locals(), NULL)
, _stack(scope->method()->max_stack())
, _locks()
{ {
assert(scope != NULL, "scope must exist"); verify();
}
ValueStack* ValueStack::copy() {
ValueStack* s = new ValueStack(scope(), locals_size(), max_stack_size());
s->_stack.appendAll(&_stack);
s->_locks.appendAll(&_locks);
s->replace_locals(this);
return s;
} }
ValueStack* ValueStack::copy_locks() { ValueStack::ValueStack(ValueStack* copy_from, Kind kind, int bci)
int sz = scope()->lock_stack_size(); : _scope(copy_from->scope())
if (stack_size() == 0) { , _caller_state(copy_from->caller_state())
sz = 0; , _bci(bci)
, _kind(kind)
, _locals()
, _stack()
, _locks(copy_from->locks_size())
{
assert(kind != EmptyExceptionState || !Compilation::current()->env()->jvmti_can_access_local_variables(), "need locals");
if (kind != EmptyExceptionState) {
// only allocate space if we need to copy the locals-array
_locals = Values(copy_from->locals_size());
_locals.appendAll(&copy_from->_locals);
} }
ValueStack* s = new ValueStack(scope(), locals_size(), sz);
s->_lock_stack = true; if (kind != ExceptionState && kind != EmptyExceptionState) {
s->_locks.appendAll(&_locks); if (kind == Parsing) {
s->replace_locals(this); // stack will be modified, so reserve enough space to avoid resizing
if (sz > 0) { _stack = Values(scope()->method()->max_stack());
assert(sz <= stack_size(), "lock stack underflow"); } else {
for (int i = 0; i < sz; i++) { // stack will not be modified, so do not waste space
s->_stack.append(_stack[i]); _stack = Values(copy_from->stack_size());
} }
_stack.appendAll(&copy_from->_stack);
} }
return s;
_locks.appendAll(&copy_from->_locks);
verify();
} }
bool ValueStack::is_same(ValueStack* s) { bool ValueStack::is_same(ValueStack* s) {
assert(s != NULL, "state must exist"); if (scope() != s->scope()) return false;
assert(scope () == s->scope (), "scopes must correspond"); if (caller_state() != s->caller_state()) return false;
assert(locals_size() == s->locals_size(), "locals sizes must correspond");
return is_same_across_scopes(s);
}
if (locals_size() != s->locals_size()) return false;
if (stack_size() != s->stack_size()) return false;
if (locks_size() != s->locks_size()) return false;
bool ValueStack::is_same_across_scopes(ValueStack* s) {
assert(s != NULL, "state must exist");
assert(stack_size () == s->stack_size (), "stack sizes must correspond");
assert(locks_size () == s->locks_size (), "locks sizes must correspond");
// compare each stack element with the corresponding stack element of s // compare each stack element with the corresponding stack element of s
int index; int index;
Value value; Value value;
...@@ -89,12 +94,6 @@ bool ValueStack::is_same_across_scopes(ValueStack* s) { ...@@ -89,12 +94,6 @@ bool ValueStack::is_same_across_scopes(ValueStack* s) {
return true; return true;
} }
ValueStack* ValueStack::caller_state() const {
return scope()->caller_state();
}
void ValueStack::clear_locals() { void ValueStack::clear_locals() {
for (int i = _locals.length() - 1; i >= 0; i--) { for (int i = _locals.length() - 1; i >= 0; i--) {
_locals.at_put(i, NULL); _locals.at_put(i, NULL);
...@@ -102,13 +101,6 @@ void ValueStack::clear_locals() { ...@@ -102,13 +101,6 @@ void ValueStack::clear_locals() {
} }
void ValueStack::replace_locals(ValueStack* with) {
assert(locals_size() == with->locals_size(), "number of locals must match");
for (int i = locals_size() - 1; i >= 0; i--) {
_locals.at_put(i, with->_locals.at(i));
}
}
void ValueStack::pin_stack_for_linear_scan() { void ValueStack::pin_stack_for_linear_scan() {
for_each_state_value(this, v, for_each_state_value(this, v,
if (v->as_Constant() == NULL && v->as_Local() == NULL) { if (v->as_Constant() == NULL && v->as_Local() == NULL) {
...@@ -123,33 +115,25 @@ void ValueStack::apply(Values list, ValueVisitor* f) { ...@@ -123,33 +115,25 @@ void ValueStack::apply(Values list, ValueVisitor* f) {
for (int i = 0; i < list.length(); i++) { for (int i = 0; i < list.length(); i++) {
Value* va = list.adr_at(i); Value* va = list.adr_at(i);
Value v0 = *va; Value v0 = *va;
if (v0 != NULL) { if (v0 != NULL && !v0->type()->is_illegal()) {
if (!v0->type()->is_illegal()) {
assert(v0->as_HiWord() == NULL, "should never see HiWord during traversal");
f->visit(va); f->visit(va);
#ifdef ASSERT #ifdef ASSERT
Value v1 = *va; Value v1 = *va;
if (v0 != v1) {
assert(v1->type()->is_illegal() || v0->type()->tag() == v1->type()->tag(), "types must match"); assert(v1->type()->is_illegal() || v0->type()->tag() == v1->type()->tag(), "types must match");
if (v0->type()->is_double_word()) { assert(!v1->type()->is_double_word() || list.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
list.at_put(i + 1, v0->hi_word());
}
}
#endif #endif
if (v0->type()->is_double_word()) i++; if (v0->type()->is_double_word()) i++;
} }
} }
}
} }
void ValueStack::values_do(ValueVisitor* f) { void ValueStack::values_do(ValueVisitor* f) {
apply(_stack, f);
apply(_locks, f);
ValueStack* state = this; ValueStack* state = this;
for_each_state(state) { for_each_state(state) {
apply(state->_locals, f); apply(state->_locals, f);
apply(state->_stack, f);
apply(state->_locks, f);
} }
} }
...@@ -164,52 +148,26 @@ Values* ValueStack::pop_arguments(int argument_size) { ...@@ -164,52 +148,26 @@ Values* ValueStack::pop_arguments(int argument_size) {
} }
int ValueStack::lock(IRScope* scope, Value obj) { int ValueStack::total_locks_size() const {
int num_locks = 0;
const ValueStack* state = this;
for_each_state(state) {
num_locks += state->locks_size();
}
return num_locks;
}
int ValueStack::lock(Value obj) {
_locks.push(obj); _locks.push(obj);
scope->set_min_number_of_locks(locks_size()); int num_locks = total_locks_size();
return locks_size() - 1; scope()->set_min_number_of_locks(num_locks);
return num_locks - 1;
} }
int ValueStack::unlock() { int ValueStack::unlock() {
_locks.pop(); _locks.pop();
return locks_size(); return total_locks_size();
}
ValueStack* ValueStack::push_scope(IRScope* scope) {
assert(scope->caller() == _scope, "scopes must have caller/callee relationship");
ValueStack* res = new ValueStack(scope,
scope->method()->max_locals(),
max_stack_size() + scope->method()->max_stack());
// Preserves stack and monitors.
res->_stack.appendAll(&_stack);
res->_locks.appendAll(&_locks);
assert(res->_stack.size() <= res->max_stack_size(), "stack overflow");
return res;
}
ValueStack* ValueStack::pop_scope() {
assert(_scope->caller() != NULL, "scope must have caller");
IRScope* scope = _scope->caller();
int max_stack = max_stack_size() - _scope->method()->max_stack();
assert(max_stack >= 0, "stack underflow");
ValueStack* res = new ValueStack(scope,
scope->method()->max_locals(),
max_stack);
// Preserves stack and monitors. Restores local and store state from caller scope.
res->_stack.appendAll(&_stack);
res->_locks.appendAll(&_locks);
ValueStack* caller = caller_state();
if (caller != NULL) {
for (int i = 0; i < caller->_locals.length(); i++) {
res->_locals.at_put(i, caller->_locals.at(i));
}
assert(res->_locals.length() == res->scope()->method()->max_locals(), "just checking");
}
assert(res->_stack.size() <= res->max_stack_size(), "stack overflow");
return res;
} }
...@@ -220,11 +178,7 @@ void ValueStack::setup_phi_for_stack(BlockBegin* b, int index) { ...@@ -220,11 +178,7 @@ void ValueStack::setup_phi_for_stack(BlockBegin* b, int index) {
Value phi = new Phi(t, b, -index - 1); Value phi = new Phi(t, b, -index - 1);
_stack[index] = phi; _stack[index] = phi;
#ifdef ASSERT assert(!t->is_double_word() || _stack.at(index + 1) == NULL, "hi-word of doubleword value must be NULL");
if (t->is_double_word()) {
_stack[index + 1] = phi->hi_word();
}
#endif
} }
void ValueStack::setup_phi_for_local(BlockBegin* b, int index) { void ValueStack::setup_phi_for_local(BlockBegin* b, int index) {
...@@ -236,7 +190,9 @@ void ValueStack::setup_phi_for_local(BlockBegin* b, int index) { ...@@ -236,7 +190,9 @@ void ValueStack::setup_phi_for_local(BlockBegin* b, int index) {
} }
#ifndef PRODUCT #ifndef PRODUCT
void ValueStack::print() { void ValueStack::print() {
scope()->method()->print_name();
if (stack_is_empty()) { if (stack_is_empty()) {
tty->print_cr("empty stack"); tty->print_cr("empty stack");
} else { } else {
...@@ -244,18 +200,20 @@ void ValueStack::print() { ...@@ -244,18 +200,20 @@ void ValueStack::print() {
for (int i = 0; i < stack_size();) { for (int i = 0; i < stack_size();) {
Value t = stack_at_inc(i); Value t = stack_at_inc(i);
tty->print("%2d ", i); tty->print("%2d ", i);
tty->print("%c%d ", t->type()->tchar(), t->id());
ip.print_instr(t); ip.print_instr(t);
tty->cr(); tty->cr();
} }
} }
if (!no_active_locks()) { if (!no_active_locks()) {
InstructionPrinter ip; InstructionPrinter ip;
for (int i = 0; i < locks_size(); i--) { for (int i = 0; i < locks_size(); i++) {
Value t = lock_at(i); Value t = lock_at(i);
tty->print("lock %2d ", i); tty->print("lock %2d ", i);
if (t == NULL) { if (t == NULL) {
tty->print("this"); tty->print("this");
} else { } else {
tty->print("%c%d ", t->type()->tchar(), t->id());
ip.print_instr(t); ip.print_instr(t);
} }
tty->cr(); tty->cr();
...@@ -270,16 +228,55 @@ void ValueStack::print() { ...@@ -270,16 +228,55 @@ void ValueStack::print() {
tty->print("null"); tty->print("null");
i ++; i ++;
} else { } else {
tty->print("%c%d ", l->type()->tchar(), l->id());
ip.print_instr(l); ip.print_instr(l);
if (l->type()->is_illegal() || l->type()->is_single_word()) i ++; else i += 2; if (l->type()->is_illegal() || l->type()->is_single_word()) i ++; else i += 2;
} }
tty->cr(); tty->cr();
} }
} }
if (caller_state() != NULL) {
caller_state()->print();
}
} }
void ValueStack::verify() { void ValueStack::verify() {
Unimplemented(); assert(scope() != NULL, "scope must exist");
if (caller_state() != NULL) {
assert(caller_state()->scope() == scope()->caller(), "invalid caller scope");
caller_state()->verify();
}
if (kind() == Parsing) {
assert(bci() == -99, "bci not defined during parsing");
} else {
assert(bci() >= -1, "bci out of range");
assert(bci() < scope()->method()->code_size(), "bci out of range");
assert(bci() == SynchronizationEntryBCI || Bytecodes::is_defined(scope()->method()->java_code_at_bci(bci())), "make sure bci points at a real bytecode");
assert(scope()->method()->liveness_at_bci(bci()).is_valid(), "liveness at bci must be valid");
}
int i;
for (i = 0; i < stack_size(); i++) {
Value v = _stack.at(i);
if (v == NULL) {
assert(_stack.at(i - 1)->type()->is_double_word(), "only hi-words are NULL on stack");
} else if (v->type()->is_double_word()) {
assert(_stack.at(i + 1) == NULL, "hi-word must be NULL");
}
}
for (i = 0; i < locals_size(); i++) {
Value v = _locals.at(i);
if (v != NULL && v->type()->is_double_word()) {
assert(_locals.at(i + 1) == NULL, "hi-word must be NULL");
}
}
for_each_state_value(this, v,
assert(v != NULL, "just test if state-iteration succeeds");
);
} }
#endif // PRODUCT #endif // PRODUCT
...@@ -23,9 +23,23 @@ ...@@ -23,9 +23,23 @@
*/ */
class ValueStack: public CompilationResourceObj { class ValueStack: public CompilationResourceObj {
public:
enum Kind {
Parsing, // During abstract interpretation in GraphBuilder
CallerState, // Caller state when inlining
StateBefore, // Before before execution of instruction
StateAfter, // After execution of instruction
ExceptionState, // Exception handling of instruction
EmptyExceptionState, // Exception handling of instructions not covered by an xhandler
BlockBeginState // State of BlockBegin instruction with phi functions of this block
};
private: private:
IRScope* _scope; // the enclosing scope IRScope* _scope; // the enclosing scope
bool _lock_stack; // indicates that this ValueStack is for an exception site ValueStack* _caller_state;
int _bci;
Kind _kind;
Values _locals; // the locals Values _locals; // the locals
Values _stack; // the expression stack Values _stack; // the expression stack
Values _locks; // the monitor stack (holding the locked values) Values _locks; // the monitor stack (holding the locked values)
...@@ -36,100 +50,79 @@ class ValueStack: public CompilationResourceObj { ...@@ -36,100 +50,79 @@ class ValueStack: public CompilationResourceObj {
} }
Value check(ValueTag tag, Value t, Value h) { Value check(ValueTag tag, Value t, Value h) {
assert(h->as_HiWord()->lo_word() == t, "incorrect stack pair"); assert(h == NULL, "hi-word of doubleword value must be NULL");
return check(tag, t); return check(tag, t);
} }
// helper routine // helper routine
static void apply(Values list, ValueVisitor* f); static void apply(Values list, ValueVisitor* f);
// for simplified copying
ValueStack(ValueStack* copy_from, Kind kind, int bci);
public: public:
// creation // creation
ValueStack(IRScope* scope, int locals_size, int max_stack_size); ValueStack(IRScope* scope, ValueStack* caller_state);
// merging ValueStack* copy() { return new ValueStack(this, _kind, _bci); }
ValueStack* copy(); // returns a copy of this w/ cleared locals ValueStack* copy(Kind new_kind, int new_bci) { return new ValueStack(this, new_kind, new_bci); }
ValueStack* copy_locks(); // returns a copy of this w/ cleared locals and stack ValueStack* copy_for_parsing() { return new ValueStack(this, Parsing, -99); }
// Note that when inlining of methods with exception
// handlers is enabled, this stack may have a void set_caller_state(ValueStack* s) { assert(kind() == EmptyExceptionState, "only EmptyExceptionStates can be modified"); _caller_state = s; }
// non-empty expression stack (size defined by
// scope()->lock_stack_size())
bool is_same(ValueStack* s); // returns true if this & s's types match (w/o checking locals) bool is_same(ValueStack* s); // returns true if this & s's types match (w/o checking locals)
bool is_same_across_scopes(ValueStack* s); // same as is_same but returns true even if stacks are in different scopes (used for block merging w/inlining)
// accessors // accessors
IRScope* scope() const { return _scope; } IRScope* scope() const { return _scope; }
bool is_lock_stack() const { return _lock_stack; } ValueStack* caller_state() const { return _caller_state; }
int bci() const { return _bci; }
Kind kind() const { return _kind; }
int locals_size() const { return _locals.length(); } int locals_size() const { return _locals.length(); }
int stack_size() const { return _stack.length(); } int stack_size() const { return _stack.length(); }
int locks_size() const { return _locks.length(); } int locks_size() const { return _locks.length(); }
int max_stack_size() const { return _stack.capacity(); }
bool stack_is_empty() const { return _stack.is_empty(); } bool stack_is_empty() const { return _stack.is_empty(); }
bool no_active_locks() const { return _locks.is_empty(); } bool no_active_locks() const { return _locks.is_empty(); }
ValueStack* caller_state() const; int total_locks_size() const;
// locals access // locals access
void clear_locals(); // sets all locals to NULL; void clear_locals(); // sets all locals to NULL;
// Kill local i. Also kill local i+1 if i was a long or double.
void invalidate_local(int i) { void invalidate_local(int i) {
Value x = _locals.at(i); assert(_locals.at(i)->type()->is_single_word() ||
if (x != NULL && x->type()->is_double_word()) { _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
assert(_locals.at(i + 1)->as_HiWord()->lo_word() == x, "locals inconsistent");
_locals.at_put(i + 1, NULL);
}
_locals.at_put(i, NULL); _locals.at_put(i, NULL);
} }
Value local_at(int i) const {
Value load_local(int i) const {
Value x = _locals.at(i); Value x = _locals.at(i);
if (x != NULL && x->type()->is_illegal()) return NULL; assert(x == NULL || x->type()->is_single_word() ||
assert(x == NULL || x->as_HiWord() == NULL, "index points to hi word"); _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
assert(x == NULL || x->type()->is_illegal() || x->type()->is_single_word() || x == _locals.at(i+1)->as_HiWord()->lo_word(), "locals inconsistent");
return x; return x;
} }
Value local_at(int i) const { return _locals.at(i); }
// Store x into local i.
void store_local(int i, Value x) { void store_local(int i, Value x) {
// Kill the old value // When overwriting local i, check if i - 1 was the start of a
invalidate_local(i); // double word local and kill it.
_locals.at_put(i, x);
// Writing a double word can kill other locals
if (x != NULL && x->type()->is_double_word()) {
// If x + i was the start of a double word local then kill i + 2.
Value x2 = _locals.at(i + 1);
if (x2 != NULL && x2->type()->is_double_word()) {
_locals.at_put(i + 2, NULL);
}
// If x is a double word local, also update i + 1.
#ifdef ASSERT
_locals.at_put(i + 1, x->hi_word());
#else
_locals.at_put(i + 1, NULL);
#endif
}
// If x - 1 was the start of a double word local then kill i - 1.
if (i > 0) { if (i > 0) {
Value prev = _locals.at(i - 1); Value prev = _locals.at(i - 1);
if (prev != NULL && prev->type()->is_double_word()) { if (prev != NULL && prev->type()->is_double_word()) {
_locals.at_put(i - 1, NULL); _locals.at_put(i - 1, NULL);
} }
} }
}
void replace_locals(ValueStack* with); _locals.at_put(i, x);
if (x->type()->is_double_word()) {
// hi-word of doubleword value is always NULL
_locals.at_put(i + 1, NULL);
}
}
// stack access // stack access
Value stack_at(int i) const { Value stack_at(int i) const {
Value x = _stack.at(i); Value x = _stack.at(i);
assert(x->as_HiWord() == NULL, "index points to hi word");
assert(x->type()->is_single_word() || assert(x->type()->is_single_word() ||
x->subst() == _stack.at(i+1)->as_HiWord()->lo_word(), "stack inconsistent"); _stack.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
return x; return x;
} }
...@@ -146,7 +139,6 @@ class ValueStack: public CompilationResourceObj { ...@@ -146,7 +139,6 @@ class ValueStack: public CompilationResourceObj {
void values_do(ValueVisitor* f); void values_do(ValueVisitor* f);
// untyped manipulation (for dup_x1, etc.) // untyped manipulation (for dup_x1, etc.)
void clear_stack() { _stack.clear(); }
void truncate_stack(int size) { _stack.trunc_to(size); } void truncate_stack(int size) { _stack.trunc_to(size); }
void raw_push(Value t) { _stack.push(t); } void raw_push(Value t) { _stack.push(t); }
Value raw_pop() { return _stack.pop(); } Value raw_pop() { return _stack.pop(); }
...@@ -156,15 +148,8 @@ class ValueStack: public CompilationResourceObj { ...@@ -156,15 +148,8 @@ class ValueStack: public CompilationResourceObj {
void fpush(Value t) { _stack.push(check(floatTag , t)); } void fpush(Value t) { _stack.push(check(floatTag , t)); }
void apush(Value t) { _stack.push(check(objectTag , t)); } void apush(Value t) { _stack.push(check(objectTag , t)); }
void rpush(Value t) { _stack.push(check(addressTag, t)); } void rpush(Value t) { _stack.push(check(addressTag, t)); }
#ifdef ASSERT
// in debug mode, use HiWord for 2-word values
void lpush(Value t) { _stack.push(check(longTag , t)); _stack.push(new HiWord(t)); }
void dpush(Value t) { _stack.push(check(doubleTag , t)); _stack.push(new HiWord(t)); }
#else
// in optimized mode, use NULL for 2-word values
void lpush(Value t) { _stack.push(check(longTag , t)); _stack.push(NULL); } void lpush(Value t) { _stack.push(check(longTag , t)); _stack.push(NULL); }
void dpush(Value t) { _stack.push(check(doubleTag , t)); _stack.push(NULL); } void dpush(Value t) { _stack.push(check(doubleTag , t)); _stack.push(NULL); }
#endif // ASSERT
void push(ValueType* type, Value t) { void push(ValueType* type, Value t) {
switch (type->tag()) { switch (type->tag()) {
...@@ -182,15 +167,8 @@ class ValueStack: public CompilationResourceObj { ...@@ -182,15 +167,8 @@ class ValueStack: public CompilationResourceObj {
Value fpop() { return check(floatTag , _stack.pop()); } Value fpop() { return check(floatTag , _stack.pop()); }
Value apop() { return check(objectTag , _stack.pop()); } Value apop() { return check(objectTag , _stack.pop()); }
Value rpop() { return check(addressTag, _stack.pop()); } Value rpop() { return check(addressTag, _stack.pop()); }
#ifdef ASSERT
// in debug mode, check for HiWord consistency
Value lpop() { Value h = _stack.pop(); return check(longTag , _stack.pop(), h); } Value lpop() { Value h = _stack.pop(); return check(longTag , _stack.pop(), h); }
Value dpop() { Value h = _stack.pop(); return check(doubleTag, _stack.pop(), h); } Value dpop() { Value h = _stack.pop(); return check(doubleTag, _stack.pop(), h); }
#else
// in optimized mode, ignore HiWord since it is NULL
Value lpop() { _stack.pop(); return check(longTag , _stack.pop()); }
Value dpop() { _stack.pop(); return check(doubleTag, _stack.pop()); }
#endif // ASSERT
Value pop(ValueType* type) { Value pop(ValueType* type) {
switch (type->tag()) { switch (type->tag()) {
...@@ -208,16 +186,10 @@ class ValueStack: public CompilationResourceObj { ...@@ -208,16 +186,10 @@ class ValueStack: public CompilationResourceObj {
Values* pop_arguments(int argument_size); Values* pop_arguments(int argument_size);
// locks access // locks access
int lock (IRScope* scope, Value obj); int lock (Value obj);
int unlock(); int unlock();
Value lock_at(int i) const { return _locks.at(i); } Value lock_at(int i) const { return _locks.at(i); }
// Inlining support
ValueStack* push_scope(IRScope* scope); // "Push" new scope, returning new resulting stack
// Preserves stack and locks, destroys locals
ValueStack* pop_scope(); // "Pop" topmost scope, returning new resulting stack
// Preserves stack and locks, destroys locals
// SSA form IR support // SSA form IR support
void setup_phi_for_stack(BlockBegin* b, int index); void setup_phi_for_stack(BlockBegin* b, int index);
void setup_phi_for_local(BlockBegin* b, int index); void setup_phi_for_local(BlockBegin* b, int index);
...@@ -299,16 +271,18 @@ class ValueStack: public CompilationResourceObj { ...@@ -299,16 +271,18 @@ class ValueStack: public CompilationResourceObj {
int cur_index; \ int cur_index; \
ValueStack* cur_state = v_state; \ ValueStack* cur_state = v_state; \
Value v_value; \ Value v_value; \
for_each_state(cur_state) { \
{ \ { \
for_each_stack_value(cur_state, cur_index, v_value) { \ for_each_local_value(cur_state, cur_index, v_value) { \
v_code; \ v_code; \
} \ } \
} \ } \
for_each_state(cur_state) { \ { \
for_each_local_value(cur_state, cur_index, v_value) { \ for_each_stack_value(cur_state, cur_index, v_value) { \
v_code; \ v_code; \
} \ } \
} \ } \
} \
} }
......
...@@ -216,9 +216,6 @@ ...@@ -216,9 +216,6 @@
develop(bool, DeoptC1, true, \ develop(bool, DeoptC1, true, \
"Use deoptimization in C1") \ "Use deoptimization in C1") \
\ \
develop(bool, DeoptOnAsyncException, true, \
"Deoptimize upon Thread.stop(); improves precision of IR") \
\
develop(bool, PrintBailouts, false, \ develop(bool, PrintBailouts, false, \
"Print bailout and its reason") \ "Print bailout and its reason") \
\ \
......
...@@ -448,3 +448,7 @@ thread.cpp c1_Compiler.hpp ...@@ -448,3 +448,7 @@ thread.cpp c1_Compiler.hpp
top.hpp c1_globals.hpp top.hpp c1_globals.hpp
vmStructs.hpp c1_Runtime1.hpp vmStructs.hpp c1_Runtime1.hpp
c1_Canonicalizer.cpp c1_ValueStack.hpp
c1_LIR.cpp c1_ValueStack.hpp
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册