Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(652)

Side by Side Diff: src/compiler.h

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

Powered by Google App Engine
This is Rietveld 408576698