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 7957627b8d295efc2db49d1f44f8605cfc06a5e5..001a50a7df0f83503c8dddfea5e55a328c0e72c0 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 09a06cf8d6f2d52d5bf7697e496bf5e5cb265e8a..aa44b449fdde1618e1425260df0f611f1099312a 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 ac7f0cd0e044957690d64a14629c49b42d933b74..a43feaa196e0b1963ba718d9dd01b548d03757fd 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