Skip to content

Commit 7ea7f2e

Browse files
MokoSanmrsharm
andauthored
Updated type of heap_segment_survived from int to size_t to facilitate survival >= 2GB. (#80302)
* Updated type of survived from int to size_t * Fixed another printf message * Reordered the survived field * Addressed feedback. Co-authored-by: Mukund Raghav Sharma <[email protected]>
1 parent d37197c commit 7ea7f2e

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

src/coreclr/gc/env/gcenv.base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ inline HRESULT HRESULT_FROM_WIN32(unsigned long x)
8686
#define CLR_E_GC_BAD_AFFINITY_CONFIG_FORMAT 0x8013200B
8787
#define CLR_E_GC_BAD_HARD_LIMIT 0x8013200D
8888
#define CLR_E_GC_LARGE_PAGE_MISSING_HARD_LIMIT 0x8013200E
89+
#define CLR_E_GC_BAD_REGION_SIZE 0x8013200F
8990

9091
#define NOERROR 0x0
9192
#define ERROR_TIMEOUT 1460

src/coreclr/gc/gc.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23106,15 +23106,15 @@ void gc_heap::sync_promoted_bytes()
2310623106
total_old_card_surv += g_heaps[hp_idx]->old_card_survived_per_region[region_index];
2310723107
}
2310823108

23109-
heap_segment_survived (current_region) = (int)total_surv;
23109+
heap_segment_survived (current_region) = total_surv;
2311023110
heap_segment_old_card_survived (current_region) = (int)total_old_card_surv;
2311123111
#else
23112-
heap_segment_survived (current_region) = (int)(survived_per_region[region_index]);
23112+
heap_segment_survived (current_region) = survived_per_region[region_index];
2311323113
heap_segment_old_card_survived (current_region) =
2311423114
(int)(old_card_survived_per_region[region_index]);
2311523115
#endif //MULTIPLE_HEAPS
2311623116

