Save full source position state to avoid forced positions.

Review URL: http://codereview.chromium.org/5277008

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5908 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
vitalyr@chromium.org 2010-11-30 13:17:36 +00:00
parent 2f74ca3b6d
commit b0e4479e70
7 changed files with 86 additions and 92 deletions

View File

@ -1691,14 +1691,14 @@ void FullCodeGenerator::EmitCallWithIC(Call* expr,
// Code common for calls using the IC.
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
for (int i = 0; i < arg_count; i++) {
VisitForStackValue(args->at(i));
}
__ mov(r2, Operand(name));
}
// Record source position for debugger.
SetSourcePosition(expr->position(), FORCED_POSITION);
SetSourcePosition(expr->position());
// Call the IC initialization code.
InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
Handle<Code> ic = StubCache::ComputeCallInitialize(arg_count, in_loop);
@ -1724,13 +1724,13 @@ void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr,
// Code common for calls using the IC.
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
for (int i = 0; i < arg_count; i++) {
VisitForStackValue(args->at(i));
}
}
// Record source position for debugger.
SetSourcePosition(expr->position(), FORCED_POSITION);
SetSourcePosition(expr->position());
// Call the IC initialization code.
InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
Handle<Code> ic = StubCache::ComputeKeyedCallInitialize(arg_count, in_loop);
@ -1746,13 +1746,13 @@ void FullCodeGenerator::EmitCallWithStub(Call* expr) {
// Code common for calls using the call stub.
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
for (int i = 0; i < arg_count; i++) {
VisitForStackValue(args->at(i));
}
}
// Record source position for debugger.
SetSourcePosition(expr->position(), FORCED_POSITION);
SetSourcePosition(expr->position());
InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE);
__ CallStub(&stub);
@ -1775,7 +1775,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
{ PreserveStatementPositionScope pos_scope(masm()->positions_recorder());
{ PreservePositionScope pos_scope(masm()->positions_recorder());
VisitForStackValue(fun);
__ LoadRoot(r2, Heap::kUndefinedValueRootIndex);
__ push(r2); // Reserved receiver slot.
@ -1810,7 +1810,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
}
// Record source position for debugger.
SetSourcePosition(expr->position(), FORCED_POSITION);
SetSourcePosition(expr->position());
InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE);
__ CallStub(&stub);
@ -1827,7 +1827,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
// Call to a lookup slot (dynamically introduced variable).
Label slow, done;
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
// Generate code for loading from variables potentially shadowed
// by eval-introduced variables.
EmitDynamicLoadFromSlotFastCase(var->AsSlot(),
@ -1868,7 +1868,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
Literal* key = prop->key()->AsLiteral();
if (key != NULL && key->handle()->IsSymbol()) {
// Call to a named property, use call IC.
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
VisitForStackValue(prop->obj());
}
EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET);
@ -1876,15 +1876,15 @@ void FullCodeGenerator::VisitCall(Call* expr) {
// Call to a keyed property.
// For a synthetic property use keyed load IC followed by function call,
// for a regular property use keyed CallIC.
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
VisitForStackValue(prop->obj());
}
if (prop->is_synthetic()) {
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
VisitForAccumulatorValue(prop->key());
}
// Record source code position for IC call.
SetSourcePosition(prop->position(), FORCED_POSITION);
SetSourcePosition(prop->position());
__ pop(r1); // We do not need to keep the receiver.
Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize));
@ -1908,7 +1908,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
lit->set_try_full_codegen(true);
}
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
VisitForStackValue(fun);
}
// Load global receiver object.

View File

