Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Merge pull request #12489 from jkotas/GetAllocatedBytesForCurrentThread
Browse files Browse the repository at this point in the history
Expose GC.GetAllocatedBytesForCurrentThread in netcoreapp1.1
  • Loading branch information
stephentoub authored Oct 9, 2016
2 parents 094938f + 67bc5d4 commit a8f2bf2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,9 @@ public static void RemoveMemoryPressure(long bytesAllocated) { }
public static void ReRegisterForFinalize(object obj) { }
public static void SuppressFinalize(object obj) { }
public static void WaitForPendingFinalizers() { }
#if netcoreapp11
public static long GetAllocatedBytesForCurrentThread() { return default(long); }
#endif
}
public enum GCCollectionMode
{
Expand Down
1 change: 1 addition & 0 deletions src/System.Runtime/tests/System.Runtime.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp1.1'">
<Compile Include="System\ArrayTests.netcoreapp1.1.cs" />
<Compile Include="System\EnumTests.netcoreapp1.1.cs" />
<Compile Include="System\GCTests.netcoreapp1.1.cs" />
<Compile Include="System\IntPtrTests.netcoreapp1.1.cs" />
<Compile Include="System\LazyTests.netcoreapp1.1.cs" />
<Compile Include="System\Runtime\CompilerServices\RuntimeHelpersTests.netcoreapp1.1.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/System.Runtime/tests/System/GCTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace System.Tests
{
public static class GCTests
public static partial class GCTests
{
private static bool s_is32Bits = IntPtr.Size == 4; // Skip IntPtr tests on 32-bit platforms

Expand Down
27 changes: 27 additions & 0 deletions src/System.Runtime/tests/System/GCTests.netcoreapp1.1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 Xunit;

namespace System.Tests
{
public static partial class GCTests
{
[Theory]
[InlineData(1000)]
[InlineData(100000)]
public static void GetAllocatedBytesForCurrentThread(int size)
{
long start = GC.GetAllocatedBytesForCurrentThread();

GC.KeepAlive(new String('a', size));

long end = GC.GetAllocatedBytesForCurrentThread();

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}");
}
}
}

0 comments on commit a8f2bf2

Please sign in to comment.