| 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 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 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 "list.h" |
| 33 #include "platform.h" | 34 #include "platform.h" |
| 34 #include "platform/mutex.h" | 35 #include "platform/mutex.h" |
| 35 #include "platform/time.h" | 36 #include "platform/time.h" |
| 36 #include "unbound-queue-inl.h" | 37 #include "unbound-queue-inl.h" |
| 37 | 38 |
| 38 namespace v8 { | 39 namespace v8 { |
| 39 namespace internal { | 40 namespace internal { |
| 40 | 41 |
| 41 class HOptimizedGraphBuilder; | 42 class HOptimizedGraphBuilder; |
| 42 class OptimizingCompiler; | 43 class OptimizingCompiler; |
| 43 class SharedFunctionInfo; | 44 class SharedFunctionInfo; |
| 44 | 45 |
| 45 class OptimizingCompilerThread : public Thread { | 46 class OptimizingCompilerThread : public Thread { |
| 46 public: | 47 public: |
| 47 explicit OptimizingCompilerThread(Isolate *isolate) : | 48 explicit OptimizingCompilerThread(Isolate *isolate) : |
| 48 Thread("OptimizingCompilerThread"), | 49 Thread("OptimizingCompilerThread"), |
| 49 #ifdef DEBUG | 50 #ifdef DEBUG |
| 50 thread_id_(0), | 51 thread_id_(0), |
| 51 #endif | 52 #endif |
| 52 isolate_(isolate), | 53 isolate_(isolate), |
| 53 stop_semaphore_(0), | 54 stop_semaphore_(0), |
| 54 input_queue_semaphore_(0) { | 55 input_queue_semaphore_(0), |
| 56 osr_candidates_(2), |
| 57 ready_for_osr_(2), |
| 58 osr_hits_(0), |
| 59 osr_attempts_(0) { |
| 55 NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE)); | 60 NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE)); |
| 56 NoBarrier_Store(&queue_length_, static_cast<AtomicWord>(0)); | 61 NoBarrier_Store(&queue_length_, static_cast<AtomicWord>(0)); |
| 57 } | 62 } |
| 58 ~OptimizingCompilerThread() {} | 63 ~OptimizingCompilerThread() {} |
| 59 | 64 |
| 60 void Run(); | 65 void Run(); |
| 61 void Stop(); | 66 void Stop(); |
| 62 void Flush(); | 67 void Flush(); |
| 63 void QueueForOptimization(OptimizingCompiler* optimizing_compiler); | 68 void QueueForOptimization(OptimizingCompiler* optimizing_compiler); |
| 64 void InstallOptimizedFunctions(); | 69 void InstallOptimizedFunctions(); |
| 70 OptimizingCompiler* FindReadyOSRCandidate(Handle<JSFunction> function, |
| 71 uint32_t osr_pc_offset); |
| 72 bool IsQueuedForOSR(Handle<JSFunction> function, uint32_t osr_pc_offset); |
| 73 |
| 74 // Remove the oldest OSR candidates that are ready so that we |
| 75 // only have |limit| left waiting. |
| 76 void RemoveStaleOSRCandidates(int limit = kReadyForOSRLimit); |
| 65 | 77 |
| 66 inline bool IsQueueAvailable() { | 78 inline bool IsQueueAvailable() { |
| 67 // We don't need a barrier since we have a data dependency right | 79 // We don't need a barrier since we have a data dependency right |
| 68 // after. | 80 // after. |
| 69 Atomic32 current_length = NoBarrier_Load(&queue_length_); | 81 Atomic32 current_length = NoBarrier_Load(&queue_length_); |
| 70 | 82 |
| 71 // This can be queried only from the execution thread. | 83 // This can be queried only from the execution thread. |
| 72 ASSERT(!IsOptimizerThread()); | 84 ASSERT(!IsOptimizerThread()); |
| 73 // Since only the execution thread increments queue_length_ and | 85 // Since only the execution thread increments queue_length_ and |
| 74 // only one thread can run inside an Isolate at one time, a direct | 86 // only one thread can run inside an Isolate at one time, a direct |
| 75 // doesn't introduce a race -- queue_length_ may decreased in | 87 // doesn't introduce a race -- queue_length_ may decreased in |
| 76 // meantime, but not increased. | 88 // meantime, but not increased. |
| 77 return (current_length < FLAG_concurrent_recompilation_queue_length); | 89 return (current_length < FLAG_concurrent_recompilation_queue_length); |
| 78 } | 90 } |
| 79 | 91 |
| 80 #ifdef DEBUG | 92 #ifdef DEBUG |
| 81 bool IsOptimizerThread(); | 93 bool IsOptimizerThread(); |
| 82 #endif | 94 #endif |
| 83 | 95 |
| 84 private: | 96 private: |
| 85 enum StopFlag { CONTINUE, STOP, FLUSH }; | 97 enum StopFlag { CONTINUE, STOP, FLUSH }; |
| 86 | 98 |
| 87 void FlushInputQueue(bool restore_function_code); | 99 void FlushInputQueue(bool restore_function_code); |
| 88 void FlushOutputQueue(bool restore_function_code); | 100 void FlushOutputQueue(bool restore_function_code); |
| 89 | |
| 90 void CompileNext(); | 101 void CompileNext(); |
| 91 | 102 |
| 92 #ifdef DEBUG | 103 #ifdef DEBUG |
| 93 int thread_id_; | 104 int thread_id_; |
| 94 Mutex thread_id_mutex_; | 105 Mutex thread_id_mutex_; |
| 95 #endif | 106 #endif |
| 96 | 107 |
| 97 Isolate* isolate_; | 108 Isolate* isolate_; |
| 98 Semaphore stop_semaphore_; | 109 Semaphore stop_semaphore_; |
| 99 Semaphore input_queue_semaphore_; | 110 Semaphore input_queue_semaphore_; |
| 111 |
| 112 // Queue of incoming recompilation tasks (including OSR). |
| 100 UnboundQueue<OptimizingCompiler*> input_queue_; | 113 UnboundQueue<OptimizingCompiler*> input_queue_; |
| 114 // Queue of recompilation tasks ready to be installed (excluding OSR). |
| 101 UnboundQueue<OptimizingCompiler*> output_queue_; | 115 UnboundQueue<OptimizingCompiler*> output_queue_; |
| 116 // List of all OSR related recompilation tasks (both incoming and ready ones). |
| 117 List<OptimizingCompiler*> osr_candidates_; |
| 118 // List of recompilation tasks ready for OSR. |
| 119 List<OptimizingCompiler*> ready_for_osr_; |
| 120 |
| 102 Mutex install_mutex_; | 121 Mutex install_mutex_; |
| 103 volatile AtomicWord stop_thread_; | 122 volatile AtomicWord stop_thread_; |
| 104 volatile Atomic32 queue_length_; | 123 volatile Atomic32 queue_length_; |
| 105 TimeDelta time_spent_compiling_; | 124 TimeDelta time_spent_compiling_; |
| 106 TimeDelta time_spent_total_; | 125 TimeDelta time_spent_total_; |
| 126 |
| 127 Mutex osr_list_mutex_; |
| 128 int osr_hits_; |
| 129 int osr_attempts_; |
| 130 |
| 131 static const int kReadyForOSRLimit = 4; |
| 107 }; | 132 }; |
| 108 | 133 |
| 109 } } // namespace v8::internal | 134 } } // namespace v8::internal |
| 110 | 135 |
| 111 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ | 136 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ |
| OLD | NEW |