OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_OPTIMIZING_COMPILER_THREAD_H_ | 5 #ifndef V8_OPTIMIZING_COMPILER_THREAD_H_ |
6 #define V8_OPTIMIZING_COMPILER_THREAD_H_ | 6 #define V8_OPTIMIZING_COMPILER_THREAD_H_ |
7 | 7 |
8 #include "src/base/atomicops.h" | 8 #include "src/base/atomicops.h" |
| 9 #include "src/base/platform/condition-variable.h" |
9 #include "src/base/platform/mutex.h" | 10 #include "src/base/platform/mutex.h" |
10 #include "src/base/platform/platform.h" | 11 #include "src/base/platform/platform.h" |
11 #include "src/base/platform/time.h" | 12 #include "src/base/platform/time.h" |
12 #include "src/flags.h" | 13 #include "src/flags.h" |
13 #include "src/list.h" | 14 #include "src/list.h" |
14 #include "src/unbound-queue-inl.h" | 15 #include "src/unbound-queue-inl.h" |
15 | 16 |
16 namespace v8 { | 17 namespace v8 { |
17 namespace internal { | 18 namespace internal { |
18 | 19 |
(...skipping 12 matching lines...) Expand all Loading... |
31 stop_semaphore_(0), | 32 stop_semaphore_(0), |
32 input_queue_semaphore_(0), | 33 input_queue_semaphore_(0), |
33 input_queue_capacity_(FLAG_concurrent_recompilation_queue_length), | 34 input_queue_capacity_(FLAG_concurrent_recompilation_queue_length), |
34 input_queue_length_(0), | 35 input_queue_length_(0), |
35 input_queue_shift_(0), | 36 input_queue_shift_(0), |
36 osr_buffer_capacity_(FLAG_concurrent_recompilation_queue_length + 4), | 37 osr_buffer_capacity_(FLAG_concurrent_recompilation_queue_length + 4), |
37 osr_buffer_cursor_(0), | 38 osr_buffer_cursor_(0), |
38 osr_hits_(0), | 39 osr_hits_(0), |
39 osr_attempts_(0), | 40 osr_attempts_(0), |
40 blocked_jobs_(0), | 41 blocked_jobs_(0), |
41 ref_count_(1), | 42 ref_count_(0), |
42 tracing_enabled_(FLAG_trace_concurrent_recompilation), | 43 tracing_enabled_(FLAG_trace_concurrent_recompilation), |
43 job_based_recompilation_(FLAG_job_based_recompilation), | 44 job_based_recompilation_(FLAG_job_based_recompilation), |
44 recompilation_delay_(FLAG_concurrent_recompilation_delay) { | 45 recompilation_delay_(FLAG_concurrent_recompilation_delay) { |
45 base::NoBarrier_Store(&stop_thread_, | 46 base::NoBarrier_Store(&stop_thread_, |
46 static_cast<base::AtomicWord>(CONTINUE)); | 47 static_cast<base::AtomicWord>(CONTINUE)); |
47 input_queue_ = NewArray<OptimizedCompileJob*>(input_queue_capacity_); | 48 input_queue_ = NewArray<OptimizedCompileJob*>(input_queue_capacity_); |
48 if (FLAG_concurrent_osr) { | 49 if (FLAG_concurrent_osr) { |
49 // Allocate and mark OSR buffer slots as empty. | 50 // Allocate and mark OSR buffer slots as empty. |
50 osr_buffer_ = NewArray<OptimizedCompileJob*>(osr_buffer_capacity_); | 51 osr_buffer_ = NewArray<OptimizedCompileJob*>(osr_buffer_capacity_); |
51 for (int i = 0; i < osr_buffer_capacity_; i++) osr_buffer_[i] = NULL; | 52 for (int i = 0; i < osr_buffer_capacity_; i++) osr_buffer_[i] = NULL; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 90 |
90 private: | 91 private: |
91 class CompileTask; | 92 class CompileTask; |
92 | 93 |
93 enum StopFlag { CONTINUE, STOP, FLUSH }; | 94 enum StopFlag { CONTINUE, STOP, FLUSH }; |
94 | 95 |
95 void FlushInputQueue(bool restore_function_code); | 96 void FlushInputQueue(bool restore_function_code); |
96 void FlushOutputQueue(bool restore_function_code); | 97 void FlushOutputQueue(bool restore_function_code); |
97 void FlushOsrBuffer(bool restore_function_code); | 98 void FlushOsrBuffer(bool restore_function_code); |
98 void CompileNext(OptimizedCompileJob* job); | 99 void CompileNext(OptimizedCompileJob* job); |
99 OptimizedCompileJob* NextInput(StopFlag* flag = NULL); | 100 OptimizedCompileJob* NextInput(bool check_if_flushing = false); |
100 | 101 |
101 // Add a recompilation task for OSR to the cyclic buffer, awaiting OSR entry. | 102 // Add a recompilation task for OSR to the cyclic buffer, awaiting OSR entry. |
102 // Tasks evicted from the cyclic buffer are discarded. | 103 // Tasks evicted from the cyclic buffer are discarded. |
103 void AddToOsrBuffer(OptimizedCompileJob* compiler); | 104 void AddToOsrBuffer(OptimizedCompileJob* compiler); |
104 | 105 |
105 inline int InputQueueIndex(int i) { | 106 inline int InputQueueIndex(int i) { |
106 int result = (i + input_queue_shift_) % input_queue_capacity_; | 107 int result = (i + input_queue_shift_) % input_queue_capacity_; |
107 DCHECK_LE(0, result); | 108 DCHECK_LE(0, result); |
108 DCHECK_LT(result, input_queue_capacity_); | 109 DCHECK_LT(result, input_queue_capacity_); |
109 return result; | 110 return result; |
(...skipping 28 matching lines...) Expand all Loading... |
138 | 139 |
139 volatile base::AtomicWord stop_thread_; | 140 volatile base::AtomicWord stop_thread_; |
140 base::TimeDelta time_spent_compiling_; | 141 base::TimeDelta time_spent_compiling_; |
141 base::TimeDelta time_spent_total_; | 142 base::TimeDelta time_spent_total_; |
142 | 143 |
143 int osr_hits_; | 144 int osr_hits_; |
144 int osr_attempts_; | 145 int osr_attempts_; |
145 | 146 |
146 int blocked_jobs_; | 147 int blocked_jobs_; |
147 | 148 |
148 volatile base::AtomicWord ref_count_; | 149 int ref_count_; |
| 150 base::Mutex ref_count_mutex_; |
| 151 base::ConditionVariable ref_count_zero_; |
149 | 152 |
150 // Copies of FLAG_trace_concurrent_recompilation, | 153 // Copies of FLAG_trace_concurrent_recompilation, |
151 // FLAG_concurrent_recompilation_delay and | 154 // FLAG_concurrent_recompilation_delay and |
152 // FLAG_job_based_recompilation that will be used from the background thread. | 155 // FLAG_job_based_recompilation that will be used from the background thread. |
153 // | 156 // |
154 // Since flags might get modified while the background thread is running, it | 157 // Since flags might get modified while the background thread is running, it |
155 // is not safe to access them directly. | 158 // is not safe to access them directly. |
156 bool tracing_enabled_; | 159 bool tracing_enabled_; |
157 bool job_based_recompilation_; | 160 bool job_based_recompilation_; |
158 int recompilation_delay_; | 161 int recompilation_delay_; |
159 }; | 162 }; |
160 | 163 |
161 } } // namespace v8::internal | 164 } } // namespace v8::internal |
162 | 165 |
163 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ | 166 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ |
OLD | NEW |