| 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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 JavaScriptFrame* osr_frame_ = nullptr; | 530 JavaScriptFrame* osr_frame_ = nullptr; |
| 531 | 531 |
| 532 Vector<const char> debug_name_; | 532 Vector<const char> debug_name_; |
| 533 | 533 |
| 534 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); | 534 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); |
| 535 }; | 535 }; |
| 536 | 536 |
| 537 // A base class for compilation jobs intended to run concurrent to the main | 537 // A base class for compilation jobs intended to run concurrent to the main |
| 538 // thread. The job is split into three phases which are called in sequence on | 538 // thread. The job is split into three phases which are called in sequence on |
| 539 // different threads and with different limitations: | 539 // different threads and with different limitations: |
| 540 // 1) PrepareJob: Runs on main thread. No major limitations. | 540 // 1) CreateGraph: Runs on main thread. No major limitations. |
| 541 // 2) ExecuteJob: Runs concurrently. No heap allocation or handle derefs. | 541 // 2) OptimizeGraph: Runs concurrently. No heap allocation or handle derefs. |
| 542 // 3) FinalizeJob: Runs on main thread. No dependency changes. | 542 // 3) GenerateCode: Runs on main thread. No dependency changes. |
| 543 // | 543 // |
| 544 // Each of the three phases can either fail or succeed. The current state of | 544 // Each of the three phases can either fail or succeed. Apart from their return |
| 545 // the job can be checked using {state()}. | 545 // value, the status of the phase last run can be checked using {last_status()} |
| 546 // as well. When failing we distinguish between the following levels: |
| 547 // a) AbortOptimization: Persistent failure, disable future optimization. |
| 548 // b) RetryOptimzation: Transient failure, try again next time. |
| 546 class CompilationJob { | 549 class CompilationJob { |
| 547 public: | 550 public: |
| 548 enum Status { SUCCEEDED, FAILED }; | 551 explicit CompilationJob(CompilationInfo* info, const char* compiler_name) |
| 549 enum class State { | 552 : info_(info), compiler_name_(compiler_name), last_status_(SUCCEEDED) {} |
| 550 kReadyToPrepare, | |
| 551 kReadyToExecute, | |
| 552 kReadyToFinalize, | |
| 553 kSucceeded, | |
| 554 kFailed, | |
| 555 }; | |
| 556 | |
| 557 explicit CompilationJob(CompilationInfo* info, const char* compiler_name, | |
| 558 State initial_state = State::kReadyToPrepare) | |
| 559 : info_(info), compiler_name_(compiler_name), state_(initial_state) {} | |
| 560 virtual ~CompilationJob() {} | 553 virtual ~CompilationJob() {} |
| 561 | 554 |
| 562 // Prepare the compile job. Must be called on the main thread. | 555 enum Status { FAILED, SUCCEEDED }; |
| 563 MUST_USE_RESULT Status PrepareJob(); | |
| 564 | 556 |
| 565 // Executes the compile job. Can be called off the main thread. | 557 MUST_USE_RESULT Status CreateGraph(); |
| 566 MUST_USE_RESULT Status ExecuteJob(); | 558 MUST_USE_RESULT Status OptimizeGraph(); |
| 559 MUST_USE_RESULT Status GenerateCode(); |
| 567 | 560 |
| 568 // Finalizes the compile job. Must be called on the main thread. | 561 Status last_status() const { return last_status_; } |
| 569 MUST_USE_RESULT Status FinalizeJob(); | 562 CompilationInfo* info() const { return info_; } |
| 563 Isolate* isolate() const { return info()->isolate(); } |
| 570 | 564 |
| 571 // Report a transient failure, try again next time. Should only be called on | |
| 572 // optimization compilation jobs. | |
| 573 Status RetryOptimization(BailoutReason reason) { | 565 Status RetryOptimization(BailoutReason reason) { |
| 574 DCHECK(info_->IsOptimizing()); | |
| 575 info_->RetryOptimization(reason); | 566 info_->RetryOptimization(reason); |
| 576 state_ = State::kFailed; | 567 return SetLastStatus(FAILED); |
| 577 return FAILED; | |
| 578 } | 568 } |
| 579 | 569 |
| 580 // Report a persistent failure, disable future optimization on the function. | |
| 581 // Should only be called on optimization compilation jobs. | |
| 582 Status AbortOptimization(BailoutReason reason) { | 570 Status AbortOptimization(BailoutReason reason) { |
| 583 DCHECK(info_->IsOptimizing()); | |
| 584 info_->AbortOptimization(reason); | 571 info_->AbortOptimization(reason); |
| 585 state_ = State::kFailed; | 572 return SetLastStatus(FAILED); |
| 586 return FAILED; | |
| 587 } | 573 } |
| 588 | 574 |
| 589 void RecordOptimizationStats(); | 575 void RecordOptimizationStats(); |
| 590 | 576 |
| 591 // Registers weak object to optimized code dependencies. | 577 protected: |
| 592 // TODO(turbofan): Move this to pipeline.cc once Crankshaft dies. | 578 void RegisterWeakObjectsInOptimizedCode(Handle<Code> code); |
| 593 static void RegisterWeakObjectsInOptimizedCode(Handle<Code> code); | |
| 594 | 579 |
| 595 State state() const { return state_; } | |
| 596 CompilationInfo* info() const { return info_; } | |
| 597 Isolate* isolate() const { return info()->isolate(); } | |
| 598 | |
| 599 protected: | |
| 600 // Overridden by the actual implementation. | 580 // Overridden by the actual implementation. |
| 601 virtual Status PrepareJobImpl() = 0; | 581 virtual Status CreateGraphImpl() = 0; |
| 602 virtual Status ExecuteJobImpl() = 0; | 582 virtual Status OptimizeGraphImpl() = 0; |
| 603 virtual Status FinalizeJobImpl() = 0; | 583 virtual Status GenerateCodeImpl() = 0; |
| 604 | 584 |
| 605 private: | 585 private: |
| 606 CompilationInfo* info_; | 586 CompilationInfo* info_; |
| 607 base::TimeDelta time_taken_to_prepare_; | 587 base::TimeDelta time_taken_to_create_graph_; |
| 608 base::TimeDelta time_taken_to_execute_; | 588 base::TimeDelta time_taken_to_optimize_; |
| 609 base::TimeDelta time_taken_to_finalize_; | 589 base::TimeDelta time_taken_to_codegen_; |
| 610 const char* compiler_name_; | 590 const char* compiler_name_; |
| 611 State state_; | 591 Status last_status_; |
| 612 | 592 |
| 613 MUST_USE_RESULT Status UpdateState(Status status, State next_state) { | 593 MUST_USE_RESULT Status SetLastStatus(Status status) { |
| 614 if (status == SUCCEEDED) { | 594 last_status_ = status; |
| 615 state_ = next_state; | 595 return last_status_; |
| 616 } else { | |
| 617 state_ = State::kFailed; | |
| 618 } | |
| 619 return status; | |
| 620 } | 596 } |
| 621 }; | 597 }; |
| 622 | 598 |
| 623 } // namespace internal | 599 } // namespace internal |
| 624 } // namespace v8 | 600 } // namespace v8 |
| 625 | 601 |
| 626 #endif // V8_COMPILER_H_ | 602 #endif // V8_COMPILER_H_ |
| OLD | NEW |