cppgc: Fix leftover cached events

Clear cached events if there is no embedder recorder.

Bug: chromium:1154636
Change-Id: I9ad3b752ea242d07b417ce3022936789c47afc6a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3358292
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78464}
This commit is contained in:
Omer Katz 2021-12-30 11:48:04 +01:00 committed by V8 LUCI CQ
parent a8b999920b
commit 97751649ad
3 changed files with 20 additions and 2 deletions

View File

@ -233,6 +233,7 @@ void UnifiedHeapMarker::AddObject(void* object) {
void CppHeap::MetricRecorderAdapter::AddMainThreadEvent(
const FullCycle& cppgc_event) {
DCHECK(!last_full_gc_event_.has_value());
last_full_gc_event_ = cppgc_event;
GetIsolate()->heap()->tracer()->NotifyGCCompleted();
}
@ -311,6 +312,13 @@ CppHeap::MetricRecorderAdapter::ExtractLastIncrementalMarkEvent() {
return std::move(last_incremental_mark_event_);
}
void CppHeap::MetricRecorderAdapter::ClearCachedEvents() {
incremental_mark_batched_events_.events.clear();
incremental_sweep_batched_events_.events.clear();
last_incremental_mark_event_.reset();
last_full_gc_event_.reset();
}
Isolate* CppHeap::MetricRecorderAdapter::GetIsolate() const {
DCHECK_NOT_NULL(cpp_heap_.isolate());
return reinterpret_cast<Isolate*>(cpp_heap_.isolate());

View File

@ -64,6 +64,8 @@ class V8_EXPORT_PRIVATE CppHeap final
cppgc::internal::MetricRecorder::MainThreadIncrementalMark>
ExtractLastIncrementalMarkEvent();
void ClearCachedEvents();
private:
Isolate* GetIsolate() const;

View File

@ -1381,7 +1381,16 @@ void GCTracer::ReportFullCycleToRecorder() {
const std::shared_ptr<metrics::Recorder>& recorder =
heap_->isolate()->metrics_recorder();
DCHECK_NOT_NULL(recorder);
if (!recorder->HasEmbedderRecorder()) return;
metrics_report_pending_ = false;
if (!recorder->HasEmbedderRecorder()) {
incremental_mark_batched_events_.events.clear();
if (heap_->cpp_heap()) {
v8::internal::CppHeap::From(heap_->cpp_heap())
->GetMetricRecorder()
->ClearCachedEvents();
}
return;
}
if (!incremental_mark_batched_events_.events.empty()) {
FlushBatchedIncrementalEvents(incremental_mark_batched_events_,
heap_->isolate());
@ -1416,7 +1425,6 @@ void GCTracer::ReportFullCycleToRecorder() {
}
// TODO(chromium:1154636): Populate v8 metrics.
recorder->AddMainThreadEvent(event, GetContextId(heap_->isolate()));
metrics_report_pending_ = false;
}
void GCTracer::ReportIncrementalMarkingStepToRecorder() {