| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_OPTIMIZING_COMPILER_THREAD_H_ | 5 #ifndef V8_OPTIMIZING_COMPILER_THREAD_H_ |
| 6 #define V8_OPTIMIZING_COMPILER_THREAD_H_ | 6 #define V8_OPTIMIZING_COMPILER_THREAD_H_ |
| 7 | 7 |
| 8 #include "src/base/atomicops.h" | 8 #include "src/base/atomicops.h" |
| 9 #include "src/base/platform/mutex.h" | 9 #include "src/base/platform/mutex.h" |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| 11 #include "src/base/platform/time.h" | 11 #include "src/base/platform/time.h" |
| 12 #include "src/flags.h" | 12 #include "src/flags.h" |
| 13 #include "src/list.h" | 13 #include "src/list.h" |
| 14 #include "src/unbound-queue-inl.h" | 14 #include "src/unbound-queue-inl.h" |
| 15 | 15 |
| 16 namespace v8 { | 16 namespace v8 { |
| 17 namespace internal { | 17 namespace internal { |
| 18 | 18 |
| 19 class HOptimizedGraphBuilder; | 19 class HOptimizedGraphBuilder; |
| 20 class OptimizedCompileJob; | 20 class OptimizedCompileJob; |
| 21 class SharedFunctionInfo; | 21 class SharedFunctionInfo; |
| 22 | 22 |
| 23 class OptimizingCompilerThread : public base::Thread { | 23 class OptimizingCompilerThread : public base::Thread { |
| 24 public: | 24 public: |
| 25 explicit OptimizingCompilerThread(Isolate* isolate) | 25 explicit OptimizingCompilerThread(Isolate* isolate) |
| 26 : Thread(Options("OptimizingCompilerThread")), | 26 : Thread(Options("OptimizingCompilerThread")), |
| 27 #ifdef DEBUG | 27 #if DCHECK_IS_ON |
| 28 thread_id_(0), | 28 thread_id_(0), |
| 29 #endif | 29 #endif |
| 30 isolate_(isolate), | 30 isolate_(isolate), |
| 31 stop_semaphore_(0), | 31 stop_semaphore_(0), |
| 32 input_queue_semaphore_(0), | 32 input_queue_semaphore_(0), |
| 33 input_queue_capacity_(FLAG_concurrent_recompilation_queue_length), | 33 input_queue_capacity_(FLAG_concurrent_recompilation_queue_length), |
| 34 input_queue_length_(0), | 34 input_queue_length_(0), |
| 35 input_queue_shift_(0), | 35 input_queue_shift_(0), |
| 36 osr_buffer_capacity_(FLAG_concurrent_recompilation_queue_length + 4), | 36 osr_buffer_capacity_(FLAG_concurrent_recompilation_queue_length + 4), |
| 37 osr_buffer_cursor_(0), | 37 osr_buffer_cursor_(0), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // Advance cursor of the cyclic buffer to next empty slot or stale OSR job. | 73 // Advance cursor of the cyclic buffer to next empty slot or stale OSR job. |
| 74 // Dispose said OSR job in the latter case. Calling this on every GC | 74 // Dispose said OSR job in the latter case. Calling this on every GC |
| 75 // should make sure that we do not hold onto stale jobs indefinitely. | 75 // should make sure that we do not hold onto stale jobs indefinitely. |
| 76 AddToOsrBuffer(NULL); | 76 AddToOsrBuffer(NULL); |
| 77 } | 77 } |
| 78 | 78 |
| 79 static bool Enabled(int max_available) { | 79 static bool Enabled(int max_available) { |
| 80 return (FLAG_concurrent_recompilation && max_available > 1); | 80 return (FLAG_concurrent_recompilation && max_available > 1); |
| 81 } | 81 } |
| 82 | 82 |
| 83 #ifdef DEBUG | 83 #if DCHECK_IS_ON |
| 84 static bool IsOptimizerThread(Isolate* isolate); | 84 static bool IsOptimizerThread(Isolate* isolate); |
| 85 bool IsOptimizerThread(); | 85 bool IsOptimizerThread(); |
| 86 #endif | 86 #endif |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 class CompileTask; | 89 class CompileTask; |
| 90 | 90 |
| 91 enum StopFlag { CONTINUE, STOP, FLUSH }; | 91 enum StopFlag { CONTINUE, STOP, FLUSH }; |
| 92 | 92 |
| 93 void FlushInputQueue(bool restore_function_code); | 93 void FlushInputQueue(bool restore_function_code); |
| 94 void FlushOutputQueue(bool restore_function_code); | 94 void FlushOutputQueue(bool restore_function_code); |
| 95 void FlushOsrBuffer(bool restore_function_code); | 95 void FlushOsrBuffer(bool restore_function_code); |
| 96 void CompileNext(); | 96 void CompileNext(); |
| 97 OptimizedCompileJob* NextInput(); | 97 OptimizedCompileJob* NextInput(); |
| 98 | 98 |
| 99 // Add a recompilation task for OSR to the cyclic buffer, awaiting OSR entry. | 99 // Add a recompilation task for OSR to the cyclic buffer, awaiting OSR entry. |
| 100 // Tasks evicted from the cyclic buffer are discarded. | 100 // Tasks evicted from the cyclic buffer are discarded. |
| 101 void AddToOsrBuffer(OptimizedCompileJob* compiler); | 101 void AddToOsrBuffer(OptimizedCompileJob* compiler); |
| 102 | 102 |
| 103 inline int InputQueueIndex(int i) { | 103 inline int InputQueueIndex(int i) { |
| 104 int result = (i + input_queue_shift_) % input_queue_capacity_; | 104 int result = (i + input_queue_shift_) % input_queue_capacity_; |
| 105 DCHECK_LE(0, result); | 105 DCHECK_LE(0, result); |
| 106 DCHECK_LT(result, input_queue_capacity_); | 106 DCHECK_LT(result, input_queue_capacity_); |
| 107 return result; | 107 return result; |
| 108 } | 108 } |
| 109 | 109 |
| 110 #ifdef DEBUG | 110 #if DCHECK_IS_ON |
| 111 int thread_id_; | 111 int thread_id_; |
| 112 base::Mutex thread_id_mutex_; | 112 base::Mutex thread_id_mutex_; |
| 113 #endif | 113 #endif |
| 114 | 114 |
| 115 Isolate* isolate_; | 115 Isolate* isolate_; |
| 116 base::Semaphore stop_semaphore_; | 116 base::Semaphore stop_semaphore_; |
| 117 base::Semaphore input_queue_semaphore_; | 117 base::Semaphore input_queue_semaphore_; |
| 118 | 118 |
| 119 // Circular queue of incoming recompilation tasks (including OSR). | 119 // Circular queue of incoming recompilation tasks (including OSR). |
| 120 OptimizedCompileJob** input_queue_; | 120 OptimizedCompileJob** input_queue_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 148 // | 148 // |
| 149 // Since flags might get modified while the background thread is running, it | 149 // Since flags might get modified while the background thread is running, it |
| 150 // is not safe to access them directly. | 150 // is not safe to access them directly. |
| 151 bool tracing_enabled_; | 151 bool tracing_enabled_; |
| 152 bool job_based_recompilation_; | 152 bool job_based_recompilation_; |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 } } // namespace v8::internal | 155 } } // namespace v8::internal |
| 156 | 156 |
| 157 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ | 157 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ |
| OLD | NEW |