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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 | 8 |
9 #include "src/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 } | 640 } |
641 | 641 |
642 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 642 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
643 Handle<Script>(info->script()), Handle<Code>(info->code()), | 643 Handle<Script>(info->script()), Handle<Code>(info->code()), |
644 info)); | 644 info)); |
645 } | 645 } |
646 | 646 |
647 | 647 |
648 static bool CompileUnoptimizedCode(CompilationInfo* info) { | 648 static bool CompileUnoptimizedCode(CompilationInfo* info) { |
649 DCHECK(AllowCompilation::IsAllowed(info->isolate())); | 649 DCHECK(AllowCompilation::IsAllowed(info->isolate())); |
650 DCHECK(info->function() != NULL); | 650 if (!Compiler::Analyze(info) || !FullCodeGenerator::MakeCode(info)) { |
wingo
2014/10/28 08:31:02
This part changed since the last patch to signal S
| |
651 if (!Rewriter::Rewrite(info)) return false; | |
652 if (!Scope::Analyze(info)) return false; | |
653 DCHECK(info->scope() != NULL); | |
654 | |
655 if (!FullCodeGenerator::MakeCode(info)) { | |
656 Isolate* isolate = info->isolate(); | 651 Isolate* isolate = info->isolate(); |
657 if (!isolate->has_pending_exception()) isolate->StackOverflow(); | 652 if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
658 return false; | 653 return false; |
659 } | 654 } |
660 return true; | 655 return true; |
661 } | 656 } |
662 | 657 |
663 | 658 |
664 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( | 659 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( |
665 CompilationInfo* info) { | 660 CompilationInfo* info) { |
666 VMState<COMPILER> state(info->isolate()); | 661 VMState<COMPILER> state(info->isolate()); |
667 PostponeInterruptsScope postpone(info->isolate()); | 662 PostponeInterruptsScope postpone(info->isolate()); |
668 | 663 |
669 // Parse and update CompilationInfo with the results. | 664 // Parse and update CompilationInfo with the results. |
670 if (!Parser::Parse(info)) return MaybeHandle<Code>(); | 665 if (!Parser::Parse(info)) return MaybeHandle<Code>(); |
671 Handle<SharedFunctionInfo> shared = info->shared_info(); | 666 Handle<SharedFunctionInfo> shared = info->shared_info(); |
672 FunctionLiteral* lit = info->function(); | 667 FunctionLiteral* lit = info->function(); |
673 shared->set_strict_mode(lit->strict_mode()); | 668 shared->set_strict_mode(lit->strict_mode()); |
674 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 669 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
675 shared->set_bailout_reason(lit->dont_optimize_reason()); | 670 shared->set_bailout_reason(lit->dont_optimize_reason()); |
676 shared->set_ast_node_count(lit->ast_node_count()); | |
677 | 671 |
678 // Compile unoptimized code. | 672 // Compile unoptimized code. |
679 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); | 673 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); |
680 | 674 |
681 CHECK_EQ(Code::FUNCTION, info->code()->kind()); | 675 CHECK_EQ(Code::FUNCTION, info->code()->kind()); |
682 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); | 676 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
683 | 677 |
684 // Update the shared function info with the scope info. Allocating the | 678 // Update the shared function info with the scope info. Allocating the |
685 // ScopeInfo object may cause a GC. | 679 // ScopeInfo object may cause a GC. |
686 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone()); | 680 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
736 // Do not cache bound functions. | 730 // Do not cache bound functions. |
737 if (shared->bound()) return; | 731 if (shared->bound()) return; |
738 Handle<FixedArray> literals(function->literals()); | 732 Handle<FixedArray> literals(function->literals()); |
739 Handle<Context> native_context(function->context()->native_context()); | 733 Handle<Context> native_context(function->context()->native_context()); |
740 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 734 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
741 literals, info->osr_ast_id()); | 735 literals, info->osr_ast_id()); |
742 } | 736 } |
743 } | 737 } |
744 | 738 |
745 | 739 |
746 static bool CompileOptimizedPrologue(CompilationInfo* info) { | 740 static bool Renumber(CompilationInfo* info) { |
747 if (!Parser::Parse(info)) return false; | 741 if (!AstNumbering::Renumber(info->function(), info->zone())) return false; |
742 if (!info->shared_info().is_null()) { | |
743 info->shared_info()->set_ast_node_count(info->function()->ast_node_count()); | |
744 } | |
745 return true; | |
746 } | |
747 | |
748 | |
749 bool Compiler::Analyze(CompilationInfo* info) { | |
750 DCHECK(info->function() != NULL); | |
748 if (!Rewriter::Rewrite(info)) return false; | 751 if (!Rewriter::Rewrite(info)) return false; |
749 if (!Scope::Analyze(info)) return false; | 752 if (!Scope::Analyze(info)) return false; |
750 if (!AstNumbering::Renumber(info->function(), info->zone())) return false; | 753 if (!Renumber(info)) return false; |
751 DCHECK(info->scope() != NULL); | 754 DCHECK(info->scope() != NULL); |
752 return true; | 755 return true; |
753 } | 756 } |
754 | 757 |
755 | 758 |
759 bool Compiler::ParseAndAnalyze(CompilationInfo* info) { | |
760 if (!Parser::Parse(info)) return false; | |
761 return Compiler::Analyze(info); | |
762 } | |
763 | |
764 | |
756 static bool GetOptimizedCodeNow(CompilationInfo* info) { | 765 static bool GetOptimizedCodeNow(CompilationInfo* info) { |
757 if (!CompileOptimizedPrologue(info)) return false; | 766 if (!Compiler::ParseAndAnalyze(info)) return false; |
758 | 767 |
759 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); | 768 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); |
760 | 769 |
761 OptimizedCompileJob job(info); | 770 OptimizedCompileJob job(info); |
762 if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED || | 771 if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED || |
763 job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED || | 772 job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED || |
764 job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) { | 773 job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) { |
765 if (FLAG_trace_opt) { | 774 if (FLAG_trace_opt) { |
766 PrintF("[aborted optimizing "); | 775 PrintF("[aborted optimizing "); |
767 info->closure()->ShortPrint(); | 776 info->closure()->ShortPrint(); |
(...skipping 21 matching lines...) Expand all Loading... | |
789 if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { | 798 if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { |
790 if (FLAG_trace_concurrent_recompilation) { | 799 if (FLAG_trace_concurrent_recompilation) { |
791 PrintF(" ** Compilation queue full, will retry optimizing "); | 800 PrintF(" ** Compilation queue full, will retry optimizing "); |
792 info->closure()->ShortPrint(); | 801 info->closure()->ShortPrint(); |
793 PrintF(" later.\n"); | 802 PrintF(" later.\n"); |
794 } | 803 } |
795 return false; | 804 return false; |
796 } | 805 } |
797 | 806 |
798 CompilationHandleScope handle_scope(info); | 807 CompilationHandleScope handle_scope(info); |
799 if (!CompileOptimizedPrologue(info)) return false; | 808 if (!Compiler::ParseAndAnalyze(info)) return false; |
800 info->SaveHandles(); // Copy handles to the compilation handle scope. | 809 info->SaveHandles(); // Copy handles to the compilation handle scope. |
801 | 810 |
802 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); | 811 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); |
803 | 812 |
804 OptimizedCompileJob* job = new (info->zone()) OptimizedCompileJob(info); | 813 OptimizedCompileJob* job = new (info->zone()) OptimizedCompileJob(info); |
805 OptimizedCompileJob::Status status = job->CreateGraph(); | 814 OptimizedCompileJob::Status status = job->CreateGraph(); |
806 if (status != OptimizedCompileJob::SUCCEEDED) return false; | 815 if (status != OptimizedCompileJob::SUCCEEDED) return false; |
807 isolate->optimizing_compiler_thread()->QueueForOptimization(job); | 816 isolate->optimizing_compiler_thread()->QueueForOptimization(job); |
808 | 817 |
809 if (FLAG_trace_concurrent_recompilation) { | 818 if (FLAG_trace_concurrent_recompilation) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
903 } | 912 } |
904 function->ReplaceCode(*code); | 913 function->ReplaceCode(*code); |
905 DCHECK(function->is_compiled()); | 914 DCHECK(function->is_compiled()); |
906 return true; | 915 return true; |
907 } | 916 } |
908 | 917 |
909 | 918 |
910 // TODO(turbofan): In the future, unoptimized code with deopt support could | 919 // TODO(turbofan): In the future, unoptimized code with deopt support could |
911 // be generated lazily once deopt is triggered. | 920 // be generated lazily once deopt is triggered. |
912 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { | 921 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { |
922 DCHECK(info->function() != NULL); | |
923 DCHECK(info->scope() != NULL); | |
913 if (!info->shared_info()->has_deoptimization_support()) { | 924 if (!info->shared_info()->has_deoptimization_support()) { |
914 CompilationInfoWithZone unoptimized(info->shared_info()); | 925 CompilationInfoWithZone unoptimized(info->shared_info()); |
915 // Note that we use the same AST that we will use for generating the | 926 // Note that we use the same AST that we will use for generating the |
916 // optimized code. | 927 // optimized code. |
917 unoptimized.SetFunction(info->function()); | 928 unoptimized.SetFunction(info->function()); |
918 unoptimized.PrepareForCompilation(info->scope()); | 929 unoptimized.PrepareForCompilation(info->scope()); |
919 unoptimized.SetContext(info->context()); | 930 unoptimized.SetContext(info->context()); |
920 unoptimized.EnableDeoptimizationSupport(); | 931 unoptimized.EnableDeoptimizationSupport(); |
921 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; | 932 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; |
922 | 933 |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1297 // the inner unction must be allowed to be compiled lazily. | 1308 // the inner unction must be allowed to be compiled lazily. |
1298 DCHECK(allow_lazy); | 1309 DCHECK(allow_lazy); |
1299 } | 1310 } |
1300 | 1311 |
1301 // Generate code | 1312 // Generate code |
1302 Handle<ScopeInfo> scope_info; | 1313 Handle<ScopeInfo> scope_info; |
1303 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { | 1314 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { |
1304 Handle<Code> code = isolate->builtins()->CompileLazy(); | 1315 Handle<Code> code = isolate->builtins()->CompileLazy(); |
1305 info.SetCode(code); | 1316 info.SetCode(code); |
1306 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); | 1317 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); |
1307 } else if (FullCodeGenerator::MakeCode(&info)) { | 1318 } else if (Renumber(&info) && FullCodeGenerator::MakeCode(&info)) { |
1308 DCHECK(!info.code().is_null()); | 1319 DCHECK(!info.code().is_null()); |
1309 scope_info = ScopeInfo::Create(info.scope(), info.zone()); | 1320 scope_info = ScopeInfo::Create(info.scope(), info.zone()); |
1310 } else { | 1321 } else { |
1311 return Handle<SharedFunctionInfo>::null(); | 1322 return Handle<SharedFunctionInfo>::null(); |
1312 } | 1323 } |
1313 | 1324 |
1314 // Create a shared function info object. | 1325 // Create a shared function info object. |
1315 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo( | 1326 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo( |
1316 literal->name(), literal->materialized_literal_count(), literal->kind(), | 1327 literal->name(), literal->materialized_literal_count(), literal->kind(), |
1317 info.code(), scope_info, info.feedback_vector()); | 1328 info.code(), scope_info, info.feedback_vector()); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1457 AllowHandleDereference allow_deref; | 1468 AllowHandleDereference allow_deref; |
1458 bool tracing_on = info()->IsStub() | 1469 bool tracing_on = info()->IsStub() |
1459 ? FLAG_trace_hydrogen_stubs | 1470 ? FLAG_trace_hydrogen_stubs |
1460 : (FLAG_trace_hydrogen && | 1471 : (FLAG_trace_hydrogen && |
1461 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1472 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
1462 return (tracing_on && | 1473 return (tracing_on && |
1463 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1474 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
1464 } | 1475 } |
1465 | 1476 |
1466 } } // namespace v8::internal | 1477 } } // namespace v8::internal |
OLD | NEW |