Skip to content

Commit 2acef87

Browse files
authored
Filter out addresses that are not in bookkeeping range during background promote (#77067)
1 parent 7ebeed1 commit 2acef87

File tree

2 files changed

+51
-31
lines changed

2 files changed

+51
-31
lines changed

src/coreclr/gc/gc.cpp

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7907,6 +7907,32 @@ BOOL gc_heap::ephemeral_pointer_p (uint8_t* o)
79077907
#endif //USE_REGIONS
79087908
}
79097909

7910+
// This needs to check the range that's covered by bookkeeping because find_object will
7911+
// need to look at the brick table.
7912+
inline
7913+
bool gc_heap::is_in_find_object_range (uint8_t* o)
7914+
{
7915+
if (o == nullptr)
7916+
{
7917+
return false;
7918+
}
7919+
#if defined(USE_REGIONS) && defined(FEATURE_CONSERVATIVE_GC)
7920+
return ((o >= g_gc_lowest_address) && (o < bookkeeping_covered_committed));
7921+
#else //USE_REGIONS && FEATURE_CONSERVATIVE_GC
7922+
if ((o >= g_gc_lowest_address) && (o < g_gc_highest_address))
7923+
{
7924+
#ifdef USE_REGIONS
7925+
assert ((o >= g_gc_lowest_address) && (o < bookkeeping_covered_committed));
7926+
#endif //USE_REGIONS
7927+
return true;
7928+
}
7929+
else
7930+
{
7931+
return false;
7932+
}
7933+
#endif //USE_REGIONS && FEATURE_CONSERVATIVE_GC
7934+
}
7935+
79107936
#ifdef USE_REGIONS
79117937
// This assumes o is guaranteed to be in a region.
79127938
inline
@@ -7927,14 +7953,6 @@ bool gc_heap::is_in_condemned_gc (uint8_t* o)
79277953
return true;
79287954
}
79297955

7930-
// This needs to check the range that's covered by bookkeeping because find_object will
7931-
// need to look at the brick table.
7932-
inline
7933-
bool gc_heap::is_in_bookkeeping_range (uint8_t* o)
7934-
{
7935-
return ((o >= g_gc_lowest_address) && (o < bookkeeping_covered_committed));
7936-
}
7937-
79387956
inline
79397957
bool gc_heap::should_check_brick_for_reloc (uint8_t* o)
79407958
{
@@ -25214,8 +25232,10 @@ void gc_heap::background_promote (Object** ppObject, ScanContext* sc, uint32_t f
2521425232

2521525233
uint8_t* o = (uint8_t*)*ppObject;
2521625234

25217-
if (o == 0)
25235+
if (!is_in_find_object_range (o))
25236+
{
2521825237
return;
25238+
}
2521925239

2522025240
#ifdef DEBUG_DestroyedHandleValue
2522125241
// we can race with destroy handle during concurrent scan
@@ -35978,8 +35998,10 @@ void gc_heap::background_promote_callback (Object** ppObject, ScanContext* sc,
3597835998

3597935999
uint8_t* o = (uint8_t*)*ppObject;
3598036000

35981-
if (o == 0)
36001+
if (!is_in_find_object_range (o))
36002+
{
3598236003
return;
36004+
}
3598336005

3598436006
HEAP_FROM_THREAD;
3598536007

@@ -45907,8 +45929,10 @@ void GCHeap::Promote(Object** ppObject, ScanContext* sc, uint32_t flags)
4590745929

4590845930
uint8_t* o = (uint8_t*)*ppObject;
4590945931

45910-
if (o == 0)
45932+
if (!gc_heap::is_in_find_object_range (o))
45933+
{
4591145934
return;
45935+
}
4591245936

4591345937
#ifdef DEBUG_DestroyedHandleValue
4591445938
// we can race with destroy handle during concurrent scan
@@ -45921,7 +45945,7 @@ void GCHeap::Promote(Object** ppObject, ScanContext* sc, uint32_t flags)
4592145945
gc_heap* hp = gc_heap::heap_of (o);
4592245946

4592345947
#ifdef USE_REGIONS
45924-
if (!gc_heap::is_in_bookkeeping_range (o) || !gc_heap::is_in_condemned_gc (o))
45948+
if (!gc_heap::is_in_condemned_gc (o))
4592545949
#else //USE_REGIONS
4592645950
if ((o < hp->gc_low) || (o >= hp->gc_high))
4592745951
#endif //USE_REGIONS
@@ -45975,19 +45999,16 @@ void GCHeap::Relocate (Object** ppObject, ScanContext* sc,
4597545999

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

46002+
if (!gc_heap::is_in_find_object_range (object))
46003+
{
46004+
return;
46005+
}
46006+
4597846007
THREAD_NUMBER_FROM_CONTEXT;
4597946008

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

45983-
if (!object
45984-
#ifdef USE_REGIONS
45985-
|| !gc_heap::is_in_bookkeeping_range (object))
45986-
#else //USE_REGIONS
45987-
|| !((object >= g_gc_lowest_address) && (object < g_gc_highest_address)))
45988-
#endif //USE_REGIONS
45989-
return;
45990-
4599146012
gc_heap* hp = gc_heap::heap_of (object);
4599246013

4599346014
#ifdef _DEBUG
@@ -46437,20 +46458,19 @@ GCHeap::GetContainingObject (void *pInteriorPtr, bool fCollectedGenOnly)
4643746458
{
4643846459
uint8_t *o = (uint8_t*)pInteriorPtr;
4643946460

46461+
if (!gc_heap::is_in_find_object_range (o))
46462+
{
46463+
return NULL;
46464+
}
46465+
4644046466
gc_heap* hp = gc_heap::heap_of (o);
4644146467

4644246468
#ifdef USE_REGIONS
46443-
if (gc_heap::is_in_bookkeeping_range (o))
46444-
{
46445-
if (fCollectedGenOnly && !gc_heap::is_in_condemned_gc (o))
46446-
{
46447-
return NULL;
46448-
}
46449-
}
46450-
else
46469+
if (fCollectedGenOnly && !gc_heap::is_in_condemned_gc (o))
4645146470
{
4645246471
return NULL;
4645346472
}
46473+
4645446474
#else //USE_REGIONS
4645546475

4645646476
uint8_t* lowest = (fCollectedGenOnly ? hp->gc_low : hp->lowest_address);

src/coreclr/gc/gcpriv.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,15 +3134,15 @@ class gc_heap
31343134
void copy_mark_bits_for_addresses (uint8_t* dest, uint8_t* src, size_t len);
31353135
#endif //BACKGROUND_GC
31363136

3137+
PER_HEAP_ISOLATED
3138+
bool is_in_find_object_range (uint8_t* o);
3139+
31373140
#ifdef USE_REGIONS
31383141
PER_HEAP_ISOLATED
31393142
bool is_in_gc_range (uint8_t* o);
31403143
// o is guaranteed to be in the heap range.
31413144
PER_HEAP_ISOLATED
31423145
bool is_in_condemned_gc (uint8_t* o);
3143-
// requires checking if o is in the heap range first.
3144-
PER_HEAP_ISOLATED
3145-
bool is_in_bookkeeping_range (uint8_t* o);
31463146
PER_HEAP_ISOLATED
31473147
bool should_check_brick_for_reloc (uint8_t* o);
31483148
#endif //USE_REGIONS

0 commit comments

Comments
 (0)