HeapConstants.h 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. class HeapConstants
  6. {
  7. public:
  8. #if defined(_M_IX86_OR_ARM32)
  9. static const uint MaxSmallObjectSize = 512;
  10. #else
  11. static const uint MaxSmallObjectSize = 768;
  12. #endif
  13. #if SMALLBLOCK_MEDIUM_ALLOC
  14. static const uint MaxMediumObjectSize = 8 * 1024; // Maximum medium object size is 8K
  15. #else
  16. static const uint MaxMediumObjectSize = 9216;
  17. #endif
  18. static const uint ObjectAllocationShift = 4; // 16
  19. static const uint ObjectGranularity = 1 << ObjectAllocationShift;
  20. static const uint BucketCount = (MaxSmallObjectSize >> ObjectAllocationShift);
  21. #ifdef BUCKETIZE_MEDIUM_ALLOCATIONS
  22. static const uint MediumObjectGranularity = 256;
  23. static const uint MediumBucketCount = (MaxMediumObjectSize - MaxSmallObjectSize) / MediumObjectGranularity;
  24. #endif
  25. };
  26. ///
  27. /// BlockAttributes are used to determine the allocation characteristics of a heap block
  28. /// These include the number of pages to allocate, the object capacity of the block
  29. /// and the shape of the object's bit vectors
  30. /// Since the constants here are used while generating the ValidPointerMap constants
  31. /// please remember to regenerate the ValidPointersMap by first switching to a dynamic VPM
  32. /// as controlled by the USE_STATIC_VPM in HeapInfo.h, and then running GenValidPointers.cmd
  33. ///
  34. class SmallAllocationBlockAttributes
  35. {
  36. public:
  37. static const size_t MinObjectSize = HeapConstants::ObjectGranularity;
  38. #if defined(_M_IX86_OR_ARM32)
  39. static const size_t PageCount = 2;
  40. #else
  41. static const size_t PageCount = 4;
  42. #endif
  43. static const size_t BitVectorCount = ((PageCount * AutoSystemInfo::PageSize) / HeapConstants::ObjectGranularity);
  44. static const ushort MaxAddressBit = BitVectorCount - 1;
  45. static const uint BucketCount = HeapConstants::BucketCount;
  46. static const size_t BucketGranularity = HeapConstants::ObjectGranularity;
  47. static const uint MaxObjectSize = HeapConstants::MaxSmallObjectSize;
  48. static const uint MaxObjectCount = PageCount * AutoSystemInfo::PageSize / HeapConstants::ObjectGranularity;
  49. static const uint MaxSmallObjectCount = MaxObjectCount;
  50. static const uint ObjectCountPerPage = AutoSystemInfo::PageSize / HeapConstants::ObjectGranularity;
  51. // This is there for RecyclerSweep to distinguish which bucket index to use
  52. static const bool IsSmallBlock = true;
  53. static const bool IsMediumBlock = false;
  54. static const bool IsLargeBlock = false;
  55. static BOOL IsAlignedObjectSize(size_t sizeCat);
  56. };
  57. class MediumAllocationBlockAttributes
  58. {
  59. public:
  60. static const size_t PageCount = 8;
  61. static const size_t MinObjectSize = HeapConstants::MaxSmallObjectSize;
  62. static const ushort BitVectorCount = ((PageCount * AutoSystemInfo::PageSize) / HeapConstants::ObjectGranularity);
  63. static const size_t MaxAddressBit = (BitVectorCount - 1);
  64. static const uint MaxObjectSize = HeapConstants::MaxMediumObjectSize;
  65. static const uint BucketCount = HeapConstants::MediumBucketCount;
  66. static const size_t BucketGranularity = HeapConstants::MediumObjectGranularity;
  67. static const uint MaxObjectCount = PageCount * AutoSystemInfo::PageSize / (MinObjectSize + BucketGranularity);
  68. static const uint MaxSmallObjectCount = PageCount * AutoSystemInfo::PageSize / HeapConstants::ObjectGranularity;
  69. static const uint ObjectCountPerPage = AutoSystemInfo::PageSize / MinObjectSize;
  70. // This is there for RecyclerSweep to distinguish which bucket index to use
  71. static const bool IsSmallBlock = false;
  72. static const bool IsMediumBlock = true;
  73. static const bool IsLargeBlock = false;
  74. static BOOL IsAlignedObjectSize(size_t sizeCat);
  75. };
  76. class LargeAllocationBlockAttributes
  77. {
  78. public:
  79. // This is there for RecyclerSweep to distinguish which bucket index to use
  80. static const bool IsSmallBlock = false;
  81. static const bool IsMediumBlock = false;
  82. static const bool IsLargeBlock = true;
  83. };