Commit 768f22f6 authored by verwaest's avatar verwaest Committed by Commit bot

[parser] Keep track of whether we are in a temp-zone in the parser, and don't...

[parser] Keep track of whether we are in a temp-zone in the parser, and don't lazy parse anymore once we are

This avoids entering a nested temp zone, and fixes up tracing and runtime callstats names.

BUG=

Review-Url: https://codereview.chromium.org/2514353002
Cr-Commit-Position: refs/heads/master@{#41147}
parent 330ecc82
...@@ -112,8 +112,13 @@ class DiscardableZoneScope { ...@@ -112,8 +112,13 @@ class DiscardableZoneScope {
fni_(parser->ast_value_factory_, temp_zone), fni_(parser->ast_value_factory_, temp_zone),
parser_(parser), parser_(parser),
prev_fni_(parser->fni_), prev_fni_(parser->fni_),
prev_zone_(parser->zone_) { prev_zone_(parser->zone_),
prev_allow_lazy_(parser->allow_lazy_),
prev_temp_zoned_(parser->temp_zoned_) {
if (use_temp_zone) { if (use_temp_zone) {
DCHECK(!parser_->temp_zoned_);
parser_->allow_lazy_ = false;
parser_->temp_zoned_ = true;
parser_->fni_ = &fni_; parser_->fni_ = &fni_;
parser_->zone_ = temp_zone; parser_->zone_ = temp_zone;
if (parser_->reusable_preparser_ != nullptr) { if (parser_->reusable_preparser_ != nullptr) {
...@@ -125,6 +130,8 @@ class DiscardableZoneScope { ...@@ -125,6 +130,8 @@ class DiscardableZoneScope {
void Reset() { void Reset() {
parser_->fni_ = prev_fni_; parser_->fni_ = prev_fni_;
parser_->zone_ = prev_zone_; parser_->zone_ = prev_zone_;
parser_->allow_lazy_ = prev_allow_lazy_;
parser_->temp_zoned_ = prev_temp_zoned_;
if (parser_->reusable_preparser_ != nullptr) { if (parser_->reusable_preparser_ != nullptr) {
parser_->reusable_preparser_->zone_ = prev_zone_; parser_->reusable_preparser_->zone_ = prev_zone_;
parser_->reusable_preparser_->factory()->set_zone(prev_zone_); parser_->reusable_preparser_->factory()->set_zone(prev_zone_);
...@@ -139,6 +146,8 @@ class DiscardableZoneScope { ...@@ -139,6 +146,8 @@ class DiscardableZoneScope {
Parser* parser_; Parser* parser_;
FuncNameInferrer* prev_fni_; FuncNameInferrer* prev_fni_;
Zone* prev_zone_; Zone* prev_zone_;
bool prev_allow_lazy_;
bool prev_temp_zoned_;
DISALLOW_COPY_AND_ASSIGN(DiscardableZoneScope); DISALLOW_COPY_AND_ASSIGN(DiscardableZoneScope);
}; };
...@@ -146,10 +155,11 @@ class DiscardableZoneScope { ...@@ -146,10 +155,11 @@ class DiscardableZoneScope {
void Parser::SetCachedData(ParseInfo* info) { void Parser::SetCachedData(ParseInfo* info) {
DCHECK_NULL(cached_parse_data_); DCHECK_NULL(cached_parse_data_);
if (consume_cached_parse_data()) { if (consume_cached_parse_data()) {
if (allow_lazy_) {
cached_parse_data_ = ParseData::FromCachedData(*info->cached_data()); cached_parse_data_ = ParseData::FromCachedData(*info->cached_data());
if (cached_parse_data_ == nullptr) { if (cached_parse_data_ != nullptr) return;
compile_options_ = ScriptCompiler::kNoCompileOptions;
} }
compile_options_ = ScriptCompiler::kNoCompileOptions;
} }
} }
...@@ -592,6 +602,7 @@ Parser::Parser(ParseInfo* info) ...@@ -592,6 +602,7 @@ Parser::Parser(ParseInfo* info)
compile_options_(info->compile_options()), compile_options_(info->compile_options()),
cached_parse_data_(nullptr), cached_parse_data_(nullptr),
total_preparse_skipped_(0), total_preparse_skipped_(0),
temp_zoned_(false),
log_(nullptr) { log_(nullptr) {
// Even though we were passed ParseInfo, we should not store it in // Even though we were passed ParseInfo, we should not store it in
// Parser - this makes sure that Isolate is not accidentally accessed via // Parser - this makes sure that Isolate is not accidentally accessed via
...@@ -680,7 +691,11 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { ...@@ -680,7 +691,11 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
ParserLogger logger; ParserLogger logger;
if (produce_cached_parse_data()) { if (produce_cached_parse_data()) {
if (allow_lazy_) {
log_ = &logger; log_ = &logger;
} else {
compile_options_ = ScriptCompiler::kNoCompileOptions;
}
} else if (consume_cached_parse_data()) { } else if (consume_cached_parse_data()) {
cached_parse_data_->Initialize(); cached_parse_data_->Initialize();
} }
...@@ -2692,18 +2707,19 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -2692,18 +2707,19 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
scope->AnalyzePartially(&previous_zone_ast_node_factory); scope->AnalyzePartially(&previous_zone_ast_node_factory);
} }
DCHECK_IMPLIES(use_temp_zone, temp_zoned_);
if (FLAG_trace_preparse) { if (FLAG_trace_preparse) {
PrintF(" [%s]: %i-%i %.*s\n", PrintF(" [%s]: %i-%i %.*s\n",
is_lazy_top_level_function is_lazy_top_level_function
? "Preparse no-resolution" ? "Preparse no-resolution"
: (use_temp_zone ? "Preparse resolution" : "Full parse"), : (temp_zoned_ ? "Preparse resolution" : "Full parse"),
scope->start_position(), scope->end_position(), scope->start_position(), scope->end_position(),
function_name->byte_length(), function_name->raw_data()); function_name->byte_length(), function_name->raw_data());
} }
if (is_lazy_top_level_function) { if (is_lazy_top_level_function) {
CHANGE_CURRENT_RUNTIME_COUNTER(runtime_call_stats_, CHANGE_CURRENT_RUNTIME_COUNTER(runtime_call_stats_,
PreParseNoVariableResolution); PreParseNoVariableResolution);
} else if (use_temp_zone) { } else if (temp_zoned_) {
CHANGE_CURRENT_RUNTIME_COUNTER(runtime_call_stats_, CHANGE_CURRENT_RUNTIME_COUNTER(runtime_call_stats_,
PreParseWithVariableResolution); PreParseWithVariableResolution);
} }
...@@ -3116,6 +3132,8 @@ ZoneList<Statement*>* Parser::ParseFunction( ...@@ -3116,6 +3132,8 @@ ZoneList<Statement*>* Parser::ParseFunction(
DeclarationScope* function_scope, int* num_parameters, int* function_length, DeclarationScope* function_scope, int* num_parameters, int* function_length,
bool* has_duplicate_parameters, int* materialized_literal_count, bool* has_duplicate_parameters, int* materialized_literal_count,
int* expected_property_count, bool* ok) { int* expected_property_count, bool* ok) {
ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY);
FunctionState function_state(&function_state_, &scope_state_, function_scope); FunctionState function_state(&function_state_, &scope_state_, function_scope);
DuplicateFinder duplicate_finder(scanner()->unicode_cache()); DuplicateFinder duplicate_finder(scanner()->unicode_cache());
...@@ -3160,7 +3178,6 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody( ...@@ -3160,7 +3178,6 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
const AstRawString* function_name, int pos, const AstRawString* function_name, int pos,
const ParserFormalParameters& parameters, FunctionKind kind, const ParserFormalParameters& parameters, FunctionKind kind,
FunctionLiteral::FunctionType function_type, bool* ok) { FunctionLiteral::FunctionType function_type, bool* ok) {
ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY);
ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone()); ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone());
static const int kFunctionNameAssignmentIndex = 0; static const int kFunctionNameAssignmentIndex = 0;
...@@ -3819,7 +3836,13 @@ void Parser::ParseOnBackground(ParseInfo* info) { ...@@ -3819,7 +3836,13 @@ void Parser::ParseOnBackground(ParseInfo* info) {
FunctionLiteral* result = NULL; FunctionLiteral* result = NULL;
ParserLogger logger; ParserLogger logger;
if (produce_cached_parse_data()) log_ = &logger; if (produce_cached_parse_data()) {
if (allow_lazy_) {
log_ = &logger;
} else {
compile_options_ = ScriptCompiler::kNoCompileOptions;
}
}
if (FLAG_runtime_stats) { if (FLAG_runtime_stats) {
// Create separate runtime stats for background parsing. // Create separate runtime stats for background parsing.
runtime_call_stats_ = new (zone()) RuntimeCallStats(); runtime_call_stats_ = new (zone()) RuntimeCallStats();
......
...@@ -290,12 +290,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -290,12 +290,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
return compile_options_; return compile_options_;
} }
bool consume_cached_parse_data() const { bool consume_cached_parse_data() const {
return allow_lazy_ && return compile_options_ == ScriptCompiler::kConsumeParserCache;
compile_options_ == ScriptCompiler::kConsumeParserCache;
} }
bool produce_cached_parse_data() const { bool produce_cached_parse_data() const {
return allow_lazy_ && return compile_options_ == ScriptCompiler::kProduceParserCache;
compile_options_ == ScriptCompiler::kProduceParserCache;
} }
void ParseModuleItemList(ZoneList<Statement*>* body, bool* ok); void ParseModuleItemList(ZoneList<Statement*>* body, bool* ok);
...@@ -1145,6 +1143,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) { ...@@ -1145,6 +1143,7 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
int use_counts_[v8::Isolate::kUseCounterFeatureCount]; int use_counts_[v8::Isolate::kUseCounterFeatureCount];
int total_preparse_skipped_; int total_preparse_skipped_;
bool allow_lazy_; bool allow_lazy_;
bool temp_zoned_;
ParserLogger* log_; ParserLogger* log_;
}; };
......
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