Skip to content
Draft
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: 3 additions & 3 deletions src/plan/compressor/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<VM: VMBinding> Plan for Compressor<VM> {

// Prepare global/collectors/mutators
scheduler.work_buckets[WorkBucketStage::Prepare]
.add(Prepare::<CompressorWorkContext<VM>>::new(self));
.add(Prepare::<CompressorWorkContext<VM>>::new());

scheduler.work_buckets[WorkBucketStage::CalculateForwarding].add(GenerateWork::new(
&self.compressor_space,
Expand All @@ -112,7 +112,7 @@ impl<VM: VMBinding> Plan for Compressor<VM> {

// Release global/collectors/mutators
scheduler.work_buckets[WorkBucketStage::Release]
.add(Release::<CompressorWorkContext<VM>>::new(self));
.add(Release::<CompressorWorkContext<VM>>::new());

// Reference processing
if !*self.base().options.no_reference_types {
Expand Down Expand Up @@ -167,7 +167,7 @@ impl<VM: VMBinding> Plan for Compressor<VM> {
}
#[cfg(feature = "sanity")]
scheduler.work_buckets[WorkBucketStage::Final]
.add(crate::util::sanity::sanity_checker::ScheduleSanityGC::<Self>::new(self));
.add(crate::util::sanity::sanity_checker::ScheduleSanityGC::<Self>::new());
}

fn current_gc_may_move_object(&self) -> bool {
Expand Down
6 changes: 3 additions & 3 deletions src/plan/concurrent/immix/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl<VM: VMBinding> ConcurrentImmix<VM> {
scheduler.work_buckets[WorkBucketStage::Unconstrained]
.add(StopMutators::<ConcurrentImmixGCWorkContext<VM>>::new());
scheduler.work_buckets[WorkBucketStage::Prepare]
.add(Prepare::<ConcurrentImmixGCWorkContext<VM>>::new(self));
.add(Prepare::<ConcurrentImmixGCWorkContext<VM>>::new());
}

fn schedule_concurrent_marking_final_pause(&'static self, scheduler: &GCWorkScheduler<VM>) {
Expand All @@ -387,13 +387,13 @@ impl<VM: VMBinding> ConcurrentImmix<VM> {
.add(StopMutators::<ConcurrentImmixGCWorkContext<VM>>::new_no_scan_roots());

scheduler.work_buckets[WorkBucketStage::Release]
.add(Release::<ConcurrentImmixGCWorkContext<VM>>::new(self));
.add(Release::<ConcurrentImmixGCWorkContext<VM>>::new());

// Sanity
#[cfg(feature = "sanity")]
{
use crate::util::sanity::sanity_checker::ScheduleSanityGC;
scheduler.work_buckets[WorkBucketStage::Final].add(ScheduleSanityGC::<Self>::new(self));
scheduler.work_buckets[WorkBucketStage::Final].add(ScheduleSanityGC::<Self>::new());
}

// Deal with weak ref and finalizers
Expand Down
18 changes: 11 additions & 7 deletions src/plan/gc_work.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
//! This module holds work packets for `CommonPlan` and `BasePlan`, or other work packets not
//! directly related to scheduling.

use crate::{plan::global::CommonPlan, scheduler::GCWork, vm::VMBinding};
use std::marker::PhantomData;

use crate::{scheduler::GCWork, vm::VMBinding};

#[derive(Default)]
pub(super) struct SetCommonPlanUnlogBits<VM: VMBinding> {
pub common_plan: &'static CommonPlan<VM>,
phantom_data: PhantomData<VM>,
}

impl<VM: VMBinding> GCWork<VM> for SetCommonPlanUnlogBits<VM> {
fn do_work(
&mut self,
_worker: &mut crate::scheduler::GCWorker<VM>,
_mmtk: &'static crate::MMTK<VM>,
mmtk: &'static crate::MMTK<VM>,
) {
self.common_plan.set_side_log_bits();
mmtk.get_plan().common().set_side_log_bits();
}
}

#[derive(Default)]
pub(super) struct ClearCommonPlanUnlogBits<VM: VMBinding> {
pub common_plan: &'static CommonPlan<VM>,
phantom_data: PhantomData<VM>,
}

impl<VM: VMBinding> GCWork<VM> for ClearCommonPlanUnlogBits<VM> {
fn do_work(
&mut self,
_worker: &mut crate::scheduler::GCWorker<VM>,
_mmtk: &'static crate::MMTK<VM>,
mmtk: &'static crate::MMTK<VM>,
) {
self.common_plan.clear_side_log_bits();
mmtk.get_plan().common().clear_side_log_bits();
}
}
7 changes: 2 additions & 5 deletions src/plan/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,18 +758,15 @@ impl<VM: VMBinding> CommonPlan<VM> {

pub(crate) fn schedule_unlog_bits_op(&mut self, unlog_bits_op: UnlogBitsOperation) {
if VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC.is_on_side() {
// # Safety: CommonPlan reference is always valid within this collection cycle.
let common_plan = unsafe { &*(self as *const CommonPlan<VM>) };

match unlog_bits_op {
UnlogBitsOperation::NoOp => {}
UnlogBitsOperation::BulkSet => {
self.base.scheduler.work_buckets[WorkBucketStage::Prepare]
.add(SetCommonPlanUnlogBits { common_plan });
.add(SetCommonPlanUnlogBits::default());
}
UnlogBitsOperation::BulkClear => {
self.base.scheduler.work_buckets[WorkBucketStage::Release]
.add(ClearCommonPlanUnlogBits { common_plan });
.add(ClearCommonPlanUnlogBits::default());
}
}
}
Expand Down
15 changes: 6 additions & 9 deletions src/plan/markcompact/gc_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ impl<VM: VMBinding> CalculateForwardingAddress<VM> {

/// create another round of root scanning work packets
/// to update object references
#[derive(Default)]
pub struct UpdateReferences<VM: VMBinding> {
plan: *const MarkCompact<VM>,
p: PhantomData<VM>,
}

unsafe impl<VM: VMBinding> Send for UpdateReferences<VM> {}

impl<VM: VMBinding> GCWork<VM> for UpdateReferences<VM> {
fn do_work(&mut self, worker: &mut GCWorker<VM>, mmtk: &'static MMTK<VM>) {
// The following needs to be done right before the second round of root scanning
VM::VMScanning::prepare_for_roots_re_scanning();
mmtk.state.prepare_for_stack_scanning();
// Prepare common and base spaces for the 2nd round of transitive closure
let plan_mut = unsafe { &mut *(self.plan as *mut MarkCompact<VM>) };
let plan_mut = unsafe { mmtk.get_plan_mut() }
.downcast_mut::<MarkCompact<VM>>()
.unwrap();
plan_mut.common.release(worker.tls, true);
plan_mut.common.prepare(worker.tls, true);
#[cfg(feature = "extreme_assertions")]
Expand All @@ -67,11 +67,8 @@ impl<VM: VMBinding> GCWork<VM> for UpdateReferences<VM> {
}

impl<VM: VMBinding> UpdateReferences<VM> {
pub fn new(plan: &MarkCompact<VM>) -> Self {
Self {
plan,
p: PhantomData,
}
pub fn new() -> Self {
Self { p: PhantomData }
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/plan/markcompact/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ impl<VM: VMBinding> Plan for MarkCompact<VM> {

// Prepare global/collectors/mutators
scheduler.work_buckets[WorkBucketStage::Prepare]
.add(Prepare::<MarkCompactGCWorkContext<VM>>::new(self));
.add(Prepare::<MarkCompactGCWorkContext<VM>>::new());

scheduler.work_buckets[WorkBucketStage::CalculateForwarding]
.add(CalculateForwardingAddress::<VM>::new(&self.mc_space));
// do another trace to update references
scheduler.work_buckets[WorkBucketStage::SecondRoots].add(UpdateReferences::<VM>::new(self));
scheduler.work_buckets[WorkBucketStage::SecondRoots].add(UpdateReferences::<VM>::new());
scheduler.work_buckets[WorkBucketStage::Compact].add(Compact::<VM>::new(&self.mc_space));

// Release global/collectors/mutators
scheduler.work_buckets[WorkBucketStage::Release]
.add(Release::<MarkCompactGCWorkContext<VM>>::new(self));
.add(Release::<MarkCompactGCWorkContext<VM>>::new());

// Reference processing
if !*self.base().options.no_reference_types {
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<VM: VMBinding> Plan for MarkCompact<VM> {
}
#[cfg(feature = "sanity")]
scheduler.work_buckets[WorkBucketStage::Final]
.add(crate::util::sanity::sanity_checker::ScheduleSanityGC::<Self>::new(self));
.add(crate::util::sanity::sanity_checker::ScheduleSanityGC::<Self>::new());
}

fn collection_required(&self, space_full: bool, _space: Option<SpaceStats<Self::VM>>) -> bool {
Expand Down
26 changes: 14 additions & 12 deletions src/scheduler/gc_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,24 @@ impl<VM: VMBinding> GCWork<VM> for ScheduleCollection {
/// We assume this work packet is the only running work packet that accesses plan, and there should
/// be no other concurrent work packet that accesses plan (read or write). Otherwise, there may
/// be a race condition.
#[derive(Default)]
pub struct Prepare<C: GCWorkContext> {
pub plan: *const C::PlanType,
phantom_data: PhantomData<C>,
}

unsafe impl<C: GCWorkContext> Send for Prepare<C> {}

impl<C: GCWorkContext> Prepare<C> {
pub fn new(plan: *const C::PlanType) -> Self {
Self { plan }
pub fn new() -> Self {
Self {
phantom_data: PhantomData,
}
}
}

impl<C: GCWorkContext> GCWork<C::VM> for Prepare<C> {
fn do_work(&mut self, worker: &mut GCWorker<C::VM>, mmtk: &'static MMTK<C::VM>) {
trace!("Prepare Global");
// We assume this is the only running work packet that accesses plan at the point of execution
let plan_mut: &mut C::PlanType = unsafe { &mut *(self.plan as *const _ as *mut _) };
let plan_mut = unsafe { mmtk.get_plan_mut() };
plan_mut.prepare(worker.tls);

if plan_mut.constraints().needs_prepare_mutator {
Expand Down Expand Up @@ -112,26 +113,27 @@ impl<VM: VMBinding> GCWork<VM> for PrepareCollector {
/// We assume this work packet is the only running work packet that accesses plan, and there should
/// be no other concurrent work packet that accesses plan (read or write). Otherwise, there may
/// be a race condition.
#[derive(Default)]
pub struct Release<C: GCWorkContext> {
pub plan: *const C::PlanType,
phantom_data: PhantomData<C>,
}

impl<C: GCWorkContext> Release<C> {
pub fn new(plan: *const C::PlanType) -> Self {
Self { plan }
pub fn new() -> Self {
Self {
phantom_data: PhantomData,
}
}
}

unsafe impl<C: GCWorkContext> Send for Release<C> {}

impl<C: GCWorkContext + 'static> GCWork<C::VM> for Release<C> {
fn do_work(&mut self, worker: &mut GCWorker<C::VM>, mmtk: &'static MMTK<C::VM>) {
trace!("Release Global");

mmtk.gc_trigger.policy.on_gc_release(mmtk);
// We assume this is the only running work packet that accesses plan at the point of execution

let plan_mut: &mut C::PlanType = unsafe { &mut *(self.plan as *const _ as *mut _) };
let plan_mut = unsafe { mmtk.get_plan_mut() };
plan_mut.release(worker.tls);

let release_mutator_packets = <C::VM as VMBinding>::VMActivePlan::mutators()
Expand Down
6 changes: 3 additions & 3 deletions src/scheduler/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ impl<VM: VMBinding> GCWorkScheduler<VM> {
self.work_buckets[WorkBucketStage::Unconstrained].add(StopMutators::<C>::new());

// Prepare global/collectors/mutators
self.work_buckets[WorkBucketStage::Prepare].add(Prepare::<C>::new(plan));
self.work_buckets[WorkBucketStage::Prepare].add(Prepare::<C>::new());

// Release global/collectors/mutators
self.work_buckets[WorkBucketStage::Release].add(Release::<C>::new(plan));
self.work_buckets[WorkBucketStage::Release].add(Release::<C>::new());

// Analysis GC work
#[cfg(feature = "analysis")]
Expand All @@ -162,7 +162,7 @@ impl<VM: VMBinding> GCWorkScheduler<VM> {
{
use crate::util::sanity::sanity_checker::ScheduleSanityGC;
self.work_buckets[WorkBucketStage::Final]
.add(ScheduleSanityGC::<C::PlanType>::new(plan));
.add(ScheduleSanityGC::<C::PlanType>::new());
}

// Reference processing
Expand Down
Loading
Loading