summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/GC.cs
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2017-04-13 14:17:19 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2017-04-13 14:17:19 +0900
commita56e30c8d33048216567753d9d3fefc2152af8ac (patch)
tree7e5d979695fc4a431740982eb1cfecc2898b23a5 /src/mscorlib/src/System/GC.cs
parent4b11dc566a5bbfa1378d6266525c281b028abcc8 (diff)
downloadcoreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.tar.gz
coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.tar.bz2
coreclr-a56e30c8d33048216567753d9d3fefc2152af8ac.zip
Imported Upstream version 2.0.0.11353upstream/2.0.0.11353
Diffstat (limited to 'src/mscorlib/src/System/GC.cs')
-rw-r--r--src/mscorlib/src/System/GC.cs167
1 files changed, 92 insertions, 75 deletions
diff --git a/src/mscorlib/src/System/GC.cs b/src/mscorlib/src/System/GC.cs
index fd09ef7984..aeb0ca5196 100644
--- a/src/mscorlib/src/System/GC.cs
+++ b/src/mscorlib/src/System/GC.cs
@@ -12,21 +12,22 @@
**
**
===========================================================*/
-namespace System {
- //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.Contracts;
-
+//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.Contracts;
+
+namespace System
+{
[Serializable]
public enum GCCollectionMode
{
@@ -60,7 +61,7 @@ namespace System {
NotApplicable = 4
}
- public static class GC
+ public static class GC
{
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern int GetGCLatencyMode();
@@ -95,9 +96,9 @@ namespace System {
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern int GetMaxGeneration();
-
+
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern int _CollectionCount (int generation, int getSpecialGCCount);
+ private static extern int _CollectionCount(int generation, int getSpecialGCCount);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern bool IsServerGC();
@@ -107,35 +108,41 @@ namespace System {
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private static extern void _RemoveMemoryPressure(UInt64 bytesAllocated);
-
- public static void AddMemoryPressure (long bytesAllocated) {
- if( bytesAllocated <= 0) {
- throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
- Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
+
+ public static void AddMemoryPressure(long bytesAllocated)
+ {
+ if (bytesAllocated <= 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
+ SR.ArgumentOutOfRange_NeedPosNum);
}
- if( (4 == IntPtr.Size) && (bytesAllocated > Int32.MaxValue) ) {
- throw new ArgumentOutOfRangeException("pressure",
- Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegInt32"));
+ if ((4 == IntPtr.Size) && (bytesAllocated > Int32.MaxValue))
+ {
+ throw new ArgumentOutOfRangeException("pressure",
+ SR.ArgumentOutOfRange_MustBeNonNegInt32);
}
Contract.EndContractBlock();
_AddMemoryPressure((ulong)bytesAllocated);
}
- public static void RemoveMemoryPressure (long bytesAllocated) {
- if( bytesAllocated <= 0) {
- throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
- Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
+ public static void RemoveMemoryPressure(long bytesAllocated)
+ {
+ if (bytesAllocated <= 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
+ SR.ArgumentOutOfRange_NeedPosNum);
}
- if( (4 == IntPtr.Size) && (bytesAllocated > Int32.MaxValue) ) {
- throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
- Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegInt32"));
+ if ((4 == IntPtr.Size) && (bytesAllocated > Int32.MaxValue))
+ {
+ throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
+ SR.ArgumentOutOfRange_MustBeNonNegInt32);
}
Contract.EndContractBlock();
- _RemoveMemoryPressure((ulong) bytesAllocated);
+ _RemoveMemoryPressure((ulong)bytesAllocated);
}
@@ -144,40 +151,42 @@ namespace System {
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern int GetGeneration(Object obj);
-
+
// Forces a collection of all generations from 0 through Generation.
//
- public static void Collect(int generation) {
+ public static void Collect(int generation)
+ {
Collect(generation, GCCollectionMode.Default);
}
-
+
// Garbage Collect all generations.
//
- public static void Collect() {
+ public static void Collect()
+ {
//-1 says to GC all generations.
_Collect(-1, (int)InternalGCCollectionMode.Blocking);
}
- public static void Collect(int generation, GCCollectionMode mode)
+ public static void Collect(int generation, GCCollectionMode mode)
{
Collect(generation, mode, true);
}
- public static void Collect(int generation, GCCollectionMode mode, bool blocking)
+ public static void Collect(int generation, GCCollectionMode mode, bool blocking)
{
Collect(generation, mode, blocking, false);
}
public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting)
{
- if (generation<0)
+ if (generation < 0)
{
- throw new ArgumentOutOfRangeException(nameof(generation), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
+ throw new ArgumentOutOfRangeException(nameof(generation), SR.ArgumentOutOfRange_GenericPositive);
}
if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized))
{
- throw new ArgumentOutOfRangeException(nameof(mode), Environment.GetResourceString("ArgumentOutOfRange_Enum"));
+ throw new ArgumentOutOfRangeException(nameof(mode), SR.ArgumentOutOfRange_Enum);
}
Contract.EndContractBlock();
@@ -204,16 +213,16 @@ namespace System {
_Collect(generation, iInternalModes);
}
- public static int CollectionCount (int generation)
+ public static int CollectionCount(int generation)
{
- if (generation<0)
+ if (generation < 0)
{
- throw new ArgumentOutOfRangeException(nameof(generation), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
+ throw new ArgumentOutOfRangeException(nameof(generation), SR.ArgumentOutOfRange_GenericPositive);
}
Contract.EndContractBlock();
return _CollectionCount(generation, 0);
}
-
+
// This method DOES NOT DO ANYTHING in and of itself. It's used to
// prevent a finalizable object from losing any outstanding references
// a touch too early. The JIT is very aggressive about keeping an
@@ -256,15 +265,17 @@ namespace System {
// Returns the generation in which wo currently resides.
//
- public static int GetGeneration(WeakReference wo) {
+ public static int GetGeneration(WeakReference wo)
+ {
int result = GetGenerationWR(wo.m_handle);
KeepAlive(wo);
return result;
}
-
+
// Returns the maximum GC generation. Currently assumes only 1 heap.
//
- public static int MaxGeneration {
+ public static int MaxGeneration
+ {
get { return GetMaxGeneration(); }
}
@@ -272,17 +283,19 @@ namespace System {
[SuppressUnmanagedCodeSecurity]
private static extern void _WaitForPendingFinalizers();
- public static void WaitForPendingFinalizers() {
+ public static void WaitForPendingFinalizers()
+ {
// QCalls can not be exposed from mscorlib directly, need to wrap it.
_WaitForPendingFinalizers();
}
-
+
// Indicates that the system should not call the Finalize() method on
// an object that would normally require this call.
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void _SuppressFinalize(Object o);
- public static void SuppressFinalize(Object obj) {
+ public static void SuppressFinalize(Object obj)
+ {
if (obj == null)
throw new ArgumentNullException(nameof(obj));
Contract.EndContractBlock();
@@ -295,8 +308,9 @@ namespace System {
// needs to resurrect itself or an object that it references.
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void _ReRegisterForFinalize(Object o);
-
- public static void ReRegisterForFinalize(Object obj) {
+
+ public static void ReRegisterForFinalize(Object obj)
+ {
if (obj == null)
throw new ArgumentNullException(nameof(obj));
Contract.EndContractBlock();
@@ -307,7 +321,8 @@ namespace System {
// the GC heap. This does not return the total size of the GC heap, but
// only the live objects in the GC heap.
//
- public static long GetTotalMemory(bool forceFullCollection) {
+ public static long GetTotalMemory(bool forceFullCollection)
+ {
long size = GetTotalMemory();
if (!forceFullCollection)
return size;
@@ -319,7 +334,8 @@ namespace System {
int reps = 20; // Number of iterations
long newSize = size;
float diff;
- do {
+ do
+ {
GC.WaitForPendingFinalizers();
GC.Collect();
size = newSize;
@@ -332,7 +348,8 @@ namespace System {
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern long _GetAllocatedBytesForCurrentThread();
- public static long GetAllocatedBytesForCurrentThread() {
+ public static long GetAllocatedBytesForCurrentThread()
+ {
return _GetAllocatedBytesForCurrentThread();
}
@@ -352,27 +369,27 @@ namespace System {
{
if ((maxGenerationThreshold <= 0) || (maxGenerationThreshold >= 100))
{
- throw new ArgumentOutOfRangeException(nameof(maxGenerationThreshold),
+ throw new ArgumentOutOfRangeException(nameof(maxGenerationThreshold),
String.Format(
CultureInfo.CurrentCulture,
- Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper"),
- 1,
+ SR.ArgumentOutOfRange_Bounds_Lower_Upper,
+ 1,
99));
}
-
+
if ((largeObjectHeapThreshold <= 0) || (largeObjectHeapThreshold >= 100))
{
- throw new ArgumentOutOfRangeException(nameof(largeObjectHeapThreshold),
+ throw new ArgumentOutOfRangeException(nameof(largeObjectHeapThreshold),
String.Format(
CultureInfo.CurrentCulture,
- Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper"),
- 1,
+ SR.ArgumentOutOfRange_Bounds_Lower_Upper,
+ 1,
99));
-}
+ }
if (!_RegisterForFullGCNotification(maxGenerationThreshold, largeObjectHeapThreshold))
{
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotWithConcurrentGC"));
+ throw new InvalidOperationException(SR.InvalidOperation_NotWithConcurrentGC);
}
}
@@ -380,7 +397,7 @@ namespace System {
{
if (!_CancelFullGCNotification())
{
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotWithConcurrentGC"));
+ throw new InvalidOperationException(SR.InvalidOperation_NotWithConcurrentGC);
}
}
@@ -392,7 +409,7 @@ namespace System {
public static GCNotificationStatus WaitForFullGCApproach(int millisecondsTimeout)
{
if (millisecondsTimeout < -1)
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
+ throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
return (GCNotificationStatus)_WaitForFullGCApproach(millisecondsTimeout);
}
@@ -405,11 +422,11 @@ namespace System {
public static GCNotificationStatus WaitForFullGCComplete(int millisecondsTimeout)
{
if (millisecondsTimeout < -1)
- throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
+ throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), SR.ArgumentOutOfRange_NeedNonNegOrNegative1);
return (GCNotificationStatus)_WaitForFullGCComplete(millisecondsTimeout);
}
- enum StartNoGCRegionStatus
+ private enum StartNoGCRegionStatus
{
Succeeded = 0,
NotEnoughMemory = 1,
@@ -417,7 +434,7 @@ namespace System {
AlreadyInProgress = 3
}
- enum EndNoGCRegionStatus
+ private enum EndNoGCRegionStatus
{
Succeeded = 0,
NotInProgress = 1,
@@ -425,11 +442,11 @@ namespace System {
AllocationExceeded = 3
}
- static bool StartNoGCRegionWorker(long totalSize, bool hasLohSize, long lohSize, bool disallowFullBlockingGC)
+ private static bool StartNoGCRegionWorker(long totalSize, bool hasLohSize, long lohSize, bool disallowFullBlockingGC)
{
StartNoGCRegionStatus status = (StartNoGCRegionStatus)_StartNoGCRegion(totalSize, hasLohSize, lohSize, disallowFullBlockingGC);
if (status == StartNoGCRegionStatus.AmountTooLarge)
- throw new ArgumentOutOfRangeException(nameof(totalSize),
+ throw new ArgumentOutOfRangeException(nameof(totalSize),
"totalSize is too large. For more information about setting the maximum size, see \"Latency Modes\" in http://go.microsoft.com/fwlink/?LinkId=522706");
else if (status == StartNoGCRegionStatus.AlreadyInProgress)
throw new InvalidOperationException("The NoGCRegion mode was already in progress");
@@ -458,7 +475,7 @@ namespace System {
return StartNoGCRegionWorker(totalSize, true, lohSize, disallowFullBlockingGC);
}
- static EndNoGCRegionStatus EndNoGCRegionWorker()
+ private static EndNoGCRegionStatus EndNoGCRegionWorker()
{
EndNoGCRegionStatus status = (EndNoGCRegionStatus)_EndNoGCRegion();
if (status == EndNoGCRegionStatus.NotInProgress)