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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 // so we can afford to adjust the estimate generously. | 571 // so we can afford to adjust the estimate generously. |
572 estimate += 8; | 572 estimate += 8; |
573 } else { | 573 } else { |
574 estimate += 3; | 574 estimate += 3; |
575 } | 575 } |
576 | 576 |
577 shared->set_expected_nof_properties(estimate); | 577 shared->set_expected_nof_properties(estimate); |
578 } | 578 } |
579 | 579 |
580 | 580 |
| 581 static void MaybeDisableOptimization(Handle<SharedFunctionInfo> shared_info, |
| 582 BailoutReason bailout_reason) { |
| 583 if (bailout_reason != kNoReason) { |
| 584 shared_info->DisableOptimization(bailout_reason); |
| 585 } |
| 586 } |
| 587 |
| 588 |
581 // Sets the function info on a function. | 589 // Sets the function info on a function. |
582 // The start_position points to the first '(' character after the function name | 590 // The start_position points to the first '(' character after the function name |
583 // in the full script source. When counting characters in the script source the | 591 // in the full script source. When counting characters in the script source the |
584 // the first character is number 0 (not 1). | 592 // the first character is number 0 (not 1). |
585 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, | 593 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, |
586 FunctionLiteral* lit, | 594 FunctionLiteral* lit, |
587 bool is_toplevel, | 595 bool is_toplevel, |
588 Handle<Script> script) { | 596 Handle<Script> script) { |
589 function_info->set_length(lit->parameter_count()); | 597 function_info->set_length(lit->parameter_count()); |
590 function_info->set_formal_parameter_count(lit->parameter_count()); | 598 function_info->set_formal_parameter_count(lit->parameter_count()); |
591 function_info->set_script(*script); | 599 function_info->set_script(*script); |
592 function_info->set_function_token_position(lit->function_token_position()); | 600 function_info->set_function_token_position(lit->function_token_position()); |
593 function_info->set_start_position(lit->start_position()); | 601 function_info->set_start_position(lit->start_position()); |
594 function_info->set_end_position(lit->end_position()); | 602 function_info->set_end_position(lit->end_position()); |
595 function_info->set_is_expression(lit->is_expression()); | 603 function_info->set_is_expression(lit->is_expression()); |
596 function_info->set_is_anonymous(lit->is_anonymous()); | 604 function_info->set_is_anonymous(lit->is_anonymous()); |
597 function_info->set_is_toplevel(is_toplevel); | 605 function_info->set_is_toplevel(is_toplevel); |
598 function_info->set_inferred_name(*lit->inferred_name()); | 606 function_info->set_inferred_name(*lit->inferred_name()); |
599 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 607 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
600 function_info->set_allows_lazy_compilation_without_context( | 608 function_info->set_allows_lazy_compilation_without_context( |
601 lit->AllowsLazyCompilationWithoutContext()); | 609 lit->AllowsLazyCompilationWithoutContext()); |
602 function_info->set_strict_mode(lit->strict_mode()); | 610 function_info->set_strict_mode(lit->strict_mode()); |
603 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); | 611 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
604 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); | 612 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
605 function_info->set_ast_node_count(lit->ast_node_count()); | 613 function_info->set_ast_node_count(lit->ast_node_count()); |
606 function_info->set_is_function(lit->is_function()); | 614 function_info->set_is_function(lit->is_function()); |
607 function_info->set_bailout_reason(lit->dont_optimize_reason()); | 615 MaybeDisableOptimization(function_info, lit->dont_optimize_reason()); |
608 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); | 616 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); |
609 function_info->set_kind(lit->kind()); | 617 function_info->set_kind(lit->kind()); |
610 function_info->set_asm_function(lit->scope()->asm_function()); | 618 function_info->set_asm_function(lit->scope()->asm_function()); |
611 } | 619 } |
612 | 620 |
613 | 621 |
614 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 622 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
615 CompilationInfo* info, | 623 CompilationInfo* info, |
616 Handle<SharedFunctionInfo> shared) { | 624 Handle<SharedFunctionInfo> shared) { |
617 // SharedFunctionInfo is passed separately, because if CompilationInfo | 625 // SharedFunctionInfo is passed separately, because if CompilationInfo |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 CompilationInfo* info) { | 668 CompilationInfo* info) { |
661 VMState<COMPILER> state(info->isolate()); | 669 VMState<COMPILER> state(info->isolate()); |
662 PostponeInterruptsScope postpone(info->isolate()); | 670 PostponeInterruptsScope postpone(info->isolate()); |
663 | 671 |
664 // Parse and update CompilationInfo with the results. | 672 // Parse and update CompilationInfo with the results. |
665 if (!Parser::Parse(info)) return MaybeHandle<Code>(); | 673 if (!Parser::Parse(info)) return MaybeHandle<Code>(); |
666 Handle<SharedFunctionInfo> shared = info->shared_info(); | 674 Handle<SharedFunctionInfo> shared = info->shared_info(); |
667 FunctionLiteral* lit = info->function(); | 675 FunctionLiteral* lit = info->function(); |
668 shared->set_strict_mode(lit->strict_mode()); | 676 shared->set_strict_mode(lit->strict_mode()); |
669 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 677 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
670 shared->set_bailout_reason(lit->dont_optimize_reason()); | 678 MaybeDisableOptimization(shared, lit->dont_optimize_reason()); |
671 | 679 |
672 // Compile unoptimized code. | 680 // Compile unoptimized code. |
673 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); | 681 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); |
674 | 682 |
675 CHECK_EQ(Code::FUNCTION, info->code()->kind()); | 683 CHECK_EQ(Code::FUNCTION, info->code()->kind()); |
676 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); | 684 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
677 | 685 |
678 // Update the shared function info with the scope info. Allocating the | 686 // Update the shared function info with the scope info. Allocating the |
679 // ScopeInfo object may cause a GC. | 687 // ScopeInfo object may cause a GC. |
680 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone()); | 688 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 Handle<Context> native_context(function->context()->native_context()); | 741 Handle<Context> native_context(function->context()->native_context()); |
734 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 742 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
735 literals, info->osr_ast_id()); | 743 literals, info->osr_ast_id()); |
736 } | 744 } |
737 } | 745 } |
738 | 746 |
739 | 747 |
740 static bool Renumber(CompilationInfo* info) { | 748 static bool Renumber(CompilationInfo* info) { |
741 if (!AstNumbering::Renumber(info->function(), info->zone())) return false; | 749 if (!AstNumbering::Renumber(info->function(), info->zone())) return false; |
742 if (!info->shared_info().is_null()) { | 750 if (!info->shared_info().is_null()) { |
743 info->shared_info()->set_ast_node_count(info->function()->ast_node_count()); | 751 FunctionLiteral* lit = info->function(); |
| 752 info->shared_info()->set_ast_node_count(lit->ast_node_count()); |
| 753 MaybeDisableOptimization(info->shared_info(), lit->dont_optimize_reason()); |
| 754 info->shared_info()->set_dont_cache(lit->flags()->Contains(kDontCache)); |
744 } | 755 } |
745 return true; | 756 return true; |
746 } | 757 } |
747 | 758 |
748 | 759 |
749 bool Compiler::Analyze(CompilationInfo* info) { | 760 bool Compiler::Analyze(CompilationInfo* info) { |
750 DCHECK(info->function() != NULL); | 761 DCHECK(info->function() != NULL); |
751 if (!Rewriter::Rewrite(info)) return false; | 762 if (!Rewriter::Rewrite(info)) return false; |
752 if (!Scope::Analyze(info)) return false; | 763 if (!Scope::Analyze(info)) return false; |
753 if (!Renumber(info)) return false; | 764 if (!Renumber(info)) return false; |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1470 AllowHandleDereference allow_deref; | 1481 AllowHandleDereference allow_deref; |
1471 bool tracing_on = info()->IsStub() | 1482 bool tracing_on = info()->IsStub() |
1472 ? FLAG_trace_hydrogen_stubs | 1483 ? FLAG_trace_hydrogen_stubs |
1473 : (FLAG_trace_hydrogen && | 1484 : (FLAG_trace_hydrogen && |
1474 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1485 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
1475 return (tracing_on && | 1486 return (tracing_on && |
1476 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1487 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
1477 } | 1488 } |
1478 | 1489 |
1479 } } // namespace v8::internal | 1490 } } // namespace v8::internal |
OLD | NEW |