| 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 !function()->flags()->Contains(kDontSelfOptimize) && | 284 !function()->flags()->Contains(kDontSelfOptimize) && |
| 285 !function()->dont_optimize() && | 285 !function()->dont_optimize() && |
| 286 function()->scope()->AllowsLazyCompilation() && | 286 function()->scope()->AllowsLazyCompilation() && |
| 287 (shared_info().is_null() || !shared_info()->optimization_disabled()); | 287 (shared_info().is_null() || !shared_info()->optimization_disabled()); |
| 288 } | 288 } |
| 289 | 289 |
| 290 | 290 |
| 291 void CompilationInfo::PrepareForCompilation(Scope* scope) { | 291 void CompilationInfo::PrepareForCompilation(Scope* scope) { |
| 292 DCHECK(scope_ == NULL); | 292 DCHECK(scope_ == NULL); |
| 293 scope_ = scope; | 293 scope_ = scope; |
| 294 } |
| 294 | 295 |
| 296 |
| 297 void CompilationInfo::EnsureFeedbackVector() { |
| 295 if (feedback_vector_.is_null()) { | 298 if (feedback_vector_.is_null()) { |
| 296 // Allocate the feedback vector too. | |
| 297 feedback_vector_ = isolate()->factory()->NewTypeFeedbackVector( | 299 feedback_vector_ = isolate()->factory()->NewTypeFeedbackVector( |
| 298 function()->slot_count(), function()->ic_slot_count()); | 300 function()->slot_count(), function()->ic_slot_count()); |
| 299 } | 301 } |
| 300 DCHECK(feedback_vector_->Slots() == function()->slot_count() && | 302 DCHECK(feedback_vector_->Slots() == function()->slot_count() && |
| 301 feedback_vector_->ICSlots() == function()->ic_slot_count()); | 303 feedback_vector_->ICSlots() == function()->ic_slot_count()); |
| 302 } | 304 } |
| 303 | 305 |
| 304 | 306 |
| 305 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { | 307 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { |
| 306 public: | 308 public: |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 DCHECK(info->function() != NULL); | 652 DCHECK(info->function() != NULL); |
| 651 if (!Rewriter::Rewrite(info)) return false; | 653 if (!Rewriter::Rewrite(info)) return false; |
| 652 if (!Scope::Analyze(info)) return false; | 654 if (!Scope::Analyze(info)) return false; |
| 653 DCHECK(info->scope() != NULL); | 655 DCHECK(info->scope() != NULL); |
| 654 | 656 |
| 655 if (!FullCodeGenerator::MakeCode(info)) { | 657 if (!FullCodeGenerator::MakeCode(info)) { |
| 656 Isolate* isolate = info->isolate(); | 658 Isolate* isolate = info->isolate(); |
| 657 if (!isolate->has_pending_exception()) isolate->StackOverflow(); | 659 if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
| 658 return false; | 660 return false; |
| 659 } | 661 } |
| 662 |
| 660 return true; | 663 return true; |
| 661 } | 664 } |
| 662 | 665 |
| 663 | 666 |
| 664 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( | 667 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( |
| 665 CompilationInfo* info) { | 668 CompilationInfo* info) { |
| 666 VMState<COMPILER> state(info->isolate()); | 669 VMState<COMPILER> state(info->isolate()); |
| 667 PostponeInterruptsScope postpone(info->isolate()); | 670 PostponeInterruptsScope postpone(info->isolate()); |
| 668 | 671 |
| 669 // Parse and update CompilationInfo with the results. | 672 // Parse and update CompilationInfo with the results. |
| 670 if (!Parser::Parse(info)) return MaybeHandle<Code>(); | 673 if (!Parser::Parse(info)) return MaybeHandle<Code>(); |
| 671 Handle<SharedFunctionInfo> shared = info->shared_info(); | 674 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 672 FunctionLiteral* lit = info->function(); | 675 FunctionLiteral* lit = info->function(); |
| 673 shared->set_strict_mode(lit->strict_mode()); | 676 shared->set_strict_mode(lit->strict_mode()); |
| 674 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 677 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
| 675 shared->set_bailout_reason(lit->dont_optimize_reason()); | |
| 676 shared->set_ast_node_count(lit->ast_node_count()); | |
| 677 | 678 |
| 678 // Compile unoptimized code. | 679 // Compile unoptimized code. |
| 679 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); | 680 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); |
| 680 | 681 |
| 681 CHECK_EQ(Code::FUNCTION, info->code()->kind()); | 682 CHECK_EQ(Code::FUNCTION, info->code()->kind()); |
| 682 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); | 683 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
| 683 | 684 |
| 684 // Update the shared function info with the scope info. Allocating the | 685 // Update the shared function info with the scope info. Allocating the |
| 685 // ScopeInfo object may cause a GC. | 686 // ScopeInfo object may cause a GC. |
| 686 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone()); | 687 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 741 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
| 741 literals, info->osr_ast_id()); | 742 literals, info->osr_ast_id()); |
| 742 } | 743 } |
| 743 } | 744 } |
| 744 | 745 |
| 745 | 746 |
| 746 static bool CompileOptimizedPrologue(CompilationInfo* info) { | 747 static bool CompileOptimizedPrologue(CompilationInfo* info) { |
| 747 if (!Parser::Parse(info)) return false; | 748 if (!Parser::Parse(info)) return false; |
| 748 if (!Rewriter::Rewrite(info)) return false; | 749 if (!Rewriter::Rewrite(info)) return false; |
| 749 if (!Scope::Analyze(info)) return false; | 750 if (!Scope::Analyze(info)) return false; |
| 750 if (!AstNumbering::Renumber(info->function(), info->zone())) return false; | 751 if (!AstNumbering::Renumber(info->function(), info->shared_info(), |
| 752 info->zone())) { |
| 753 return false; |
| 754 } |
| 751 DCHECK(info->scope() != NULL); | 755 DCHECK(info->scope() != NULL); |
| 752 return true; | 756 return true; |
| 753 } | 757 } |
| 754 | 758 |
| 755 | 759 |
| 756 static bool GetOptimizedCodeNow(CompilationInfo* info) { | 760 static bool GetOptimizedCodeNow(CompilationInfo* info) { |
| 757 if (!CompileOptimizedPrologue(info)) return false; | 761 if (!CompileOptimizedPrologue(info)) return false; |
| 758 | 762 |
| 759 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); | 763 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); |
| 760 | 764 |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1296 // Make sure that if the toplevel code (possibly to be serialized), | 1300 // Make sure that if the toplevel code (possibly to be serialized), |
| 1297 // the inner unction must be allowed to be compiled lazily. | 1301 // the inner unction must be allowed to be compiled lazily. |
| 1298 DCHECK(allow_lazy); | 1302 DCHECK(allow_lazy); |
| 1299 } | 1303 } |
| 1300 | 1304 |
| 1301 // Generate code | 1305 // Generate code |
| 1302 Handle<ScopeInfo> scope_info; | 1306 Handle<ScopeInfo> scope_info; |
| 1303 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { | 1307 if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) { |
| 1304 Handle<Code> code = isolate->builtins()->CompileLazy(); | 1308 Handle<Code> code = isolate->builtins()->CompileLazy(); |
| 1305 info.SetCode(code); | 1309 info.SetCode(code); |
| 1310 // There's no need in theory for a lazy-compiled function to have a type |
| 1311 // feedback vector, but some parts of the system expect all |
| 1312 // SharedFunctionInfo instances to have one. The size of the vector depends |
| 1313 // on how many feedback-needing nodes are in the tree, and when lazily |
| 1314 // parsing we might not know that, if this function was never parsed before. |
| 1315 // In that case the vector will be replaced the next time MakeCode is |
| 1316 // called. |
| 1317 info.EnsureFeedbackVector(); |
| 1306 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); | 1318 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); |
| 1307 } else if (FullCodeGenerator::MakeCode(&info)) { | 1319 } else if (FullCodeGenerator::MakeCode(&info)) { |
| 1320 // MakeCode will ensure that the feedback vector is present and |
| 1321 // appropriately sized. |
| 1308 DCHECK(!info.code().is_null()); | 1322 DCHECK(!info.code().is_null()); |
| 1309 scope_info = ScopeInfo::Create(info.scope(), info.zone()); | 1323 scope_info = ScopeInfo::Create(info.scope(), info.zone()); |
| 1310 } else { | 1324 } else { |
| 1311 return Handle<SharedFunctionInfo>::null(); | 1325 return Handle<SharedFunctionInfo>::null(); |
| 1312 } | 1326 } |
| 1313 | 1327 |
| 1314 // Create a shared function info object. | 1328 // Create a shared function info object. |
| 1315 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo( | 1329 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo( |
| 1316 literal->name(), literal->materialized_literal_count(), literal->kind(), | 1330 literal->name(), literal->materialized_literal_count(), literal->kind(), |
| 1317 info.code(), scope_info, info.feedback_vector()); | 1331 info.code(), scope_info, info.feedback_vector()); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 AllowHandleDereference allow_deref; | 1471 AllowHandleDereference allow_deref; |
| 1458 bool tracing_on = info()->IsStub() | 1472 bool tracing_on = info()->IsStub() |
| 1459 ? FLAG_trace_hydrogen_stubs | 1473 ? FLAG_trace_hydrogen_stubs |
| 1460 : (FLAG_trace_hydrogen && | 1474 : (FLAG_trace_hydrogen && |
| 1461 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1475 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
| 1462 return (tracing_on && | 1476 return (tracing_on && |
| 1463 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1477 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
| 1464 } | 1478 } |
| 1465 | 1479 |
| 1466 } } // namespace v8::internal | 1480 } } // namespace v8::internal |
| OLD | NEW |