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" |
| 10 #include "src/base/platform/platform.h" |
| 11 #include "src/base/platform/time.h" |
9 #include "src/flags.h" | 12 #include "src/flags.h" |
10 #include "src/list.h" | 13 #include "src/list.h" |
11 #include "src/platform.h" | |
12 #include "src/platform/mutex.h" | |
13 #include "src/platform/time.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 Thread { | 23 class OptimizingCompilerThread : public base::Thread { |
24 public: | 24 public: |
25 explicit OptimizingCompilerThread(Isolate *isolate) : | 25 explicit OptimizingCompilerThread(Isolate *isolate) : |
26 Thread("OptimizingCompilerThread"), | 26 Thread("OptimizingCompilerThread"), |
27 #ifdef DEBUG | 27 #ifdef DEBUG |
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), |
(...skipping 22 matching lines...) Expand all Loading... |
56 void QueueForOptimization(OptimizedCompileJob* optimizing_compiler); | 56 void QueueForOptimization(OptimizedCompileJob* optimizing_compiler); |
57 void Unblock(); | 57 void Unblock(); |
58 void InstallOptimizedFunctions(); | 58 void InstallOptimizedFunctions(); |
59 OptimizedCompileJob* FindReadyOSRCandidate(Handle<JSFunction> function, | 59 OptimizedCompileJob* FindReadyOSRCandidate(Handle<JSFunction> function, |
60 BailoutId osr_ast_id); | 60 BailoutId osr_ast_id); |
61 bool IsQueuedForOSR(Handle<JSFunction> function, BailoutId osr_ast_id); | 61 bool IsQueuedForOSR(Handle<JSFunction> function, BailoutId osr_ast_id); |
62 | 62 |
63 bool IsQueuedForOSR(JSFunction* function); | 63 bool IsQueuedForOSR(JSFunction* function); |
64 | 64 |
65 inline bool IsQueueAvailable() { | 65 inline bool IsQueueAvailable() { |
66 LockGuard<Mutex> access_input_queue(&input_queue_mutex_); | 66 base::LockGuard<base::Mutex> access_input_queue(&input_queue_mutex_); |
67 return input_queue_length_ < input_queue_capacity_; | 67 return input_queue_length_ < input_queue_capacity_; |
68 } | 68 } |
69 | 69 |
70 inline void AgeBufferedOsrJobs() { | 70 inline void AgeBufferedOsrJobs() { |
71 // Advance cursor of the cyclic buffer to next empty slot or stale OSR job. | 71 // Advance cursor of the cyclic buffer to next empty slot or stale OSR job. |
72 // Dispose said OSR job in the latter case. Calling this on every GC | 72 // Dispose said OSR job in the latter case. Calling this on every GC |
73 // should make sure that we do not hold onto stale jobs indefinitely. | 73 // should make sure that we do not hold onto stale jobs indefinitely. |
74 AddToOsrBuffer(NULL); | 74 AddToOsrBuffer(NULL); |
75 } | 75 } |
76 | 76 |
(...skipping 21 matching lines...) Expand all Loading... |
98 | 98 |
99 inline int InputQueueIndex(int i) { | 99 inline int InputQueueIndex(int i) { |
100 int result = (i + input_queue_shift_) % input_queue_capacity_; | 100 int result = (i + input_queue_shift_) % input_queue_capacity_; |
101 ASSERT_LE(0, result); | 101 ASSERT_LE(0, result); |
102 ASSERT_LT(result, input_queue_capacity_); | 102 ASSERT_LT(result, input_queue_capacity_); |
103 return result; | 103 return result; |
104 } | 104 } |
105 | 105 |
106 #ifdef DEBUG | 106 #ifdef DEBUG |
107 int thread_id_; | 107 int thread_id_; |
108 Mutex thread_id_mutex_; | 108 base::Mutex thread_id_mutex_; |
109 #endif | 109 #endif |
110 | 110 |
111 Isolate* isolate_; | 111 Isolate* isolate_; |
112 Semaphore stop_semaphore_; | 112 base::Semaphore stop_semaphore_; |
113 Semaphore input_queue_semaphore_; | 113 base::Semaphore input_queue_semaphore_; |
114 | 114 |
115 // Circular queue of incoming recompilation tasks (including OSR). | 115 // Circular queue of incoming recompilation tasks (including OSR). |
116 OptimizedCompileJob** input_queue_; | 116 OptimizedCompileJob** input_queue_; |
117 int input_queue_capacity_; | 117 int input_queue_capacity_; |
118 int input_queue_length_; | 118 int input_queue_length_; |
119 int input_queue_shift_; | 119 int input_queue_shift_; |
120 Mutex input_queue_mutex_; | 120 base::Mutex input_queue_mutex_; |
121 | 121 |
122 // Queue of recompilation tasks ready to be installed (excluding OSR). | 122 // Queue of recompilation tasks ready to be installed (excluding OSR). |
123 UnboundQueue<OptimizedCompileJob*> output_queue_; | 123 UnboundQueue<OptimizedCompileJob*> output_queue_; |
124 | 124 |
125 // Cyclic buffer of recompilation tasks for OSR. | 125 // Cyclic buffer of recompilation tasks for OSR. |
126 OptimizedCompileJob** osr_buffer_; | 126 OptimizedCompileJob** osr_buffer_; |
127 int osr_buffer_capacity_; | 127 int osr_buffer_capacity_; |
128 int osr_buffer_cursor_; | 128 int osr_buffer_cursor_; |
129 | 129 |
130 volatile base::AtomicWord stop_thread_; | 130 volatile base::AtomicWord stop_thread_; |
131 TimeDelta time_spent_compiling_; | 131 base::TimeDelta time_spent_compiling_; |
132 TimeDelta time_spent_total_; | 132 base::TimeDelta time_spent_total_; |
133 | 133 |
134 int osr_hits_; | 134 int osr_hits_; |
135 int osr_attempts_; | 135 int osr_attempts_; |
136 | 136 |
137 int blocked_jobs_; | 137 int blocked_jobs_; |
138 }; | 138 }; |
139 | 139 |
140 } } // namespace v8::internal | 140 } } // namespace v8::internal |
141 | 141 |
142 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ | 142 #endif // V8_OPTIMIZING_COMPILER_THREAD_H_ |
OLD | NEW |