From 2ee07809ff7d6fbc9209e7e21aeeb3037efbb9a7 Mon Sep 17 00:00:00 2001 From: Roma Marusyk Date: Thu, 5 Mar 2020 01:19:10 +0200 Subject: [PATCH] Remove calls to empty RuntimeHelpers.PrepareConstrainedRegions() #33179 --- .../src/System/Net/Windows/WebSockets/WebSocketBase.cs | 3 --- .../src/System/IO/UnmanagedMemoryStream.cs | 7 ------- .../src/System/Runtime/MemoryFailPoint.cs | 9 --------- .../Internal/MemoryBlocks/MemoryMappedFileBlock.cs | 10 ---------- .../Internal/MemoryBlocks/NativeHeapMemoryBlock.cs | 9 --------- .../Reflection/Internal/Utilities/PinnedObject.cs | 9 --------- .../System/Reflection/Metadata/Internal/VirtualHeap.cs | 8 -------- 7 files changed, 55 deletions(-) diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs index 586c0cbea28feb..b54a0f21d24aa8 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs @@ -8,7 +8,6 @@ using System.Globalization; using System.IO; using System.Net.Sockets; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using System.Threading; @@ -1020,7 +1019,6 @@ private void ReleaseLocks(ref bool thisLockTaken, ref bool sessionHandleLockTake if (thisLockTaken || sessionHandleLockTaken) { - RuntimeHelpers.PrepareConstrainedRegions(); try { } @@ -1104,7 +1102,6 @@ private static void ReleaseLock(object lockObject, ref bool lockTaken) Debug.Assert(lockObject != null, "'lockObject' MUST NOT be NULL."); if (lockTaken) { - RuntimeHelpers.PrepareConstrainedRegions(); try { } diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs b/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs index ef508648226b8c..ecdb454203bf4e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs @@ -4,7 +4,6 @@ using System.Buffers; using System.Diagnostics; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -128,7 +127,6 @@ protected void Initialize(SafeBuffer buffer, long offset, long length, FileAcces unsafe { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { buffer.AcquirePointer(ref pointer); @@ -260,7 +258,6 @@ public override void CopyTo(ReadOnlySpanAction callback, object? { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); @@ -490,7 +487,6 @@ internal int ReadCore(Span buffer) { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); @@ -606,7 +602,6 @@ public override int ReadByte() unsafe { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); @@ -786,7 +781,6 @@ internal unsafe void WriteCore(ReadOnlySpan buffer) } byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); @@ -920,7 +914,6 @@ public override void WriteByte(byte value) unsafe { byte* pointer = null; - RuntimeHelpers.PrepareConstrainedRegions(); try { _buffer.AcquirePointer(ref pointer); diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.cs index 191e2fed58cd8f..d6c29347d425d1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.cs @@ -14,7 +14,6 @@ ===========================================================*/ using System.Threading; -using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Diagnostics; @@ -235,10 +234,6 @@ public MemoryFailPoint(int sizeInMegabytes) if (!needPageFile) continue; - // Attempt to grow the OS's page file. Note that we ignore - // any allocation routines from the host intentionally. - RuntimeHelpers.PrepareConstrainedRegions(); - // This shouldn't overflow due to the if clauses above. UIntPtr numBytes = new UIntPtr(segmentSize); GrowPageFileIfNecessaryAndPossible(numBytes); @@ -286,8 +281,6 @@ public MemoryFailPoint(int sizeInMegabytes) if (LastKnownFreeAddressSpace < 0) CheckForFreeAddressSpace(segmentSize, true); - RuntimeHelpers.PrepareConstrainedRegions(); - AddMemoryFailPointReservation((long)size); _mustSubtractReservation = true; } @@ -317,8 +310,6 @@ private void Dispose(bool disposing) // within the GC heap. if (_mustSubtractReservation) { - RuntimeHelpers.PrepareConstrainedRegions(); - AddMemoryFailPointReservation(-((long)_reservedMemory)); _mustSubtractReservation = false; } diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/MemoryMappedFileBlock.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/MemoryMappedFileBlock.cs index f2dfb49c95e136..a25a50be94052c 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/MemoryMappedFileBlock.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/MemoryMappedFileBlock.cs @@ -2,7 +2,6 @@ // 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; using System.Runtime.InteropServices; using System.Threading; @@ -18,10 +17,6 @@ private sealed class DisposableData : CriticalDisposableObject public DisposableData(IDisposable accessor, SafeBuffer safeBuffer, long offset) { - // Make sure the current thread isn't aborted in between acquiring the pointer and assigning the fields. -#if !NETSTANDARD1_1 - RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { } @@ -38,11 +33,6 @@ public DisposableData(IDisposable accessor, SafeBuffer safeBuffer, long offset) protected override void Release() { - // Make sure the current thread isn't aborted in between zeroing the references and releasing/disposing. - // Safe buffer only frees the underlying resource if its ref count drops to zero, so we have to make sure it does. -#if !NETSTANDARD1_1 - RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { } diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/NativeHeapMemoryBlock.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/NativeHeapMemoryBlock.cs index f944457eefde0c..ea017245975993 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/NativeHeapMemoryBlock.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/MemoryBlocks/NativeHeapMemoryBlock.cs @@ -2,7 +2,6 @@ // 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; using System.Runtime.InteropServices; using System.Threading; @@ -22,10 +21,6 @@ private unsafe sealed class DisposableData : CriticalDisposableObject public DisposableData(int size) { - // make sure the current thread isn't aborted in between allocating and storing the pointer -#if !NETSTANDARD1_1 - RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { } @@ -37,10 +32,6 @@ public DisposableData(int size) protected override void Release() { - // make sure the current thread isn't aborted in between zeroing the pointer and freeing the memory -#if !NETSTANDARD1_1 - RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { } diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/PinnedObject.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/PinnedObject.cs index 47ca6238f2d101..7357e591e92452 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/PinnedObject.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/PinnedObject.cs @@ -2,7 +2,6 @@ // 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; using System.Runtime.InteropServices; using System.Threading; @@ -18,10 +17,6 @@ internal sealed class PinnedObject : CriticalDisposableObject public PinnedObject(object obj) { - // Make sure the current thread isn't aborted in between allocating the handle and storing it. -#if !NETSTANDARD1_1 - RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { } @@ -34,10 +29,6 @@ public PinnedObject(object obj) protected override void Release() { - // Make sure the current thread isn't aborted in between zeroing the handle and freeing it. -#if !NETSTANDARD1_1 - RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { } diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Internal/VirtualHeap.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Internal/VirtualHeap.cs index 4faab2f817670c..f85ba4e7fe3ff5 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Internal/VirtualHeap.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Internal/VirtualHeap.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Reflection.Internal; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; @@ -46,10 +45,6 @@ private VirtualHeap() protected override void Release() { - // Make sure the current thread isn't aborted in the middle of the operation. -#if !NETSTANDARD1_1 - RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { } @@ -95,9 +90,6 @@ internal MemoryBlock AddBlob(uint rawHandle, byte[] value) var blobs = GetBlobs(); MemoryBlock result; -#if !NETSTANDARD1_1 - RuntimeHelpers.PrepareConstrainedRegions(); -#endif try { }