Skip to content

Commit 1e79646

Browse files
qinsoonJavad Amiri
and
Javad Amiri
authored
Object model specs refactoring (#367)
* Many funcitons take Metadata args as references * Use specific types for ObjectModel. Remove vm_metadata_used() from Space. * add comments for side metadata offsets to objectmodel Co-authored-by: Javad Amiri <[email protected]>
1 parent a849906 commit 1e79646

22 files changed

+312
-209
lines changed

src/plan/barriers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<E: ProcessEdgesWork> ObjectRememberingBarrier<E> {
5353
#[inline(always)]
5454
fn enqueue_node<VM: VMBinding>(&mut self, obj: ObjectReference) {
5555
if compare_exchange_metadata::<VM>(
56-
self.meta,
56+
&self.meta,
5757
obj,
5858
0b1,
5959
0b0,

src/plan/gencopy/gc_work.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<VM: VMBinding> CopyContext for GenCopyCopyContext<VM> {
5858
object_forwarding::clear_forwarding_bits::<VM>(obj);
5959
if !super::NO_SLOW && super::ACTIVE_BARRIER == BarrierSelector::ObjectBarrier {
6060
store_metadata::<VM>(
61-
VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC,
61+
&VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC,
6262
obj,
6363
0b1,
6464
None,

src/plan/gencopy/global.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<VM: VMBinding> GenCopy<VM> {
200200
) -> Self {
201201
let mut heap = HeapMeta::new(HEAP_START, HEAP_END);
202202
let gencopy_specs = if super::ACTIVE_BARRIER == BarrierSelector::ObjectBarrier {
203-
metadata::extract_side_metadata(&[VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC])
203+
metadata::extract_side_metadata(&[*VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC])
204204
} else {
205205
vec![]
206206
};

src/plan/gencopy/mutator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn create_gencopy_mutator<VM: VMBinding>(
5959
allocators: Allocators::<VM>::new(mutator_tls, &*mmtk.plan, &config.space_mapping),
6060
barrier: box ObjectRememberingBarrier::<GenCopyNurseryProcessEdges<VM>>::new(
6161
mmtk,
62-
VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC,
62+
*VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC,
6363
),
6464
mutator_tls,
6565
config,

src/policy/copyspace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ impl<VM: VMBinding> CopySpace<VM> {
7777
heap: &mut HeapMeta,
7878
) -> Self {
7979
let local_specs = extract_side_metadata(&[
80-
VM::VMObjectModel::LOCAL_FORWARDING_BITS_SPEC,
81-
VM::VMObjectModel::LOCAL_FORWARDING_POINTER_SPEC,
80+
*VM::VMObjectModel::LOCAL_FORWARDING_BITS_SPEC,
81+
*VM::VMObjectModel::LOCAL_FORWARDING_POINTER_SPEC,
8282
]);
8383
let common = CommonSpace::new(
8484
SpaceOptions {

src/policy/immortalspace.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ impl<VM: VMBinding> SFT for ImmortalSpace<VM> {
4646
}
4747
fn initialize_object_metadata(&self, object: ObjectReference, _alloc: bool) {
4848
let old_value = load_metadata::<VM>(
49-
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
49+
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
5050
object,
5151
None,
5252
Some(Ordering::SeqCst),
5353
);
5454
let new_value = (old_value & GC_MARK_BIT_MASK) | self.mark_state;
5555
store_metadata::<VM>(
56-
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
56+
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
5757
object,
5858
new_value,
5959
None,
@@ -106,7 +106,7 @@ impl<VM: VMBinding> ImmortalSpace<VM> {
106106
side_metadata_specs: SideMetadataContext {
107107
global: global_side_metadata_specs,
108108
local: metadata::extract_side_metadata(&[
109-
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
109+
*VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
110110
]),
111111
},
112112
},
@@ -133,7 +133,7 @@ impl<VM: VMBinding> ImmortalSpace<VM> {
133133
fn test_and_mark(object: ObjectReference, value: usize) -> bool {
134134
loop {
135135
let old_value = load_metadata::<VM>(
136-
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
136+
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
137137
object,
138138
None,
139139
Some(Ordering::SeqCst),
@@ -143,7 +143,7 @@ impl<VM: VMBinding> ImmortalSpace<VM> {
143143
}
144144

145145
if compare_exchange_metadata::<VM>(
146-
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
146+
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
147147
object,
148148
old_value,
149149
old_value ^ GC_MARK_BIT_MASK,

src/policy/largeobjectspace.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<VM: VMBinding> SFT for LargeObjectSpace<VM> {
5252
}
5353
fn initialize_object_metadata(&self, object: ObjectReference, alloc: bool) {
5454
let old_value = load_metadata::<VM>(
55-
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
55+
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
5656
object,
5757
None,
5858
Some(Ordering::SeqCst),
@@ -62,7 +62,7 @@ impl<VM: VMBinding> SFT for LargeObjectSpace<VM> {
6262
new_value |= NURSERY_BIT;
6363
}
6464
store_metadata::<VM>(
65-
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
65+
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
6666
object,
6767
new_value,
6868
None,
@@ -118,7 +118,7 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
118118
side_metadata_specs: SideMetadataContext {
119119
global: global_side_metadata_specs,
120120
local: metadata::extract_side_metadata(&[
121-
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
121+
*VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
122122
]),
123123
},
124124
},
@@ -208,7 +208,7 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
208208
MARK_BIT
209209
};
210210
let old_value = load_metadata::<VM>(
211-
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
211+
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
212212
object,
213213
None,
214214
Some(Ordering::SeqCst),
@@ -218,7 +218,7 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
218218
return false;
219219
}
220220
if compare_exchange_metadata::<VM>(
221-
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
221+
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
222222
object,
223223
old_value,
224224
old_value & !LOS_BIT_MASK | value,
@@ -234,7 +234,7 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
234234

235235
fn test_mark_bit(&self, object: ObjectReference, value: usize) -> bool {
236236
load_metadata::<VM>(
237-
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
237+
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
238238
object,
239239
None,
240240
Some(Ordering::SeqCst),
@@ -245,7 +245,7 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
245245
/// Check if a given object is in nursery
246246
fn is_in_nursery(&self, object: ObjectReference) -> bool {
247247
load_metadata::<VM>(
248-
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
248+
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
249249
object,
250250
None,
251251
Some(Ordering::Relaxed),
@@ -257,14 +257,14 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
257257
fn clear_nursery(&self, object: ObjectReference) {
258258
loop {
259259
let old_val = load_metadata::<VM>(
260-
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
260+
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
261261
object,
262262
None,
263263
Some(Ordering::Relaxed),
264264
);
265265
let new_val = old_val & !NURSERY_BIT;
266266
if compare_exchange_metadata::<VM>(
267-
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
267+
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
268268
object,
269269
old_val,
270270
new_val,

src/policy/mallocspace/global.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<VM: VMBinding> MallocSpace<VM> {
149149
global: global_side_metadata_specs,
150150
local: metadata::extract_side_metadata(&[
151151
MetadataSpec::OnSide(ALLOC_SIDE_METADATA_SPEC),
152-
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
152+
*VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
153153
]),
154154
},
155155
#[cfg(debug_assertions)]

src/policy/mallocspace/metadata.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ pub fn is_alloced(object: ObjectReference) -> bool {
7373
}
7474

7575
pub fn is_alloced_object(address: Address) -> bool {
76-
side_metadata::load_atomic(ALLOC_SIDE_METADATA_SPEC, address, Ordering::SeqCst) == 1
76+
side_metadata::load_atomic(&ALLOC_SIDE_METADATA_SPEC, address, Ordering::SeqCst) == 1
7777
}
7878

7979
pub fn is_marked<VM: VMBinding>(object: ObjectReference) -> bool {
8080
load_metadata::<VM>(
81-
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
81+
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
8282
object,
8383
None,
8484
Some(Ordering::SeqCst),
@@ -87,7 +87,7 @@ pub fn is_marked<VM: VMBinding>(object: ObjectReference) -> bool {
8787

8888
pub fn set_alloc_bit(object: ObjectReference) {
8989
side_metadata::store_atomic(
90-
ALLOC_SIDE_METADATA_SPEC,
90+
&ALLOC_SIDE_METADATA_SPEC,
9191
object.to_address(),
9292
1,
9393
Ordering::SeqCst,
@@ -96,7 +96,7 @@ pub fn set_alloc_bit(object: ObjectReference) {
9696

9797
pub fn set_mark_bit<VM: VMBinding>(object: ObjectReference) {
9898
store_metadata::<VM>(
99-
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
99+
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
100100
object,
101101
1,
102102
None,
@@ -106,7 +106,7 @@ pub fn set_mark_bit<VM: VMBinding>(object: ObjectReference) {
106106

107107
pub fn unset_alloc_bit(object: ObjectReference) {
108108
side_metadata::store_atomic(
109-
ALLOC_SIDE_METADATA_SPEC,
109+
&ALLOC_SIDE_METADATA_SPEC,
110110
object.to_address(),
111111
0,
112112
Ordering::SeqCst,
@@ -115,7 +115,7 @@ pub fn unset_alloc_bit(object: ObjectReference) {
115115

116116
pub fn unset_mark_bit<VM: VMBinding>(object: ObjectReference) {
117117
store_metadata::<VM>(
118-
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
118+
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
119119
object,
120120
0,
121121
None,

src/scheduler/gc_work.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<E: ProcessEdgesWork> GCWork<E::VM> for ProcessModBuf<E> {
497497
if !self.modbuf.is_empty() {
498498
for obj in &self.modbuf {
499499
compare_exchange_metadata::<E::VM>(
500-
self.meta,
500+
&self.meta,
501501
*obj,
502502
0b0,
503503
0b1,

src/util/metadata/global.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use crate::util::metadata::side_metadata;
2-
use crate::vm::ObjectModel;
3-
use atomic::Ordering;
4-
52
use crate::util::metadata::side_metadata::SideMetadataSpec;
63
use crate::util::ObjectReference;
4+
use crate::vm::ObjectModel;
75
use crate::vm::VMBinding;
6+
use atomic::Ordering;
87

98
use super::header_metadata::HeaderMetadataSpec;
109

@@ -39,7 +38,7 @@ impl MetadataSpec {
3938
///
4039
#[inline(always)]
4140
pub fn load_metadata<VM: VMBinding>(
42-
metadata_spec: MetadataSpec,
41+
metadata_spec: &MetadataSpec,
4342
object: ObjectReference,
4443
mask: Option<usize>,
4544
atomic_ordering: Option<Ordering>,
@@ -70,7 +69,7 @@ pub fn load_metadata<VM: VMBinding>(
7069
///
7170
#[inline(always)]
7271
pub fn store_metadata<VM: VMBinding>(
73-
metadata_spec: MetadataSpec,
72+
metadata_spec: &MetadataSpec,
7473
object: ObjectReference,
7574
val: usize,
7675
mask: Option<usize>,
@@ -108,7 +107,7 @@ pub fn store_metadata<VM: VMBinding>(
108107
///
109108
#[inline(always)]
110109
pub fn compare_exchange_metadata<VM: VMBinding>(
111-
metadata_spec: MetadataSpec,
110+
metadata_spec: &MetadataSpec,
112111
object: ObjectReference,
113112
old_val: usize,
114113
new_val: usize,
@@ -150,7 +149,7 @@ pub fn compare_exchange_metadata<VM: VMBinding>(
150149
///
151150
#[inline(always)]
152151
pub fn fetch_add_metadata<VM: VMBinding>(
153-
metadata_spec: MetadataSpec,
152+
metadata_spec: &MetadataSpec,
154153
object: ObjectReference,
155154
val: usize,
156155
order: Ordering,
@@ -178,7 +177,7 @@ pub fn fetch_add_metadata<VM: VMBinding>(
178177
///
179178
#[inline(always)]
180179
pub fn fetch_sub_metadata<VM: VMBinding>(
181-
metadata_spec: MetadataSpec,
180+
metadata_spec: &MetadataSpec,
182181
object: ObjectReference,
183182
val: usize,
184183
order: Ordering,

src/util/metadata/header_metadata.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl fmt::Debug for HeaderMetadataSpec {
4444
/// This function provides a default implementation for the `load_metadata` method from the `ObjectModel` trait.
4545
#[inline(always)]
4646
pub fn load_metadata(
47-
metadata_spec: HeaderMetadataSpec,
47+
metadata_spec: &HeaderMetadataSpec,
4848
object: ObjectReference,
4949
optional_mask: Option<usize>,
5050
atomic_ordering: Option<Ordering>,
@@ -151,7 +151,7 @@ pub fn load_metadata(
151151
/// This function provides a default implementation for the `store_metadata` method from the `ObjectModel` trait.
152152
#[inline(always)]
153153
pub fn store_metadata(
154-
metadata_spec: HeaderMetadataSpec,
154+
metadata_spec: &HeaderMetadataSpec,
155155
object: ObjectReference,
156156
val: usize,
157157
optional_mask: Option<usize>,
@@ -353,7 +353,7 @@ pub fn store_metadata(
353353
/// This function provides a default implementation for the `compare_exchange_metadata` method from the `ObjectModel` trait.
354354
#[inline(always)]
355355
pub fn compare_exchange_metadata(
356-
metadata_spec: HeaderMetadataSpec,
356+
metadata_spec: &HeaderMetadataSpec,
357357
object: ObjectReference,
358358
old_metadata: usize,
359359
new_metadata: usize,
@@ -510,7 +510,7 @@ pub fn compare_exchange_metadata(
510510
/// This function provides a default implementation for the `fetch_add_metadata` method from the `ObjectModel` trait.
511511
#[inline(always)]
512512
pub fn fetch_add_metadata(
513-
metadata_spec: HeaderMetadataSpec,
513+
metadata_spec: &HeaderMetadataSpec,
514514
object: ObjectReference,
515515
val: usize,
516516
order: Ordering,
@@ -602,7 +602,7 @@ pub fn fetch_add_metadata(
602602
/// This function provides a default implementation for the `fetch_sub_metadata` method from the `ObjectModel` trait.
603603
#[inline(always)]
604604
pub fn fetch_sub_metadata(
605-
metadata_spec: HeaderMetadataSpec,
605+
metadata_spec: &HeaderMetadataSpec,
606606
object: ObjectReference,
607607
val: usize,
608608
order: Ordering,

src/util/metadata/side_metadata/constants.rs

+26
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,36 @@ pub(super) const CHUNK_MASK: usize = (1 << LOG_BYTES_IN_CHUNK) - 1;
5151
pub(super) const LOCAL_SIDE_METADATA_PER_CHUNK: usize =
5252
BYTES_IN_CHUNK >> LOG_LOCAL_SIDE_METADATA_WORST_CASE_RATIO;
5353

54+
// The constants _VM_BASE_ADDRESS depends on the side metadata we use inside mmtk-core.
55+
// If we add any new side metadata internal to mmtk-core, we need to update this accordingly.
56+
57+
// TODO: We should think if it is possible to update this when we create a new side metadata spec.
58+
// One issue is that these need to be constants. Possibly we need to use macros or custom build scripts.
59+
60+
// --------------------------------------------------
61+
//
62+
// Global Metadata
63+
//
64+
// MMTk reserved Global side metadata offsets:
65+
// [currently empty]
66+
//
67+
// --------------------------------------------------
68+
5469
/// The base address for the global side metadata space available to VM bindings, to be used for the per-object metadata.
5570
/// VM bindings must use this to avoid overlap with core internal global side metadata.
5671
pub const GLOBAL_SIDE_METADATA_VM_BASE_ADDRESS: Address = GLOBAL_SIDE_METADATA_BASE_ADDRESS;
5772

73+
// --------------------------------------------------
74+
// PolicySpecific Metadata
75+
//
76+
// MMTk reserved PolicySpecific side metadata offsets:
77+
//
78+
// 1 - MarkSweep Alloc bit:
79+
// - Offset `0x0` on 32-bits
80+
// - Offset `LOCAL_SIDE_METADATA_BASE_ADDRESS` on 64-bits
81+
//
82+
// --------------------------------------------------
83+
5884
/// The base address for the local side metadata space available to VM bindings, to be used for the per-object metadata.
5985
/// VM bindings must use this to avoid overlap with core internal local side metadata.
6086
#[cfg(target_pointer_width = "64")]

0 commit comments

Comments
 (0)