Commit 25a55381 authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

cppgc: Join concurrent marking instead of cancelling

Join instead of cancel to make use of the the main thread.

Also make the Join() call explicit instead of implicitly finishing
concurrency on advancing tracing form the main thread.

Bug: v8:12600
Change-Id: I60d3e82bfc2e8a3ccc2dda761a5d3eb3ac7694d1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3578855Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79910}
parent 3864c961
...@@ -607,6 +607,10 @@ void CppHeap::EnterFinalPause(cppgc::EmbedderStackState stack_state) { ...@@ -607,6 +607,10 @@ void CppHeap::EnterFinalPause(cppgc::EmbedderStackState stack_state) {
compactor_.CancelIfShouldNotCompact(MarkingType::kAtomic, stack_state); compactor_.CancelIfShouldNotCompact(MarkingType::kAtomic, stack_state);
} }
bool CppHeap::FinishConcurrentMarkingIfNeeded() {
return marker_->JoinConcurrentMarkingIfNeeded();
}
void CppHeap::TraceEpilogue() { void CppHeap::TraceEpilogue() {
CHECK(in_atomic_pause_); CHECK(in_atomic_pause_);
CHECK(marking_done_); CHECK(marking_done_);
...@@ -738,7 +742,10 @@ void CppHeap::CollectGarbageForTesting(CollectionType collection_type, ...@@ -738,7 +742,10 @@ void CppHeap::CollectGarbageForTesting(CollectionType collection_type,
StartTracing(); StartTracing();
} }
EnterFinalPause(stack_state); EnterFinalPause(stack_state);
AdvanceTracing(std::numeric_limits<double>::infinity()); CHECK(AdvanceTracing(std::numeric_limits<double>::infinity()));
if (FinishConcurrentMarkingIfNeeded()) {
CHECK(AdvanceTracing(std::numeric_limits<double>::infinity()));
}
TraceEpilogue(); TraceEpilogue();
} }
} }
......
...@@ -134,6 +134,7 @@ class V8_EXPORT_PRIVATE CppHeap final ...@@ -134,6 +134,7 @@ class V8_EXPORT_PRIVATE CppHeap final
bool IsTracingDone(); bool IsTracingDone();
void TraceEpilogue(); void TraceEpilogue();
void EnterFinalPause(cppgc::EmbedderStackState stack_state); void EnterFinalPause(cppgc::EmbedderStackState stack_state);
bool FinishConcurrentMarkingIfNeeded();
void RunMinorGC(StackState); void RunMinorGC(StackState);
......
...@@ -203,19 +203,14 @@ void ConcurrentMarkerBase::Start() { ...@@ -203,19 +203,14 @@ void ConcurrentMarkerBase::Start() {
std::make_unique<ConcurrentMarkingTask>(*this)); std::make_unique<ConcurrentMarkingTask>(*this));
} }
bool ConcurrentMarkerBase::Cancel() { bool ConcurrentMarkerBase::Join() {
if (!concurrent_marking_handle_ || !concurrent_marking_handle_->IsValid()) if (!concurrent_marking_handle_ || !concurrent_marking_handle_->IsValid())
return false; return false;
concurrent_marking_handle_->Cancel(); concurrent_marking_handle_->Join();
return true; return true;
} }
void ConcurrentMarkerBase::JoinForTesting() {
if (concurrent_marking_handle_ && concurrent_marking_handle_->IsValid())
concurrent_marking_handle_->Join();
}
bool ConcurrentMarkerBase::IsActive() const { bool ConcurrentMarkerBase::IsActive() const {
return concurrent_marking_handle_ && concurrent_marking_handle_->IsValid(); return concurrent_marking_handle_ && concurrent_marking_handle_->IsValid();
} }
......
...@@ -24,10 +24,8 @@ class V8_EXPORT_PRIVATE ConcurrentMarkerBase { ...@@ -24,10 +24,8 @@ class V8_EXPORT_PRIVATE ConcurrentMarkerBase {
ConcurrentMarkerBase& operator=(const ConcurrentMarkerBase&) = delete; ConcurrentMarkerBase& operator=(const ConcurrentMarkerBase&) = delete;
void Start(); void Start();
// Returns whether the job has been cancelled. // Returns whether the job has been joined.
bool Cancel(); bool Join();
void JoinForTesting();
void NotifyIncrementalMutatorStepCompleted(); void NotifyIncrementalMutatorStepCompleted();
......
...@@ -317,6 +317,9 @@ void MarkerBase::FinishMarking(MarkingConfig::StackState stack_state) { ...@@ -317,6 +317,9 @@ void MarkerBase::FinishMarking(MarkingConfig::StackState stack_state) {
StatsCollector::EnabledScope stats_scope(heap().stats_collector(), StatsCollector::EnabledScope stats_scope(heap().stats_collector(),
StatsCollector::kAtomicMark); StatsCollector::kAtomicMark);
CHECK(AdvanceMarkingWithLimits(v8::base::TimeDelta::Max(), SIZE_MAX)); CHECK(AdvanceMarkingWithLimits(v8::base::TimeDelta::Max(), SIZE_MAX));
if (JoinConcurrentMarkingIfNeeded()) {
CHECK(AdvanceMarkingWithLimits(v8::base::TimeDelta::Max(), SIZE_MAX));
}
mutator_marking_state_.Publish(); mutator_marking_state_.Publish();
} }
LeaveAtomicPause(); LeaveAtomicPause();
...@@ -447,9 +450,9 @@ void MarkerBase::AdvanceMarkingOnAllocation() { ...@@ -447,9 +450,9 @@ void MarkerBase::AdvanceMarkingOnAllocation() {
} }
} }
bool MarkerBase::CancelConcurrentMarkingIfNeeded() { bool MarkerBase::JoinConcurrentMarkingIfNeeded() {
if (config_.marking_type != MarkingConfig::MarkingType::kAtomic || if (config_.marking_type != MarkingConfig::MarkingType::kAtomic ||
!concurrent_marker_->Cancel()) !concurrent_marker_->Join())
return false; return false;
// Concurrent markers may have pushed some "leftover" in-construction objects // Concurrent markers may have pushed some "leftover" in-construction objects
...@@ -478,9 +481,6 @@ bool MarkerBase::AdvanceMarkingWithLimits(v8::base::TimeDelta max_duration, ...@@ -478,9 +481,6 @@ bool MarkerBase::AdvanceMarkingWithLimits(v8::base::TimeDelta max_duration,
// adjustment. // adjustment.
is_done = ProcessWorklistsWithDeadline(marked_bytes_limit, deadline); is_done = ProcessWorklistsWithDeadline(marked_bytes_limit, deadline);
} }
if (is_done && CancelConcurrentMarkingIfNeeded()) {
is_done = ProcessWorklistsWithDeadline(marked_bytes_limit, deadline);
}
schedule_.UpdateMutatorThreadMarkedBytes( schedule_.UpdateMutatorThreadMarkedBytes(
mutator_marking_state_.marked_bytes()); mutator_marking_state_.marked_bytes());
} }
...@@ -637,7 +637,7 @@ void MarkerBase::SetMainThreadMarkingDisabledForTesting(bool value) { ...@@ -637,7 +637,7 @@ void MarkerBase::SetMainThreadMarkingDisabledForTesting(bool value) {
} }
void MarkerBase::WaitForConcurrentMarkingForTesting() { void MarkerBase::WaitForConcurrentMarkingForTesting() {
concurrent_marker_->JoinForTesting(); concurrent_marker_->Join();
} }
Marker::Marker(HeapBase& heap, cppgc::Platform* platform, MarkingConfig config) Marker::Marker(HeapBase& heap, cppgc::Platform* platform, MarkingConfig config)
......
...@@ -100,6 +100,8 @@ class V8_EXPORT_PRIVATE MarkerBase { ...@@ -100,6 +100,8 @@ class V8_EXPORT_PRIVATE MarkerBase {
void ProcessWeakness(); void ProcessWeakness();
bool JoinConcurrentMarkingIfNeeded();
inline void WriteBarrierForInConstructionObject(HeapObjectHeader&); inline void WriteBarrierForInConstructionObject(HeapObjectHeader&);
template <WriteBarrierType type> template <WriteBarrierType type>
...@@ -149,8 +151,6 @@ class V8_EXPORT_PRIVATE MarkerBase { ...@@ -149,8 +151,6 @@ class V8_EXPORT_PRIVATE MarkerBase {
void AdvanceMarkingOnAllocation(); void AdvanceMarkingOnAllocation();
bool CancelConcurrentMarkingIfNeeded();
void HandleNotFullyConstructedObjects(); void HandleNotFullyConstructedObjects();
HeapBase& heap_; HeapBase& heap_;
......
...@@ -1021,6 +1021,9 @@ void MarkCompactCollector::FinishConcurrentMarking() { ...@@ -1021,6 +1021,9 @@ void MarkCompactCollector::FinishConcurrentMarking() {
non_atomic_marking_state()); non_atomic_marking_state());
heap()->concurrent_marking()->FlushNativeContexts(&native_context_stats_); heap()->concurrent_marking()->FlushNativeContexts(&native_context_stats_);
} }
if (auto* cpp_heap = CppHeap::From(heap_->cpp_heap())) {
cpp_heap->FinishConcurrentMarkingIfNeeded();
}
} }
void MarkCompactCollector::VerifyMarking() { void MarkCompactCollector::VerifyMarking() {
......
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