@@ -409,6 +409,43 @@ impl ReservedAllocators {
409
409
"Allocator mapping declared more free list allocators than the max allowed."
410
410
) ;
411
411
}
412
+
413
+ // We may add more allocators from common/base plan after reserved allocators.
414
+
415
+ fn add_bump_pointer_allocator ( & mut self ) -> AllocatorSelector {
416
+ let selector = AllocatorSelector :: BumpPointer ( self . n_bump_pointer ) ;
417
+ self . n_bump_pointer += 1 ;
418
+ selector
419
+ }
420
+ fn add_large_object_allocator ( & mut self ) -> AllocatorSelector {
421
+ let selector = AllocatorSelector :: LargeObject ( self . n_large_object ) ;
422
+ self . n_large_object += 1 ;
423
+ selector
424
+ }
425
+ #[ allow( dead_code) ]
426
+ fn add_malloc_allocator ( & mut self ) -> AllocatorSelector {
427
+ let selector = AllocatorSelector :: Malloc ( self . n_malloc ) ;
428
+ self . n_malloc += 1 ;
429
+ selector
430
+ }
431
+ #[ allow( dead_code) ]
432
+ fn add_immix_allocator ( & mut self ) -> AllocatorSelector {
433
+ let selector = AllocatorSelector :: Immix ( self . n_immix ) ;
434
+ self . n_immix += 1 ;
435
+ selector
436
+ }
437
+ #[ allow( dead_code) ]
438
+ fn add_mark_compact_allocator ( & mut self ) -> AllocatorSelector {
439
+ let selector = AllocatorSelector :: MarkCompact ( self . n_mark_compact ) ;
440
+ self . n_mark_compact += 1 ;
441
+ selector
442
+ }
443
+ #[ allow( dead_code) ]
444
+ fn add_free_list_allocator ( & mut self ) -> AllocatorSelector {
445
+ let selector = AllocatorSelector :: FreeList ( self . n_free_list ) ;
446
+ self . n_free_list += 1 ;
447
+ selector
448
+ }
412
449
}
413
450
414
451
/// Create an allocator mapping for spaces in Common/BasePlan for a plan. A plan should reserve its own allocators.
@@ -430,35 +467,22 @@ pub(crate) fn create_allocator_mapping(
430
467
431
468
#[ cfg( feature = "code_space" ) ]
432
469
{
433
- map[ AllocationSemantics :: Code ] = AllocatorSelector :: BumpPointer ( reserved. n_bump_pointer ) ;
434
- reserved. n_bump_pointer += 1 ;
435
-
436
- map[ AllocationSemantics :: LargeCode ] =
437
- AllocatorSelector :: BumpPointer ( reserved. n_bump_pointer ) ;
438
- reserved. n_bump_pointer += 1 ;
470
+ map[ AllocationSemantics :: Code ] = reserved. add_bump_pointer_allocator ( ) ;
471
+ map[ AllocationSemantics :: LargeCode ] = reserved. add_bump_pointer_allocator ( ) ;
439
472
}
440
473
441
474
#[ cfg( feature = "ro_space" ) ]
442
475
{
443
- map[ AllocationSemantics :: ReadOnly ] =
444
- AllocatorSelector :: BumpPointer ( reserved. n_bump_pointer ) ;
445
- reserved. n_bump_pointer += 1 ;
476
+ map[ AllocationSemantics :: ReadOnly ] = reserved. add_bump_pointer_allocator ( ) ;
446
477
}
447
478
448
479
// spaces in common plan
449
480
450
481
if include_common_plan {
451
- map[ AllocationSemantics :: Immortal ] =
452
- AllocatorSelector :: BumpPointer ( reserved. n_bump_pointer ) ;
453
- reserved. n_bump_pointer += 1 ;
454
-
455
- map[ AllocationSemantics :: Los ] = AllocatorSelector :: LargeObject ( reserved. n_large_object ) ;
456
- reserved. n_large_object += 1 ;
457
-
482
+ map[ AllocationSemantics :: Immortal ] = reserved. add_bump_pointer_allocator ( ) ;
483
+ map[ AllocationSemantics :: Los ] = reserved. add_large_object_allocator ( ) ;
458
484
// TODO: This should be freelist allocator once we use marksweep for nonmoving space.
459
- map[ AllocationSemantics :: NonMoving ] =
460
- AllocatorSelector :: BumpPointer ( reserved. n_bump_pointer ) ;
461
- reserved. n_bump_pointer += 1 ;
485
+ map[ AllocationSemantics :: NonMoving ] = reserved. add_bump_pointer_allocator ( ) ;
462
486
}
463
487
464
488
reserved. validate ( ) ;
@@ -487,45 +511,34 @@ pub(crate) fn create_space_mapping<VM: VMBinding>(
487
511
#[ cfg( feature = "code_space" ) ]
488
512
{
489
513
vec. push ( (
490
- AllocatorSelector :: BumpPointer ( reserved. n_bump_pointer ) ,
514
+ reserved. add_bump_pointer_allocator ( ) ,
491
515
& plan. base ( ) . code_space ,
492
516
) ) ;
493
- reserved. n_bump_pointer += 1 ;
494
517
vec. push ( (
495
- AllocatorSelector :: BumpPointer ( reserved. n_bump_pointer ) ,
518
+ reserved. add_bump_pointer_allocator ( ) ,
496
519
& plan. base ( ) . code_lo_space ,
497
520
) ) ;
498
- reserved. n_bump_pointer += 1 ;
499
521
}
500
522
501
523
#[ cfg( feature = "ro_space" ) ]
502
- {
503
- vec. push ( (
504
- AllocatorSelector :: BumpPointer ( reserved. n_bump_pointer ) ,
505
- & plan. base ( ) . ro_space ,
506
- ) ) ;
507
- reserved. n_bump_pointer += 1 ;
508
- }
524
+ vec. push ( ( reserved. add_bump_pointer_allocator ( ) , & plan. base ( ) . ro_space ) ) ;
509
525
510
526
// spaces in CommonPlan
511
527
512
528
if include_common_plan {
513
529
vec. push ( (
514
- AllocatorSelector :: BumpPointer ( reserved. n_bump_pointer ) ,
530
+ reserved. add_bump_pointer_allocator ( ) ,
515
531
plan. common ( ) . get_immortal ( ) ,
516
532
) ) ;
517
- reserved. n_bump_pointer += 1 ;
518
533
vec. push ( (
519
- AllocatorSelector :: LargeObject ( reserved. n_large_object ) ,
534
+ reserved. add_large_object_allocator ( ) ,
520
535
plan. common ( ) . get_los ( ) ,
521
536
) ) ;
522
- reserved. n_large_object += 1 ;
523
537
// TODO: This should be freelist allocator once we use marksweep for nonmoving space.
524
538
vec. push ( (
525
- AllocatorSelector :: BumpPointer ( reserved. n_bump_pointer ) ,
539
+ reserved. add_bump_pointer_allocator ( ) ,
526
540
plan. common ( ) . get_nonmoving ( ) ,
527
541
) ) ;
528
- reserved. n_bump_pointer += 1 ;
529
542
}
530
543
531
544
reserved. validate ( ) ;
0 commit comments