23117-
dprintf (REGIONS_LOG, ("region #%zd %p surv %d, old card surv %d",
23117+
dprintf (REGIONS_LOG, ("region #%zd %p surv %zd, old card surv %d",
2311823118
region_index,
2311923119
heap_segment_mem (current_region),
2312023120
heap_segment_survived (current_region),
@@ -23308,8 +23308,8 @@ void gc_heap::equalize_promoted_bytes()
2330823308
{
2330923309
break;
2331023310
}
23311-
assert (surv_per_heap[i] >= (size_t)heap_segment_survived (region));
23312-
dprintf (REGIONS_LOG, ("heap: %d surv: %zd - %d = %zd",
23311+
assert (surv_per_heap[i] >= heap_segment_survived (region));
23312+
dprintf (REGIONS_LOG, ("heap: %d surv: %zd - %zd = %zd",
2331323313
i,
2331423314
surv_per_heap[i],
2331523315
heap_segment_survived (region),
@@ -23320,7 +23320,7 @@ void gc_heap::equalize_promoted_bytes()
2332023320
heap_segment_next (region) = surplus_regions;
2332123321
surplus_regions = region;
2332223322

23323-
max_survived = max (max_survived, (size_t)heap_segment_survived (region));
23323+
max_survived = max (max_survived, heap_segment_survived (region));
2332423324
}
2332523325
if (surv_per_heap[i] < avg_surv_per_heap)
2332623326
{
@@ -23338,7 +23338,7 @@ void gc_heap::equalize_promoted_bytes()
2333823338
heap_segment* next_region;
2333923339
for (heap_segment* region = surplus_regions; region != nullptr; region = next_region)
2334023340
{
23341-
int size_class = (int)(heap_segment_survived (region)*survived_scale_factor);
23341+
size_t size_class = (size_t)(heap_segment_survived (region)*survived_scale_factor);
2334223342
assert ((0 <= size_class) && (size_class < NUM_SIZE_CLASSES));
2334323343
next_region = heap_segment_next (region);
2334423344
heap_segment_next (region) = surplus_regions_by_size_class[size_class];
@@ -23400,7 +23400,7 @@ void gc_heap::equalize_promoted_bytes()
2340023400
g_heaps[heap_num]->thread_rw_region_front (gen_idx, region);
2340123401

2340223402
// adjust survival for this heap
23403-
dprintf (REGIONS_LOG, ("heap: %d surv: %zd + %d = %zd",
23403+
dprintf (REGIONS_LOG, ("heap: %d surv: %zd + %zd = %zd",
2340423404
heap_num,
2340523405
surv_per_heap[heap_num],
2340623406
heap_segment_survived (region),
@@ -31434,7 +31434,7 @@ heap_segment* gc_heap::find_first_valid_region (heap_segment* region, bool compa
3143431434
if (heap_segment_swept_in_plan (current_region))
3143531435
{
3143631436
int gen_num = heap_segment_gen_num (current_region);
31437-
dprintf (REGIONS_LOG, ("threading SIP region %p surv %d onto gen%d",
31437+
dprintf (REGIONS_LOG, ("threading SIP region %p surv %zd onto gen%d",
3143831438
heap_segment_mem (current_region), heap_segment_survived (current_region), gen_num));
3143931439

3144031440
generation* gen = generation_of (gen_num);
@@ -31760,8 +31760,8 @@ bool gc_heap::should_sweep_in_plan (heap_segment* region)
3176031760
size_t basic_region_size = (size_t)1 << min_segment_size_shr;
3176131761
assert (heap_segment_gen_num (region) == heap_segment_plan_gen_num (region));
3176231762

31763-
int surv_ratio = (int)(((double)heap_segment_survived (region) * 100.0) / (double)basic_region_size);
31764-
dprintf (2222, ("SSIP: region %p surv %d / %zd = %d%%(%d)",
31763+
uint8_t surv_ratio = (uint8_t)(((double)heap_segment_survived (region) * 100.0) / (double)basic_region_size);
31764+
dprintf (2222, ("SSIP: region %p surv %hu / %zd = %d%%(%d)",
3176531765
heap_segment_mem (region),
3176631766
heap_segment_survived (region),
3176731767
basic_region_size,
@@ -31971,12 +31971,12 @@ void gc_heap::sweep_region_in_plan (heap_segment* region,
3197131971
size_t region_index = get_basic_region_index_for_address (heap_segment_mem (region));
3197231972
dprintf (REGIONS_LOG, ("region #%zd %p survived %zd, %s recorded %d",
3197331973
region_index, heap_segment_mem (region), survived,
31974-
((survived == (size_t)heap_segment_survived (region)) ? "same as" : "diff from"),
31974+
((survived == heap_segment_survived (region)) ? "same as" : "diff from"),
3197531975
heap_segment_survived (region)));
3197631976
#ifdef MULTIPLE_HEAPS
31977-
assert (survived <= (size_t)heap_segment_survived (region));
31977+
assert (survived <= heap_segment_survived (region));
3197831978
#else
31979-
assert (survived == (size_t)heap_segment_survived (region));
31979+
assert (survived == heap_segment_survived (region));
3198031980
#endif //MULTIPLE_HEAPS
3198131981
#endif //_DEBUG
3198231982

@@ -45422,6 +45422,12 @@ HRESULT GCHeap::Initialize()
4542245422
gc_heap::enable_special_regions_p = (bool)GCConfig::GetGCEnableSpecialRegions();
4542345423
size_t gc_region_size = (size_t)GCConfig::GetGCRegionSize();
4542445424

45425+
// Constraining the size of region size to be < 2 GB.
45426+
if (gc_region_size >= MAX_REGION_SIZE)
45427+
{
45428+
return CLR_E_GC_BAD_REGION_SIZE;
45429+
}
45430+
4542545431
// Adjust GCRegionSize based on how large each heap would be, for smaller heaps we would
4542645432
// like to keep Region sizes small. We choose between 4, 2 and 1mb based on the calculations
4542745433
// below (unless its configured explictly) such that there are at least 2 regions available

src/coreclr/gc/gcpriv.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ void GCLogConfig (const char *fmt, ... );
191191

192192
#define MAX_NUM_BUCKETS (MAX_INDEX_POWER2 - MIN_INDEX_POWER2 + 1)
193193

194+
#ifdef USE_REGIONS
195+
#define MAX_REGION_SIZE 0x80000000
196+
#endif // USE_REGIONS
197+
194198
#define MAX_NUM_FREE_SPACES 200
195199
#define MIN_NUM_FREE_SPACES 5
196200

@@ -5738,6 +5742,7 @@ class heap_segment
57385742
uint8_t* saved_allocated;
57395743
uint8_t* saved_bg_allocated;
57405744
#ifdef USE_REGIONS
5745+
size_t survived;
57415746
// These generation numbers are initialized to -1.
57425747
// For plan_gen_num:
57435748
// for all regions in condemned generations it needs
@@ -5752,7 +5757,6 @@ class heap_segment
57525757
// swept_in_plan_p can be folded into gen_num.
57535758
bool swept_in_plan_p;
57545759
int plan_gen_num;
5755-
int survived;
57565760
int old_card_survived;
57575761
int pinned_survived;
57585762
// at the end of each GC, we increase each region in the region free list
@@ -6191,7 +6195,7 @@ int& heap_segment_age_in_free (heap_segment* inst)
61916195
return inst->age_in_free;
61926196
}
61936197
inline
6194-
int& heap_segment_survived (heap_segment* inst)
6198+
size_t& heap_segment_survived (heap_segment* inst)
61956199
{
61966200
return inst->survived;
61976201
}

src/coreclr/inc/corerror.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,12 @@
21332133
<Comment>During a GC initialization, GC large page support requires hard limit settings.</Comment>
21342134
</HRESULT>
21352135

2136+
<HRESULT NumericValue="0x8013200F">
2137+
<SymbolicName>CLR_E_GC_BAD_REGION_SIZE</SymbolicName>
2138+
<Message>"GC Region Size must be less than 2GB."</Message>
2139+
<Comment>During a GC initialization, GC Region Size must be less than 2GB.</Comment>
2140+
</HRESULT>
2141+
21362142
<HRESULT NumericValue="E_ACCESSDENIED">
21372143
<SymbolicName>COR_E_UNAUTHORIZEDACCESS</SymbolicName>
21382144
<Comment> 0x80070005 // Access is denied.</Comment>

src/coreclr/pal/prebuilt/corerror/mscorurt.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,5 +301,6 @@ BEGIN
301301
MSG_FOR_URT_HR(CLR_E_GC_BAD_AFFINITY_CONFIG_FORMAT) "GCHeapAffinitizeRanges configuration string has invalid format."
302302
MSG_FOR_URT_HR(CLR_E_GC_BAD_HARD_LIMIT) "GC heap hard limit configuration is invalid."
303303
MSG_FOR_URT_HR(CLR_E_GC_LARGE_PAGE_MISSING_HARD_LIMIT) "GC large page support requires hard limit settings."
304+
MSG_FOR_URT_HR(CLR_E_GC_BAD_REGION_SIZE) "GC Region Size must be less than 2GB."
304305
MSG_FOR_URT_HR(COR_E_BADIMAGEFORMAT) "The format of a DLL or executable being loaded is invalid."
305306
END

src/coreclr/pal/prebuilt/inc/corerror.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@
374374
#define CLR_E_GC_BAD_AFFINITY_CONFIG_FORMAT EMAKEHR(0x200b)
375375
#define CLR_E_GC_BAD_HARD_LIMIT EMAKEHR(0x200d)
376376
#define CLR_E_GC_LARGE_PAGE_MISSING_HARD_LIMIT EMAKEHR(0x200e)
377+
#define CLR_E_GC_BAD_REGION_SIZE EMAKEHR(0x200f)
377378
#define COR_E_UNAUTHORIZEDACCESS E_ACCESSDENIED
378379
#define COR_E_ARGUMENT E_INVALIDARG
379380
#define COR_E_INVALIDCAST E_NOINTERFACE

0 commit comments

Comments
 (0)