X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/93a3786624b2768d89bfa27e46598dc64e2fb70a..40a37d088818fc2fbeba2ef850dbcaaf294befbf:/heap/BlockAllocator.h?ds=sidebyside diff --git a/heap/BlockAllocator.h b/heap/BlockAllocator.h index 8ac5d2f..eb6867f 100644 --- a/heap/BlockAllocator.h +++ b/heap/BlockAllocator.h @@ -26,26 +26,26 @@ #ifndef BlockAllocator_h #define BlockAllocator_h +#include "GCActivityCallback.h" #include "HeapBlock.h" #include "Region.h" +#include #include #include #include #include #include -#if PLATFORM(IOS) -#include "GCActivityCallback.h" -#endif - namespace JSC { class BlockAllocator; +class CodeBlock; class CopiedBlock; class CopyWorkListSegment; +template class GCArraySegment; class HandleBlock; +class JSCell; class VM; -class MarkStackSegment; class MarkedBlock; class WeakBlock; @@ -62,10 +62,12 @@ public: template void deallocate(T*); template void deallocateCustomSize(T*); + JS_EXPORT_PRIVATE void releaseFreeRegions(); + private: - void waitForRelativeTimeWhileHoldingLock(double relative); - void waitForRelativeTime(double relative); + void waitForDuration(std::chrono::milliseconds); + friend ThreadIdentifier createBlockFreeingThread(BlockAllocator*); void blockFreeingThreadMain(); static void blockFreeingThreadStartFunc(void* heap); @@ -90,14 +92,13 @@ private: DeadBlock* tryAllocateFromRegion(RegionSet&, DoublyLinkedList&, size_t&); bool allRegionSetsAreEmpty() const; - void releaseFreeRegions(); template RegionSet& regionSetFor(); SuperRegion m_superRegion; RegionSet m_copiedRegionSet; RegionSet m_markedRegionSet; - // WeakBlocks and MarkStackSegments use the same RegionSet since they're the same size. + // WeakBlocks and GCArraySegments use the same RegionSet since they're the same size. RegionSet m_fourKBBlockRegionSet; RegionSet m_workListRegionSet; @@ -107,8 +108,8 @@ private: bool m_isCurrentlyAllocating; bool m_blockFreeingThreadShouldQuit; SpinLock m_regionLock; - Mutex m_emptyRegionConditionLock; - ThreadCondition m_emptyRegionCondition; + std::mutex m_emptyRegionConditionMutex; + std::condition_variable m_emptyRegionCondition; ThreadIdentifier m_blockFreeingThread; }; @@ -201,14 +202,12 @@ inline void BlockAllocator::deallocate(T* block) } if (shouldWakeBlockFreeingThread) { - MutexLocker mutexLocker(m_emptyRegionConditionLock); - m_emptyRegionCondition.signal(); + std::lock_guard lock(m_emptyRegionConditionMutex); + m_emptyRegionCondition.notify_one(); } -#if PLATFORM(IOS) - if (!GCActivityCallback::s_shouldCreateGCTimer); + if (!m_blockFreeingThread) releaseFreeRegions(); -#endif } template @@ -220,77 +219,27 @@ inline void BlockAllocator::deallocateCustomSize(T* block) region->destroy(); } -template <> -inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor() -{ - return m_copiedRegionSet; -} - -template <> -inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor() -{ - return m_markedRegionSet; -} - -template <> -inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor() -{ - return m_fourKBBlockRegionSet; -} - -template <> -inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor() -{ - return m_fourKBBlockRegionSet; -} - -template <> -inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor() -{ - return m_workListRegionSet; -} - -template <> -inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor() -{ - return m_fourKBBlockRegionSet; -} - -template <> -inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor >() -{ - return m_copiedRegionSet; -} - -template <> -inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor >() -{ - return m_markedRegionSet; -} - -template <> -inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor >() -{ - return m_fourKBBlockRegionSet; -} - -template <> -inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor >() -{ - return m_fourKBBlockRegionSet; -} - -template <> -inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor >() -{ - return m_workListRegionSet; -} - -template <> -inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor >() -{ - return m_fourKBBlockRegionSet; -} +#define REGION_SET_FOR(blockType, set) \ + template <> \ + inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor() \ + { \ + return set; \ + } \ + template <> \ + inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor>() \ + { \ + return set; \ + } \ + +REGION_SET_FOR(MarkedBlock, m_markedRegionSet); +REGION_SET_FOR(CopiedBlock, m_copiedRegionSet); +REGION_SET_FOR(WeakBlock, m_fourKBBlockRegionSet); +REGION_SET_FOR(GCArraySegment, m_fourKBBlockRegionSet); +REGION_SET_FOR(GCArraySegment, m_fourKBBlockRegionSet); +REGION_SET_FOR(CopyWorkListSegment, m_workListRegionSet); +REGION_SET_FOR(HandleBlock, m_fourKBBlockRegionSet); + +#undef REGION_SET_FOR template inline BlockAllocator::RegionSet& BlockAllocator::regionSetFor()