use crate::memory_manager;
use crate::util::alloc::AllocatorInfo;
use crate::util::options::PlanSelector;
use crate::util::test_util::fixtures::*;
use crate::util::test_util::mock_vm::*;
use crate::AllocationSemantics;
#[test]
pub fn test_allocator_info() {
with_mockvm(
default_setup,
|| {
let fixture = MMTKFixture::create();
let selector = memory_manager::get_allocator_mapping(
fixture.get_mmtk(),
AllocationSemantics::Default,
);
let base_offset = crate::plan::Mutator::<MockVM>::get_allocator_base_offset(selector);
let allocator_info = AllocatorInfo::new::<MockVM>(selector);
match *fixture.get_mmtk().get_options().plan {
PlanSelector::NoGC
| PlanSelector::Immix
| PlanSelector::SemiSpace
| PlanSelector::GenCopy
| PlanSelector::GenImmix
| PlanSelector::MarkCompact
| PlanSelector::Compressor
| PlanSelector::ConcurrentImmix
| PlanSelector::StickyImmix => {
let AllocatorInfo::BumpPointer {
bump_pointer_offset,
} = allocator_info
else {
panic!("Expected AllocatorInfo for a bump pointer allocator");
};
assert_eq!(
base_offset + crate::util::constants::BYTES_IN_ADDRESS,
bump_pointer_offset
);
}
PlanSelector::MarkSweep => {
if cfg!(feature = "malloc_mark_sweep") {
assert!(matches!(allocator_info, AllocatorInfo::None))
} else {
assert!(matches!(allocator_info, AllocatorInfo::Unimplemented))
}
}
PlanSelector::PageProtect => assert!(matches!(allocator_info, AllocatorInfo::None)),
}
},
no_cleanup,
)
}