Commit 97751649 authored by Omer Katz's avatar Omer Katz Committed by V8 LUCI CQ

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/+/3358292Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78464}
parent a8b99992
......@@ -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());
......
......@@ -64,6 +64,8 @@ class V8_EXPORT_PRIVATE CppHeap final
cppgc::internal::MetricRecorder::MainThreadIncrementalMark>
ExtractLastIncrementalMarkEvent();
void ClearCachedEvents();
private:
Isolate* GetIsolate() const;
......
......@@ -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() {
......
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