@ -801,19 +801,17 @@ ExternalReference ExternalReference::debug_step_in_fp_address() {
#endif
void PositionsRecorder::RecordPosition(int pos,
PositionRecordingType recording_type) {
void PositionsRecorder::RecordPosition(int pos) {
ASSERT(pos != RelocInfo::kNoPosition);
ASSERT(pos >= 0);
current_position_ = pos;
current_position_recording_type_ = recording_type;
state_.current_position = pos;
}
void PositionsRecorder::RecordStatementPosition(int pos) {
ASSERT(pos != RelocInfo::kNoPosition);
ASSERT(pos >= 0);
current_statement_position_ = pos;
state_.current_statement_position = pos;
}
@ -822,31 +820,26 @@ bool PositionsRecorder::WriteRecordedPositions() {
// Write the statement position if it is different from what was written last
// time.
if (current_statement_position_ != written_statement_position_) {
if (state_.current_statement_position != state_.written_statement_position) {
EnsureSpace ensure_space(assembler_);
assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION,
current_statement_position_);
written_statement_position_ = current_statement_position_;
state_.current_statement_position);
state_.written_statement_position = state_.current_statement_position;
written = true;
}
// Write the position if it is different from what was written last time and
// also different from the written statement position or was forced.
if (current_position_ != written_position_ &&
(current_position_ != current_statement_position_ || !written) &&
(current_position_ != written_statement_position_
|| current_position_recording_type_ == FORCED_POSITION)) {
// also different from the written statement position.
if (state_.current_position != state_.written_position &&
state_.current_position != state_.written_statement_position) {
EnsureSpace ensure_space(assembler_);
assembler_->RecordRelocInfo(RelocInfo::POSITION, current_position_);
written_position_ = current_position_;
assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position);
state_.written_position = state_.current_position;
written = true;
}
current_position_recording_type_ = NORMAL_POSITION;
// Return whether something was written.
return written;
}
} } // namespace v8::internal

View File

