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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 | 53 |
54 while (true) { | 54 while (true) { |
55 input_queue_semaphore_->Wait(); | 55 input_queue_semaphore_->Wait(); |
56 Logger::TimerEventScope timer( | 56 Logger::TimerEventScope timer( |
57 isolate_, Logger::TimerEventScope::v8_recompile_parallel); | 57 isolate_, Logger::TimerEventScope::v8_recompile_parallel); |
58 | 58 |
59 if (FLAG_parallel_recompilation_delay != 0) { | 59 if (FLAG_parallel_recompilation_delay != 0) { |
60 OS::Sleep(FLAG_parallel_recompilation_delay); | 60 OS::Sleep(FLAG_parallel_recompilation_delay); |
61 } | 61 } |
62 | 62 |
63 if (Acquire_Load(&stop_thread_)) { | 63 switch (static_cast<StopFlag>(Acquire_Load(&stop_thread_))) { |
64 stop_semaphore_->Signal(); | 64 case CONTINUE: |
65 if (FLAG_trace_parallel_recompilation) { | 65 break; |
66 time_spent_total_ = OS::Ticks() - epoch; | 66 case STOP: |
67 } | 67 if (FLAG_trace_parallel_recompilation) { |
68 return; | 68 time_spent_total_ = OS::Ticks() - epoch; |
69 } | |
70 stop_semaphore_->Signal(); | |
71 return; | |
72 case FLUSH: | |
73 // Reset input queue semaphore. | |
74 delete input_queue_semaphore_; | |
75 input_queue_semaphore_ = OS::CreateSemaphore(0); | |
76 // Signal for main thread to start flushing. | |
77 stop_semaphore_->Signal(); | |
78 // Return to start of consumer loop. | |
79 continue; | |
69 } | 80 } |
70 | 81 |
71 int64_t compiling_start = 0; | 82 int64_t compiling_start = 0; |
72 if (FLAG_trace_parallel_recompilation) compiling_start = OS::Ticks(); | 83 if (FLAG_trace_parallel_recompilation) compiling_start = OS::Ticks(); |
73 | 84 |
74 CompileNext(); | 85 CompileNext(); |
75 | 86 |
76 if (FLAG_trace_parallel_recompilation) { | 87 if (FLAG_trace_parallel_recompilation) { |
77 time_spent_compiling_ += OS::Ticks() - compiling_start; | 88 time_spent_compiling_ += OS::Ticks() - compiling_start; |
78 } | 89 } |
(...skipping 16 matching lines...) Expand all Loading... | |
95 // are always also queued. | 106 // are always also queued. |
96 ScopedLock mark_and_queue(install_mutex_); | 107 ScopedLock mark_and_queue(install_mutex_); |
97 { Heap::RelocationLock relocation_lock(isolate_->heap()); | 108 { Heap::RelocationLock relocation_lock(isolate_->heap()); |
98 AllowHandleDereference ahd; | 109 AllowHandleDereference ahd; |
99 optimizing_compiler->info()->closure()->MarkForInstallingRecompiledCode(); | 110 optimizing_compiler->info()->closure()->MarkForInstallingRecompiledCode(); |
100 } | 111 } |
101 output_queue_.Enqueue(optimizing_compiler); | 112 output_queue_.Enqueue(optimizing_compiler); |
102 } | 113 } |
103 | 114 |
104 | 115 |
116 void OptimizingCompilerThread::FlushQueue( | |
117 UnboundQueue<OptimizingCompiler*>* queue, | |
118 bool restore_function_code) { | |
119 ASSERT(!IsOptimizerThread()); | |
120 OptimizingCompiler* optimizing_compiler; | |
121 // The optimizing compiler is allocated in the CompilationInfo's zone. | |
122 while (queue->Dequeue(&optimizing_compiler)) { | |
123 CompilationInfo* info = optimizing_compiler->info(); | |
124 if (restore_function_code) { | |
125 Handle<JSFunction> function = info->closure(); | |
126 function->ReplaceCode(function->shared()->code()); | |
127 } | |
128 delete info; | |
129 } | |
130 } | |
131 | |
132 | |
133 void OptimizingCompilerThread::Flush() { | |
134 ASSERT(!IsOptimizerThread()); | |
135 Release_Store(&stop_thread_, static_cast<AtomicWord>(FLUSH)); | |
Michael Starzinger
2013/08/06 17:57:56
This is still racey, the FLUSH command might be ex
| |
136 input_queue_semaphore_->Signal(); | |
137 stop_semaphore_->Wait(); | |
138 | |
139 // At this point, the optimizing thread is idling. It is waiting for | |
140 // the input semaphore, which has just been reset. It will not continue | |
141 // as long as the input semaphore is not signaled (by the main thread). | |
142 // Relying the input semaphore, we don't need any explicit memory barrier. | |
143 FlushQueue(&input_queue_, true); | |
144 FlushQueue(&output_queue_, true); | |
145 NoBarrier_Store(&queue_length_, static_cast<AtomicWord>(0)); | |
146 NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE)); | |
147 } | |
148 | |
149 | |
105 void OptimizingCompilerThread::Stop() { | 150 void OptimizingCompilerThread::Stop() { |
106 ASSERT(!IsOptimizerThread()); | 151 ASSERT(!IsOptimizerThread()); |
107 Release_Store(&stop_thread_, static_cast<AtomicWord>(true)); | 152 Release_Store(&stop_thread_, static_cast<AtomicWord>(STOP)); |
108 input_queue_semaphore_->Signal(); | 153 input_queue_semaphore_->Signal(); |
109 stop_semaphore_->Wait(); | 154 stop_semaphore_->Wait(); |
110 | 155 |
111 if (FLAG_parallel_recompilation_delay != 0) { | 156 if (FLAG_parallel_recompilation_delay != 0) { |
112 // Barrier when loading queue length is not necessary since the write | 157 // Barrier when loading queue length is not necessary since the write |
113 // happens in CompileNext on the same thread. | 158 // happens in CompileNext on the same thread. |
114 while (NoBarrier_Load(&queue_length_) > 0) CompileNext(); | 159 while (NoBarrier_Load(&queue_length_) > 0) CompileNext(); |
115 InstallOptimizedFunctions(); | 160 InstallOptimizedFunctions(); |
116 } else { | 161 } else { |
117 OptimizingCompiler* optimizing_compiler; | 162 FlushQueue(&input_queue_, false); |
118 // The optimizing compiler is allocated in the CompilationInfo's zone. | 163 FlushQueue(&output_queue_, false); |
119 while (input_queue_.Dequeue(&optimizing_compiler)) { | |
120 delete optimizing_compiler->info(); | |
121 } | |
122 while (output_queue_.Dequeue(&optimizing_compiler)) { | |
123 delete optimizing_compiler->info(); | |
124 } | |
125 } | 164 } |
126 | 165 |
127 if (FLAG_trace_parallel_recompilation) { | 166 if (FLAG_trace_parallel_recompilation) { |
128 double compile_time = static_cast<double>(time_spent_compiling_); | 167 double compile_time = static_cast<double>(time_spent_compiling_); |
129 double total_time = static_cast<double>(time_spent_total_); | 168 double total_time = static_cast<double>(time_spent_total_); |
130 double percentage = (compile_time * 100) / total_time; | 169 double percentage = (compile_time * 100) / total_time; |
131 PrintF(" ** Compiler thread did %.2f%% useful work\n", percentage); | 170 PrintF(" ** Compiler thread did %.2f%% useful work\n", percentage); |
132 } | 171 } |
133 | 172 |
134 Join(); | 173 Join(); |
(...skipping 28 matching lines...) Expand all Loading... | |
163 #ifdef DEBUG | 202 #ifdef DEBUG |
164 bool OptimizingCompilerThread::IsOptimizerThread() { | 203 bool OptimizingCompilerThread::IsOptimizerThread() { |
165 if (!FLAG_parallel_recompilation) return false; | 204 if (!FLAG_parallel_recompilation) return false; |
166 ScopedLock lock(thread_id_mutex_); | 205 ScopedLock lock(thread_id_mutex_); |
167 return ThreadId::Current().ToInteger() == thread_id_; | 206 return ThreadId::Current().ToInteger() == thread_id_; |
168 } | 207 } |
169 #endif | 208 #endif |
170 | 209 |
171 | 210 |
172 } } // namespace v8::internal | 211 } } // namespace v8::internal |
OLD | NEW |