Skip to content

Commit

Permalink
filtering out addresses conservatively reported that land in the GC r…
Browse files Browse the repository at this point in the history
…ange but not in bookkeeping range (#76737)

this fixes the last issue standing in the way of enabling regions for AoT. AoT could conservatively report addresses that land in the GC heap range but not in range that bookkeeping covers. so these need to filtered out.
  • Loading branch information
Maoni0 authored Oct 8, 2022
1 parent 415a417 commit cb6e5e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
30 changes: 14 additions & 16 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7925,18 +7925,12 @@ bool gc_heap::is_in_condemned_gc (uint8_t* o)
return true;
}

// REGIONS TODO -
// This method can be called by GCHeap::Promote/Relocate which means
// it could be in the heap range but not actually in a valid region.
// This would return true but find_object will return 0. But this
// seems counter-intuitive so we should consider a better implementation.
// 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_condemned (uint8_t* o)
bool gc_heap::is_in_bookkeeping_range (uint8_t* o)
{
if ((o >= g_gc_lowest_address) && (o < g_gc_highest_address))
return is_in_condemned_gc (o);
else
return false;
return ((o >= g_gc_lowest_address) && (o < bookkeeping_covered_committed));
}

inline
Expand Down Expand Up @@ -45898,7 +45892,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_condemned (o))
if (!gc_heap::is_in_bookkeeping_range (o) || !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 @@ -45957,7 +45951,12 @@ void GCHeap::Relocate (Object** ppObject, ScanContext* sc,
//dprintf (3, ("Relocate location %Ix\n", (size_t)ppObject));
dprintf (3, ("R: %Ix", (size_t)ppObject));

if (!object || !((object >= g_gc_lowest_address) && (object < g_gc_highest_address)))
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);
Expand Down Expand Up @@ -46412,17 +46411,16 @@ GCHeap::GetContainingObject (void *pInteriorPtr, bool fCollectedGenOnly)
gc_heap* hp = gc_heap::heap_of (o);

#ifdef USE_REGIONS
if (fCollectedGenOnly)
if (gc_heap::is_in_bookkeeping_range (o))
{
if (!gc_heap::is_in_condemned (o))
if (fCollectedGenOnly && !gc_heap::is_in_condemned_gc (o))
{
return NULL;
}
}
else
{
if (!((o >= g_gc_lowest_address) && (o < g_gc_highest_address)))
return NULL;
return NULL;
}
#else //USE_REGIONS

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/gc/gcpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ inline void FATAL_GC_ERROR()
// This means any empty regions can be freely used for any generation. For
// Server GC we will balance regions between heaps.
// For now disable regions for StandAlone GC, NativeAOT and MacOS builds
#if defined (HOST_64BIT) && !defined (BUILD_AS_STANDALONE) && !defined(__APPLE__) && !defined(FEATURE_NATIVEAOT)
#if defined (HOST_64BIT) && !defined (BUILD_AS_STANDALONE) && !defined(__APPLE__)
#define USE_REGIONS
#endif //HOST_64BIT && BUILD_AS_STANDALONE

Expand Down Expand Up @@ -3142,7 +3142,7 @@ class gc_heap
bool is_in_condemned_gc (uint8_t* o);
// requires checking if o is in the heap range first.
PER_HEAP_ISOLATED
bool is_in_condemned (uint8_t* o);
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

0 comments on commit cb6e5e7

Please sign in to comment.