| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- namespace Memory
- {
- template <class THeapBlockType>
- class SmallFinalizableHeapBucketBaseT : public SmallNormalHeapBucketBase<THeapBlockType>
- {
- typedef SmallNormalHeapBucketBase<THeapBlockType> BaseT;
- public:
- typedef typename THeapBlockType::HeapBlockAttributes TBlockAttributes;
- SmallFinalizableHeapBucketBaseT();
- ~SmallFinalizableHeapBucketBaseT();
- void DisposeObjects();
- void TransferDisposedObjects();
- void FinalizeAllObjects();
- static void FinalizeHeapBlockList(THeapBlockType * list);
- #ifdef DUMP_FRAGMENTATION_STATS
- void AggregateBucketStats(HeapBucketStats& stats);
- #endif
- protected:
- void EnumerateObjects(ObjectInfoBits infoBits, void (*CallBackFunction)(void * address, size_t size));
- friend class HeapBucket;
- template <class TBlockAttributes>
- friend class HeapBucketGroup;
- void ResetMarks(ResetMarkFlags flags);
- void Sweep(RecyclerSweep& recyclerSweep);
- #if DBG || defined(RECYCLER_SLOW_CHECK_ENABLED)
- size_t GetNonEmptyHeapBlockCount(bool checkCount) const;
- #endif
- #ifdef RECYCLER_SLOW_CHECK_ENABLED
- size_t Check();
- #endif
- #ifdef RECYCLER_MEMORY_VERIFY
- void Verify();
- #endif
- #ifdef RECYCLER_VERIFY_MARK
- void VerifyMark();
- #endif
- #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
- friend class ::ScriptMemoryDumper;
- #endif
- template <typename TBlockType>
- friend class HeapBucketT;
- protected:
- THeapBlockType * pendingDisposeList; // list of block that has finalizable object that needs to be disposed
- #if DBG || defined(RECYCLER_SLOW_CHECK_ENABLED)
- THeapBlockType * tempPendingDisposeList;
- #endif
- };
- template <class TBlockAttributes>
- class SmallFinalizableHeapBucketT : public SmallFinalizableHeapBucketBaseT<SmallFinalizableHeapBlockT<TBlockAttributes> >
- {
- };
- #ifdef RECYCLER_WRITE_BARRIER
- template <class TBlockAttributes>
- class SmallFinalizableWithBarrierHeapBucketT : public SmallFinalizableHeapBucketBaseT<SmallFinalizableWithBarrierHeapBlockT<TBlockAttributes> >
- {
- };
- #endif
- typedef SmallFinalizableHeapBucketT<MediumAllocationBlockAttributes> MediumFinalizableHeapBucket;
- typedef SmallFinalizableHeapBucketT<SmallAllocationBlockAttributes> SmallFinalizableHeapBucket;
- #ifdef RECYCLER_WRITE_BARRIER
- typedef SmallFinalizableWithBarrierHeapBucketT<MediumAllocationBlockAttributes> MediumFinalizableWithBarrierHeapBucket;
- typedef SmallFinalizableWithBarrierHeapBucketT<SmallAllocationBlockAttributes> SmallFinalizableWithBarrierHeapBucket;
- #endif
- // GC-TODO: Move this away
- template <ObjectInfoBits attributes, class TBlockAttributes>
- class SmallHeapBlockType
- {
- public:
- CompileAssert(attributes & FinalizeBit);
- typedef SmallFinalizableHeapBlockT<TBlockAttributes> BlockType;
- typedef SmallFinalizableHeapBucketT<TBlockAttributes> BucketType;
- };
- template <>
- class SmallHeapBlockType<LeafBit, SmallAllocationBlockAttributes>
- {
- public:
- typedef SmallLeafHeapBlock BlockType;
- typedef SmallLeafHeapBucketT<SmallAllocationBlockAttributes> BucketType;
- };
- template <>
- class SmallHeapBlockType<NoBit, SmallAllocationBlockAttributes>
- {
- public:
- typedef SmallNormalHeapBlock BlockType;
- typedef SmallNormalHeapBucket BucketType;
- };
- #ifdef RECYCLER_WRITE_BARRIER
- template <>
- class SmallHeapBlockType<WithBarrierBit, SmallAllocationBlockAttributes>
- {
- public:
- typedef SmallNormalWithBarrierHeapBlock BlockType;
- typedef SmallNormalWithBarrierHeapBucket BucketType;
- };
- template <>
- class SmallHeapBlockType<(ObjectInfoBits)(WithBarrierBit|LeafBit), SmallAllocationBlockAttributes>
- {
- public:
- typedef SmallLeafHeapBlock BlockType;
- typedef SmallLeafHeapBucketT<SmallAllocationBlockAttributes> BucketType;
- };
- template <>
- class SmallHeapBlockType<FinalizableWithBarrierBit, SmallAllocationBlockAttributes>
- {
- public:
- typedef SmallFinalizableWithBarrierHeapBlock BlockType;
- typedef SmallFinalizableWithBarrierHeapBucket BucketType;
- };
- #endif
- #if SMALLBLOCK_MEDIUM_ALLOC
- template <>
- class SmallHeapBlockType<FinalizeBit, MediumAllocationBlockAttributes>
- {
- public:
- typedef MediumFinalizableHeapBlock BlockType;
- typedef MediumFinalizableHeapBucket BucketType;
- };
- template <>
- class SmallHeapBlockType<LeafBit, MediumAllocationBlockAttributes>
- {
- public:
- typedef MediumLeafHeapBlock BlockType;
- typedef SmallLeafHeapBucketT<MediumAllocationBlockAttributes> BucketType;
- };
- template <>
- class SmallHeapBlockType<NoBit, MediumAllocationBlockAttributes>
- {
- public:
- typedef MediumNormalHeapBlock BlockType;
- typedef MediumNormalHeapBucket BucketType;
- };
- #ifdef RECYCLER_WRITE_BARRIER
- template <>
- class SmallHeapBlockType<WithBarrierBit, MediumAllocationBlockAttributes>
- {
- public:
- typedef MediumNormalWithBarrierHeapBlock BlockType;
- typedef MediumNormalWithBarrierHeapBucket BucketType;
- };
- template <>
- class SmallHeapBlockType<(ObjectInfoBits)(WithBarrierBit | LeafBit), MediumAllocationBlockAttributes>
- {
- public:
- typedef MediumLeafHeapBlock BlockType;
- typedef SmallLeafHeapBucketT<MediumAllocationBlockAttributes> BucketType;
- };
- template <>
- class SmallHeapBlockType<FinalizableWithBarrierBit, MediumAllocationBlockAttributes>
- {
- public:
- typedef MediumFinalizableWithBarrierHeapBlock BlockType;
- typedef MediumFinalizableWithBarrierHeapBucket BucketType;
- };
- #endif
- #endif
- template <class TBlockAttributes>
- class HeapBucketGroup
- {
- template <ObjectInfoBits objectAttributes>
- class BucketGetter
- {
- public:
- typedef typename SmallHeapBlockType<objectAttributes, TBlockAttributes>::BucketType BucketType;
- static BucketType& GetBucket(HeapBucketGroup<TBlockAttributes> * heapBucketGroup)
- {
- CompileAssert(objectAttributes & FinalizeBit);
- return heapBucketGroup->finalizableHeapBucket;
- }
- };
- template <>
- class BucketGetter<LeafBit>
- {
- public:
- typedef typename SmallHeapBlockType<LeafBit, TBlockAttributes>::BucketType BucketType;
- static BucketType& GetBucket(HeapBucketGroup<TBlockAttributes> * heapBucketGroup)
- {
- return heapBucketGroup->leafHeapBucket;
- }
- };
- template <>
- class BucketGetter<NoBit>
- {
- public:
- typedef typename SmallHeapBlockType<NoBit, TBlockAttributes>::BucketType BucketType;
- static BucketType& GetBucket(HeapBucketGroup<TBlockAttributes> * heapBucketGroup)
- {
- return heapBucketGroup->heapBucket;
- }
- };
- template <>
- class BucketGetter<(ObjectInfoBits)(FinalizeBit | LeafBit)>
- {
- public:
- typedef typename SmallHeapBlockType<(ObjectInfoBits)(FinalizeBit | LeafBit), TBlockAttributes>::BucketType BucketType;
- static BucketType& GetBucket(HeapBucketGroup<TBlockAttributes> * heapBucketGroup)
- {
- // TODO: SWB implemente finalizable leaf bucket
- return heapBucketGroup->finalizableHeapBucket;
- }
- };
- #ifdef RECYCLER_WRITE_BARRIER
- template <>
- class BucketGetter<WithBarrierBit>
- {
- public:
- typedef typename SmallHeapBlockType<WithBarrierBit, TBlockAttributes>::BucketType BucketType;
- static BucketType& GetBucket(HeapBucketGroup<TBlockAttributes> * heapBucketGroup)
- {
- return heapBucketGroup->smallNormalWithBarrierHeapBucket;
- }
- };
- template <>
- class BucketGetter<(ObjectInfoBits)(WithBarrierBit | LeafBit)>
- {
- public:
- typedef typename SmallHeapBlockType<(ObjectInfoBits)(WithBarrierBit | LeafBit), TBlockAttributes>::BucketType BucketType;
- static BucketType& GetBucket(HeapBucketGroup<TBlockAttributes> * heapBucketGroup)
- {
- // WithBarrierBit | LeafBit combination should not exist, this is only for compilation purpose
- Assert(false);
- return heapBucketGroup->leafHeapBucket;
- }
- };
- template <>
- class BucketGetter<FinalizableWithBarrierBit>
- {
- public:
- typedef typename SmallHeapBlockType<FinalizableWithBarrierBit, TBlockAttributes>::BucketType BucketType;
- static BucketType& GetBucket(HeapBucketGroup<TBlockAttributes> * heapBucketGroup)
- {
- return heapBucketGroup->smallFinalizableWithBarrierHeapBucket;
- }
- };
- #endif
- public:
- template <ObjectInfoBits objectAttributes>
- typename SmallHeapBlockType<objectAttributes, TBlockAttributes>::BucketType& GetBucket()
- {
- return BucketGetter<objectAttributes>::GetBucket(this);
- }
- void Initialize(HeapInfo * heapInfo, uint sizeCat);
- void ResetMarks(ResetMarkFlags flags);
- void ScanInitialImplicitRoots(Recycler * recycler);
- void ScanNewImplicitRoots(Recycler * recycler);
- void Sweep(RecyclerSweep& recyclerSweep);
- uint Rescan(Recycler * recycler, RescanFlags flags);
- #if ENABLE_CONCURRENT_GC
- void SweepPendingObjects(RecyclerSweep& recyclerSweep);
- #endif
- #if ENABLE_PARTIAL_GC
- void SweepPartialReusePages(RecyclerSweep& recyclerSweep);
- void FinishPartialCollect(RecyclerSweep * recyclerSweep);
- #endif
- #if ENABLE_CONCURRENT_GC
- void PrepareSweep();
- void SetupBackgroundSweep(RecyclerSweep& recyclerSweep);
- void TransferPendingEmptyHeapBlocks(RecyclerSweep& recyclerSweep);
- #endif
- void SweepFinalizableObjects(RecyclerSweep& recyclerSweep);
- void DisposeObjects();
- void TransferDisposedObjects();
- void EnumerateObjects(ObjectInfoBits infoBits, void (*CallBackFunction)(void * address, size_t size));
- void FinalizeAllObjects();
- static unsigned int GetHeapBucketOffset() { return offsetof(HeapBucketGroup<TBlockAttributes>, heapBucket); }
- #if DBG || defined(RECYCLER_SLOW_CHECK_ENABLED)
- size_t GetNonEmptyHeapBlockCount(bool checkCount) const;
- size_t GetEmptyHeapBlockCount() const;
- #endif
- #ifdef RECYCLER_SLOW_CHECK_ENABLED
- size_t Check();
- #endif
- #ifdef RECYCLER_MEMORY_VERIFY
- void Verify();
- #endif
- #ifdef RECYCLER_VERIFY_MARK
- void VerifyMark();
- #endif
- #if DBG
- bool AllocatorsAreEmpty();
- #endif
- private:
- SmallNormalHeapBucketT<TBlockAttributes> heapBucket;
- SmallLeafHeapBucketT<TBlockAttributes> leafHeapBucket;
- SmallFinalizableHeapBucketT<TBlockAttributes> finalizableHeapBucket;
- #ifdef RECYCLER_WRITE_BARRIER
- SmallNormalWithBarrierHeapBucketT<TBlockAttributes> smallNormalWithBarrierHeapBucket;
- SmallFinalizableWithBarrierHeapBucketT<TBlockAttributes> smallFinalizableWithBarrierHeapBucket;
- #endif
- };
- extern template class HeapBucketGroup<SmallAllocationBlockAttributes>;
- extern template class HeapBucketGroup<MediumAllocationBlockAttributes>;
- }
|