Commit 5f2f418d authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[scanner] Rewrite character streams by separating underlying bytestreams from buffering.

Additionally now we only scan over flat heap strings.

Change-Id: Ic449b19aecd7fc3f283a04a3df6a39772d471565
Reviewed-on: https://chromium-review.googlesource.com/1125854Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54224}
parent 6bdfeea6
...@@ -134,7 +134,7 @@ void UnoptimizedCompileJob::PrepareOnMainThread(Isolate* isolate) { ...@@ -134,7 +134,7 @@ void UnoptimizedCompileJob::PrepareOnMainThread(Isolate* isolate) {
Handle<String> source(String::cast(script->source()), isolate); Handle<String> source(String::cast(script->source()), isolate);
if (source->IsExternalTwoByteString() || source->IsExternalOneByteString()) { if (source->IsExternalTwoByteString() || source->IsExternalOneByteString()) {
std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For( std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(
source, shared_->StartPosition(), shared_->EndPosition())); isolate, source, shared_->StartPosition(), shared_->EndPosition()));
parse_info_->set_character_stream(std::move(stream)); parse_info_->set_character_stream(std::move(stream));
} else { } else {
source = String::Flatten(isolate, source); source = String::Flatten(isolate, source);
...@@ -192,7 +192,7 @@ void UnoptimizedCompileJob::PrepareOnMainThread(Isolate* isolate) { ...@@ -192,7 +192,7 @@ void UnoptimizedCompileJob::PrepareOnMainThread(Isolate* isolate) {
} }
wrapper_ = isolate->global_handles()->Create(*wrapper); wrapper_ = isolate->global_handles()->Create(*wrapper);
std::unique_ptr<Utf16CharacterStream> stream( std::unique_ptr<Utf16CharacterStream> stream(
ScannerStream::For(wrapper_, shared_->StartPosition() - offset, ScannerStream::For(isolate, wrapper_, shared_->StartPosition() - offset,
shared_->EndPosition() - offset)); shared_->EndPosition() - offset));
parse_info_->set_character_stream(std::move(stream)); parse_info_->set_character_stream(std::move(stream));
} }
......
...@@ -25,9 +25,9 @@ bool ParseProgram(ParseInfo* info, Isolate* isolate) { ...@@ -25,9 +25,9 @@ bool ParseProgram(ParseInfo* info, Isolate* isolate) {
// Create a character stream for the parser. // Create a character stream for the parser.
Handle<String> source(String::cast(info->script()->source()), isolate); Handle<String> source(String::cast(info->script()->source()), isolate);
source = String::Flatten(isolate, source);
isolate->counters()->total_parse_size()->Increment(source->length()); isolate->counters()->total_parse_size()->Increment(source->length());
std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(source)); std::unique_ptr<Utf16CharacterStream> stream(
ScannerStream::For(isolate, source));
info->set_character_stream(std::move(stream)); info->set_character_stream(std::move(stream));
Parser parser(info); Parser parser(info);
...@@ -60,10 +60,10 @@ bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info, ...@@ -60,10 +60,10 @@ bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
// Create a character stream for the parser. // Create a character stream for the parser.
Handle<String> source(String::cast(info->script()->source()), isolate); Handle<String> source(String::cast(info->script()->source()), isolate);
source = String::Flatten(isolate, source);
isolate->counters()->total_parse_size()->Increment(source->length()); isolate->counters()->total_parse_size()->Increment(source->length());
std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For( std::unique_ptr<Utf16CharacterStream> stream(
source, shared_info->StartPosition(), shared_info->EndPosition())); ScannerStream::For(isolate, source, shared_info->StartPosition(),
shared_info->EndPosition()));
info->set_character_stream(std::move(stream)); info->set_character_stream(std::move(stream));
VMState<PARSER> state(isolate); VMState<PARSER> state(isolate);
......
This diff is collapsed.
...@@ -19,9 +19,9 @@ class String; ...@@ -19,9 +19,9 @@ class String;
class V8_EXPORT_PRIVATE ScannerStream { class V8_EXPORT_PRIVATE ScannerStream {
public: public:
static Utf16CharacterStream* For(Handle<String> data); static Utf16CharacterStream* For(Isolate* isolate, Handle<String> data);
static Utf16CharacterStream* For(Handle<String> data, int start_pos, static Utf16CharacterStream* For(Isolate* isolate, Handle<String> data,
int end_pos); int start_pos, int end_pos);
static Utf16CharacterStream* For( static Utf16CharacterStream* For(
ScriptCompiler::ExternalSourceStream* source_stream, ScriptCompiler::ExternalSourceStream* source_stream,
ScriptCompiler::StreamedSource::Encoding encoding, ScriptCompiler::StreamedSource::Encoding encoding,
......
...@@ -315,7 +315,7 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length, ...@@ -315,7 +315,7 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length,
i::Handle<i::String> uc16_string( i::Handle<i::String> uc16_string(
factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked()); factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked());
std::unique_ptr<i::Utf16CharacterStream> uc16_stream( std::unique_ptr<i::Utf16CharacterStream> uc16_stream(
i::ScannerStream::For(uc16_string, start, end)); i::ScannerStream::For(isolate, uc16_string, start, end));
TestCharacterStream(one_byte_source, uc16_stream.get(), length, start, end); TestCharacterStream(one_byte_source, uc16_stream.get(), length, start, end);
// This avoids the GC from trying to free a stack allocated resource. // This avoids the GC from trying to free a stack allocated resource.
...@@ -335,7 +335,7 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length, ...@@ -335,7 +335,7 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length,
factory->NewExternalStringFromOneByte(&one_byte_resource) factory->NewExternalStringFromOneByte(&one_byte_resource)
.ToHandleChecked()); .ToHandleChecked());
std::unique_ptr<i::Utf16CharacterStream> one_byte_stream( std::unique_ptr<i::Utf16CharacterStream> one_byte_stream(
i::ScannerStream::For(ext_one_byte_string, start, end)); i::ScannerStream::For(isolate, ext_one_byte_string, start, end));
TestCharacterStream(one_byte_source, one_byte_stream.get(), length, start, TestCharacterStream(one_byte_source, one_byte_stream.get(), length, start,
end); end);
// This avoids the GC from trying to free a stack allocated resource. // This avoids the GC from trying to free a stack allocated resource.
...@@ -347,7 +347,7 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length, ...@@ -347,7 +347,7 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length,
// 1-byte generic i::String // 1-byte generic i::String
{ {
std::unique_ptr<i::Utf16CharacterStream> string_stream( std::unique_ptr<i::Utf16CharacterStream> string_stream(
i::ScannerStream::For(one_byte_string, start, end)); i::ScannerStream::For(isolate, one_byte_string, start, end));
TestCharacterStream(one_byte_source, string_stream.get(), length, start, TestCharacterStream(one_byte_source, string_stream.get(), length, start,
end); end);
} }
...@@ -357,7 +357,7 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length, ...@@ -357,7 +357,7 @@ void TestCharacterStreams(const char* one_byte_source, unsigned length,
i::Handle<i::String> two_byte_string = i::Handle<i::String> two_byte_string =
factory->NewStringFromTwoByte(two_byte_vector).ToHandleChecked(); factory->NewStringFromTwoByte(two_byte_vector).ToHandleChecked();
std::unique_ptr<i::Utf16CharacterStream> two_byte_string_stream( std::unique_ptr<i::Utf16CharacterStream> two_byte_string_stream(
i::ScannerStream::For(two_byte_string, start, end)); i::ScannerStream::For(isolate, two_byte_string, start, end));
TestCharacterStream(one_byte_source, two_byte_string_stream.get(), length, TestCharacterStream(one_byte_source, two_byte_string_stream.get(), length,
start, end); start, end);
} }
......
...@@ -1174,7 +1174,7 @@ void TestParserSyncWithFlags(i::Handle<i::String> source, ...@@ -1174,7 +1174,7 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
if (test_preparser) { if (test_preparser) {
i::Scanner scanner(isolate->unicode_cache()); i::Scanner scanner(isolate->unicode_cache());
std::unique_ptr<i::Utf16CharacterStream> stream( std::unique_ptr<i::Utf16CharacterStream> stream(
i::ScannerStream::For(source)); i::ScannerStream::For(isolate, source));
i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
i::AstValueFactory ast_value_factory( i::AstValueFactory ast_value_factory(
&zone, CcTest::i_isolate()->ast_string_constants(), &zone, CcTest::i_isolate()->ast_string_constants(),
......
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