From a2d1f1fce577ce2f9698d5370864c66d7bb4dc5d Mon Sep 17 00:00:00 2001 From: hewei Date: Thu, 10 Jul 2025 09:04:03 +0800 Subject: [PATCH] fix stw Signed-off-by: hewei Change-Id: Ia88ccedc5d3b4f6660e0127bef878703fb84aae9 --- .../heap/w_collector/w_collector.cpp | 90 +++---------------- 1 file changed, 11 insertions(+), 79 deletions(-) diff --git a/common_components/heap/w_collector/w_collector.cpp b/common_components/heap/w_collector/w_collector.cpp index 52564dca84..57cb81e5af 100755 --- a/common_components/heap/w_collector/w_collector.cpp +++ b/common_components/heap/w_collector/w_collector.cpp @@ -635,84 +635,18 @@ void WCollector::DoGarbageCollection() { const bool isNotYoungGC = gcReason_ != GCReason::GC_REASON_YOUNG; OHOS_HITRACE(HITRACE_LEVEL_COMMERCIAL, "CMCGC::DoGarbageCollection", ""); - if (gcMode_ == GCMode::STW) { // 2: stw-gc -#ifdef ENABLE_CMC_RB_DFX - WVerify::DisableReadBarrierDFX(*this); -#endif - - ScopedStopTheWorld stw("stw-gc"); - auto collectedRoots = EnumRoots(); - TraceHeap(collectedRoots); - TransitionToGCPhase(GCPhase::GC_PHASE_FINAL_MARK, true); - Remark(); - PostTrace(); - - Preforward(); - ConcurrentPreforward(); - // reclaim large objects should after preforward(may process weak ref) and - // before fix heap(may clear live bit) - if (isNotYoungGC) { - CollectLargeGarbage(); - } - SweepThreadLocalJitFort(); - - CopyFromSpace(); - WVerify::VerifyAfterForward(*this); - PrepareFix(); - FixHeap(); - if (isNotYoungGC) { - CollectPinnedGarbage(); - } - - TransitionToGCPhase(GCPhase::GC_PHASE_IDLE, true); - - ClearAllGCInfo(); - CollectSmallSpace(); - -#if defined(ENABLE_CMC_RB_DFX) - WVerify::EnableReadBarrierDFX(*this); -#endif - return; - } else if (gcMode_ == GCMode::CONCURRENT_MARK) { // 1: concurrent-mark - auto collectedRoots = EnumRoots(); - TraceHeap(collectedRoots); - { - ScopedStopTheWorld stw("final-mark", true, GCPhase::GC_PHASE_FINAL_MARK); - Remark(); - PostTrace(); - reinterpret_cast(theAllocator_).PrepareForward(); - Preforward(); - } - ConcurrentPreforward(); - // reclaim large objects should after preforward(may process weak ref) and - // before fix heap(may clear live bit) - if (isNotYoungGC) { - CollectLargeGarbage(); - } - SweepThreadLocalJitFort(); - - CopyFromSpace(); - WVerify::VerifyAfterForward(*this); - - PrepareFix(); - FixHeap(); - if (isNotYoungGC) { - CollectPinnedGarbage(); - } - - TransitionToGCPhase(GCPhase::GC_PHASE_IDLE, true); - ClearAllGCInfo(); - CollectSmallSpace(); - return; - } - - auto collectedRoots = EnumRoots(); + ScopedStopTheWorld stw("stw-gc"); + auto collectedRoots = EnumRoots(); TraceHeap(collectedRoots); - PreforwardFlip(); + TransitionToGCPhase(GCPhase::GC_PHASE_FINAL_MARK, true); + Remark(); + PostTrace(); + + Preforward(); ConcurrentPreforward(); - // reclaim large objects should after preforward(may process weak ref) - // and before fix heap(may clear live bit) + // reclaim large objects should after preforward(may process weak ref) and + // before fix heap(may clear live bit) if (isNotYoungGC) { CollectLargeGarbage(); } @@ -721,16 +655,14 @@ void WCollector::DoGarbageCollection() CopyFromSpace(); WVerify::VerifyAfterForward(*this); - { - ScopedStopTheWorld stw("wgc-preparefix"); - PrepareFix(); - } + PrepareFix(); FixHeap(); if (isNotYoungGC) { CollectPinnedGarbage(); } TransitionToGCPhase(GCPhase::GC_PHASE_IDLE, true); + ClearAllGCInfo(); CollectSmallSpace(); } -- Gitee