Skip to content

Commit

Permalink
Object model specs refactoring (#367)
Browse files Browse the repository at this point in the history
* 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 <javad.amiri@anu.edu.au>
  • Loading branch information
qinsoon and Javad Amiri committed Jul 8, 2021
1 parent a849906 commit 1e79646
Show file tree
Hide file tree
Showing 22 changed files with 312 additions and 209 deletions.
2 changes: 1 addition & 1 deletion src/plan/barriers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<E: ProcessEdgesWork> ObjectRememberingBarrier<E> {
#[inline(always)]
fn enqueue_node<VM: VMBinding>(&mut self, obj: ObjectReference) {
if compare_exchange_metadata::<VM>(
self.meta,
&self.meta,
obj,
0b1,
0b0,
Expand Down
2 changes: 1 addition & 1 deletion src/plan/gencopy/gc_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<VM: VMBinding> CopyContext for GenCopyCopyContext<VM> {
object_forwarding::clear_forwarding_bits::<VM>(obj);
if !super::NO_SLOW && super::ACTIVE_BARRIER == BarrierSelector::ObjectBarrier {
store_metadata::<VM>(
VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC,
&VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC,
obj,
0b1,
None,
Expand Down
2 changes: 1 addition & 1 deletion src/plan/gencopy/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<VM: VMBinding> GenCopy<VM> {
) -> Self {
let mut heap = HeapMeta::new(HEAP_START, HEAP_END);
let gencopy_specs = if super::ACTIVE_BARRIER == BarrierSelector::ObjectBarrier {
metadata::extract_side_metadata(&[VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC])
metadata::extract_side_metadata(&[*VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC])
} else {
vec![]
};
Expand Down
2 changes: 1 addition & 1 deletion src/plan/gencopy/mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn create_gencopy_mutator<VM: VMBinding>(
allocators: Allocators::<VM>::new(mutator_tls, &*mmtk.plan, &config.space_mapping),
barrier: box ObjectRememberingBarrier::<GenCopyNurseryProcessEdges<VM>>::new(
mmtk,
VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC,
*VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC,
),
mutator_tls,
config,
Expand Down
4 changes: 2 additions & 2 deletions src/policy/copyspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ impl<VM: VMBinding> CopySpace<VM> {
heap: &mut HeapMeta,
) -> Self {
let local_specs = extract_side_metadata(&[
VM::VMObjectModel::LOCAL_FORWARDING_BITS_SPEC,
VM::VMObjectModel::LOCAL_FORWARDING_POINTER_SPEC,
*VM::VMObjectModel::LOCAL_FORWARDING_BITS_SPEC,
*VM::VMObjectModel::LOCAL_FORWARDING_POINTER_SPEC,
]);
let common = CommonSpace::new(
SpaceOptions {
Expand Down
10 changes: 5 additions & 5 deletions src/policy/immortalspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ impl<VM: VMBinding> SFT for ImmortalSpace<VM> {
}
fn initialize_object_metadata(&self, object: ObjectReference, _alloc: bool) {
let old_value = load_metadata::<VM>(
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
object,
None,
Some(Ordering::SeqCst),
);
let new_value = (old_value & GC_MARK_BIT_MASK) | self.mark_state;
store_metadata::<VM>(
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
object,
new_value,
None,
Expand Down Expand Up @@ -106,7 +106,7 @@ impl<VM: VMBinding> ImmortalSpace<VM> {
side_metadata_specs: SideMetadataContext {
global: global_side_metadata_specs,
local: metadata::extract_side_metadata(&[
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
*VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
]),
},
},
Expand All @@ -133,7 +133,7 @@ impl<VM: VMBinding> ImmortalSpace<VM> {
fn test_and_mark(object: ObjectReference, value: usize) -> bool {
loop {
let old_value = load_metadata::<VM>(
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
object,
None,
Some(Ordering::SeqCst),
Expand All @@ -143,7 +143,7 @@ impl<VM: VMBinding> ImmortalSpace<VM> {
}

if compare_exchange_metadata::<VM>(
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
object,
old_value,
old_value ^ GC_MARK_BIT_MASK,
Expand Down
18 changes: 9 additions & 9 deletions src/policy/largeobjectspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<VM: VMBinding> SFT for LargeObjectSpace<VM> {
}
fn initialize_object_metadata(&self, object: ObjectReference, alloc: bool) {
let old_value = load_metadata::<VM>(
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
object,
None,
Some(Ordering::SeqCst),
Expand All @@ -62,7 +62,7 @@ impl<VM: VMBinding> SFT for LargeObjectSpace<VM> {
new_value |= NURSERY_BIT;
}
store_metadata::<VM>(
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
object,
new_value,
None,
Expand Down Expand Up @@ -118,7 +118,7 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
side_metadata_specs: SideMetadataContext {
global: global_side_metadata_specs,
local: metadata::extract_side_metadata(&[
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
*VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
]),
},
},
Expand Down Expand Up @@ -208,7 +208,7 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
MARK_BIT
};
let old_value = load_metadata::<VM>(
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
object,
None,
Some(Ordering::SeqCst),
Expand All @@ -218,7 +218,7 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
return false;
}
if compare_exchange_metadata::<VM>(
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
object,
old_value,
old_value & !LOS_BIT_MASK | value,
Expand All @@ -234,7 +234,7 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {

fn test_mark_bit(&self, object: ObjectReference, value: usize) -> bool {
load_metadata::<VM>(
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
object,
None,
Some(Ordering::SeqCst),
Expand All @@ -245,7 +245,7 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
/// Check if a given object is in nursery
fn is_in_nursery(&self, object: ObjectReference) -> bool {
load_metadata::<VM>(
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
object,
None,
Some(Ordering::Relaxed),
Expand All @@ -257,14 +257,14 @@ impl<VM: VMBinding> LargeObjectSpace<VM> {
fn clear_nursery(&self, object: ObjectReference) {
loop {
let old_val = load_metadata::<VM>(
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
object,
None,
Some(Ordering::Relaxed),
);
let new_val = old_val & !NURSERY_BIT;
if compare_exchange_metadata::<VM>(
VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
&VM::VMObjectModel::LOCAL_LOS_MARK_NURSERY_SPEC,
object,
old_val,
new_val,
Expand Down
2 changes: 1 addition & 1 deletion src/policy/mallocspace/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<VM: VMBinding> MallocSpace<VM> {
global: global_side_metadata_specs,
local: metadata::extract_side_metadata(&[
MetadataSpec::OnSide(ALLOC_SIDE_METADATA_SPEC),
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
*VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
]),
},
#[cfg(debug_assertions)]
Expand Down
12 changes: 6 additions & 6 deletions src/policy/mallocspace/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ pub fn is_alloced(object: ObjectReference) -> bool {
}

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

pub fn is_marked<VM: VMBinding>(object: ObjectReference) -> bool {
load_metadata::<VM>(
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
object,
None,
Some(Ordering::SeqCst),
Expand All @@ -87,7 +87,7 @@ pub fn is_marked<VM: VMBinding>(object: ObjectReference) -> bool {

pub fn set_alloc_bit(object: ObjectReference) {
side_metadata::store_atomic(
ALLOC_SIDE_METADATA_SPEC,
&ALLOC_SIDE_METADATA_SPEC,
object.to_address(),
1,
Ordering::SeqCst,
Expand All @@ -96,7 +96,7 @@ pub fn set_alloc_bit(object: ObjectReference) {

pub fn set_mark_bit<VM: VMBinding>(object: ObjectReference) {
store_metadata::<VM>(
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
object,
1,
None,
Expand All @@ -106,7 +106,7 @@ pub fn set_mark_bit<VM: VMBinding>(object: ObjectReference) {

pub fn unset_alloc_bit(object: ObjectReference) {
side_metadata::store_atomic(
ALLOC_SIDE_METADATA_SPEC,
&ALLOC_SIDE_METADATA_SPEC,
object.to_address(),
0,
Ordering::SeqCst,
Expand All @@ -115,7 +115,7 @@ pub fn unset_alloc_bit(object: ObjectReference) {

pub fn unset_mark_bit<VM: VMBinding>(object: ObjectReference) {
store_metadata::<VM>(
VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
&VM::VMObjectModel::LOCAL_MARK_BIT_SPEC,
object,
0,
None,
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/gc_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ impl<E: ProcessEdgesWork> GCWork<E::VM> for ProcessModBuf<E> {
if !self.modbuf.is_empty() {
for obj in &self.modbuf {
compare_exchange_metadata::<E::VM>(
self.meta,
&self.meta,
*obj,
0b0,
0b1,
Expand Down
15 changes: 7 additions & 8 deletions src/util/metadata/global.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::util::metadata::side_metadata;
use crate::vm::ObjectModel;
use atomic::Ordering;

use crate::util::metadata::side_metadata::SideMetadataSpec;
use crate::util::ObjectReference;
use crate::vm::ObjectModel;
use crate::vm::VMBinding;
use atomic::Ordering;

use super::header_metadata::HeaderMetadataSpec;

Expand Down Expand Up @@ -39,7 +38,7 @@ impl MetadataSpec {
///
#[inline(always)]
pub fn load_metadata<VM: VMBinding>(
metadata_spec: MetadataSpec,
metadata_spec: &MetadataSpec,
object: ObjectReference,
mask: Option<usize>,
atomic_ordering: Option<Ordering>,
Expand Down Expand Up @@ -70,7 +69,7 @@ pub fn load_metadata<VM: VMBinding>(
///
#[inline(always)]
pub fn store_metadata<VM: VMBinding>(
metadata_spec: MetadataSpec,
metadata_spec: &MetadataSpec,
object: ObjectReference,
val: usize,
mask: Option<usize>,
Expand Down Expand Up @@ -108,7 +107,7 @@ pub fn store_metadata<VM: VMBinding>(
///
#[inline(always)]
pub fn compare_exchange_metadata<VM: VMBinding>(
metadata_spec: MetadataSpec,
metadata_spec: &MetadataSpec,
object: ObjectReference,
old_val: usize,
new_val: usize,
Expand Down Expand Up @@ -150,7 +149,7 @@ pub fn compare_exchange_metadata<VM: VMBinding>(
///
#[inline(always)]
pub fn fetch_add_metadata<VM: VMBinding>(
metadata_spec: MetadataSpec,
metadata_spec: &MetadataSpec,
object: ObjectReference,
val: usize,
order: Ordering,
Expand Down Expand Up @@ -178,7 +177,7 @@ pub fn fetch_add_metadata<VM: VMBinding>(
///
#[inline(always)]
pub fn fetch_sub_metadata<VM: VMBinding>(
metadata_spec: MetadataSpec,
metadata_spec: &MetadataSpec,
object: ObjectReference,
val: usize,
order: Ordering,
Expand Down
10 changes: 5 additions & 5 deletions src/util/metadata/header_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl fmt::Debug for HeaderMetadataSpec {
/// This function provides a default implementation for the `load_metadata` method from the `ObjectModel` trait.
#[inline(always)]
pub fn load_metadata(
metadata_spec: HeaderMetadataSpec,
metadata_spec: &HeaderMetadataSpec,
object: ObjectReference,
optional_mask: Option<usize>,
atomic_ordering: Option<Ordering>,
Expand Down Expand Up @@ -151,7 +151,7 @@ pub fn load_metadata(
/// This function provides a default implementation for the `store_metadata` method from the `ObjectModel` trait.
#[inline(always)]
pub fn store_metadata(
metadata_spec: HeaderMetadataSpec,
metadata_spec: &HeaderMetadataSpec,
object: ObjectReference,
val: usize,
optional_mask: Option<usize>,
Expand Down Expand Up @@ -353,7 +353,7 @@ pub fn store_metadata(
/// This function provides a default implementation for the `compare_exchange_metadata` method from the `ObjectModel` trait.
#[inline(always)]
pub fn compare_exchange_metadata(
metadata_spec: HeaderMetadataSpec,
metadata_spec: &HeaderMetadataSpec,
object: ObjectReference,
old_metadata: usize,
new_metadata: usize,
Expand Down Expand Up @@ -510,7 +510,7 @@ pub fn compare_exchange_metadata(
/// This function provides a default implementation for the `fetch_add_metadata` method from the `ObjectModel` trait.
#[inline(always)]
pub fn fetch_add_metadata(
metadata_spec: HeaderMetadataSpec,
metadata_spec: &HeaderMetadataSpec,
object: ObjectReference,
val: usize,
order: Ordering,
Expand Down Expand Up @@ -602,7 +602,7 @@ pub fn fetch_add_metadata(
/// This function provides a default implementation for the `fetch_sub_metadata` method from the `ObjectModel` trait.
#[inline(always)]
pub fn fetch_sub_metadata(
metadata_spec: HeaderMetadataSpec,
metadata_spec: &HeaderMetadataSpec,
object: ObjectReference,
val: usize,
order: Ordering,
Expand Down
26 changes: 26 additions & 0 deletions src/util/metadata/side_metadata/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,36 @@ pub(super) const CHUNK_MASK: usize = (1 << LOG_BYTES_IN_CHUNK) - 1;
pub(super) const LOCAL_SIDE_METADATA_PER_CHUNK: usize =
BYTES_IN_CHUNK >> LOG_LOCAL_SIDE_METADATA_WORST_CASE_RATIO;

// The constants _VM_BASE_ADDRESS depends on the side metadata we use inside mmtk-core.
// If we add any new side metadata internal to mmtk-core, we need to update this accordingly.

// TODO: We should think if it is possible to update this when we create a new side metadata spec.
// One issue is that these need to be constants. Possibly we need to use macros or custom build scripts.

// --------------------------------------------------
//
// Global Metadata
//
// MMTk reserved Global side metadata offsets:
// [currently empty]
//
// --------------------------------------------------

/// The base address for the global side metadata space available to VM bindings, to be used for the per-object metadata.
/// VM bindings must use this to avoid overlap with core internal global side metadata.
pub const GLOBAL_SIDE_METADATA_VM_BASE_ADDRESS: Address = GLOBAL_SIDE_METADATA_BASE_ADDRESS;

// --------------------------------------------------
// PolicySpecific Metadata
//
// MMTk reserved PolicySpecific side metadata offsets:
//
// 1 - MarkSweep Alloc bit:
// - Offset `0x0` on 32-bits
// - Offset `LOCAL_SIDE_METADATA_BASE_ADDRESS` on 64-bits
//
// --------------------------------------------------

/// The base address for the local side metadata space available to VM bindings, to be used for the per-object metadata.
/// VM bindings must use this to avoid overlap with core internal local side metadata.
#[cfg(target_pointer_width = "64")]
Expand Down
Loading

0 comments on commit 1e79646

Please sign in to comment.