| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_OPTIMIZING_COMPILER_THREAD_H_ | 28 #ifndef V8_OPTIMIZING_COMPILER_THREAD_H_ |
| 29 #define V8_OPTIMIZING_COMPILER_THREAD_H_ | 29 #define V8_OPTIMIZING_COMPILER_THREAD_H_ |
| 30 | 30 |
| 31 #include "atomicops.h" | 31 #include "atomicops.h" |
| 32 #include "flags.h" | 32 #include "flags.h" |
| 33 #include "platform.h" | 33 #include "platform.h" |
| 34 #include "platform/mutex.h" |
| 34 #include "platform/time.h" | 35 #include "platform/time.h" |
| 35 #include "unbound-queue-inl.h" | 36 #include "unbound-queue-inl.h" |
| 36 | 37 |
| 37 namespace v8 { | 38 namespace v8 { |
| 38 namespace internal { | 39 namespace internal { |
| 39 | 40 |
| 40 class HOptimizedGraphBuilder; | 41 class HOptimizedGraphBuilder; |
| 41 class OptimizingCompiler; | 42 class OptimizingCompiler; |
| 42 class SharedFunctionInfo; | 43 class SharedFunctionInfo; |
| 43 | 44 |
| 44 class OptimizingCompilerThread : public Thread { | 45 class OptimizingCompilerThread : public Thread { |
| 45 public: | 46 public: |
| 46 explicit OptimizingCompilerThread(Isolate *isolate) : | 47 explicit OptimizingCompilerThread(Isolate *isolate) : |
| 47 Thread("OptimizingCompilerThread"), | 48 Thread("OptimizingCompilerThread"), |
| 48 #ifdef DEBUG | 49 #ifdef DEBUG |
| 49 thread_id_(0), | 50 thread_id_(0), |
| 50 thread_id_mutex_(OS::CreateMutex()), | |
| 51 #endif | 51 #endif |
| 52 isolate_(isolate), | 52 isolate_(isolate), |
| 53 stop_semaphore_(OS::CreateSemaphore(0)), | 53 stop_semaphore_(OS::CreateSemaphore(0)), |
| 54 input_queue_semaphore_(OS::CreateSemaphore(0)), | 54 input_queue_semaphore_(OS::CreateSemaphore(0)) { |
| 55 install_mutex_(OS::CreateMutex()) { | |
| 56 NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE)); | 55 NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE)); |
| 57 NoBarrier_Store(&queue_length_, static_cast<AtomicWord>(0)); | 56 NoBarrier_Store(&queue_length_, static_cast<AtomicWord>(0)); |
| 58 } | 57 } |
| 59 | 58 |
| 60 void Run(); | 59 void Run(); |
| 61 void Stop(); | 60 void Stop(); |
| 62 void Flush(); | 61 void Flush(); |
| 63 void QueueForOptimization(OptimizingCompiler* optimizing_compiler); | 62 void QueueForOptimization(OptimizingCompiler* optimizing_compiler); |
| 64 void InstallOptimizedFunctions(); | 63 void InstallOptimizedFunctions(); |
| 65 | 64 |
| 66 inline bool IsQueueAvailable() { | 65 inline bool IsQueueAvailable() { |
| 67 // We don't need a barrier since we have a data dependency right | 66 // We don't need a barrier since we have a data dependency right |
| 68 // after. | 67 // after. |
| 69 Atomic32 current_length = NoBarrier_Load(&queue_length_); | 68 Atomic32 current_length = NoBarrier_Load(&queue_length_); |
| 70 | 69 |
| 71 // This can be queried only from the execution thread. | 70 // This can be queried only from the execution thread. |
| 72 ASSERT(!IsOptimizerThread()); | 71 ASSERT(!IsOptimizerThread()); |
| 73 // Since only the execution thread increments queue_length_ and | 72 // Since only the execution thread increments queue_length_ and |
| 74 // only one thread can run inside an Isolate at one time, a direct | 73 // only one thread can run inside an Isolate at one time, a direct |
| 75 // doesn't introduce a race -- queue_length_ may decreased in | 74 // doesn't introduce a race -- queue_length_ may decreased in |
| 76 // meantime, but not increased. | 75 // meantime, but not increased. |
| 77 return (current_length < FLAG_concurrent_recompilation_queue_length); | 76 return (current_length < FLAG_concurrent_recompilation_queue_length); |
| 78 } | 77 } |
| 79 | 78 |
| 80 #ifdef DEBUG | 79 #ifdef DEBUG |
| 81 bool IsOptimizerThread(); | 80 bool IsOptimizerThread(); |
| 82 #endif | 81 #endif |
| 83 | 82 |
| 84 ~OptimizingCompilerThread() { | 83 ~OptimizingCompilerThread() { |
| 85 delete install_mutex_; | |
| 86 delete input_queue_semaphore_; | 84 delete input_queue_semaphore_; |
| 87 delete stop_semaphore_; | 85 delete stop_semaphore_; |
| 88 #ifdef DEBUG | 86 #ifdef DEBUG |
| 89 delete thread_id_mutex_; | |
| 90 #endif | 87 #endif |
| 91 } | 88 } |
| 92 | 89 |
| 93 private: | 90 private: |
| 94 enum StopFlag { CONTINUE, STOP, FLUSH }; | 91 enum StopFlag { CONTINUE, STOP, FLUSH }; |
| 95 | 92 |
| 96 void FlushInputQueue(bool restore_function_code); | 93 void FlushInputQueue(bool restore_function_code); |
| 97 void FlushOutputQueue(bool restore_function_code); | 94 void FlushOutputQueue(bool restore_function_code); |
| 98 | 95 |
| 99 void CompileNext(); | 96 void CompileNext(); |
| 100 | 97 |
| 101 #ifdef DEBUG | 98 #ifdef DEBUG |
| 102 int thread_id_; | 99 int thread_id_; |
| 103 Mutex* thread_id_mutex_; | 100 Mutex thread_id_mutex_; |
| 104 #endif | 101 #endif |
| 105 | 102 |
| 106 Isolate* isolate_; | 103 Isolate* isolate_; |
| 107 Semaphore* stop_semaphore_; | 104 Semaphore* stop_semaphore_; |
| 108 Semaphore* input_queue_semaphore_; | 105 Semaphore* input_queue_semaphore_; |
| 109 UnboundQueue<OptimizingCompiler*> input_queue_; | 106 UnboundQueue<OptimizingCompiler*> input_queue_; |
| 110 UnboundQueue<OptimizingCompiler*> output_queue_; | 107 UnboundQueue<OptimizingCompiler*> output_queue_; |
| 111 Mutex* install_mutex_; | 108 Mutex install_mutex_; |
| 112 volatile AtomicWord stop_thread_; | 109 volatile AtomicWord stop_thread_; |
| 113 volatile Atomic32 queue_length_; | 110 volatile Atomic32 queue_length_; |
| 114 TimeDelta time_spent_compiling_; | 111 TimeDelta time_spent_compiling_; |
| 115 TimeDelta time_spent_total_; | 112 TimeDelta time_spent_total_; |
| 116 }; | 113 }; |
| 117 | 114 |
| 118 } } // namespace v8::internal | 115 } } // namespace v8::internal |
| 119 | 116 |
| 120 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ | 117 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ |
| OLD | NEW |