Commit 172277f4 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[parser] Use shared buffer for PreparseDataBuilder children

Get rid of yet another ZoneChunkList.

Change-Id: If63b1b87e007f4d146532b2c66f101280d3fcf2f
Reviewed-on: https://chromium-review.googlesource.com/c/1421319Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59027}
parent 66eaf9fe
......@@ -84,10 +84,11 @@ STATIC_ASSERT(LanguageModeSize <= LanguageField::kNumValues);
*/
PreparseDataBuilder::PreparseDataBuilder(Zone* zone,
PreparseDataBuilder* parent_builder)
PreparseDataBuilder* parent_builder,
std::vector<void*>* children_buffer)
: parent_(parent_builder),
byte_data_(),
children_(zone),
children_buffer_(children_buffer),
function_scope_(nullptr),
num_inner_functions_(0),
num_inner_with_data_(0),
......@@ -98,19 +99,22 @@ void PreparseDataBuilder::DataGatheringScope::Start(
DeclarationScope* function_scope) {
Zone* main_zone = preparser_->main_zone();
builder_ = new (main_zone)
PreparseDataBuilder(main_zone, preparser_->preparse_data_builder());
PreparseDataBuilder(main_zone, preparser_->preparse_data_builder(),
preparser_->preparse_data_builder_buffer());
preparser_->set_preparse_data_builder(builder_);
function_scope->set_preparse_data_builder(builder_);
}
PreparseDataBuilder::DataGatheringScope::~DataGatheringScope() {
if (builder_ == nullptr) return;
// Copy over the data from the buffer into the zone-allocated byte_data_
PreparseDataBuilder* parent = builder_->parent_;
if (parent != nullptr && builder_->HasDataForParent()) {
parent->children_.push_back(builder_);
}
preparser_->set_preparse_data_builder(parent);
builder_->FinalizeChildren(preparser_->main_zone());
if (parent == nullptr) return;
if (!builder_->HasDataForParent()) return;
parent->AddChild(builder_);
}
#ifdef DEBUG
......@@ -232,6 +236,21 @@ bool PreparseDataBuilder::HasDataForParent() const {
return HasData() || function_scope_ != nullptr;
}
void PreparseDataBuilder::AddChild(PreparseDataBuilder* child) {
DCHECK(!finalized_children_);
children_buffer_.Add(child);
}
void PreparseDataBuilder::FinalizeChildren(Zone* zone) {
DCHECK(!finalized_children_);
Vector<PreparseDataBuilder*> children = children_buffer_.CopyTo(zone);
children_buffer_.Rewind();
children_ = children;
#ifdef DEBUG
finalized_children_ = true;
#endif
}
bool PreparseDataBuilder::ScopeNeedsData(Scope* scope) {
if (scope->scope_type() == ScopeType::FUNCTION_SCOPE) {
// Default constructors don't need data (they cannot contain inner functions
......@@ -284,7 +303,7 @@ void PreparseDataBuilder::SaveScopeAllocationData(DeclarationScope* scope,
// Reserve Uint32 for scope_data_start debug info.
byte_data_.WriteUint32(0);
#endif
DCHECK(finalized_children_);
for (const auto& builder : children_) {
// Keep track of functions with inner data. {children_} contains also the
// builders that have no inner functions at all.
......@@ -397,6 +416,7 @@ Handle<PreparseData> PreparseDataBuilder::Serialize(Isolate* isolate) {
Handle<PreparseData> data =
byte_data_.CopyToHeap(isolate, num_inner_with_data_);
int i = 0;
DCHECK(finalized_children_);
for (const auto& builder : children_) {
if (!builder->HasData()) continue;
Handle<PreparseData> child_data = builder->Serialize(isolate);
......@@ -411,6 +431,7 @@ ZonePreparseData* PreparseDataBuilder::Serialize(Zone* zone) {
DCHECK(!ThisOrParentBailedOut());
ZonePreparseData* data = byte_data_.CopyToZone(zone, num_inner_with_data_);
int i = 0;
DCHECK(finalized_children_);
for (const auto& builder : children_) {
if (!builder->HasData()) continue;
ZonePreparseData* child = builder->Serialize(zone);
......
......@@ -89,7 +89,9 @@ class PreparseDataBuilder : public ZoneObject,
public:
// Create a PreparseDataBuilder object which will collect data as we
// parse.
explicit PreparseDataBuilder(Zone* zone, PreparseDataBuilder* parent_builder);
explicit PreparseDataBuilder(Zone* zone, PreparseDataBuilder* parent_builder,
std::vector<void*>* children_buffer);
~PreparseDataBuilder() {}
PreparseDataBuilder* parent() const { return parent_; }
......@@ -191,6 +193,9 @@ class PreparseDataBuilder : public ZoneObject,
Handle<PreparseData> Serialize(Isolate* isolate);
ZonePreparseData* Serialize(Zone* zone);
void FinalizeChildren(Zone* zone);
void AddChild(PreparseDataBuilder* child);
void SaveDataForScope(Scope* scope);
void SaveDataForVariable(Variable* var);
void SaveDataForInnerScopes(Scope* scope);
......@@ -200,7 +205,10 @@ class PreparseDataBuilder : public ZoneObject,
PreparseDataBuilder* parent_;
ByteData byte_data_;
ZoneChunkList<PreparseDataBuilder*> children_;
union {
ScopedPtrList<PreparseDataBuilder> children_buffer_;
Vector<PreparseDataBuilder*> children_;
};
DeclarationScope* function_scope_;
int num_inner_functions_;
......@@ -210,6 +218,10 @@ class PreparseDataBuilder : public ZoneObject,
bool bailed_out_ : 1;
bool has_data_ : 1;
#ifdef DEBUG
bool finalized_children_ = false;
#endif
DISALLOW_COPY_AND_ASSIGN(PreparseDataBuilder);
};
......
......@@ -943,7 +943,10 @@ class PreParser : public ParserBase<PreParser> {
runtime_call_stats, logger, script_id,
parsing_module, parsing_on_main_thread),
use_counts_(nullptr),
preparse_data_builder_(nullptr) {}
preparse_data_builder_(nullptr),
preparse_data_builder_buffer_() {
preparse_data_builder_buffer_.reserve(16);
}
static bool IsPreParser() { return true; }
......@@ -977,6 +980,10 @@ class PreParser : public ParserBase<PreParser> {
preparse_data_builder_ = preparse_data_builder;
}
std::vector<void*>* preparse_data_builder_buffer() {
return &preparse_data_builder_buffer_;
}
private:
friend class i::ExpressionScope<ParserTypes<PreParser>>;
friend class i::VariableDeclarationParsingScope<ParserTypes<PreParser>>;
......@@ -1640,6 +1647,7 @@ class PreParser : public ParserBase<PreParser> {
PreParserLogger log_;
PreparseDataBuilder* preparse_data_builder_;
std::vector<void*> preparse_data_builder_buffer_;
};
PreParserExpression PreParser::SpreadCall(const PreParserExpression& function,
......
......@@ -364,6 +364,13 @@ class ScopedPtrList final {
target->AddAll(Vector<T*>(data, length()), zone);
}
Vector<T*> CopyTo(Zone* zone) {
DCHECK_LE(end_, buffer_.size());
T** data = zone->NewArray<T*>(length());
MemCopy(data, &buffer_[start_], length() * sizeof(T*));
return Vector<T*>(data, length());
}
void Add(T* value) {
DCHECK_EQ(buffer_.size(), end_);
buffer_.push_back(value);
......
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