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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 if (FLAG_trace_concurrent_recompilation) { | 67 if (FLAG_trace_concurrent_recompilation) { |
68 time_spent_total_ = total_timer.Elapsed(); | 68 time_spent_total_ = total_timer.Elapsed(); |
69 } | 69 } |
70 stop_semaphore_.Signal(); | 70 stop_semaphore_.Signal(); |
71 return; | 71 return; |
72 case FLUSH: | 72 case FLUSH: |
73 // The main thread is blocked, waiting for the stop semaphore. | 73 // The main thread is blocked, waiting for the stop semaphore. |
74 { AllowHandleDereference allow_handle_dereference; | 74 { AllowHandleDereference allow_handle_dereference; |
75 FlushInputQueue(true); | 75 FlushInputQueue(true); |
76 } | 76 } |
| 77 Release_Store(&queue_length_, static_cast<AtomicWord>(0)); |
77 Release_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE)); | 78 Release_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE)); |
78 stop_semaphore_.Signal(); | 79 stop_semaphore_.Signal(); |
79 // Return to start of consumer loop. | 80 // Return to start of consumer loop. |
80 continue; | 81 continue; |
81 } | 82 } |
82 | 83 |
83 ElapsedTimer compiling_timer; | 84 ElapsedTimer compiling_timer; |
84 if (FLAG_trace_concurrent_recompilation) compiling_timer.Start(); | 85 if (FLAG_trace_concurrent_recompilation) compiling_timer.Start(); |
85 | 86 |
86 CompileNext(); | 87 CompileNext(); |
(...skipping 19 matching lines...) Expand all Loading... |
106 | 107 |
107 // The function may have already been optimized by OSR. Simply continue. | 108 // The function may have already been optimized by OSR. Simply continue. |
108 // Use a mutex to make sure that functions marked for install | 109 // Use a mutex to make sure that functions marked for install |
109 // are always also queued. | 110 // are always also queued. |
110 if (!optimizing_compiler->info()->osr_ast_id().IsNone()) { | 111 if (!optimizing_compiler->info()->osr_ast_id().IsNone()) { |
111 ASSERT(FLAG_concurrent_osr); | 112 ASSERT(FLAG_concurrent_osr); |
112 LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); | 113 LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); |
113 osr_candidates_.RemoveElement(optimizing_compiler); | 114 osr_candidates_.RemoveElement(optimizing_compiler); |
114 ready_for_osr_.Add(optimizing_compiler); | 115 ready_for_osr_.Add(optimizing_compiler); |
115 } else { | 116 } else { |
116 LockGuard<Mutex> access_queue(&queue_mutex_); | |
117 output_queue_.Enqueue(optimizing_compiler); | 117 output_queue_.Enqueue(optimizing_compiler); |
118 isolate_->stack_guard()->RequestInstallCode(); | 118 isolate_->stack_guard()->RequestInstallCode(); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 | 122 |
123 void OptimizingCompilerThread::FlushInputQueue(bool restore_function_code) { | 123 void OptimizingCompilerThread::FlushInputQueue(bool restore_function_code) { |
124 OptimizingCompiler* optimizing_compiler; | 124 OptimizingCompiler* optimizing_compiler; |
125 // The optimizing compiler is allocated in the CompilationInfo's zone. | 125 // The optimizing compiler is allocated in the CompilationInfo's zone. |
126 while (input_queue_.Dequeue(&optimizing_compiler)) { | 126 while (input_queue_.Dequeue(&optimizing_compiler)) { |
127 // This should not block, since we have one signal on the input queue | 127 // This should not block, since we have one signal on the input queue |
128 // semaphore corresponding to each element in the input queue. | 128 // semaphore corresponding to each element in the input queue. |
129 input_queue_semaphore_.Wait(); | 129 input_queue_semaphore_.Wait(); |
130 CompilationInfo* info = optimizing_compiler->info(); | 130 CompilationInfo* info = optimizing_compiler->info(); |
131 if (restore_function_code) { | 131 if (restore_function_code) { |
132 Handle<JSFunction> function = info->closure(); | 132 Handle<JSFunction> function = info->closure(); |
133 function->ReplaceCode(function->shared()->code()); | 133 function->ReplaceCode(function->shared()->code()); |
134 } | 134 } |
135 delete info; | 135 delete info; |
136 } | 136 } |
137 Release_Store(&queue_length_, static_cast<AtomicWord>(0)); | |
138 | |
139 LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); | |
140 osr_candidates_.Clear(); | |
141 } | 137 } |
142 | 138 |
143 | 139 |
144 void OptimizingCompilerThread::FlushOutputQueue(bool restore_function_code) { | 140 void OptimizingCompilerThread::FlushOutputQueue(bool restore_function_code) { |
145 OptimizingCompiler* optimizing_compiler; | 141 OptimizingCompiler* optimizing_compiler; |
146 // The optimizing compiler is allocated in the CompilationInfo's zone. | 142 // The optimizing compiler is allocated in the CompilationInfo's zone. |
147 while (true) { | 143 while (output_queue_.Dequeue(&optimizing_compiler)) { |
148 { LockGuard<Mutex> access_queue(&queue_mutex_); | |
149 if (!output_queue_.Dequeue(&optimizing_compiler)) break; | |
150 } | |
151 CompilationInfo* info = optimizing_compiler->info(); | 144 CompilationInfo* info = optimizing_compiler->info(); |
152 if (restore_function_code) { | 145 if (restore_function_code) { |
153 Handle<JSFunction> function = info->closure(); | 146 Handle<JSFunction> function = info->closure(); |
154 function->ReplaceCode(function->shared()->code()); | 147 function->ReplaceCode(function->shared()->code()); |
155 } | 148 } |
156 delete info; | 149 delete info; |
157 } | 150 } |
158 | 151 |
| 152 osr_candidates_.Clear(); |
159 RemoveStaleOSRCandidates(0); | 153 RemoveStaleOSRCandidates(0); |
160 } | 154 } |
161 | 155 |
162 | 156 |
163 void OptimizingCompilerThread::Flush() { | 157 void OptimizingCompilerThread::Flush() { |
164 ASSERT(!IsOptimizerThread()); | 158 ASSERT(!IsOptimizerThread()); |
165 Release_Store(&stop_thread_, static_cast<AtomicWord>(FLUSH)); | 159 Release_Store(&stop_thread_, static_cast<AtomicWord>(FLUSH)); |
166 input_queue_semaphore_.Signal(); | 160 input_queue_semaphore_.Signal(); |
167 stop_semaphore_.Wait(); | 161 stop_semaphore_.Wait(); |
168 FlushOutputQueue(true); | 162 FlushOutputQueue(true); |
(...skipping 26 matching lines...) Expand all Loading... |
195 PrintF("[COSR hit rate %d / %d]\n", osr_hits_, osr_attempts_); | 189 PrintF("[COSR hit rate %d / %d]\n", osr_hits_, osr_attempts_); |
196 } | 190 } |
197 | 191 |
198 Join(); | 192 Join(); |
199 } | 193 } |
200 | 194 |
201 | 195 |
202 void OptimizingCompilerThread::InstallOptimizedFunctions() { | 196 void OptimizingCompilerThread::InstallOptimizedFunctions() { |
203 ASSERT(!IsOptimizerThread()); | 197 ASSERT(!IsOptimizerThread()); |
204 HandleScope handle_scope(isolate_); | 198 HandleScope handle_scope(isolate_); |
205 | |
206 OptimizingCompiler* compiler; | 199 OptimizingCompiler* compiler; |
207 while (true) { | 200 while (true) { |
208 { LockGuard<Mutex> access_queue(&queue_mutex_); | 201 if (!output_queue_.Dequeue(&compiler)) return; |
209 if (!output_queue_.Dequeue(&compiler)) break; | |
210 } | |
211 Compiler::InstallOptimizedCode(compiler); | 202 Compiler::InstallOptimizedCode(compiler); |
212 } | 203 } |
213 | 204 |
214 // Remove the oldest OSR candidates that are ready so that we | 205 // Remove the oldest OSR candidates that are ready so that we |
215 // only have limited number of them waiting. | 206 // only have limited number of them waiting. |
216 if (FLAG_concurrent_osr) RemoveStaleOSRCandidates(); | 207 if (FLAG_concurrent_osr) RemoveStaleOSRCandidates(); |
217 } | 208 } |
218 | 209 |
219 | 210 |
220 void OptimizingCompilerThread::QueueForOptimization( | 211 void OptimizingCompilerThread::QueueForOptimization( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 #ifdef DEBUG | 288 #ifdef DEBUG |
298 bool OptimizingCompilerThread::IsOptimizerThread() { | 289 bool OptimizingCompilerThread::IsOptimizerThread() { |
299 if (!FLAG_concurrent_recompilation) return false; | 290 if (!FLAG_concurrent_recompilation) return false; |
300 LockGuard<Mutex> lock_guard(&thread_id_mutex_); | 291 LockGuard<Mutex> lock_guard(&thread_id_mutex_); |
301 return ThreadId::Current().ToInteger() == thread_id_; | 292 return ThreadId::Current().ToInteger() == thread_id_; |
302 } | 293 } |
303 #endif | 294 #endif |
304 | 295 |
305 | 296 |
306 } } // namespace v8::internal | 297 } } // namespace v8::internal |
OLD | NEW |