Skip to content

Feature/four state forwarding bits #977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/policy/immix/immixspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::util::metadata::side_metadata::SideMetadataSpec;
#[cfg(feature = "vo_bit")]
use crate::util::metadata::vo_bit;
use crate::util::metadata::{self, MetadataSpec};
use crate::util::object_forwarding as ForwardingWord;
use crate::util::object_forwarding;
use crate::util::{Address, ObjectReference};
use crate::vm::*;
use crate::{
Expand Down Expand Up @@ -91,8 +91,8 @@ impl<VM: VMBinding> SFT for ImmixSpace<VM> {
return None;
}

if ForwardingWord::is_forwarded::<VM>(object) {
Some(ForwardingWord::read_forwarding_pointer::<VM>(object))
if object_forwarding::is_forwarded::<VM>(object) {
Some(object_forwarding::read_forwarding_pointer::<VM>(object))
} else {
None
}
Expand All @@ -110,7 +110,7 @@ impl<VM: VMBinding> SFT for ImmixSpace<VM> {
}

// If the object is forwarded, it is live, too.
ForwardingWord::is_forwarded::<VM>(object)
object_forwarding::is_forwarded::<VM>(object)
}
#[cfg(feature = "object_pinning")]
fn pin_object(&self, object: ObjectReference) -> bool {
Expand Down Expand Up @@ -581,14 +581,14 @@ impl<VM: VMBinding> ImmixSpace<VM> {
#[cfg(feature = "vo_bit")]
vo_bit::helper::on_trace_object::<VM>(object);

let forwarding_status = ForwardingWord::attempt_to_forward::<VM>(object);
if ForwardingWord::state_is_forwarded_or_being_forwarded(forwarding_status) {
let forwarding_status = object_forwarding::attempt_to_forward::<VM>(object);
if object_forwarding::state_is_forwarded_or_being_forwarded(forwarding_status) {
// We lost the forwarding race as some other thread has set the forwarding word; wait
// until the object has been forwarded by the winner. Note that the object may not
// necessarily get forwarded since Immix opportunistically moves objects.
#[allow(clippy::let_and_return)]
let new_object =
ForwardingWord::spin_and_get_forwarded_object::<VM>(object, forwarding_status);
object_forwarding::spin_and_get_forwarded_object::<VM>(object, forwarding_status);
#[cfg(debug_assertions)]
{
if new_object == object {
Expand All @@ -611,7 +611,7 @@ impl<VM: VMBinding> ImmixSpace<VM> {
} else if self.is_marked(object) {
// We won the forwarding race but the object is already marked so we clear the
// forwarding status and return the unmoved object
ForwardingWord::clear_forwarding_bits::<VM>(object);
object_forwarding::clear_forwarding_bits::<VM>(object);
object
} else {
// We won the forwarding race; actually forward and copy the object if it is not pinned
Expand All @@ -620,7 +620,7 @@ impl<VM: VMBinding> ImmixSpace<VM> {
|| (!nursery_collection && self.defrag.space_exhausted())
{
self.attempt_mark(object, self.mark_state);
ForwardingWord::clear_forwarding_bits::<VM>(object);
object_forwarding::clear_forwarding_bits::<VM>(object);
Block::containing::<VM>(object).set_state(BlockState::Marked);

#[cfg(feature = "vo_bit")]
Expand All @@ -634,7 +634,7 @@ impl<VM: VMBinding> ImmixSpace<VM> {
// Clippy complains if the "vo_bit" feature is not enabled.
#[allow(clippy::let_and_return)]
let new_object =
ForwardingWord::forward_object::<VM>(object, semantics, copy_context);
object_forwarding::forward_object::<VM>(object, semantics, copy_context);

#[cfg(feature = "vo_bit")]
vo_bit::helper::on_object_forwarded::<VM>(new_object);
Expand Down
49 changes: 47 additions & 2 deletions src/util/object_forwarding.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,56 @@
use crate::util::copy::*;
use crate::util::metadata::MetadataSpec;
/// https://github.com/JikesRVM/JikesRVM/blob/master/MMTk/src/org/mmtk/utility/ForwardingWord.java
use crate::util::{constants, ObjectReference};
use crate::vm::ObjectModel;
use crate::vm::VMBinding;
use std::sync::atomic::Ordering;

#[derive(Clone, Copy, PartialEq, Eq)]
enum ForwardingState {
NotTriggered,
BeingForwarded,
Forwarded,
MarkedWontForward,
}

impl ForwardingState {
pub fn encode(&self, mark_state: bool) -> u8 {
match mark_state {
false => match self {
ForwardingState::NotTriggered => 0b00,
ForwardingState::BeingForwarded => 0b10,
ForwardingState::Forwarded => 0b11,
ForwardingState::MarkedWontForward => 0b01,
},
true => match self {
ForwardingState::NotTriggered => 0b01,
ForwardingState::BeingForwarded => 0b10,
ForwardingState::Forwarded => 0b11,
ForwardingState::MarkedWontForward => 0b00,
},
}
}

pub fn decode(value: u8, mark_state: bool) -> Self {
match mark_state {
false => match value {
0b00 => ForwardingState::NotTriggered,
0b10 => ForwardingState::BeingForwarded,
0b11 => ForwardingState::Forwarded,
0b01 => ForwardingState::MarkedWontForward,
_ => unreachable!(),
},
true => match value {
0b01 => ForwardingState::NotTriggered,
0b10 => ForwardingState::BeingForwarded,
0b11 => ForwardingState::Forwarded,
0b00 => ForwardingState::MarkedWontForward,
_ => unreachable!(),
},
}
}
}

const FORWARDING_NOT_TRIGGERED_YET: u8 = 0b00;
const BEING_FORWARDED: u8 = 0b10;
const FORWARDED: u8 = 0b11;
Expand Down Expand Up @@ -174,7 +219,7 @@ pub fn write_forwarding_pointer<VM: VMBinding>(
get_forwarding_status::<VM>(object),
);

trace!("GCForwardingWord::write({:#?}, {:x})\n", object, new_object);
trace!("write_forwarding_pointer({}, {})", object, new_object);
VM::VMObjectModel::LOCAL_FORWARDING_POINTER_SPEC.store_atomic::<VM, usize>(
object,
new_object.to_raw_address().as_usize(),
Expand Down