Skip to content

Commit a2c6012

Browse files
committed
Rename attributes
Make attributes less specific to tracing.
1 parent 6c6522c commit a2c6012

File tree

14 files changed

+70
-60
lines changed

14 files changed

+70
-60
lines changed

docs/userguide/src/tutorial/code/mygc_semispace/global.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ use mmtk_macros::PlanTraceObject;
3131
#[derive(PlanTraceObject)]
3232
pub struct MyGC<VM: VMBinding> {
3333
pub hi: AtomicBool,
34-
#[trace(CopySemantics::DefaultCopy)]
34+
#[space]
35+
#[copy_semantics(CopySemantics::DefaultCopy)]
3536
pub copyspace0: CopySpace<VM>,
36-
#[trace(CopySemantics::DefaultCopy)]
37+
#[space]
38+
#[copy_semantics(CopySemantics::DefaultCopy)]
3739
pub copyspace1: CopySpace<VM>,
38-
#[fallback_trace]
40+
#[parent]
3941
pub common: CommonPlan<VM>,
4042
}
4143
// ANCHOR_END: plan_def

docs/userguide/src/tutorial/mygc/ss/collection.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ it can use `PlanProcessEdges`.
182182
You can manually provide an implementation of `PlanTraceObject` for `MyGC`. But you can also use the derive macro MMTK provides,
183183
and the macro will generate an implementation of `PlanTraceObject`:
184184
* 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
185+
* add `#[space]
186+
#[copy_semantics(CopySemantics::Default)]` to both copy space fields, `copyspace0` and `copyspace1`. This tells the macro to generate
186187
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+
* add `#[parent]` to `common`. This tells the macro that if an object is not found in any space with `#[space]` in ths plan,
188189
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
189190
in large object space or immortal space in the common plan. `CommonPlan` also implements `PlanTraceObject`, so it knows how to
190191
find a space for the object and trace it in the same way.
@@ -244,4 +245,4 @@ If the benchmarks pass - good job! You have built a functional copying
244245
collector!
245246

