@@ -404,20 +404,22 @@ pub struct CreateSpecificPlanArgs<'a, VM: VMBinding> {
404
404
405
405
impl < VM : VMBinding > CreateSpecificPlanArgs < ' _ , VM > {
406
406
/// Get a PlanCreateSpaceArgs that can be used to create a space
407
- pub fn get_space_args (
407
+ pub fn _get_space_args (
408
408
& mut self ,
409
409
name : & ' static str ,
410
410
zeroed : bool ,
411
411
permission_exec : bool ,
412
+ unlog_allocated_object : bool ,
413
+ unlog_traced_object : bool ,
412
414
vmrequest : VMRequest ,
413
415
) -> PlanCreateSpaceArgs < VM > {
414
416
PlanCreateSpaceArgs {
415
417
name,
416
418
zeroed,
417
419
permission_exec,
418
420
vmrequest,
419
- unlog_allocated_object : self . constraints . unlog_allocated_object ,
420
- unlog_traced_object : self . constraints . unlog_traced_object ,
421
+ unlog_allocated_object,
422
+ unlog_traced_object,
421
423
global_side_metadata_specs : self . global_side_metadata_specs . clone ( ) ,
422
424
vm_map : self . global_args . vm_map ,
423
425
mmapper : self . global_args . mmapper ,
@@ -429,39 +431,121 @@ impl<VM: VMBinding> CreateSpecificPlanArgs<'_, VM> {
429
431
global_state : self . global_args . state . clone ( ) ,
430
432
}
431
433
}
434
+
435
+ // The following are some convenience methods for common presets.
436
+ // These are not an exhaustive list -- it is just common presets that are used by most plans.
437
+
438
+ /// Get a preset for a nursery space (where young objects are located).
439
+ pub fn get_nursery_space_args (
440
+ & mut self ,
441
+ name : & ' static str ,
442
+ zeroed : bool ,
443
+ permission_exec : bool ,
444
+ vmrequest : VMRequest ,
445
+ ) -> PlanCreateSpaceArgs < VM > {
446
+ // Objects are allocatd as young, and when traced, they stay young. If they are copied out of the nursery space, they will be moved to a mature space,
447
+ // and log bits will be set in that case by the mature space.
448
+ self . _get_space_args ( name, zeroed, permission_exec, false , false , vmrequest)
449
+ }
450
+
451
+ /// Get a preset for a mature space (where mature objects are located).
452
+ pub fn get_mature_space_args (
453
+ & mut self ,
454
+ name : & ' static str ,
455
+ zeroed : bool ,
456
+ permission_exec : bool ,
457
+ vmrequest : VMRequest ,
458
+ ) -> PlanCreateSpaceArgs < VM > {
459
+ // Objects are allocated as mature (pre-tenured), and when traced, they stay mature.
460
+ // If an object gets copied into a mature space, the object is also mature,
461
+ self . _get_space_args ( name, zeroed, permission_exec, true , true , vmrequest)
462
+ }
463
+
464
+ // Get a preset for a mixed age space (where both young and mature objects are located).
465
+ pub fn get_mixed_age_space_args (
466
+ & mut self ,
467
+ name : & ' static str ,
468
+ zeroed : bool ,
469
+ permission_exec : bool ,
470
+ vmrequest : VMRequest ,
471
+ ) -> PlanCreateSpaceArgs < VM > {
472
+ // Objects are allocated as young, and when traced, they become mature objects.
473
+ self . _get_space_args ( name, zeroed, permission_exec, false , true , vmrequest)
474
+ }
475
+
476
+ /// Get a preset for spaces in a non-generational plan.
477
+ pub fn get_normal_space_args (
478
+ & mut self ,
479
+ name : & ' static str ,
480
+ zeroed : bool ,
481
+ permission_exec : bool ,
482
+ vmrequest : VMRequest ,
483
+ ) -> PlanCreateSpaceArgs < VM > {
484
+ // Non generational plan: we do not use any of the flags about log bits.
485
+ self . _get_space_args ( name, zeroed, permission_exec, false , false , vmrequest)
486
+ }
487
+
488
+ /// Get a preset for spaces in [`crate::plan::global::CommonPlan`].
489
+ /// Spaces like LOS which may include both young and mature objects should not use this method.
490
+ pub fn get_common_space_args (
491
+ & mut self ,
492
+ generational : bool ,
493
+ name : & ' static str ,
494
+ ) -> PlanCreateSpaceArgs < VM > {
495
+ self . get_base_space_args (
496
+ generational,
497
+ name,
498
+ false , // Common spaces are not executable.
499
+ )
500
+ }
501
+
502
+ /// Get a preset for spaces in [`crate::plan::global::BasePlan`].
503
+ pub fn get_base_space_args (
504
+ & mut self ,
505
+ generational : bool ,
506
+ name : & ' static str ,
507
+ permission_exec : bool ,
508
+ ) -> PlanCreateSpaceArgs < VM > {
509
+ if generational {
510
+ // In generational plans, common/base spaces behave like a mature space:
511
+ // * the objects in these spaces are not traced in a nursery GC
512
+ // * the log bits for the objects are maintained exactly the same as a mature space.
513
+ // Thus we consider them as mature spaces.
514
+ self . get_mature_space_args ( name, true , permission_exec, VMRequest :: discontiguous ( ) )
515
+ } else {
516
+ self . get_normal_space_args ( name, true , permission_exec, VMRequest :: discontiguous ( ) )
517
+ }
518
+ }
432
519
}
433
520
434
521
impl < VM : VMBinding > BasePlan < VM > {
435
522
#[ allow( unused_mut) ] // 'args' only needs to be mutable for certain features
436
523
pub fn new ( mut args : CreateSpecificPlanArgs < VM > ) -> BasePlan < VM > {
524
+ let _generational = args. constraints . generational ;
437
525
BasePlan {
438
526
#[ cfg( feature = "code_space" ) ]
439
- code_space : ImmortalSpace :: new ( args. get_space_args (
527
+ code_space : ImmortalSpace :: new ( args. get_base_space_args (
528
+ _generational,
440
529
"code_space" ,
441
530
true ,
442
- true ,
443
- VMRequest :: discontiguous ( ) ,
444
531
) ) ,
445
532
#[ cfg( feature = "code_space" ) ]
446
- code_lo_space : ImmortalSpace :: new ( args. get_space_args (
533
+ code_lo_space : ImmortalSpace :: new ( args. get_base_space_args (
534
+ _generational,
447
535
"code_lo_space" ,
448
536
true ,
449
- true ,
450
- VMRequest :: discontiguous ( ) ,
451
537
) ) ,
452
538
#[ cfg( feature = "ro_space" ) ]
453
- ro_space : ImmortalSpace :: new ( args. get_space_args (
539
+ ro_space : ImmortalSpace :: new ( args. get_base_space_args (
540
+ _generational,
454
541
"ro_space" ,
455
- true ,
456
542
false ,
457
- VMRequest :: discontiguous ( ) ,
458
543
) ) ,
459
544
#[ cfg( feature = "vm_space" ) ]
460
- vm_space : VMSpace :: new ( args. get_space_args (
545
+ vm_space : VMSpace :: new ( args. get_base_space_args (
546
+ _generational,
461
547
"vm_space" ,
462
- false ,
463
548
false , // it doesn't matter -- we are not mmapping for VM space.
464
- VMRequest :: discontiguous ( ) ,
465
549
) ) ,
466
550
467
551
global_state : args. global_args . state . clone ( ) ,
@@ -609,15 +693,16 @@ pub struct CommonPlan<VM: VMBinding> {
609
693
impl < VM : VMBinding > CommonPlan < VM > {
610
694
pub fn new ( mut args : CreateSpecificPlanArgs < VM > ) -> CommonPlan < VM > {
611
695
let needs_log_bit = args. constraints . needs_log_bit ;
696
+ let generational = args. constraints . generational ;
612
697
CommonPlan {
613
- immortal : ImmortalSpace :: new ( args. get_space_args (
614
- "immortal" ,
615
- true ,
616
- false ,
617
- VMRequest :: discontiguous ( ) ,
618
- ) ) ,
698
+ immortal : ImmortalSpace :: new ( args. get_common_space_args ( generational, "immortal" ) ) ,
619
699
los : LargeObjectSpace :: new (
620
- args. get_space_args ( "los" , true , false , VMRequest :: discontiguous ( ) ) ,
700
+ // LOS is a bit special, as it is a mixed age space. It has a logical nursery.
701
+ if generational {
702
+ args. get_mixed_age_space_args ( "los" , true , false , VMRequest :: discontiguous ( ) )
703
+ } else {
704
+ args. get_normal_space_args ( "los" , true , false , VMRequest :: discontiguous ( ) )
705
+ } ,
621
706
false ,
622
707
needs_log_bit,
623
708
) ,
@@ -677,7 +762,7 @@ impl<VM: VMBinding> CommonPlan<VM> {
677
762
}
678
763
679
764
fn new_nonmoving_space ( args : & mut CreateSpecificPlanArgs < VM > ) -> NonMovingSpace < VM > {
680
- let space_args = args. get_space_args ( "nonmoving" , true , false , VMRequest :: discontiguous ( ) ) ;
765
+ let space_args = args. get_common_space_args ( args . constraints . generational , "nonmoving" ) ;
681
766
cfg_if:: cfg_if! {
682
767
if #[ cfg( any( feature = "immortal_as_nonmoving" , feature = "marksweep_as_nonmoving" ) ) ] {
683
768
NonMovingSpace :: new( space_args)
@@ -686,7 +771,6 @@ impl<VM: VMBinding> CommonPlan<VM> {
686
771
NonMovingSpace :: new(
687
772
space_args,
688
773
crate :: policy:: immix:: ImmixSpaceArgs {
689
- #[ cfg( feature = "vo_bit" ) ]
690
774
mixed_age: false ,
691
775
never_move_objects: true ,
692
776
} ,
0 commit comments