use super::SemiSpace;
use crate::plan::barriers::NoBarrier;
use crate::plan::mutator_context::unreachable_prepare_func;
use crate::plan::mutator_context::Mutator;
use crate::plan::mutator_context::MutatorConfig;
use crate::plan::mutator_context::{
create_allocator_mapping, create_space_mapping, ReservedAllocators,
};
use crate::plan::AllocationSemantics;
use crate::util::alloc::allocators::{AllocatorSelector, Allocators};
use crate::util::alloc::BumpAllocator;
use crate::util::{VMMutatorThread, VMWorkerThread};
use crate::vm::VMBinding;
use crate::MMTK;
use enum_map::EnumMap;
pub fn ss_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {
let bump_allocator = unsafe {
mutator
.allocators
.get_allocator_mut(mutator.config.allocator_mapping[AllocationSemantics::Default])
}
.downcast_mut::<BumpAllocator<VM>>()
.unwrap();
bump_allocator.rebind(
mutator
.plan
.downcast_ref::<SemiSpace<VM>>()
.unwrap()
.tospace(),
);
}
const RESERVED_ALLOCATORS: ReservedAllocators = ReservedAllocators {
n_bump_pointer: 1,
..ReservedAllocators::DEFAULT
};
lazy_static! {
pub static ref ALLOCATOR_MAPPING: EnumMap<AllocationSemantics, AllocatorSelector> = {
let mut map = create_allocator_mapping(RESERVED_ALLOCATORS, true);
map[AllocationSemantics::Default] = AllocatorSelector::BumpPointer(0);
map
};
}
pub fn create_ss_mutator<VM: VMBinding>(
mutator_tls: VMMutatorThread,
mmtk: &'static MMTK<VM>,
) -> Mutator<VM> {
let ss = mmtk.get_plan().downcast_ref::<SemiSpace<VM>>().unwrap();
let config = MutatorConfig {
allocator_mapping: &ALLOCATOR_MAPPING,
space_mapping: Box::new({
let mut vec = create_space_mapping(RESERVED_ALLOCATORS, true, ss);
vec.push((AllocatorSelector::BumpPointer(0), ss.tospace()));
vec
}),
prepare_func: &unreachable_prepare_func,
release_func: &ss_mutator_release,
};
Mutator {
allocators: Allocators::<VM>::new(mutator_tls, mmtk, &config.space_mapping),
barrier: Box::new(NoBarrier),
mutator_tls,
config,
plan: ss,
}
}