HeapConstants.h 4.4 KB

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