Skip to content

Commit d72e781

Browse files
committed
Refactoring to reduce ifdefs
1 parent e121749 commit d72e781

File tree

2 files changed

+38
-40
lines changed

2 files changed

+38
-40
lines changed

src/coreclr/gc/gc.cpp

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7905,6 +7905,32 @@ BOOL gc_heap::ephemeral_pointer_p (uint8_t* o)
79057905
#endif //USE_REGIONS
79067906
}
79077907

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

7928-
// This needs to check the range that's covered by bookkeeping because find_object will
7929-
// need to look at the brick table.
7930-
inline
7931-
bool gc_heap::is_in_bookkeeping_range (uint8_t* o)
7932-
{
7933-
return ((o >= g_gc_lowest_address) && (o < bookkeeping_covered_committed));
7934-
}
7935-
79367954
inline
79377955
bool gc_heap::should_check_brick_for_reloc (uint8_t* o)
79387956
{
@@ -25185,15 +25203,10 @@ void gc_heap::background_promote (Object** ppObject, ScanContext* sc, uint32_t f
2518525203

2518625204
uint8_t* o = (uint8_t*)*ppObject;
2518725205

25188-
if (o == 0)
25189-
return;
25190-
25191-
#if defined(FEATURE_CONSERVATIVE_GC) && defined(USE_REGIONS)
25192-
if (!is_in_bookkeeping_range (o))
25206+
if (!is_in_find_object_range (o))
2519325207
{
2519425208
return;
2519525209
}
25196-
#endif
2519725210

2519825211
#ifdef DEBUG_DestroyedHandleValue
2519925212
// we can race with destroy handle during concurrent scan
@@ -35956,15 +35969,10 @@ void gc_heap::background_promote_callback (Object** ppObject, ScanContext* sc,
3595635969

3595735970
uint8_t* o = (uint8_t*)*ppObject;
3595835971

35959-
if (o == 0)
35960-
return;
35961-
35962-
#if defined(FEATURE_CONSERVATIVE_GC) && defined(USE_REGIONS)
35963-
if (!is_in_bookkeeping_range (o))
35972+
if (!is_in_find_object_range (o))
3596435973
{
3596535974
return;
3596635975
}
35967-
#endif
3596835976

3596935977
HEAP_FROM_THREAD;
3597035978

@@ -45892,15 +45900,10 @@ void GCHeap::Promote(Object** ppObject, ScanContext* sc, uint32_t flags)
4589245900

4589345901
uint8_t* o = (uint8_t*)*ppObject;
4589445902

45895-
if (o == 0)
45896-
return;
45897-
45898-
#if defined(FEATURE_CONSERVATIVE_GC) && defined(USE_REGIONS)
45899-
if (!gc_heap::is_in_bookkeeping_range (o))
45903+
if (!gc_heap::is_in_find_object_range (o))
4590045904
{
4590145905
return;
4590245906
}
45903-
#endif
4590445907

4590545908
#ifdef DEBUG_DestroyedHandleValue
4590645909
// we can race with destroy handle during concurrent scan
@@ -45967,19 +45970,16 @@ void GCHeap::Relocate (Object** ppObject, ScanContext* sc,
4596745970

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

45973+
if (!gc_heap::is_in_find_object_range (object))
45974+
{
45975+
return;
45976+
}
45977+
4597045978
THREAD_NUMBER_FROM_CONTEXT;
4597145979

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

45975-
if (!object
45976-
#if defined(USE_REGIONS) && defined(FEATURE_CONSERVATIVE_GC)
45977-
|| !gc_heap::is_in_bookkeeping_range (object))
45978-
#else //USE_REGIONS && FEATURE_CONSERVATIVE_GC
45979-
|| !((object >= g_gc_lowest_address) && (object < g_gc_highest_address)))
45980-
#endif //USE_REGIONS && FEATURE_CONSERVATIVE_GC
45981-
return;
45982-
4598345983
gc_heap* hp = gc_heap::heap_of (object);
4598445984

4598545985
#ifdef _DEBUG
@@ -46429,12 +46429,10 @@ GCHeap::GetContainingObject (void *pInteriorPtr, bool fCollectedGenOnly)
4642946429
{
4643046430
uint8_t *o = (uint8_t*)pInteriorPtr;
4643146431

46432-
#if defined(FEATURE_CONSERVATIVE_GC) && defined(USE_REGIONS)
46433-
if (!gc_heap::is_in_bookkeeping_range (o))
46432+
if (!gc_heap::is_in_find_object_range (o))
4643446433
{
4643546434
return NULL;
4643646435
}
46437-
#endif
4643846436

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

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)