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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 484 |
485 // The current OSR frame for specialization or {nullptr}. | 485 // The current OSR frame for specialization or {nullptr}. |
486 JavaScriptFrame* osr_frame_ = nullptr; | 486 JavaScriptFrame* osr_frame_ = nullptr; |
487 | 487 |
488 const char* debug_name_; | 488 const char* debug_name_; |
489 | 489 |
490 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); | 490 DISALLOW_COPY_AND_ASSIGN(CompilationInfo); |
491 }; | 491 }; |
492 | 492 |
493 | 493 |
494 // A wrapper around a CompilationInfo that detaches the Handles from | |
495 // the underlying DeferredHandleScope and stores them in info_ on | |
496 // destruction. | |
497 class CompilationHandleScope BASE_EMBEDDED { | |
498 public: | |
499 explicit CompilationHandleScope(CompilationInfo* info) | |
500 : deferred_(info->isolate()), info_(info) {} | |
501 ~CompilationHandleScope() { | |
502 info_->set_deferred_handles(deferred_.Detach()); | |
503 } | |
504 | |
505 private: | |
506 DeferredHandleScope deferred_; | |
507 CompilationInfo* info_; | |
508 }; | |
509 | |
510 | |
511 class HGraph; | 494 class HGraph; |
512 class LChunk; | 495 class LChunk; |
513 | 496 |
514 // A helper class that calls the three compilation phases in | 497 // A helper class that calls the three compilation phases in |
515 // Crankshaft and keeps track of its state. The three phases | 498 // Crankshaft and keeps track of its state. The three phases |
516 // CreateGraph, OptimizeGraph and GenerateAndInstallCode can either | 499 // CreateGraph, OptimizeGraph and GenerateAndInstallCode can either |
517 // fail, bail-out to the full code generator or succeed. Apart from | 500 // fail, bail-out to the full code generator or succeed. Apart from |
518 // their return value, the status of the phase last run can be checked | 501 // their return value, the status of the phase last run can be checked |
519 // using last_status(). | 502 // using last_status(). |
520 class OptimizedCompileJob: public ZoneObject { | 503 class OptimizedCompileJob: public ZoneObject { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 // parameters which then can be executed. If the source code contains other | 578 // parameters which then can be executed. If the source code contains other |
596 // functions, they will be compiled and allocated as part of the compilation | 579 // functions, they will be compiled and allocated as part of the compilation |
597 // of the source code. | 580 // of the source code. |
598 | 581 |
599 // Please note this interface returns shared function infos. This means you | 582 // Please note this interface returns shared function infos. This means you |
600 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a | 583 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a |
601 // real function with a context. | 584 // real function with a context. |
602 | 585 |
603 class Compiler : public AllStatic { | 586 class Compiler : public AllStatic { |
604 public: | 587 public: |
605 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCode( | 588 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; |
606 Handle<JSFunction> function); | |
607 MUST_USE_RESULT static MaybeHandle<Code> GetLazyCode( | |
608 Handle<JSFunction> function); | |
609 | 589 |
610 static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); | 590 static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); |
| 591 static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode); |
611 static bool CompileDebugCode(Handle<JSFunction> function); | 592 static bool CompileDebugCode(Handle<JSFunction> function); |
612 static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); | 593 static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); |
613 static void CompileForLiveEdit(Handle<Script> script); | 594 static void CompileForLiveEdit(Handle<Script> script); |
614 | 595 |
615 // Parser::Parse, then Compiler::Analyze. | 596 // Parser::Parse, then Compiler::Analyze. |
616 static bool ParseAndAnalyze(ParseInfo* info); | 597 static bool ParseAndAnalyze(ParseInfo* info); |
617 // Rewrite, analyze scopes, and renumber. | 598 // Rewrite, analyze scopes, and renumber. |
618 static bool Analyze(ParseInfo* info); | 599 static bool Analyze(ParseInfo* info); |
619 // Adds deoptimization support, requires ParseAndAnalyze. | 600 // Adds deoptimization support, requires ParseAndAnalyze. |
620 static bool EnsureDeoptimizationSupport(CompilationInfo* info); | 601 static bool EnsureDeoptimizationSupport(CompilationInfo* info); |
(...skipping 20 matching lines...) Expand all Loading... |
641 int source_length); | 622 int source_length); |
642 | 623 |
643 // Create a shared function info object (the code may be lazily compiled). | 624 // Create a shared function info object (the code may be lazily compiled). |
644 static Handle<SharedFunctionInfo> GetSharedFunctionInfo( | 625 static Handle<SharedFunctionInfo> GetSharedFunctionInfo( |
645 FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer); | 626 FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer); |
646 | 627 |
647 // Create a shared function info object for a native function literal. | 628 // Create a shared function info object for a native function literal. |
648 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative( | 629 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative( |
649 v8::Extension* extension, Handle<String> name); | 630 v8::Extension* extension, Handle<String> name); |
650 | 631 |
651 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; | |
652 | |
653 // Generate and return optimized code or start a concurrent optimization job. | 632 // Generate and return optimized code or start a concurrent optimization job. |
654 // In the latter case, return the InOptimizationQueue builtin. On failure, | 633 // In the latter case, return the InOptimizationQueue builtin. On failure, |
655 // return the empty handle. | 634 // return the empty handle. |
656 MUST_USE_RESULT static MaybeHandle<Code> GetOptimizedCode( | 635 MUST_USE_RESULT static MaybeHandle<Code> GetOptimizedCode( |
657 Handle<JSFunction> function, ConcurrencyMode mode, | 636 Handle<JSFunction> function, ConcurrencyMode mode, |
658 BailoutId osr_ast_id = BailoutId::None(), | 637 BailoutId osr_ast_id = BailoutId::None(), |
659 JavaScriptFrame* osr_frame = nullptr); | 638 JavaScriptFrame* osr_frame = nullptr); |
660 | 639 |
661 // Generate and return code from previously queued optimization job. | 640 // Generate and return code from previously queued optimization job. |
662 // On failure, return the empty handle. | 641 // On failure, return the empty handle. |
663 MUST_USE_RESULT static MaybeHandle<Code> GetConcurrentlyOptimizedCode( | 642 MUST_USE_RESULT static MaybeHandle<Code> GetConcurrentlyOptimizedCode( |
664 OptimizedCompileJob* job); | 643 OptimizedCompileJob* job); |
665 }; | 644 }; |
666 | 645 |
667 } // namespace internal | 646 } // namespace internal |
668 } // namespace v8 | 647 } // namespace v8 |
669 | 648 |
670 #endif // V8_COMPILER_H_ | 649 #endif // V8_COMPILER_H_ |
OLD | NEW |