Skip to content

Commit 7e4e34b

Browse files
camillobruniCommit bot
authored andcommitted
[counters] Use separate counters for background parsing
BUG= Review-Url: https://codereview.chromium.org/2509683002 Cr-Commit-Position: refs/heads/master@{#41047}
1 parent d3231f5 commit 7e4e34b

9 files changed

Lines changed: 78 additions & 42 deletions

File tree

src/counters.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,11 +728,16 @@ class RuntimeCallTimer {
728728
V(Object_DeleteProperty) \
729729
V(OptimizeCode) \
730730
V(ParseArrowFunctionLiteral) \
731+
V(ParseBackgroundArrowFunctionLiteral) \
732+
V(ParseBackgroundFunctionLiteral) \
731733
V(ParseEval) \
732734
V(ParseFunction) \
733735
V(ParseFunctionLiteral) \
734736
V(ParseProgram) \
735737
V(PreParseArrowFunctionLiteral) \
738+
V(PreParseBackgroundArrowFunctionLiteral) \
739+
V(PreParseBackgroundNoVariableResolution) \
740+
V(PreParseBackgroundWithVariableResolution) \
736741
V(PreParseNoVariableResolution) \
737742
V(PreParseWithVariableResolution) \
738743
V(PropertyCallback) \

src/parsing/parser-base.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,16 @@ class ParserBase {
192192

193193
ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit,
194194
v8::Extension* extension, AstValueFactory* ast_value_factory,
195-
RuntimeCallStats* runtime_call_stats)
195+
RuntimeCallStats* runtime_call_stats,
196+
bool parsing_on_main_thread = true)
196197
: scope_state_(nullptr),
197198
function_state_(nullptr),
198199
extension_(extension),
199200
fni_(nullptr),
200201
ast_value_factory_(ast_value_factory),
201202
ast_node_factory_(ast_value_factory),
202203
runtime_call_stats_(runtime_call_stats),
204+
parsing_on_main_thread_(parsing_on_main_thread),
203205
parsing_module_(false),
204206
stack_limit_(stack_limit),
205207
zone_(zone),
@@ -1421,6 +1423,7 @@ class ParserBase {
14211423
AstValueFactory* ast_value_factory_; // Not owned.
14221424
typename Types::Factory ast_node_factory_;
14231425
RuntimeCallStats* runtime_call_stats_;
1426+
bool parsing_on_main_thread_;
14241427
bool parsing_module_;
14251428
uintptr_t stack_limit_;
14261429

@@ -3887,10 +3890,14 @@ template <typename Impl>
38873890
typename ParserBase<Impl>::ExpressionT
38883891
ParserBase<Impl>::ParseArrowFunctionLiteral(
38893892
bool accept_IN, const FormalParametersT& formal_parameters, bool* ok) {
3893+
const RuntimeCallStats::CounterId counters[2][2] = {
3894+
{&RuntimeCallStats::ParseArrowFunctionLiteral,
3895+
&RuntimeCallStats::ParseBackgroundArrowFunctionLiteral},
3896+
{&RuntimeCallStats::PreParseArrowFunctionLiteral,
3897+
&RuntimeCallStats::PreParseBackgroundArrowFunctionLiteral}};
38903898
RuntimeCallTimerScope runtime_timer(
38913899
runtime_call_stats_,
3892-
Impl::IsPreParser() ? &RuntimeCallStats::ParseArrowFunctionLiteral
3893-
: &RuntimeCallStats::PreParseArrowFunctionLiteral);
3900+
counters[Impl::IsPreParser()][parsing_on_main_thread_]);
38943901

38953902
if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) {
38963903
// ASI inserts `;` after arrow parameters if a line terminator is found.

src/parsing/parser.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,8 @@ Expression* Parser::NewV8Intrinsic(const AstRawString* name,
582582
Parser::Parser(ParseInfo* info)
583583
: ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(),
584584
info->extension(), info->ast_value_factory(),
585-
info->isolate()->counters()->runtime_call_stats()),
585+
info->isolate()->counters()->runtime_call_stats(),
586+
true),
586587
scanner_(info->unicode_cache()),
587588
reusable_preparser_(nullptr),
588589
original_scope_(nullptr),
@@ -591,7 +592,6 @@ Parser::Parser(ParseInfo* info)
591592
compile_options_(info->compile_options()),
592593
cached_parse_data_(nullptr),
593594
total_preparse_skipped_(0),
594-
parsing_on_main_thread_(true),
595595
log_(nullptr) {
596596
// Even though we were passed ParseInfo, we should not store it in
597597
// Parser - this makes sure that Isolate is not accidentally accessed via
@@ -664,7 +664,6 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
664664
// It's OK to use the Isolate & counters here, since this function is only
665665
// called in the main thread.
666666
DCHECK(parsing_on_main_thread_);
667-
668667
RuntimeCallTimerScope runtime_timer(
669668
runtime_call_stats_, info->is_eval() ? &RuntimeCallStats::ParseEval
670669
: &RuntimeCallStats::ParseProgram);
@@ -2577,8 +2576,11 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
25772576
bool is_lazy_top_level_function =
25782577
can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables();
25792578

2580-
RuntimeCallTimerScope runtime_timer(runtime_call_stats_,
2581-
&RuntimeCallStats::ParseFunctionLiteral);
2579+
RuntimeCallTimerScope runtime_timer(
2580+
runtime_call_stats_,
2581+
parsing_on_main_thread_
2582+
? &RuntimeCallStats::ParseFunctionLiteral
2583+
: &RuntimeCallStats::ParseBackgroundFunctionLiteral);
25822584

25832585
// Determine whether we can still lazy parse the inner function.
25842586
// The preconditions are:
@@ -2787,9 +2789,9 @@ Parser::LazyParsingResult Parser::SkipFunction(
27872789
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.PreParse");
27882790

27892791
if (reusable_preparser_ == NULL) {
2790-
reusable_preparser_ = new PreParser(zone(), &scanner_, ast_value_factory(),
2791-
&pending_error_handler_,
2792-
runtime_call_stats_, stack_limit_);
2792+
reusable_preparser_ = new PreParser(
2793+
zone(), &scanner_, stack_limit_, ast_value_factory(),
2794+
&pending_error_handler_, runtime_call_stats_, parsing_on_main_thread_);
27932795
#define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
27942796
SET_ALLOW(natives);
27952797
SET_ALLOW(harmony_do_expressions);

src/parsing/parser.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,6 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
11451145
// parsing.
11461146
int use_counts_[v8::Isolate::kUseCounterFeatureCount];
11471147
int total_preparse_skipped_;
1148-
bool parsing_on_main_thread_;
11491148
bool allow_lazy_;
11501149
ParserLogger* log_;
11511150
};

src/parsing/preparser.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,14 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
179179
LanguageMode language_mode, bool* ok) {
180180
// Function ::
181181
// '(' FormalParameterList? ')' '{' FunctionBody '}'
182+
const RuntimeCallStats::CounterId counters[2][2] = {
183+
{&RuntimeCallStats::PreParseWithVariableResolution,
184+
&RuntimeCallStats::PreParseBackgroundWithVariableResolution},
185+
{&RuntimeCallStats::PreParseNoVariableResolution,
186+
&RuntimeCallStats::PreParseBackgroundNoVariableResolution}};
182187
RuntimeCallTimerScope runtime_timer(
183188
runtime_call_stats_,
184-
track_unresolved_variables_
185-
? &RuntimeCallStats::PreParseWithVariableResolution
186-
: &RuntimeCallStats::PreParseNoVariableResolution);
189+
counters[track_unresolved_variables_][parsing_on_main_thread_]);
187190

188191
// Parse function body.
189192
PreParserStatementList body;

src/parsing/preparser.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,11 +838,14 @@ class PreParser : public ParserBase<PreParser> {
838838
kPreParseSuccess
839839
};
840840

841-
PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory,
841+
PreParser(Zone* zone, Scanner* scanner, uintptr_t stack_limit,
842+
AstValueFactory* ast_value_factory,
842843
PendingCompilationErrorHandler* pending_error_handler,
843-
RuntimeCallStats* runtime_call_stats, uintptr_t stack_limit)
844+
RuntimeCallStats* runtime_call_stats,
845+
bool parsing_on_main_thread = true)
844846
: ParserBase<PreParser>(zone, scanner, stack_limit, nullptr,
845-
ast_value_factory, runtime_call_stats),
847+
ast_value_factory, runtime_call_stats,
848+
parsing_on_main_thread),
846849
use_counts_(nullptr),
847850
track_unresolved_variables_(false),
848851
pending_error_handler_(pending_error_handler) {}

