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_COMPILER_H_ | 5 #ifndef V8_COMPILER_H_ |
6 #define V8_COMPILER_H_ | 6 #define V8_COMPILER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 kSucceeded, | 160 kSucceeded, |
161 kFailed, | 161 kFailed, |
162 }; | 162 }; |
163 | 163 |
164 CompilationJob(Isolate* isolate, CompilationInfo* info, | 164 CompilationJob(Isolate* isolate, CompilationInfo* info, |
165 const char* compiler_name, | 165 const char* compiler_name, |
166 State initial_state = State::kReadyToPrepare) | 166 State initial_state = State::kReadyToPrepare) |
167 : info_(info), | 167 : info_(info), |
168 compiler_name_(compiler_name), | 168 compiler_name_(compiler_name), |
169 state_(initial_state), | 169 state_(initial_state), |
170 stack_limit_(isolate->stack_guard()->real_climit()), | 170 stack_limit_(isolate->stack_guard()->real_climit()) {} |
171 executed_on_background_thread_(false) {} | |
172 virtual ~CompilationJob() {} | 171 virtual ~CompilationJob() {} |
173 | 172 |
174 // Prepare the compile job. Must be called on the main thread. | 173 // Prepare the compile job. Must be called on the main thread. |
175 MUST_USE_RESULT Status PrepareJob(); | 174 MUST_USE_RESULT Status PrepareJob(); |
176 | 175 |
177 // Executes the compile job. Can be called on a background thread if | 176 // Executes the compile job. Can be called on a background thread if |
178 // can_execute_on_background_thread() returns true. | 177 // can_execute_on_background_thread() returns true. |
179 MUST_USE_RESULT Status ExecuteJob(); | 178 MUST_USE_RESULT Status ExecuteJob(); |
180 | 179 |
181 // Finalizes the compile job. Must be called on the main thread. | 180 // Finalizes the compile job. Must be called on the main thread. |
182 MUST_USE_RESULT Status FinalizeJob(); | 181 MUST_USE_RESULT Status FinalizeJob(); |
183 | 182 |
184 // Report a transient failure, try again next time. Should only be called on | 183 // Report a transient failure, try again next time. Should only be called on |
185 // optimization compilation jobs. | 184 // optimization compilation jobs. |
186 Status RetryOptimization(BailoutReason reason); | 185 Status RetryOptimization(BailoutReason reason); |
187 | 186 |
188 // Report a persistent failure, disable future optimization on the function. | 187 // Report a persistent failure, disable future optimization on the function. |
189 // Should only be called on optimization compilation jobs. | 188 // Should only be called on optimization compilation jobs. |
190 Status AbortOptimization(BailoutReason reason); | 189 Status AbortOptimization(BailoutReason reason); |
191 | 190 |
192 void RecordOptimizedCompilationStats() const; | 191 void RecordOptimizedCompilationStats() const; |
193 void RecordUnoptimizedCompilationStats() const; | 192 void RecordUnoptimizedCompilationStats() const; |
194 | 193 |
195 virtual bool can_execute_on_background_thread() const { return true; } | 194 virtual bool can_execute_on_background_thread() const { return true; } |
196 | 195 |
197 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | 196 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
198 uintptr_t stack_limit() const { return stack_limit_; } | 197 uintptr_t stack_limit() const { return stack_limit_; } |
199 | 198 |
200 bool executed_on_background_thread() const { | |
201 DCHECK_IMPLIES(!can_execute_on_background_thread(), | |
202 !executed_on_background_thread_); | |
203 return executed_on_background_thread_; | |
204 } | |
205 State state() const { return state_; } | 199 State state() const { return state_; } |
206 CompilationInfo* info() const { return info_; } | 200 CompilationInfo* info() const { return info_; } |
207 Isolate* isolate() const; | 201 Isolate* isolate() const; |
208 | 202 |
209 protected: | 203 protected: |
210 // Overridden by the actual implementation. | 204 // Overridden by the actual implementation. |
211 virtual Status PrepareJobImpl() = 0; | 205 virtual Status PrepareJobImpl() = 0; |
212 virtual Status ExecuteJobImpl() = 0; | 206 virtual Status ExecuteJobImpl() = 0; |
213 virtual Status FinalizeJobImpl() = 0; | 207 virtual Status FinalizeJobImpl() = 0; |
214 | 208 |
215 // Registers weak object to optimized code dependencies. | 209 // Registers weak object to optimized code dependencies. |
216 // TODO(turbofan): Move this to pipeline.cc once Crankshaft dies. | 210 // TODO(turbofan): Move this to pipeline.cc once Crankshaft dies. |
217 void RegisterWeakObjectsInOptimizedCode(Handle<Code> code); | 211 void RegisterWeakObjectsInOptimizedCode(Handle<Code> code); |
218 | 212 |
219 private: | 213 private: |
220 CompilationInfo* info_; | 214 CompilationInfo* info_; |
221 base::TimeDelta time_taken_to_prepare_; | 215 base::TimeDelta time_taken_to_prepare_; |
222 base::TimeDelta time_taken_to_execute_; | 216 base::TimeDelta time_taken_to_execute_; |
223 base::TimeDelta time_taken_to_finalize_; | 217 base::TimeDelta time_taken_to_finalize_; |
224 const char* compiler_name_; | 218 const char* compiler_name_; |
225 State state_; | 219 State state_; |
226 uintptr_t stack_limit_; | 220 uintptr_t stack_limit_; |
227 bool executed_on_background_thread_; | |
228 | 221 |
229 MUST_USE_RESULT Status UpdateState(Status status, State next_state) { | 222 MUST_USE_RESULT Status UpdateState(Status status, State next_state) { |
230 if (status == SUCCEEDED) { | 223 if (status == SUCCEEDED) { |
231 state_ = next_state; | 224 state_ = next_state; |
232 } else { | 225 } else { |
233 state_ = State::kFailed; | 226 state_ = State::kFailed; |
234 } | 227 } |
235 return status; | 228 return status; |
236 } | 229 } |
237 }; | 230 }; |
238 | 231 |
239 } // namespace internal | 232 } // namespace internal |
240 } // namespace v8 | 233 } // namespace v8 |
241 | 234 |
242 #endif // V8_COMPILER_H_ | 235 #endif // V8_COMPILER_H_ |
OLD | NEW |