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

Filter out addresses that are not in bookkeeping range during background promote #77067

Merged
merged 4 commits into from
Oct 21, 2022
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
76 changes: 48 additions & 28 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7905,6 +7905,32 @@ BOOL gc_heap::ephemeral_pointer_p (uint8_t* o)
#endif //USE_REGIONS
}

// This needs to check the range that's covered by bookkeeping because find_object will
// need to look at the brick table.
inline
bool gc_heap::is_in_find_object_range (uint8_t* o)
{
if (o == nullptr)
{
return false;
}
#if defined(USE_REGIONS) && defined(FEATURE_CONSERVATIVE_GC)
return ((o >= g_gc_lowest_address) && (o < bookkeeping_covered_committed));
#else //USE_REGIONS && FEATURE_CONSERVATIVE_GC
if ((o >= g_gc_lowest_address) && (o < g_gc_highest_address))
{
#ifdef USE_REGIONS
assert ((o >= g_gc_lowest_address) && (o < bookkeeping_covered_committed));
#endif //USE_REGIONS
return true;
}
else
{
return false;
}
#endif //USE_REGIONS && FEATURE_CONSERVATIVE_GC
}

#ifdef USE_REGIONS
// This assumes o is guaranteed to be in a region.
inline
Expand All @@ -7925,14 +7951,6 @@ bool gc_heap::is_in_condemned_gc (uint8_t* o)
return true;
}

// This needs to check the range that's covered by bookkeeping because find_object will
// need to look at the brick table.
inline
bool gc_heap::is_in_bookkeeping_range (uint8_t* o)
{
return ((o >= g_gc_lowest_address) && (o < bookkeeping_covered_committed));
}

inline
bool gc_heap::should_check_brick_for_reloc (uint8_t* o)
{
Expand Down Expand Up @@ -25185,8 +25203,10 @@ void gc_heap::background_promote (Object** ppObject, ScanContext* sc, uint32_t f

uint8_t* o = (uint8_t*)*ppObject;

if (o == 0)
if (!is_in_find_object_range (o))
{
return;
}

#ifdef DEBUG_DestroyedHandleValue
// we can race with destroy handle during concurrent scan
Expand Down Expand Up @@ -35949,8 +35969,10 @@ void gc_heap::background_promote_callback (Object** ppObject, ScanContext* sc,

uint8_t* o = (uint8_t*)*ppObject;

if (o == 0)
if (!is_in_find_object_range (o))
cshung marked this conversation as resolved.
Show resolved Hide resolved
{
return;
}

HEAP_FROM_THREAD;

Expand Down Expand Up @@ -45878,8 +45900,10 @@ void GCHeap::Promote(Object** ppObject, ScanContext* sc, uint32_t flags)

uint8_t* o = (uint8_t*)*ppObject;

if (o == 0)
if (!gc_heap::is_in_find_object_range (o))
{
return;
}

#ifdef DEBUG_DestroyedHandleValue
// we can race with destroy handle during concurrent scan
Expand All @@ -45892,7 +45916,7 @@ void GCHeap::Promote(Object** ppObject, ScanContext* sc, uint32_t flags)
gc_heap* hp = gc_heap::heap_of (o);

#ifdef USE_REGIONS
if (!gc_heap::is_in_bookkeeping_range (o) || !gc_heap::is_in_condemned_gc (o))
if (!gc_heap::is_in_condemned_gc (o))
#else //USE_REGIONS
if ((o < hp->gc_low) || (o >= hp->gc_high))
#endif //USE_REGIONS
Expand Down Expand Up @@ -45946,19 +45970,16 @@ void GCHeap::Relocate (Object** ppObject, ScanContext* sc,

uint8_t* object = (uint8_t*)(Object*)(*ppObject);

if (!gc_heap::is_in_find_object_range (object))
{
return;
}

THREAD_NUMBER_FROM_CONTEXT;

//dprintf (3, ("Relocate location %Ix\n", (size_t)ppObject));
dprintf (3, ("R: %Ix", (size_t)ppObject));

if (!object
#ifdef USE_REGIONS
|| !gc_heap::is_in_bookkeeping_range (object))
#else //USE_REGIONS
|| !((object >= g_gc_lowest_address) && (object < g_gc_highest_address)))
#endif //USE_REGIONS
return;

gc_heap* hp = gc_heap::heap_of (object);

#ifdef _DEBUG
Expand Down Expand Up @@ -46408,20 +46429,19 @@ GCHeap::GetContainingObject (void *pInteriorPtr, bool fCollectedGenOnly)
{
uint8_t *o = (uint8_t*)pInteriorPtr;

if (!gc_heap::is_in_find_object_range (o))
{
return NULL;
}

gc_heap* hp = gc_heap::heap_of (o);

#ifdef USE_REGIONS
if (gc_heap::is_in_bookkeeping_range (o))
{
if (fCollectedGenOnly && !gc_heap::is_in_condemned_gc (o))
{
return NULL;
}
}
else
if (fCollectedGenOnly && !gc_heap::is_in_condemned_gc (o))
{
return NULL;
}

#else //USE_REGIONS

uint8_t* lowest = (fCollectedGenOnly ? hp->gc_low : hp->lowest_address);
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/gc/gcpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3134,15 +3134,15 @@ class gc_heap
void copy_mark_bits_for_addresses (uint8_t* dest, uint8_t* src, size_t len);
#endif //BACKGROUND_GC

PER_HEAP_ISOLATED
bool is_in_find_object_range (uint8_t* o);

#ifdef USE_REGIONS
PER_HEAP_ISOLATED
bool is_in_gc_range (uint8_t* o);
// o is guaranteed to be in the heap range.
PER_HEAP_ISOLATED
bool is_in_condemned_gc (uint8_t* o);
// requires checking if o is in the heap range first.
PER_HEAP_ISOLATED
bool is_in_bookkeeping_range (uint8_t* o);
PER_HEAP_ISOLATED
bool should_check_brick_for_reloc (uint8_t* o);
#endif //USE_REGIONS
Expand Down