| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | #ifndef __GCCONFIG_H__ |
| 6 | #define __GCCONFIG_H__ |
| 7 | |
| 8 | // gcconfig.h - GC configuration management and retrieval. |
| 9 | // |
| 10 | // This file and the GCConfig class are designed to be the primary entry point |
| 11 | // for querying configuration information from within the GC. |
| 12 | |
| 13 | // GCConfigStringHolder is a wrapper around a configuration string obtained |
| 14 | // from the EE. Such strings must be disposed using GCToEEInterface::FreeStringConfigValue, |
| 15 | // so this class ensures that is done correctly. |
| 16 | // |
| 17 | // The name is unfortunately a little long, but "ConfigStringHolder" is already taken by the |
| 18 | // EE's config mechanism. |
| 19 | class GCConfigStringHolder |
| 20 | { |
| 21 | private: |
| 22 | const char* m_str; |
| 23 | |
| 24 | public: |
| 25 | // Constructs a new GCConfigStringHolder around a string obtained from |
| 26 | // GCToEEInterface::GetStringConfigValue. |
| 27 | explicit GCConfigStringHolder(const char* str) |
| 28 | : m_str(str) {} |
| 29 | |
| 30 | // No copy operators - this type cannot be copied. |
| 31 | GCConfigStringHolder(const GCConfigStringHolder&) = delete; |
| 32 | GCConfigStringHolder& operator=(const GCConfigStringHolder&) = delete; |
| 33 | |
| 34 | // This type is returned by-value by string config functions, so it |
| 35 | // requires a move constructor. |
| 36 | GCConfigStringHolder(GCConfigStringHolder&&) = default; |
| 37 | |
| 38 | // Frees a string config value by delegating to GCToEEInterface::FreeStringConfigValue. |
| 39 | ~GCConfigStringHolder() |
| 40 | { |
| 41 | if (m_str) |
| 42 | { |
| 43 | GCToEEInterface::FreeStringConfigValue(m_str); |
| 44 | } |
| 45 | |
| 46 | m_str = nullptr; |
| 47 | } |
| 48 | |
| 49 | // Retrieves the wrapped config string. |
| 50 | const char* Get() const { return m_str; } |
| 51 | }; |
| 52 | |
| 53 | // Each one of these keys produces a method on GCConfig with the name "Get{name}", where {name} |
| 54 | // is the first parameter of the *_CONFIG macros below. |
| 55 | #define GC_CONFIGURATION_KEYS \ |
| 56 | BOOL_CONFIG(ServerGC, "gcServer", false, "Whether we should be using Server GC") \ |
| 57 | BOOL_CONFIG(ConcurrentGC, "gcConcurrent", true, "Whether we should be using Concurrent GC") \ |
| 58 | BOOL_CONFIG(ConservativeGC, "gcConservative", false, "Enables/Disables conservative GC") \ |
| 59 | BOOL_CONFIG(ForceCompact, "gcForceCompact", false, \ |
| 60 | "When set to true, always do compacting GC") \ |
| 61 | BOOL_CONFIG(RetainVM, "GCRetainVM", false, \ |
| 62 | "When set we put the segments that should be deleted on a standby list (instead of " \ |
| 63 | "releasing them back to the OS) which will be considered to satisfy new segment requests"\ |
| 64 | " (note that the same thing can be specified via API which is the supported way)") \ |
| 65 | BOOL_CONFIG(StressMix, "GCStressMix", false, \ |
| 66 | "Specifies whether the GC mix mode is enabled or not") \ |
| 67 | BOOL_CONFIG(BreakOnOOM, "GCBreakOnOOM", false, \ |
| 68 | "Does a DebugBreak at the soonest time we detect an OOM") \ |
| 69 | BOOL_CONFIG(NoAffinitize, "GCNoAffinitize", false, \ |
| 70 | "If set, do not affinitize server GC threads") \ |
| 71 | BOOL_CONFIG(LogEnabled, "GCLogEnabled", false, \ |
| 72 | "Specifies if you want to turn on logging in GC") \ |
| 73 | BOOL_CONFIG(ConfigLogEnabled, "GCConfigLogEnabled", false, \ |
| 74 | "Specifies the name of the GC config log file") \ |
| 75 | BOOL_CONFIG(GCNumaAware, "GCNumaAware", true, "Enables numa allocations in the GC") \ |
| 76 | BOOL_CONFIG(GCCpuGroup, "GCCpuGroup", false, "Enables CPU groups in the GC") \ |
| 77 | INT_CONFIG(HeapVerifyLevel, "HeapVerify", HEAPVERIFY_NONE, \ |
| 78 | "When set verifies the integrity of the managed heap on entry and exit of each GC") \ |
| 79 | INT_CONFIG(LOHCompactionMode, "GCLOHCompact", 0, "Specifies the LOH compaction mode") \ |
| 80 | INT_CONFIG(LOHThreshold, "GCLOHThreshold", LARGE_OBJECT_SIZE, \ |
| 81 | "Specifies the size that will make objects go on LOH") \ |
| 82 | INT_CONFIG(BGCSpinCount, "BGCSpinCount", 140, "Specifies the bgc spin count") \ |
| 83 | INT_CONFIG(BGCSpin, "BGCSpin", 2, "Specifies the bgc spin time") \ |
| 84 | INT_CONFIG(HeapCount, "GCHeapCount", 0, "Specifies the number of server GC heaps") \ |
| 85 | INT_CONFIG(Gen0Size, "GCgen0size", 0, "Specifies the smallest gen0 size") \ |
| 86 | INT_CONFIG(SegmentSize, "GCSegmentSize", 0, "Specifies the managed heap segment size") \ |
| 87 | INT_CONFIG(LatencyMode, "GCLatencyMode", -1, \ |
| 88 | "Specifies the GC latency mode - batch, interactive or low latency (note that the same " \ |
| 89 | "thing can be specified via API which is the supported way") \ |
| 90 | INT_CONFIG(LatencyLevel, "GCLatencyLevel", 1, \ |
| 91 | "Specifies the GC latency level that you want to optimize for. Must be a number from 0" \ |
| 92 | "3. See documentation for more details on each level.") \ |
| 93 | INT_CONFIG(LogFileSize, "GCLogFileSize", 0, "Specifies the GC log file size") \ |
| 94 | INT_CONFIG(CompactRatio, "GCCompactRatio", 0, \ |
| 95 | "Specifies the ratio compacting GCs vs sweeping") \ |
| 96 | INT_CONFIG(GCHeapAffinitizeMask, "GCHeapAffinitizeMask", 0, \ |
| 97 | "Specifies processor mask for Server GC threads") \ |
| 98 | INT_CONFIG(GCHighMemPercent, "GCHighMemPercent", 0, \ |
| 99 | "The percent for GC to consider as high memory") \ |
| 100 | INT_CONFIG(GCProvModeStress, "GCProvModeStress", 0, \ |
| 101 | "Stress the provisional modes") \ |
| 102 | STRING_CONFIG(LogFile, "GCLogFile", "Specifies the name of the GC log file") \ |
| 103 | STRING_CONFIG(ConfigLogFile, "GCConfigLogFile", \ |
| 104 | "Specifies the name of the GC config log file") \ |
| 105 | STRING_CONFIG(MixLogFile, "GCMixLog", \ |
| 106 | "Specifies the name of the log file for GC mix statistics") |
| 107 | |
| 108 | // This class is responsible for retreiving configuration information |
| 109 | // for how the GC should operate. |
| 110 | class GCConfig |
| 111 | { |
| 112 | #define BOOL_CONFIG(name, unused_key, unused_default, unused_doc) \ |
| 113 | public: static bool Get##name(); \ |
| 114 | private: static bool s_##name; |
| 115 | #define INT_CONFIG(name, unused_key, unused_default, unused_doc) \ |
| 116 | public: static int64_t Get##name(); \ |
| 117 | private: static int64_t s_##name; |
| 118 | #define STRING_CONFIG(name, unused_key, unused_doc) \ |
| 119 | public: static GCConfigStringHolder Get##name(); |
| 120 | GC_CONFIGURATION_KEYS |
| 121 | #undef BOOL_CONFIG |
| 122 | #undef INT_CONFIG |
| 123 | #undef STRING_CONFIG |
| 124 | |
| 125 | public: |
| 126 | // Flags that may inhabit the number returned for the HeapVerifyLevel config option. |
| 127 | // Keep this in sync with vm\eeconfig.h if this ever changes. |
| 128 | enum HeapVerifyFlags { |
| 129 | HEAPVERIFY_NONE = 0, |
| 130 | HEAPVERIFY_GC = 1, // Verify the heap at beginning and end of GC |
| 131 | HEAPVERIFY_BARRIERCHECK = 2, // Verify the brick table |
| 132 | HEAPVERIFY_SYNCBLK = 4, // Verify sync block scanning |
| 133 | |
| 134 | // the following options can be used to mitigate some of the overhead introduced |
| 135 | // by heap verification. some options might cause heap verifiction to be less |
| 136 | // effective depending on the scenario. |
| 137 | |
| 138 | HEAPVERIFY_NO_RANGE_CHECKS = 0x10, // Excludes checking if an OBJECTREF is within the bounds of the managed heap |
| 139 | HEAPVERIFY_NO_MEM_FILL = 0x20, // Excludes filling unused segment portions with fill pattern |
| 140 | HEAPVERIFY_POST_GC_ONLY = 0x40, // Performs heap verification post-GCs only (instead of before and after each GC) |
| 141 | HEAPVERIFY_DEEP_ON_COMPACT = 0x80 // Performs deep object verfication only on compacting GCs. |
| 142 | }; |
| 143 | |
| 144 | // Initializes the GCConfig subsystem. Must be called before accessing any |
| 145 | // configuration information. |
| 146 | static void Initialize(); |
| 147 | |
| 148 | }; |
| 149 | |
| 150 | #endif // __GCCONFIG_H__ |
| 151 | |