Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove calls to empty RuntimeHelpers.PrepareConstrainedRegions() #33191

Merged
merged 4 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ internal void Insert(ref T[] list, string? name, MemberListType listType)
{
bool lockTaken = false;

RuntimeHelpers.PrepareConstrainedRegions();
try
{
Monitor.Enter(this, ref lockTaken);
Expand Down Expand Up @@ -1576,7 +1575,6 @@ internal MethodInfo GetGenericMethodInfo(RuntimeMethodHandleInternal genericMeth
Interlocked.CompareExchange(ref s_methodInstantiationsLock!, new object(), null);

bool lockTaken = false;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
Monitor.Enter(s_methodInstantiationsLock, ref lockTaken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ internal void SetHandle(IntPtr handle)

internal void SetWaitObject(WaitHandle waitObject)
{
// needed for DangerousAddRef
RuntimeHelpers.PrepareConstrainedRegions();

m_internalWaitObject = waitObject;
if (waitObject != null)
{
Expand All @@ -61,8 +58,6 @@ internal bool Unregister(
)
{
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
Expand Down Expand Up @@ -383,7 +378,6 @@ public static bool BindHandle(SafeHandle osHandle)

bool ret = false;
bool mustReleaseSafeHandle = false;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
osHandle.DangerousAddRef(ref mustReleaseSafeHandle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1018,26 +1017,16 @@ private void ReleaseLocks(ref bool thisLockTaken, ref bool sessionHandleLockTake
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();
Marusyk marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}

Expand Down Expand Up @@ -1104,15 +1093,8 @@ private static void ReleaseLock(object lockObject, ref bool lockTaken)
Debug.Assert(lockObject != null, "'lockObject' MUST NOT be NULL.");
if (lockTaken)
{
RuntimeHelpers.PrepareConstrainedRegions();
Marusyk marked this conversation as resolved.
Show resolved Hide resolved
try
{
}
finally
{
Monitor.Exit(lockObject);
lockTaken = false;
}
Monitor.Exit(lockObject);
lockTaken = false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,7 +127,6 @@ protected void Initialize(SafeBuffer buffer, long offset, long length, FileAcces
unsafe
{
byte* pointer = null;
RuntimeHelpers.PrepareConstrainedRegions();
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
try
{
buffer.AcquirePointer(ref pointer);
Expand Down Expand Up @@ -260,7 +258,6 @@ public override void CopyTo(ReadOnlySpanAction<byte, object?> callback, object?
{
byte* pointer = null;

RuntimeHelpers.PrepareConstrainedRegions();
try
{
_buffer.AcquirePointer(ref pointer);
Expand Down Expand Up @@ -490,7 +487,6 @@ internal int ReadCore(Span<byte> buffer)
{
byte* pointer = null;

RuntimeHelpers.PrepareConstrainedRegions();
try
{
_buffer.AcquirePointer(ref pointer);
Expand Down Expand Up @@ -606,7 +602,6 @@ public override int ReadByte()
unsafe
{
byte* pointer = null;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
_buffer.AcquirePointer(ref pointer);
Expand Down Expand Up @@ -786,7 +781,6 @@ internal unsafe void WriteCore(ReadOnlySpan<byte> buffer)
}

byte* pointer = null;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
_buffer.AcquirePointer(ref pointer);
Expand Down Expand Up @@ -920,7 +914,6 @@ public override void WriteByte(byte value)
unsafe
{
byte* pointer = null;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
_buffer.AcquirePointer(ref pointer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
===========================================================*/

using System.Threading;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Diagnostics;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -286,8 +281,6 @@ public MemoryFailPoint(int sizeInMegabytes)
if (LastKnownFreeAddressSpace < 0)
CheckForFreeAddressSpace(segmentSize, true);

RuntimeHelpers.PrepareConstrainedRegions();

AddMemoryFailPointReservation((long)size);
_mustSubtractReservation = true;
}
Expand Down Expand Up @@ -317,8 +310,6 @@ private void Dispose(bool disposing)
// within the GC heap.
if (_mustSubtractReservation)
{
RuntimeHelpers.PrepareConstrainedRegions();

AddMemoryFailPointReservation(-((long)_reservedMemory));
_mustSubtractReservation = false;
}
Expand Down