Skip to content

Commit d8f9a69

Browse files
committed
WIP: Fix errors after rebase onto PR#146 -- nogc/semispace working
1 parent b55bf86 commit d8f9a69

File tree

10 files changed

+32
-29
lines changed

10 files changed

+32
-29
lines changed

src/mm/memory_manager.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ pub fn gc_init<VM: VMBinding>(mmtk: &MMTK<VM>, heap_size: usize) {
5959
pub fn bind_mutator<VM: VMBinding>(
6060
mmtk: &'static MMTK<VM>,
6161
tls: OpaquePointer,
62-
) -> Box<Mutator<VM, SelectedPlan<VM>>> {
62+
) -> Box<Mutator<SelectedPlan<VM>>> {
6363
SelectedPlan::bind_mutator(&mmtk.plan, tls)
6464
}
6565

66-
pub fn destroy_mutator<VM: VMBinding>(mutator: Box<Mutator<VM, SelectedPlan<VM>>>) {
66+
pub fn destroy_mutator<VM: VMBinding>(mutator: Box<Mutator<SelectedPlan<VM>>>) {
6767
drop(mutator);
6868
}
6969

70-
pub fn flush_mutator<VM: VMBinding>(mutator: &mut SelectedMutator<VM>) {
70+
pub fn flush_mutator<VM: VMBinding>(mutator: &mut Mutator<SelectedPlan<VM>>) {
7171
mutator.flush()
7272
}
7373

7474
pub fn alloc<VM: VMBinding>(
75-
mutator: &mut Mutator<VM, SelectedPlan<VM>>,
75+
mutator: &mut Mutator<SelectedPlan<VM>>,
7676
size: usize,
7777
align: usize,
7878
offset: isize,
@@ -82,7 +82,7 @@ pub fn alloc<VM: VMBinding>(
8282
}
8383

8484
pub fn post_alloc<VM: VMBinding>(
85-
mutator: &mut Mutator<VM, SelectedPlan<VM>>,
85+
mutator: &mut Mutator<SelectedPlan<VM>>,
8686
refer: ObjectReference,
8787
type_refer: ObjectReference,
8888
bytes: usize,

src/plan/mutator_context.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,34 @@ use enum_map::EnumMap;
1313
// This struct is part of the Mutator struct.
1414
// We are trying to make it fixed-sized so that VM bindings can easily define a Mutator type to have the exact same layout as our Mutator struct.
1515
#[repr(C)]
16-
pub struct MutatorConfig<VM: VMBinding, P: Plan<VM> + 'static> {
16+
pub struct MutatorConfig<P: Plan> {
1717
// Mapping between allocation semantics and allocator selector
1818
pub allocator_mapping: &'static EnumMap<AllocationType, AllocatorSelector>,
1919
// Mapping between allocator selector and spaces. Each pair represents a mapping.
2020
// Put this behind a box, so it is a pointer-sized field.
2121
#[allow(clippy::box_vec)]
22-
pub space_mapping: Box<Vec<(AllocatorSelector, &'static dyn Space<VM>)>>,
22+
pub space_mapping: Box<Vec<(AllocatorSelector, &'static dyn Space<P::VM>)>>,
2323
// Plan-specific code for mutator prepare/release
24-
pub prepare_func: &'static dyn Fn(&mut Mutator<VM, P>, OpaquePointer),
25-
pub release_func: &'static dyn Fn(&mut Mutator<VM, P>, OpaquePointer),
24+
pub prepare_func: &'static dyn Fn(&mut Mutator<P>, OpaquePointer),
25+
pub release_func: &'static dyn Fn(&mut Mutator<P>, OpaquePointer),
2626
}
2727

28+
unsafe impl <P: Plan> Send for MutatorConfig<P> {}
29+
unsafe impl <P: Plan> Sync for MutatorConfig<P> {}
30+
2831
// We are trying to make this struct fixed-sized so that VM bindings can easily define a type to have the exact same layout as this struct.
2932
// Currently Mutator is fixed sized, and we should try keep this invariant:
3033
// - Allocators are fixed-length arrays of allocators.
3134
// - MutatorConfig has 3 pointers/refs (including one fat pointer), and is fixed sized.
3235
#[repr(C)]
33-
pub struct Mutator<VM: VMBinding, P: Plan<VM> + 'static> {
34-
pub allocators: Allocators<VM>,
36+
pub struct Mutator<P: Plan> {
37+
pub allocators: Allocators<P::VM>,
3538
pub mutator_tls: OpaquePointer,
3639
pub plan: &'static P,
37-
pub config: MutatorConfig<VM, P>,
40+
pub config: MutatorConfig<P>,
3841
}
3942

40-
impl<VM: VMBinding, P: Plan<VM>> MutatorContext<VM> for Mutator<VM, P> {
43+
impl <P: Plan<Mutator=Self>> MutatorContext<P::VM> for Mutator<P> {
4144
fn prepare(&mut self, tls: OpaquePointer) {
4245
(*self.config.prepare_func)(self, tls)
4346
}

src/plan/nogc/global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ unsafe impl<VM: VMBinding> Sync for NoGC<VM> {}
3636

3737
impl<VM: VMBinding> Plan for NoGC<VM> {
3838
type VM = VM;
39-
type Mutator = Mutator<VM, Self>;
39+
type Mutator = Mutator<Self>;
4040
type CopyContext = NoCopy<VM>;
4141

4242
fn new(
@@ -80,7 +80,7 @@ impl<VM: VMBinding> Plan for NoGC<VM> {
8080
&self.base
8181
}
8282

83-
fn bind_mutator(&'static self, tls: OpaquePointer) -> Box<Mutator<VM, Self>> {
83+
fn bind_mutator(&'static self, tls: OpaquePointer) -> Box<Mutator<Self>> {
8484
Box::new(create_nogc_mutator(tls, self))
8585
}
8686

src/plan/nogc/mutator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ lazy_static! {
1616
};
1717
}
1818

19-
pub fn nogc_mutator_noop<VM: VMBinding>(_mutator: &mut Mutator<VM, SemiSpace<VM>>, _tls: OpaquePointer) {
20-
19+
pub fn nogc_mutator_noop<VM: VMBinding>(_mutator: &mut Mutator<NoGC<VM>>, _tls: OpaquePointer) {
20+
unreachable!();
2121
}
2222

2323
pub fn create_nogc_mutator<VM: VMBinding>(
2424
mutator_tls: OpaquePointer,
2525
plan: &'static NoGC<VM>,
26-
) -> Mutator<VM, NoGC<VM>> {
26+
) -> Mutator<NoGC<VM>> {
2727
let config = MutatorConfig {
2828
allocator_mapping: &*ALLOCATOR_MAPPING,
29-
space_mapping: box vec![(AllocatorSelector::BumpPointer(0), plan.get_immortal_space())],
29+
space_mapping: box vec![(AllocatorSelector::BumpPointer(0), &plan.nogc_space)],
3030
prepare_func: &nogc_mutator_noop,
3131
release_func: &nogc_mutator_noop,
3232
};

src/plan/semispace/global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ unsafe impl<VM: VMBinding> Sync for SemiSpace<VM> {}
4646

4747
impl<VM: VMBinding> Plan for SemiSpace<VM> {
4848
type VM = VM;
49-
type Mutator = Mutator<VM, Self>;
49+
type Mutator = Mutator<Self>;
5050
type CopyContext = SSCopyContext<VM>;
5151

5252
fn new(
@@ -101,7 +101,7 @@ impl<VM: VMBinding> Plan for SemiSpace<VM> {
101101
scheduler.set_finalizer(Some(EndOfGC));
102102
}
103103

104-
fn bind_mutator(&'static self, tls: OpaquePointer) -> Box<Mutator<VM, Self>> {
104+
fn bind_mutator(&'static self, tls: OpaquePointer) -> Box<Mutator<Self>> {
105105
Box::new(create_ss_mutator(tls, self))
106106
}
107107

src/plan/semispace/mutator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use crate::vm::VMBinding;
1515
use enum_map::enum_map;
1616
use enum_map::EnumMap;
1717

18-
pub fn ss_mutator_prepare<VM: VMBinding>(mutator: &mut Mutator<VM, SemiSpace<VM>>, _tls: OpaquePointer) {
18+
pub fn ss_mutator_prepare<VM: VMBinding>(mutator: &mut Mutator<SemiSpace<VM>>, _tls: OpaquePointer) {
1919
// Do nothing
2020
}
2121

22-
pub fn ss_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM, SemiSpace<VM>>, _tls: OpaquePointer) {
22+
pub fn ss_mutator_release<VM: VMBinding>(mutator: &mut Mutator<SemiSpace<VM>>, _tls: OpaquePointer) {
2323
// rebind the allocation bump pointer to the appropriate semispace
2424
let bump_allocator = unsafe {
2525
mutator
@@ -42,7 +42,7 @@ lazy_static! {
4242
pub fn create_ss_mutator<VM: VMBinding>(
4343
mutator_tls: OpaquePointer,
4444
plan: &'static SemiSpace<VM>,
45-
) -> Mutator<VM, SemiSpace<VM>> {
45+
) -> Mutator<SemiSpace<VM>> {
4646
let config = MutatorConfig {
4747
allocator_mapping: &*ALLOCATOR_MAPPING,
4848
space_mapping: box vec![

src/scheduler/gc_works.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl <E: ProcessEdgesWork> GCWork<E::VM> for ScanStackRoots<E> {
217217
}
218218
}
219219

220-
pub struct ScanStackRoot<Edges: ProcessEdgesWork>(pub &'static mut SelectedMutator<Edges::VM>);
220+
pub struct ScanStackRoot<Edges: ProcessEdgesWork>(pub &'static mut Mutator<SelectedPlan<Edges::VM>>);
221221

222222
impl <E: ProcessEdgesWork> GCWork<E::VM> for ScanStackRoot<E> {
223223
fn do_work(&mut self, worker: &mut GCWorker<E::VM>, mmtk: &'static MMTK<E::VM>) {

src/util/heap/monotonepageresource.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use super::PageResource;
1717

1818
use crate::util::heap::layout::heap_layout::VMMap;
1919
use crate::vm::VMBinding;
20+
use std::sync::atomic::Ordering;
2021
use libc::{c_void, memset};
2122

2223
pub struct MonotonePageResource<VM: VMBinding> {

src/util/heap/pageresource.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub trait PageResource<VM: VMBinding>: 'static {
108108
}
109109

110110
pub struct CommonPageResource<VM: VMBinding> {
111-
reserved: AtomicUsize,
111+
pub reserved: AtomicUsize,
112112
committed: AtomicUsize,
113113

114114
pub contiguous: bool,

src/vm/scanning.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use crate::plan::{TraceLocal, TransitiveClosure};
1+
use crate::plan::{TraceLocal, TransitiveClosure, Mutator, SelectedPlan};
22
use crate::util::ObjectReference;
33
use crate::util::OpaquePointer;
44
use crate::vm::VMBinding;
55
use crate::scheduler::gc_works::ProcessEdgesWork;
6-
use crate::SelectedMutator;
76

87
pub trait Scanning<VM: VMBinding> {
98
/// Scan stack roots after all mutators are paused
@@ -26,7 +25,7 @@ pub trait Scanning<VM: VMBinding> {
2625
/// Scan all the mutators for roots
2726
fn scan_thread_roots<W: ProcessEdgesWork<VM=VM>>();
2827
/// Scan one mutator for roots
29-
fn scan_thread_root<W: ProcessEdgesWork<VM=VM>>(mutator: &'static mut SelectedMutator<VM>);
28+
fn scan_thread_root<W: ProcessEdgesWork<VM=VM>>(mutator: &'static mut Mutator<SelectedPlan<VM>>);
3029
/// The creation of all root scan tasks (except thread scanning) goes here
3130
fn scan_vm_specific_roots<W: ProcessEdgesWork<VM=VM>>();
3231
fn compute_static_roots<T: TraceLocal>(trace: &mut T, tls: OpaquePointer);

0 commit comments

Comments
 (0)