From b89b60c5be78064a9dbcf5d3672bdb18fa62a639 Mon Sep 17 00:00:00 2001 From: x00416111 Date: Sat, 5 Jul 2025 10:51:52 +0800 Subject: [PATCH] [CMC] Fixed cal pinned garbage size Fixed cal pinned garbage size Issue: [Bug]:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICK5X1 Change-Id: Id3adcff4021d53af263a2ddb35e952a40c493ce4 Signed-off-by: x00416111 --- .../heap/allocator/region_manager.cpp | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/common_components/heap/allocator/region_manager.cpp b/common_components/heap/allocator/region_manager.cpp index feee6f3bf1..91c7e521ac 100755 --- a/common_components/heap/allocator/region_manager.cpp +++ b/common_components/heap/allocator/region_manager.cpp @@ -675,22 +675,31 @@ void RegionManager::FixFixedRegionList(TraceCollector& collector, RegionList& li auto liveBytes = region->GetLiveByteCount(); if (liveBytes == 0) { RegionDesc* del = region; + auto calGarbageSize = [&del, &cellCount, &garbageSize](BaseObject* object) { + if (!del->IsFreePinnedObject(object)) { + garbageSize += (cellCount + 1) * sizeof(uint64_t); + } + }; + del->VisitAllObjectsWithFixedSize(cellCount, calGarbageSize); + region = region->GetNextRegion(); list.DeleteRegion(del); - garbageSize += CollectRegion(del); + CollectRegion(del); continue; } - region->VisitAllObjectsWithFixedSize(cellCount, - [&collector, ®ion, &cellCount, &garbageSize](BaseObject* object) { + auto fixObj = [&collector, ®ion, &cellCount, &garbageSize](BaseObject* object) { if (collector.IsSurvivedObject(object)) { collector.FixObjectRefFields(object); } else { DLOG(ALLOC, "reclaim pinned obj %p", object); - garbageSize += (cellCount + 1) * sizeof(uint64_t); - region->CollectPinnedGarbage(object, cellCount); + bool succ = region->CollectPinnedGarbage(object, cellCount); + if (succ) { + garbageSize += (cellCount + 1) * sizeof(uint64_t); + } } - }); + }; + region->VisitAllObjectsWithFixedSize(cellCount, fixObj); region = region->GetNextRegion(); } stats.pinnedGarbageSize += garbageSize; -- Gitee