Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Feedback for GC method
  • Loading branch information
AaronRobinsonMSFT committed Jan 25, 2024
commit 7c5dbd03e22e89888f56d728442bed9bfc7dc53f
14 changes: 9 additions & 5 deletions src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,17 @@ public static void KeepAlive(object? obj)
//
public static int GetGeneration(WeakReference wo)
{
int result = GetGenerationWR(wo.WeakHandle);
// Note - This throws an NRE if given a null weak reference.
object? obj = GCHandle.InternalGet(wo.WeakHandle);
KeepAlive(wo);
return result;
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "GCInterface_GetGenerationWR")]
private static partial int GetGenerationWR(IntPtr handle);
if (obj is null)
{
throw new ArgumentNullException(nameof(wo));
}

return GetGeneration(obj);
}

// Returns the maximum GC generation. Currently assumes only 1 heap.
//
Expand Down
32 changes: 0 additions & 32 deletions src/coreclr/vm/comutilnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,38 +795,6 @@ extern "C" int QCALLTYPE GCInterface_EndNoGCRegion()
return retVal;
}

/*===============================GetGenerationWR================================
**Action: Returns the generation in which the object pointed to by a WeakReference is found.
**Returns:
**Arguments: args->handle -- the OBJECTHANDLE to the object which we're locating.
**Exceptions: ArgumentException if handle points to an object which is not accessible.
==============================================================================*/
extern "C" int QCALLTYPE GCInterface_GetGenerationWR(LPVOID handle)
{
QCALL_CONTRACT;

int retVal = 0;

BEGIN_QCALL;

GCX_COOP();

OBJECTREF temp = NULL;
GCPROTECT_BEGIN(temp);

temp = ObjectFromHandle((OBJECTHANDLE) handle);
if (temp == NULL)
COMPlusThrowArgumentNull(W("wo"));

retVal = (INT32)GCHeapUtilities::GetGCHeap()->WhichGeneration(OBJECTREFToObject(temp));

GCPROTECT_END();

END_QCALL;

return retVal;
}

FCIMPL0(int, GCInterface::GetLastGCPercentTimeInGC)
{
FCALL_CONTRACT;
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/comutilnative.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ extern "C" int QCALLTYPE GCInterface_StartNoGCRegion(INT64 totalSize, BOOL lohSi

extern "C" int QCALLTYPE GCInterface_EndNoGCRegion();

extern "C" int QCALLTYPE GCInterface_GetGenerationWR(LPVOID handle);

extern "C" void QCALLTYPE GCInterface_AddMemoryPressure(UINT64 bytesAllocated);

extern "C" void QCALLTYPE GCInterface_RemoveMemoryPressure(UINT64 bytesAllocated);
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/qcallentrypoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ static const Entry s_QCall[] =
DllImportEntry(GCInterface_WaitForFullGCComplete)
DllImportEntry(GCInterface_StartNoGCRegion)
DllImportEntry(GCInterface_EndNoGCRegion)
DllImportEntry(GCInterface_GetGenerationWR)
DllImportEntry(GCInterface_GetTotalMemory)
DllImportEntry(GCInterface_Collect)
DllImportEntry(GCInterface_WaitForPendingFinalizers)
Expand Down