Skip to content

Remove ptr/ref to Plan from work packets - #1510

Draft
wks wants to merge 1 commit into
mmtk:masterfrom
wks:fix/no-capture-plan
Draft

wks wants to merge 1 commit into
mmtk:masterfrom
wks:fix/no-capture-plan

Conversation

@wks

@wks wks commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

GCWork::do_work has an mmtk parameter, and the MMTK::get_plan() and MMTK::get_plan_mut() methods provide access to the plan instance. It is therefore pointless for a work packet to capture a pointer or reference inside the struct itself.

This PR does not fix the fact that Plan::prepare and Plan::release have &mut self arguments. Therefore, getting &mut Plan from an MMTK instance is still unsafe. See:
#852

`GCWork::do_work` has an `mmtk` parameter, and the `MMTK::get_plan()`
and `MMTK::get_plan_mut()` methods provide access to the plan instance.
It is therefore pointless for a work packet to capture a pointer or
reference inside the struct itself.

This PR does not fix the fact that `Plan::prepare` and `Plan::release`
have `&mut self` arguments.  Therefore, getting `&mut Plan` from an
`MMTK` instance is still unsafe.  See:
mmtk#852
@wks

wks commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

I am not sure if it is worth making this change. It is always safer to use fewer raw pointers and weird casting statements like unsafe { &mut *(self.plan as *const _ as *mut _) }. But this PR doesn't really make mmtk.get_plan() or mmtk.get_plan_mut() safe because MMTK::plan is still an UnsafeCell<Box<dyn Plan<VM = VM>>>.

@qinsoon

qinsoon commented Jun 9, 2026

Copy link
Copy Markdown
Member

I am not sure if it is worth making this change. It is always safer to use fewer raw pointers and weird casting statements like unsafe { &mut *(self.plan as *const _ as *mut _) }. But this PR doesn't really make mmtk.get_plan() or mmtk.get_plan_mut() safe because MMTK::plan is still an UnsafeCell<Box<dyn Plan<VM = VM>>>.

I think it is cleaner. With the refactoring, all we need to address is the unsafe on MMTK::get_plan/get_plan_mut.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants