Commit 92844597 authored by verwaest's avatar verwaest Committed by Commit bot

Explicitly check for lazy parser when dealing with parser cache

BUG=v8:5501

Review-Url: https://codereview.chromium.org/2417643004
Cr-Commit-Position: refs/heads/master@{#40269}
parent e902b69d
...@@ -43,10 +43,7 @@ BackgroundParsingTask::BackgroundParsingTask( ...@@ -43,10 +43,7 @@ BackgroundParsingTask::BackgroundParsingTask(
// Parse eagerly with ignition since we will compile eagerly. // Parse eagerly with ignition since we will compile eagerly.
info->set_allow_lazy_parsing(!(i::FLAG_ignition && i::FLAG_ignition_eager)); info->set_allow_lazy_parsing(!(i::FLAG_ignition && i::FLAG_ignition_eager));
if (options == ScriptCompiler::kProduceParserCache ||
options == ScriptCompiler::kProduceCodeCache) {
source_->info->set_cached_data(&script_data_); source_->info->set_cached_data(&script_data_);
}
// Parser needs to stay alive for finalizing the parsing on the main // Parser needs to stay alive for finalizing the parsing on the main
// thread. // thread.
source_->parser.reset(new Parser(source_->info.get())); source_->parser.reset(new Parser(source_->info.get()));
......
...@@ -1036,31 +1036,9 @@ Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { ...@@ -1036,31 +1036,9 @@ Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
Handle<SharedFunctionInfo> result; Handle<SharedFunctionInfo> result;
{ VMState<COMPILER> state(info->isolate()); { VMState<COMPILER> state(info->isolate());
if (parse_info->literal() == NULL) { if (parse_info->literal() == nullptr && !Parse(parse_info)) {
// Parse the script if needed (if it's already parsed, literal() is
// non-NULL). If compiling for debugging, we may eagerly compile inner
// functions, so do not parse lazily in that case.
ScriptCompiler::CompileOptions options = parse_info->compile_options();
bool parse_allow_lazy =
options == ScriptCompiler::kConsumeParserCache ||
String::cast(script->source())->length() > FLAG_min_preparse_length;
parse_info->set_allow_lazy_parsing(parse_allow_lazy);
if (!parse_allow_lazy &&
(options == ScriptCompiler::kProduceParserCache ||
options == ScriptCompiler::kConsumeParserCache)) {
// We are going to parse eagerly, but we either 1) have cached data
// produced by lazy parsing or 2) are asked to generate cached data.
// Eager parsing cannot benefit from cached data, and producing cached
// data while parsing eagerly is not implemented.
parse_info->set_cached_data(nullptr);
parse_info->set_compile_options(ScriptCompiler::kNoCompileOptions);
}
if (!Parse(parse_info)) {
return Handle<SharedFunctionInfo>::null(); return Handle<SharedFunctionInfo>::null();
} }
}
FunctionLiteral* lit = parse_info->literal(); FunctionLiteral* lit = parse_info->literal();
......
...@@ -66,6 +66,8 @@ ParseInfo::ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared) ...@@ -66,6 +66,8 @@ ParseInfo::ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared)
ParseInfo::ParseInfo(Zone* zone, Handle<Script> script) : ParseInfo(zone) { ParseInfo::ParseInfo(Zone* zone, Handle<Script> script) : ParseInfo(zone) {
isolate_ = script->GetIsolate(); isolate_ = script->GetIsolate();
set_allow_lazy_parsing(String::cast(script->source())->length() >
FLAG_min_preparse_length);
set_toplevel(); set_toplevel();
set_hash_seed(isolate_->heap()->HashSeed()); set_hash_seed(isolate_->heap()->HashSeed());
set_stack_limit(isolate_->stack_guard()->real_climit()); set_stack_limit(isolate_->stack_guard()->real_climit());
......
...@@ -99,6 +99,9 @@ class ParseInfo { ...@@ -99,6 +99,9 @@ class ParseInfo {
return compile_options_; return compile_options_;
} }
void set_compile_options(ScriptCompiler::CompileOptions compile_options) { void set_compile_options(ScriptCompiler::CompileOptions compile_options) {
if (compile_options == ScriptCompiler::kConsumeParserCache) {
set_allow_lazy_parsing();
}
compile_options_ = compile_options; compile_options_ = compile_options;
} }
......
...@@ -150,12 +150,11 @@ class DiscardableZoneScope { ...@@ -150,12 +150,11 @@ class DiscardableZoneScope {
}; };
void Parser::SetCachedData(ParseInfo* info) { void Parser::SetCachedData(ParseInfo* info) {
if (compile_options_ == ScriptCompiler::kNoCompileOptions) { DCHECK_NULL(cached_parse_data_);
cached_parse_data_ = NULL; if (consume_cached_parse_data()) {
} else {
DCHECK(info->cached_data() != NULL);
if (compile_options_ == ScriptCompiler::kConsumeParserCache) {
cached_parse_data_ = ParseData::FromCachedData(*info->cached_data()); cached_parse_data_ = ParseData::FromCachedData(*info->cached_data());
if (cached_parse_data_ == nullptr) {
compile_options_ = ScriptCompiler::kNoCompileOptions;
} }
} }
} }
...@@ -638,7 +637,7 @@ Parser::Parser(ParseInfo* info) ...@@ -638,7 +637,7 @@ Parser::Parser(ParseInfo* info)
original_scope_(NULL), original_scope_(NULL),
target_stack_(NULL), target_stack_(NULL),
compile_options_(info->compile_options()), compile_options_(info->compile_options()),
cached_parse_data_(NULL), cached_parse_data_(nullptr),
total_preparse_skipped_(0), total_preparse_skipped_(0),
pre_parse_timer_(NULL), pre_parse_timer_(NULL),
parsing_on_main_thread_(true) { parsing_on_main_thread_(true) {
...@@ -669,7 +668,8 @@ Parser::Parser(ParseInfo* info) ...@@ -669,7 +668,8 @@ Parser::Parser(ParseInfo* info)
? FunctionLiteral::kShouldLazyCompile ? FunctionLiteral::kShouldLazyCompile
: FunctionLiteral::kShouldEagerCompile); : FunctionLiteral::kShouldEagerCompile);
set_allow_lazy(FLAG_lazy && info->allow_lazy_parsing() && set_allow_lazy(FLAG_lazy && info->allow_lazy_parsing() &&
!info->is_native() && info->extension() == nullptr); !info->is_native() && info->extension() == nullptr &&
can_compile_lazily);
set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); set_allow_natives(FLAG_allow_natives_syntax || info->is_native());
set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() &&
info->isolate()->is_tail_call_elimination_enabled()); info->isolate()->is_tail_call_elimination_enabled());
......
...@@ -247,11 +247,12 @@ class Parser : public ParserBase<Parser> { ...@@ -247,11 +247,12 @@ class Parser : public ParserBase<Parser> {
return compile_options_; return compile_options_;
} }
bool consume_cached_parse_data() const { bool consume_cached_parse_data() const {
return compile_options_ == ScriptCompiler::kConsumeParserCache && return allow_lazy() &&
cached_parse_data_ != NULL; compile_options_ == ScriptCompiler::kConsumeParserCache;
} }
bool produce_cached_parse_data() const { bool produce_cached_parse_data() const {
return compile_options_ == ScriptCompiler::kProduceParserCache; return allow_lazy() &&
compile_options_ == ScriptCompiler::kProduceParserCache;
} }
void ParseModuleItemList(ZoneList<Statement*>* body, bool* ok); void ParseModuleItemList(ZoneList<Statement*>* body, bool* ok);
......
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