public static int CollectionCount(int generation) { throw null; }
public static void EndNoGCRegion() { }
public static long GetAllocatedBytesForCurrentThread() { throw null; }
+ public static GCMemoryInfo GetGCMemoryInfo() { throw null; }
public static int GetGeneration(object obj) { throw null; }
public static int GetGeneration(System.WeakReference wo) { throw null; }
public static long GetTotalMemory(bool forceFullCollection) { throw null; }
public static System.GCNotificationStatus WaitForFullGCComplete(int millisecondsTimeout) { throw null; }
public static void WaitForPendingFinalizers() { }
}
+ public readonly struct GCMemoryInfo
+ {
+ public long HighMemoryLoadThresholdBytes { get { throw null; } }
+ public long MemoryLoadBytes { get { throw null; } }
+ public long TotalAvailableMemoryBytes { get { throw null; } }
+ public long HeapSizeBytes { get { throw null; } }
+ public long FragmentedBytes { get { throw null; } }
+ }
public enum GCCollectionMode
{
Default = 0,
TypesMustExist : Type 'System.Range.OffsetAndLength' does not exist in the implementation but it does exist in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Memory<T>' does not implement interface 'System.IEquatable<System.Memory<T>>' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.ReadOnlyMemory<T>' does not implement interface 'System.IEquatable<System.ReadOnlyMemory<T>>' in the implementation but it does in the contract.
+MembersMustExist : Member 'System.GC.GetGCMemoryInfo()' does not exist in the implementation but it does exist in the contract.
+TypesMustExist : Type 'System.GCMemoryInfo' does not exist in the implementation but it does exist in the contract.
// See the LICENSE file in the project root for more information.
using System;
+using System.Runtime.InteropServices;
+using Microsoft.DotNet.RemoteExecutor;
using Xunit;
namespace System.Tests
Assert.True((end - start) > size, $"Allocated too little: start: {start} end: {end} size: {size}");
Assert.True((end - start) < 5 * size, $"Allocated too much: start: {start} end: {end} size: {size}");
}
+
+ [Fact]
+ public static void GetGCMemoryInfo()
+ {
+ RemoteExecutor.Invoke(() =>
+ {
+ // Allows to update the value returned by GC.GetGCMemoryInfo
+ GC.Collect();
+
+ GCMemoryInfo memoryInfo1 = GC.GetGCMemoryInfo();
+
+ Assert.True(memoryInfo1.HighMemoryLoadThresholdBytes > 0);
+ Assert.True(memoryInfo1.MemoryLoadBytes > 0);
+ Assert.True(memoryInfo1.TotalAvailableMemoryBytes > 0);
+ Assert.True(memoryInfo1.HeapSizeBytes > 0);
+ Assert.True(memoryInfo1.FragmentedBytes >= 0);
+
+ GCHandle[] gch = new GCHandle[64 * 1024];
+ for (int i = 0; i < gch.Length * 2; ++i)
+ {
+ byte[] arr = new byte[64];
+ if (i % 2 == 0)
+ {
+ gch[i / 2] = GCHandle.Alloc(arr, GCHandleType.Pinned);
+ }
+ }
+
+ // Allows to update the value returned by GC.GetGCMemoryInfo
+ GC.Collect();
+
+ GCMemoryInfo memoryInfo2 = GC.GetGCMemoryInfo();
+
+ Assert.True(memoryInfo2.HighMemoryLoadThresholdBytes == memoryInfo1.HighMemoryLoadThresholdBytes);
+ Assert.True(memoryInfo2.MemoryLoadBytes >= memoryInfo1.MemoryLoadBytes);
+ Assert.True(memoryInfo2.TotalAvailableMemoryBytes == memoryInfo1.TotalAvailableMemoryBytes);
+ Assert.True(memoryInfo2.HeapSizeBytes > memoryInfo1.HeapSizeBytes);
+ Assert.True(memoryInfo2.FragmentedBytes > memoryInfo1.FragmentedBytes);
+ }).Dispose();
+ }
}
}