summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2019-02-08 11:57:48 -0500
committerJan Kotas <jkotas@microsoft.com>2019-02-08 08:57:48 -0800
commit13ae47e082c7ca0da9d4d8d99c29a83da052e1c7 (patch)
treeccefe67d72b94883a10adc8b99160e564af4223a
parent5f36ff27b199da0dafe81cbfe07b16fb370b7442 (diff)
downloadcoreclr-13ae47e082c7ca0da9d4d8d99c29a83da052e1c7.tar.gz
coreclr-13ae47e082c7ca0da9d4d8d99c29a83da052e1c7.tar.bz2
coreclr-13ae47e082c7ca0da9d4d8d99c29a83da052e1c7.zip
Move GCSettings to shared (#22483)
Mainly just type definitions and error handling that gets shared.
-rw-r--r--src/System.Private.CoreLib/Resources/Strings.resx3
-rw-r--r--src/System.Private.CoreLib/System.Private.CoreLib.csproj2
-rw-r--r--src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems1
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/GCSettings.cs69
-rw-r--r--src/System.Private.CoreLib/src/System/GC.cs25
-rw-r--r--src/System.Private.CoreLib/src/System/Runtime/GCSettings.CoreCLR.cs29
-rw-r--r--src/System.Private.CoreLib/src/System/Runtime/GcSettings.cs86
-rw-r--r--src/vm/ecalllist.h14
8 files changed, 113 insertions, 116 deletions
diff --git a/src/System.Private.CoreLib/Resources/Strings.resx b/src/System.Private.CoreLib/Resources/Strings.resx
index 2af274fd43..6dc744dea2 100644
--- a/src/System.Private.CoreLib/Resources/Strings.resx
+++ b/src/System.Private.CoreLib/Resources/Strings.resx
@@ -2617,6 +2617,9 @@
<data name="InvalidOperation_SetData_OnlyOnce" xml:space="preserve">
<value>SetData can only be used to set the value of a given name once.</value>
</data>
+ <data name="InvalidOperation_SetLatencyModeNoGC" xml:space="preserve">
+ <value>The NoGCRegion mode is in progress.End it and then set a different mode.</value>
+ </data>
<data name="InvalidOperation_ShouldNotHaveMethodBody" xml:space="preserve">
<value>Method body should not exist.</value>
</data>
diff --git a/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/System.Private.CoreLib.csproj
index 2feaaa25f8..777f1f07aa 100644
--- a/src/System.Private.CoreLib/System.Private.CoreLib.csproj
+++ b/src/System.Private.CoreLib/System.Private.CoreLib.csproj
@@ -242,7 +242,7 @@
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\RuntimeFeature.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\RuntimeHelpers.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\TypeDependencyAttribute.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Runtime\GcSettings.cs" />
+ <Compile Include="$(BclSourcesRoot)\System\Runtime\GCSettings.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ComTypes\IEnumerable.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\CriticalHandle.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\Expando\IExpando.cs" />
diff --git a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
index 8063228b62..8ee292ba60 100644
--- a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
+++ b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
@@ -687,6 +687,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Versioning\NonVersionableAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Versioning\TargetFrameworkAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\AmbiguousImplementationException.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\GCSettings.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\MemoryFailPoint.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\SByte.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Security\AllowPartiallyTrustedCallersAttribute.cs" />
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/GCSettings.cs b/src/System.Private.CoreLib/shared/System/Runtime/GCSettings.cs
new file mode 100644
index 0000000000..86d10f4b53
--- /dev/null
+++ b/src/System.Private.CoreLib/shared/System/Runtime/GCSettings.cs
@@ -0,0 +1,69 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+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))
+ {
+ throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_Enum);
+ }
+
+ 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))
+ {
+ throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_Enum);
+ }
+
+ SetLOHCompactionMode(value);
+ }
+ }
+ }
+}
diff --git a/src/System.Private.CoreLib/src/System/GC.cs b/src/System.Private.CoreLib/src/System/GC.cs
index 838e8147f2..1e0268e905 100644
--- a/src/System.Private.CoreLib/src/System/GC.cs
+++ b/src/System.Private.CoreLib/src/System/GC.cs
@@ -12,18 +12,10 @@
**
**
===========================================================*/
-//This class only static members and doesn't require the serializable keyword.
-using System;
-using System.Reflection;
-using System.Security;
-using System.Threading;
-using System.Runtime;
using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
using System.Globalization;
using System.Runtime.InteropServices;
-using System.Runtime.Versioning;
using System.Diagnostics;
namespace System
@@ -61,12 +53,6 @@ namespace System
public static class GC
{
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern int GetGCLatencyMode();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern int SetGCLatencyMode(int newLatencyMode);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void GetMemoryInfo(out uint highMemLoadThreshold,
out ulong totalPhysicalMem,
out uint lastRecordedMemLoad,
@@ -79,13 +65,7 @@ namespace System
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern int _EndNoGCRegion();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern int GetLOHCompactionMode();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern void SetLOHCompactionMode(int newLOHCompactionMode);
-
+
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern int GetGenerationWR(IntPtr handle);
@@ -102,9 +82,6 @@ namespace System
private static extern int _CollectionCount(int generation, int getSpecialGCCount);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern bool IsServerGC();
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern ulong GetSegmentSize();
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
diff --git a/src/System.Private.CoreLib/src/System/Runtime/GCSettings.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Runtime/GCSettings.CoreCLR.cs
new file mode 100644
index 0000000000..1fbc1dc4f1
--- /dev/null
+++ b/src/System.Private.CoreLib/src/System/Runtime/GCSettings.CoreCLR.cs
@@ -0,0 +1,29 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.CompilerServices;
+
+namespace System.Runtime
+{
+ public static partial class GCSettings
+ {
+ public static extern bool IsServerGC
+ {
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ private static extern GCLatencyMode GetGCLatencyMode();
+
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ private static extern SetLatencyModeStatus SetGCLatencyMode(GCLatencyMode newLatencyMode);
+
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ private static extern GCLargeObjectHeapCompactionMode GetLOHCompactionMode();
+
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ private static extern void SetLOHCompactionMode(GCLargeObjectHeapCompactionMode newLOHCompactionMode);
+ }
+}
diff --git a/src/System.Private.CoreLib/src/System/Runtime/GcSettings.cs b/src/System.Private.CoreLib/src/System/Runtime/GcSettings.cs
deleted file mode 100644
index 6e08aa3dc5..0000000000
--- a/src/System.Private.CoreLib/src/System/Runtime/GcSettings.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-
-using System;
-using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
-
-namespace System.Runtime
-{
- // These settings are the same format as in clr\src\vm\gcpriv.h
- // make sure you change that file if you change this file!
-
- public enum GCLargeObjectHeapCompactionMode
- {
- Default = 1,
- CompactOnce = 2
- }
-
- public enum GCLatencyMode
- {
- Batch = 0,
- Interactive = 1,
- LowLatency = 2,
- SustainedLowLatency = 3,
- NoGCRegion = 4
- }
-
- public static class GCSettings
- {
- private enum SetLatencyModeStatus
- {
- Succeeded = 0,
- NoGCInProgress = 1 // NoGCRegion is in progress, can't change pause mode.
- };
-
- public static GCLatencyMode LatencyMode
- {
- get
- {
- return (GCLatencyMode)(GC.GetGCLatencyMode());
- }
-
- // We don't want to allow this API when hosted.
- set
- {
- if ((value < GCLatencyMode.Batch) || (value > GCLatencyMode.SustainedLowLatency))
- {
- throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum);
- }
-
- if (GC.SetGCLatencyMode((int)value) == (int)SetLatencyModeStatus.NoGCInProgress)
- throw new InvalidOperationException("The NoGCRegion mode is in progress. End it and then set a different mode.");
- }
- }
-
- public static GCLargeObjectHeapCompactionMode LargeObjectHeapCompactionMode
- {
- get
- {
- return (GCLargeObjectHeapCompactionMode)(GC.GetLOHCompactionMode());
- }
-
- // We don't want to allow this API when hosted.
- set
- {
- if ((value < GCLargeObjectHeapCompactionMode.Default) ||
- (value > GCLargeObjectHeapCompactionMode.CompactOnce))
- {
- throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum);
- }
-
- GC.SetLOHCompactionMode((int)value);
- }
- }
-
- public static bool IsServerGC
- {
- get
- {
- return GC.IsServerGC();
- }
- }
- }
-}
diff --git a/src/vm/ecalllist.h b/src/vm/ecalllist.h
index c604db35d8..6b96316931 100644
--- a/src/vm/ecalllist.h
+++ b/src/vm/ecalllist.h
@@ -776,13 +776,8 @@ FCFuncStart(gGCInterfaceFuncs)
FCFuncElement("_WaitForFullGCComplete", GCInterface::WaitForFullGCComplete)
FCFuncElement("_CollectionCount", GCInterface::CollectionCount)
FCFuncElement("GetMemoryInfo", GCInterface::GetMemoryInfo)
- FCFuncElement("GetGCLatencyMode", GCInterface::GetGcLatencyMode)
- FCFuncElement("SetGCLatencyMode", GCInterface::SetGcLatencyMode)
- FCFuncElement("GetLOHCompactionMode", GCInterface::GetLOHCompactionMode)
- FCFuncElement("SetLOHCompactionMode", GCInterface::SetLOHCompactionMode)
QCFuncElement("_StartNoGCRegion", GCInterface::StartNoGCRegion)
QCFuncElement("_EndNoGCRegion", GCInterface::EndNoGCRegion)
- FCFuncElement("IsServerGC", SystemNative::IsServerGC)
FCFuncElement("GetSegmentSize", GCInterface::GetSegmentSize)
QCFuncElement("_AddMemoryPressure", GCInterface::_AddMemoryPressure)
QCFuncElement("_RemoveMemoryPressure", GCInterface::_RemoveMemoryPressure)
@@ -798,6 +793,14 @@ FCFuncStart(gGCInterfaceFuncs)
FCFuncElement("_GetAllocatedBytesForCurrentThread", GCInterface::GetAllocatedBytesForCurrentThread)
FCFuncEnd()
+FCFuncStart(gGCSettingsFuncs)
+ FCFuncElement("get_IsServerGC", SystemNative::IsServerGC)
+ FCFuncElement("GetGCLatencyMode", GCInterface::GetGcLatencyMode)
+ FCFuncElement("GetLOHCompactionMode", GCInterface::GetLOHCompactionMode)
+ FCFuncElement("SetGCLatencyMode", GCInterface::SetGcLatencyMode)
+ FCFuncElement("SetLOHCompactionMode", GCInterface::SetLOHCompactionMode)
+FCFuncEnd()
+
FCFuncStart(gInteropMarshalFuncs)
FCFuncElement("GetLastWin32Error", MarshalNative::GetLastWin32Error)
FCFuncElement("SetLastWin32Error", MarshalNative::SetLastWin32Error)
@@ -1224,6 +1227,7 @@ FCClassElement("FileLoadException", "System.IO", gFileLoadExceptionFuncs)
FCClassElement("FormatterServices", "System.Runtime.Serialization", gSerializationFuncs)
FCClassElement("GC", "System", gGCInterfaceFuncs)
FCClassElement("GCHandle", "System.Runtime.InteropServices", gGCHandleFuncs)
+FCClassElement("GCSettings", "System.Runtime", gGCSettingsFuncs)
#ifdef FEATURE_COMINTEROP
FCClassElement("IEnumerable", "System.Collections", gStdMngIEnumerableFuncs)
FCClassElement("IEnumerator", "System.Collections", gStdMngIEnumeratorFuncs)