@@ -104,13 +104,19 @@ the new `tospace`.
104104
105105### Prepare mutator
106106
107- Going back to ` mutator.rs ` , create a new function called
108- ` mygc_mutator_prepare(_mutator: &mut Mutator <MyGC<VM>>, _tls: OpaquePointer,) ` .
109- This function will be called at the preparation stage of a collection
110- (at the start of a collection) for each mutator. Its body can stay empty, as
111- there aren't any preparation steps for the mutator in this GC.
112- In ` create_mygc_mutator() ` , find the field ` prep_func ` and change it from
113- ` mygc_mutator_noop() ` to ` mygc_mutator_prepare() ` .
107+ Going back to ` mutator.rs ` , create a new function called
108+ ` mygc_mutator_prepare<VM: VMBinding>(_mutator: &mut Mutator<VM>, _tls: VMWorkerThread) ` .
109+ This function will be called at the preparation stage of a collection (at the start of a
110+ collection) for each mutator. Its body can stay empty, as there aren't any preparation steps for
111+ the mutator in this GC. In ` create_mygc_mutator() ` , find the field ` prepare_func ` and change it
112+ from ` &unreachable_prepare_func ` to ` &mygc_mutator_prepare ` .
113+
114+ > 💡 Hint: If your plan does nothing when preparing mutators, there is an optimization you can do.
115+ You may set the plan constraints field ` PlanConstraints::needs_prepare_mutator ` to ` false ` so that
116+ the ` PrepareMutator ` work packets which call ` prepare_func ` will not be created in the first place.
117+ This optimization is helpful for VMs that run with a large number of mutator threads. If you do
118+ this optimization, you may also leave the ` MutatorConfig::prepare_func ` field as
119+ ` &unreachable_prepare_func ` to indicate it should not be called.
114120
115121## Release
116122
@@ -131,24 +137,18 @@ routines for the common plan spaces and the fromspace.
131137
132138### Release in mutator
133139
134- Go back to ` mutator.rs ` . In ` create_mygc_mutator() ` , replace
135- ` mygc_mutator_noop() ` in the ` release_func ` field with ` mygc_mutator_release() ` .
136- Leave the ` release() ` function in the ` CopyContext ` empty. There are no
137- release steps for ` CopyContext ` in this collector.
138-
139- Create a new function called ` mygc_mutator_release() ` that takes the same
140- inputs as the ` prepare() ` function above. This function will be called at the
141- release stage of a collection (at the end of a collection) for each mutator.
142- It rebinds the allocator for the ` Default ` allocation semantics to the new
143- tospace. When the mutator threads resume, any new allocations for ` Default `
144- will then go to the new tospace.
145-
140+ Go back to ` mutator.rs ` . Create a new function called ` mygc_mutator_release() ` that takes the same
141+ inputs as the ` mygc_mutator_prepare() ` function above.
142+
146143``` rust
147144{{#include .. / .. / code / mygc_semispace / mutator . rs: release }}
148145```
149146
150- Delete ` mygc_mutator_noop() ` . It was a placeholder for the prepare and
151- release functions that you have now added, so it is now dead code.
147+ Then go to ` create_mygc_mutator() ` , replace ` &unreachable_release_func ` in the ` release_func ` field
148+ with ` &mygc_mutator_release ` . This function will be called at the release stage of a collection
149+ (at the end of a collection) for each mutator. It rebinds the allocator for the ` Default `
150+ allocation semantics to the new tospace. When the mutator threads resume, any new allocations for
151+ ` Default ` will then go to the new tospace.
152152
153153## ProcessEdgesWork for MyGC
154154
0 commit comments