2014-09-12 09:12:08 +00:00
|
|
|
// 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"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
BackgroundParsingTask::BackgroundParsingTask(
|
|
|
|
StreamedSource* source, ScriptCompiler::CompileOptions options,
|
|
|
|
int stack_size, Isolate* isolate)
|
2015-03-09 14:51:13 +00:00
|
|
|
: source_(source), stack_size_(stack_size) {
|
2014-09-12 09:12:08 +00:00
|
|
|
// 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);
|
2015-01-19 14:29:01 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
// Prepare the data for the internalization phase and compilation phase, which
|
|
|
|
// will happen in the main thread after parsing.
|
|
|
|
Zone* zone = new Zone();
|
|
|
|
ParseInfo* info = new ParseInfo(zone);
|
|
|
|
source->zone.Reset(zone);
|
|
|
|
source->info.Reset(info);
|
|
|
|
info->set_isolate(isolate);
|
|
|
|
info->set_source_stream(source->source_stream.get());
|
|
|
|
info->set_source_stream_encoding(source->encoding);
|
|
|
|
info->set_hash_seed(isolate->heap()->HashSeed());
|
|
|
|
info->set_global();
|
|
|
|
info->set_unicode_cache(&source_->unicode_cache);
|
|
|
|
|
|
|
|
bool disable_lazy = Compiler::DebuggerWantsEagerCompilation(isolate);
|
|
|
|
if (disable_lazy && options == ScriptCompiler::kProduceParserCache) {
|
2015-01-19 14:29:01 +00:00
|
|
|
// Producing cached data while parsing eagerly is not supported.
|
2015-03-09 14:51:13 +00:00
|
|
|
options = ScriptCompiler::kNoCompileOptions;
|
2015-01-19 14:29:01 +00:00
|
|
|
}
|
2015-03-09 14:51:13 +00:00
|
|
|
|
|
|
|
info->set_compile_options(options);
|
|
|
|
info->set_allow_lazy_parsing(!disable_lazy);
|
2014-09-12 09:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BackgroundParsingTask::Run() {
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
DisallowHandleAllocation no_handles;
|
|
|
|
DisallowHandleDereference no_deref;
|
|
|
|
|
|
|
|
ScriptData* script_data = NULL;
|
2015-03-09 14:51:13 +00:00
|
|
|
ScriptCompiler::CompileOptions options = source_->info->compile_options();
|
|
|
|
if (options == ScriptCompiler::kProduceParserCache ||
|
|
|
|
options == ScriptCompiler::kProduceCodeCache) {
|
|
|
|
source_->info->set_cached_data(&script_data);
|
2014-09-12 09:12:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 11:56:57 +00:00
|
|
|
uintptr_t stack_limit =
|
|
|
|
reinterpret_cast<uintptr_t>(&stack_limit) - stack_size_ * KB;
|
2014-09-12 09:12:08 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
source_->info->set_stack_limit(stack_limit);
|
2014-09-12 09:12:08 +00:00
|
|
|
// Parser needs to stay alive for finalizing the parsing on the main
|
|
|
|
// thread. Passing &parse_info is OK because Parser doesn't store it.
|
2015-03-09 14:51:13 +00:00
|
|
|
source_->parser.Reset(new Parser(source_->info.get()));
|
2015-02-12 13:02:30 +00:00
|
|
|
source_->parser->ParseOnBackground(source_->info.get());
|
2014-09-12 09:12:08 +00:00
|
|
|
|
|
|
|
if (script_data != NULL) {
|
|
|
|
source_->cached_data.Reset(new ScriptCompiler::CachedData(
|
|
|
|
script_data->data(), script_data->length(),
|
|
|
|
ScriptCompiler::CachedData::BufferOwned));
|
|
|
|
script_data->ReleaseDataOwnership();
|
|
|
|
delete script_data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace v8::internal
|