From ca4f6379b7575fdd7b0baf44cd8c6e62b79c0314 Mon Sep 17 00:00:00 2001 From: ttliang Date: Sat, 12 Jul 2025 20:44:39 +0800 Subject: [PATCH] enable cmc gc with 1.2 runtime in 0702_br Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICUX6F Signed-off-by: ttliang Change-Id: Ib7ae36b78dbbeddfc203b7cf35b29387e065464e --- .../heap/collector/trace_collector.cpp | 2 +- common_components/heap/heap_visitor.cpp | 64 +++++++++---------- common_components/heap/verification.cpp | 6 +- .../heap/w_collector/w_collector.cpp | 4 +- ecmascript/dfx/hprof/heap_snapshot.cpp | 6 +- ecmascript/mem/cmc_gc/hooks.cpp | 5 -- libark_jsruntime.map | 1 + 7 files changed, 42 insertions(+), 46 deletions(-) diff --git a/common_components/heap/collector/trace_collector.cpp b/common_components/heap/collector/trace_collector.cpp index e2117d7842..6e6961a592 100755 --- a/common_components/heap/collector/trace_collector.cpp +++ b/common_components/heap/collector/trace_collector.cpp @@ -237,7 +237,7 @@ void TraceCollector::EnumConcurrencyModelRoots(RootSet& rootSet) const void TraceCollector::EnumStaticRoots(RootSet& rootSet) const { const RefFieldVisitor& visitor = [&rootSet, this](RefField<>& root) { EnumRefFieldRoot(root, rootSet); }; - VisitRoots(visitor); + VisitRoots(visitor, true); } class MergeMutatorRootsScope { diff --git a/common_components/heap/heap_visitor.cpp b/common_components/heap/heap_visitor.cpp index f65696ac35..eda41591b4 100755 --- a/common_components/heap/heap_visitor.cpp +++ b/common_components/heap/heap_visitor.cpp @@ -43,58 +43,58 @@ void RegisterSweepStaticRootsHook(SweepStaticRootsHookFunc func) } -void VisitRoots(const RefFieldVisitor &visitor) +void VisitRoots(const RefFieldVisitor &visitor, bool isMark) { VisitDynamicGlobalRoots(visitor); VisitDynamicLocalRoots(visitor); VisitBaseRoots(visitor); - // if (isMark) { - // if (g_visitStaticRootsHook != nullptr) { - // g_visitStaticRootsHook(visitor); - // } - // } else { - // if (g_updateStaticRootsHook != nullptr) { - // g_updateStaticRootsHook(visitor); - // } - // } + if (isMark) { + if (g_visitStaticRootsHook != nullptr) { + g_visitStaticRootsHook(visitor); + } + } else { + if (g_updateStaticRootsHook != nullptr) { + g_updateStaticRootsHook(visitor); + } + } } void VisitWeakRoots(const WeakRefFieldVisitor &visitor) { VisitDynamicWeakGlobalRoots(visitor); VisitDynamicWeakLocalRoots(visitor); - // if (g_updateStaticRootsHook != nullptr) { - // g_updateStaticRootsHook(visitor); - // } - // if (g_sweepStaticRootsHook != nullptr) { - // g_sweepStaticRootsHook(visitor); - // } + if (g_updateStaticRootsHook != nullptr) { + g_updateStaticRootsHook(visitor); + } + if (g_sweepStaticRootsHook != nullptr) { + g_sweepStaticRootsHook(visitor); + } } -void VisitGlobalRoots(const RefFieldVisitor &visitor) +void VisitGlobalRoots(const RefFieldVisitor &visitor, bool isMark) { VisitDynamicGlobalRoots(visitor); VisitBaseRoots(visitor); - // if (isMark) { - // if (g_visitStaticRootsHook != nullptr) { - // g_visitStaticRootsHook(visitor); - // } - // } else { - // if (g_updateStaticRootsHook != nullptr) { - // g_updateStaticRootsHook(visitor); - // } - // } + if (isMark) { + if (g_visitStaticRootsHook != nullptr) { + g_visitStaticRootsHook(visitor); + } + } else { + if (g_updateStaticRootsHook != nullptr) { + g_updateStaticRootsHook(visitor); + } + } } void VisitWeakGlobalRoots(const WeakRefFieldVisitor &visitor) { VisitDynamicWeakGlobalRoots(visitor); - // if (g_updateStaticRootsHook != nullptr) { - // g_updateStaticRootsHook(visitor); - // } - // if (g_sweepStaticRootsHook != nullptr) { - // g_sweepStaticRootsHook(visitor); - // } + if (g_updateStaticRootsHook != nullptr) { + g_updateStaticRootsHook(visitor); + } + if (g_sweepStaticRootsHook != nullptr) { + g_sweepStaticRootsHook(visitor); + } } // Visit specific mutator's root. diff --git a/common_components/heap/verification.cpp b/common_components/heap/verification.cpp index 7ee2c04141..086e5733f3 100755 --- a/common_components/heap/verification.cpp +++ b/common_components/heap/verification.cpp @@ -50,7 +50,7 @@ */ namespace common { -void VisitRoots(const RefFieldVisitor& visitorFunc); +void VisitRoots(const RefFieldVisitor& visitorFunc, bool isMark); void VisitWeakRoots(const WeakRefFieldVisitor& visitorFunc); #define CONTEXT " at " << __FILE__ << ":" << __LINE__ << std::endl @@ -332,7 +332,7 @@ public: MarkStack roots; RefFieldVisitor refVisitor = [&](RefField<>& ref) { visitor.VerifyRef(nullptr, ref); }; - VisitRoots(refVisitor); + VisitRoots(refVisitor, true); } void IterateWeakRoot(VerifyVisitor& visitor) @@ -401,7 +401,7 @@ private: void EnumStrongRoots(const std::function&)>& markFunc) { - VisitRoots(markFunc); + VisitRoots(markFunc, true); } void Trace(MarkStack& markStack) {} diff --git a/common_components/heap/w_collector/w_collector.cpp b/common_components/heap/w_collector/w_collector.cpp index df0932a091..648ba80a41 100755 --- a/common_components/heap/w_collector/w_collector.cpp +++ b/common_components/heap/w_collector/w_collector.cpp @@ -378,7 +378,7 @@ void WCollector::RemarkAndPreforwardStaticRoots(WorkStack& workStack) markObject(oldObj); } }; - VisitRoots(visitor); + VisitRoots(visitor, false); // inline MergeAllocBufferRoots MutatorManager &mutatorManager = MutatorManager::Instance(); bool worldStopped = mutatorManager.WorldStopped(); @@ -709,7 +709,7 @@ void WCollector::EnumRootsFlip(WorkStack& rootSet) TransitionToGCPhase(GCPhase::GC_PHASE_ENUM, true); const RefFieldVisitor& visitor = [this, &rootSet](RefField<>& root) { EnumRefFieldRoot(root, rootSet); }; - VisitGlobalRoots(visitor); + VisitGlobalRoots(visitor, true); MergeAllocBufferRoots(rootSet); }; FlipFunction enumMutatorRoot = [this, &rootSet, &stackMutex](Mutator &mutator) { diff --git a/ecmascript/dfx/hprof/heap_snapshot.cpp b/ecmascript/dfx/hprof/heap_snapshot.cpp index f36545b249..511a0c5b1e 100755 --- a/ecmascript/dfx/hprof/heap_snapshot.cpp +++ b/ecmascript/dfx/hprof/heap_snapshot.cpp @@ -1319,16 +1319,16 @@ void HeapSnapshot::HandleCMCGCRoots(Node *syntheticRoot, CUnorderedSetWriteToLeakStackTraceFd(buffer); heapProfiler->CloseLeakStackTraceFd(); } else { - common::VisitRoots(visitor); + common::VisitRoots(visitor, false); } heapProfiler->ClearHandleBackTrace(); #else - common::VisitRoots(visitor); + common::VisitRoots(visitor, false); #endif // ENABLE_LOCAL_HANDLE_LEAK_DETECT } diff --git a/ecmascript/mem/cmc_gc/hooks.cpp b/ecmascript/mem/cmc_gc/hooks.cpp index 15d43ffcd8..c4e7ce8e45 100644 --- a/ecmascript/mem/cmc_gc/hooks.cpp +++ b/ecmascript/mem/cmc_gc/hooks.cpp @@ -107,11 +107,6 @@ private: void VisitBaseRoots(const RefFieldVisitor &visitorFunc) { - // todo 梁婷婷 - if (!panda::ecmascript::Runtime::HasInstance()) { - return; - } - BaseClassRoots &baseClassRoots = BaseRuntime::GetInstance()->GetBaseClassRoots(); // When visit roots, the language of the object is not used, so using the visitorFunc will work for // both dynamic and static. diff --git a/libark_jsruntime.map b/libark_jsruntime.map index b01cda1428..8516394e47 100644 --- a/libark_jsruntime.map +++ b/libark_jsruntime.map @@ -100,6 +100,7 @@ panda::JsiFastNativeScope::*; panda::JSExecutionScope::*; common::BaseRuntime::*; + common::BaseObject::*; common::HeapAllocator::*; common::VisitDynamicGlobalRoots*; common::VisitDynamicWeakGlobalRoots*; -- Gitee