Remove calls to empty RuntimeHelpers.PrepareConstrainedRegions() (#33191)
authorRoman Marusyk <Marusyk@users.noreply.github.com>
Mon, 16 Mar 2020 14:39:37 +0000 (16:39 +0200)
committerGitHub <noreply@github.com>
Mon, 16 Mar 2020 14:39:37 +0000 (07:39 -0700)
Fixes #33179

src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs
src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs
src/libraries/System.Private.CoreLib/src/System/IO/UnmanagedMemoryStream.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.cs

index 7c1c75f..734c969 100644 (file)
@@ -367,7 +367,6 @@ namespace System
                 {
                     bool lockTaken = false;
 
-                    RuntimeHelpers.PrepareConstrainedRegions();
                     try
                     {
                         Monitor.Enter(this, ref lockTaken);
@@ -1576,7 +1575,6 @@ namespace System
                     Interlocked.CompareExchange(ref s_methodInstantiationsLock!, new object(), null);
 
                 bool lockTaken = false;
-                RuntimeHelpers.PrepareConstrainedRegions();
                 try
                 {
                     Monitor.Enter(s_methodInstantiationsLock, ref lockTaken);
index 7dc9170..c2d72e3 100644 (file)
@@ -46,9 +46,6 @@ namespace System.Threading
 
         internal void SetWaitObject(WaitHandle waitObject)
         {
-            // needed for DangerousAddRef
-            RuntimeHelpers.PrepareConstrainedRegions();
-
             m_internalWaitObject = waitObject;
             if (waitObject != null)
             {
@@ -61,8 +58,6 @@ namespace System.Threading
              )
         {
             bool result = false;
-            // needed for DangerousRelease
-            RuntimeHelpers.PrepareConstrainedRegions();
 
             // lock(this) cannot be used reliably in Cer since thin lock could be
             // promoted to syncblock and that is not a guaranteed operation
@@ -383,7 +378,6 @@ namespace System.Threading
 
             bool ret = false;
             bool mustReleaseSafeHandle = false;
-            RuntimeHelpers.PrepareConstrainedRegions();
             try
             {
                 osHandle.DangerousAddRef(ref mustReleaseSafeHandle);
index 586c0cb..8016bb2 100644 (file)
@@ -8,7 +8,6 @@ using System.Diagnostics;
 using System.Globalization;
 using System.IO;
 using System.Net.Sockets;
-using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Text;
 using System.Threading;
@@ -1018,26 +1017,16 @@ namespace System.Net.WebSockets
             Debug.Assert(_thisLock != null, "'_thisLock' MUST NOT be NULL.");
             Debug.Assert(SessionHandle != null, "'SessionHandle' MUST NOT be NULL.");
 
-            if (thisLockTaken || sessionHandleLockTaken)
+            if (thisLockTaken)
             {
-                RuntimeHelpers.PrepareConstrainedRegions();
-                try
-                {
-                }
-                finally
-                {
-                    if (thisLockTaken)
-                    {
-                        Monitor.Exit(_thisLock);
-                        thisLockTaken = false;
-                    }
+                Monitor.Exit(_thisLock);
+                thisLockTaken = false;
+            }
 
-                    if (sessionHandleLockTaken)
-                    {
-                        Monitor.Exit(SessionHandle);
-                        sessionHandleLockTaken = false;
-                    }
-                }
+            if (sessionHandleLockTaken)
+            {
+                Monitor.Exit(SessionHandle);
+                sessionHandleLockTaken = false;
             }
         }
 
@@ -1104,15 +1093,8 @@ namespace System.Net.WebSockets
             Debug.Assert(lockObject != null, "'lockObject' MUST NOT be NULL.");
             if (lockTaken)
             {
-                RuntimeHelpers.PrepareConstrainedRegions();
-                try
-                {
-                }
-                finally
-                {
-                    Monitor.Exit(lockObject);
-                    lockTaken = false;
-                }
+                Monitor.Exit(lockObject);
+                lockTaken = false;
             }
         }
 
index ef50864..ecdb454 100644 (file)
@@ -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 @@ namespace System.IO
             unsafe
             {
                 byte* pointer = null;
-                RuntimeHelpers.PrepareConstrainedRegions();
                 try
                 {
                     buffer.AcquirePointer(ref pointer);
@@ -260,7 +258,6 @@ namespace System.IO
                 {
                     byte* pointer = null;
 
-                    RuntimeHelpers.PrepareConstrainedRegions();
                     try
                     {
                         _buffer.AcquirePointer(ref pointer);
@@ -490,7 +487,6 @@ namespace System.IO
                     {
                         byte* pointer = null;
 
-                        RuntimeHelpers.PrepareConstrainedRegions();
                         try
                         {
                             _buffer.AcquirePointer(ref pointer);
@@ -606,7 +602,6 @@ namespace System.IO
                 unsafe
                 {
                     byte* pointer = null;
-                    RuntimeHelpers.PrepareConstrainedRegions();
                     try
                     {
                         _buffer.AcquirePointer(ref pointer);
@@ -786,7 +781,6 @@ namespace System.IO
                     }
 
                     byte* pointer = null;
-                    RuntimeHelpers.PrepareConstrainedRegions();
                     try
                     {
                         _buffer.AcquirePointer(ref pointer);
@@ -920,7 +914,6 @@ namespace System.IO
                 unsafe
                 {
                     byte* pointer = null;
-                    RuntimeHelpers.PrepareConstrainedRegions();
                     try
                     {
                         _buffer.AcquirePointer(ref pointer);
index 191e2fe..d6c2934 100644 (file)
@@ -14,7 +14,6 @@
 ===========================================================*/
 
 using System.Threading;
-using System.Runtime.CompilerServices;
 using System.Runtime.ConstrainedExecution;
 using System.Diagnostics;
 
@@ -235,10 +234,6 @@ namespace System.Runtime
                         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 @@ namespace System.Runtime
             if (LastKnownFreeAddressSpace < 0)
                 CheckForFreeAddressSpace(segmentSize, true);
 
-            RuntimeHelpers.PrepareConstrainedRegions();
-
             AddMemoryFailPointReservation((long)size);
             _mustSubtractReservation = true;
         }
@@ -317,8 +310,6 @@ namespace System.Runtime
             // within the GC heap.
             if (_mustSubtractReservation)
             {
-                RuntimeHelpers.PrepareConstrainedRegions();
-
                 AddMemoryFailPointReservation(-((long)_reservedMemory));
                 _mustSubtractReservation = false;
             }