| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2010 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 "isolate.h" |
| 31 #include "v8threads.h" |
| 32 |
| 33 namespace v8 { |
| 34 namespace internal { |
| 35 |
| 36 |
| 37 void OptimizingCompilerThread::Run() { |
| 38 while (true) { |
| 39 queue_semaphore_->Wait(); |
| 40 if (Acquire_Load(&stop_thread_)) { |
| 41 return; |
| 42 } |
| 43 Handle<JSFunction> function; |
| 44 { |
| 45 ScopedLock mutex_lock(queue_mutex_); |
| 46 queue_.Dequeue(&function); |
| 47 } |
| 48 |
| 49 Locker lock(reinterpret_cast<v8::Isolate*>(isolate_)); |
| 50 if (Acquire_Load(&stop_thread_)) { |
| 51 return; |
| 52 } |
| 53 |
| 54 if (isolate_->context() == NULL || !isolate_->context()->IsContext()) { |
| 55 continue; |
| 56 } |
| 57 |
| 58 isolate_->Enter(); |
| 59 { |
| 60 HandleScope scope(isolate_); |
| 61 if (!function->IsOptimized()) { |
| 62 isolate_->factory()->CompileJSFunction(function); |
| 63 isolate_->counters()->functions_compiled_parallely()->Increment(); |
| 64 } |
| 65 |
| 66 isolate_->global_handles()->Destroy( |
| 67 reinterpret_cast<Object **>(function.location())); |
| 68 } |
| 69 isolate_->Exit(); |
| 70 } |
| 71 } |
| 72 |
| 73 |
| 74 void OptimizingCompilerThread::StopThread() { |
| 75 Release_Store(&stop_thread_, static_cast<AtomicWord>(true)); |
| 76 queue_semaphore_->Signal(); |
| 77 { |
| 78 // We don't need to use the Unlocker class here because we don't |
| 79 // need to present a consistent view of the isolate to the |
| 80 // optimizing compiler thread at this point. Either the compiler |
| 81 // is waiting for the ThreadManager lock and will return |
| 82 // immediately after the getting it or is currently optimizing a |
| 83 // function and hence already has the lock. |
| 84 |
| 85 bool to_unlock = isolate_->thread_manager()->IsLockedByCurrentThread(); |
| 86 if (to_unlock) |
| 87 isolate_->thread_manager()->Unlock(); |
| 88 |
| 89 Join(); |
| 90 |
| 91 if (to_unlock) |
| 92 isolate_->thread_manager()->Lock(); |
| 93 } |
| 94 |
| 95 Handle<JSFunction> not_used; |
| 96 while (!queue_.IsEmpty()) { |
| 97 queue_.Dequeue(¬_used); |
| 98 } |
| 99 } |
| 100 |
| 101 |
| 102 void OptimizingCompilerThread::QueueForOptimization( |
| 103 Handle<JSFunction> function) { |
| 104 { |
| 105 ScopedLock lock(queue_mutex_); |
| 106 queue_.Enqueue(function); |
| 107 } |
| 108 queue_semaphore_->Signal(); |
| 109 Unlocker unlock(reinterpret_cast<v8::Isolate*>(isolate_)); |
| 110 Thread::YieldCPU(); |
| 111 } |
| 112 |
| 113 |
| 114 } } // namespace v8::internal |
| 115 |
| OLD | NEW |