Commit b0295b8c authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

cppgc: Extract NotifySweepingCompleted from Sweeper::Finish

This is required for enabling scopes such that NotifySweepingCompleted
is not called from within a scope.

Bug: chromium:1056170
Change-Id: Ia66aa4de8c22bfa7dfe1e02ee1e0d3ad088f7bf6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2549761Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71282}
parent a07c14f6
......@@ -243,6 +243,7 @@ void CppHeap::TraceEpilogue(TraceSummary* trace_summary) {
compactable_space_handling};
sweeper().Start(sweeping_config);
}
sweeper().NotifyDoneIfNeeded();
}
} // namespace internal
......
......@@ -54,6 +54,8 @@ class V8_EXPORT_PRIVATE CppHeap final : public cppgc::internal::HeapBase,
// finalization is not needed) thus this method is left empty.
}
void PostGarbageCollection() final {}
Isolate& isolate_;
bool marking_done_ = false;
};
......
......@@ -139,6 +139,9 @@ class V8_EXPORT_PRIVATE HeapBase {
void AdvanceIncrementalGarbageCollectionOnAllocationIfNeeded();
// Notifies the heap that a GC is done.
virtual void PostGarbageCollection() = 0;
protected:
virtual void FinalizeIncrementalGarbageCollectionIfNeeded(
cppgc::Heap::StackState) = 0;
......
......@@ -173,9 +173,11 @@ void Heap::FinalizeGarbageCollection(Config::StackState stack_state) {
Sweeper::SweepingConfig::CompactableSpaceHandling::kSweep};
sweeper_.Start(sweeping_config);
}
gc_in_progress_ = false;
sweeper_.NotifyDoneIfNeeded();
}
void Heap::PostGarbageCollection() { gc_in_progress_ = false; }
void Heap::DisableHeapGrowingForTesting() { growing_.DisableForTesting(); }
} // namespace internal
......
......@@ -49,6 +49,8 @@ class V8_EXPORT_PRIVATE Heap final : public HeapBase,
FinalizeGarbageCollection(stack_state);
}
void PostGarbageCollection() final;
Config config_;
GCInvoker gc_invoker_;
HeapGrowing growing_;
......
......@@ -13,6 +13,7 @@
#include "src/base/platform/mutex.h"
#include "src/heap/cppgc/free-list.h"
#include "src/heap/cppgc/globals.h"
#include "src/heap/cppgc/heap-base.h"
#include "src/heap/cppgc/heap-object-header.h"
#include "src/heap/cppgc/heap-page.h"
#include "src/heap/cppgc/heap-space.h"
......@@ -523,6 +524,7 @@ class Sweeper::SweeperImpl final {
cppgc::TaskPriority::kUserBlocking);
}
Finish();
NotifyDone();
}
void Finish() {
......@@ -536,12 +538,28 @@ class Sweeper::SweeperImpl final {
MutatorThreadSweeper sweeper(&space_states_, platform_);
sweeper.Sweep();
FinalizeSweep();
}
void FinalizeSweep() {
// Synchronize with the concurrent sweeper and call remaining finalizers.
SynchronizeAndFinalizeConcurrentSweeping();
is_in_progress_ = false;
notify_done_pending_ = true;
}
void NotifyDone() {
DCHECK(!is_in_progress_);
DCHECK(notify_done_pending_);
notify_done_pending_ = false;
stats_collector_->NotifySweepingCompleted();
// Notify the heap that GC is finished.
heap_->heap()->PostGarbageCollection();
}
void NotifyDoneIfNeeded() {
if (!notify_done_pending_) return;
NotifyDone();
}
void WaitForConcurrentSweepingForTesting() {
......@@ -573,7 +591,8 @@ class Sweeper::SweeperImpl final {
sweeper.SweepWithDeadline(deadline_in_seconds);
if (sweep_complete) {
sweeper_->SynchronizeAndFinalizeConcurrentSweeping();
sweeper_->FinalizeSweep();
sweeper_->NotifyDone();
} else {
sweeper_->ScheduleIncrementalSweeping();
}
......@@ -625,6 +644,7 @@ class Sweeper::SweeperImpl final {
IncrementalSweepTask::Handle incremental_sweeper_handle_;
std::unique_ptr<cppgc::JobHandle> concurrent_sweeper_handle_;
bool is_in_progress_ = false;
bool notify_done_pending_ = false;
};
Sweeper::Sweeper(RawHeap* heap, cppgc::Platform* platform,
......@@ -638,6 +658,7 @@ void Sweeper::FinishIfRunning() { impl_->FinishIfRunning(); }
void Sweeper::WaitForConcurrentSweepingForTesting() {
impl_->WaitForConcurrentSweepingForTesting();
}
void Sweeper::NotifyDoneIfNeeded() { impl_->NotifyDoneIfNeeded(); }
} // namespace internal
} // namespace cppgc
......@@ -39,6 +39,7 @@ class V8_EXPORT_PRIVATE Sweeper final {
// Sweeper::Start assumes the heap holds no linear allocation buffers.
void Start(SweepingConfig);
void FinishIfRunning();
void NotifyDoneIfNeeded();
private:
void WaitForConcurrentSweepingForTesting();
......
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