@ -587,23 +587,27 @@ class ExternalReference BASE_EMBEDDED {
// -----------------------------------------------------------------------------
// Position recording support
enum PositionRecordingType { FORCED_POSITION, NORMAL_POSITION };
struct PositionState {
PositionState() : current_position(RelocInfo::kNoPosition),
written_position(RelocInfo::kNoPosition),
current_statement_position(RelocInfo::kNoPosition),
written_statement_position(RelocInfo::kNoPosition) {}
int current_position;
int written_position;
int current_statement_position;
int written_statement_position;
};
class PositionsRecorder BASE_EMBEDDED {
public:
explicit PositionsRecorder(Assembler* assembler)
: assembler_(assembler),
current_position_(RelocInfo::kNoPosition),
current_position_recording_type_(NORMAL_POSITION),
written_position_(RelocInfo::kNoPosition),
current_statement_position_(RelocInfo::kNoPosition),
written_statement_position_(RelocInfo::kNoPosition) { }
: assembler_(assembler) {}
// Set current position to pos. If recording_type is FORCED_POSITION then
// WriteRecordedPositions will write this position even if it is equal to
// statement position previously written for another pc.
void RecordPosition(int pos,
PositionRecordingType recording_type = NORMAL_POSITION);
// Set current position to pos.
void RecordPosition(int pos);
// Set current statement position to pos.
void RecordStatementPosition(int pos);
@ -611,37 +615,37 @@ class PositionsRecorder BASE_EMBEDDED {
// Write recorded positions to relocation information.
bool WriteRecordedPositions();
int current_position() const { return current_position_; }
int current_position() const { return state_.current_position; }
int current_statement_position() const { return current_statement_position_; }
int current_statement_position() const {
return state_.current_statement_position;
}
private:
Assembler* assembler_;
PositionState state_;
int current_position_;
PositionRecordingType current_position_recording_type_;
int written_position_;
friend class PreservePositionScope;
int current_statement_position_;
int written_statement_position_;
DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
};
class PreserveStatementPositionScope BASE_EMBEDDED {
class PreservePositionScope BASE_EMBEDDED {
public:
explicit PreserveStatementPositionScope(PositionsRecorder* positions_recorder)
explicit PreservePositionScope(PositionsRecorder* positions_recorder)
: positions_recorder_(positions_recorder),
statement_position_(positions_recorder->current_statement_position()) {}
saved_state_(positions_recorder->state_) {}
~PreserveStatementPositionScope() {
if (statement_position_ != RelocInfo::kNoPosition) {
positions_recorder_->RecordStatementPosition(statement_position_);
}
~PreservePositionScope() {
positions_recorder_->state_ = saved_state_;
}
private:
PositionsRecorder* positions_recorder_;
int statement_position_;
const PositionState saved_state_;
DISALLOW_COPY_AND_ASSIGN(PreservePositionScope);
};

View File

@ -558,10 +558,9 @@ void FullCodeGenerator::SetStatementPosition(int pos) {
}
void FullCodeGenerator::SetSourcePosition(
int pos, PositionRecordingType recording_type) {
void FullCodeGenerator::SetSourcePosition(int pos) {
if (FLAG_debug_info && pos != RelocInfo::kNoPosition) {
masm_->positions_recorder()->RecordPosition(pos, recording_type);
masm_->positions_recorder()->RecordPosition(pos);
}
}

View File

@ -423,9 +423,7 @@ class FullCodeGenerator: public AstVisitor {
void SetStatementPosition(Statement* stmt);
void SetExpressionPosition(Expression* expr, int pos);
void SetStatementPosition(int pos);
void SetSourcePosition(
int pos,
PositionRecordingType recording_type = NORMAL_POSITION);
void SetSourcePosition(int pos);
// Non-local control flow support.
void EnterFinallyBlock();

View File

@ -2003,14 +2003,14 @@ void FullCodeGenerator::EmitCallWithIC(Call* expr,
// Code common for calls using the IC.
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
for (int i = 0; i < arg_count; i++) {
VisitForStackValue(args->at(i));
}
__ Set(ecx, Immediate(name));
}
// Record source position of the IC call.
SetSourcePosition(expr->position(), FORCED_POSITION);
SetSourcePosition(expr->position());
InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
Handle<Code> ic = StubCache::ComputeCallInitialize(arg_count, in_loop);
EmitCallIC(ic, mode);
@ -2035,13 +2035,13 @@ void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr,
// Load the arguments.
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
for (int i = 0; i < arg_count; i++) {
VisitForStackValue(args->at(i));
}
}
// Record source position of the IC call.
SetSourcePosition(expr->position(), FORCED_POSITION);
SetSourcePosition(expr->position());
InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
Handle<Code> ic = StubCache::ComputeKeyedCallInitialize(arg_count, in_loop);
__ mov(ecx, Operand(esp, (arg_count + 1) * kPointerSize)); // Key.
@ -2056,13 +2056,13 @@ void FullCodeGenerator::EmitCallWithStub(Call* expr) {
// Code common for calls using the call stub.
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
for (int i = 0; i < arg_count; i++) {
VisitForStackValue(args->at(i));
}
}
// Record source position for debugger.
SetSourcePosition(expr->position(), FORCED_POSITION);
SetSourcePosition(expr->position());
InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE);
__ CallStub(&stub);
@ -2084,7 +2084,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
// arguments.
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
{ PreserveStatementPositionScope pos_scope(masm()->positions_recorder());
{ PreservePositionScope pos_scope(masm()->positions_recorder());
VisitForStackValue(fun);
// Reserved receiver slot.
__ push(Immediate(Factory::undefined_value()));
@ -2114,7 +2114,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
__ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax);
}
// Record source position for debugger.
SetSourcePosition(expr->position(), FORCED_POSITION);
SetSourcePosition(expr->position());
InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE);
__ CallStub(&stub);
@ -2130,7 +2130,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
// Call to a lookup slot (dynamically introduced variable).
Label slow, done;
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
// Generate code for loading from variables potentially shadowed
// by eval-introduced variables.
EmitDynamicLoadFromSlotFastCase(var->AsSlot(),
@ -2176,15 +2176,15 @@ void FullCodeGenerator::VisitCall(Call* expr) {
// Call to a keyed property.
// For a synthetic property use keyed load IC followed by function call,
// for a regular property use keyed EmitCallIC.
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
VisitForStackValue(prop->obj());
}
if (prop->is_synthetic()) {
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
VisitForAccumulatorValue(prop->key());
}
// Record source code position for IC call.
SetSourcePosition(prop->position(), FORCED_POSITION);
SetSourcePosition(prop->position());
__ pop(edx); // We do not need to keep the receiver.
Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize));
@ -2209,7 +2209,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
loop_depth() == 0) {
lit->set_try_full_codegen(true);
}
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
VisitForStackValue(fun);
}
// Load global receiver object.

