Chromium Code Reviews| Index: src/compiler.cc |
| diff --git a/src/compiler.cc b/src/compiler.cc |
| index b46a201240ace18de63c56e60af31b0a2aee4130..5ef8f948704bace8354ff2f8ee0e9fb37512cd1a 100644 |
| --- a/src/compiler.cc |
| +++ b/src/compiler.cc |
| @@ -47,6 +47,7 @@ ScriptData::ScriptData(const byte* data, int length) |
| CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone) |
| : flags_(kThisHasUses), |
| script_(script), |
| + source_stream_(NULL), |
| osr_ast_id_(BailoutId::None()), |
| parameter_count_(0), |
| optimization_id_(-1), |
| @@ -73,6 +74,7 @@ CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, |
| : flags_(kLazy | kThisHasUses), |
| shared_info_(shared_info), |
| script_(Handle<Script>(Script::cast(shared_info->script()))), |
| + source_stream_(NULL), |
| osr_ast_id_(BailoutId::None()), |
| parameter_count_(0), |
| optimization_id_(-1), |
| @@ -87,6 +89,7 @@ CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) |
| closure_(closure), |
| shared_info_(Handle<SharedFunctionInfo>(closure->shared())), |
| script_(Handle<Script>(Script::cast(shared_info_->script()))), |
| + source_stream_(NULL), |
| context_(closure->context()), |
| osr_ast_id_(BailoutId::None()), |
| parameter_count_(0), |
| @@ -100,6 +103,7 @@ CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) |
| CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, |
| Zone* zone) |
| : flags_(kLazy | kThisHasUses), |
| + source_stream_(NULL), |
| osr_ast_id_(BailoutId::None()), |
| parameter_count_(0), |
| optimization_id_(-1), |
| @@ -110,6 +114,19 @@ CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, |
| } |
| +CompilationInfo::CompilationInfo(ScriptCompiler::ExternalSourceStream* stream, |
| + Isolate* isolate, Zone* zone) |
| + : flags_(kThisHasUses), |
| + source_stream_(stream), |
| + osr_ast_id_(BailoutId::None()), |
| + parameter_count_(0), |
| + optimization_id_(-1), |
| + ast_value_factory_(NULL), |
| + ast_value_factory_owned_(false) { |
| + Initialize(isolate, BASE, zone); |
| +} |
| + |
| + |
| void CompilationInfo::Initialize(Isolate* isolate, |
| Mode mode, |
| Zone* zone) { |
| @@ -136,7 +153,9 @@ void CompilationInfo::Initialize(Isolate* isolate, |
| } |
| mode_ = mode; |
| abort_due_to_dependency_ = false; |
| - if (script_->type()->value() == Script::TYPE_NATIVE) MarkAsNative(); |
| + if (!script_.is_null() && script_->type()->value() == Script::TYPE_NATIVE) { |
| + MarkAsNative(); |
| + } |
| if (isolate_->debug()->is_active()) MarkAsDebug(); |
| if (FLAG_context_specialization) MarkAsContextSpecializing(); |
| if (FLAG_turbo_types) MarkAsTypingEnabled(); |
| @@ -810,13 +829,6 @@ void Compiler::CompileForLiveEdit(Handle<Script> script) { |
| } |
| -static bool DebuggerWantsEagerCompilation(CompilationInfo* info, |
| - bool allow_lazy_without_ctx = false) { |
| - return LiveEditFunctionTracker::IsActive(info->isolate()) || |
| - (info->isolate()->DebuggerHasBreakPoints() && !allow_lazy_without_ctx); |
| -} |
| - |
| - |
| static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { |
| Isolate* isolate = info->isolate(); |
| PostponeInterruptsScope postpone(isolate); |
| @@ -831,28 +843,34 @@ static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { |
| DCHECK(info->is_eval() || info->is_global()); |
| - bool parse_allow_lazy = |
| - (info->compile_options() == ScriptCompiler::kConsumeParserCache || |
| - String::cast(script->source())->length() > FLAG_min_preparse_length) && |
| - !DebuggerWantsEagerCompilation(info); |
| - |
| - if (!parse_allow_lazy && |
| - (info->compile_options() == ScriptCompiler::kProduceParserCache || |
| - info->compile_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. We cannot use |
| - // the existing data, since it won't contain all the symbols we need for |
| - // eager parsing. In addition, it doesn't make sense to produce the data |
| - // when parsing eagerly. That data would contain all symbols, but no |
| - // functions, so it cannot be used to aid lazy parsing later. |
| - info->SetCachedData(NULL, ScriptCompiler::kNoCompileOptions); |
| - } |
| - |
| Handle<SharedFunctionInfo> result; |
| { VMState<COMPILER> state(info->isolate()); |
| - if (!Parser::Parse(info, parse_allow_lazy)) { |
| - return Handle<SharedFunctionInfo>::null(); |
| + if (info->function() == NULL) { |
| + // Parse the script if needed (if it's already parsed, function() returns |
| + // non-NULL. |
| + bool parse_allow_lazy = |
| + (info->compile_options() == ScriptCompiler::kConsumeParserCache || |
| + String::cast(script->source())->length() > |
| + FLAG_min_preparse_length) && |
| + !Compiler::DebuggerWantsEagerCompilation(info); |
| + |
| + if (!parse_allow_lazy && |
| + (info->compile_options() == ScriptCompiler::kProduceParserCache || |
| + info->compile_options() == ScriptCompiler::kConsumeParserCache)) { |
| + // We are going to parse eagerly, but we either 1) have cached data |
| + // produced |
|
Sven Panne
2014/09/01 09:07:46
Funny spacing.
marja
2014/09/01 11:58:17
Done.
|
| + // by lazy parsing or 2) are asked to generate cached data. We cannot |
| + // use |
| + // the existing data, since it won't contain all the symbols we need for |
| + // eager parsing. In addition, it doesn't make sense to produce the data |
| + // when parsing eagerly. That data would contain all symbols, but no |
| + // functions, so it cannot be used to aid lazy parsing later. |
| + info->SetCachedData(NULL, ScriptCompiler::kNoCompileOptions); |
| + } |
| + if (!Parser::Parse(info, parse_allow_lazy)) { |
| + return Handle<SharedFunctionInfo>::null(); |
| + } |
| } |
| FunctionLiteral* lit = info->function(); |
| @@ -899,7 +917,8 @@ static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { |
| SetExpectedNofPropertiesFromEstimate(result, |
| lit->expected_property_count()); |
| - script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); |
| + if (!script.is_null()) |
| + script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); |
| live_edit_tracker.RecordFunctionInfo(result, lit, info->zone()); |
| } |
| @@ -1056,6 +1075,24 @@ Handle<SharedFunctionInfo> Compiler::CompileScript( |
| } |
| +Handle<SharedFunctionInfo> Compiler::CompileStreamedScript( |
| + CompilationInfo* info, int source_length) { |
| + Isolate* isolate = info->isolate(); |
| + isolate->counters()->total_load_size()->Increment(source_length); |
| + isolate->counters()->total_compile_size()->Increment(source_length); |
| + |
| + // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the |
| + // real code caching lands, streaming needs to be adapted to use it. |
| + |
| + if (FLAG_use_strict) info->SetStrictMode(STRICT); |
| + |
| + Handle<SharedFunctionInfo> result = CompileToplevel(info); |
| + |
| + if (result.is_null()) isolate->ReportPendingMessages(); |
| + return result; |
| +} |
| + |
| + |
| Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo( |
| FunctionLiteral* literal, Handle<Script> script, |
| CompilationInfo* outer_info) { |
| @@ -1355,6 +1392,13 @@ void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
| } |
| +bool Compiler::DebuggerWantsEagerCompilation(CompilationInfo* info, |
| + bool allow_lazy_without_ctx) { |
| + return LiveEditFunctionTracker::IsActive(info->isolate()) || |
| + (info->isolate()->DebuggerHasBreakPoints() && !allow_lazy_without_ctx); |
| +} |
| + |
| + |
| CompilationPhase::CompilationPhase(const char* name, CompilationInfo* info) |
| : name_(name), info_(info), zone_(info->isolate()) { |
| if (FLAG_hydrogen_stats) { |