Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: src/parser-thread.cc

Issue 214883002: Two-threaded parser (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: code review (svenpanne) Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include "parser-thread.h"
29
30 #include "parser.h"
31 #include "preparse-data.h"
32 #include "scanner-character-streams.h"
33
34 namespace v8 {
35 namespace internal {
36
37 static const int kFastParserThreadStackSize = 64 * KB;
38
39 FastParserThread::FastParserThread(Utf16CharacterStream* stream,
40 bool allow_harmony_scoping,
41 bool allow_modules,
42 bool allow_natives_syntax,
43 bool allow_generators,
44 bool allow_for_of,
45 bool allow_harmony_numeric_literals)
46 : Thread(
47 Thread::Options("v8::FastParserThread", kFastParserThreadStackSize)),
48 stream_(stream),
49 result_(PreParser::kPreParseSuccess),
50 allow_harmony_scoping_(allow_harmony_scoping),
51 allow_modules_(allow_modules),
52 allow_natives_syntax_(allow_natives_syntax),
53 allow_generators_(allow_generators),
54 allow_for_of_(allow_for_of),
55 allow_harmony_numeric_literals_(allow_harmony_numeric_literals) {}
56
57
58 void FastParserThread::Produce(int start, int end, int literals, int properties,
59 StrictMode strict_mode) {
60 mutex_.Lock();
Sven Panne 2014/04/16 11:55:35 Use LockGuard here...
marja 2014/04/16 14:33:10 Done.
61 LazyFunction function(start, end, literals, properties, strict_mode);
62 data_.Enqueue(function);
63 have_data_.NotifyOne();
64 mutex_.Unlock();
65 }
66
67
68 void FastParserThread::Consume(int* start, int* end, int* literals,
69 int* properties, StrictMode* strict_mode) {
70 mutex_.Lock();
Sven Panne 2014/04/16 11:55:35 ... and here.
marja 2014/04/16 14:33:10 Done.
71 if (data_.IsEmpty())
72 have_data_.Wait(&mutex_); // Implicitly locks and unlocks the mutex.
73 ASSERT(!data_.IsEmpty());
74 LazyFunction function;
75 data_.Dequeue(&function);
76 mutex_.Unlock();
77 *start = function.start;
78 *end = function.end;
79 *literals = function.literals;
80 *properties = function.properties;
81 *strict_mode = function.strict_mode;
82 }
83
84
85 void FastParserThread::Run() {
86 DisallowHeapAllocation no_allocation;
87 DisallowHandleAllocation no_handles;
88 DisallowHandleDereference no_deref;
89 UnicodeCache unicode_cache;
90 Scanner scanner(&unicode_cache);
91 uintptr_t limit =
92 reinterpret_cast<uintptr_t>(&limit) - kFastParserThreadStackSize;
93 PreParser preparser(&scanner, &recorder_, limit, this);
94 preparser.set_allow_lazy(true);
95 preparser.set_allow_harmony_scoping(allow_harmony_scoping_);
96 preparser.set_allow_modules(allow_modules_);
97 preparser.set_allow_natives_syntax(allow_natives_syntax_);
98 preparser.set_allow_generators(allow_generators_);
99 preparser.set_allow_for_of(allow_for_of_);
100 preparser.set_allow_harmony_numeric_literals(allow_harmony_numeric_literals_);
101 scanner.Initialize(stream_);
102 result_ = preparser.PreParseProgram();
103
104 // Queue a dummy data element, so that the Parser doesn't wait forever if it
105 // expects the thread to produce more data than it will. (For example, when
106 // the thread parses a function and encounters an error.)
107 Produce(-1, -1, -1, -1, SLOPPY);
108 }
109
110 } } // namespace v8::internal
OLDNEW
« src/parser.cc ('K') | « src/parser-thread.h ('k') | src/preparse-data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698