View File

@ -1722,14 +1722,14 @@ void FullCodeGenerator::EmitCallWithIC(Call* expr,
// Code common for calls using the IC.
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
for (int i = 0; i < arg_count; i++) {
VisitForStackValue(args->at(i));
}
__ Move(rcx, name);
}
// Record source position for debugger.
SetSourcePosition(expr->position(), FORCED_POSITION);
SetSourcePosition(expr->position());
// Call the IC initialization code.
InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
Handle<Code> ic = StubCache::ComputeCallInitialize(arg_count, in_loop);
@ -1755,13 +1755,13 @@ void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr,
// Load the arguments.
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
for (int i = 0; i < arg_count; i++) {
VisitForStackValue(args->at(i));
}
}
// Record source position for debugger.
SetSourcePosition(expr->position(), FORCED_POSITION);
SetSourcePosition(expr->position());
// Call the IC initialization code.
InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
Handle<Code> ic = StubCache::ComputeKeyedCallInitialize(arg_count, in_loop);
@ -1777,13 +1777,13 @@ void FullCodeGenerator::EmitCallWithStub(Call* expr) {
// Code common for calls using the call stub.
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
for (int i = 0; i < arg_count; i++) {
VisitForStackValue(args->at(i));
}
}
// Record source position for debugger.
SetSourcePosition(expr->position(), FORCED_POSITION);
SetSourcePosition(expr->position());
InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE);
__ CallStub(&stub);
@ -1806,7 +1806,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
// arguments.
ZoneList<Expression*>* args = expr->arguments();
int arg_count = args->length();
{ PreserveStatementPositionScope pos_scope(masm()->positions_recorder());
{ PreservePositionScope pos_scope(masm()->positions_recorder());
VisitForStackValue(fun);
__ PushRoot(Heap::kUndefinedValueRootIndex); // Reserved receiver slot.
@ -1835,7 +1835,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
__ movq(Operand(rsp, (arg_count + 1) * kPointerSize), rax);
}
// Record source position for debugger.
SetSourcePosition(expr->position(), FORCED_POSITION);
SetSourcePosition(expr->position());
InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE);
__ CallStub(&stub);
@ -1852,7 +1852,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
// Call to a lookup slot (dynamically introduced variable).
Label slow, done;
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
// Generate code for loading from variables potentially shadowed
// by eval-introduced variables.
EmitDynamicLoadFromSlotFastCase(var->AsSlot(),
@ -1893,7 +1893,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
Literal* key = prop->key()->AsLiteral();
if (key != NULL && key->handle()->IsSymbol()) {
// Call to a named property, use call IC.
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
VisitForStackValue(prop->obj());
}
EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET);
@ -1901,16 +1901,16 @@ void FullCodeGenerator::VisitCall(Call* expr) {
// Call to a keyed property.
// For a synthetic property use keyed load IC followed by function call,
// for a regular property use KeyedCallIC.
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
VisitForStackValue(prop->obj());
}
if (prop->is_synthetic()) {
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
VisitForAccumulatorValue(prop->key());
__ movq(rdx, Operand(rsp, 0));
}
// Record source code position for IC call.
SetSourcePosition(prop->position(), FORCED_POSITION);
SetSourcePosition(prop->position());
Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize));
EmitCallIC(ic, RelocInfo::CODE_TARGET);
// Pop receiver.
@ -1935,7 +1935,7 @@ void FullCodeGenerator::VisitCall(Call* expr) {
loop_depth() == 0) {
lit->set_try_full_codegen(true);
}
{ PreserveStatementPositionScope scope(masm()->positions_recorder());
{ PreservePositionScope scope(masm()->positions_recorder());
VisitForStackValue(fun);
}
// Load global receiver object.