You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use macro to generate process edges for plans (#575)
This PR adds `PlanProcessEdges`, and a few macros/traits that are used in `PlanProcessEdges`. This PR removes policy-specific code from plan, and use macros to generate trace object work for each plan. This PR closes#258, and closes#576.
* add a trait `PolicyTraceObject`. Each policy provides an implementation of this. With this trait, a plan no longer include any policy-specific code in trace object.
* add a trait `PlanTraceObject` and related macros. With the macro, plan implementer can declaratively specify trace object behavior with attributes, and the implementation of `PlanTraceObject` will be generated by the macro.
* add a type `PlanProcessEdges`. This uses `PlanTraceObject` to provide a general implementation of `ProcessEdgesWork`. We no longer need any plan-specific process edges work.
the tracing of objects to their respective spaces through [Space Function Table (SFT)](https://www.mmtk.io/mmtk-core/mmtk/policy/space/trait.SFT.html).
169
+
As long as all the policies in a plan provide an implementation of `sft_trace_object()` in their SFT implementations,
170
+
the plan can use `SFTProcessEdges`. Currently most policies provide an implementation for `sft_trace_object()`, except
171
+
mark compact and immix. Those two policies use multiple GC traces, and due to the limitation of SFT, SFT does not allow
172
+
multiple `sft_trace_object()` for a policy.
173
+
174
+
`SFTProcessEdges` is the simplest approach when all the policies support it. Fortunately, we can use it for our GC, semispace.
175
+
176
+
### Approach 2: Derive `PlanTraceObject` and use `PlanProcessEdges`
177
+
178
+
`PlanProcessEdges` is another general `ProcessEdgesWork` implementation that can be used by most plans. When a plan
179
+
implements the [`PlanTraceObject`](https://www.mmtk.io/mmtk-core/mmtk/plan/transitive_closure/trait.PlanTraceObject.html),
180
+
it can use `PlanProcessEdges`.
181
+
182
+
You can manually provide an implementation of `PlanTraceObject` for `MyGC`. But you can also use the derive macro MMTK provides,
183
+
and the macro will generate an implementation of `PlanTraceObject`:
184
+
* add `#[derive(PlanTraceObject)]` for `MyGC` (import the macro properly: `use mmtk_macros::PlanTraceObject`)
185
+
* add `#[trace(CopySemantics::Default)]` to both copy space fields, `copyspace0` and `copyspace1`. This tells the macro to generate
186
+
trace code for both spaces, and for any copying in the spaces, use `CopySemantics::DefaultCopy` that we have configured early.
187
+
* add `#[fallback_trace]` to `common`. This tells the macro that if an object is not found in any space with `#[trace]` in ths plan,
188
+
try find the space for the object in the 'parent' plan. In our case, we fall back to the `CommonPlan`, as the object may be
189
+
in large object space or immortal space in the common plan. `CommonPlan` also implements `PlanTraceObject`, so it knows how to
190
+
find a space for the object and trace it in the same way.
191
+
192
+
With the derive macro, your `MyGC` struct should look like this:
0 commit comments