GCSettings.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. using System.Diagnostics;
  5. namespace System.Runtime
  6. {
  7. public enum GCLargeObjectHeapCompactionMode
  8. {
  9. Default = 1,
  10. CompactOnce = 2
  11. }
  12. // These settings are the same format as in the GC in the runtime.
  13. public enum GCLatencyMode
  14. {
  15. Batch = 0,
  16. Interactive = 1,
  17. LowLatency = 2,
  18. SustainedLowLatency = 3,
  19. NoGCRegion = 4
  20. }
  21. public static partial class GCSettings
  22. {
  23. private enum SetLatencyModeStatus
  24. {
  25. Succeeded = 0,
  26. NoGCInProgress = 1 // NoGCRegion is in progress, can't change pause mode.
  27. };
  28. public static GCLatencyMode LatencyMode
  29. {
  30. get => GetGCLatencyMode();
  31. set
  32. {
  33. if ((value < GCLatencyMode.Batch) ||
  34. (value > GCLatencyMode.SustainedLowLatency))
  35. {
  36. throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_Enum);
  37. }
  38. SetLatencyModeStatus status = SetGCLatencyMode(value);
  39. if (status == SetLatencyModeStatus.NoGCInProgress)
  40. {
  41. throw new InvalidOperationException(SR.InvalidOperation_SetLatencyModeNoGC);
  42. }
  43. Debug.Assert(status == SetLatencyModeStatus.Succeeded, $"Unexpected return value '{status}' from {nameof(SetGCLatencyMode)}.");
  44. }
  45. }
  46. public static GCLargeObjectHeapCompactionMode LargeObjectHeapCompactionMode
  47. {
  48. get => GetLOHCompactionMode();
  49. set
  50. {
  51. if ((value < GCLargeObjectHeapCompactionMode.Default) ||
  52. (value > GCLargeObjectHeapCompactionMode.CompactOnce))
  53. {
  54. throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_Enum);
  55. }
  56. SetLOHCompactionMode(value);
  57. }
  58. }
  59. }
  60. }