| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #endif | 45 #endif |
| 46 Isolate::SetIsolateThreadLocals(isolate_, NULL); | 46 Isolate::SetIsolateThreadLocals(isolate_, NULL); |
| 47 DisallowHeapAllocation no_allocation; | 47 DisallowHeapAllocation no_allocation; |
| 48 DisallowHandleAllocation no_handles; | 48 DisallowHandleAllocation no_handles; |
| 49 DisallowHandleDereference no_deref; | 49 DisallowHandleDereference no_deref; |
| 50 | 50 |
| 51 ElapsedTimer total_timer; | 51 ElapsedTimer total_timer; |
| 52 if (FLAG_trace_concurrent_recompilation) total_timer.Start(); | 52 if (FLAG_trace_concurrent_recompilation) total_timer.Start(); |
| 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_concurrent); | 57 isolate_, Logger::TimerEventScope::v8_recompile_concurrent); |
| 58 | 58 |
| 59 if (FLAG_concurrent_recompilation_delay != 0) { | 59 if (FLAG_concurrent_recompilation_delay != 0) { |
| 60 OS::Sleep(FLAG_concurrent_recompilation_delay); | 60 OS::Sleep(FLAG_concurrent_recompilation_delay); |
| 61 } | 61 } |
| 62 | 62 |
| 63 switch (static_cast<StopFlag>(Acquire_Load(&stop_thread_))) { | 63 switch (static_cast<StopFlag>(Acquire_Load(&stop_thread_))) { |
| 64 case CONTINUE: | 64 case CONTINUE: |
| 65 break; | 65 break; |
| 66 case STOP: | 66 case STOP: |
| 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(&queue_length_, static_cast<AtomicWord>(0)); |
| 78 Release_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE)); | 78 Release_Store(&stop_thread_, static_cast<AtomicWord>(CONTINUE)); |
| 79 stop_semaphore_->Signal(); | 79 stop_semaphore_.Signal(); |
| 80 // Return to start of consumer loop. | 80 // Return to start of consumer loop. |
| 81 continue; | 81 continue; |
| 82 } | 82 } |
| 83 | 83 |
| 84 ElapsedTimer compiling_timer; | 84 ElapsedTimer compiling_timer; |
| 85 if (FLAG_trace_concurrent_recompilation) compiling_timer.Start(); | 85 if (FLAG_trace_concurrent_recompilation) compiling_timer.Start(); |
| 86 | 86 |
| 87 CompileNext(); | 87 CompileNext(); |
| 88 | 88 |
| 89 if (FLAG_trace_concurrent_recompilation) { | 89 if (FLAG_trace_concurrent_recompilation) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 116 output_queue_.Enqueue(optimizing_compiler); | 116 output_queue_.Enqueue(optimizing_compiler); |
| 117 } | 117 } |
| 118 | 118 |
| 119 | 119 |
| 120 void OptimizingCompilerThread::FlushInputQueue(bool restore_function_code) { | 120 void OptimizingCompilerThread::FlushInputQueue(bool restore_function_code) { |
| 121 OptimizingCompiler* optimizing_compiler; | 121 OptimizingCompiler* optimizing_compiler; |
| 122 // The optimizing compiler is allocated in the CompilationInfo's zone. | 122 // The optimizing compiler is allocated in the CompilationInfo's zone. |
| 123 while (input_queue_.Dequeue(&optimizing_compiler)) { | 123 while (input_queue_.Dequeue(&optimizing_compiler)) { |
| 124 // This should not block, since we have one signal on the input queue | 124 // This should not block, since we have one signal on the input queue |
| 125 // semaphore corresponding to each element in the input queue. | 125 // semaphore corresponding to each element in the input queue. |
| 126 input_queue_semaphore_->Wait(); | 126 input_queue_semaphore_.Wait(); |
| 127 CompilationInfo* info = optimizing_compiler->info(); | 127 CompilationInfo* info = optimizing_compiler->info(); |
| 128 if (restore_function_code) { | 128 if (restore_function_code) { |
| 129 Handle<JSFunction> function = info->closure(); | 129 Handle<JSFunction> function = info->closure(); |
| 130 function->ReplaceCode(function->shared()->code()); | 130 function->ReplaceCode(function->shared()->code()); |
| 131 } | 131 } |
| 132 delete info; | 132 delete info; |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 | 136 |
| 137 void OptimizingCompilerThread::FlushOutputQueue(bool restore_function_code) { | 137 void OptimizingCompilerThread::FlushOutputQueue(bool restore_function_code) { |
| 138 OptimizingCompiler* optimizing_compiler; | 138 OptimizingCompiler* optimizing_compiler; |
| 139 // The optimizing compiler is allocated in the CompilationInfo's zone. | 139 // The optimizing compiler is allocated in the CompilationInfo's zone. |
| 140 while (output_queue_.Dequeue(&optimizing_compiler)) { | 140 while (output_queue_.Dequeue(&optimizing_compiler)) { |
| 141 CompilationInfo* info = optimizing_compiler->info(); | 141 CompilationInfo* info = optimizing_compiler->info(); |
| 142 if (restore_function_code) { | 142 if (restore_function_code) { |
| 143 Handle<JSFunction> function = info->closure(); | 143 Handle<JSFunction> function = info->closure(); |
| 144 function->ReplaceCode(function->shared()->code()); | 144 function->ReplaceCode(function->shared()->code()); |
| 145 } | 145 } |
| 146 delete info; | 146 delete info; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 | 150 |
| 151 void OptimizingCompilerThread::Flush() { | 151 void OptimizingCompilerThread::Flush() { |
| 152 ASSERT(!IsOptimizerThread()); | 152 ASSERT(!IsOptimizerThread()); |
| 153 Release_Store(&stop_thread_, static_cast<AtomicWord>(FLUSH)); | 153 Release_Store(&stop_thread_, static_cast<AtomicWord>(FLUSH)); |
| 154 input_queue_semaphore_->Signal(); | 154 input_queue_semaphore_.Signal(); |
| 155 stop_semaphore_->Wait(); | 155 stop_semaphore_.Wait(); |
| 156 FlushOutputQueue(true); | 156 FlushOutputQueue(true); |
| 157 } | 157 } |
| 158 | 158 |
| 159 | 159 |
| 160 void OptimizingCompilerThread::Stop() { | 160 void OptimizingCompilerThread::Stop() { |
| 161 ASSERT(!IsOptimizerThread()); | 161 ASSERT(!IsOptimizerThread()); |
| 162 Release_Store(&stop_thread_, static_cast<AtomicWord>(STOP)); | 162 Release_Store(&stop_thread_, static_cast<AtomicWord>(STOP)); |
| 163 input_queue_semaphore_->Signal(); | 163 input_queue_semaphore_.Signal(); |
| 164 stop_semaphore_->Wait(); | 164 stop_semaphore_.Wait(); |
| 165 | 165 |
| 166 if (FLAG_concurrent_recompilation_delay != 0) { | 166 if (FLAG_concurrent_recompilation_delay != 0) { |
| 167 // Barrier when loading queue length is not necessary since the write | 167 // Barrier when loading queue length is not necessary since the write |
| 168 // happens in CompileNext on the same thread. | 168 // happens in CompileNext on the same thread. |
| 169 // This is used only for testing. | 169 // This is used only for testing. |
| 170 while (NoBarrier_Load(&queue_length_) > 0) CompileNext(); | 170 while (NoBarrier_Load(&queue_length_) > 0) CompileNext(); |
| 171 InstallOptimizedFunctions(); | 171 InstallOptimizedFunctions(); |
| 172 } else { | 172 } else { |
| 173 FlushInputQueue(false); | 173 FlushInputQueue(false); |
| 174 FlushOutputQueue(false); | 174 FlushOutputQueue(false); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 197 } | 197 } |
| 198 | 198 |
| 199 | 199 |
| 200 void OptimizingCompilerThread::QueueForOptimization( | 200 void OptimizingCompilerThread::QueueForOptimization( |
| 201 OptimizingCompiler* optimizing_compiler) { | 201 OptimizingCompiler* optimizing_compiler) { |
| 202 ASSERT(IsQueueAvailable()); | 202 ASSERT(IsQueueAvailable()); |
| 203 ASSERT(!IsOptimizerThread()); | 203 ASSERT(!IsOptimizerThread()); |
| 204 Barrier_AtomicIncrement(&queue_length_, static_cast<Atomic32>(1)); | 204 Barrier_AtomicIncrement(&queue_length_, static_cast<Atomic32>(1)); |
| 205 optimizing_compiler->info()->closure()->MarkInRecompileQueue(); | 205 optimizing_compiler->info()->closure()->MarkInRecompileQueue(); |
| 206 input_queue_.Enqueue(optimizing_compiler); | 206 input_queue_.Enqueue(optimizing_compiler); |
| 207 input_queue_semaphore_->Signal(); | 207 input_queue_semaphore_.Signal(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 | 210 |
| 211 #ifdef DEBUG | 211 #ifdef DEBUG |
| 212 bool OptimizingCompilerThread::IsOptimizerThread() { | 212 bool OptimizingCompilerThread::IsOptimizerThread() { |
| 213 if (!FLAG_concurrent_recompilation) return false; | 213 if (!FLAG_concurrent_recompilation) return false; |
| 214 LockGuard<Mutex> lock_guard(&thread_id_mutex_); | 214 LockGuard<Mutex> lock_guard(&thread_id_mutex_); |
| 215 return ThreadId::Current().ToInteger() == thread_id_; | 215 return ThreadId::Current().ToInteger() == thread_id_; |
| 216 } | 216 } |
| 217 #endif | 217 #endif |
| 218 | 218 |
| 219 | 219 |
| 220 } } // namespace v8::internal | 220 } } // namespace v8::internal |
| OLD | NEW |