Chromium Code Reviews| Index: src/parser-thread.cc |
| diff --git a/src/parser-thread.cc b/src/parser-thread.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5fa0f9134ec45447823c0b9c7b78b97182303227 |
| --- /dev/null |
| +++ b/src/parser-thread.cc |
| @@ -0,0 +1,110 @@ |
| +// Copyright 2014 the V8 project authors. All rights reserved. |
| +// Redistribution and use in source and binary forms, with or without |
| +// modification, are permitted provided that the following conditions are |
| +// met: |
| +// |
| +// * Redistributions of source code must retain the above copyright |
| +// notice, this list of conditions and the following disclaimer. |
| +// * Redistributions in binary form must reproduce the above |
| +// copyright notice, this list of conditions and the following |
| +// disclaimer in the documentation and/or other materials provided |
| +// with the distribution. |
| +// * Neither the name of Google Inc. nor the names of its |
| +// contributors may be used to endorse or promote products derived |
| +// from this software without specific prior written permission. |
| +// |
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + |
| +#include "parser-thread.h" |
| + |
| +#include "parser.h" |
| +#include "preparse-data.h" |
| +#include "scanner-character-streams.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| + |
| +static const int kFastParserThreadStackSize = 64 * KB; |
| + |
| +FastParserThread::FastParserThread(Utf16CharacterStream* stream, |
| + bool allow_harmony_scoping, |
| + bool allow_modules, |
| + bool allow_natives_syntax, |
| + bool allow_generators, |
| + bool allow_for_of, |
| + bool allow_harmony_numeric_literals) |
| + : Thread( |
| + Thread::Options("v8::FastParserThread", kFastParserThreadStackSize)), |
| + stream_(stream), |
| + result_(PreParser::kPreParseSuccess), |
| + allow_harmony_scoping_(allow_harmony_scoping), |
| + allow_modules_(allow_modules), |
| + allow_natives_syntax_(allow_natives_syntax), |
| + allow_generators_(allow_generators), |
| + allow_for_of_(allow_for_of), |
| + allow_harmony_numeric_literals_(allow_harmony_numeric_literals) {} |
| + |
| + |
| +void FastParserThread::Produce(int start, int end, int literals, int properties, |
| + StrictMode strict_mode) { |
| + mutex_.Lock(); |
|
Sven Panne
2014/04/16 11:55:35
Use LockGuard here...
marja
2014/04/16 14:33:10
Done.
|
| + LazyFunction function(start, end, literals, properties, strict_mode); |
| + data_.Enqueue(function); |
| + have_data_.NotifyOne(); |
| + mutex_.Unlock(); |
| +} |
| + |
| + |
| +void FastParserThread::Consume(int* start, int* end, int* literals, |
| + int* properties, StrictMode* strict_mode) { |
| + mutex_.Lock(); |
|
Sven Panne
2014/04/16 11:55:35
... and here.
marja
2014/04/16 14:33:10
Done.
|
| + if (data_.IsEmpty()) |
| + have_data_.Wait(&mutex_); // Implicitly locks and unlocks the mutex. |
| + ASSERT(!data_.IsEmpty()); |
| + LazyFunction function; |
| + data_.Dequeue(&function); |
| + mutex_.Unlock(); |
| + *start = function.start; |
| + *end = function.end; |
| + *literals = function.literals; |
| + *properties = function.properties; |
| + *strict_mode = function.strict_mode; |
| +} |
| + |
| + |
| +void FastParserThread::Run() { |
| + DisallowHeapAllocation no_allocation; |
| + DisallowHandleAllocation no_handles; |
| + DisallowHandleDereference no_deref; |
| + UnicodeCache unicode_cache; |
| + Scanner scanner(&unicode_cache); |
| + uintptr_t limit = |
| + reinterpret_cast<uintptr_t>(&limit) - kFastParserThreadStackSize; |
| + PreParser preparser(&scanner, &recorder_, limit, this); |
| + preparser.set_allow_lazy(true); |
| + preparser.set_allow_harmony_scoping(allow_harmony_scoping_); |
| + preparser.set_allow_modules(allow_modules_); |
| + preparser.set_allow_natives_syntax(allow_natives_syntax_); |
| + preparser.set_allow_generators(allow_generators_); |
| + preparser.set_allow_for_of(allow_for_of_); |
| + preparser.set_allow_harmony_numeric_literals(allow_harmony_numeric_literals_); |
| + scanner.Initialize(stream_); |
| + result_ = preparser.PreParseProgram(); |
| + |
| + // Queue a dummy data element, so that the Parser doesn't wait forever if it |
| + // expects the thread to produce more data than it will. (For example, when |
| + // the thread parses a function and encounters an error.) |
| + Produce(-1, -1, -1, -1, SLOPPY); |
| +} |
| + |
| +} } // namespace v8::internal |