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/mutex.h" | 9 #include "src/base/platform/mutex.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 thread_id_(0), | 28 thread_id_(0), |
29 #endif | 29 #endif |
30 isolate_(isolate), | 30 isolate_(isolate), |
31 stop_semaphore_(0), | 31 stop_semaphore_(0), |
32 input_queue_semaphore_(0), | 32 input_queue_semaphore_(0), |
33 input_queue_capacity_(FLAG_concurrent_recompilation_queue_length), | 33 input_queue_capacity_(FLAG_concurrent_recompilation_queue_length), |
34 input_queue_length_(0), | 34 input_queue_length_(0), |
35 input_queue_shift_(0), | 35 input_queue_shift_(0), |
36 osr_buffer_capacity_(FLAG_concurrent_recompilation_queue_length + 4), | 36 osr_buffer_capacity_(FLAG_concurrent_recompilation_queue_length + 4), |
37 osr_buffer_cursor_(0), | 37 osr_buffer_cursor_(0), |
| 38 task_count_(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 tracing_enabled_(FLAG_trace_concurrent_recompilation), | 42 tracing_enabled_(FLAG_trace_concurrent_recompilation), |
42 job_based_recompilation_(FLAG_job_based_recompilation) { | 43 job_based_recompilation_(FLAG_job_based_recompilation), |
| 44 recompilation_delay_(FLAG_concurrent_recompilation_delay) { |
43 base::NoBarrier_Store(&stop_thread_, | 45 base::NoBarrier_Store(&stop_thread_, |
44 static_cast<base::AtomicWord>(CONTINUE)); | 46 static_cast<base::AtomicWord>(CONTINUE)); |
45 input_queue_ = NewArray<OptimizedCompileJob*>(input_queue_capacity_); | 47 input_queue_ = NewArray<OptimizedCompileJob*>(input_queue_capacity_); |
46 if (FLAG_concurrent_osr) { | 48 if (FLAG_concurrent_osr) { |
47 // Allocate and mark OSR buffer slots as empty. | 49 // Allocate and mark OSR buffer slots as empty. |
48 osr_buffer_ = NewArray<OptimizedCompileJob*>(osr_buffer_capacity_); | 50 osr_buffer_ = NewArray<OptimizedCompileJob*>(osr_buffer_capacity_); |
49 for (int i = 0; i < osr_buffer_capacity_; i++) osr_buffer_[i] = NULL; | 51 for (int i = 0; i < osr_buffer_capacity_; i++) osr_buffer_[i] = NULL; |
50 } | 52 } |
51 } | 53 } |
52 | 54 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 #endif | 88 #endif |
87 | 89 |
88 private: | 90 private: |
89 class CompileTask; | 91 class CompileTask; |
90 | 92 |
91 enum StopFlag { CONTINUE, STOP, FLUSH }; | 93 enum StopFlag { CONTINUE, STOP, FLUSH }; |
92 | 94 |
93 void FlushInputQueue(bool restore_function_code); | 95 void FlushInputQueue(bool restore_function_code); |
94 void FlushOutputQueue(bool restore_function_code); | 96 void FlushOutputQueue(bool restore_function_code); |
95 void FlushOsrBuffer(bool restore_function_code); | 97 void FlushOsrBuffer(bool restore_function_code); |
96 void CompileNext(); | 98 void CompileNext(OptimizedCompileJob* job); |
97 OptimizedCompileJob* NextInput(); | 99 OptimizedCompileJob* NextInput(StopFlag* flag = NULL); |
98 | 100 |
99 // Add a recompilation task for OSR to the cyclic buffer, awaiting OSR entry. | 101 // Add a recompilation task for OSR to the cyclic buffer, awaiting OSR entry. |
100 // Tasks evicted from the cyclic buffer are discarded. | 102 // Tasks evicted from the cyclic buffer are discarded. |
101 void AddToOsrBuffer(OptimizedCompileJob* compiler); | 103 void AddToOsrBuffer(OptimizedCompileJob* compiler); |
102 | 104 |
103 inline int InputQueueIndex(int i) { | 105 inline int InputQueueIndex(int i) { |
104 int result = (i + input_queue_shift_) % input_queue_capacity_; | 106 int result = (i + input_queue_shift_) % input_queue_capacity_; |
105 DCHECK_LE(0, result); | 107 DCHECK_LE(0, result); |
106 DCHECK_LT(result, input_queue_capacity_); | 108 DCHECK_LT(result, input_queue_capacity_); |
107 return result; | 109 return result; |
(...skipping 23 matching lines...) Expand all Loading... |
131 | 133 |
132 // Cyclic buffer of recompilation tasks for OSR. | 134 // Cyclic buffer of recompilation tasks for OSR. |
133 OptimizedCompileJob** osr_buffer_; | 135 OptimizedCompileJob** osr_buffer_; |
134 int osr_buffer_capacity_; | 136 int osr_buffer_capacity_; |
135 int osr_buffer_cursor_; | 137 int osr_buffer_cursor_; |
136 | 138 |
137 volatile base::AtomicWord stop_thread_; | 139 volatile base::AtomicWord stop_thread_; |
138 base::TimeDelta time_spent_compiling_; | 140 base::TimeDelta time_spent_compiling_; |
139 base::TimeDelta time_spent_total_; | 141 base::TimeDelta time_spent_total_; |
140 | 142 |
| 143 int task_count_; |
| 144 // TODO(jochen): This is currently a RecursiveMutex since both Flush/Stop and |
| 145 // Unblock try to get it, but the former methods both can call Unblock. Once |
| 146 // job based recompilation is on by default, and the dedicated thread can be |
| 147 // removed, this should be refactored to not use a RecursiveMutex. |
| 148 base::RecursiveMutex task_count_mutex_; |
| 149 |
141 int osr_hits_; | 150 int osr_hits_; |
142 int osr_attempts_; | 151 int osr_attempts_; |
143 | 152 |
144 int blocked_jobs_; | 153 int blocked_jobs_; |
145 | 154 |
146 // Copies of FLAG_trace_concurrent_recompilation and | 155 // Copies of FLAG_trace_concurrent_recompilation, |
| 156 // FLAG_concurrent_recompilation_delay and |
147 // FLAG_job_based_recompilation that will be used from the background thread. | 157 // FLAG_job_based_recompilation that will be used from the background thread. |
148 // | 158 // |
149 // Since flags might get modified while the background thread is running, it | 159 // Since flags might get modified while the background thread is running, it |
150 // is not safe to access them directly. | 160 // is not safe to access them directly. |
151 bool tracing_enabled_; | 161 bool tracing_enabled_; |
152 bool job_based_recompilation_; | 162 bool job_based_recompilation_; |
| 163 int recompilation_delay_; |
153 }; | 164 }; |
154 | 165 |
155 } } // namespace v8::internal | 166 } } // namespace v8::internal |
156 | 167 |
157 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ | 168 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ |
OLD | NEW |