Use source position table for crankshaft code.

R=bmeurer@chromium.org
BUG=v8:5117

Review-Url: https://codereview.chromium.org/2101523003
Cr-Commit-Position: refs/heads/master@{#37357}
This commit is contained in:
yangguo 2016-06-28 21:27:29 -07:00 committed by Commit bot
parent 5dbec9be14
commit b1063f7a41
23 changed files with 70 additions and 93 deletions

View File

@ -60,6 +60,9 @@ void LCodeGen::FinishCode(Handle<Code> code) {
DCHECK(is_done());
code->set_stack_slots(GetTotalFrameSlotCount());
code->set_safepoint_table_offset(safepoints_.GetCodeOffset());
Handle<ByteArray> source_positions =
source_position_table_builder_.ToSourcePositionTable();
code->set_source_position_table(*source_positions);
PopulateDeoptimizationData(code);
}
@ -906,12 +909,6 @@ void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
}
void LCodeGen::RecordAndWritePosition(int position) {
if (position == RelocInfo::kNoPosition) return;
masm()->positions_recorder()->RecordPosition(position);
}
static const char* LabelType(LLabel* label) {
if (label->is_loop_header()) return " (loop header)";
if (label->is_osr_entry()) return " (OSR entry)";

View File

@ -253,7 +253,7 @@ class LCodeGen: public LCodeGenBase {
void EmitIntegerMathAbs(LMathAbs* instr);
// Support for recording safepoint and position information.
// Support for recording safepoint information.
void RecordSafepoint(LPointerMap* pointers,
Safepoint::Kind kind,
int arguments,
@ -264,8 +264,6 @@ class LCodeGen: public LCodeGenBase {
int arguments,
Safepoint::DeoptMode mode);
void RecordAndWritePosition(int position) override;
static Condition TokenToCondition(Token::Value op, bool is_unsigned);
void EmitGoto(int block);

View File

@ -445,12 +445,6 @@ void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id,
}
void LCodeGen::RecordAndWritePosition(int position) {
if (position == RelocInfo::kNoPosition) return;
masm()->positions_recorder()->RecordPosition(position);
}
void LCodeGen::RecordSafepointWithLazyDeopt(LInstruction* instr,
SafepointMode safepoint_mode) {
if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) {
@ -824,6 +818,9 @@ void LCodeGen::FinishCode(Handle<Code> code) {
DCHECK(is_done());
code->set_stack_slots(GetTotalFrameSlotCount());
code->set_safepoint_table_offset(safepoints_.GetCodeOffset());
Handle<ByteArray> source_positions =
source_position_table_builder_.ToSourcePositionTable();
code->set_source_position_table(*source_positions);
PopulateDeoptimizationData(code);
}

View File

@ -331,8 +331,7 @@ class LCodeGen: public LCodeGenBase {
int formal_parameter_count, int arity,
bool is_tail_call, LInstruction* instr);
// Support for recording safepoint and position information.
void RecordAndWritePosition(int position) override;
// Support for recording safepoint information.
void RecordSafepoint(LPointerMap* pointers,
Safepoint::Kind kind,
int arguments,

View File

@ -69,6 +69,9 @@ void LCodeGen::FinishCode(Handle<Code> code) {
code->set_stack_slots(GetTotalFrameSlotCount());
code->set_safepoint_table_offset(safepoints_.GetCodeOffset());
PopulateDeoptimizationData(code);
Handle<ByteArray> source_positions =
source_position_table_builder_.ToSourcePositionTable();
code->set_source_position_table(*source_positions);
if (info()->ShouldEnsureSpaceForLazyDeopt()) {
Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(code);
}
@ -807,12 +810,6 @@ void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
}
void LCodeGen::RecordAndWritePosition(int position) {
if (position == RelocInfo::kNoPosition) return;
masm()->positions_recorder()->RecordPosition(position);
}
static const char* LabelType(LLabel* label) {
if (label->is_loop_header()) return " (loop header)";
if (label->is_osr_entry()) return " (OSR entry)";

View File

@ -239,7 +239,7 @@ class LCodeGen: public LCodeGenBase {
void EmitIntegerMathAbs(LMathAbs* instr);
// Support for recording safepoint and position information.
// Support for recording safepoint information.
void RecordSafepoint(LPointerMap* pointers,
Safepoint::Kind kind,
int arguments,
@ -250,8 +250,6 @@ class LCodeGen: public LCodeGenBase {
int arguments,
Safepoint::DeoptMode mode);
void RecordAndWritePosition(int position) override;
static Condition TokenToCondition(Token::Value op, bool is_unsigned);
void EmitGoto(int block);

View File

@ -45,7 +45,6 @@ HGraph* LCodeGenBase::graph() const {
return chunk()->graph();
}
LCodeGenBase::LCodeGenBase(LChunk* chunk, MacroAssembler* assembler,
CompilationInfo* info)
: chunk_(static_cast<LPlatformChunk*>(chunk)),
@ -61,8 +60,8 @@ LCodeGenBase::LCodeGenBase(LChunk* chunk, MacroAssembler* assembler,
translations_(info->zone()),
inlined_function_count_(0),
last_lazy_deopt_pc_(0),
osr_pc_offset_(-1) {}
osr_pc_offset_(-1),
source_position_table_builder_(info->isolate(), info->zone()) {}
bool LCodeGenBase::GenerateBody() {
DCHECK(is_generating());
@ -137,6 +136,10 @@ void LCodeGenBase::CheckEnvironmentUsage() {
#endif
}
void LCodeGenBase::RecordAndWritePosition(int pos) {
if (pos == RelocInfo::kNoPosition) return;
source_position_table_builder_.AddPosition(masm_->pc_offset(), pos, false);
}
void LCodeGenBase::Comment(const char* format, ...) {
if (!FLAG_code_comments) return;
@ -371,5 +374,6 @@ Deoptimizer::DeoptInfo LCodeGenBase::MakeDeoptInfo(
deopt_reason, deopt_id);
return deopt_info;
}
} // namespace internal
} // namespace v8

View File

@ -8,6 +8,7 @@
#include "src/bailout-reason.h"
#include "src/compiler.h"
#include "src/deoptimizer.h"
#include "src/source-position-table.h"
namespace v8 {
namespace internal {
@ -34,6 +35,9 @@ class LCodeGenBase BASE_EMBEDDED {
Zone* zone() const { return zone_; }
LPlatformChunk* chunk() const { return chunk_; }
HGraph* graph() const;
SourcePositionTableBuilder* source_position_table_builder() {
return &source_position_table_builder_;
}
void PRINTF_FORMAT(2, 3) Comment(const char* format, ...);
void DeoptComment(const Deoptimizer::DeoptInfo& deopt_info);
@ -45,7 +49,7 @@ class LCodeGenBase BASE_EMBEDDED {
virtual void GenerateBodyInstructionPost(LInstruction* instr) {}
virtual void EnsureSpaceForLazyDeopt(int space_needed) = 0;
virtual void RecordAndWritePosition(int position) = 0;
void RecordAndWritePosition(int position);
int GetNextEmittedBlock() const;
@ -85,6 +89,7 @@ class LCodeGenBase BASE_EMBEDDED {
int inlined_function_count_;
int last_lazy_deopt_pc_;
int osr_pc_offset_;
SourcePositionTableBuilder source_position_table_builder_;
bool is_unused() const { return status_ == UNUSED; }
bool is_generating() const { return status_ == GENERATING; }

View File

@ -448,13 +448,14 @@ LChunk* LChunk::NewChunk(HGraph* graph) {
Handle<Code> LChunk::Codegen() {
MacroAssembler assembler(info()->isolate(), NULL, 0,
CodeObjectRequired::kYes);
LOG_CODE_EVENT(info()->isolate(),
CodeStartLinePosInfoRecordEvent(
assembler.positions_recorder()));
// Code serializer only takes unoptimized code.
DCHECK(!info()->will_serialize());
LCodeGen generator(this, &assembler, info());
LOG_CODE_EVENT(info()->isolate(),
CodeStartLinePosInfoRecordEvent(
generator.source_position_table_builder()));
MarkEmptyBlocks();
if (generator.GenerateCode()) {
@ -465,7 +466,7 @@ Handle<Code> LChunk::Codegen() {
CommitDependencies(code);
code->set_is_crankshafted(true);
void* jit_handler_data =
assembler.positions_recorder()->DetachJITHandlerData();
generator.source_position_table_builder()->DetachJITHandlerData();
LOG_CODE_EVENT(info()->isolate(),
CodeEndLinePosInfoRecordEvent(AbstractCode::cast(*code),
jit_handler_data));

View File

@ -83,6 +83,9 @@ void LCodeGen::FinishCode(Handle<Code> code) {
DCHECK(is_done());
code->set_stack_slots(GetTotalFrameSlotCount());
code->set_safepoint_table_offset(safepoints_.GetCodeOffset());
Handle<ByteArray> source_positions =
source_position_table_builder_.ToSourcePositionTable();
code->set_source_position_table(*source_positions);
PopulateDeoptimizationData(code);
}
@ -872,12 +875,6 @@ void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
}
void LCodeGen::RecordAndWritePosition(int position) {
if (position == RelocInfo::kNoPosition) return;
masm()->positions_recorder()->RecordPosition(position);
}
static const char* LabelType(LLabel* label) {
if (label->is_loop_header()) return " (loop header)";
if (label->is_osr_entry()) return " (OSR entry)";

View File

@ -251,7 +251,7 @@ class LCodeGen: public LCodeGenBase {
void EmitIntegerMathAbs(LMathAbs* instr);
// Support for recording safepoint and position information.
// Support for recording safepoint information.
void RecordSafepoint(LPointerMap* pointers,
Safepoint::Kind kind,
int arguments,
@ -262,8 +262,6 @@ class LCodeGen: public LCodeGenBase {
int arguments,
Safepoint::DeoptMode mode);
void RecordAndWritePosition(int position) override;
static Condition TokenToCondition(Token::Value op, bool is_unsigned);
void EmitGoto(int block);

View File

@ -59,6 +59,9 @@ void LCodeGen::FinishCode(Handle<Code> code) {
DCHECK(is_done());
code->set_stack_slots(GetTotalFrameSlotCount());
code->set_safepoint_table_offset(safepoints_.GetCodeOffset());
Handle<ByteArray> source_positions =
source_position_table_builder_.ToSourcePositionTable();
code->set_source_position_table(*source_positions);
PopulateDeoptimizationData(code);
}
@ -861,12 +864,6 @@ void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
}
void LCodeGen::RecordAndWritePosition(int position) {
if (position == RelocInfo::kNoPosition) return;
masm()->positions_recorder()->RecordPosition(position);
}
static const char* LabelType(LLabel* label) {
if (label->is_loop_header()) return " (loop header)";
if (label->is_osr_entry()) return " (OSR entry)";

View File

@ -254,7 +254,7 @@ class LCodeGen: public LCodeGenBase {
void EmitIntegerMathAbs(LMathAbs* instr);
void EmitSmiMathAbs(LMathAbs* instr);
// Support for recording safepoint and position information.
// Support for recording safepoint information.
void RecordSafepoint(LPointerMap* pointers,
Safepoint::Kind kind,
int arguments,
@ -265,8 +265,6 @@ class LCodeGen: public LCodeGenBase {
int arguments,
Safepoint::DeoptMode mode);
void RecordAndWritePosition(int position) override;
static Condition TokenToCondition(Token::Value op, bool is_unsigned);
void EmitGoto(int block);

View File

@ -61,6 +61,9 @@ void LCodeGen::FinishCode(Handle<Code> code) {
DCHECK(is_done());
code->set_stack_slots(GetTotalFrameSlotCount());
code->set_safepoint_table_offset(safepoints_.GetCodeOffset());
Handle<ByteArray> source_positions =
source_position_table_builder_.ToSourcePositionTable();
code->set_source_position_table(*source_positions);
PopulateDeoptimizationData(code);
}
@ -833,12 +836,6 @@ void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
}
void LCodeGen::RecordAndWritePosition(int position) {
if (position == RelocInfo::kNoPosition) return;
masm()->positions_recorder()->RecordPosition(position);
}
static const char* LabelType(LLabel* label) {
if (label->is_loop_header()) return " (loop header)";
if (label->is_osr_entry()) return " (OSR entry)";

View File

@ -228,7 +228,7 @@ class LCodeGen : public LCodeGenBase {
void EmitInteger32MathAbs(LMathAbs* instr);
#endif
// Support for recording safepoint and position information.
// Support for recording safepoint information.
void RecordSafepoint(LPointerMap* pointers, Safepoint::Kind kind,
int arguments, Safepoint::DeoptMode mode);
void RecordSafepoint(LPointerMap* pointers, Safepoint::DeoptMode mode);
@ -236,8 +236,6 @@ class LCodeGen : public LCodeGenBase {
void RecordSafepointWithRegisters(LPointerMap* pointers, int arguments,
Safepoint::DeoptMode mode);
void RecordAndWritePosition(int position) override;
static Condition TokenToCondition(Token::Value op);
void EmitGoto(int block);

View File

@ -55,6 +55,9 @@ void LCodeGen::FinishCode(Handle<Code> code) {
DCHECK(is_done());
code->set_stack_slots(GetTotalFrameSlotCount());
code->set_safepoint_table_offset(safepoints_.GetCodeOffset());
Handle<ByteArray> source_positions =
source_position_table_builder_.ToSourcePositionTable();
code->set_source_position_table(*source_positions);
PopulateDeoptimizationData(code);
}
@ -816,11 +819,6 @@ void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, deopt_mode);
}
void LCodeGen::RecordAndWritePosition(int position) {
if (position == RelocInfo::kNoPosition) return;
masm()->positions_recorder()->RecordPosition(position);
}
static const char* LabelType(LLabel* label) {
if (label->is_loop_header()) return " (loop header)";
if (label->is_osr_entry()) return " (OSR entry)";

View File

@ -228,7 +228,7 @@ class LCodeGen : public LCodeGenBase {
void EmitInteger32MathAbs(LMathAbs* instr);
#endif
// Support for recording safepoint and position information.
// Support for recording safepoint information.
void RecordSafepoint(LPointerMap* pointers, Safepoint::Kind kind,
int arguments, Safepoint::DeoptMode mode);
void RecordSafepoint(LPointerMap* pointers, Safepoint::DeoptMode mode);
@ -236,8 +236,6 @@ class LCodeGen : public LCodeGenBase {
void RecordSafepointWithRegisters(LPointerMap* pointers, int arguments,
Safepoint::DeoptMode mode);
void RecordAndWritePosition(int position) override;
static Condition TokenToCondition(Token::Value op);
void EmitGoto(int block);

View File

@ -66,6 +66,9 @@ void LCodeGen::FinishCode(Handle<Code> code) {
DCHECK(is_done());
code->set_stack_slots(GetTotalFrameSlotCount());
code->set_safepoint_table_offset(safepoints_.GetCodeOffset());
Handle<ByteArray> source_positions =
source_position_table_builder_.ToSourcePositionTable();
code->set_source_position_table(*source_positions);
PopulateDeoptimizationData(code);
}
@ -835,12 +838,6 @@ void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
}
void LCodeGen::RecordAndWritePosition(int position) {
if (position == RelocInfo::kNoPosition) return;
masm()->positions_recorder()->RecordPosition(position);
}
static const char* LabelType(LLabel* label) {
if (label->is_loop_header()) return " (loop header)";
if (label->is_osr_entry()) return " (OSR entry)";

View File

@ -238,7 +238,7 @@ class LCodeGen: public LCodeGenBase {
void EmitIntegerMathAbs(LMathAbs* instr);
void EmitSmiMathAbs(LMathAbs* instr);
// Support for recording safepoint and position information.
// Support for recording safepoint information.
void RecordSafepoint(LPointerMap* pointers,
Safepoint::Kind kind,
int arguments,
@ -248,7 +248,6 @@ class LCodeGen: public LCodeGenBase {
void RecordSafepointWithRegisters(LPointerMap* pointers,
int arguments,
Safepoint::DeoptMode mode);
void RecordAndWritePosition(int position) override;
static Condition TokenToCondition(Token::Value op, bool is_unsigned);
void EmitGoto(int block);

View File

@ -68,6 +68,9 @@ void LCodeGen::FinishCode(Handle<Code> code) {
DCHECK(is_done());
code->set_stack_slots(GetTotalFrameSlotCount());
code->set_safepoint_table_offset(safepoints_.GetCodeOffset());
Handle<ByteArray> source_positions =
source_position_table_builder_.ToSourcePositionTable();
code->set_source_position_table(*source_positions);
PopulateDeoptimizationData(code);
if (info()->ShouldEnsureSpaceForLazyDeopt()) {
Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(code);
@ -1098,12 +1101,6 @@ void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers,
}
void LCodeGen::RecordAndWritePosition(int position) {
if (position == RelocInfo::kNoPosition) return;
masm()->positions_recorder()->RecordPosition(position);
}
static const char* LabelType(LLabel* label) {
if (label->is_loop_header()) return " (loop header)";
if (label->is_osr_entry()) return " (OSR entry)";

View File

@ -267,7 +267,7 @@ class LCodeGen: public LCodeGenBase {
void EmitIntegerMathAbs(LMathAbs* instr);
// Support for recording safepoint and position information.
// Support for recording safepoint information.
void RecordSafepoint(LPointerMap* pointers,
Safepoint::Kind kind,
int arguments,
@ -278,8 +278,6 @@ class LCodeGen: public LCodeGenBase {
int arguments,
Safepoint::DeoptMode mode);
void RecordAndWritePosition(int position) override;
static Condition TokenToCondition(Token::Value op, bool is_unsigned);
void EmitGoto(int block);

View File

@ -13592,7 +13592,7 @@ int Code::SourcePosition(int code_offset) {
code_offset--;
// Find the closest position attached to a pc lower or equal to the current.
// Note that the pc of reloc infos grow monotonically.
if (kind() == FUNCTION) {
if (kind() == FUNCTION || (is_optimized_code() && !is_turbofanned())) {
for (SourcePositionTableIterator it(source_position_table());
!it.done() && it.code_offset() <= code_offset; it.Advance()) {
position = it.source_position();
@ -13617,7 +13617,7 @@ int Code::SourceStatementPosition(int code_offset) {
int position = SourcePosition(code_offset);
// Now find the closest statement position before the position.
int statement_position = 0;
if (kind() == FUNCTION) {
if (kind() == FUNCTION || (is_optimized_code() && !is_turbofanned())) {
for (SourcePositionTableIterator it(source_position_table()); !it.done();
it.Advance()) {
if (it.is_statement()) {

View File

@ -90,16 +90,25 @@ void ProfilerListener::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
line_table = new JITLineInfoTable();
if (abstract_code->IsCode()) {
Code* code = abstract_code->GetCode();
if (code->kind() == Code::FUNCTION) {
SourcePositionTableIterator it(code->source_position_table());
for (; !it.done(); it.Advance()) {
int start_position = shared->start_position();
int end_position = shared->end_position();
if (code->kind() == Code::FUNCTION ||
(code->is_optimized_code() && !code->is_turbofanned())) {
for (SourcePositionTableIterator it(code->source_position_table());
!it.done(); it.Advance()) {
int position = it.source_position();
// TODO(alph): in case of inlining the position may correspond to an
// inlined function source code. Do not collect positions that fall
// beyond the function source code. There's however a chance the
// inlined function has similar positions but in another script. So
// the proper fix is to store script_id in some form along with the
// inlined function positions.
if (position < start_position || position >= end_position) continue;
int line_number = script->GetLineNumber(it.source_position()) + 1;
int pc_offset = it.code_offset() + Code::kHeaderSize;
line_table->SetPosition(pc_offset, line_number);
}
} else {
int start_position = shared->start_position();
int end_position = shared->end_position();
for (RelocIterator it(code); !it.done(); it.next()) {
RelocInfo* reloc_info = it.rinfo();
if (!RelocInfo::IsPosition(reloc_info->rmode())) continue;