Commit 51727469 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[parser] Report use counts with off-thread finalization

We forgot to add statistic reporting for off-thread finalization -- this
needs to be done during the main-thread fix-ups since it can call
embedder callbacks.

Change-Id: I3959a1512166cbdea028799c771f733a6c8a6163
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3217198
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77358}
parent 695b5d31
......@@ -1636,6 +1636,7 @@ void BackgroundCompileTask::Run() {
&isolate, isolate.factory()->empty_string(), kNullMaybeHandle,
ScriptOriginOptions(false, false, false, info_->flags().is_module()));
parser_->UpdateStatistics(script, use_counts_, &total_preparse_skipped_);
parser_->HandleSourceURLComments(&isolate, script);
MaybeHandle<SharedFunctionInfo> maybe_result;
......@@ -3150,6 +3151,15 @@ Compiler::GetSharedFunctionInfoForStreamedScript(
scripts = WeakArrayList::Append(isolate, scripts,
MaybeObjectHandle::Weak(script));
isolate->heap()->SetRootScriptList(*scripts);
for (int i = 0;
i < static_cast<int>(v8::Isolate::kUseCounterFeatureCount); ++i) {
v8::Isolate::UseCounterFeature feature =
static_cast<v8::Isolate::UseCounterFeature>(i);
isolate->CountUsage(feature, task->use_count(feature));
}
isolate->counters()->total_preparse_skipped()->Increment(
task->total_preparse_skipped());
} else {
ParseInfo* parse_info = task->info();
DCHECK_EQ(parse_info->flags().is_module(), origin_options.IsModule());
......
......@@ -525,6 +525,11 @@ class V8_EXPORT_PRIVATE BackgroundCompileTask {
return &finalize_unoptimized_compilation_data_;
}
int use_count(v8::Isolate::UseCounterFeature feature) const {
return use_counts_[static_cast<int>(feature)];
}
int total_preparse_skipped() const { return total_preparse_skipped_; }
// Jobs which could not be finalized in the background task, and need to be
// finalized on the main thread.
DeferredFinalizationJobDataList* jobs_to_retry_finalization_on_main_thread() {
......@@ -559,6 +564,8 @@ class V8_EXPORT_PRIVATE BackgroundCompileTask {
IsCompiledScope is_compiled_scope_;
FinalizeUnoptimizedCompilationDataList finalize_unoptimized_compilation_data_;
DeferredFinalizationJobDataList jobs_to_retry_finalization_on_main_thread_;
int use_counts_[v8::Isolate::kUseCounterFeatureCount] = {0};
int total_preparse_skipped_ = 0;
// Single function data for top-level function compilation.
int start_position_;
......
......@@ -4715,6 +4715,12 @@ void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) {
}
}
void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature, int count) {
for (int i = 0; i < count; ++i) {
CountUsage(feature);
}
}
int Isolate::GetNextScriptId() { return heap()->NextScriptId(); }
// static
......
......@@ -1496,6 +1496,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback);
void CountUsage(v8::Isolate::UseCounterFeature feature);
void CountUsage(v8::Isolate::UseCounterFeature feature, int count);
static std::string GetTurboCfgFileName(Isolate* isolate);
......
......@@ -711,12 +711,9 @@ void Heap::DumpJSONHeapStatistics(std::stringstream& stream) {
void Heap::ReportStatisticsAfterGC() {
for (int i = 0; i < static_cast<int>(v8::Isolate::kUseCounterFeatureCount);
++i) {
int count = deferred_counters_[i];
isolate()->CountUsage(static_cast<v8::Isolate::UseCounterFeature>(i),
deferred_counters_[i]);
deferred_counters_[i] = 0;
while (count > 0) {
count--;
isolate()->CountUsage(static_cast<v8::Isolate::UseCounterFeature>(i));
}
}
}
......
......@@ -3265,6 +3265,24 @@ void Parser::UpdateStatistics(Isolate* isolate, Handle<Script> script) {
total_preparse_skipped_);
}
void Parser::UpdateStatistics(Handle<Script> script, int* use_counts,
int* preparse_skipped) {
// Move statistics to Isolate.
for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
++feature) {
if (use_counts_[feature] > 0) {
use_counts[feature]++;
}
}
if (scanner_.FoundHtmlComment()) {
use_counts[v8::Isolate::kHtmlComment]++;
if (script->line_offset() == 0 && script->column_offset() == 0) {
use_counts[v8::Isolate::kHtmlCommentInExternalScript]++;
}
}
*preparse_skipped = total_preparse_skipped_;
}
void Parser::ParseOnBackground(ParseInfo* info, int start_position,
int end_position, int function_literal_id) {
RCS_SCOPE(runtime_call_stats_, RuntimeCallCounterId::kParseBackgroundProgram);
......
......@@ -161,6 +161,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
// Move statistics to Isolate
void UpdateStatistics(Isolate* isolate, Handle<Script> script);
void UpdateStatistics(Handle<Script> script, int* use_counters,
int* preparse_skipped);
template <typename IsolateT>
void HandleSourceURLComments(IsolateT* isolate, Handle<Script> script);
......
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