Commit c60faf2a authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[counters] Convert RuntimeCallTimerScopes to use kThreadSpecific

Converts and uses of RuntimeCallTimerScopes that switch the counter
based on the thread, to use kThreadSpecific and remove the counter
selection.

Also moves RuntimeCallTimerScope::CounterMode to RuntimeCallStats,
since now CorrectCurrentCounterId also takes it as a parameter.

Bug: v8:10006
Change-Id: I14a503e0b83bb69c071f9665956de094bb33c0ba
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1928864Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65141}
parent af90964b
...@@ -548,10 +548,8 @@ void DeclarationScope::HoistSloppyBlockFunctions(AstNodeFactory* factory) { ...@@ -548,10 +548,8 @@ void DeclarationScope::HoistSloppyBlockFunctions(AstNodeFactory* factory) {
bool DeclarationScope::Analyze(ParseInfo* info) { bool DeclarationScope::Analyze(ParseInfo* info) {
RuntimeCallTimerScope runtimeTimer( RuntimeCallTimerScope runtimeTimer(
info->runtime_call_stats(), info->runtime_call_stats(), RuntimeCallCounterId::kCompileScopeAnalysis,
info->on_background_thread() RuntimeCallStats::kThreadSpecific);
? RuntimeCallCounterId::kCompileBackgroundScopeAnalysis
: RuntimeCallCounterId::kCompileScopeAnalysis);
DCHECK_NOT_NULL(info->literal()); DCHECK_NOT_NULL(info->literal());
DeclarationScope* scope = info->literal()->scope(); DeclarationScope* scope = info->literal()->scope();
......
...@@ -1100,9 +1100,9 @@ BackgroundCompileTask::~BackgroundCompileTask() = default; ...@@ -1100,9 +1100,9 @@ BackgroundCompileTask::~BackgroundCompileTask() = default;
namespace { namespace {
// A scope object that ensures a parse info's runtime call stats, stack limit // A scope object that ensures a parse info's runtime call stats and stack limit
// and on_background_thread fields is set correctly during worker-thread // are set correctly during worker-thread compile, and restores it after going
// compile, and restores it after going out of scope. // out of scope.
class OffThreadParseInfoScope { class OffThreadParseInfoScope {
public: public:
OffThreadParseInfoScope( OffThreadParseInfoScope(
...@@ -1112,7 +1112,6 @@ class OffThreadParseInfoScope { ...@@ -1112,7 +1112,6 @@ class OffThreadParseInfoScope {
original_runtime_call_stats_(parse_info_->runtime_call_stats()), original_runtime_call_stats_(parse_info_->runtime_call_stats()),
original_stack_limit_(parse_info_->stack_limit()), original_stack_limit_(parse_info_->stack_limit()),
worker_thread_scope_(worker_thread_runtime_stats) { worker_thread_scope_(worker_thread_runtime_stats) {
parse_info_->set_on_background_thread(true);
parse_info_->set_runtime_call_stats(worker_thread_scope_.Get()); parse_info_->set_runtime_call_stats(worker_thread_scope_.Get());
parse_info_->set_stack_limit(GetCurrentStackPosition() - stack_size * KB); parse_info_->set_stack_limit(GetCurrentStackPosition() - stack_size * KB);
} }
...@@ -1120,7 +1119,6 @@ class OffThreadParseInfoScope { ...@@ -1120,7 +1119,6 @@ class OffThreadParseInfoScope {
~OffThreadParseInfoScope() { ~OffThreadParseInfoScope() {
parse_info_->set_stack_limit(original_stack_limit_); parse_info_->set_stack_limit(original_stack_limit_);
parse_info_->set_runtime_call_stats(original_runtime_call_stats_); parse_info_->set_runtime_call_stats(original_runtime_call_stats_);
parse_info_->set_on_background_thread(false);
} }
private: private:
...@@ -1170,11 +1168,9 @@ void BackgroundCompileTask::Run() { ...@@ -1170,11 +1168,9 @@ void BackgroundCompileTask::Run() {
bool Compiler::Analyze(ParseInfo* parse_info) { bool Compiler::Analyze(ParseInfo* parse_info) {
DCHECK_NOT_NULL(parse_info->literal()); DCHECK_NOT_NULL(parse_info->literal());
RuntimeCallTimerScope runtimeTimer( RuntimeCallTimerScope runtimeTimer(parse_info->runtime_call_stats(),
parse_info->runtime_call_stats(), RuntimeCallCounterId::kCompileAnalyse,
parse_info->on_background_thread() RuntimeCallStats::kThreadSpecific);
? RuntimeCallCounterId::kCompileBackgroundAnalyse
: RuntimeCallCounterId::kCompileAnalyse);
if (!Rewriter::Rewrite(parse_info)) return false; if (!Rewriter::Rewrite(parse_info)) return false;
if (!DeclarationScope::Analyze(parse_info)) return false; if (!DeclarationScope::Analyze(parse_info)) return false;
return true; return true;
......
...@@ -153,9 +153,8 @@ InterpreterCompilationJob::InterpreterCompilationJob( ...@@ -153,9 +153,8 @@ InterpreterCompilationJob::InterpreterCompilationJob(
InterpreterCompilationJob::Status InterpreterCompilationJob::ExecuteJobImpl() { InterpreterCompilationJob::Status InterpreterCompilationJob::ExecuteJobImpl() {
RuntimeCallTimerScope runtimeTimerScope( RuntimeCallTimerScope runtimeTimerScope(
parse_info()->runtime_call_stats(), parse_info()->runtime_call_stats(),
parse_info()->on_background_thread() RuntimeCallCounterId::kCompileIgnition,
? RuntimeCallCounterId::kCompileBackgroundIgnition RuntimeCallStats::kThreadSpecific);
: RuntimeCallCounterId::kCompileIgnition);
// TODO(lpy): add support for background compilation RCS trace. // TODO(lpy): add support for background compilation RCS trace.
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileIgnition"); TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileIgnition");
......
...@@ -515,9 +515,14 @@ void RuntimeCallStats::Add(RuntimeCallStats* other) { ...@@ -515,9 +515,14 @@ void RuntimeCallStats::Add(RuntimeCallStats* other) {
} }
// static // static
void RuntimeCallStats::CorrectCurrentCounterId( void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallCounterId counter_id,
RuntimeCallCounterId counter_id) { CounterMode mode) {
DCHECK(IsCalledOnTheSameThread()); DCHECK(IsCalledOnTheSameThread());
if (mode == RuntimeCallStats::CounterMode::kThreadSpecific) {
counter_id = CounterIdForThread(counter_id);
}
DCHECK(IsCounterAppropriateForThread(counter_id));
RuntimeCallTimer* timer = current_timer(); RuntimeCallTimer* timer = current_timer();
if (timer == nullptr) return; if (timer == nullptr) return;
RuntimeCallCounter* counter = GetCounter(counter_id); RuntimeCallCounter* counter = GetCounter(counter_id);
......
...@@ -1068,6 +1068,11 @@ class RuntimeCallStats final { ...@@ -1068,6 +1068,11 @@ class RuntimeCallStats final {
public: public:
enum ThreadType { kMainIsolateThread, kWorkerThread }; enum ThreadType { kMainIsolateThread, kWorkerThread };
// If kExact is chosen the counter will be use as given. With kThreadSpecific,
// if the RuntimeCallStats was created for a worker thread, then the
// background specific version of the counter will be used instead.
enum CounterMode { kExact, kThreadSpecific };
explicit V8_EXPORT_PRIVATE RuntimeCallStats(ThreadType thread_type); explicit V8_EXPORT_PRIVATE RuntimeCallStats(ThreadType thread_type);
// Starting measuring the time for a function. This will establish the // Starting measuring the time for a function. This will establish the
...@@ -1083,7 +1088,7 @@ class RuntimeCallStats final { ...@@ -1083,7 +1088,7 @@ class RuntimeCallStats final {
// Set counter id for the innermost measurement. It can be used to refine // Set counter id for the innermost measurement. It can be used to refine
// event kind when a runtime entry counter is too generic. // event kind when a runtime entry counter is too generic.
V8_EXPORT_PRIVATE void CorrectCurrentCounterId( V8_EXPORT_PRIVATE void CorrectCurrentCounterId(
RuntimeCallCounterId counter_id); RuntimeCallCounterId counter_id, CounterMode mode = kExact);
V8_EXPORT_PRIVATE void Reset(); V8_EXPORT_PRIVATE void Reset();
// Add all entries from another stats object. // Add all entries from another stats object.
...@@ -1198,22 +1203,18 @@ class WorkerThreadRuntimeCallStatsScope final { ...@@ -1198,22 +1203,18 @@ class WorkerThreadRuntimeCallStatsScope final {
// the time of C++ scope. // the time of C++ scope.
class RuntimeCallTimerScope { class RuntimeCallTimerScope {
public: public:
// If kExact is chosen the counter will be use as given. With kThreadSpecific,
// if the RuntimeCallStats was created for a worker thread, then the
// background specific version of the counter will be used instead.
enum CounterMode { kExact, kThreadSpecific };
inline RuntimeCallTimerScope(Isolate* isolate, inline RuntimeCallTimerScope(Isolate* isolate,
RuntimeCallCounterId counter_id); RuntimeCallCounterId counter_id);
inline RuntimeCallTimerScope(RuntimeCallStats* stats, inline RuntimeCallTimerScope(RuntimeCallStats* stats,
RuntimeCallCounterId counter_id, RuntimeCallCounterId counter_id,
CounterMode mode = CounterMode::kExact) { RuntimeCallStats::CounterMode mode =
RuntimeCallStats::CounterMode::kExact) {
if (V8_LIKELY(!TracingFlags::is_runtime_stats_enabled() || if (V8_LIKELY(!TracingFlags::is_runtime_stats_enabled() ||
stats == nullptr)) { stats == nullptr)) {
return; return;
} }
stats_ = stats; stats_ = stats;
if (mode == CounterMode::kThreadSpecific) { if (mode == RuntimeCallStats::CounterMode::kThreadSpecific) {
counter_id = stats->CounterIdForThread(counter_id); counter_id = stats->CounterIdForThread(counter_id);
} }
......
...@@ -86,8 +86,6 @@ class V8_EXPORT_PRIVATE ParseInfo { ...@@ -86,8 +86,6 @@ class V8_EXPORT_PRIVATE ParseInfo {
FLAG_ACCESSOR(kCoverageEnabled, coverage_enabled, set_coverage_enabled) FLAG_ACCESSOR(kCoverageEnabled, coverage_enabled, set_coverage_enabled)
FLAG_ACCESSOR(kBlockCoverageEnabled, block_coverage_enabled, FLAG_ACCESSOR(kBlockCoverageEnabled, block_coverage_enabled,
set_block_coverage_enabled) set_block_coverage_enabled)
FLAG_ACCESSOR(kOnBackgroundThread, on_background_thread,
set_on_background_thread)
FLAG_ACCESSOR(kAllowEvalCache, allow_eval_cache, set_allow_eval_cache) FLAG_ACCESSOR(kAllowEvalCache, allow_eval_cache, set_allow_eval_cache)
FLAG_ACCESSOR(kRequiresInstanceMembersInitializer, FLAG_ACCESSOR(kRequiresInstanceMembersInitializer,
requires_instance_members_initializer, requires_instance_members_initializer,
...@@ -306,25 +304,24 @@ class V8_EXPORT_PRIVATE ParseInfo { ...@@ -306,25 +304,24 @@ class V8_EXPORT_PRIVATE ParseInfo {
kCoverageEnabled = 1u << 10, kCoverageEnabled = 1u << 10,
kBlockCoverageEnabled = 1u << 11, kBlockCoverageEnabled = 1u << 11,
kIsAsmWasmBroken = 1u << 12, kIsAsmWasmBroken = 1u << 12,
kOnBackgroundThread = 1u << 13, kAllowEvalCache = 1u << 13,
kAllowEvalCache = 1u << 14, kRequiresInstanceMembersInitializer = 1u << 14,
kRequiresInstanceMembersInitializer = 1u << 15, kContainsAsmModule = 1u << 15,
kContainsAsmModule = 1u << 16, kMightAlwaysOpt = 1u << 16,
kMightAlwaysOpt = 1u << 17, kAllowLazyCompile = 1u << 17,
kAllowLazyCompile = 1u << 18, kAllowNativeSyntax = 1u << 18,
kAllowNativeSyntax = 1u << 19, kAllowHarmonyPublicFields = 1u << 19,
kAllowHarmonyPublicFields = 1u << 20, kAllowHarmonyStaticFields = 1u << 20,
kAllowHarmonyStaticFields = 1u << 21, kAllowHarmonyDynamicImport = 1u << 21,
kAllowHarmonyDynamicImport = 1u << 22, kAllowHarmonyImportMeta = 1u << 22,
kAllowHarmonyImportMeta = 1u << 23, kAllowHarmonyOptionalChaining = 1u << 23,
kAllowHarmonyOptionalChaining = 1u << 24, kAllowHarmonyPrivateFields = 1u << 24,
kAllowHarmonyPrivateFields = 1u << 25, kAllowHarmonyPrivateMethods = 1u << 25,
kAllowHarmonyPrivateMethods = 1u << 26, kIsOneshotIIFE = 1u << 26,
kIsOneshotIIFE = 1u << 27, kCollectSourcePositions = 1u << 27,
kCollectSourcePositions = 1u << 28, kAllowHarmonyNullish = 1u << 28,
kAllowHarmonyNullish = 1u << 29, kAllowHarmonyTopLevelAwait = 1u << 29,
kAllowHarmonyTopLevelAwait = 1u << 30, kREPLMode = 1u << 30,
kREPLMode = 1u << 31,
}; };
//------------- Inputs to parsing and scope analysis ----------------------- //------------- Inputs to parsing and scope analysis -----------------------
......
...@@ -4200,14 +4200,12 @@ template <typename Impl> ...@@ -4200,14 +4200,12 @@ template <typename Impl>
typename ParserBase<Impl>::ExpressionT typename ParserBase<Impl>::ExpressionT
ParserBase<Impl>::ParseArrowFunctionLiteral( ParserBase<Impl>::ParseArrowFunctionLiteral(
const FormalParametersT& formal_parameters) { const FormalParametersT& formal_parameters) {
const RuntimeCallCounterId counters[2][2] = { const RuntimeCallCounterId counters[2] = {
{RuntimeCallCounterId::kParseBackgroundArrowFunctionLiteral, RuntimeCallCounterId::kParseArrowFunctionLiteral,
RuntimeCallCounterId::kParseArrowFunctionLiteral}, RuntimeCallCounterId::kPreParseArrowFunctionLiteral};
{RuntimeCallCounterId::kPreParseBackgroundArrowFunctionLiteral, RuntimeCallTimerScope runtime_timer(runtime_call_stats_,
RuntimeCallCounterId::kPreParseArrowFunctionLiteral}}; counters[Impl::IsPreParser()],
RuntimeCallTimerScope runtime_timer( RuntimeCallStats::kThreadSpecific);
runtime_call_stats_,
counters[Impl::IsPreParser()][parsing_on_main_thread_]);
base::ElapsedTimer timer; base::ElapsedTimer timer;
if (V8_UNLIKELY(FLAG_log_function_events)) timer.Start(); if (V8_UNLIKELY(FLAG_log_function_events)) timer.Start();
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "src/codegen/bailout-reason.h" #include "src/codegen/bailout-reason.h"
#include "src/common/message-template.h" #include "src/common/message-template.h"
#include "src/compiler-dispatcher/compiler-dispatcher.h" #include "src/compiler-dispatcher/compiler-dispatcher.h"
#include "src/logging/counters.h"
#include "src/logging/log.h" #include "src/logging/log.h"
#include "src/numbers/conversions-inl.h" #include "src/numbers/conversions-inl.h"
#include "src/objects/scope-info.h" #include "src/objects/scope-info.h"
...@@ -2333,10 +2334,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -2333,10 +2334,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
const bool is_lazy_inner_function = is_lazy && !is_top_level; const bool is_lazy_inner_function = is_lazy && !is_top_level;
RuntimeCallTimerScope runtime_timer( RuntimeCallTimerScope runtime_timer(
runtime_call_stats_, runtime_call_stats_, RuntimeCallCounterId::kParseFunctionLiteral,
parsing_on_main_thread_ RuntimeCallStats::kThreadSpecific);
? RuntimeCallCounterId::kParseFunctionLiteral
: RuntimeCallCounterId::kParseBackgroundFunctionLiteral);
base::ElapsedTimer timer; base::ElapsedTimer timer;
if (V8_UNLIKELY(FLAG_log_function_events)) timer.Start(); if (V8_UNLIKELY(FLAG_log_function_events)) timer.Start();
...@@ -2429,12 +2428,10 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -2429,12 +2428,10 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
} }
if (V8_UNLIKELY(TracingFlags::is_runtime_stats_enabled()) && if (V8_UNLIKELY(TracingFlags::is_runtime_stats_enabled()) &&
did_preparse_successfully) { did_preparse_successfully) {
const RuntimeCallCounterId counters[2] = {
RuntimeCallCounterId::kPreParseBackgroundWithVariableResolution,
RuntimeCallCounterId::kPreParseWithVariableResolution};
if (runtime_call_stats_) { if (runtime_call_stats_) {
runtime_call_stats_->CorrectCurrentCounterId( runtime_call_stats_->CorrectCurrentCounterId(
counters[parsing_on_main_thread_]); RuntimeCallCounterId::kPreParseWithVariableResolution,
RuntimeCallStats::kThreadSpecific);
} }
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "src/base/logging.h" #include "src/base/logging.h"
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/logging/counters.h"
#include "src/numbers/conversions-inl.h" #include "src/numbers/conversions-inl.h"
#include "src/numbers/conversions.h" #include "src/numbers/conversions.h"
#include "src/parsing/parser-base.h" #include "src/parsing/parser-base.h"
...@@ -276,11 +277,10 @@ PreParser::Expression PreParser::ParseFunctionLiteral( ...@@ -276,11 +277,10 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
DCHECK_NE(FunctionSyntaxKind::kWrapped, function_syntax_kind); DCHECK_NE(FunctionSyntaxKind::kWrapped, function_syntax_kind);
// Function :: // Function ::
// '(' FormalParameterList? ')' '{' FunctionBody '}' // '(' FormalParameterList? ')' '{' FunctionBody '}'
const RuntimeCallCounterId counters[2] = { RuntimeCallTimerScope runtime_timer(
RuntimeCallCounterId::kPreParseBackgroundWithVariableResolution, runtime_call_stats_,
RuntimeCallCounterId::kPreParseWithVariableResolution}; RuntimeCallCounterId::kPreParseWithVariableResolution,
RuntimeCallTimerScope runtime_timer(runtime_call_stats_, RuntimeCallStats::kThreadSpecific);
counters[parsing_on_main_thread_]);
base::ElapsedTimer timer; base::ElapsedTimer timer;
if (V8_UNLIKELY(FLAG_log_function_events)) timer.Start(); if (V8_UNLIKELY(FLAG_log_function_events)) timer.Start();
......
...@@ -366,9 +366,8 @@ bool Rewriter::Rewrite(ParseInfo* info) { ...@@ -366,9 +366,8 @@ bool Rewriter::Rewrite(ParseInfo* info) {
RuntimeCallTimerScope runtimeTimer( RuntimeCallTimerScope runtimeTimer(
info->runtime_call_stats(), info->runtime_call_stats(),
info->on_background_thread() RuntimeCallCounterId::kCompileRewriteReturnResult,
? RuntimeCallCounterId::kCompileBackgroundRewriteReturnResult RuntimeCallStats::kThreadSpecific);
: RuntimeCallCounterId::kCompileRewriteReturnResult);
FunctionLiteral* function = info->literal(); FunctionLiteral* function = info->literal();
DCHECK_NOT_NULL(function); DCHECK_NOT_NULL(function);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment