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