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 "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 ~Timer() { | 564 ~Timer() { |
565 *location_ += timer_.Elapsed(); | 565 *location_ += timer_.Elapsed(); |
566 } | 566 } |
567 | 567 |
568 OptimizedCompileJob* job_; | 568 OptimizedCompileJob* job_; |
569 base::ElapsedTimer timer_; | 569 base::ElapsedTimer timer_; |
570 base::TimeDelta* location_; | 570 base::TimeDelta* location_; |
571 }; | 571 }; |
572 }; | 572 }; |
573 | 573 |
574 | 574 // The V8 compiler API. |
575 // The V8 compiler | 575 // |
| 576 // This is the central hub for dispatching to the various compilers within V8. |
| 577 // Logic for which compiler to choose and how to wire compilation results into |
| 578 // the object heap should be kept inside this class. |
576 // | 579 // |
577 // General strategy: Source code is translated into an anonymous function w/o | 580 // General strategy: Source code is translated into an anonymous function w/o |
578 // parameters which then can be executed. If the source code contains other | 581 // parameters which then can be executed. If the source code contains other |
579 // functions, they will be compiled and allocated as part of the compilation | 582 // functions, they might be compiled and allocated as part of the compilation |
580 // of the source code. | 583 // of the source code or deferred for lazy compilation at a later point. |
581 | |
582 // Please note this interface returns shared function infos. This means you | |
583 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a | |
584 // real function with a context. | |
585 | |
586 class Compiler : public AllStatic { | 584 class Compiler : public AllStatic { |
587 public: | 585 public: |
588 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; | 586 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; |
589 | 587 |
| 588 // =========================================================================== |
| 589 // The following family of methods ensures a given function is compiled. The |
| 590 // general contract is that failures will be reported by returning {false}, |
| 591 // whereas successful compilation ensures the {is_compiled} predicate on the |
| 592 // given function holds. |
| 593 |
590 static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); | 594 static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); |
591 static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode); | 595 static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode); |
592 static bool CompileDebugCode(Handle<JSFunction> function); | 596 static bool CompileDebugCode(Handle<JSFunction> function); |
593 static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); | 597 static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); |
594 static void CompileForLiveEdit(Handle<Script> script); | 598 static void CompileForLiveEdit(Handle<Script> script); |
595 | 599 |
596 // Parser::Parse, then Compiler::Analyze. | 600 // Parser::Parse, then Compiler::Analyze. |
597 static bool ParseAndAnalyze(ParseInfo* info); | 601 static bool ParseAndAnalyze(ParseInfo* info); |
598 // Rewrite, analyze scopes, and renumber. | 602 // Rewrite, analyze scopes, and renumber. |
599 static bool Analyze(ParseInfo* info); | 603 static bool Analyze(ParseInfo* info); |
600 // Adds deoptimization support, requires ParseAndAnalyze. | 604 // Adds deoptimization support, requires ParseAndAnalyze. |
601 static bool EnsureDeoptimizationSupport(CompilationInfo* info); | 605 static bool EnsureDeoptimizationSupport(CompilationInfo* info); |
602 | 606 |
| 607 // =========================================================================== |
| 608 // The following family of methods instantiates new functions for script or |
| 609 // function literals. The decision whether those functions have been compiled |
| 610 // is left to the discretion of the compiler. |
| 611 // |
| 612 // Please note this interface returns shared function infos. This means you |
| 613 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a |
| 614 // real function with a context. |
| 615 |
603 // Compile a String source within a context for eval. | 616 // Compile a String source within a context for eval. |
604 MUST_USE_RESULT static MaybeHandle<JSFunction> GetFunctionFromEval( | 617 MUST_USE_RESULT static MaybeHandle<JSFunction> GetFunctionFromEval( |
605 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 618 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
606 Handle<Context> context, LanguageMode language_mode, | 619 Handle<Context> context, LanguageMode language_mode, |
607 ParseRestriction restriction, int line_offset, int column_offset = 0, | 620 ParseRestriction restriction, int line_offset, int column_offset = 0, |
608 Handle<Object> script_name = Handle<Object>(), | 621 Handle<Object> script_name = Handle<Object>(), |
609 ScriptOriginOptions options = ScriptOriginOptions()); | 622 ScriptOriginOptions options = ScriptOriginOptions()); |
610 | 623 |
611 // Compile a String source within a context. | 624 // Compile a String source within a context. |
612 static Handle<SharedFunctionInfo> CompileScript( | 625 static Handle<SharedFunctionInfo> CompileScript( |
613 Handle<String> source, Handle<Object> script_name, int line_offset, | 626 Handle<String> source, Handle<Object> script_name, int line_offset, |
614 int column_offset, ScriptOriginOptions resource_options, | 627 int column_offset, ScriptOriginOptions resource_options, |
615 Handle<Object> source_map_url, Handle<Context> context, | 628 Handle<Object> source_map_url, Handle<Context> context, |
616 v8::Extension* extension, ScriptData** cached_data, | 629 v8::Extension* extension, ScriptData** cached_data, |
617 ScriptCompiler::CompileOptions compile_options, | 630 ScriptCompiler::CompileOptions compile_options, |
618 NativesFlag is_natives_code, bool is_module); | 631 NativesFlag is_natives_code, bool is_module); |
619 | 632 |
620 static Handle<SharedFunctionInfo> CompileStreamedScript(Handle<Script> script, | 633 static Handle<SharedFunctionInfo> CompileStreamedScript(Handle<Script> script, |
621 ParseInfo* info, | 634 ParseInfo* info, |
622 int source_length); | 635 int source_length); |
623 | 636 |
624 // Create a shared function info object (the code may be lazily compiled). | 637 // Create a shared function info object (the code may be lazily compiled). |
625 static Handle<SharedFunctionInfo> GetSharedFunctionInfo( | 638 static Handle<SharedFunctionInfo> GetSharedFunctionInfo( |
626 FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer); | 639 FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer); |
627 | 640 |
628 // Create a shared function info object for a native function literal. | 641 // Create a shared function info object for a native function literal. |
629 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative( | 642 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative( |
630 v8::Extension* extension, Handle<String> name); | 643 v8::Extension* extension, Handle<String> name); |
631 | 644 |
632 // Generate and return optimized code or start a concurrent optimization job. | 645 // =========================================================================== |
633 // In the latter case, return the InOptimizationQueue builtin. On failure, | 646 // The following family of methods provides support for OSR. Code generated |
634 // return the empty handle. | 647 // for entry via OSR might not be suitable for normal entry, hence will be |
635 MUST_USE_RESULT static MaybeHandle<Code> GetOptimizedCode( | 648 // returned directly to the caller. |
636 Handle<JSFunction> function, ConcurrencyMode mode, | 649 // |
637 BailoutId osr_ast_id = BailoutId::None(), | 650 // Please note this interface is the only part dealing with {Code} objects |
638 JavaScriptFrame* osr_frame = nullptr); | 651 // directly. Other methods are agnostic to {Code} and can use an interpreter |
| 652 // instead of generating JIT code for a function at all. |
| 653 |
| 654 // Generate and return optimized code for OSR, or empty handle on failure. |
| 655 MUST_USE_RESULT static MaybeHandle<Code> GetOptimizedCodeForOSR( |
| 656 Handle<JSFunction> function, ConcurrencyMode mode, BailoutId osr_ast_id, |
| 657 JavaScriptFrame* osr_frame); |
639 | 658 |
640 // Generate and return code from previously queued optimization job. | 659 // Generate and return code from previously queued optimization job. |
641 // On failure, return the empty handle. | 660 // On failure, return the empty handle. |
642 MUST_USE_RESULT static MaybeHandle<Code> GetConcurrentlyOptimizedCode( | 661 MUST_USE_RESULT static MaybeHandle<Code> GetConcurrentlyOptimizedCode( |
643 OptimizedCompileJob* job); | 662 OptimizedCompileJob* job); |
644 }; | 663 }; |
645 | 664 |
646 } // namespace internal | 665 } // namespace internal |
647 } // namespace v8 | 666 } // namespace v8 |
648 | 667 |
649 #endif // V8_COMPILER_H_ | 668 #endif // V8_COMPILER_H_ |
OLD | NEW |