Skip to content

Commit 77caee7

Browse files
Remove explicit GC Poll from GC.SuppressFinalize()
1 parent a3d6c25 commit 77caee7

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,18 @@ public static void WaitForPendingFinalizers()
346346

347347
// Indicates that the system should not call the Finalize() method on
348348
// an object that would normally require this call.
349-
[MethodImpl(MethodImplOptions.InternalCall)]
350-
private static extern void _SuppressFinalize(object o);
349+
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "GCInterface_SuppressFinalize")]
350+
[SuppressGCTransition]
351+
private static partial void SuppressFinalize(ObjectHandleOnStack obj);
351352

352-
public static void SuppressFinalize(object obj)
353+
public static unsafe void SuppressFinalize(object obj)
353354
{
354355
ArgumentNullException.ThrowIfNull(obj);
355356

356-
_SuppressFinalize(obj);
357+
if (RuntimeHelpers.GetMethodTable(obj)->HasFinalizer)
358+
{
359+
SuppressFinalize(ObjectHandleOnStack.Create(ref obj));
360+
}
357361
}
358362

359363
// Indicates that the system should call the Finalize() method on an object

src/coreclr/vm/comutilnative.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,21 +1106,14 @@ extern "C" void QCALLTYPE GCInterface_UnregisterFrozenSegment(void* segment)
11061106
**Arguments: Object of interest
11071107
**Exceptions: None
11081108
==============================================================================*/
1109-
FCIMPL1(void, GCInterface::SuppressFinalize, Object *obj)
1109+
extern "C" void QCALLTYPE GCInterface_SuppressFinalize(QCall::ObjectHandleOnStack pObj)
11101110
{
1111-
FCALL_CONTRACT;
1111+
QCALL_CONTRACT_NO_GC_TRANSITION;
11121112

11131113
// Checked by the caller
1114-
_ASSERTE(obj != NULL);
1115-
1116-
if (!obj->GetMethodTable ()->HasFinalizer())
1117-
return;
1118-
1119-
GCHeapUtilities::GetGCHeap()->SetFinalizationRun(obj);
1120-
FC_GC_POLL();
1114+
_ASSERTE(pObj.Get()->GetMethodTable()->HasFinalizer());
1115+
GCHeapUtilities::GetGCHeap()->SetFinalizationRun(OBJECTREFToObject(pObj.Get()));
11211116
}
1122-
FCIMPLEND
1123-
11241117

11251118
/*============================ReRegisterForFinalize==============================
11261119
**Action: Indicate that an object's finalizer should be run by the system.

src/coreclr/vm/comutilnative.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ class GCInterface {
181181

182182
static FCDECL0(int, GetMaxGeneration);
183183
static FCDECL1(void, KeepAlive, Object *obj);
184-
static FCDECL1(void, SuppressFinalize, Object *obj);
185184
static FCDECL2(int, CollectionCount, INT32 generation, INT32 getSpecialGCCount);
186185

187186
static FCDECL0(INT64, GetAllocatedBytesForCurrentThread);
@@ -212,6 +211,8 @@ extern "C" INT64 QCALLTYPE GCInterface_GetTotalMemory();
212211

213212
extern "C" void QCALLTYPE GCInterface_Collect(INT32 generation, INT32 mode);
214213

214+
extern "C" void QCALLTYPE GCInterface_SuppressFinalize(QCall::ObjectHandleOnStack pObj);
215+
215216
extern "C" void* QCALLTYPE GCInterface_GetNextFinalizableObject(QCall::ObjectHandleOnStack pObj);
216217

217218
extern "C" void QCALLTYPE GCInterface_WaitForPendingFinalizers();

src/coreclr/vm/ecalllist.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,6 @@ FCFuncStart(gGCInterfaceFuncs)
270270
FCFuncElement("GetGenerationSize", GCInterface::GetGenerationSize)
271271
FCFuncElement("GetGenerationInternal", GCInterface::GetGenerationInternal)
272272
FCFuncElement("GetMaxGeneration", GCInterface::GetMaxGeneration)
273-
FCFuncElement("_SuppressFinalize", GCInterface::SuppressFinalize)
274-
275273
FCFuncElement("GetAllocatedBytesForCurrentThread", GCInterface::GetAllocatedBytesForCurrentThread)
276274
FCFuncElement("GetTotalAllocatedBytesApproximate", GCInterface::GetTotalAllocatedBytesApproximate)
277275
FCFuncEnd()

src/coreclr/vm/qcallentrypoints.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ static const Entry s_QCall[] =
318318
DllImportEntry(GCInterface_AllocateNewArray)
319319
DllImportEntry(GCInterface_GetTotalMemory)
320320
DllImportEntry(GCInterface_Collect)
321+
DllImportEntry(GCInterface_SuppressFinalize)
321322
DllImportEntry(GCInterface_ReRegisterForFinalize)
322323
DllImportEntry(GCInterface_GetNextFinalizableObject)
323324
DllImportEntry(GCInterface_WaitForPendingFinalizers)

0 commit comments

Comments
 (0)