Commit 3885fa09 authored by yangguo's avatar yangguo Committed by Commit bot

Do not record source positions for non-script or native script compiles.

R=bmeurer@chromium.org, mstarzinger@chromium.org, rmcilroy@chromium.org

Review-Url: https://codereview.chromium.org/2112853002
Cr-Commit-Position: refs/heads/master@{#37602}
parent 717b2eaf
......@@ -224,6 +224,13 @@ int CompilationInfo::GetDeclareGlobalsFlags() const {
DeclareGlobalsLanguageMode::encode(parse_info()->language_mode());
}
SourcePositionTableBuilder::RecordingMode
CompilationInfo::SourcePositionRecordingMode() const {
return parse_info() && parse_info()->is_native()
? SourcePositionTableBuilder::OMIT_SOURCE_POSITIONS
: SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS;
}
bool CompilationInfo::ExpectsJSReceiverAsReceiver() {
return is_sloppy(parse_info()->language_mode()) && !parse_info()->is_native();
}
......
......@@ -9,6 +9,7 @@
#include "src/ast/ast.h"
#include "src/bailout-reason.h"
#include "src/compilation-dependencies.h"
#include "src/source-position-table.h"
#include "src/source-position.h"
#include "src/zone.h"
......@@ -435,6 +436,8 @@ class CompilationInfo final {
int GetDeclareGlobalsFlags() const;
SourcePositionTableBuilder::RecordingMode SourcePositionRecordingMode() const;
protected:
ParseInfo* parse_info_;
......
......@@ -54,7 +54,8 @@ CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage,
jump_tables_(nullptr),
ools_(nullptr),
osr_pc_offset_(-1),
source_position_table_builder_(info->isolate(), zone()) {
source_position_table_builder_(info->isolate(), code->zone(),
info->SourcePositionRecordingMode()) {
for (int i = 0; i < code->InstructionBlockCount(); ++i) {
new (&labels_[i]) Label;
}
......
......@@ -63,7 +63,8 @@ LCodeGenBase::LCodeGenBase(LChunk* chunk, MacroAssembler* assembler,
inlined_function_count_(0),
last_lazy_deopt_pc_(0),
osr_pc_offset_(-1),
source_position_table_builder_(info->isolate(), info->zone()) {}
source_position_table_builder_(info->isolate(), info->zone(),
info->SourcePositionRecordingMode()) {}
bool LCodeGenBase::GenerateBody() {
DCHECK(is_generating());
......
......@@ -47,7 +47,8 @@ class FullCodeGenerator: public AstVisitor {
info->zone()),
back_edges_(2, info->zone()),
handler_table_(info->zone()),
source_position_table_builder_(info->isolate(), info->zone()),
source_position_table_builder_(info->isolate(), info->zone(),
info->SourcePositionRecordingMode()),
ic_total_count_(0) {
DCHECK(!info->IsStub());
Initialize();
......
......@@ -17,10 +17,10 @@ namespace v8 {
namespace internal {
namespace interpreter {
BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate, Zone* zone,
int parameter_count,
int context_count, int locals_count,
FunctionLiteral* literal)
BytecodeArrayBuilder::BytecodeArrayBuilder(
Isolate* isolate, Zone* zone, int parameter_count, int context_count,
int locals_count, FunctionLiteral* literal,
SourcePositionTableBuilder::RecordingMode source_position_mode)
: isolate_(isolate),
zone_(zone),
bytecode_generated_(false),
......@@ -31,7 +31,8 @@ BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate, Zone* zone,
local_register_count_(locals_count),
context_register_count_(context_count),
temporary_allocator_(zone, fixed_register_count()),
bytecode_array_writer_(isolate, zone, &constant_array_builder_),
bytecode_array_writer_(isolate, zone, &constant_array_builder_,
source_position_mode),
pipeline_(&bytecode_array_writer_) {
DCHECK_GE(parameter_count_, 0);
DCHECK_GE(context_register_count_, 0);
......
......@@ -27,9 +27,11 @@ class Register;
class BytecodeArrayBuilder final : public ZoneObject {
public:
BytecodeArrayBuilder(Isolate* isolate, Zone* zone, int parameter_count,
int context_count, int locals_count,
FunctionLiteral* literal = nullptr);
BytecodeArrayBuilder(
Isolate* isolate, Zone* zone, int parameter_count, int context_count,
int locals_count, FunctionLiteral* literal = nullptr,
SourcePositionTableBuilder::RecordingMode source_position_mode =
SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS);
Handle<BytecodeArray> ToBytecodeArray();
......
......@@ -17,12 +17,13 @@ STATIC_CONST_MEMBER_DEFINITION const size_t
BytecodeArrayWriter::kMaxSizeOfPackedBytecode;
BytecodeArrayWriter::BytecodeArrayWriter(
Isolate* isolate, Zone* zone, ConstantArrayBuilder* constant_array_builder)
Isolate* isolate, Zone* zone, ConstantArrayBuilder* constant_array_builder,
SourcePositionTableBuilder::RecordingMode source_position_mode)
: isolate_(isolate),
bytecodes_(zone),
max_register_count_(0),
unbound_jumps_(0),
source_position_table_builder_(isolate, zone),
source_position_table_builder_(isolate, zone, source_position_mode),
constant_array_builder_(constant_array_builder) {}
// override
......
......@@ -22,8 +22,10 @@ class ConstantArrayBuilder;
// generation pipeline.
class BytecodeArrayWriter final : public BytecodePipelineStage {
public:
BytecodeArrayWriter(Isolate* isolate, Zone* zone,
ConstantArrayBuilder* constant_array_builder);
BytecodeArrayWriter(
Isolate* isolate, Zone* zone,
ConstantArrayBuilder* constant_array_builder,
SourcePositionTableBuilder::RecordingMode source_position_mode);
virtual ~BytecodeArrayWriter();
// BytecodePipelineStage interface.
......
......@@ -547,7 +547,8 @@ BytecodeGenerator::BytecodeGenerator(CompilationInfo* info)
builder_(new (zone()) BytecodeArrayBuilder(
info->isolate(), info->zone(), info->num_parameters_including_this(),
info->scope()->MaxNestedContextChainLength(),
info->scope()->num_stack_slots(), info->literal())),
info->scope()->num_stack_slots(), info->literal(),
info->SourcePositionRecordingMode())),
info_(info),
scope_(info->scope()),
globals_(0, info->zone()),
......
......@@ -104,19 +104,23 @@ void DecodeEntry(ByteArray* bytes, int* index, PositionTableEntry* entry) {
} // namespace
SourcePositionTableBuilder::SourcePositionTableBuilder(Isolate* isolate,
Zone* zone)
SourcePositionTableBuilder::SourcePositionTableBuilder(
Isolate* isolate, Zone* zone,
SourcePositionTableBuilder::RecordingMode mode)
: isolate_(isolate),
mode_(mode),
bytes_(zone),
#ifdef ENABLE_SLOW_DCHECKS
raw_entries_(zone),
#endif
previous_(),
jit_handler_data_(nullptr) {
if (Omit()) return;
LOG_CODE_EVENT(isolate_, CodeStartLinePosInfoRecordEvent(&jit_handler_data_));
}
void SourcePositionTableBuilder::EndJitLogging(AbstractCode* code) {
if (Omit()) return;
LOG_CODE_EVENT(isolate_,
CodeEndLinePosInfoRecordEvent(code, jit_handler_data_));
}
......@@ -124,6 +128,7 @@ void SourcePositionTableBuilder::EndJitLogging(AbstractCode* code) {
void SourcePositionTableBuilder::AddPosition(size_t code_offset,
int source_position,
bool is_statement) {
if (Omit()) return;
int offset = static_cast<int>(code_offset);
AddEntry({offset, source_position, is_statement});
}
......@@ -150,6 +155,7 @@ void SourcePositionTableBuilder::AddEntry(const PositionTableEntry& entry) {
Handle<ByteArray> SourcePositionTableBuilder::ToSourcePositionTable() {
if (bytes_.empty()) return isolate_->factory()->empty_byte_array();
DCHECK(!Omit());
Handle<ByteArray> table = isolate_->factory()->NewByteArray(
static_cast<int>(bytes_.size()), TENURED);
......@@ -168,8 +174,9 @@ Handle<ByteArray> SourcePositionTableBuilder::ToSourcePositionTable() {
DCHECK_EQ(encoded.is_statement(), raw->is_statement);
}
DCHECK(raw == raw_entries_.end());
// No additional source positions after creating the table.
mode_ = OMIT_SOURCE_POSITIONS;
#endif
return table;
}
......
......@@ -32,7 +32,10 @@ struct PositionTableEntry {
class SourcePositionTableBuilder {
public:
SourcePositionTableBuilder(Isolate* isolate, Zone* zone);
enum RecordingMode { OMIT_SOURCE_POSITIONS, RECORD_SOURCE_POSITIONS };
SourcePositionTableBuilder(Isolate* isolate, Zone* zone,
RecordingMode mode = RECORD_SOURCE_POSITIONS);
void EndJitLogging(AbstractCode* code);
......@@ -42,7 +45,10 @@ class SourcePositionTableBuilder {
private:
void AddEntry(const PositionTableEntry& entry);
inline bool Omit() const { return mode_ == OMIT_SOURCE_POSITIONS; }
Isolate* isolate_;
RecordingMode mode_;
ZoneVector<byte> bytes_;
#ifdef ENABLE_SLOW_DCHECKS
ZoneVector<PositionTableEntry> raw_entries_;
......
......@@ -23,7 +23,9 @@ class BytecodeArrayWriterUnittest : public TestWithIsolateAndZone {
public:
BytecodeArrayWriterUnittest()
: constant_array_builder_(isolate(), zone()),
bytecode_array_writer_(isolate(), zone(), &constant_array_builder_) {}
bytecode_array_writer_(
isolate(), zone(), &constant_array_builder_,
SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS) {}
~BytecodeArrayWriterUnittest() override {}
void Write(BytecodeNode* node, const BytecodeSourceInfo& info);
......@@ -135,14 +137,14 @@ TEST_F(BytecodeArrayWriterUnittest, SimpleExample) {
CHECK_EQ(bytecodes()->at(i), bytes[i]);
}
writer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array());
Handle<BytecodeArray> bytecode_array =
writer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array());
CHECK_EQ(bytecodes()->size(), arraysize(bytes));
PositionTableEntry expected_positions[] = {
{0, 10, false}, {1, 55, true}, {7, 70, true}};
Handle<ByteArray> source_positions =
source_position_table_builder()->ToSourcePositionTable();
SourcePositionTableIterator source_iterator(*source_positions);
SourcePositionTableIterator source_iterator(
bytecode_array->source_position_table());
for (size_t i = 0; i < arraysize(expected_positions); ++i) {
const PositionTableEntry& expected = expected_positions[i];
CHECK_EQ(source_iterator.code_offset(), expected.code_offset);
......
......@@ -28,10 +28,10 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS [1].toString() is '1'
PASS [1].toLocaleString() is 'toLocaleString'
FAIL [1].toLocaleString() should be 1. Threw exception TypeError: (var).toLocaleString is not a function
FAIL [1].toLocaleString() should be 1. Threw exception TypeError: string is not a function
PASS [/r/].toString() is 'toString2'
PASS [/r/].toLocaleString() is 'toLocaleString2'
FAIL [/r/].toLocaleString() should be toString2. Threw exception TypeError: (var).toLocaleString is not a function
FAIL [/r/].toLocaleString() should be toString2. Threw exception TypeError: string is not a function
PASS caught is true
PASS successfullyParsed is true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment