Skip to content

Commit d731b4c

Browse files
committed
WIP: Attempting to remove cfg in create_allocator_mapping
NOTE: IT DOESN'T COMPILE. create_allocator_mapping doesn't have the `<VM>` generic parameter, but the `NonMovingSpace` trait needs it. There ought to be a way to work around it.
1 parent 6bee4f0 commit d731b4c

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

src/plan/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(crate) use global::PlanTraceObject;
3131
mod mutator_context;
3232
pub use mutator_context::Mutator;
3333
pub use mutator_context::MutatorContext;
34+
pub(crate) use mutator_context::ReservedAllocators;
3435

3536
mod plan_constraints;
3637
pub use plan_constraints::PlanConstraints;

src/plan/mutator_context.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl ReservedAllocators {
439439

440440
// We may add more allocators from common/base plan after reserved allocators.
441441

442-
fn add_bump_pointer_allocator(&mut self) -> AllocatorSelector {
442+
pub(crate) fn add_bump_pointer_allocator(&mut self) -> AllocatorSelector {
443443
let selector = AllocatorSelector::BumpPointer(self.n_bump_pointer);
444444
self.n_bump_pointer += 1;
445445
selector
@@ -450,13 +450,13 @@ impl ReservedAllocators {
450450
selector
451451
}
452452
#[allow(dead_code)]
453-
fn add_malloc_allocator(&mut self) -> AllocatorSelector {
453+
pub(crate) fn add_malloc_allocator(&mut self) -> AllocatorSelector {
454454
let selector = AllocatorSelector::Malloc(self.n_malloc);
455455
self.n_malloc += 1;
456456
selector
457457
}
458458
#[allow(dead_code)]
459-
fn add_immix_allocator(&mut self) -> AllocatorSelector {
459+
pub(crate) fn add_immix_allocator(&mut self) -> AllocatorSelector {
460460
let selector = AllocatorSelector::Immix(self.n_immix);
461461
self.n_immix += 1;
462462
selector
@@ -506,20 +506,11 @@ pub(crate) fn create_allocator_mapping(
506506
// spaces in common plan
507507

508508
if include_common_plan {
509+
// TODO: This file currently contains information about all spaces (i.e. what allocator each space uses).
510+
// We really should let each space reserve its appropriate allocator.
509511
map[AllocationSemantics::Immortal] = reserved.add_bump_pointer_allocator();
510512
map[AllocationSemantics::Los] = reserved.add_large_object_allocator();
511-
map[AllocationSemantics::NonMoving] = if cfg!(not(any(
512-
feature = "immortal_as_nonmoving",
513-
feature = "marksweep_as_nonmoving"
514-
))) {
515-
reserved.add_immix_allocator()
516-
} else if cfg!(feature = "marksweep_as_nonmoving") {
517-
reserved.add_free_list_allocator()
518-
} else if cfg!(feature = "immortal_as_nonmoving") {
519-
reserved.add_bump_pointer_allocator()
520-
} else {
521-
panic!("No policy selected for nonmoving space")
522-
};
513+
map[AllocationSemantics::NonMoving] = ChosenNonMovingSpace::reserve_allocator(&mut reserved);
523514
}
524515

525516
reserved.validate();

src/policy/nonmovingspace.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
//! We can use Cargo features to choose one of `ImmixSpace` (default), `ImmortalSpace` and
44
//! `MarkSweepSpace` as the non-moving space.
55
6-
use crate::{util::VMWorkerThread, vm::VMBinding, AllocationSemantics, Mutator};
6+
use crate::{
7+
plan::ReservedAllocators,
8+
util::{alloc::AllocatorSelector, VMWorkerThread},
9+
vm::VMBinding,
10+
AllocationSemantics, Mutator,
11+
};
712

813
use super::space::{PlanCreateSpaceArgs, Space};
914

@@ -21,6 +26,8 @@ pub(crate) trait NonMovingSpace<VM: VMBinding>: Space<VM> {
2126
fn end_of_gc_nonmoving_space(&mut self);
2227
/// Call this in `common_release_func` when using this space as the non-moving space.
2328
fn release_mutator_nonmoving_space(mutator: &mut Mutator<VM>, tls: VMWorkerThread);
29+
/// Call this to reserve allocator in `create_space_mapping`.
30+
fn reserve_allocator(reserved: &mut ReservedAllocators) -> AllocatorSelector;
2431
}
2532

2633
impl<VM: VMBinding> NonMovingSpace<VM> for crate::policy::immortalspace::ImmortalSpace<VM> {
@@ -43,6 +50,10 @@ impl<VM: VMBinding> NonMovingSpace<VM> for crate::policy::immortalspace::Immorta
4350
fn release_mutator_nonmoving_space(_mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {
4451
// Do nothing
4552
}
53+
54+
fn reserve_allocator(reserved: &mut ReservedAllocators) -> AllocatorSelector {
55+
reserved.add_bump_pointer_allocator()
56+
}
4657
}
4758

4859
impl<VM: VMBinding> NonMovingSpace<VM>
@@ -75,6 +86,10 @@ impl<VM: VMBinding> NonMovingSpace<VM>
7586
.unwrap()
7687
.release();
7788
}
89+
90+
fn reserve_allocator(reserved: &mut ReservedAllocators) -> AllocatorSelector {
91+
reserved.add_malloc_allocator()
92+
}
7893
}
7994

8095
impl<VM: VMBinding> NonMovingSpace<VM> for crate::policy::immix::ImmixSpace<VM> {
@@ -113,6 +128,10 @@ impl<VM: VMBinding> NonMovingSpace<VM> for crate::policy::immix::ImmixSpace<VM>
113128
.unwrap()
114129
.reset();
115130
}
131+
132+
fn reserve_allocator(reserved: &mut ReservedAllocators) -> AllocatorSelector {
133+
reserved.add_immix_allocator()
134+
}
116135
}
117136

118137
// Choose one concrete non-moving space implementation according to the enabled Cargo feature.

0 commit comments

Comments
 (0)