Fix runtime_call_stats for background parsing.

BUG=v8:6093

Change-Id: Ia14f6200adbe6c557f9b899e67f2d96bf76f3a44
Reviewed-on: https://chromium-review.googlesource.com/494590
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Commit-Queue: Wiktor Garbacz <wiktorg@google.com>
Cr-Commit-Position: refs/heads/master@{#45093}
This commit is contained in:
Wiktor Garbacz 2017-05-03 19:53:55 +02:00 committed by Commit Bot
parent 0fad007a98
commit ca8b120f97
6 changed files with 30 additions and 11 deletions

View File

@ -2473,6 +2473,7 @@ MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context,
source->parser->ReportErrors(isolate, script);
}
source->parser->UpdateStatistics(isolate, script);
source->info->UpdateStatisticsAfterBackgroundParse(isolate);
i::DeferredHandleScope deferred_handle_scope(isolate);
{

View File

@ -37,6 +37,9 @@ BackgroundParsingTask::BackgroundParsingTask(
info->set_unicode_cache(&source_->unicode_cache);
info->set_compile_options(options);
info->set_allow_lazy_parsing();
if (V8_UNLIKELY(FLAG_runtime_stats)) {
info->set_runtime_call_stats(new (info->zone()) RuntimeCallStats());
}
source_->info->set_cached_data(&script_data_);
// Parser needs to stay alive for finalizing the parsing on the main

View File

@ -90,6 +90,10 @@ CompilerDispatcherJob::CompilerDispatcherJob(
parse_info_->set_language_mode(language_mode);
parse_info_->set_function_literal_id(function_literal_id);
parse_info_->set_ast_string_constants(ast_string_constants);
if (V8_UNLIKELY(FLAG_runtime_stats)) {
parse_info_->set_runtime_call_stats(new (parse_info_->zone())
RuntimeCallStats());
}
parse_info_->set_native(native);
parse_info_->set_module(module);
@ -266,6 +270,10 @@ void CompilerDispatcherJob::PrepareToParseOnMainThread() {
parse_info_->set_unicode_cache(unicode_cache_.get());
parse_info_->set_language_mode(shared_->language_mode());
parse_info_->set_function_literal_id(shared_->function_literal_id());
if (V8_UNLIKELY(FLAG_runtime_stats)) {
parse_info_->set_runtime_call_stats(new (parse_info_->zone())
RuntimeCallStats());
}
parser_.reset(new Parser(parse_info_.get()));
MaybeHandle<ScopeInfo> outer_scope_info;
@ -334,6 +342,7 @@ bool CompilerDispatcherJob::FinalizeParsingOnMainThread() {
status_ = CompileJobStatus::kReadyToAnalyze;
}
parser_->UpdateStatistics(isolate_, script);
parse_info_->UpdateStatisticsAfterBackgroundParse(isolate_);
DeferredHandleScope scope(isolate_);
{

View File

@ -164,6 +164,20 @@ void ParseInfo::InitFromIsolate(Isolate* isolate) {
set_ast_string_constants(isolate->ast_string_constants());
}
void ParseInfo::UpdateStatisticsAfterBackgroundParse(Isolate* isolate) {
// Copy over the counters from the background thread to the main counters on
// the isolate.
RuntimeCallStats* main_call_stats = isolate->counters()->runtime_call_stats();
if (FLAG_runtime_stats ==
v8::tracing::TracingCategoryObserver::ENABLED_BY_NATIVE) {
DCHECK_NE(main_call_stats, runtime_call_stats());
DCHECK_NOT_NULL(main_call_stats);
DCHECK_NOT_NULL(runtime_call_stats());
main_call_stats->Add(runtime_call_stats());
}
set_runtime_call_stats(main_call_stats);
}
void ParseInfo::ParseFinished(std::unique_ptr<ParseInfo> info) {
if (info->literal()) {
base::LockGuard<base::Mutex> access_child_infos(&child_infos_mutex_);

View File

@ -246,6 +246,8 @@ class V8_EXPORT_PRIVATE ParseInfo : public CompileJobFinishCallback {
}
}
void UpdateStatisticsAfterBackgroundParse(Isolate* isolate);
// The key of the map is the FunctionLiteral's start_position
std::map<int, ParseInfo*> child_infos() const;

View File

@ -3519,13 +3519,6 @@ void Parser::UpdateStatistics(Isolate* isolate, Handle<Script> script) {
}
isolate->counters()->total_preparse_skipped()->Increment(
total_preparse_skipped_);
if (!parsing_on_main_thread_ &&
FLAG_runtime_stats ==
v8::tracing::TracingCategoryObserver::ENABLED_BY_NATIVE) {
// Copy over the counters from the background thread to the main counters on
// the isolate.
isolate->counters()->runtime_call_stats()->Add(runtime_call_stats_);
}
}
void Parser::ParseOnBackground(ParseInfo* info) {
@ -3542,10 +3535,6 @@ void Parser::ParseOnBackground(ParseInfo* info) {
compile_options_ = ScriptCompiler::kNoCompileOptions;
}
}
if (FLAG_runtime_stats) {
// Create separate runtime stats for background parsing.
runtime_call_stats_ = new (zone()) RuntimeCallStats();
}
std::unique_ptr<Utf16CharacterStream> stream;
Utf16CharacterStream* stream_ptr;
@ -5231,6 +5220,7 @@ void Parser::StitchAst(ParseInfo* top_level_parse_info, Isolate* isolate) {
// If the parse task failed the function will be treated as lazy function
// and reparsed before it gets called
if (!result) continue;
result->UpdateStatisticsAfterBackgroundParse(isolate);
if (!result->literal()) continue;
while ((*it)->start_position() != child_info.first) {
if (++it == literals_to_stitch_.end()) {