@@ -1370,6 +1370,29 @@ rb_objspace_free(rb_objspace_t *objspace)
1370
1370
free (objspace );
1371
1371
}
1372
1372
1373
+ static void
1374
+ heap_pages_expand_sorted_to (rb_objspace_t * objspace , size_t next_length )
1375
+ {
1376
+ struct heap_page * * sorted ;
1377
+ size_t size = next_length * sizeof (struct heap_page * );
1378
+
1379
+ gc_report (3 , objspace , "heap_pages_expand_sorted: next_length: %d, size: %d\n" , (int )next_length , (int )size );
1380
+
1381
+ if (heap_pages_sorted_length > 0 ) {
1382
+ sorted = (struct heap_page * * )realloc (heap_pages_sorted , size );
1383
+ if (sorted ) heap_pages_sorted = sorted ;
1384
+ }
1385
+ else {
1386
+ sorted = heap_pages_sorted = (struct heap_page * * )malloc (size );
1387
+ }
1388
+
1389
+ if (sorted == 0 ) {
1390
+ rb_memerror ();
1391
+ }
1392
+
1393
+ heap_pages_sorted_length = next_length ;
1394
+ }
1395
+
1373
1396
static void
1374
1397
heap_pages_expand_sorted (rb_objspace_t * objspace )
1375
1398
{
@@ -1378,24 +1401,7 @@ heap_pages_expand_sorted(rb_objspace_t *objspace)
1378
1401
next_length += heap_tomb -> total_pages ;
1379
1402
1380
1403
if (next_length > heap_pages_sorted_length ) {
1381
- struct heap_page * * sorted ;
1382
- size_t size = next_length * sizeof (struct heap_page * );
1383
-
1384
- gc_report (3 , objspace , "heap_pages_expand_sorted: next_length: %d, size: %d\n" , (int )next_length , (int )size );
1385
-
1386
- if (heap_pages_sorted_length > 0 ) {
1387
- sorted = (struct heap_page * * )realloc (heap_pages_sorted , size );
1388
- if (sorted ) heap_pages_sorted = sorted ;
1389
- }
1390
- else {
1391
- sorted = heap_pages_sorted = (struct heap_page * * )malloc (size );
1392
- }
1393
-
1394
- if (sorted == 0 ) {
1395
- rb_memerror ();
1396
- }
1397
-
1398
- heap_pages_sorted_length = next_length ;
1404
+ heap_pages_expand_sorted_to (objspace , next_length );
1399
1405
}
1400
1406
}
1401
1407
@@ -1533,6 +1539,9 @@ heap_page_allocate(rb_objspace_t *objspace)
1533
1539
rb_bug ("same heap page is allocated: %p at %" PRIuVALUE , (void * )page_body , (VALUE )mid );
1534
1540
}
1535
1541
}
1542
+ if (heap_allocated_pages >= heap_pages_sorted_length ) {
1543
+ heap_pages_expand_sorted_to (objspace , heap_allocated_pages + 1 );
1544
+ }
1536
1545
if (hi < heap_allocated_pages ) {
1537
1546
MEMMOVE (& heap_pages_sorted [hi + 1 ], & heap_pages_sorted [hi ], struct heap_page_header * , heap_allocated_pages - hi );
1538
1547
}
@@ -1542,7 +1551,10 @@ heap_page_allocate(rb_objspace_t *objspace)
1542
1551
heap_allocated_pages ++ ;
1543
1552
objspace -> profile .total_allocated_pages ++ ;
1544
1553
1545
- if (RGENGC_CHECK_MODE ) assert (heap_allocated_pages <= heap_pages_sorted_length );
1554
+ if (heap_allocated_pages > heap_pages_sorted_length ) {
1555
+ rb_bug ("heap_page_allocate: allocated(%" PRIdSIZE ") > sorted(%" PRIdSIZE ")" ,
1556
+ heap_allocated_pages , heap_pages_sorted_length );
1557
+ }
1546
1558
1547
1559
if (heap_pages_lomem == 0 || heap_pages_lomem > start ) heap_pages_lomem = start ;
1548
1560
if (heap_pages_himem < end ) heap_pages_himem = end ;
0 commit comments