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

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: DISALLOW_COPY_AND_ASSIGN 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
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 Handle<Script> script, ParseInfo* info, int source_length); 113 Handle<Script> script, ParseInfo* info, int source_length);
114 114
115 // Create a shared function info object (the code may be lazily compiled). 115 // Create a shared function info object (the code may be lazily compiled).
116 static Handle<SharedFunctionInfo> GetSharedFunctionInfo( 116 static Handle<SharedFunctionInfo> GetSharedFunctionInfo(
117 FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer); 117 FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer);
118 118
119 // Create a shared function info object for a native function literal. 119 // Create a shared function info object for a native function literal.
120 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative( 120 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative(
121 v8::Extension* extension, Handle<String> name); 121 v8::Extension* extension, Handle<String> name);
122 122
123 // Registers weak object to optimized code dependencies.
124 static void RegisterWeakObjectsInOptimizedCode(Handle<Code> code);
Michael Starzinger 2016/08/16 08:46:40 IMHO this doesn't belong into the "Compiler" inter
rmcilroy 2016/08/16 11:10:44 Done.
125
123 // =========================================================================== 126 // ===========================================================================
124 // The following family of methods provides support for OSR. Code generated 127 // The following family of methods provides support for OSR. Code generated
125 // for entry via OSR might not be suitable for normal entry, hence will be 128 // for entry via OSR might not be suitable for normal entry, hence will be
126 // returned directly to the caller. 129 // returned directly to the caller.
127 // 130 //
128 // Please note this interface is the only part dealing with {Code} objects 131 // Please note this interface is the only part dealing with {Code} objects
129 // directly. Other methods are agnostic to {Code} and can use an interpreter 132 // directly. Other methods are agnostic to {Code} and can use an interpreter
130 // instead of generating JIT code for a function at all. 133 // instead of generating JIT code for a function at all.
131 134
132 // Generate and return optimized code for OSR, or empty handle on failure. 135 // Generate and return optimized code for OSR, or empty handle on failure.
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 JavaScriptFrame* osr_frame_ = nullptr; 533 JavaScriptFrame* osr_frame_ = nullptr;
531 534
532 Vector<const char> debug_name_; 535 Vector<const char> debug_name_;
533 536
534 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); 537 DISALLOW_COPY_AND_ASSIGN(CompilationInfo);
535 }; 538 };
536 539
537 // 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
538 // 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
539 // different threads and with different limitations: 542 // different threads and with different limitations:
540 // 1) CreateGraph: Runs on main thread. No major limitations. 543 // 1) PrepareJob: Runs on main thread. No major limitations.
541 // 2) OptimizeGraph: Runs concurrently. No heap allocation or handle derefs. 544 // 2) ExecuteJob: Runs concurrently. No heap allocation or handle derefs.
542 // 3) GenerateCode: Runs on main thread. No dependency changes. 545 // 3) FinalizeJob: Runs on main thread. No dependency changes.
543 // 546 //
544 // 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
545 // value, the status of the phase last run can be checked using {last_status()} 548 // 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 { 549 class CompilationJob {
550 public: 550 public:
551 explicit CompilationJob(CompilationInfo* info, const char* compiler_name) 551 enum Status { SUCCEEDED, FAILED };
552 : 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) {}
553 virtual ~CompilationJob() {} 563 virtual ~CompilationJob() {}
554 564
555 enum Status { FAILED, SUCCEEDED }; 565 // Prepare the compile job. Must be called on the main thread.
566 MUST_USE_RESULT Status PrepareJob();
556 567
557 MUST_USE_RESULT Status CreateGraph(); 568 // Executes the compile job. Can called off the main thread.
Michael Starzinger 2016/08/16 08:46:40 nit: s/Can called/Can be called/
rmcilroy 2016/08/16 11:10:44 Done.
558 MUST_USE_RESULT Status OptimizeGraph(); 569 MUST_USE_RESULT Status ExecuteJob();
559 MUST_USE_RESULT Status GenerateCode();
560 570
561 Status last_status() const { return last_status_; } 571 // Finalizes the compile job. Must be called on the main thread.
562 CompilationInfo* info() const { return info_; } 572 MUST_USE_RESULT Status FinalizeJob();
563 Isolate* isolate() const { return info()->isolate(); }
564 573
574 // Report a transient failure, try again next time. Should only be called on
575 // optimization compilation jobs.
565 Status RetryOptimization(BailoutReason reason) { 576 Status RetryOptimization(BailoutReason reason) {
577 DCHECK(info_->IsOptimizing());
566 info_->RetryOptimization(reason); 578 info_->RetryOptimization(reason);
567 return SetLastStatus(FAILED); 579 state_ = State::kFailed;
580 return FAILED;
568 } 581 }
569 582
583 // Report a persistent failure, disable future optimization on the function.
584 // Should only be called on optimization compilation jobs.
570 Status AbortOptimization(BailoutReason reason) { 585 Status AbortOptimization(BailoutReason reason) {
586 DCHECK(info_->IsOptimizing());
571 info_->AbortOptimization(reason); 587 info_->AbortOptimization(reason);
572 return SetLastStatus(FAILED); 588 state_ = State::kFailed;
589 return FAILED;
573 } 590 }
574 591
575 void RecordOptimizationStats(); 592 void RecordOptimizationStats();
576 593
594 State state() const { return state_; }
595 CompilationInfo* info() const { return info_; }
596 Isolate* isolate() const { return info()->isolate(); }
597
577 protected: 598 protected:
578 void RegisterWeakObjectsInOptimizedCode(Handle<Code> code);
579
580 // Overridden by the actual implementation. 599 // Overridden by the actual implementation.
581 virtual Status CreateGraphImpl() = 0; 600 virtual Status PrepareJobImpl() = 0;
582 virtual Status OptimizeGraphImpl() = 0; 601 virtual Status ExecuteJobImpl() = 0;
583 virtual Status GenerateCodeImpl() = 0; 602 virtual Status FinalizeJobImpl() = 0;
584 603
585 private: 604 private:
586 CompilationInfo* info_; 605 CompilationInfo* info_;
587 base::TimeDelta time_taken_to_create_graph_; 606 base::TimeDelta time_taken_to_prepare_;
588 base::TimeDelta time_taken_to_optimize_; 607 base::TimeDelta time_taken_to_execute_;
589 base::TimeDelta time_taken_to_codegen_; 608 base::TimeDelta time_taken_to_finalize_;
590 const char* compiler_name_; 609 const char* compiler_name_;
591 Status last_status_; 610 State state_;
592 611
593 MUST_USE_RESULT Status SetLastStatus(Status status) { 612 MUST_USE_RESULT Status UpdateState(Status status, State next_state) {
594 last_status_ = status; 613 if (status == SUCCEEDED)
Michael Starzinger 2016/08/16 08:46:40 nit: Curly braces around bodies of multi-line if s
rmcilroy 2016/08/16 11:10:44 Done.
595 return last_status_; 614 state_ = next_state;
615 else
616 state_ = State::kFailed;
617 return status;
596 } 618 }
597 }; 619 };
598 620
599 } // namespace internal 621 } // namespace internal
600 } // namespace v8 622 } // namespace v8
601 623
602 #endif // V8_COMPILER_H_ 624 #endif // V8_COMPILER_H_
OLDNEW
« no previous file with comments | « src/ast/ast.h ('k') | src/compiler.cc » ('j') | src/interpreter/interpreter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698