From 14331ec537ae9c6df7904c734c8ed59796a9762f Mon Sep 17 00:00:00 2001 From: Anton Bikineev Date: Fri, 25 Feb 2022 15:42:53 +0100 Subject: [PATCH] cppgc: young-gen: Schedule Minor GCs The CL runs Oilpan minor GCs after each Scavenger cycle. Bug: chromium:1029379 Change-Id: Ic67cf4dc9158759207f0209640f1720bf188cc1d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3472500 Reviewed-by: Michael Lippautz Commit-Queue: Anton Bikineev Cr-Commit-Position: refs/heads/main@{#79440} --- src/heap/cppgc-js/cpp-heap.cc | 22 ++++++++++++++++++++++ src/heap/cppgc-js/cpp-heap.h | 2 ++ src/heap/heap.cc | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/src/heap/cppgc-js/cpp-heap.cc b/src/heap/cppgc-js/cpp-heap.cc index e4079f23f8..9bdf06b374 100644 --- a/src/heap/cppgc-js/cpp-heap.cc +++ b/src/heap/cppgc-js/cpp-heap.cc @@ -642,6 +642,28 @@ void CppHeap::TraceEpilogue() { sweeper().NotifyDoneIfNeeded(); } +void CppHeap::RunMinorGC() { +#if defined(CPPGC_YOUNG_GENERATION) + if (in_no_gc_scope()) return; + // Minor GC does not support nesting in full GCs. + if (IsMarking()) return; + // Finish sweeping in case it is still running. + sweeper().FinishIfRunning(); + + SetStackEndOfCurrentGC(v8::base::Stack::GetCurrentStackPosition()); + + // Perform an atomic GC, with starting incremental/concurrent marking and + // immediately finalizing the garbage collection. + InitializeTracing( + cppgc::internal::GarbageCollector::Config::CollectionType::kMinor, + GarbageCollectionFlagValues::kForced); + StartTracing(); + EnterFinalPause(cppgc::EmbedderStackState::kMayContainHeapPointers); + AdvanceTracing(std::numeric_limits::infinity()); + TraceEpilogue(); +#endif // defined(CPPGC_YOUNG_GENERATION) +} + void CppHeap::AllocatedObjectSizeIncreased(size_t bytes) { buffered_allocated_bytes_ += static_cast(bytes); ReportBufferedAllocationSizeIfPossible(); diff --git a/src/heap/cppgc-js/cpp-heap.h b/src/heap/cppgc-js/cpp-heap.h index c16363c15b..70958b2b6d 100644 --- a/src/heap/cppgc-js/cpp-heap.h +++ b/src/heap/cppgc-js/cpp-heap.h @@ -129,6 +129,8 @@ class V8_EXPORT_PRIVATE CppHeap final void TraceEpilogue(); void EnterFinalPause(cppgc::EmbedderStackState stack_state); + void RunMinorGC(); + // StatsCollector::AllocationObserver interface. void AllocatedObjectSizeIncreased(size_t) final; void AllocatedObjectSizeDecreased(size_t) final; diff --git a/src/heap/heap.cc b/src/heap/heap.cc index 822dc58174..40f17f48c2 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -2327,6 +2327,10 @@ size_t Heap::PerformGarbageCollection( local_embedder_heap_tracer()->TraceEpilogue(); } + if (collector == GarbageCollector::SCAVENGER && cpp_heap()) { + CppHeap::From(cpp_heap())->RunMinorGC(); + } + #ifdef VERIFY_HEAP if (FLAG_verify_heap) { // We don't really perform a GC here but need this scope for the nested