| OLD | NEW |
| (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 #ifndef V8_PARSER_THREAD_H_ |
| 29 #define V8_PARSER_THREAD_H_ |
| 30 |
| 31 #include "platform.h" |
| 32 #include "platform/semaphore.h" |
| 33 #include "preparser.h" |
| 34 |
| 35 // This thread does a fast pass over the source, and produced data on lazy |
| 36 // functions. It won't interact with the V8 heap or the Isolate (for example, |
| 37 // create or dereference Handles). This will only hold if the |
| 38 // Utf16CharacterStream passed to the constructor does not interact with the V8 |
| 39 // heap either. |
| 40 |
| 41 namespace v8 { |
| 42 namespace internal { |
| 43 |
| 44 class BackgroundParsingTask; |
| 45 class SingletonLogger; |
| 46 class Utf16CharacterStream; |
| 47 |
| 48 class FastParserThread : public Thread { |
| 49 public: |
| 50 // Used for signalling errors. |
| 51 static const int kInvalidFunctionStart = -1; |
| 52 |
| 53 FastParserThread(); |
| 54 |
| 55 // Should be only called by the main thread. Takes ownership of the |
| 56 // stream. The thread can only handle one background parsing task at a time, |
| 57 // so this cannot be called again before FinishBackgroundParsing has been |
| 58 // called for the current task. (For the purposes of parallel preparsing, this |
| 59 // is enough; we will never have more than one script to preparse.) |
| 60 void StartBackgroundParsing(Utf16CharacterStream* stream, |
| 61 bool allow_harmony_scoping, |
| 62 bool allow_modules, |
| 63 bool allow_natives_syntax, |
| 64 bool allow_generators, |
| 65 bool allow_for_of, |
| 66 bool allow_harmony_numeric_literals); |
| 67 |
| 68 void FinishBackgroundParsing(); |
| 69 |
| 70 void Run(); |
| 71 |
| 72 // Should only be called when no background task is in progress. |
| 73 void Stop(); |
| 74 |
| 75 // Should be only called from the background thread. |
| 76 void Produce(int start, int end, int literals, int properties, |
| 77 StrictMode strict_mode); |
| 78 |
| 79 // Should be only called by the main thread. |
| 80 void Consume(int* start, int* end, int* literals, int* properties, |
| 81 StrictMode* strict_mode); |
| 82 |
| 83 PreParser::PreParseResult result() const; |
| 84 const SingletonLogger* recorder() const; |
| 85 |
| 86 private: |
| 87 BackgroundParsingTask* current_task_; |
| 88 Semaphore have_work_; |
| 89 Semaphore work_done_; |
| 90 bool should_stop_; |
| 91 }; |
| 92 |
| 93 } } // namespace v8::internal |
| 94 |
| 95 #endif // V8_PARSER_THREAD_H_ |
| OLD | NEW |