Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | |
| 28 #include "optimizing-compiler-thread.h" | |
| 29 | |
| 30 #include "v8.h" | |
| 31 | |
| 32 #include "hydrogen.h" | |
| 33 #include "isolate.h" | |
| 34 #include "v8threads.h" | |
| 35 | |
| 36 namespace v8 { | |
| 37 namespace internal { | |
| 38 | |
| 39 | |
| 40 void OptimizingCompilerThread::Run() { | |
| 41 #ifdef DEBUG | |
| 42 thread_id_ = ThreadId::Current().ToInteger(); | |
| 43 #endif | |
| 44 Isolate::SetIsolateThreadLocals(isolate_, NULL); | |
| 45 | |
| 46 while (true) { | |
| 47 input_queue_semaphore_->Wait(); | |
| 48 if (Acquire_Load(&stop_thread_)) { | |
| 49 stop_semaphore_->Signal(); | |
| 50 return; | |
| 51 } | |
| 52 | |
| 53 Heap::RelocationLock relocation_lock(isolate_->heap()); | |
| 54 OptimizingCompiler* optimizing_compiler = NULL; | |
| 55 input_queue_.Dequeue(&optimizing_compiler); | |
| 56 Barrier_AtomicIncrement(&queue_length_, static_cast<Atomic32>(-1)); | |
| 57 | |
| 58 ASSERT(!optimizing_compiler->info()->closure()->IsOptimized()); | |
| 59 | |
| 60 OptimizingCompiler::Status status = optimizing_compiler->OptimizeGraph(); | |
| 61 ASSERT(status != OptimizingCompiler::FAILED); | |
| 62 (void) status; | |
| 63 | |
| 64 output_queue_.Enqueue(optimizing_compiler); | |
| 65 isolate_->stack_guard()->RequestCodeReadyEvent(); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 | |
| 70 void OptimizingCompilerThread::Stop() { | |
| 71 Release_Store(&stop_thread_, static_cast<AtomicWord>(true)); | |
| 72 input_queue_semaphore_->Signal(); | |
| 73 stop_semaphore_->Wait(); | |
| 74 } | |
| 75 | |
| 76 | |
| 77 void OptimizingCompilerThread::InstallOptimizedFunctions() { | |
| 78 HandleScope handle_scope(isolate_); | |
| 79 int functions_installed = 0; | |
| 80 while (!output_queue_.IsEmpty()) { | |
| 81 OptimizingCompiler* compiler = NULL; | |
|
Yang
2012/07/19 12:47:30
Maybe OptimizingCompileTask would be a better name
sanjoy
2012/07/19 15:06:09
I'm not sure about this -- MakeCrankshaftCode uses
| |
| 82 output_queue_.Dequeue(&compiler); | |
| 83 Compiler::InstallOptimizedCode(compiler); | |
| 84 functions_installed++; | |
| 85 } | |
| 86 if (FLAG_trace_parallel_recompilation && functions_installed != 0) { | |
| 87 PrintF(" ** Installed %d function(s).\n", functions_installed); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 | |
| 92 void OptimizingCompilerThread::QueueForOptimization( | |
| 93 OptimizingCompiler* optimizing_compiler) { | |
| 94 input_queue_.Enqueue(optimizing_compiler); | |
| 95 input_queue_semaphore_->Signal(); | |
| 96 } | |
| 97 | |
| 98 #ifdef DEBUG | |
| 99 bool OptimizingCompilerThread::IsOptimizerThread() { | |
| 100 return ThreadId::Current().ToInteger() == thread_id_; | |
| 101 } | |
| 102 #endif | |
| 103 | |
| 104 | |
| 105 } } // namespace v8::internal | |
| OLD | NEW |