Commit 84b07ec2 authored by jochen's avatar jochen Committed by Commit bot

Create a character stream and hook it up to the parse info

Also make it possible to use the background parser from a character
stream. The External{One,Two}ByteStringUtf16CharacterStreams work both
on foreground and background threads.

BUG=v8:5215
R=marja@chromium.org,vogelheim@chromium.org

Review-Url: https://codereview.chromium.org/2195603002
Cr-Commit-Position: refs/heads/master@{#38162}
parent dc78fefb
......@@ -8,6 +8,7 @@
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/parsing/parser.h"
#include "src/parsing/scanner-character-streams.h"
#include "src/unicode-cache.h"
#include "src/zone.h"
......@@ -18,7 +19,8 @@ CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate,
Handle<JSFunction> function)
: isolate_(isolate),
function_(Handle<JSFunction>::cast(
isolate_->global_handles()->Create(*function))) {}
isolate_->global_handles()->Create(*function))),
can_parse_on_background_thread_(false) {}
CompilerDispatcherJob::~CompilerDispatcherJob() {
DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
......@@ -28,11 +30,30 @@ CompilerDispatcherJob::~CompilerDispatcherJob() {
void CompilerDispatcherJob::PrepareToParseOnMainThread() {
DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
DCHECK(status_ == CompileJobStatus::kInitial);
HandleScope scope(isolate_);
unicode_cache_.reset(new UnicodeCache());
zone_.reset(new Zone(isolate_->allocator()));
Handle<SharedFunctionInfo> shared(function_->shared(), isolate_);
Handle<Script> script(Script::cast(shared->script()), isolate_);
Handle<String> source(String::cast(script->source()), isolate_);
if (source->IsExternalTwoByteString()) {
can_parse_on_background_thread_ = true;
character_stream_.reset(new ExternalTwoByteStringUtf16CharacterStream(
Handle<ExternalTwoByteString>::cast(source), shared->start_position(),
shared->end_position()));
} else if (source->IsExternalOneByteString()) {
can_parse_on_background_thread_ = true;
character_stream_.reset(new ExternalOneByteStringUtf16CharacterStream(
Handle<ExternalOneByteString>::cast(source), shared->start_position(),
shared->end_position()));
} else {
can_parse_on_background_thread_ = false;
character_stream_.reset(new GenericStringUtf16CharacterStream(
source, shared->start_position(), shared->end_position()));
}
parse_info_.reset(new ParseInfo(zone_.get()));
parse_info_->set_isolate(isolate_);
// TODO(jochen): We need to hook up a fake source stream here.
parse_info_->set_character_stream(character_stream_.get());
parse_info_->set_hash_seed(isolate_->heap()->HashSeed());
parse_info_->set_unicode_cache(unicode_cache_.get());
status_ = CompileJobStatus::kReadyToParse;
......
......@@ -18,6 +18,7 @@ class Isolate;
class JSFunction;
class ParseInfo;
class UnicodeCache;
class Utf16CharacterStream;
class Zone;
enum class CompileJobStatus {
......@@ -43,8 +44,11 @@ class CompilerDispatcherJob {
// Members required for parsing.
std::unique_ptr<UnicodeCache> unicode_cache_;
std::unique_ptr<Zone> zone_;
std::unique_ptr<Utf16CharacterStream> character_stream_;
std::unique_ptr<ParseInfo> parse_info_;
bool can_parse_on_background_thread_;
DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherJob);
};
......
......@@ -46,6 +46,7 @@ ParseInfo::ParseInfo(Zone* zone)
flags_(0),
source_stream_(nullptr),
source_stream_encoding_(ScriptCompiler::StreamedSource::ONE_BYTE),
character_stream_(nullptr),
extension_(nullptr),
compile_options_(ScriptCompiler::kNoCompileOptions),
script_scope_(nullptr),
......@@ -828,7 +829,8 @@ Parser::Parser(ParseInfo* info)
// Even though we were passed ParseInfo, we should not store it in
// Parser - this makes sure that Isolate is not accidentally accessed via
// ParseInfo during background parsing.
DCHECK(!info->script().is_null() || info->source_stream() != NULL);
DCHECK(!info->script().is_null() || info->source_stream() != nullptr ||
info->character_stream() != nullptr);
set_allow_lazy(info->allow_lazy_parsing());
set_allow_natives(FLAG_allow_natives_syntax || info->is_native());
set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() &&
......@@ -5476,10 +5478,18 @@ void Parser::ParseOnBackground(ParseInfo* info) {
CompleteParserRecorder recorder;
if (produce_cached_parse_data()) log_ = &recorder;
DCHECK(info->source_stream() != NULL);
ExternalStreamingStream stream(info->source_stream(),
info->source_stream_encoding());
scanner_.Initialize(&stream);
std::unique_ptr<Utf16CharacterStream> stream;
Utf16CharacterStream* stream_ptr;
if (info->character_stream()) {
DCHECK(info->source_stream() == nullptr);
stream_ptr = info->character_stream();
} else {
DCHECK(info->character_stream() == nullptr);
stream.reset(new ExternalStreamingStream(info->source_stream(),
info->source_stream_encoding()));
stream_ptr = stream.get();
}
scanner_.Initialize(stream_ptr);
DCHECK(info->context().is_null() || info->context()->IsNativeContext());
// When streaming, we don't know the length of the source until we have parsed
......
......@@ -85,6 +85,11 @@ class ParseInfo {
source_stream_encoding_ = source_stream_encoding;
}
Utf16CharacterStream* character_stream() const { return character_stream_; }
void set_character_stream(Utf16CharacterStream* character_stream) {
character_stream_ = character_stream;
}
v8::Extension* extension() { return extension_; }
void set_extension(v8::Extension* extension) { extension_ = extension; }
......@@ -175,6 +180,7 @@ class ParseInfo {
unsigned flags_;
ScriptCompiler::ExternalSourceStream* source_stream_;
ScriptCompiler::StreamedSource::Encoding source_stream_encoding_;
Utf16CharacterStream* character_stream_;
v8::Extension* extension_;
ScriptCompiler::CompileOptions compile_options_;
Scope* script_scope_;
......
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