Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let FreeListPageResource hold FreeList in sync #925

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/mmtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl<VM: VMBinding> MMTK<VM> {

let scheduler = GCWorkScheduler::new(num_workers, (*options.thread_affinity).clone());

let plan = crate::plan::create_plan(
let mut plan = crate::plan::create_plan(
*options.plan,
VM_MAP.as_ref(),
MMAPPER.as_ref(),
Expand All @@ -128,11 +128,13 @@ impl<VM: VMBinding> MMTK<VM> {
);

// TODO: This probably does not work if we have multiple MMTk instances.
VM_MAP.boot();
// This needs to be called after we create Plan. It needs to use HeapMeta, which is gradually built when we create spaces.
VM_MAP.finalize_static_space_map(
plan.base().heap.get_discontig_start(),
plan.base().heap.get_discontig_end(),
&mut |start| {
plan.update_discontiguous_page_resources(start);
},
);

if *options.transparent_hugepages {
Expand Down
10 changes: 9 additions & 1 deletion src/plan/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::util::metadata::side_metadata::SideMetadataSpec;
use crate::util::options::Options;
use crate::util::options::PlanSelector;
use crate::util::statistics::stats::Stats;
use crate::util::{conversions, ObjectReference};
use crate::util::{conversions, Address, ObjectReference};
use crate::util::{VMMutatorThread, VMWorkerThread};
use crate::vm::*;
use downcast_rs::Downcast;
Expand Down Expand Up @@ -371,6 +371,14 @@ pub trait Plan: 'static + HasSpaces + Sync + Downcast {
true
}

fn update_discontiguous_page_resources(&mut self, start: Address) {
self.for_each_space_mut(&mut |space: &mut dyn Space<Self::VM>| {
space.for_each_page_resource_mut(&mut |pr| {
pr.update_discontiguous_start(start);
});
});
}

/// Call `space.verify_side_metadata_sanity` for all spaces in this plan.
fn verify_side_metadata_sanity(&self) {
let mut side_metadata_sanity_checker = SideMetadataSanity::new();
Expand Down
4 changes: 4 additions & 0 deletions src/policy/copyspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ impl<VM: VMBinding> Space<VM> for CopySpace<VM> {
&self.pr
}

fn for_each_page_resource_mut(&mut self, f: &mut dyn FnMut(&mut dyn PageResource<VM>)) {
f(&mut self.pr);
}

fn common(&self) -> &CommonSpace<VM> {
&self.common
}
Expand Down
3 changes: 3 additions & 0 deletions src/policy/immix/immixspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ impl<VM: VMBinding> Space<VM> for ImmixSpace<VM> {
fn get_page_resource(&self) -> &dyn PageResource<VM> {
&self.pr
}
fn for_each_page_resource_mut(&mut self, f: &mut dyn FnMut(&mut dyn PageResource<VM>)) {
f(&mut self.pr);
}
fn common(&self) -> &CommonSpace<VM> {
&self.common
}
Expand Down
3 changes: 3 additions & 0 deletions src/policy/immortalspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ impl<VM: VMBinding> Space<VM> for ImmortalSpace<VM> {
fn get_page_resource(&self) -> &dyn PageResource<VM> {
&self.pr
}
fn for_each_page_resource_mut(&mut self, f: &mut dyn FnMut(&mut dyn PageResource<VM>)) {
f(&mut self.pr);
}
fn common(&self) -> &CommonSpace<VM> {
&self.common
}
Expand Down
3 changes: 3 additions & 0 deletions src/policy/largeobjectspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ impl<VM: VMBinding> Space<VM> for LargeObjectSpace<VM> {
fn get_page_resource(&self) -> &dyn PageResource<VM> {
&self.pr
}
fn for_each_page_resource_mut(&mut self, f: &mut dyn FnMut(&mut dyn PageResource<VM>)) {
f(&mut self.pr);
}

fn initialize_sft(&self, sft_map: &mut dyn crate::policy::sft_map::SFTMap) {
self.common().initialize_sft(self.as_sft(), sft_map)
Expand Down
4 changes: 4 additions & 0 deletions src/policy/lockfreeimmortalspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ impl<VM: VMBinding> Space<VM> for LockFreeImmortalSpace<VM> {
fn get_page_resource(&self) -> &dyn PageResource<VM> {
unimplemented!()
}
fn for_each_page_resource_mut(&mut self, _f: &mut dyn FnMut(&mut dyn PageResource<VM>)) {
// We have no page resources!
}

fn common(&self) -> &CommonSpace<VM> {
unimplemented!()
}
Expand Down
4 changes: 4 additions & 0 deletions src/policy/markcompactspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ impl<VM: VMBinding> Space<VM> for MarkCompactSpace<VM> {
&self.pr
}

fn for_each_page_resource_mut(&mut self, f: &mut dyn FnMut(&mut dyn PageResource<VM>)) {
f(&mut self.pr);
}

fn common(&self) -> &CommonSpace<VM> {
&self.common
}
Expand Down
4 changes: 4 additions & 0 deletions src/policy/marksweepspace/malloc_ms/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ impl<VM: VMBinding> Space<VM> for MallocSpace<VM> {
unreachable!()
}

fn for_each_page_resource_mut(&mut self, _f: &mut dyn FnMut(&mut dyn PageResource<VM>)) {
// We have no page resources!
}

fn common(&self) -> &CommonSpace<VM> {
unreachable!()
}
Expand Down
8 changes: 6 additions & 2 deletions src/policy/marksweepspace/native_ms/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
scheduler::{GCWorkScheduler, GCWorker},
util::{
copy::CopySemantics,
heap::FreeListPageResource,
heap::{FreeListPageResource, PageResource},
metadata::{self, side_metadata::SideMetadataSpec, MetadataSpec},
ObjectReference,
},
Expand Down Expand Up @@ -152,10 +152,14 @@ impl<VM: VMBinding> Space<VM> for MarkSweepSpace<VM> {
self
}

fn get_page_resource(&self) -> &dyn crate::util::heap::PageResource<VM> {
fn get_page_resource(&self) -> &dyn PageResource<VM> {
&self.pr
}

fn for_each_page_resource_mut(&mut self, f: &mut dyn FnMut(&mut dyn PageResource<VM>)) {
f(&mut self.pr);
}

fn initialize_sft(&self, sft_map: &mut dyn crate::policy::sft_map::SFTMap) {
self.common().initialize_sft(self.as_sft(), sft_map)
}
Expand Down
5 changes: 5 additions & 0 deletions src/policy/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ use downcast_rs::Downcast;
pub trait Space<VM: VMBinding>: 'static + SFT + Sync + Downcast {
fn as_space(&self) -> &dyn Space<VM>;
fn as_sft(&self) -> &(dyn SFT + Sync + 'static);

// TODO: Generate this function automatically in mmtk-macros like PlanTraceObject.
fn get_page_resource(&self) -> &dyn PageResource<VM>;

// TODO: Generate this function automatically in mmtk-macros like PlanTraceObject.
fn for_each_page_resource_mut(&mut self, f: &mut dyn FnMut(&mut dyn PageResource<VM>));

/// Initialize entires in SFT map for the space. This is called when the Space object
/// has a non-moving address, as we will use the address to set sft.
/// Currently after we create a boxed plan, spaces in the plan have a non-moving address.
Expand Down
3 changes: 3 additions & 0 deletions src/policy/vmspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ impl<VM: VMBinding> Space<VM> for VMSpace<VM> {
fn get_page_resource(&self) -> &dyn PageResource<VM> {
&self.pr
}
fn for_each_page_resource_mut(&mut self, f: &mut dyn FnMut(&mut dyn PageResource<VM>)) {
f(&mut self.pr)
}
fn common(&self) -> &CommonSpace<VM> {
&self.common
}
Expand Down
7 changes: 6 additions & 1 deletion src/util/freelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ const MULTI_MASK: i32 = 1 << (TOTAL_BITS - 1);
const COALESC_MASK: i32 = 1 << (TOTAL_BITS - 2);
const SIZE_MASK: i32 = (1 << UNIT_BITS) - 1;

pub trait FreeList: Sync + Downcast {
// TODO: FreeList should not implement Sync.
// FreeList instances are not thread-safe.
// They need external synchronisation (e.g. using Mutex).
// On the other hand, to put FreeList into a Mutex<T>, FreeList must implement Send.
// There is no problem sending FreeList instances between threads.
pub trait FreeList: Sync + Send + Downcast {
fn head(&self) -> i32;
// fn head_mut(&mut self) -> &mut i32;
fn heads(&self) -> i32;
Expand Down
4 changes: 4 additions & 0 deletions src/util/heap/blockpageresource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ impl<VM: VMBinding, B: Region> PageResource<VM> for BlockPageResource<VM, B> {
self.flpr.common_mut()
}

fn update_discontiguous_start(&mut self, start: Address) {
self.flpr.update_discontiguous_start(start);
}

fn alloc_pages(
&self,
space_descriptor: SpaceDescriptor,
Expand Down
Loading