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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 ReportMessage(MessageTemplate::kNotDefined, name); | 579 ReportMessage(MessageTemplate::kNotDefined, name); |
580 *ok = false; | 580 *ok = false; |
581 return nullptr; | 581 return nullptr; |
582 } | 582 } |
583 | 583 |
584 return factory()->NewCallRuntime(context_index, args, pos); | 584 return factory()->NewCallRuntime(context_index, args, pos); |
585 } | 585 } |
586 | 586 |
587 Parser::Parser(ParseInfo* info) | 587 Parser::Parser(ParseInfo* info) |
588 : ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(), | 588 : ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(), |
589 info->extension(), info->ast_value_factory()), | 589 info->extension(), info->ast_value_factory(), |
590 info->isolate()->counters()->runtime_call_stats()), | |
590 scanner_(info->unicode_cache()), | 591 scanner_(info->unicode_cache()), |
591 reusable_preparser_(nullptr), | 592 reusable_preparser_(nullptr), |
592 original_scope_(nullptr), | 593 original_scope_(nullptr), |
593 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 594 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
594 target_stack_(nullptr), | 595 target_stack_(nullptr), |
595 compile_options_(info->compile_options()), | 596 compile_options_(info->compile_options()), |
596 cached_parse_data_(nullptr), | 597 cached_parse_data_(nullptr), |
597 total_preparse_skipped_(0), | 598 total_preparse_skipped_(0), |
598 parsing_on_main_thread_(true), | 599 parsing_on_main_thread_(true), |
599 log_(nullptr) { | 600 log_(nullptr) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 } | 664 } |
664 | 665 |
665 FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { | 666 FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { |
666 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 667 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
667 // see comment for HistogramTimerScope class. | 668 // see comment for HistogramTimerScope class. |
668 | 669 |
669 // It's OK to use the Isolate & counters here, since this function is only | 670 // It's OK to use the Isolate & counters here, since this function is only |
670 // called in the main thread. | 671 // called in the main thread. |
671 DCHECK(parsing_on_main_thread_); | 672 DCHECK(parsing_on_main_thread_); |
672 | 673 |
673 RuntimeCallTimerScope runtime_timer(isolate, &RuntimeCallStats::ParseProgram); | 674 RuntimeCallTimerScope runtime_timer( |
675 runtime_call_stats_, info->is_eval() ? &RuntimeCallStats::ParseEval | |
676 : &RuntimeCallStats::ParseProgram); | |
674 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseProgram"); | 677 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseProgram"); |
675 Handle<String> source(String::cast(info->script()->source())); | 678 Handle<String> source(String::cast(info->script()->source())); |
676 isolate->counters()->total_parse_size()->Increment(source->length()); | 679 isolate->counters()->total_parse_size()->Increment(source->length()); |
677 base::ElapsedTimer timer; | 680 base::ElapsedTimer timer; |
678 if (FLAG_trace_parse) { | 681 if (FLAG_trace_parse) { |
679 timer.Start(); | 682 timer.Start(); |
680 } | 683 } |
681 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); | 684 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); |
682 | 685 |
683 // Initialize parser state. | 686 // Initialize parser state. |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
826 // Make sure the target stack is empty. | 829 // Make sure the target stack is empty. |
827 DCHECK(target_stack_ == NULL); | 830 DCHECK(target_stack_ == NULL); |
828 | 831 |
829 return result; | 832 return result; |
830 } | 833 } |
831 | 834 |
832 FunctionLiteral* Parser::ParseFunction(Isolate* isolate, ParseInfo* info) { | 835 FunctionLiteral* Parser::ParseFunction(Isolate* isolate, ParseInfo* info) { |
833 // It's OK to use the Isolate & counters here, since this function is only | 836 // It's OK to use the Isolate & counters here, since this function is only |
834 // called in the main thread. | 837 // called in the main thread. |
835 DCHECK(parsing_on_main_thread_); | 838 DCHECK(parsing_on_main_thread_); |
836 RuntimeCallTimerScope runtime_timer(isolate, | 839 RuntimeCallTimerScope runtime_timer(runtime_call_stats_, |
837 &RuntimeCallStats::ParseFunction); | 840 &RuntimeCallStats::ParseFunction); |
838 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseFunction"); | 841 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseFunction"); |
839 Handle<String> source(String::cast(info->script()->source())); | 842 Handle<String> source(String::cast(info->script()->source())); |
840 isolate->counters()->total_parse_size()->Increment(source->length()); | 843 isolate->counters()->total_parse_size()->Increment(source->length()); |
841 base::ElapsedTimer timer; | 844 base::ElapsedTimer timer; |
842 if (FLAG_trace_parse) { | 845 if (FLAG_trace_parse) { |
843 timer.Start(); | 846 timer.Start(); |
844 } | 847 } |
845 Handle<SharedFunctionInfo> shared_info = info->shared_info(); | 848 Handle<SharedFunctionInfo> shared_info = info->shared_info(); |
846 DeserializeScopeChain(info, info->maybe_outer_scope_info()); | 849 DeserializeScopeChain(info, info->maybe_outer_scope_info()); |
(...skipping 1726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2573 DCHECK_IMPLIES(parse_lazily(), FLAG_lazy); | 2576 DCHECK_IMPLIES(parse_lazily(), FLAG_lazy); |
2574 DCHECK_IMPLIES(parse_lazily(), allow_lazy()); | 2577 DCHECK_IMPLIES(parse_lazily(), allow_lazy()); |
2575 DCHECK_IMPLIES(parse_lazily(), extension_ == nullptr); | 2578 DCHECK_IMPLIES(parse_lazily(), extension_ == nullptr); |
2576 | 2579 |
2577 bool can_preparse = parse_lazily() && | 2580 bool can_preparse = parse_lazily() && |
2578 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; | 2581 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; |
2579 | 2582 |
2580 bool is_lazy_top_level_function = | 2583 bool is_lazy_top_level_function = |
2581 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); | 2584 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); |
2582 | 2585 |
2586 RuntimeCallTimerScope runtime_timer(runtime_call_stats_, | |
2587 &RuntimeCallStats::ParseFunctionLiteral); | |
2588 | |
2583 // Determine whether we can still lazy parse the inner function. | 2589 // Determine whether we can still lazy parse the inner function. |
2584 // The preconditions are: | 2590 // The preconditions are: |
2585 // - Lazy compilation has to be enabled. | 2591 // - Lazy compilation has to be enabled. |
2586 // - Neither V8 natives nor native function declarations can be allowed, | 2592 // - Neither V8 natives nor native function declarations can be allowed, |
2587 // since parsing one would retroactively force the function to be | 2593 // since parsing one would retroactively force the function to be |
2588 // eagerly compiled. | 2594 // eagerly compiled. |
2589 // - The invoker of this parser can't depend on the AST being eagerly | 2595 // - The invoker of this parser can't depend on the AST being eagerly |
2590 // built (either because the function is about to be compiled, or | 2596 // built (either because the function is about to be compiled, or |
2591 // because the AST is going to be inspected for some reason). | 2597 // because the AST is going to be inspected for some reason). |
2592 // - Because of the above, we can't be attempting to parse a | 2598 // - Because of the above, we can't be attempting to parse a |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2690 scope->AnalyzePartially(&previous_zone_ast_node_factory); | 2696 scope->AnalyzePartially(&previous_zone_ast_node_factory); |
2691 } | 2697 } |
2692 | 2698 |
2693 if (FLAG_trace_preparse) { | 2699 if (FLAG_trace_preparse) { |
2694 PrintF(" [%s]: %i-%i %.*s\n", | 2700 PrintF(" [%s]: %i-%i %.*s\n", |
2695 is_lazy_top_level_function | 2701 is_lazy_top_level_function |
2696 ? "Preparse no-resolution" | 2702 ? "Preparse no-resolution" |
2697 : (use_temp_zone ? "Preparse resolution" : "Full parse"), | 2703 : (use_temp_zone ? "Preparse resolution" : "Full parse"), |
2698 scope->start_position(), scope->end_position(), | 2704 scope->start_position(), scope->end_position(), |
2699 function_name->byte_length(), function_name->raw_data()); | 2705 function_name->byte_length(), function_name->raw_data()); |
2706 if (is_lazy_top_level_function) { | |
2707 CHANGE_CURRENT_RUNTIME_COUNTER(runtime_call_stats_, | |
2708 PreParseNoVariableResolution); | |
2709 } else if (use_temp_zone) { | |
2710 CHANGE_CURRENT_RUNTIME_COUNTER(runtime_call_stats_, | |
2711 PreParseWithVariableResolution); | |
2712 } | |
2700 } | 2713 } |
2701 | 2714 |
2702 // Validate function name. We can do this only after parsing the function, | 2715 // Validate function name. We can do this only after parsing the function, |
2703 // since the function can declare itself strict. | 2716 // since the function can declare itself strict. |
2704 language_mode = scope->language_mode(); | 2717 language_mode = scope->language_mode(); |
2705 CheckFunctionName(language_mode, function_name, function_name_validity, | 2718 CheckFunctionName(language_mode, function_name, function_name_validity, |
2706 function_name_location, CHECK_OK); | 2719 function_name_location, CHECK_OK); |
2707 | 2720 |
2708 if (is_strict(language_mode)) { | 2721 if (is_strict(language_mode)) { |
2709 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), | 2722 CheckStrictOctalLiteral(scope->start_position(), scope->end_position(), |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3284 MarkCollectedTailCallExpressions(); | 3297 MarkCollectedTailCallExpressions(); |
3285 return result; | 3298 return result; |
3286 } | 3299 } |
3287 | 3300 |
3288 PreParser::PreParseResult Parser::ParseFunctionWithPreParser( | 3301 PreParser::PreParseResult Parser::ParseFunctionWithPreParser( |
3289 FunctionKind kind, DeclarationScope* function_scope, bool is_inner_function, | 3302 FunctionKind kind, DeclarationScope* function_scope, bool is_inner_function, |
3290 bool may_abort) { | 3303 bool may_abort) { |
3291 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse"); | 3304 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse"); |
3292 | 3305 |
3293 if (reusable_preparser_ == NULL) { | 3306 if (reusable_preparser_ == NULL) { |
3294 reusable_preparser_ = | 3307 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), |
3295 new PreParser(zone(), &scanner_, ast_value_factory(), stack_limit_); | 3308 runtime_call_stats_, stack_limit_); |
3296 reusable_preparser_->set_allow_lazy(true); | 3309 reusable_preparser_->set_allow_lazy(true); |
3297 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); | 3310 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); |
3298 SET_ALLOW(natives); | 3311 SET_ALLOW(natives); |
3299 SET_ALLOW(harmony_do_expressions); | 3312 SET_ALLOW(harmony_do_expressions); |
3300 SET_ALLOW(harmony_function_sent); | 3313 SET_ALLOW(harmony_function_sent); |
3301 SET_ALLOW(harmony_async_await); | 3314 SET_ALLOW(harmony_async_await); |
3302 SET_ALLOW(harmony_trailing_commas); | 3315 SET_ALLOW(harmony_trailing_commas); |
3303 SET_ALLOW(harmony_class_fields); | 3316 SET_ALLOW(harmony_class_fields); |
3304 #undef SET_ALLOW | 3317 #undef SET_ALLOW |
3305 } | 3318 } |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3803 | 3816 |
3804 | 3817 |
3805 void Parser::ParseOnBackground(ParseInfo* info) { | 3818 void Parser::ParseOnBackground(ParseInfo* info) { |
3806 parsing_on_main_thread_ = false; | 3819 parsing_on_main_thread_ = false; |
3807 | 3820 |
3808 DCHECK(info->literal() == NULL); | 3821 DCHECK(info->literal() == NULL); |
3809 FunctionLiteral* result = NULL; | 3822 FunctionLiteral* result = NULL; |
3810 | 3823 |
3811 ParserLogger logger; | 3824 ParserLogger logger; |
3812 if (produce_cached_parse_data()) log_ = &logger; | 3825 if (produce_cached_parse_data()) log_ = &logger; |
3826 RuntimeCallStats* default_runtime_call_stats = runtime_call_stats_; | |
3827 if (FLAG_runtime_call_stats) { | |
lpy
2016/11/09 16:47:42
How about using FLAG_runtime_stats here? I prefer
Camillo Bruni
2016/11/10 10:49:40
done.
| |
3828 // Create separate runtime stats for background parsing. | |
3829 runtime_call_stats_ = new (zone()) RuntimeCallStats(); | |
3830 } | |
3813 | 3831 |
3814 std::unique_ptr<Utf16CharacterStream> stream; | 3832 std::unique_ptr<Utf16CharacterStream> stream; |
3815 Utf16CharacterStream* stream_ptr; | 3833 Utf16CharacterStream* stream_ptr; |
3816 if (info->character_stream()) { | 3834 if (info->character_stream()) { |
3817 DCHECK(info->source_stream() == nullptr); | 3835 DCHECK(info->source_stream() == nullptr); |
3818 stream_ptr = info->character_stream(); | 3836 stream_ptr = info->character_stream(); |
3819 } else { | 3837 } else { |
3820 DCHECK(info->character_stream() == nullptr); | 3838 DCHECK(info->character_stream() == nullptr); |
3821 stream.reset(ScannerStream::For(info->source_stream(), | 3839 stream.reset(ScannerStream::For(info->source_stream(), |
3822 info->source_stream_encoding())); | 3840 info->source_stream_encoding())); |
(...skipping 19 matching lines...) Expand all Loading... | |
3842 | 3860 |
3843 info->set_literal(result); | 3861 info->set_literal(result); |
3844 | 3862 |
3845 // We cannot internalize on a background thread; a foreground task will take | 3863 // We cannot internalize on a background thread; a foreground task will take |
3846 // care of calling Parser::Internalize just before compilation. | 3864 // care of calling Parser::Internalize just before compilation. |
3847 | 3865 |
3848 if (produce_cached_parse_data()) { | 3866 if (produce_cached_parse_data()) { |
3849 if (result != NULL) *info->cached_data() = logger.GetScriptData(); | 3867 if (result != NULL) *info->cached_data() = logger.GetScriptData(); |
3850 log_ = NULL; | 3868 log_ = NULL; |
3851 } | 3869 } |
3870 if (FLAG_runtime_call_stats) { | |
lpy
2016/11/09 16:47:42
Same here.
Camillo Bruni
2016/11/10 10:49:40
done.
| |
3871 // Copy over the counters from the background thread to the main counters on | |
3872 // the isolate. | |
3873 // TODO(cbruni,lpy): properly attach the runtime stats to the trace for | |
3874 // background parsing. | |
3875 default_runtime_call_stats->Add(runtime_call_stats_); | |
3876 } | |
3852 } | 3877 } |
3853 | 3878 |
3854 Parser::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) { | 3879 Parser::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) { |
3855 return new (zone()) TemplateLiteral(zone(), pos); | 3880 return new (zone()) TemplateLiteral(zone(), pos); |
3856 } | 3881 } |
3857 | 3882 |
3858 | 3883 |
3859 void Parser::AddTemplateSpan(TemplateLiteralState* state, bool tail) { | 3884 void Parser::AddTemplateSpan(TemplateLiteralState* state, bool tail) { |
3860 int pos = scanner()->location().beg_pos; | 3885 int pos = scanner()->location().beg_pos; |
3861 int end = scanner()->location().end_pos - (tail ? 1 : 2); | 3886 int end = scanner()->location().end_pos - (tail ? 1 : 2); |
(...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5419 | 5444 |
5420 return final_loop; | 5445 return final_loop; |
5421 } | 5446 } |
5422 | 5447 |
5423 #undef CHECK_OK | 5448 #undef CHECK_OK |
5424 #undef CHECK_OK_VOID | 5449 #undef CHECK_OK_VOID |
5425 #undef CHECK_FAILED | 5450 #undef CHECK_FAILED |
5426 | 5451 |
5427 } // namespace internal | 5452 } // namespace internal |
5428 } // namespace v8 | 5453 } // namespace v8 |
OLD | NEW |