Commit d43c6e59 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

Decouple SourcePositionTableBuilder from Zone

Currently the SourcePositionTableBuilder requires a Zone because it
holds a ZoneVector<byte> of the encoded entries. Since ZoneVector is a
suboptimal data structure anyway, and for Liftoff we don't even have a
Zone allocated currently, this CL replaces the ZoneVector by
std::vector.

R=mstarzinger@chromium.org

Bug: v8:6600
Change-Id: I8010143e917e2351664e2b53746753b597f4407a
Reviewed-on: https://chromium-review.googlesource.com/779181Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49534}
parent 82ca5146
......@@ -69,8 +69,7 @@ CodeGenerator::CodeGenerator(
osr_helper_(osr_helper),
osr_pc_offset_(-1),
optimized_out_literal_id_(-1),
source_position_table_builder_(zone(),
info->SourcePositionRecordingMode()),
source_position_table_builder_(info->SourcePositionRecordingMode()),
protected_instructions_(protected_instructions),
result_(kSuccess) {
for (int i = 0; i < code->InstructionBlockCount(); ++i) {
......
......@@ -948,8 +948,7 @@ static int TranslatePosition(int original_position,
void TranslateSourcePositionTable(Handle<BytecodeArray> code,
Handle<JSArray> position_change_array) {
Isolate* isolate = code->GetIsolate();
Zone zone(isolate->allocator(), ZONE_NAME);
SourcePositionTableBuilder builder(&zone);
SourcePositionTableBuilder builder;
Handle<ByteArray> source_position_table(code->SourcePositionTable());
for (SourcePositionTableIterator iterator(*source_position_table);
......
......@@ -31,8 +31,7 @@ class BytecodeRegisterOptimizer;
class BytecodeJumpTable;
class Register;
class V8_EXPORT_PRIVATE BytecodeArrayBuilder final
: public NON_EXPORTED_BASE(ZoneObject) {
class V8_EXPORT_PRIVATE BytecodeArrayBuilder final {
public:
BytecodeArrayBuilder(
Zone* zone, int parameter_count, int locals_count,
......
......@@ -26,7 +26,7 @@ BytecodeArrayWriter::BytecodeArrayWriter(
SourcePositionTableBuilder::RecordingMode source_position_mode)
: bytecodes_(zone),
unbound_jumps_(0),
source_position_table_builder_(zone, source_position_mode),
source_position_table_builder_(source_position_mode),
constant_array_builder_(constant_array_builder),
last_bytecode_(Bytecode::kIllegal),
last_bytecode_offset_(0),
......
......@@ -812,10 +812,9 @@ class BytecodeGenerator::FeedbackSlotCache : public ZoneObject {
BytecodeGenerator::BytecodeGenerator(
CompilationInfo* info, const AstStringConstants* ast_string_constants)
: zone_(info->zone()),
builder_(new (zone()) BytecodeArrayBuilder(
zone(), info->num_parameters_including_this(),
info->scope()->num_stack_slots(), info->feedback_vector_spec(),
info->SourcePositionRecordingMode())),
builder_(zone(), info->num_parameters_including_this(),
info->scope()->num_stack_slots(), info->feedback_vector_spec(),
info->SourcePositionRecordingMode()),
info_(info),
ast_string_constants_(ast_string_constants),
closure_scope_(info->scope()),
......
......@@ -242,7 +242,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
inline Register generator_object() const;
inline BytecodeArrayBuilder* builder() const { return builder_; }
inline BytecodeArrayBuilder* builder() { return &builder_; }
inline Zone* zone() const { return zone_; }
inline DeclarationScope* closure_scope() const { return closure_scope_; }
inline CompilationInfo* info() const { return info_; }
......@@ -265,7 +265,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
execution_result_ = execution_result;
}
ExpressionResultScope* execution_result() const { return execution_result_; }
BytecodeRegisterAllocator* register_allocator() const {
BytecodeRegisterAllocator* register_allocator() {
return builder()->register_allocator();
}
......@@ -290,7 +290,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
}
Zone* zone_;
BytecodeArrayBuilder* builder_;
BytecodeArrayBuilder builder_;
CompilationInfo* info_;
const AstStringConstants* ast_string_constants_;
DeclarationScope* closure_scope_;
......
......@@ -47,7 +47,7 @@ void SubtractFromEntry(PositionTableEntry& value,
// Helper: Encode an integer.
template <typename T>
void EncodeInt(ZoneVector<byte>& bytes, T value) {
void EncodeInt(std::vector<byte>& bytes, T value) {
// Zig-zag encoding.
static const int kShift = sizeof(T) * kBitsPerByte - 1;
value = ((value << 1) ^ (value >> kShift));
......@@ -64,7 +64,7 @@ void EncodeInt(ZoneVector<byte>& bytes, T value) {
}
// Encode a PositionTableEntry.
void EncodeEntry(ZoneVector<byte>& bytes, const PositionTableEntry& entry) {
void EncodeEntry(std::vector<byte>& bytes, const PositionTableEntry& entry) {
// We only accept ascending code offsets.
DCHECK_GE(entry.code_offset, 0);
// Since code_offset is not negative, we use sign to encode is_statement.
......@@ -108,14 +108,8 @@ void DecodeEntry(ByteArray* bytes, int* index, PositionTableEntry* entry) {
} // namespace
SourcePositionTableBuilder::SourcePositionTableBuilder(
Zone* zone, SourcePositionTableBuilder::RecordingMode mode)
: mode_(mode),
bytes_(zone),
#ifdef ENABLE_SLOW_DCHECKS
raw_entries_(zone),
#endif
previous_() {
}
SourcePositionTableBuilder::RecordingMode mode)
: mode_(mode), previous_() {}
void SourcePositionTableBuilder::AddPosition(size_t code_offset,
SourcePosition source_position,
......
......@@ -35,8 +35,8 @@ class V8_EXPORT_PRIVATE SourcePositionTableBuilder {
public:
enum RecordingMode { OMIT_SOURCE_POSITIONS, RECORD_SOURCE_POSITIONS };
SourcePositionTableBuilder(Zone* zone,
RecordingMode mode = RECORD_SOURCE_POSITIONS);
explicit SourcePositionTableBuilder(
RecordingMode mode = RECORD_SOURCE_POSITIONS);
void AddPosition(size_t code_offset, SourcePosition source_position,
bool is_statement);
......@@ -49,9 +49,9 @@ class V8_EXPORT_PRIVATE SourcePositionTableBuilder {
inline bool Omit() const { return mode_ == OMIT_SOURCE_POSITIONS; }
RecordingMode mode_;
ZoneVector<byte> bytes_;
std::vector<byte> bytes_;
#ifdef ENABLE_SLOW_DCHECKS
ZoneVector<PositionTableEntry> raw_entries_;
std::vector<PositionTableEntry> raw_entries_;
#endif
PositionTableEntry previous_; // Previously written entry, to compute delta.
};
......
......@@ -12,7 +12,7 @@ namespace v8 {
namespace internal {
namespace interpreter {
class SourcePositionTableTest : public TestWithIsolateAndZone {
class SourcePositionTableTest : public TestWithIsolate {
public:
SourcePositionTableTest() {}
~SourcePositionTableTest() override {}
......@@ -28,7 +28,7 @@ static int offsets[] = {0, 1, 2, 3, 4, 30, 31, 32,
129, 250, 1000, 9999, 12000, 31415926};
TEST_F(SourcePositionTableTest, EncodeStatement) {
SourcePositionTableBuilder builder(zone());
SourcePositionTableBuilder builder;
for (size_t i = 0; i < arraysize(offsets); i++) {
builder.AddPosition(offsets[i], toPos(offsets[i]), true);
}
......@@ -39,7 +39,7 @@ TEST_F(SourcePositionTableTest, EncodeStatement) {
}
TEST_F(SourcePositionTableTest, EncodeStatementDuplicates) {
SourcePositionTableBuilder builder(zone());
SourcePositionTableBuilder builder;
for (size_t i = 0; i < arraysize(offsets); i++) {
builder.AddPosition(offsets[i], toPos(offsets[i]), true);
builder.AddPosition(offsets[i], toPos(offsets[i] + 1), true);
......@@ -51,7 +51,7 @@ TEST_F(SourcePositionTableTest, EncodeStatementDuplicates) {
}
TEST_F(SourcePositionTableTest, EncodeExpression) {
SourcePositionTableBuilder builder(zone());
SourcePositionTableBuilder builder;
for (size_t i = 0; i < arraysize(offsets); i++) {
builder.AddPosition(offsets[i], toPos(offsets[i]), false);
}
......@@ -59,7 +59,7 @@ TEST_F(SourcePositionTableTest, EncodeExpression) {
}
TEST_F(SourcePositionTableTest, EncodeAscending) {
SourcePositionTableBuilder builder(zone());
SourcePositionTableBuilder builder;
int code_offset = 0;
int source_position = 0;
......
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