RecyclerSweepManager.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. {
  10. public:
  11. #if ENABLE_PARTIAL_GC
  12. void BeginSweep(Recycler * recycler, size_t rescanRootBytes, bool adjustPartialHeuristics);
  13. #else
  14. void BeginSweep(Recycler * recycler);
  15. #endif
  16. void FinishSweep();
  17. void EndSweep();
  18. void ShutdownCleanup();
  19. bool IsBackground() const;
  20. bool HasSetupBackgroundSweep() const;
  21. #if ENABLE_CONCURRENT_GC
  22. void BackgroundSweep();
  23. void BeginBackground(bool forceForeground);
  24. void EndBackground();
  25. #if DBG || defined(RECYCLER_SLOW_CHECK_ENABLED)
  26. template <typename TBlockType> size_t GetHeapBlockCount(HeapBucketT<TBlockType> const * heapBucket);
  27. size_t GetPendingMergeNewHeapBlockCount(HeapInfo const * heapInfo);
  28. #endif
  29. #endif
  30. template <typename TBlockAttributes>
  31. void AddUnaccountedNewObjectAllocBytes(SmallHeapBlockT<TBlockAttributes> * smallHeapBlock);
  32. #if ENABLE_PARTIAL_GC
  33. bool InPartialCollect() const;
  34. void StartPartialCollectMode();
  35. bool DoPartialCollectMode();
  36. bool DoAdjustPartialHeuristics() const;
  37. bool AdjustPartialHeuristics();
  38. void SubtractSweepNewObjectAllocBytes(size_t newObjectExpectSweepByteCount);
  39. size_t GetNewObjectAllocBytes() const;
  40. size_t GetNewObjectFreeBytes() const;
  41. size_t GetPartialUnusedFreeByteCount() const;
  42. size_t GetPartialCollectSmallHeapBlockReuseMinFreeBytes() const;
  43. template <typename TBlockAttributes>
  44. void NotifyAllocableObjects(SmallHeapBlockT<TBlockAttributes> * smallHeapBlock);
  45. void AddUnusedFreeByteCount(uint expectedFreeByteCount);
  46. static const uint MinPartialUncollectedNewPageCount; // 4MB pages
  47. static const uint MaxPartialCollectRescanRootBytes; // 5MB
  48. #endif
  49. private:
  50. bool IsMemProtectMode() const;
  51. Recycler * recycler;
  52. RecyclerSweep defaultHeapRecyclerSweep;
  53. bool background;
  54. bool forceForeground;
  55. bool inPartialCollect;
  56. #if ENABLE_PARTIAL_GC
  57. bool adjustPartialHeuristics;
  58. size_t lastPartialUncollectedAllocBytes;
  59. size_t nextPartialUncollectedAllocBytes;
  60. // Sweep data for partial activation heuristic
  61. size_t rescanRootBytes;
  62. size_t reuseHeapBlockCount;
  63. size_t reuseByteCount;
  64. // Partial reuse Heuristic
  65. size_t partialCollectSmallHeapBlockReuseMinFreeBytes;
  66. // Data to update unusedPartialCollectFreeBytes
  67. size_t partialUnusedFreeByteCount;
  68. #if DBG
  69. bool partial;
  70. #endif
  71. #endif
  72. friend class HeapInfoManager;
  73. };
  74. #if DBG || defined(RECYCLER_SLOW_CHECK_ENABLED)
  75. template <typename TBlockType>
  76. size_t
  77. RecyclerSweepManager::GetHeapBlockCount(HeapBucketT<TBlockType> const * heapBucket)
  78. {
  79. return this->defaultHeapRecyclerSweep.GetHeapBlockCount(heapBucket);
  80. }
  81. #endif
  82. };