@@ -462,20 +462,20 @@ static NOINLINE void *malloc_page(void)
462
462
region -> meta = (jl_gc_pagemeta_t * )(mem + pages_sz + freemap_sz );
463
463
region -> lb = 0 ;
464
464
region -> ub = 0 ;
465
+ region -> pg_cnt = REGION_PG_COUNT ;
465
466
#ifdef _OS_WINDOWS_
466
- VirtualAlloc (region -> freemap , REGION_PG_COUNT / 8 ,
467
+ VirtualAlloc (region -> freemap , region -> pg_cnt / 8 ,
467
468
MEM_COMMIT , PAGE_READWRITE );
468
- VirtualAlloc (region -> meta ,
469
- REGION_PG_COUNT * sizeof (jl_gc_pagemeta_t ),
469
+ VirtualAlloc (region -> meta , region -> pg_cnt * sizeof (jl_gc_pagemeta_t ),
470
470
MEM_COMMIT , PAGE_READWRITE );
471
471
#endif
472
- memset (region -> freemap , 0xff , REGION_PG_COUNT / 8 );
472
+ memset (region -> freemap , 0xff , region -> pg_cnt / 8 );
473
473
}
474
- for (i = region -> lb ; i < REGION_PG_COUNT / 32 ; i ++ ) {
474
+ for (i = region -> lb ; i < region -> pg_cnt / 32 ; i ++ ) {
475
475
if (region -> freemap [i ])
476
476
break ;
477
477
}
478
- if (i == REGION_PG_COUNT / 32 ) {
478
+ if (i == region -> pg_cnt / 32 ) {
479
479
// region full
480
480
region_i ++ ;
481
481
continue ;
@@ -516,12 +516,15 @@ static void free_page(void *p)
516
516
{
517
517
int pg_idx = -1 ;
518
518
int i ;
519
- for (i = 0 ; i < REGION_COUNT && regions [i ].pages != NULL ; i ++ ) {
520
- pg_idx = page_index (& regions [i ], p );
521
- if (pg_idx >= 0 && pg_idx < REGION_PG_COUNT ) break ;
519
+ region_t * region = regions ;
520
+ for (i = 0 ; i < REGION_COUNT && regions [i ].pages != NULL ; i ++ ) {
521
+ region = & regions [i ];
522
+ pg_idx = page_index (region , p );
523
+ if (pg_idx >= 0 && pg_idx < region -> pg_cnt ) {
524
+ break ;
525
+ }
522
526
}
523
- assert (i < REGION_COUNT && regions [i ].pages != NULL );
524
- region_t * region = & regions [i ];
527
+ assert (i < REGION_COUNT && region -> pages != NULL );
525
528
uint32_t msk = (uint32_t )(1 << (pg_idx % 32 ));
526
529
assert (!(region -> freemap [pg_idx /32 ] & msk ));
527
530
region -> freemap [pg_idx /32 ] ^= msk ;
@@ -534,7 +537,7 @@ static void free_page(void *p)
534
537
decommit_size = jl_page_size ;
535
538
p = (void * )((uintptr_t )region -> pages [pg_idx ].data & ~(jl_page_size - 1 )); // round down to the nearest page
536
539
pg_idx = page_index (region , p );
537
- if (pg_idx + n_pages > REGION_PG_COUNT ) goto no_decommit ;
540
+ if (pg_idx + n_pages > region -> pg_cnt ) goto no_decommit ;
538
541
for (; n_pages -- ; pg_idx ++ ) {
539
542
msk = (uint32_t )(1 << ((pg_idx % 32 )));
540
543
if (!(region -> freemap [pg_idx /32 ] & msk )) goto no_decommit ;
0 commit comments