| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 OptimizingCompiler* optimizing_compiler = NULL; | 82 OptimizingCompiler* optimizing_compiler = NULL; |
| 83 input_queue_.Dequeue(&optimizing_compiler); | 83 input_queue_.Dequeue(&optimizing_compiler); |
| 84 Barrier_AtomicIncrement(&queue_length_, static_cast<Atomic32>(-1)); | 84 Barrier_AtomicIncrement(&queue_length_, static_cast<Atomic32>(-1)); |
| 85 | 85 |
| 86 // The function may have already been optimized by OSR. Simply continue. | 86 // The function may have already been optimized by OSR. Simply continue. |
| 87 OptimizingCompiler::Status status = optimizing_compiler->OptimizeGraph(); | 87 OptimizingCompiler::Status status = optimizing_compiler->OptimizeGraph(); |
| 88 USE(status); // Prevent an unused-variable error in release mode. | 88 USE(status); // Prevent an unused-variable error in release mode. |
| 89 ASSERT(status != OptimizingCompiler::FAILED); | 89 ASSERT(status != OptimizingCompiler::FAILED); |
| 90 | 90 |
| 91 // The function may have already been optimized by OSR. Simply continue. | 91 // The function may have already been optimized by OSR. Simply continue. |
| 92 // Mark it for installing before queuing so that we can be sure of the write | 92 // Use a mutex to make sure that functions marked for install |
| 93 // order: marking first and (after being queued) installing code second. | 93 // are always also queued. |
| 94 ScopedLock mark_and_queue(install_mutex_); |
| 94 { Heap::RelocationLock relocation_lock(isolate_->heap()); | 95 { Heap::RelocationLock relocation_lock(isolate_->heap()); |
| 95 AllowHandleDereference ahd; | 96 AllowHandleDereference ahd; |
| 96 optimizing_compiler->info()->closure()->MarkForInstallingRecompiledCode(); | 97 optimizing_compiler->info()->closure()->MarkForInstallingRecompiledCode(); |
| 97 } | 98 } |
| 98 output_queue_.Enqueue(optimizing_compiler); | 99 output_queue_.Enqueue(optimizing_compiler); |
| 99 } | 100 } |
| 100 | 101 |
| 101 | 102 |
| 102 void OptimizingCompilerThread::Stop() { | 103 void OptimizingCompilerThread::Stop() { |
| 103 ASSERT(!IsOptimizerThread()); | 104 ASSERT(!IsOptimizerThread()); |
| 104 Release_Store(&stop_thread_, static_cast<AtomicWord>(true)); | 105 Release_Store(&stop_thread_, static_cast<AtomicWord>(true)); |
| 105 input_queue_semaphore_->Signal(); | 106 input_queue_semaphore_->Signal(); |
| 106 stop_semaphore_->Wait(); | 107 stop_semaphore_->Wait(); |
| 107 | 108 |
| 108 if (FLAG_parallel_recompilation_delay != 0) { | 109 if (FLAG_parallel_recompilation_delay != 0) { |
| 109 InstallOptimizedFunctions(); | |
| 110 // Barrier when loading queue length is not necessary since the write | 110 // Barrier when loading queue length is not necessary since the write |
| 111 // happens in CompileNext on the same thread. | 111 // happens in CompileNext on the same thread. |
| 112 while (NoBarrier_Load(&queue_length_) > 0) { | 112 while (NoBarrier_Load(&queue_length_) > 0) CompileNext(); |
| 113 CompileNext(); | 113 InstallOptimizedFunctions(); |
| 114 InstallOptimizedFunctions(); | 114 } else { |
| 115 OptimizingCompiler* optimizing_compiler; |
| 116 while (input_queue_.Dequeue(&optimizing_compiler)) { |
| 117 // The optimizing compiler is allocated in the CompilationInfo's zone. |
| 118 delete optimizing_compiler->info(); |
| 115 } | 119 } |
| 116 } | 120 } |
| 117 | 121 |
| 118 if (FLAG_trace_parallel_recompilation) { | 122 if (FLAG_trace_parallel_recompilation) { |
| 119 double compile_time = static_cast<double>(time_spent_compiling_); | 123 double compile_time = static_cast<double>(time_spent_compiling_); |
| 120 double total_time = static_cast<double>(time_spent_total_); | 124 double total_time = static_cast<double>(time_spent_total_); |
| 121 double percentage = (compile_time * 100) / total_time; | 125 double percentage = (compile_time * 100) / total_time; |
| 122 PrintF(" ** Compiler thread did %.2f%% useful work\n", percentage); | 126 PrintF(" ** Compiler thread did %.2f%% useful work\n", percentage); |
| 123 } | 127 } |
| 124 } | 128 } |
| 125 | 129 |
| 126 | 130 |
| 127 void OptimizingCompilerThread::InstallOptimizedFunctions() { | 131 void OptimizingCompilerThread::InstallOptimizedFunctions() { |
| 128 ASSERT(!IsOptimizerThread()); | 132 ASSERT(!IsOptimizerThread()); |
| 129 HandleScope handle_scope(isolate_); | 133 HandleScope handle_scope(isolate_); |
| 130 int functions_installed = 0; | 134 OptimizingCompiler* compiler; |
| 131 while (!output_queue_.IsEmpty()) { | 135 while (true) { |
| 132 OptimizingCompiler* compiler; | 136 { // Memory barrier to ensure marked functions are queued. |
| 133 output_queue_.Dequeue(&compiler); | 137 ScopedLock marked_and_queued(install_mutex_); |
| 138 if (!output_queue_.Dequeue(&compiler)) return; |
| 139 } |
| 134 Compiler::InstallOptimizedCode(compiler); | 140 Compiler::InstallOptimizedCode(compiler); |
| 135 functions_installed++; | |
| 136 } | 141 } |
| 137 } | 142 } |
| 138 | 143 |
| 139 | 144 |
| 140 void OptimizingCompilerThread::QueueForOptimization( | 145 void OptimizingCompilerThread::QueueForOptimization( |
| 141 OptimizingCompiler* optimizing_compiler) { | 146 OptimizingCompiler* optimizing_compiler) { |
| 142 ASSERT(IsQueueAvailable()); | 147 ASSERT(IsQueueAvailable()); |
| 143 ASSERT(!IsOptimizerThread()); | 148 ASSERT(!IsOptimizerThread()); |
| 144 Barrier_AtomicIncrement(&queue_length_, static_cast<Atomic32>(1)); | 149 Barrier_AtomicIncrement(&queue_length_, static_cast<Atomic32>(1)); |
| 145 optimizing_compiler->info()->closure()->MarkInRecompileQueue(); | 150 optimizing_compiler->info()->closure()->MarkInRecompileQueue(); |
| 146 input_queue_.Enqueue(optimizing_compiler); | 151 input_queue_.Enqueue(optimizing_compiler); |
| 147 input_queue_semaphore_->Signal(); | 152 input_queue_semaphore_->Signal(); |
| 148 } | 153 } |
| 149 | 154 |
| 150 | 155 |
| 151 #ifdef DEBUG | 156 #ifdef DEBUG |
| 152 bool OptimizingCompilerThread::IsOptimizerThread() { | 157 bool OptimizingCompilerThread::IsOptimizerThread() { |
| 153 if (!FLAG_parallel_recompilation) return false; | 158 if (!FLAG_parallel_recompilation) return false; |
| 154 return ThreadId::Current().ToInteger() == thread_id_; | 159 return ThreadId::Current().ToInteger() == thread_id_; |
| 155 } | 160 } |
| 156 #endif | 161 #endif |
| 157 | 162 |
| 158 | 163 |
| 159 } } // namespace v8::internal | 164 } } // namespace v8::internal |
| OLD | NEW |