Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: src/optimizing-compiler-thread.cc

Issue 23902033: Add mutex when accessing concurrent recompilation output queue. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comment Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/optimizing-compiler-thread.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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));
78 Release_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE)); 77 Release_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE));
79 stop_semaphore_.Signal(); 78 stop_semaphore_.Signal();
80 // Return to start of consumer loop. 79 // Return to start of consumer loop.
81 continue; 80 continue;
82 } 81 }
83 82
84 ElapsedTimer compiling_timer; 83 ElapsedTimer compiling_timer;
85 if (FLAG_trace_concurrent_recompilation) compiling_timer.Start(); 84 if (FLAG_trace_concurrent_recompilation) compiling_timer.Start();
86 85
87 CompileNext(); 86 CompileNext();
(...skipping 19 matching lines...) Expand all
107 106
108 // The function may have already been optimized by OSR. Simply continue. 107 // The function may have already been optimized by OSR. Simply continue.
109 // Use a mutex to make sure that functions marked for install 108 // Use a mutex to make sure that functions marked for install
110 // are always also queued. 109 // are always also queued.
111 if (!optimizing_compiler->info()->osr_ast_id().IsNone()) { 110 if (!optimizing_compiler->info()->osr_ast_id().IsNone()) {
112 ASSERT(FLAG_concurrent_osr); 111 ASSERT(FLAG_concurrent_osr);
113 LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); 112 LockGuard<Mutex> access_osr_lists(&osr_list_mutex_);
114 osr_candidates_.RemoveElement(optimizing_compiler); 113 osr_candidates_.RemoveElement(optimizing_compiler);
115 ready_for_osr_.Add(optimizing_compiler); 114 ready_for_osr_.Add(optimizing_compiler);
116 } else { 115 } 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();
137 } 141 }
138 142
139 143
140 void OptimizingCompilerThread::FlushOutputQueue(bool restore_function_code) { 144 void OptimizingCompilerThread::FlushOutputQueue(bool restore_function_code) {
141 OptimizingCompiler* optimizing_compiler; 145 OptimizingCompiler* optimizing_compiler;
142 // The optimizing compiler is allocated in the CompilationInfo's zone. 146 // The optimizing compiler is allocated in the CompilationInfo's zone.
143 while (output_queue_.Dequeue(&optimizing_compiler)) { 147 while (true) {
148 { LockGuard<Mutex> access_queue(&queue_mutex_);
149 if (!output_queue_.Dequeue(&optimizing_compiler)) break;
150 }
144 CompilationInfo* info = optimizing_compiler->info(); 151 CompilationInfo* info = optimizing_compiler->info();
145 if (restore_function_code) { 152 if (restore_function_code) {
146 Handle<JSFunction> function = info->closure(); 153 Handle<JSFunction> function = info->closure();
147 function->ReplaceCode(function->shared()->code()); 154 function->ReplaceCode(function->shared()->code());
148 } 155 }
149 delete info; 156 delete info;
150 } 157 }
151 158
152 osr_candidates_.Clear();
153 RemoveStaleOSRCandidates(0); 159 RemoveStaleOSRCandidates(0);
154 } 160 }
155 161
156 162
157 void OptimizingCompilerThread::Flush() { 163 void OptimizingCompilerThread::Flush() {
158 ASSERT(!IsOptimizerThread()); 164 ASSERT(!IsOptimizerThread());
159 Release_Store(&stop_thread_, static_cast<AtomicWord>(FLUSH)); 165 Release_Store(&stop_thread_, static_cast<AtomicWord>(FLUSH));
160 input_queue_semaphore_.Signal(); 166 input_queue_semaphore_.Signal();
161 stop_semaphore_.Wait(); 167 stop_semaphore_.Wait();
162 FlushOutputQueue(true); 168 FlushOutputQueue(true);
(...skipping 26 matching lines...) Expand all
189 PrintF("[COSR hit rate %d / %d]\n", osr_hits_, osr_attempts_); 195 PrintF("[COSR hit rate %d / %d]\n", osr_hits_, osr_attempts_);
190 } 196 }
191 197
192 Join(); 198 Join();
193 } 199 }
194 200
195 201
196 void OptimizingCompilerThread::InstallOptimizedFunctions() { 202 void OptimizingCompilerThread::InstallOptimizedFunctions() {
197 ASSERT(!IsOptimizerThread()); 203 ASSERT(!IsOptimizerThread());
198 HandleScope handle_scope(isolate_); 204 HandleScope handle_scope(isolate_);
205
199 OptimizingCompiler* compiler; 206 OptimizingCompiler* compiler;
200 while (true) { 207 while (true) {
201 if (!output_queue_.Dequeue(&compiler)) return; 208 { LockGuard<Mutex> access_queue(&queue_mutex_);
209 if (!output_queue_.Dequeue(&optimizing_compiler)) break;
210 }
202 Compiler::InstallOptimizedCode(compiler); 211 Compiler::InstallOptimizedCode(compiler);
203 } 212 }
204 213
205 // Remove the oldest OSR candidates that are ready so that we 214 // Remove the oldest OSR candidates that are ready so that we
206 // only have limited number of them waiting. 215 // only have limited number of them waiting.
207 if (FLAG_concurrent_osr) RemoveStaleOSRCandidates(); 216 if (FLAG_concurrent_osr) RemoveStaleOSRCandidates();
208 } 217 }
209 218
210 219
211 void OptimizingCompilerThread::QueueForOptimization( 220 void OptimizingCompilerThread::QueueForOptimization(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 #ifdef DEBUG 297 #ifdef DEBUG
289 bool OptimizingCompilerThread::IsOptimizerThread() { 298 bool OptimizingCompilerThread::IsOptimizerThread() {
290 if (!FLAG_concurrent_recompilation) return false; 299 if (!FLAG_concurrent_recompilation) return false;
291 LockGuard<Mutex> lock_guard(&thread_id_mutex_); 300 LockGuard<Mutex> lock_guard(&thread_id_mutex_);
292 return ThreadId::Current().ToInteger() == thread_id_; 301 return ThreadId::Current().ToInteger() == thread_id_;
293 } 302 }
294 #endif 303 #endif
295 304
296 305
297 } } // namespace v8::internal 306 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/optimizing-compiler-thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698