| 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_(OS::CreateSemaphore(0)), | 54 stop_semaphore_(OS::CreateSemaphore(0)), |
| 54 input_queue_semaphore_(OS::CreateSemaphore(0)) { | 55 input_queue_semaphore_(OS::CreateSemaphore(0)), |
| 56 osr_candidates_(kReadyForOSRLimit), |
| 57 ready_for_osr_(kReadyForOSRLimit), |
| 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 | 63 |
| 59 void Run(); | 64 void Run(); |
| 60 void Stop(); | 65 void Stop(); |
| 61 void Flush(); | 66 void Flush(); |
| 62 void QueueForOptimization(OptimizingCompiler* optimizing_compiler); | 67 void QueueForOptimization(OptimizingCompiler* optimizing_compiler); |
| 63 void InstallOptimizedFunctions(); | 68 void InstallOptimizedFunctions(); |
| 69 OptimizingCompiler* FindReadyOSRCandidate(Handle<JSFunction> function, |
| 70 uint32_t osr_pc_offset); |
| 71 bool IsQueuedForOSR(Handle<JSFunction> function, uint32_t osr_pc_offset); |
| 72 |
| 73 // Remove the oldest OSR candidates that are ready so that we |
| 74 // only have |limit| left waiting. |
| 75 void RemoveStaleOSRCandidates(int limit = kReadyForOSRLimit); |
| 64 | 76 |
| 65 inline bool IsQueueAvailable() { | 77 inline bool IsQueueAvailable() { |
| 66 // We don't need a barrier since we have a data dependency right | 78 // We don't need a barrier since we have a data dependency right |
| 67 // after. | 79 // after. |
| 68 Atomic32 current_length = NoBarrier_Load(&queue_length_); | 80 Atomic32 current_length = NoBarrier_Load(&queue_length_); |
| 69 | 81 |
| 70 // This can be queried only from the execution thread. | 82 // This can be queried only from the execution thread. |
| 71 ASSERT(!IsOptimizerThread()); | 83 ASSERT(!IsOptimizerThread()); |
| 72 // Since only the execution thread increments queue_length_ and | 84 // Since only the execution thread increments queue_length_ and |
| 73 // only one thread can run inside an Isolate at one time, a direct | 85 // only one thread can run inside an Isolate at one time, a direct |
| (...skipping 11 matching lines...) Expand all Loading... |
| 85 delete stop_semaphore_; | 97 delete stop_semaphore_; |
| 86 #ifdef DEBUG | 98 #ifdef DEBUG |
| 87 #endif | 99 #endif |
| 88 } | 100 } |
| 89 | 101 |
| 90 private: | 102 private: |
| 91 enum StopFlag { CONTINUE, STOP, FLUSH }; | 103 enum StopFlag { CONTINUE, STOP, FLUSH }; |
| 92 | 104 |
| 93 void FlushInputQueue(bool restore_function_code); | 105 void FlushInputQueue(bool restore_function_code); |
| 94 void FlushOutputQueue(bool restore_function_code); | 106 void FlushOutputQueue(bool restore_function_code); |
| 95 | |
| 96 void CompileNext(); | 107 void CompileNext(); |
| 97 | 108 |
| 98 #ifdef DEBUG | 109 #ifdef DEBUG |
| 99 int thread_id_; | 110 int thread_id_; |
| 100 Mutex thread_id_mutex_; | 111 Mutex thread_id_mutex_; |
| 101 #endif | 112 #endif |
| 102 | 113 |
| 103 Isolate* isolate_; | 114 Isolate* isolate_; |
| 104 Semaphore* stop_semaphore_; | 115 Semaphore* stop_semaphore_; |
| 105 Semaphore* input_queue_semaphore_; | 116 Semaphore* input_queue_semaphore_; |
| 117 |
| 118 // Queue of incoming recompilation tasks (including OSR). |
| 106 UnboundQueue<OptimizingCompiler*> input_queue_; | 119 UnboundQueue<OptimizingCompiler*> input_queue_; |
| 120 // Queue of recompilation tasks ready to be installed (excluding OSR). |
| 107 UnboundQueue<OptimizingCompiler*> output_queue_; | 121 UnboundQueue<OptimizingCompiler*> output_queue_; |
| 122 // List of all OSR related recompilation tasks (both incoming and ready ones). |
| 123 List<OptimizingCompiler*> osr_candidates_; |
| 124 // List of recompilation tasks ready for OSR. |
| 125 List<OptimizingCompiler*> ready_for_osr_; |
| 126 |
| 108 Mutex install_mutex_; | 127 Mutex install_mutex_; |
| 109 volatile AtomicWord stop_thread_; | 128 volatile AtomicWord stop_thread_; |
| 110 volatile Atomic32 queue_length_; | 129 volatile Atomic32 queue_length_; |
| 111 TimeDelta time_spent_compiling_; | 130 TimeDelta time_spent_compiling_; |
| 112 TimeDelta time_spent_total_; | 131 TimeDelta time_spent_total_; |
| 132 |
| 133 Mutex osr_list_mutex_; |
| 134 int osr_hits_; |
| 135 int osr_attempts_; |
| 136 |
| 137 static const int kReadyForOSRLimit = 4; |
| 113 }; | 138 }; |
| 114 | 139 |
| 115 } } // namespace v8::internal | 140 } } // namespace v8::internal |
| 116 | 141 |
| 117 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ | 142 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ |
| OLD | NEW |