| 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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(CompilationInfo* info, const char* compiler_name, |
| 561 State initial_state = State::kReadyToPrepare) | 565 State initial_state = State::kReadyToPrepare) |
| 562 : info_(info), compiler_name_(compiler_name), state_(initial_state) {} | 566 : info_(info), |
| 567 compiler_name_(compiler_name), |
| 568 state_(initial_state), |
| 569 stack_limit_(info->isolate()->stack_guard()->real_climit()) {} |
| 563 virtual ~CompilationJob() {} | 570 virtual ~CompilationJob() {} |
| 564 | 571 |
| 565 // Prepare the compile job. Must be called on the main thread. | 572 // Prepare the compile job. Must be called on the main thread. |
| 566 MUST_USE_RESULT Status PrepareJob(); | 573 MUST_USE_RESULT Status PrepareJob(); |
| 567 | 574 |
| 568 // Executes the compile job. Can be called off the main thread. | 575 // Executes the compile job. Can be called off the main thread. |
| 569 MUST_USE_RESULT Status ExecuteJob(); | 576 MUST_USE_RESULT Status ExecuteJob(); |
| 570 | 577 |
| 571 // Finalizes the compile job. Must be called on the main thread. | 578 // Finalizes the compile job. Must be called on the main thread. |
| 572 MUST_USE_RESULT Status FinalizeJob(); | 579 MUST_USE_RESULT Status FinalizeJob(); |
| 573 | 580 |
| 581 // Record compilation stats once job has finished. |
| 582 void RecordCompilationStats() const { |
| 583 DCHECK(state() == State::kSucceeded); |
| 584 if (info_->IsOptimizing()) { |
| 585 RecordOptimizedCompilationStats(); |
| 586 } else { |
| 587 RecordUnoptimizedCompilationStats(); |
| 588 } |
| 589 } |
| 590 |
| 574 // Report a transient failure, try again next time. Should only be called on | 591 // Report a transient failure, try again next time. Should only be called on |
| 575 // optimization compilation jobs. | 592 // optimization compilation jobs. |
| 576 Status RetryOptimization(BailoutReason reason) { | 593 Status RetryOptimization(BailoutReason reason) { |
| 577 DCHECK(info_->IsOptimizing()); | 594 DCHECK(info_->IsOptimizing()); |
| 578 info_->RetryOptimization(reason); | 595 info_->RetryOptimization(reason); |
| 579 state_ = State::kFailed; | 596 state_ = State::kFailed; |
| 580 return FAILED; | 597 return FAILED; |
| 581 } | 598 } |
| 582 | 599 |
| 583 // Report a persistent failure, disable future optimization on the function. | 600 // Report a persistent failure, disable future optimization on the function. |
| 584 // Should only be called on optimization compilation jobs. | 601 // Should only be called on optimization compilation jobs. |
| 585 Status AbortOptimization(BailoutReason reason) { | 602 Status AbortOptimization(BailoutReason reason) { |
| 586 DCHECK(info_->IsOptimizing()); | 603 DCHECK(info_->IsOptimizing()); |
| 587 info_->AbortOptimization(reason); | 604 info_->AbortOptimization(reason); |
| 588 state_ = State::kFailed; | 605 state_ = State::kFailed; |
| 589 return FAILED; | 606 return FAILED; |
| 590 } | 607 } |
| 591 | 608 |
| 592 void RecordOptimizationStats(); | 609 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
| 610 uintptr_t stack_limit() const { return stack_limit_; } |
| 593 | 611 |
| 594 State state() const { return state_; } | 612 State state() const { return state_; } |
| 595 CompilationInfo* info() const { return info_; } | 613 CompilationInfo* info() const { return info_; } |
| 596 Isolate* isolate() const { return info()->isolate(); } | 614 Isolate* isolate() const { return info()->isolate(); } |
| 597 | 615 |
| 598 protected: | 616 protected: |
| 599 // Overridden by the actual implementation. | 617 // Overridden by the actual implementation. |
| 600 virtual Status PrepareJobImpl() = 0; | 618 virtual Status PrepareJobImpl() = 0; |
| 601 virtual Status ExecuteJobImpl() = 0; | 619 virtual Status ExecuteJobImpl() = 0; |
| 602 virtual Status FinalizeJobImpl() = 0; | 620 virtual Status FinalizeJobImpl() = 0; |
| 603 | 621 |
| 604 // Registers weak object to optimized code dependencies. | 622 // Registers weak object to optimized code dependencies. |
| 605 // TODO(turbofan): Move this to pipeline.cc once Crankshaft dies. | 623 // TODO(turbofan): Move this to pipeline.cc once Crankshaft dies. |
| 606 void RegisterWeakObjectsInOptimizedCode(Handle<Code> code); | 624 void RegisterWeakObjectsInOptimizedCode(Handle<Code> code); |
| 607 | 625 |
| 608 private: | 626 private: |
| 627 void RecordOptimizedCompilationStats() const; |
| 628 void RecordUnoptimizedCompilationStats() const; |
| 629 |
| 609 CompilationInfo* info_; | 630 CompilationInfo* info_; |
| 610 base::TimeDelta time_taken_to_prepare_; | 631 base::TimeDelta time_taken_to_prepare_; |
| 611 base::TimeDelta time_taken_to_execute_; | 632 base::TimeDelta time_taken_to_execute_; |
| 612 base::TimeDelta time_taken_to_finalize_; | 633 base::TimeDelta time_taken_to_finalize_; |
| 613 const char* compiler_name_; | 634 const char* compiler_name_; |
| 614 State state_; | 635 State state_; |
| 636 uintptr_t stack_limit_; |
| 615 | 637 |
| 616 MUST_USE_RESULT Status UpdateState(Status status, State next_state) { | 638 MUST_USE_RESULT Status UpdateState(Status status, State next_state) { |
| 617 if (status == SUCCEEDED) { | 639 if (status == SUCCEEDED) { |
| 618 state_ = next_state; | 640 state_ = next_state; |
| 619 } else { | 641 } else { |
| 620 state_ = State::kFailed; | 642 state_ = State::kFailed; |
| 621 } | 643 } |
| 622 return status; | 644 return status; |
| 623 } | 645 } |
| 624 }; | 646 }; |
| 625 | 647 |
| 626 } // namespace internal | 648 } // namespace internal |
| 627 } // namespace v8 | 649 } // namespace v8 |
| 628 | 650 |
| 629 #endif // V8_COMPILER_H_ | 651 #endif // V8_COMPILER_H_ |
| OLD | NEW |