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