| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 // whereas successful compilation ensures the {is_compiled} predicate on the | 50 // whereas successful compilation ensures the {is_compiled} predicate on the |
| 51 // given function holds (except for live-edit, which compiles the world). | 51 // given function holds (except for live-edit, which compiles the world). |
| 52 | 52 |
| 53 static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); | 53 static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); |
| 54 static bool CompileBaseline(Handle<JSFunction> function); | 54 static bool CompileBaseline(Handle<JSFunction> function); |
| 55 static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode); | 55 static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode); |
| 56 static bool CompileDebugCode(Handle<JSFunction> function); | 56 static bool CompileDebugCode(Handle<JSFunction> function); |
| 57 static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); | 57 static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); |
| 58 static MaybeHandle<JSArray> CompileForLiveEdit(Handle<Script> script); | 58 static MaybeHandle<JSArray> CompileForLiveEdit(Handle<Script> script); |
| 59 | 59 |
| 60 // Prepare a compilation job for unoptimized code. Requires ParseAndAnalyse. |
| 61 static CompilationJob* PrepareUnoptimizedCompilationJob( |
| 62 CompilationInfo* info); |
| 63 |
| 60 // Generate and install code from previously queued compilation job. | 64 // Generate and install code from previously queued compilation job. |
| 61 static void FinalizeCompilationJob(CompilationJob* job); | 65 static bool FinalizeCompilationJob(CompilationJob* job); |
| 62 | 66 |
| 63 // Give the compiler a chance to perform low-latency initialization tasks of | 67 // Give the compiler a chance to perform low-latency initialization tasks of |
| 64 // the given {function} on its instantiation. Note that only the runtime will | 68 // the given {function} on its instantiation. Note that only the runtime will |
| 65 // offer this chance, optimized closure instantiation will not call this. | 69 // offer this chance, optimized closure instantiation will not call this. |
| 66 static void PostInstantiation(Handle<JSFunction> function, PretenureFlag); | 70 static void PostInstantiation(Handle<JSFunction> function, PretenureFlag); |
| 67 | 71 |
| 68 // Parser::Parse, then Compiler::Analyze. | 72 // Parser::Parse, then Compiler::Analyze. |
| 69 static bool ParseAndAnalyze(ParseInfo* info); | 73 static bool ParseAndAnalyze(ParseInfo* info); |
| 70 // Rewrite, analyze scopes, and renumber. | 74 // Rewrite, analyze scopes, and renumber. |
| 71 static bool Analyze(ParseInfo* info); | 75 static bool Analyze(ParseInfo* info); |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 public: | 554 public: |
| 551 enum Status { SUCCEEDED, FAILED }; | 555 enum Status { SUCCEEDED, FAILED }; |
| 552 enum class State { | 556 enum class State { |
| 553 kReadyToPrepare, | 557 kReadyToPrepare, |
| 554 kReadyToExecute, | 558 kReadyToExecute, |
| 555 kReadyToFinalize, | 559 kReadyToFinalize, |
| 556 kSucceeded, | 560 kSucceeded, |
| 557 kFailed, | 561 kFailed, |
| 558 }; | 562 }; |
| 559 | 563 |
| 560 explicit CompilationJob(CompilationInfo* info, const char* compiler_name, | 564 explicit CompilationJob(Isolate* isolate, CompilationInfo* info, |
| 565 const char* compiler_name, |
| 561 State initial_state = State::kReadyToPrepare) | 566 State initial_state = State::kReadyToPrepare) |
| 562 : info_(info), compiler_name_(compiler_name), state_(initial_state) {} | 567 : info_(info), |
| 568 compiler_name_(compiler_name), |
| 569 state_(initial_state), |
| 570 stack_limit_(isolate->stack_guard()->real_climit()) {} |
| 563 virtual ~CompilationJob() {} | 571 virtual ~CompilationJob() {} |
| 564 | 572 |
| 565 // Prepare the compile job. Must be called on the main thread. | 573 // Prepare the compile job. Must be called on the main thread. |
| 566 MUST_USE_RESULT Status PrepareJob(); | 574 MUST_USE_RESULT Status PrepareJob(); |
| 567 | 575 |
| 568 // Executes the compile job. Can be called off the main thread. | 576 // Executes the compile job. Can be called on a background thread if |
| 577 // can_execute_on_background_thread() returns true. |
| 569 MUST_USE_RESULT Status ExecuteJob(); | 578 MUST_USE_RESULT Status ExecuteJob(); |
| 570 | 579 |
| 571 // Finalizes the compile job. Must be called on the main thread. | 580 // Finalizes the compile job. Must be called on the main thread. |
| 572 MUST_USE_RESULT Status FinalizeJob(); | 581 MUST_USE_RESULT Status FinalizeJob(); |
| 573 | 582 |
| 583 // Record compilation stats once job has finished. |
| 584 void RecordCompilationStats() const { |
| 585 DCHECK(state() == State::kSucceeded); |
| 586 if (info_->IsOptimizing()) { |
| 587 RecordOptimizedCompilationStats(); |
| 588 } else { |
| 589 RecordUnoptimizedCompilationStats(); |
| 590 } |
| 591 } |
| 592 |
| 574 // Report a transient failure, try again next time. Should only be called on | 593 // Report a transient failure, try again next time. Should only be called on |
| 575 // optimization compilation jobs. | 594 // optimization compilation jobs. |
| 576 Status RetryOptimization(BailoutReason reason) { | 595 Status RetryOptimization(BailoutReason reason) { |
| 577 DCHECK(info_->IsOptimizing()); | 596 DCHECK(info_->IsOptimizing()); |
| 578 info_->RetryOptimization(reason); | 597 info_->RetryOptimization(reason); |
| 579 state_ = State::kFailed; | 598 state_ = State::kFailed; |
| 580 return FAILED; | 599 return FAILED; |
| 581 } | 600 } |
| 582 | 601 |
| 583 // Report a persistent failure, disable future optimization on the function. | 602 // Report a persistent failure, disable future optimization on the function. |
| 584 // Should only be called on optimization compilation jobs. | 603 // Should only be called on optimization compilation jobs. |
| 585 Status AbortOptimization(BailoutReason reason) { | 604 Status AbortOptimization(BailoutReason reason) { |
| 586 DCHECK(info_->IsOptimizing()); | 605 DCHECK(info_->IsOptimizing()); |
| 587 info_->AbortOptimization(reason); | 606 info_->AbortOptimization(reason); |
| 588 state_ = State::kFailed; | 607 state_ = State::kFailed; |
| 589 return FAILED; | 608 return FAILED; |
| 590 } | 609 } |
| 591 | 610 |
| 592 void RecordOptimizationStats(); | 611 virtual bool can_execute_on_background_thread() const { return true; } |
| 612 |
| 613 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
| 614 uintptr_t stack_limit() const { return stack_limit_; } |
| 593 | 615 |
| 594 State state() const { return state_; } | 616 State state() const { return state_; } |
| 595 CompilationInfo* info() const { return info_; } | 617 CompilationInfo* info() const { return info_; } |
| 596 Isolate* isolate() const { return info()->isolate(); } | 618 Isolate* isolate() const { return info()->isolate(); } |
| 597 | 619 |
| 598 protected: | 620 protected: |
| 599 // Overridden by the actual implementation. | 621 // Overridden by the actual implementation. |
| 600 virtual Status PrepareJobImpl() = 0; | 622 virtual Status PrepareJobImpl() = 0; |
| 601 virtual Status ExecuteJobImpl() = 0; | 623 virtual Status ExecuteJobImpl() = 0; |
| 602 virtual Status FinalizeJobImpl() = 0; | 624 virtual Status FinalizeJobImpl() = 0; |
| 603 | 625 |
| 604 // Registers weak object to optimized code dependencies. | 626 // Registers weak object to optimized code dependencies. |
| 605 // TODO(turbofan): Move this to pipeline.cc once Crankshaft dies. | 627 // TODO(turbofan): Move this to pipeline.cc once Crankshaft dies. |
| 606 void RegisterWeakObjectsInOptimizedCode(Handle<Code> code); | 628 void RegisterWeakObjectsInOptimizedCode(Handle<Code> code); |
| 607 | 629 |
| 608 private: | 630 private: |
| 631 void RecordOptimizedCompilationStats() const; |
| 632 void RecordUnoptimizedCompilationStats() const; |
| 633 |
| 609 CompilationInfo* info_; | 634 CompilationInfo* info_; |
| 610 base::TimeDelta time_taken_to_prepare_; | 635 base::TimeDelta time_taken_to_prepare_; |
| 611 base::TimeDelta time_taken_to_execute_; | 636 base::TimeDelta time_taken_to_execute_; |
| 612 base::TimeDelta time_taken_to_finalize_; | 637 base::TimeDelta time_taken_to_finalize_; |
| 613 const char* compiler_name_; | 638 const char* compiler_name_; |
| 614 State state_; | 639 State state_; |
| 640 uintptr_t stack_limit_; |
| 615 | 641 |
| 616 MUST_USE_RESULT Status UpdateState(Status status, State next_state) { | 642 MUST_USE_RESULT Status UpdateState(Status status, State next_state) { |
| 617 if (status == SUCCEEDED) { | 643 if (status == SUCCEEDED) { |
| 618 state_ = next_state; | 644 state_ = next_state; |
| 619 } else { | 645 } else { |
| 620 state_ = State::kFailed; | 646 state_ = State::kFailed; |
| 621 } | 647 } |
| 622 return status; | 648 return status; |
| 623 } | 649 } |
| 624 }; | 650 }; |
| 625 | 651 |
| 626 } // namespace internal | 652 } // namespace internal |
| 627 } // namespace v8 | 653 } // namespace v8 |
| 628 | 654 |
| 629 #endif // V8_COMPILER_H_ | 655 #endif // V8_COMPILER_H_ |
| OLD | NEW |