Skip to content

Commit

Permalink
Frozen objects should be identified as Gen2 in the handle table (dotn…
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung committed Jan 20, 2024
1 parent 7ac5caf commit db3b80f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/coreclr/gc/env/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <assert.h>
#include <stdarg.h>
#include <memory.h>
#include <limits.h>

#include <new>

Expand Down
10 changes: 9 additions & 1 deletion src/coreclr/gc/handletable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
DWORD g_dwHandles = 0;
#endif // ENABLE_PERF_COUNTERS || FEATURE_EVENT_TRACE

#ifndef DACCESS_COMPILE
int GetConvertedGeneration(_UNCHECKED_OBJECTREF obj)
{
int generation = g_theGCHeap->WhichGeneration(obj);
return generation == INT_MAX ? max_generation : generation;
}
#endif //DACCESS_COMPILE

/****************************************************************************
*
* FORWARD DECLARATIONS
Expand Down Expand Up @@ -577,7 +585,7 @@ void HndWriteBarrierWorker(OBJECTHANDLE handle, _UNCHECKED_OBJECTREF value)
if (*pClumpAge != 0) // Perf optimization: if clumpAge is 0, nothing more to do
{
// find out generation
int generation = g_theGCHeap->WhichGeneration(value);
int generation = GetConvertedGeneration(value);
uint32_t uType = HandleFetchType(handle);

#ifdef FEATURE_ASYNC_PINNED_HANDLES
Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/gc/handletablepriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -942,3 +942,15 @@ void CALLBACK BlockVerifyAgeMapForBlocks(PTR_TableSegment pSegment, uint32_t uBl
PTR_TableSegment CALLBACK xxxAsyncSegmentIterator(PTR_HandleTable pTable, TableSegment *pPrevSegment, CrstHolderWithState *pCrstHolder);

/*--------------------------------------------------------------------------*/

#ifndef DACCESS_COMPILE

/*
* GetConvertedGeneration
*
* Get the generation of an object, where a frozen object is regarded as max_generation
*
*/
int GetConvertedGeneration(_UNCHECKED_OBJECTREF obj);

#endif //DACCESS_COMPILE
6 changes: 3 additions & 3 deletions src/coreclr/gc/handletablescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ void BlockResetAgeMapForBlocksWorker(uint32_t *pdwGen, uint32_t dwClumpMask, Sca
{
if (!HndIsNullOrDestroyedHandle(*pValue))
{
int thisAge = g_theGCHeap->WhichGeneration(*pValue);
int thisAge = GetConvertedGeneration(*pValue);
if (minAge > thisAge)
minAge = thisAge;

Expand All @@ -820,7 +820,7 @@ void BlockResetAgeMapForBlocksWorker(uint32_t *pdwGen, uint32_t dwClumpMask, Sca
[](Object*, Object* to, void* ctx)
{
int* minAge = reinterpret_cast<int*>(ctx);
int generation = g_theGCHeap->WhichGeneration(to);
int generation = GetConvertedGeneration(to);
if (*minAge > generation)
{
*minAge = generation;
Expand Down Expand Up @@ -903,7 +903,7 @@ static void VerifyObjectAndAge(_UNCHECKED_OBJECTREF from, _UNCHECKED_OBJECTREF o
{
VerifyObject(from, obj);

int thisAge = g_theGCHeap->WhichGeneration(obj);
int thisAge = GetConvertedGeneration(obj);

//debugging code
//if (minAge > thisAge && thisAge < g_theGCHeap->GetMaxGeneration())
Expand Down

0 comments on commit db3b80f

Please sign in to comment.