From c2fc0385dd6d151c3b609cd4793a5adb60360ae3 Mon Sep 17 00:00:00 2001 From: ivagin Date: Fri, 6 Jun 2025 14:17:13 +0300 Subject: [PATCH] Support object pinning in CMC GC Issue: ICD92C Signed-off-by: ivagin --- .../src/heap/allocator/region_manager.cpp | 28 +++++++++++++++++++ .../src/heap/allocator/region_manager.h | 3 ++ common_components/heap/heap_allocator.cpp | 12 ++++++++ 3 files changed, 43 insertions(+) diff --git a/common_components/common_runtime/src/heap/allocator/region_manager.cpp b/common_components/common_runtime/src/heap/allocator/region_manager.cpp index 7957627b8d..001a50a7df 100755 --- a/common_components/common_runtime/src/heap/allocator/region_manager.cpp +++ b/common_components/common_runtime/src/heap/allocator/region_manager.cpp @@ -693,6 +693,34 @@ uintptr_t RegionManager::AllocLargeRegion(size_t size) return AllocLarge(size, false); } +void RegionManager::PinObject(uintptr_t obj) +{ + RegionDesc* region = RegionDesc::GetRegionDescAt(reinterpret_cast(obj)); + if (region->GetRegionType() == RegionDesc::RegionType::THREAD_LOCAL_REGION) { + tlRegionList_.DeleteRegion(region); + recentPinnedRegionList_.PrependRegion(region, RegionDesc::RegionType::RECENT_PINNED_REGION); + } else if (region->GetRegionType() == RegionDesc::RegionType::RECENT_FULL_REGION) { + recentFullRegionList_.DeleteRegion(region); + recentPinnedRegionList_.PrependRegion(region, RegionDesc::RegionType::RECENT_PINNED_REGION); + } else { + ASSERT(false); + } +} + +void RegionManager::UnpinObject(uintptr_t obj) +{ + RegionDesc* region = RegionDesc::GetRegionDescAt(reinterpret_cast(obj)); + if (region->GetRegionType() == RegionDesc::RegionType::RECENT_PINNED_REGION) { + recentPinnedRegionList_.DeleteRegion(region); + tlToRegionList_.PrependRegion(region, RegionDesc::RegionType::THREAD_LOCAL_REGION); + } else if (region->GetRegionType() == RegionDesc::RegionType::FULL_PINNED_REGION) { + oldPinnedRegionList_.DeleteRegion(region); + tlToRegionList_.PrependRegion(region, RegionDesc::RegionType::THREAD_LOCAL_REGION); + } else { + ASSERT(false); + } +} + uintptr_t RegionManager::GetLastRegionForTest() { std::lock_guard guard(recentFullRegionList_.GetListMutex()); diff --git a/common_components/common_runtime/src/heap/allocator/region_manager.h b/common_components/common_runtime/src/heap/allocator/region_manager.h index 09a06cf8d6..aa44b449fd 100755 --- a/common_components/common_runtime/src/heap/allocator/region_manager.h +++ b/common_components/common_runtime/src/heap/allocator/region_manager.h @@ -144,6 +144,9 @@ public: uintptr_t AllocLargeRegion(size_t size); uintptr_t AllocJitFortRegion(size_t size); + void PinObject(uintptr_t obj); + void UnpinObject(uintptr_t obj); + // ONLY used for UT uintptr_t GetLastRegionForTest(); uintptr_t GetLastLargeRegionForTest(); diff --git a/common_components/heap/heap_allocator.cpp b/common_components/heap/heap_allocator.cpp index ac7f0cd0e0..a43feaa196 100755 --- a/common_components/heap/heap_allocator.cpp +++ b/common_components/heap/heap_allocator.cpp @@ -93,4 +93,16 @@ Address HeapAllocator::AllocateLargeRegion(size_t size) return manager.AllocLargeRegion(size); } +void HeapAllocator::PinObject(Address obj) +{ + RegionManager& manager = reinterpret_cast(Heap::GetHeap().GetAllocator()).GetRegionManager(); + return manager.PinObject(obj); +} + +void HeapAllocator::UnpinObject(Address obj) +{ + RegionManager& manager = reinterpret_cast(Heap::GetHeap().GetAllocator()).GetRegionManager(); + return manager.UnpinObject(obj); +} + } // namespace panda -- Gitee