/
GCSettings.cs
68 lines (59 loc) · 2.01 KB
/
GCSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
namespace System.Runtime
{
public enum GCLargeObjectHeapCompactionMode
{
Default = 1,
CompactOnce = 2
}
// These settings are the same format as in the GC in the runtime.
public enum GCLatencyMode
{
Batch = 0,
Interactive = 1,
LowLatency = 2,
SustainedLowLatency = 3,
NoGCRegion = 4
}
public static partial class GCSettings
{
private enum SetLatencyModeStatus
{
Succeeded = 0,
NoGCInProgress = 1 // NoGCRegion is in progress, can't change pause mode.
}
public static GCLatencyMode LatencyMode
{
get => GetGCLatencyMode();
set
{
if ((value < GCLatencyMode.Batch) ||
(value > GCLatencyMode.SustainedLowLatency))
{
ThrowHelper.ArgumentOutOfRangeException_Enum_Value();
}
SetLatencyModeStatus status = SetGCLatencyMode(value);
if (status == SetLatencyModeStatus.NoGCInProgress)
{
throw new InvalidOperationException(SR.InvalidOperation_SetLatencyModeNoGC);
}
Debug.Assert(status == SetLatencyModeStatus.Succeeded, $"Unexpected return value '{status}' from {nameof(SetGCLatencyMode)}.");
}
}
public static GCLargeObjectHeapCompactionMode LargeObjectHeapCompactionMode
{
get => GetLOHCompactionMode();
set
{
if ((value < GCLargeObjectHeapCompactionMode.Default) ||
(value > GCLargeObjectHeapCompactionMode.CompactOnce))
{
ThrowHelper.ArgumentOutOfRangeException_Enum_Value();
}
SetLOHCompactionMode(value);
}
}
}
}