246247
If you get particularly stuck, the code for the completed `MyGC` plan
247-
is available [here](https://github.com/mmtk/mmtk-core/tree/master/docs/tutorial/code/mygc_semispace).
248+
is available [here](https://github.com/mmtk/mmtk-core/tree/master/docs/tutorial/code/mygc_semispace).

macros/src/lib.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const DEBUG_MACRO_OUTPUT: bool = false;
2828
/// * add `#[post_scan]` to any space field that has some policy-specific post_scan_object(). For objects in those spaces,
2929
/// `post_scan_object()` in the policy will be called after `VM::VMScanning::scan_object()`.
3030
#[proc_macro_error]
31-
#[proc_macro_derive(PlanTraceObject, attributes(trace, post_scan, fallback_trace))]
31+
#[proc_macro_derive(PlanTraceObject, attributes(space, parent, copy_semantics, post_scan))]
3232
pub fn derive_plan_trace_object(input: TokenStream) -> TokenStream {
3333
let input = parse_macro_input!(input as DeriveInput);
3434
let ident = input.ident;
@@ -41,19 +41,16 @@ pub fn derive_plan_trace_object(input: TokenStream) -> TokenStream {
4141
abort_call_site!("`#[derive(PlanTraceObject)]` only supports structs with named fields.");
4242
};
4343

44-
let spaces = util::get_fields_with_attribute(fields, "trace");
44+
let spaces = util::get_fields_with_attribute(fields, "space");
4545
let post_scan_spaces = util::get_fields_with_attribute(fields, "post_scan");
46-
let fallback = util::get_unique_field_with_attribute(fields, "fallback_trace");
46+
let parent = util::get_unique_field_with_attribute(fields, "parent");
4747

4848
let trace_object_function =
49-
plan_trace_object_impl::generate_trace_object(&spaces, &fallback, &ty_generics);
50-
let post_scan_object_function = plan_trace_object_impl::generate_post_scan_object(
51-
&post_scan_spaces,
52-
&fallback,
53-
&ty_generics,
54-
);
49+
plan_trace_object_impl::generate_trace_object(&spaces, &parent, &ty_generics);
50+
let post_scan_object_function =
51+
plan_trace_object_impl::generate_post_scan_object(&post_scan_spaces, &parent, &ty_generics);
5552
let may_move_objects_function =
56-
plan_trace_object_impl::generate_may_move_objects(&spaces, &fallback, &ty_generics);
53+
plan_trace_object_impl::generate_may_move_objects(&spaces, &parent, &ty_generics);
5754

5855
let output = quote! {
5956
impl #impl_generics crate::plan::PlanTraceObject #ty_generics for #ident #ty_generics #where_clause {

macros/src/plan_trace_object_impl.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,26 @@ pub(crate) fn generate_trace_object<'a>(
1616
let f_ty = &f.ty;
1717

1818
// Figure out copy
19-
let trace_attr = util::get_field_attribute(f, "trace").unwrap();
20-
let copy = match &trace_attr.meta {
21-
syn::Meta::Path(_) => {
22-
// #[trace]
23-
quote!{ None }
24-
},
25-
syn::Meta::List(list) => {
26-
// #[trace(CopySemantics::BlahBlah)]
27-
let copy_semantics = list.parse_args::<Expr>().unwrap_or_else(|_| {
28-
abort_call_site!("In `#[trace(copy_semantics)]`, copy_semantics must be an expression.");
29-
});
30-
31-
quote!{ Some(#copy_semantics) }
32-
},
33-
syn::Meta::NameValue(_) => {
34-
// #[trace = BlahBlah]
35-
abort_call_site!("The #[trace] macro does not support name-value form.");
36-
},
19+
let maybe_copy_semantics_attr = util::get_field_attribute(f, "copy_semantics");
20+
let copy = match maybe_copy_semantics_attr {
21+
None => quote!{ None },
22+
Some(attr) => match &attr.meta {
23+
syn::Meta::Path(_) => {
24+
// #[copy_semantics]
25+
abort_call_site!("The `#[copy_semantics(expr)]` macro needs an argument.");
26+
},
27+
syn::Meta::List(list) => {
28+
// #[copy_semantics(BlahBlah)]
29+
let copy_semantics = list.parse_args::<Expr>().unwrap_or_else(|_| {
30+
abort_call_site!("In `#[copy_semantics(expr)]`, expr must be an expression.");
31+
});
32+
quote!{ Some(#copy_semantics) }
33+
},
34+
syn::Meta::NameValue(_) => {
35+
// #[copy_semantics = BlahBlah]
36+
abort_call_site!("The #[copy_semantics] macro does not support the name-value form.");
37+
},
38+
}
3739
};
3840

3941
quote! {

src/plan/generational/copying/global.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ use mmtk_macros::PlanTraceObject;
3131

3232
#[derive(PlanTraceObject)]
3333
pub struct GenCopy<VM: VMBinding> {
34-
#[fallback_trace]
34+
#[parent]
3535
pub gen: CommonGenPlan<VM>,
3636
pub hi: AtomicBool,
37-
#[trace(CopySemantics::Mature)]
37+
#[space]
38+
#[copy_semantics(CopySemantics::Mature)]
3839
pub copyspace0: CopySpace<VM>,
39-
#[trace(CopySemantics::Mature)]
40+
#[space]
41+
#[copy_semantics(CopySemantics::Mature)]
4042
pub copyspace1: CopySpace<VM>,
4143
}
4244

src/plan/generational/global.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ use mmtk_macros::PlanTraceObject;
2424
#[derive(PlanTraceObject)]
2525
pub struct CommonGenPlan<VM: VMBinding> {
2626
/// The nursery space.
27-
#[trace(CopySemantics::PromoteToMature)]
27+
#[space]
28+
#[copy_semantics(CopySemantics::PromoteToMature)]
2829
pub nursery: CopySpace<VM>,
2930
/// The common plan.
30-
#[fallback_trace]
31+
#[parent]
3132
pub common: CommonPlan<VM>,
3233
/// Is this GC full heap?
3334
pub gc_full_heap: AtomicBool,

src/plan/generational/immix/global.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ use mmtk_macros::PlanTraceObject;
3838
#[derive(PlanTraceObject)]
3939
pub struct GenImmix<VM: VMBinding> {
4040
/// Generational plan, which includes a nursery space and operations related with nursery.
41-
#[fallback_trace]
41+
#[parent]
4242
pub gen: CommonGenPlan<VM>,
4343
/// An immix space as the mature space.
4444
#[post_scan]
45-
#[trace(CopySemantics::Mature)]
45+
#[space]
46+
#[copy_semantics(CopySemantics::Mature)]
4647
pub immix_space: ImmixSpace<VM>,
4748
/// Whether the last GC was a defrag GC for the immix space.
4849
pub last_gc_was_defrag: AtomicBool,

src/plan/global.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,13 @@ pub struct BasePlan<VM: VMBinding> {
431431

432432
// Spaces in base plan
433433
#[cfg(feature = "code_space")]
434-
#[trace]
434+
#[space]
435435
pub code_space: ImmortalSpace<VM>,
436436
#[cfg(feature = "code_space")]
437-
#[trace]
437+
#[space]
438438
pub code_lo_space: ImmortalSpace<VM>,
439439
#[cfg(feature = "ro_space")]
440-
#[trace]
440+
#[space]
441441
pub ro_space: ImmortalSpace<VM>,
442442

443443
/// A VM space is a space allocated and populated by the VM. Currently it is used by JikesRVM
@@ -453,7 +453,7 @@ pub struct BasePlan<VM: VMBinding> {
453453
/// - The `is_in_mmtk_spaces` currently returns `true` if the given object reference is in
454454
/// the VM space.
455455
#[cfg(feature = "vm_space")]
456-
#[trace]
456+
#[space]
457457
pub vm_space: VMSpace<VM>,
458458
}
459459

@@ -898,14 +898,14 @@ CommonPlan is for representing state and features used by _many_ plans, but that
898898
*/
899899
#[derive(PlanTraceObject)]
900900
pub struct CommonPlan<VM: VMBinding> {
901-
#[trace]
901+
#[space]
902902
pub immortal: ImmortalSpace<VM>,
903-
#[trace]
903+
#[space]
904904
pub los: LargeObjectSpace<VM>,
905905
// TODO: We should use a marksweep space for nonmoving.
906-
#[trace]
906+
#[space]
907907
pub nonmoving: ImmortalSpace<VM>,
908-
#[fallback_trace]
908+
#[parent]
909909
pub base: BasePlan<VM>,
910910
}
911911

src/plan/immix/global.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ use mmtk_macros::PlanTraceObject;
2929
#[derive(PlanTraceObject)]
3030
pub struct Immix<VM: VMBinding> {
3131
#[post_scan]
32-
#[trace(CopySemantics::DefaultCopy)]
32+
#[space]
33+
#[copy_semantics(CopySemantics::DefaultCopy)]
3334
pub immix_space: ImmixSpace<VM>,
34-
#[fallback_trace]
35+
#[parent]
3536
pub common: CommonPlan<VM>,
3637
last_gc_was_defrag: AtomicBool,
3738
}

src/plan/markcompact/global.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ use mmtk_macros::PlanTraceObject;
2929

3030
#[derive(PlanTraceObject)]
3131
pub struct MarkCompact<VM: VMBinding> {
32-
#[trace(CopySemantics::DefaultCopy)]
32+
#[space]
33+
#[copy_semantics(CopySemantics::DefaultCopy)]
3334
pub mc_space: MarkCompactSpace<VM>,
34-
#[fallback_trace]
35+
#[parent]
3536
pub common: CommonPlan<VM>,
3637
}
3738

src/plan/marksweep/global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ use crate::policy::marksweepspace::native_ms::MAX_OBJECT_SIZE;
3030

3131
#[derive(PlanTraceObject)]
3232
pub struct MarkSweep<VM: VMBinding> {
33-
#[fallback_trace]
33+
#[parent]
3434
common: CommonPlan<VM>,
35-
#[trace]
35+
#[space]
3636
ms: MarkSweepSpace<VM>,
3737
}
3838

src/plan/pageprotect/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use mmtk_macros::PlanTraceObject;
2222

2323
#[derive(PlanTraceObject)]
2424
pub struct PageProtect<VM: VMBinding> {
25-
#[trace]
25+
#[space]
2626
pub space: LargeObjectSpace<VM>,
2727
pub common: CommonPlan<VM>,
2828
}

src/plan/semispace/global.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ use enum_map::EnumMap;
2525
#[derive(PlanTraceObject)]
2626
pub struct SemiSpace<VM: VMBinding> {
2727
pub hi: AtomicBool,
28-
#[trace(CopySemantics::DefaultCopy)]
28+
#[space]
29+
#[copy_semantics(CopySemantics::DefaultCopy)]
2930
pub copyspace0: CopySpace<VM>,
30-
#[trace(CopySemantics::DefaultCopy)]
31+
#[space]
32+
#[copy_semantics(CopySemantics::DefaultCopy)]
3133
pub copyspace1: CopySpace<VM>,
32-
#[fallback_trace]
34+
#[parent]
3335
pub common: CommonPlan<VM>,
3436
}
3537

src/plan/sticky/immix/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use super::gc_work::StickyImmixNurseryGCWorkContext;
2828

2929
#[derive(PlanTraceObject)]
3030
pub struct StickyImmix<VM: VMBinding> {
31-
#[fallback_trace]
31+
#[parent]
3232
immix: immix::Immix<VM>,
3333
gc_full_heap: AtomicBool,
3434
next_gc_full_heap: AtomicBool,

0 commit comments

Comments
 (0)