 Chromium Code Reviews
 Chromium Code Reviews Issue 366153002:
  Add script streaming API  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
    
  
    Issue 366153002:
  Add script streaming API  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge| Index: src/background-parsing-task.cc | 
| diff --git a/src/background-parsing-task.cc b/src/background-parsing-task.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..fc6630f680dd2d1b3e2f399008e615915ef0b22e | 
| --- /dev/null | 
| +++ b/src/background-parsing-task.cc | 
| @@ -0,0 +1,75 @@ | 
| +// Copyright 2014 the V8 project authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include "src/background-parsing-task.h" | 
| + | 
| +#include "src/parser.h" | 
| + | 
| +namespace v8 { | 
| +namespace internal { | 
| + | 
| +static const int kBackgroundParserThreadStackSize = 64 * KB; | 
| 
jochen (gone - plz use gerrit)
2014/09/09 08:06:20
should this be FLAG_stack_size
 
marja
2014/09/09 11:46:30
Done.
 | 
| + | 
| +StreamedSource::~StreamedSource() { | 
| + delete source_stream; | 
| + delete cached_data; | 
| + delete info; | 
| + delete parser; | 
| +} | 
| + | 
| + | 
| +BackgroundParsingTask::BackgroundParsingTask( | 
| + StreamedSource* source, ScriptCompiler::CompileOptions options, | 
| + Isolate* isolate) | 
| + : source_(source), options_(options) { | 
| + // Prepare the data for the internalization phase and compilation phase, which | 
| + // will happen in the main thread after parsing. | 
| + source->info = new i::CompilationInfoWithZone(source->source_stream, | 
| + source->encoding, isolate); | 
| + source->info->MarkAsGlobal(); | 
| + | 
| + // We don't set the context to the CompilationInfo yet, because the background | 
| + // thread cannot do anything with it anyway. We set it just before compilation | 
| + // on the foreground thread. | 
| + DCHECK(options == ScriptCompiler::kProduceParserCache || | 
| + options == ScriptCompiler::kProduceCodeCache || | 
| + options == ScriptCompiler::kNoCompileOptions); | 
| + source->allow_lazy = | 
| + !i::Compiler::DebuggerWantsEagerCompilation(source->info); | 
| + source->hash_seed = isolate->heap()->HashSeed(); | 
| +} | 
| + | 
| + | 
| +void BackgroundParsingTask::Run() { | 
| + DisallowHeapAllocation no_allocation; | 
| + DisallowHandleAllocation no_handles; | 
| + DisallowHandleDereference no_deref; | 
| + | 
| + ScriptData* script_data = NULL; | 
| + if (options_ == ScriptCompiler::kProduceParserCache || | 
| + options_ == ScriptCompiler::kProduceCodeCache) { | 
| + source_->info->SetCachedData(&script_data, options_); | 
| + } | 
| + | 
| + uintptr_t limit = | 
| + reinterpret_cast<uintptr_t>(&limit) - kBackgroundParserThreadStackSize; | 
| + Parser::ParseInfo parse_info = {limit, source_->hash_seed, | 
| + &source_->unicode_cache}; | 
| + | 
| + // Parser needs to stay alive for finalizing the parsing on the main | 
| + // thread. Passing &parse_info is OK because Parser doesn't store it. | 
| + source_->parser = new Parser(source_->info, &parse_info); | 
| + source_->parser->set_allow_lazy(source_->allow_lazy); | 
| + source_->parser->ParseOnBackground(); | 
| + | 
| + if (script_data != NULL) { | 
| + source_->cached_data = new ScriptCompiler::CachedData( | 
| + script_data->data(), script_data->length(), | 
| + ScriptCompiler::CachedData::BufferOwned); | 
| + script_data->ReleaseDataOwnership(); | 
| + delete script_data; | 
| + } | 
| +} | 
| +} | 
| 
jochen (gone - plz use gerrit)
2014/09/09 08:06:20
nit // namespace internal
also, empty line above
 
marja
2014/09/09 11:46:30
git cl format removes the empty line if I put one
 
marja
2014/09/09 11:46:30
Counter nit: this seems pretty customary:
$ git g
 | 
| +} // namespace v8::internal | 
| 
jochen (gone - plz use gerrit)
2014/09/09 08:06:20
// namespace v8
 |