Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: src/parsing/parser.cc

Issue 2509683002: [counters] Use separate counters for background parsing (Closed)
Patch Set: using const arrays instead of two-level ternary syntax. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 *ok = false; 575 *ok = false;
576 return nullptr; 576 return nullptr;
577 } 577 }
578 578
579 return factory()->NewCallRuntime(context_index, args, pos); 579 return factory()->NewCallRuntime(context_index, args, pos);
580 } 580 }
581 581
582 Parser::Parser(ParseInfo* info) 582 Parser::Parser(ParseInfo* info)
583 : ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(), 583 : ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(),
584 info->extension(), info->ast_value_factory(), 584 info->extension(), info->ast_value_factory(),
585 info->isolate()->counters()->runtime_call_stats()), 585 info->isolate()->counters()->runtime_call_stats(),
586 true),
586 scanner_(info->unicode_cache()), 587 scanner_(info->unicode_cache()),
587 reusable_preparser_(nullptr), 588 reusable_preparser_(nullptr),
588 original_scope_(nullptr), 589 original_scope_(nullptr),
589 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. 590 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly.
590 target_stack_(nullptr), 591 target_stack_(nullptr),
591 compile_options_(info->compile_options()), 592 compile_options_(info->compile_options()),
592 cached_parse_data_(nullptr), 593 cached_parse_data_(nullptr),
593 total_preparse_skipped_(0), 594 total_preparse_skipped_(0),
594 parsing_on_main_thread_(true),
595 log_(nullptr) { 595 log_(nullptr) {
596 // Even though we were passed ParseInfo, we should not store it in 596 // Even though we were passed ParseInfo, we should not store it in
597 // Parser - this makes sure that Isolate is not accidentally accessed via 597 // Parser - this makes sure that Isolate is not accidentally accessed via
598 // ParseInfo during background parsing. 598 // ParseInfo during background parsing.
599 DCHECK(!info->script().is_null() || info->source_stream() != nullptr || 599 DCHECK(!info->script().is_null() || info->source_stream() != nullptr ||
600 info->character_stream() != nullptr); 600 info->character_stream() != nullptr);
601 // Determine if functions can be lazily compiled. This is necessary to 601 // Determine if functions can be lazily compiled. This is necessary to
602 // allow some of our builtin JS files to be lazily compiled. These 602 // allow some of our builtin JS files to be lazily compiled. These
603 // builtins cannot be handled lazily by the parser, since we have to know 603 // builtins cannot be handled lazily by the parser, since we have to know
604 // if a function uses the special natives syntax, which is something the 604 // if a function uses the special natives syntax, which is something the
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 original_scope_ = scope; 657 original_scope_ = scope;
658 } 658 }
659 659
660 FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { 660 FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
661 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, 661 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here,
662 // see comment for HistogramTimerScope class. 662 // see comment for HistogramTimerScope class.
663 663
664 // It's OK to use the Isolate & counters here, since this function is only 664 // It's OK to use the Isolate & counters here, since this function is only
665 // called in the main thread. 665 // called in the main thread.
666 DCHECK(parsing_on_main_thread_); 666 DCHECK(parsing_on_main_thread_);
667
668 RuntimeCallTimerScope runtime_timer( 667 RuntimeCallTimerScope runtime_timer(
669 runtime_call_stats_, info->is_eval() ? &RuntimeCallStats::ParseEval 668 runtime_call_stats_, info->is_eval() ? &RuntimeCallStats::ParseEval
670 : &RuntimeCallStats::ParseProgram); 669 : &RuntimeCallStats::ParseProgram);
671 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseProgram"); 670 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseProgram");
672 Handle<String> source(String::cast(info->script()->source())); 671 Handle<String> source(String::cast(info->script()->source()));
673 isolate->counters()->total_parse_size()->Increment(source->length()); 672 isolate->counters()->total_parse_size()->Increment(source->length());
674 base::ElapsedTimer timer; 673 base::ElapsedTimer timer;
675 if (FLAG_trace_parse) { 674 if (FLAG_trace_parse) {
676 timer.Start(); 675 timer.Start();
677 } 676 }
(...skipping 1892 matching lines...) Expand 10 before | Expand all | Expand 10 after
2570 DCHECK_IMPLIES(parse_lazily(), FLAG_lazy); 2569 DCHECK_IMPLIES(parse_lazily(), FLAG_lazy);
2571 DCHECK_IMPLIES(parse_lazily(), allow_lazy_); 2570 DCHECK_IMPLIES(parse_lazily(), allow_lazy_);
2572 DCHECK_IMPLIES(parse_lazily(), extension_ == nullptr); 2571 DCHECK_IMPLIES(parse_lazily(), extension_ == nullptr);
2573 2572
2574 bool can_preparse = parse_lazily() && 2573 bool can_preparse = parse_lazily() &&
2575 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; 2574 eager_compile_hint == FunctionLiteral::kShouldLazyCompile;
2576 2575
2577 bool is_lazy_top_level_function = 2576 bool is_lazy_top_level_function =
2578 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); 2577 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables();
2579 2578
2580 RuntimeCallTimerScope runtime_timer(runtime_call_stats_, 2579 RuntimeCallTimerScope runtime_timer(
2581 &RuntimeCallStats::ParseFunctionLiteral); 2580 runtime_call_stats_,
2581 parsing_on_main_thread_
2582 ? &RuntimeCallStats::ParseFunctionLiteral
2583 : &RuntimeCallStats::ParseBackgroundFunctionLiteral);
2582 2584
2583 // Determine whether we can still lazy parse the inner function. 2585 // Determine whether we can still lazy parse the inner function.
2584 // The preconditions are: 2586 // The preconditions are:
2585 // - Lazy compilation has to be enabled. 2587 // - Lazy compilation has to be enabled.
2586 // - Neither V8 natives nor native function declarations can be allowed, 2588 // - Neither V8 natives nor native function declarations can be allowed,
2587 // since parsing one would retroactively force the function to be 2589 // since parsing one would retroactively force the function to be
2588 // eagerly compiled. 2590 // eagerly compiled.
2589 // - The invoker of this parser can't depend on the AST being eagerly 2591 // - 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 2592 // built (either because the function is about to be compiled, or
2591 // because the AST is going to be inspected for some reason). 2593 // because the AST is going to be inspected for some reason).
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
2780 return kLazyParsingComplete; 2782 return kLazyParsingComplete;
2781 } 2783 }
2782 cached_parse_data_->Reject(); 2784 cached_parse_data_->Reject();
2783 } 2785 }
2784 2786
2785 // With no cached data, we partially parse the function, without building an 2787 // With no cached data, we partially parse the function, without building an
2786 // AST. This gathers the data needed to build a lazy function. 2788 // AST. This gathers the data needed to build a lazy function.
2787 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse"); 2789 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse");
2788 2790
2789 if (reusable_preparser_ == NULL) { 2791 if (reusable_preparser_ == NULL) {
2790 reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(), 2792 reusable_preparser_ = new PreParser(
2791 &pending_error_handler_, 2793 zone(), &scanner_, stack_limit_, ast_value_factory(),
2792 runtime_call_stats_, stack_limit_); 2794 &pending_error_handler_, runtime_call_stats_, parsing_on_main_thread_);
2793 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); 2795 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
2794 SET_ALLOW(natives); 2796 SET_ALLOW(natives);
2795 SET_ALLOW(harmony_do_expressions); 2797 SET_ALLOW(harmony_do_expressions);
2796 SET_ALLOW(harmony_function_sent); 2798 SET_ALLOW(harmony_function_sent);
2797 SET_ALLOW(harmony_async_await); 2799 SET_ALLOW(harmony_async_await);
2798 SET_ALLOW(harmony_trailing_commas); 2800 SET_ALLOW(harmony_trailing_commas);
2799 SET_ALLOW(harmony_class_fields); 2801 SET_ALLOW(harmony_class_fields);
2800 #undef SET_ALLOW 2802 #undef SET_ALLOW
2801 } 2803 }
2802 // Aborting inner function preparsing would leave scopes in an inconsistent 2804 // Aborting inner function preparsing would leave scopes in an inconsistent
(...skipping 2632 matching lines...) Expand 10 before | Expand all | Expand 10 after
5435 5437
5436 return final_loop; 5438 return final_loop;
5437 } 5439 }
5438 5440
5439 #undef CHECK_OK 5441 #undef CHECK_OK
5440 #undef CHECK_OK_VOID 5442 #undef CHECK_OK_VOID
5441 #undef CHECK_FAILED 5443 #undef CHECK_FAILED
5442 5444
5443 } // namespace internal 5445 } // namespace internal
5444 } // namespace v8 5446 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698