test/cctest/test-parsing.cc

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ TEST(ScanHTMLEndComments) {
175175
&zone, CcTest::i_isolate()->heap()->HashSeed());
176176
i::PendingCompilationErrorHandler pending_error_handler;
177177
i::PreParser preparser(
178-
&zone, &scanner, &ast_value_factory, &pending_error_handler,
179-
CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit);
178+
&zone, &scanner, stack_limit, &ast_value_factory,
179+
&pending_error_handler,
180+
CcTest::i_isolate()->counters()->runtime_call_stats());
180181
i::PreParser::PreParseResult result = preparser.PreParseProgram();
181182
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
182183
CHECK(!pending_error_handler.has_pending_error());
@@ -192,8 +193,9 @@ TEST(ScanHTMLEndComments) {
192193
&zone, CcTest::i_isolate()->heap()->HashSeed());
193194
i::PendingCompilationErrorHandler pending_error_handler;
194195
i::PreParser preparser(
195-
&zone, &scanner, &ast_value_factory, &pending_error_handler,
196-
CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit);
196+
&zone, &scanner, stack_limit, &ast_value_factory,
197+
&pending_error_handler,
198+
CcTest::i_isolate()->counters()->runtime_call_stats());
197199
i::PreParser::PreParseResult result = preparser.PreParseProgram();
198200
// Even in the case of a syntax error, kPreParseSuccess is returned.
199201
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
@@ -366,8 +368,9 @@ TEST(StandAlonePreParser) {
366368
&zone, CcTest::i_isolate()->heap()->HashSeed());
367369
i::PendingCompilationErrorHandler pending_error_handler;
368370
i::PreParser preparser(
369-
&zone, &scanner, &ast_value_factory, &pending_error_handler,
370-
CcTest::i_isolate()->counters()->runtime_call_stats(), stack_limit);
371+
&zone, &scanner, stack_limit, &ast_value_factory,
372+
&pending_error_handler,
373+
CcTest::i_isolate()->counters()->runtime_call_stats());
371374
preparser.set_allow_natives(true);
372375
i::PreParser::PreParseResult result = preparser.PreParseProgram();
373376
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
@@ -400,9 +403,9 @@ TEST(StandAlonePreParserNoNatives) {
400403
i::AstValueFactory ast_value_factory(
401404
&zone, CcTest::i_isolate()->heap()->HashSeed());
402405
i::PendingCompilationErrorHandler pending_error_handler;
403-
i::PreParser preparser(
404-
&zone, &scanner, &ast_value_factory, &pending_error_handler,
405-
isolate->counters()->runtime_call_stats(), stack_limit);
406+
i::PreParser preparser(&zone, &scanner, stack_limit, &ast_value_factory,
407+
&pending_error_handler,
408+
isolate->counters()->runtime_call_stats());
406409
i::PreParser::PreParseResult result = preparser.PreParseProgram();
407410
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
408411
CHECK(pending_error_handler.has_pending_error());
@@ -467,10 +470,10 @@ TEST(RegressChromium62639) {
467470
i::AstValueFactory ast_value_factory(&zone,
468471
CcTest::i_isolate()->heap()->HashSeed());
469472
i::PendingCompilationErrorHandler pending_error_handler;
470-
i::PreParser preparser(&zone, &scanner, &ast_value_factory,
471-
&pending_error_handler,
472-
isolate->counters()->runtime_call_stats(),
473-
CcTest::i_isolate()->stack_guard()->real_climit());
473+
i::PreParser preparser(&zone, &scanner,
474+
CcTest::i_isolate()->stack_guard()->real_climit(),
475+
&ast_value_factory, &pending_error_handler,
476+
isolate->counters()->runtime_call_stats());
474477
i::PreParser::PreParseResult result = preparser.PreParseProgram();
475478
// Even in the case of a syntax error, kPreParseSuccess is returned.
476479
CHECK_EQ(i::PreParser::kPreParseSuccess, result);
@@ -543,9 +546,9 @@ TEST(PreParseOverflow) {
543546
i::AstValueFactory ast_value_factory(&zone,
544547
CcTest::i_isolate()->heap()->HashSeed());
545548
i::PendingCompilationErrorHandler pending_error_handler;
546-
i::PreParser preparser(
547-
&zone, &scanner, &ast_value_factory, &pending_error_handler,
548-
isolate->counters()->runtime_call_stats(), stack_limit);
549+
i::PreParser preparser(&zone, &scanner, stack_limit, &ast_value_factory,
550+
&pending_error_handler,
551+
isolate->counters()->runtime_call_stats());
549552
i::PreParser::PreParseResult result = preparser.PreParseProgram();
550553
CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
551554
}
@@ -1327,9 +1330,9 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
13271330
i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
13281331
i::AstValueFactory ast_value_factory(
13291332
&zone, CcTest::i_isolate()->heap()->HashSeed());
1330-
i::PreParser preparser(
1331-
&zone, &scanner, &ast_value_factory, &pending_error_handler,
1332-
isolate->counters()->runtime_call_stats(), stack_limit);
1333+
i::PreParser preparser(&zone, &scanner, stack_limit, &ast_value_factory,
1334+
&pending_error_handler,
1335+
isolate->counters()->runtime_call_stats());
13331336
SetParserFlags(&preparser, flags);
13341337
scanner.Initialize(stream.get());
13351338
i::PreParser::PreParseResult result =

tools/callstats.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,7 @@
13651365
Group.groups.get('ic').entry(),
13661366
Group.groups.get('optimize').entry(),
13671367
Group.groups.get('compile').entry(),
1368+
Group.groups.get('parse-background').entry(),
13681369
Group.groups.get('parse').entry(),
13691370
Group.groups.get('callback').entry(),
13701371
Group.groups.get('api').entry(),
@@ -1554,19 +1555,24 @@
15541555
Group.groups = new Map();
15551556
Group.add = function(name, group) {
15561557
this.groups.set(name, group);
1558+
return group;
15571559
}
15581560
Group.add('total', new Group('Total', /.*Total.*/, '#BBB'));
15591561
Group.add('ic', new Group('IC', /.*IC.*/, "#3366CC"));
15601562
Group.add('optimize', new Group('Optimize',
15611563
/StackGuard|.*Optimize.*|.*Deoptimize.*|Recompile.*/, "#DC3912"));
15621564
Group.add('compile', new Group('Compile', /.*Compile.*/, "#FFAA00"));
1565+
Group.add('parse-background',
1566+
new Group('Parse-Background', /.*ParseBackground.*/, "#af744d"));
15631567
Group.add('parse', new Group('Parse', /.*Parse.*/, "#FF6600"));
15641568
Group.add('callback', new Group('Callback', /.*Callback.*/, "#109618"));
15651569
Group.add('api', new Group('API', /.*API.*/, "#990099"));
15661570
Group.add('gc', new Group('GC', /GC|AllocateInTargetSpace/, "#0099C6"));
15671571
Group.add('javascript', new Group('JavaScript', /JS_Execution/, "#DD4477"));
15681572
Group.add('runtime', new Group('Runtime', /.*/, "#88BB00"));
1569-
Group.add('unclassified', new Group('Unclassified', /.*/, "#000"));
1573+
var group =
1574+
Group.add('unclassified', new Group('Unclassified', /.*/, "#000"));
1575+
group.enabled = false;
15701576

15711577
class GroupedEntry extends Entry {
15721578
constructor(group) {

tools/callstats.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ def read_stats(path, domain, args):
347347
('Group-Optimize',
348348
re.compile("StackGuard|.*Optimize.*|.*Deoptimize.*|Recompile.*")),
349349
('Group-Compile', re.compile(".*Compile.*")),
350+
('Group-ParseBackground', re.compile(".*ParseBackground.*")),
350351
('Group-Parse', re.compile(".*Parse.*")),
351352
('Group-Callback', re.compile(".*Callback.*")),
352353
('Group-API', re.compile(".*API.*")),
@@ -385,12 +386,19 @@ def read_stats(path, domain, args):
385386
entries[group_name]['count'] += count
386387
break
387388
# Calculate the V8-Total (all groups except Callback)
388-
total_v8 = { 'time': 0, 'count': 0 }
389+
group_data = { 'time': 0, 'count': 0 }
389390
for group_name, regexp in groups:
390391
if group_name == 'Group-Callback': continue
391-
total_v8['time'] += entries[group_name]['time']
392-
total_v8['count'] += entries[group_name]['count']
393-
entries['Group-Total-V8'] = total_v8
392+
group_data['time'] += entries[group_name]['time']
393+
group_data['count'] += entries[group_name]['count']
394+
entries['Group-Total-V8'] = group_data
395+
# Calculate the Parse-Total group
396+
group_data = { 'time': 0, 'count': 0 }
397+
for group_name, regexp in groups:
398+
if !group_name.startswith('Group-Parse'): continue
399+
group_data['time'] += entries[group_name]['time']
400+
group_data['count'] += entries[group_name]['count']
401+
entries['Group-Parse-Total'] = group_data
394402
# Append the sums as single entries to domain.
395403
for key in entries:
396404
if key not in domain: domain[key] = { 'time_list': [], 'count_list': [] }

0 commit comments

Comments
 (0)