Index: src/compiler.h |
diff --git a/src/compiler.h b/src/compiler.h |
index bd9c0dc0ca67ce4d6d08742928797ca9d5fb594a..55215733c11c66a8b9160a0adebc927e1c564ad0 100644 |
--- a/src/compiler.h |
+++ b/src/compiler.h |
@@ -540,62 +540,86 @@ class CompilationInfo final { |
// A base class for compilation jobs intended to run concurrent to the main |
// thread. The job is split into three phases which are called in sequence on |
// different threads and with different limitations: |
-// 1) CreateGraph: Runs on main thread. No major limitations. |
-// 2) OptimizeGraph: Runs concurrently. No heap allocation or handle derefs. |
-// 3) GenerateCode: Runs on main thread. No dependency changes. |
+// 1) PrepareJob: Runs on main thread. No major limitations. |
+// 2) ExecuteJob: Runs concurrently. No heap allocation or handle derefs. |
+// 3) FinalizeJob: Runs on main thread. No dependency changes. |
// |
-// Each of the three phases can either fail or succeed. Apart from their return |
-// value, the status of the phase last run can be checked using {last_status()} |
-// as well. When failing we distinguish between the following levels: |
-// a) AbortOptimization: Persistent failure, disable future optimization. |
-// b) RetryOptimzation: Transient failure, try again next time. |
+// Each of the three phases can either fail or succeed. The current state of |
+// the job can be checked using {state()}. |
class CompilationJob { |
public: |
- explicit CompilationJob(CompilationInfo* info, const char* compiler_name) |
- : info_(info), compiler_name_(compiler_name), last_status_(SUCCEEDED) {} |
+ enum Status { SUCCEEDED, FAILED }; |
+ enum class State { |
+ kReadyToPrepare, |
+ kReadyToExecute, |
+ kReadyToFinalize, |
+ kSucceeded, |
+ kFailed, |
+ }; |
+ |
+ explicit CompilationJob(CompilationInfo* info, const char* compiler_name, |
+ State initial_state = State::kReadyToPrepare) |
+ : info_(info), compiler_name_(compiler_name), state_(initial_state) {} |
virtual ~CompilationJob() {} |
- enum Status { FAILED, SUCCEEDED }; |
+ // Prepare the compile job. Must be called on the main thread. |
+ MUST_USE_RESULT Status PrepareJob(); |
- MUST_USE_RESULT Status CreateGraph(); |
- MUST_USE_RESULT Status OptimizeGraph(); |
- MUST_USE_RESULT Status GenerateCode(); |
+ // Executes the compile job. Can be called off the main thread. |
+ MUST_USE_RESULT Status ExecuteJob(); |
- Status last_status() const { return last_status_; } |
- CompilationInfo* info() const { return info_; } |
- Isolate* isolate() const { return info()->isolate(); } |
+ // Finalizes the compile job. Must be called on the main thread. |
+ MUST_USE_RESULT Status FinalizeJob(); |
+ // Report a transient failure, try again next time. Should only be called on |
+ // optimization compilation jobs. |
Status RetryOptimization(BailoutReason reason) { |
+ DCHECK(info_->IsOptimizing()); |
info_->RetryOptimization(reason); |
- return SetLastStatus(FAILED); |
+ state_ = State::kFailed; |
+ return FAILED; |
} |
+ // Report a persistent failure, disable future optimization on the function. |
+ // Should only be called on optimization compilation jobs. |
Status AbortOptimization(BailoutReason reason) { |
+ DCHECK(info_->IsOptimizing()); |
info_->AbortOptimization(reason); |
- return SetLastStatus(FAILED); |
+ state_ = State::kFailed; |
+ return FAILED; |
} |
void RecordOptimizationStats(); |
- protected: |
- void RegisterWeakObjectsInOptimizedCode(Handle<Code> code); |
+ State state() const { return state_; } |
+ CompilationInfo* info() const { return info_; } |
+ Isolate* isolate() const { return info()->isolate(); } |
+ protected: |
// Overridden by the actual implementation. |
- virtual Status CreateGraphImpl() = 0; |
- virtual Status OptimizeGraphImpl() = 0; |
- virtual Status GenerateCodeImpl() = 0; |
+ virtual Status PrepareJobImpl() = 0; |
+ virtual Status ExecuteJobImpl() = 0; |
+ virtual Status FinalizeJobImpl() = 0; |
+ |
+ // Registers weak object to optimized code dependencies. |
+ // TODO(turbofan): Move this to pipeline.cc once Crankshaft dies. |
+ void RegisterWeakObjectsInOptimizedCode(Handle<Code> code); |
private: |
CompilationInfo* info_; |
- base::TimeDelta time_taken_to_create_graph_; |
- base::TimeDelta time_taken_to_optimize_; |
- base::TimeDelta time_taken_to_codegen_; |
+ base::TimeDelta time_taken_to_prepare_; |
+ base::TimeDelta time_taken_to_execute_; |
+ base::TimeDelta time_taken_to_finalize_; |
const char* compiler_name_; |
- Status last_status_; |
- |
- MUST_USE_RESULT Status SetLastStatus(Status status) { |
- last_status_ = status; |
- return last_status_; |
+ State state_; |
+ |
+ MUST_USE_RESULT Status UpdateState(Status status, State next_state) { |
+ if (status == SUCCEEDED) { |
+ state_ = next_state; |
+ } else { |
+ state_ = State::kFailed; |
+ } |
+ return status; |
} |
}; |