diff --git a/common_components/common_runtime/src/heap/allocator/alloc_buffer.h b/common_components/common_runtime/src/heap/allocator/alloc_buffer.h index 7d7c6871cc3b1f7182708280090ed68fcd152c40..6090987677ddcb0aeb7f55d5b399fe9e253945d1 100755 --- a/common_components/common_runtime/src/heap/allocator/alloc_buffer.h +++ b/common_components/common_runtime/src/heap/allocator/alloc_buffer.h @@ -41,6 +41,7 @@ public: } DLOG(REGION, "AllocBuffer clear tlRegion %p@%#zx+%zu", tlRegion_, tlRegion_->GetRegionStart(), tlRegion_->GetRegionAllocatedSize()); + tlRegion_->UnlinkExternalTLAB(); tlRegion_ = RegionDesc::NullRegion(); } void RefershRegion(); diff --git a/common_components/common_runtime/src/heap/allocator/region_desc.h b/common_components/common_runtime/src/heap/allocator/region_desc.h index 9d419ce7d2ba38839d30fc7a8bca88d5805852a3..360e68ab7f05e2d37b3bd18539b6c27cbac7c0c9 100755 --- a/common_components/common_runtime/src/heap/allocator/region_desc.h +++ b/common_components/common_runtime/src/heap/allocator/region_desc.h @@ -106,6 +106,7 @@ public: metadata.freeSlot = nullptr; metadata.regionEnd = reinterpret_cast(nullptr); metadata.toSpaceRegion = false; + metadata.linkedExternalTlab = false; } static inline RegionDesc* NullRegion() { @@ -480,6 +481,10 @@ public: } } + uintptr_t GetRegionMeta() { + return reinterpret_cast(&metadata); + } + static void InitFreeRegion(size_t unitIdx, size_t nUnit) { RegionDesc* region = reinterpret_cast(RegionDesc::UnitInfo::GetUnitInfo(unitIdx)); @@ -895,6 +900,14 @@ public: metadata.prevRegionIdx = static_cast(prevIdx); } + void LinkExternalTLAB() { + metadata.linkedExternalTlab = true; + } + + void UnlinkExternalTLAB() { + metadata.linkedExternalTlab = false; + } + RegionDesc* GetNextRegion() const { if (UNLIKELY_CC(metadata.nextRegionIdx == NULLPTR_IDX)) { @@ -1008,6 +1021,7 @@ private: uint32_t liveByteCount; int32_t rawPointerObjectCount; + bool linkedExternalTlab; }; union { @@ -1149,6 +1163,7 @@ private: metadata.liveByteCount = 0; metadata.liveInfo = nullptr; metadata.freeSlot = nullptr; + metadata.linkedExternalTlab = false; SetRegionType(RegionType::FREE_REGION); SetUnitRole(uClass); ClearTraceCopyFixLine(); 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 8e16ab0b3dc86bb3fbb0e7dfa8128e720ed43936..5cd4fd3e684c2227d0f2ad6c4aff7a7c8969b0f5 100755 --- a/common_components/common_runtime/src/heap/allocator/region_manager.cpp +++ b/common_components/common_runtime/src/heap/allocator/region_manager.cpp @@ -700,6 +700,20 @@ uintptr_t RegionManager::AllocRegion() return start; } +uintptr_t RegionManager::AllocBufferRegion() +{ + AllocationBuffer* allocBuffer = AllocationBuffer::GetOrCreateAllocBuffer(); + RegionDesc* region = AllocateThreadLocalRegion(); + if (UNLIKELY_CC(region == nullptr)) { + return RegionDesc::NullRegion()->GetRegionMeta(); + } + + allocBuffer->SetRegion(region); + region->LinkExternalTLAB(); + + return region->GetRegionMeta(); +} + uintptr_t RegionManager::AllocPinnedRegion() { RegionDesc* region = TakeRegion(maxUnitCountPerRegion_, RegionDesc::UnitRole::SMALL_SIZED_UNITS, false, false); 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 5a43e0dee064be2f40555e5146643c3f99ac0619..a9e9f7194cea9c91d91514439b3a8ff23d0cf77c 100755 --- a/common_components/common_runtime/src/heap/allocator/region_manager.h +++ b/common_components/common_runtime/src/heap/allocator/region_manager.h @@ -140,6 +140,7 @@ public: // only used for deserialize allocation, allocate one region and regard it as full region // adapt for concurrent gc uintptr_t AllocRegion(); + uintptr_t AllocBufferRegion(); uintptr_t AllocPinnedRegion(); uintptr_t AllocLargeRegion(size_t size); uintptr_t AllocJitFortRegion(size_t size); diff --git a/common_components/common_runtime/src/heap/allocator/region_space.cpp b/common_components/common_runtime/src/heap/allocator/region_space.cpp index 1b77acac44feca0c00aa0ce97d1defcff2eb904a..20c5c94410d7e5951d8efa8daf078e4bf0e1a0ca 100755 --- a/common_components/common_runtime/src/heap/allocator/region_space.cpp +++ b/common_components/common_runtime/src/heap/allocator/region_space.cpp @@ -194,6 +194,7 @@ AllocationBuffer::~AllocationBuffer() RegionSpace& theAllocator = reinterpret_cast(Heap::GetHeap().GetAllocator()); RegionManager& manager = theAllocator.GetRegionManager(); manager.RemoveThreadLocalRegion(tlRegion_); + tlRegion_->UnlinkExternalTLAB(); manager.EnlistFullThreadLocalRegion(tlRegion_); tlRegion_ = RegionDesc::NullRegion(); } @@ -263,6 +264,7 @@ HeapAddress AllocationBuffer::AllocateImpl(size_t totalSize, AllocType allocType // allocation failed because region is full. if (tlRegion_->IsThreadLocalRegion()) { manager.RemoveThreadLocalRegion(tlRegion_); + tlRegion_->UnlinkExternalTLAB(); manager.EnlistFullThreadLocalRegion(tlRegion_); tlRegion_ = RegionDesc::NullRegion(); } diff --git a/common_components/heap/heap_allocator.cpp b/common_components/heap/heap_allocator.cpp index ac7f0cd0e044957690d64a14629c49b42d933b74..ccf97f084d33eb3e4d664f96254f65b53a7d9429 100755 --- a/common_components/heap/heap_allocator.cpp +++ b/common_components/heap/heap_allocator.cpp @@ -81,6 +81,12 @@ Address HeapAllocator::AllocateRegion() return manager.AllocRegion(); } +Address HeapAllocator::AllocateRegionBuffer() +{ + RegionManager& manager = reinterpret_cast(Heap::GetHeap().GetAllocator()).GetRegionManager(); + return manager.AllocBufferRegion(); +} + Address HeapAllocator::AllocatePinnedRegion() { RegionManager& manager = reinterpret_cast(Heap::GetHeap().GetAllocator()).GetRegionManager();