Skip to content
Merged
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
12 changes: 5 additions & 7 deletions src/mmtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use crate::scheduler::GCWorkScheduler;
#[cfg(feature = "extreme_assertions")]
use crate::util::edge_logger::EdgeLogger;
use crate::util::finalizable_processor::FinalizableProcessor;
use crate::util::heap::layout::heap_layout::Mmapper;
use crate::util::heap::layout::heap_layout::VMMap;
use crate::util::heap::layout::map::Map;
use crate::util::heap::layout::{self, Mmapper, VMMap};
use crate::util::opaque_pointer::*;
use crate::util::options::Options;
use crate::util::reference_processor::ReferenceProcessors;
Expand All @@ -31,10 +29,10 @@ lazy_static! {
// TODO: We should refactor this when we know more about how multiple MMTK instances work.

/// A global VMMap that manages the mapping of spaces to virtual memory ranges.
pub static ref VM_MAP: VMMap = VMMap::new();
pub static ref VM_MAP: Box<dyn VMMap> = layout::create_vm_map();

/// A global Mmapper for mmaping and protection of virtual memory.
pub static ref MMAPPER: Mmapper = Mmapper::new();
pub static ref MMAPPER: Box<dyn Mmapper> = layout::create_mmapper();
}

use crate::util::rust_util::InitializeOnce;
Expand Down Expand Up @@ -111,8 +109,8 @@ impl<VM: VMBinding> MMTK<VM> {

let plan = crate::plan::create_plan(
*options.plan,
&VM_MAP,
&MMAPPER,
VM_MAP.as_ref(),
MMAPPER.as_ref(),
options.clone(),
scheduler.clone(),
);
Expand Down
22 changes: 8 additions & 14 deletions src/plan/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::util::alloc::allocators::AllocatorSelector;
use crate::util::analysis::AnalysisManager;
use crate::util::copy::{CopyConfig, GCWorkerCopyContext};
use crate::util::heap::gc_trigger::GCTrigger;
use crate::util::heap::layout::heap_layout::Mmapper;
use crate::util::heap::layout::heap_layout::VMMap;
use crate::util::heap::layout::Mmapper;
use crate::util::heap::layout::VMMap;
use crate::util::heap::HeapMeta;
use crate::util::heap::VMRequest;
use crate::util::metadata::side_metadata::SideMetadataSanity;
Expand Down Expand Up @@ -66,8 +66,8 @@ pub fn create_mutator<VM: VMBinding>(

pub fn create_plan<VM: VMBinding>(
plan: PlanSelector,
vm_map: &'static VMMap,
mmapper: &'static Mmapper,
vm_map: &'static dyn VMMap,
mmapper: &'static dyn Mmapper,
options: Arc<Options>,
scheduler: Arc<GCWorkScheduler<VM>>,
) -> Box<dyn Plan<VM = VM>> {
Expand Down Expand Up @@ -185,9 +185,6 @@ pub trait Plan: 'static + Sync + Downcast {
) -> Option<&dyn crate::plan::generational::global::GenerationalPlan<VM = Self::VM>> {
None
}
fn mmapper(&self) -> &'static Mmapper {
self.base().mmapper
}
fn options(&self) -> &Options {
&self.base().options
}
Expand Down Expand Up @@ -381,8 +378,7 @@ pub struct BasePlan<VM: VMBinding> {
pub cur_collection_attempts: AtomicUsize,
pub gc_requester: Arc<GCRequester<VM>>,
pub stats: Stats,
mmapper: &'static Mmapper,
pub vm_map: &'static VMMap,
// pub vm_map: &'static dyn Map,
pub options: Arc<Options>,
pub heap: HeapMeta,
pub gc_trigger: Arc<GCTrigger<VM>>,
Expand Down Expand Up @@ -455,8 +451,8 @@ pub fn create_vm_space<VM: VMBinding>(args: &mut CreateSpecificPlanArgs<VM>) ->
/// Args needed for creating any plan. This includes a set of contexts from MMTK or global. This
/// is passed to each plan's constructor.
pub struct CreateGeneralPlanArgs<VM: VMBinding> {
pub vm_map: &'static VMMap,
pub mmapper: &'static Mmapper,
pub vm_map: &'static dyn VMMap,
pub mmapper: &'static dyn Mmapper,
pub heap: HeapMeta,
pub options: Arc<Options>,
pub gc_trigger: Arc<crate::util::heap::gc_trigger::GCTrigger<VM>>,
Expand Down Expand Up @@ -540,11 +536,9 @@ impl<VM: VMBinding> BasePlan<VM> {
cur_collection_attempts: AtomicUsize::new(0),
gc_requester: Arc::new(GCRequester::new()),
stats,
mmapper: args.global_args.mmapper,
heap: args.global_args.heap,
gc_trigger: args.global_args.gc_trigger,
vm_map: args.global_args.vm_map,
options: args.global_args.options.clone(),
options: args.global_args.options,
#[cfg(feature = "sanity")]
inside_sanity: AtomicBool::new(false),
scanned_stacks: AtomicUsize::new(0),
Expand Down
17 changes: 7 additions & 10 deletions src/policy/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ use crate::policy::sft::EMPTY_SFT_NAME;
use crate::policy::sft::SFT;
use crate::util::copy::*;
use crate::util::heap::gc_trigger::GCTrigger;
use crate::util::heap::layout::heap_layout::Mmapper;
use crate::util::heap::layout::heap_layout::VMMap;
use crate::util::heap::layout::map::Map;
use crate::util::heap::layout::vm_layout_constants::BYTES_IN_CHUNK;
use crate::util::heap::layout::Mmapper as IMmapper;
use crate::util::heap::layout::Mmapper;
use crate::util::heap::layout::VMMap;
use crate::util::heap::space_descriptor::SpaceDescriptor;
use crate::util::heap::HeapMeta;
use crate::util::memory;
Expand Down Expand Up @@ -265,7 +263,6 @@ pub trait Space<VM: VMBinding>: 'static + SFT + Sync + Downcast {
panic!("failed to mmap meta memory");
}

use crate::util::heap::layout::mmapper::Mmapper;
self.common()
.mmapper
.mark_as_mapped(self.common().start, self.common().extent);
Expand Down Expand Up @@ -394,8 +391,8 @@ pub struct CommonSpace<VM: VMBinding> {
pub extent: usize,
pub head_discontiguous_region: Address,

pub vm_map: &'static VMMap,
pub mmapper: &'static Mmapper,
pub vm_map: &'static dyn VMMap,
pub mmapper: &'static dyn Mmapper,

pub metadata: SideMetadataContext,

Expand Down Expand Up @@ -425,8 +422,8 @@ pub struct PlanCreateSpaceArgs<'a, VM: VMBinding> {
pub zeroed: bool,
pub vmrequest: VMRequest,
pub global_side_metadata_specs: Vec<SideMetadataSpec>,
pub vm_map: &'static VMMap,
pub mmapper: &'static Mmapper,
pub vm_map: &'static dyn VMMap,
pub mmapper: &'static dyn Mmapper,
pub heap: &'a mut HeapMeta,
pub constraints: &'a PlanConstraints,
pub gc_trigger: Arc<GCTrigger<VM>>,
Expand Down Expand Up @@ -563,7 +560,7 @@ impl<VM: VMBinding> CommonSpace<VM> {
}
}

pub fn vm_map(&self) -> &'static VMMap {
pub fn vm_map(&self) -> &'static dyn VMMap {
self.vm_map
}
}
Expand Down
1 change: 0 additions & 1 deletion src/util/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::ops::*;
use std::sync::atomic::Ordering;

use crate::mmtk::{MMAPPER, SFT_MAP};
use crate::util::heap::layout::mmapper::Mmapper;

/// size in bytes
pub type ByteSize = usize;
Expand Down
6 changes: 5 additions & 1 deletion src/util/generic_freelist.rs → src/util/freelist.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use downcast_rs::{impl_downcast, Downcast};

pub const FAILURE: i32 = -1;

pub const MAX_HEADS: i32 = 128; // somewhat arbitrary
Expand All @@ -12,7 +14,7 @@ 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 GenericFreeList: Sized {
pub trait FreeList: Sync + Downcast {
fn head(&self) -> i32;
// fn head_mut(&mut self) -> &mut i32;
fn heads(&self) -> i32;
Expand Down Expand Up @@ -302,3 +304,5 @@ pub trait GenericFreeList: Sized {
self.set_prev(next, prev);
}
}

impl_downcast!(FreeList);
10 changes: 7 additions & 3 deletions src/util/heap/blockpageresource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::pageresource::{PRAllocFail, PRAllocResult};
use super::{FreeListPageResource, PageResource};
use crate::util::address::Address;
use crate::util::constants::*;
use crate::util::heap::layout::heap_layout::VMMap;
use crate::util::heap::layout::vm_layout_constants::*;
use crate::util::heap::layout::VMMap;
use crate::util::heap::pageresource::CommonPageResource;
use crate::util::heap::space_descriptor::SpaceDescriptor;
use crate::util::linear_scan::Region;
Expand Down Expand Up @@ -61,7 +61,7 @@ impl<VM: VMBinding, B: Region> BlockPageResource<VM, B> {
log_pages: usize,
start: Address,
bytes: usize,
vm_map: &'static VMMap,
vm_map: &'static dyn VMMap,
num_workers: usize,
) -> Self {
assert!((1 << log_pages) <= PAGES_IN_CHUNK);
Expand All @@ -72,7 +72,11 @@ impl<VM: VMBinding, B: Region> BlockPageResource<VM, B> {
}
}

pub fn new_discontiguous(log_pages: usize, vm_map: &'static VMMap, num_workers: usize) -> Self {
pub fn new_discontiguous(
log_pages: usize,
vm_map: &'static dyn VMMap,
num_workers: usize,
) -> Self {
assert!((1 << log_pages) <= PAGES_IN_CHUNK);
Self {
flpr: FreeListPageResource::new_discontiguous(vm_map),
Expand Down
28 changes: 13 additions & 15 deletions src/util/heap/freelistpageresource.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::ops::{Deref, DerefMut};
use std::sync::{Mutex, MutexGuard};

use super::layout::map::Map;
use super::layout::vm_layout_constants::{PAGES_IN_CHUNK, PAGES_IN_SPACE64};
use super::layout::VMMap;
use super::pageresource::{PRAllocFail, PRAllocResult};
use super::PageResource;
use crate::mmtk::MMAPPER;
use crate::util::address::Address;
use crate::util::alloc::embedded_meta_data::*;
use crate::util::conversions;
use crate::util::generic_freelist;
use crate::util::generic_freelist::GenericFreeList;
use crate::util::heap::layout::heap_layout::VMMap;
use crate::util::freelist;
use crate::util::freelist::FreeList;
use crate::util::heap::layout::vm_layout_constants::*;
use crate::util::heap::pageresource::CommonPageResource;
use crate::util::heap::space_descriptor::SpaceDescriptor;
Expand All @@ -22,7 +22,7 @@ use std::marker::PhantomData;
const UNINITIALIZED_WATER_MARK: i32 = -1;

pub struct CommonFreeListPageResource {
pub(crate) free_list: Box<<VMMap as Map>::FreeList>,
pub(crate) free_list: Box<dyn FreeList>,
start: Address,
}

Expand Down Expand Up @@ -101,13 +101,13 @@ impl<VM: VMBinding> PageResource<VM> for FreeListPageResource<VM> {
let mut sync = self.sync.lock().unwrap();
let mut new_chunk = false;
let mut page_offset = self_mut.free_list.alloc(required_pages as _);
if page_offset == generic_freelist::FAILURE && self.common.growable {
if page_offset == freelist::FAILURE && self.common.growable {
page_offset =
self_mut.allocate_contiguous_chunks(space_descriptor, required_pages, &mut sync);
new_chunk = true;
}

if page_offset == generic_freelist::FAILURE {
if page_offset == freelist::FAILURE {
return Result::Err(PRAllocFail);
} else {
sync.pages_currently_on_freelist -= required_pages;
Expand All @@ -125,8 +125,6 @@ impl<VM: VMBinding> PageResource<VM> for FreeListPageResource<VM> {
// The meta-data portion of reserved Pages was committed above.
self.commit_pages(reserved_pages, required_pages, tls);
if self.protect_memory_on_release && !new_chunk {
use crate::util::heap::layout::Mmapper;
use crate::MMAPPER;
// This check is necessary to prevent us from mprotecting an address that is not yet mapped by mmapper.
// See https://github.com/mmtk/mmtk-core/issues/400.
// It is possible that one thread gets a new chunk, and returns from this function. However, the Space.acquire()
Expand All @@ -149,7 +147,7 @@ impl<VM: VMBinding> PageResource<VM> for FreeListPageResource<VM> {
}

impl<VM: VMBinding> FreeListPageResource<VM> {
pub fn new_contiguous(start: Address, bytes: usize, vm_map: &'static VMMap) -> Self {
pub fn new_contiguous(start: Address, bytes: usize, vm_map: &'static dyn VMMap) -> Self {
let pages = conversions::bytes_to_pages(bytes);
let common_flpr = {
let common_flpr = Box::new(CommonFreeListPageResource {
Expand Down Expand Up @@ -177,7 +175,7 @@ impl<VM: VMBinding> FreeListPageResource<VM> {
}
}

pub fn new_discontiguous(vm_map: &'static VMMap) -> Self {
pub fn new_discontiguous(vm_map: &'static dyn VMMap) -> Self {
let common_flpr = {
let start = AVAILABLE_START;
let common_flpr = Box::new(CommonFreeListPageResource {
Expand Down Expand Up @@ -246,7 +244,7 @@ impl<VM: VMBinding> FreeListPageResource<VM> {
let page_offset =
self_mut.allocate_contiguous_chunks(space_descriptor, PAGES_IN_CHUNK, &mut sync);

if page_offset == generic_freelist::FAILURE {
if page_offset == freelist::FAILURE {
return Result::Err(PRAllocFail);
} else {
sync.pages_currently_on_freelist -= PAGES_IN_CHUNK;
Expand All @@ -269,7 +267,7 @@ impl<VM: VMBinding> FreeListPageResource<VM> {
pages: usize,
sync: &mut MutexGuard<FreeListPageResourceSync>,
) -> i32 {
let mut rtn = generic_freelist::FAILURE;
let mut rtn = freelist::FAILURE;
let required_chunks = crate::policy::space::required_chunks(pages);
let region = self
.common
Expand Down Expand Up @@ -356,12 +354,12 @@ impl<VM: VMBinding> FreeListPageResource<VM> {
// region_start is guaranteed to be positive. Otherwise this line will fail due to subtraction overflow.
region_start -= PAGES_IN_CHUNK;
}
while next_region_start < generic_freelist::MAX_UNITS as usize
while next_region_start < freelist::MAX_UNITS as usize
&& self.free_list.is_coalescable(next_region_start as _)
{
next_region_start += PAGES_IN_CHUNK;
}
debug_assert!(next_region_start < generic_freelist::MAX_UNITS as usize);
debug_assert!(next_region_start < freelist::MAX_UNITS as usize);
if pages_freed == next_region_start - region_start {
let start = self.start;
self.free_contiguous_chunk(start + conversions::pages_to_bytes(region_start), sync);
Expand Down
3 changes: 2 additions & 1 deletion src/util/heap/layout/byte_map_mmapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ impl Default for ByteMapMmapper {

#[cfg(test)]
mod tests {
use crate::util::heap::layout::{ByteMapMmapper, Mmapper};
use super::ByteMapMmapper;
use crate::util::heap::layout::Mmapper;
use crate::util::Address;

use crate::util::constants::LOG_BYTES_IN_PAGE;
Expand Down
19 changes: 0 additions & 19 deletions src/util/heap/layout/heap_layout.rs

This file was deleted.

18 changes: 5 additions & 13 deletions src/util/heap/layout/map.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
use crate::util::generic_freelist::GenericFreeList;
use crate::util::freelist::FreeList;
use crate::util::heap::freelistpageresource::CommonFreeListPageResource;
use crate::util::heap::space_descriptor::SpaceDescriptor;
use crate::util::Address;

pub trait Map: Sized {
type FreeList: GenericFreeList;

fn new() -> Self;

pub trait VMMap: Sync {
fn insert(&self, start: Address, extent: usize, descriptor: SpaceDescriptor);

/// Create a free-list for a discontiguous space. Must only be called at boot time.
/// bind_freelist() must be called by the caller after this method.
fn create_freelist(&self, start: Address) -> Box<Self::FreeList>;
fn create_freelist(&self, start: Address) -> Box<dyn FreeList>;

/// Create a free-list for a contiguous space. Must only be called at boot time.
/// bind_freelist() must be called by the caller after this method.
fn create_parent_freelist(
&self,
start: Address,
units: usize,
grain: i32,
) -> Box<Self::FreeList>;
fn create_parent_freelist(&self, start: Address, units: usize, grain: i32)
-> Box<dyn FreeList>;

/// Bind a created freelist with the page resource.
/// This must called after create_freelist() or create_parent_freelist().
Expand Down
Loading