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