Commit 125d3630 authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

Revert "[heap] Remove sweeping state in incremental marking"

This reverts commit 7f29c48e.

Reason for revert: Causing TSAN failures on test bots.

Original change's description:
> [heap] Remove sweeping state in incremental marking
> 
> Remove the SWEEPING state from incremental marking. Sweeping is now
> always completed when starting incremental marking. Before this change
> there needed to be a safepoint each for starting marking and completing
> sweeping. Now both happens within a single safepoint.
> 
> Bug: v8:10315
> Change-Id: Iad2835554865f2de24376372affe9a98992d1fa0
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2190419
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#67678}

TBR=ulan@chromium.org,dinfuehr@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: v8:10315
Change-Id: I5e76990155cf7aeee3ecefe5e37f9028cb188a00
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2192658Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67699}
parent 383d1453
......@@ -292,17 +292,16 @@ void IncrementalMarking::Start(GarbageCollectionReason gc_reason) {
heap_->array_buffer_sweeper()->EnsureFinished();
}
if (collector_->sweeping_in_progress()) {
TRACE_GC(heap_->tracer(), GCTracer::Scope::MC_INCREMENTAL_SWEEPING);
collector_->EnsureSweepingCompleted();
#ifdef DEBUG
heap_->VerifyCountersAfterSweeping();
#endif
if (!collector_->sweeping_in_progress()) {
StartMarking();
} else {
if (FLAG_trace_incremental_marking) {
heap()->isolate()->PrintWithTimestamp(
"[IncrementalMarking] Start sweeping.\n");
}
SetState(SWEEPING);
}
CHECK(!collector_->sweeping_in_progress());
StartMarking();
heap_->AddAllocationObserversToAllSpaces(&old_generation_observer_,
&new_generation_observer_);
incremental_marking_job()->Start(heap_);
......@@ -956,6 +955,28 @@ StepResult IncrementalMarking::AdvanceWithDeadline(
return Step(kStepSizeInMs, completion_action, step_origin);
}
void IncrementalMarking::FinalizeSweeping() {
DCHECK(state_ == SWEEPING);
#ifdef DEBUG
// Enforce safepoint here such that background threads cannot allocate between
// completing sweeping and VerifyCountersAfterSweeping().
SafepointScope scope(heap());
#endif
if (collector_->sweeping_in_progress() &&
(!FLAG_concurrent_sweeping ||
!collector_->sweeper()->AreSweeperTasksRunning())) {
collector_->EnsureSweepingCompleted();
}
if (!collector_->sweeping_in_progress()) {
#ifdef DEBUG
heap_->VerifyCountersAfterSweeping();
#else
SafepointScope scope(heap());
#endif
StartMarking();
}
}
size_t IncrementalMarking::StepSizeToKeepUpWithAllocations() {
// Update bytes_allocated_ based on the allocation counter.
size_t current_counter = heap_->OldGenerationAllocationCounter();
......@@ -1046,7 +1067,7 @@ void IncrementalMarking::AdvanceOnAllocation() {
// Code using an AlwaysAllocateScope assumes that the GC state does not
// change; that implies that no marking steps must be performed.
if (heap_->gc_state() != Heap::NOT_IN_GC || !FLAG_incremental_marking ||
state_ != MARKING || heap_->always_allocate()) {
(state_ != SWEEPING && state_ != MARKING) || heap_->always_allocate()) {
return;
}
HistogramTimerScope incremental_marking_scope(
......@@ -1062,6 +1083,11 @@ StepResult IncrementalMarking::Step(double max_step_size_in_ms,
StepOrigin step_origin) {
double start = heap_->MonotonicallyIncreasingTimeInMs();
if (state_ == SWEEPING) {
TRACE_GC(heap_->tracer(), GCTracer::Scope::MC_INCREMENTAL_SWEEPING);
FinalizeSweeping();
}
StepResult combined_result = StepResult::kMoreWorkRemaining;
size_t bytes_to_process = 0;
size_t v8_bytes_processed = 0;
......
......@@ -28,7 +28,7 @@ enum class StepResult {
class V8_EXPORT_PRIVATE IncrementalMarking final {
public:
enum State : uint8_t { STOPPED, MARKING, COMPLETE };
enum State : uint8_t { STOPPED, SWEEPING, MARKING, COMPLETE };
enum CompletionAction { GC_VIA_STACK_GUARD, NO_GC_VIA_STACK_GUARD };
......@@ -115,6 +115,8 @@ class V8_EXPORT_PRIVATE IncrementalMarking final {
inline bool IsStopped() const { return state() == STOPPED; }
inline bool IsSweeping() const { return state() == SWEEPING; }
inline bool IsMarking() const { return state() >= MARKING; }
inline bool IsMarkingIncomplete() const { return state() == MARKING; }
......@@ -165,6 +167,8 @@ class V8_EXPORT_PRIVATE IncrementalMarking final {
CompletionAction completion_action,
StepOrigin step_origin);
void FinalizeSweeping();
StepResult Step(double max_step_size_in_ms, CompletionAction action,
StepOrigin step_origin);
......
......@@ -847,6 +847,10 @@ void MarkCompactCollector::Prepare() {
heap_->array_buffer_sweeper()->EnsureFinished();
}
if (heap()->incremental_marking()->IsSweeping()) {
heap()->incremental_marking()->Stop();
}
if (!was_marked_incrementally_) {
{
TRACE_GC(heap()->tracer(), GCTracer::Scope::MC_MARK_EMBEDDER_PROLOGUE);
......
......@@ -162,6 +162,9 @@ void SimulateIncrementalMarking(i::Heap* heap, bool force_completion) {
if (collector->sweeping_in_progress()) {
collector->EnsureSweepingCompleted();
}
if (marking->IsSweeping()) {
marking->FinalizeSweeping();
}
CHECK(marking->IsMarking() || marking->IsStopped() || marking->IsComplete());
if (marking->IsStopped()) {
heap->StartIncrementalMarking(i::Heap::kNoGCFlags,
......
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