Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Unified Diff: src/compiler.cc

Issue 366153002: Add script streaming API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased again? Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler.h ('k') | src/parser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index d43177e07d060a66144e8d50daa745422c581c55..70a2c95b1dae24cba551852051511c915f8c01f1 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),
@@ -59,6 +60,7 @@ CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone)
CompilationInfo::CompilationInfo(Isolate* isolate, Zone* zone)
: flags_(kThisHasUses),
script_(Handle<Script>::null()),
+ source_stream_(NULL),
osr_ast_id_(BailoutId::None()),
parameter_count_(0),
optimization_id_(-1),
@@ -73,6 +75,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 +90,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 +104,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 +115,22 @@ CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate,
}
+CompilationInfo::CompilationInfo(
+ ScriptCompiler::ExternalSourceStream* stream,
+ ScriptCompiler::StreamedSource::Encoding encoding, Isolate* isolate,
+ Zone* zone)
+ : flags_(kThisHasUses),
+ source_stream_(stream),
+ source_stream_encoding_(encoding),
+ 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 +157,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_inlining) MarkAsInliningEnabled();
@@ -810,13 +833,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 +847,30 @@ 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() is
+ // 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 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.
+ info->SetCachedData(NULL, ScriptCompiler::kNoCompileOptions);
+ }
+ if (!Parser::Parse(info, parse_allow_lazy)) {
+ return Handle<SharedFunctionInfo>::null();
+ }
}
FunctionLiteral* lit = info->function();
@@ -898,7 +916,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());
}
@@ -1055,6 +1074,19 @@ 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);
+
+ if (FLAG_use_strict) info->SetStrictMode(STRICT);
+ // 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.
+ return CompileToplevel(info);
+}
+
+
Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(
FunctionLiteral* literal, Handle<Script> script,
CompilationInfo* outer_info) {
@@ -1362,6 +1394,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) {
« no previous file with comments | « src/compiler.h ('k') | src/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698