OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 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_OPTIMIZING_COMPILER_THREAD_H_ |
| 29 #define V8_OPTIMIZING_COMPILER_THREAD_H_ |
| 30 |
| 31 #include "atomicops.h" |
| 32 #include "platform.h" |
| 33 #include "flags.h" |
| 34 #include "unbound-queue.h" |
| 35 |
| 36 namespace v8 { |
| 37 namespace internal { |
| 38 |
| 39 class HGraphBuilder; |
| 40 class OptimizingCompiler; |
| 41 |
| 42 class OptimizingCompilerThread : public Thread { |
| 43 public: |
| 44 explicit OptimizingCompilerThread(Isolate *isolate) : |
| 45 Thread("OptimizingCompilerThread"), |
| 46 isolate_(isolate), |
| 47 stop_semaphore_(OS::CreateSemaphore(0)), |
| 48 input_queue_semaphore_(OS::CreateSemaphore(0)) { |
| 49 NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(false)); |
| 50 NoBarrier_Store(&queue_length_, static_cast<AtomicWord>(0)); |
| 51 } |
| 52 |
| 53 void Run(); |
| 54 void Stop(); |
| 55 void QueueForOptimization(OptimizingCompiler* optimizing_compiler); |
| 56 void InstallOptimizedFunctions(); |
| 57 |
| 58 inline bool IsQueueAvailable() { |
| 59 // We don't need a barrier since we have a data dependency right |
| 60 // after. |
| 61 Atomic32 current_length = NoBarrier_Load(&queue_length_); |
| 62 |
| 63 // This can be queried only from the execution thread. |
| 64 ASSERT(!IsOptimizerThread()); |
| 65 // Since only the execution thread increments queue_length_ and |
| 66 // only one thread can run inside an Isolate at one time, a direct |
| 67 // doesn't introduce a race -- queue_length_ may decreased in |
| 68 // meantime, but not increased. |
| 69 return (current_length < FLAG_parallel_recompilation_queue_length); |
| 70 } |
| 71 |
| 72 #ifdef DEBUG |
| 73 bool IsOptimizerThread(); |
| 74 #endif |
| 75 |
| 76 ~OptimizingCompilerThread() { |
| 77 delete input_queue_semaphore_; |
| 78 delete stop_semaphore_; |
| 79 } |
| 80 |
| 81 private: |
| 82 Isolate* isolate_; |
| 83 Semaphore* stop_semaphore_; |
| 84 Semaphore* input_queue_semaphore_; |
| 85 UnboundQueue<OptimizingCompiler*> input_queue_; |
| 86 UnboundQueue<OptimizingCompiler*> output_queue_; |
| 87 volatile AtomicWord stop_thread_; |
| 88 volatile Atomic32 queue_length_; |
| 89 |
| 90 #ifdef DEBUG |
| 91 int thread_id_; |
| 92 #endif |
| 93 }; |
| 94 |
| 95 } } // namespace v8::internal |
| 96 |
| 97 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ |
OLD | NEW |