HeapInfoManager.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. namespace Memory
  7. {
  8. class RecyclerSweepManager;
  9. class HeapInfoManager
  10. {
  11. public:
  12. HeapInfoManager(AllocationPolicyManager * policyManager, Js::ConfigFlagsTable& configFlagsTable, IdleDecommitPageAllocator * leafPageAllocator);
  13. HeapInfo * GetDefaultHeap()
  14. {
  15. return &defaultHeap;
  16. }
  17. void Initialize(Recycler * recycler
  18. #ifdef RECYCLER_PAGE_HEAP
  19. , PageHeapMode pageheapmode = PageHeapMode::PageHeapModeOff
  20. , bool captureAllocCallStack = false
  21. , bool captureFreeCallStack = false
  22. #endif
  23. );
  24. #if defined(PROFILE_RECYCLER_ALLOC) || defined(RECYCLER_MEMORY_VERIFY) || defined(MEMSPECT_TRACKING) || defined(ETW_MEMORY_TRACKING)
  25. void Initialize(Recycler * recycler, void(*trackNativeAllocCallBack)(Recycler *, void *, size_t)
  26. #ifdef RECYCLER_PAGE_HEAP
  27. , PageHeapMode pageheapmode = PageHeapMode::PageHeapModeOff
  28. , bool captureAllocCallStack = false
  29. , bool captureFreeCallStack = false
  30. #endif
  31. );
  32. #endif
  33. bool IsPageHeapEnabled();
  34. void ScanInitialImplicitRoots();
  35. void ScanNewImplicitRoots();
  36. void ResetMarks(ResetMarkFlags flags);
  37. size_t Rescan(RescanFlags flags);
  38. void FinalizeAndSweep(RecyclerSweepManager& recyclerSweepManager, bool concurrent);
  39. void SweepSmallNonFinalizable(RecyclerSweepManager& recyclerSweepManager);
  40. #if ENABLE_PARTIAL_GC || ENABLE_CONCURRENT_GC
  41. void SweepPendingObjects(RecyclerSweepManager& recyclerSweepManager);
  42. #endif
  43. #if ENABLE_PARTIAL_GC
  44. void SweepPartialReusePages(RecyclerSweepManager& recyclerSweepManager);
  45. void FinishPartialCollect(RecyclerSweepManager * recyclerSweepManager);
  46. #endif
  47. #if ENABLE_CONCURRENT_GC
  48. void PrepareSweep();
  49. #if ENABLE_ALLOCATIONS_DURING_CONCURRENT_SWEEP
  50. void StartAllocationsDuringConcurrentSweep();
  51. bool DoTwoPassConcurrentSweepPreCheck();
  52. void FinishSweepPrep(RecyclerSweepManager& recyclerSweep);
  53. void FinishConcurrentSweepPass1(RecyclerSweepManager& recyclerSweep);
  54. void FinishConcurrentSweep();
  55. #endif
  56. void ConcurrentTransferSweptObjects(RecyclerSweepManager& recyclerSweepManager);
  57. #if ENABLE_PARTIAL_GC
  58. void ConcurrentPartialTransferSweptObjects(RecyclerSweepManager& recyclerSweepManager);
  59. #endif
  60. #endif
  61. void DisposeObjects();
  62. void TransferDisposedObjects();
  63. void EnumerateObjects(ObjectInfoBits infoBits, void(*CallBackFunction)(void * address, size_t size));
  64. #if DBG
  65. bool AllocatorsAreEmpty();
  66. #endif
  67. #ifdef RECYCLER_FINALIZE_CHECK
  68. size_t GetFinalizeCount();
  69. #endif
  70. #ifdef RECYCLER_SLOW_CHECK_ENABLED
  71. void Check();
  72. #endif
  73. #if ENABLE_MEM_STATS
  74. void ReportMemStats(Recycler * recycler);
  75. #endif
  76. #ifdef RECYCLER_MEMORY_VERIFY
  77. void Verify();
  78. #endif
  79. #ifdef RECYCLER_VERIFY_MARK
  80. void VerifyMark();
  81. #endif
  82. // ==============================================================
  83. // Page allocator APIs
  84. // ==============================================================
  85. void Prime();
  86. void Close();
  87. void DecommitNow(bool all = true);
  88. void SuspendIdleDecommitNonLeaf();
  89. void ResumeIdleDecommitNonLeaf();
  90. void EnterIdleDecommit();
  91. IdleDecommitSignal LeaveIdleDecommit(bool allowTimer);
  92. #ifdef IDLE_DECOMMIT_ENABLED
  93. DWORD IdleDecommit();
  94. #endif
  95. #if DBG
  96. void ShutdownIdleDecommit();
  97. void ResetThreadId();
  98. void SetDisableThreadAccessCheck();
  99. #endif
  100. AllocationPolicyManager * GetAllocationPolicyManager();
  101. bool IsRecyclerPageAllocator(PageAllocator * pageAllocator);
  102. bool IsRecyclerLeafPageAllocator(PageAllocator * pageAllocator);
  103. bool IsRecyclerLargeBlockPageAllocator(PageAllocator * pageAllocator);
  104. #ifdef RECYCLER_WRITE_BARRIER
  105. bool IsRecyclerWithBarrierPageAllocator(PageAllocator * pageAllocator);
  106. #endif
  107. size_t GetUsedBytes();
  108. size_t GetReservedBytes();
  109. size_t GetCommittedBytes();
  110. size_t GetNumberOfSegments();
  111. #if ENABLE_BACKGROUND_PAGE_ZEROING
  112. void StartQueueZeroPage();
  113. void StopQueueZeroPage();
  114. void BackgroundZeroQueuedPages();
  115. void FlushBackgroundPages();
  116. void ZeroQueuedPages();
  117. #if DBG
  118. bool HasZeroQueuedPages();
  119. #endif
  120. #endif
  121. #if ENABLE_PARTIAL_GC || ENABLE_CONCURRENT_GC
  122. #ifdef RECYCLER_WRITE_WATCH
  123. void EnableWriteWatch();
  124. bool ResetWriteWatch();
  125. #if DBG
  126. size_t GetWriteWatchPageCount();
  127. #endif
  128. #endif
  129. #endif
  130. #ifdef RECYCLER_MEMORY_VERIFY
  131. void EnableVerify();
  132. #endif
  133. #ifdef RECYCLER_NO_PAGE_REUSE
  134. void DisablePageReuse();
  135. #endif
  136. #ifdef RECYCLER_PAGE_HEAP
  137. bool DoCaptureAllocCallStack();
  138. bool DoCaptureFreeCallStack();
  139. #endif
  140. private:
  141. template <class Fn>
  142. void ForEachHeapInfo(Fn fn);
  143. template <class Fn>
  144. void ForEachHeapInfo(RecyclerSweepManager& recyclerSweepManager, Fn fn);
  145. template <class Fn>
  146. void ForEachHeapInfo(RecyclerSweepManager * recyclerSweepManager, Fn fn);
  147. template <class Fn>
  148. bool AreAllHeapInfo(Fn fn);
  149. template <class Fn>
  150. bool IsAnyHeapInfo(Fn fn);
  151. friend class Recycler;
  152. friend class HeapBucket;
  153. friend class HeapBlockMap32;
  154. friend class LargeHeapBucket;
  155. template <typename TBlockType>
  156. friend class HeapBucketT;
  157. template <typename TBlockType>
  158. friend class SmallHeapBlockAllocator;
  159. template <typename TBlockAttributes>
  160. friend class SmallFinalizableHeapBucketT;
  161. template <typename TBlockAttributes>
  162. friend class SmallLeafHeapBucketBaseT;
  163. template <typename TBlockAttributes>
  164. friend class SmallHeapBlockT;
  165. template <typename TBlockAttributes>
  166. friend class SmallLeafHeapBlockT;
  167. template <typename TBlockAttributes>
  168. friend class SmallFinalizableHeapBlockT;
  169. #ifdef RECYCLER_VISITED_HOST
  170. template <typename TBlockAttributes>
  171. friend class SmallRecyclerVisitedHostHeapBlockT;
  172. #endif
  173. friend class LargeHeapBlock;
  174. friend class HeapInfo;
  175. friend class RecyclerSweepManager;
  176. HeapInfo defaultHeap;
  177. size_t uncollectedAllocBytes;
  178. size_t lastUncollectedAllocBytes;
  179. size_t uncollectedExternalBytes;
  180. uint pendingZeroPageCount;
  181. #if ENABLE_PARTIAL_GC
  182. size_t uncollectedNewPageCount;
  183. size_t unusedPartialCollectFreeBytes;
  184. #endif
  185. };
  186. }