From eb57db271587324328747f663ccbdfe54ad2fb43 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Thu, 12 Oct 2023 15:32:16 +0800 Subject: [PATCH 1/2] Stop using the name "ForwardingWord" The name is likely inherited from JikesRVM. But since we changed its name, we should just use the module name "object_forwarding" directly. --- src/policy/immix/immixspace.rs | 20 ++++++++++---------- src/util/object_forwarding.rs | 3 +-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/policy/immix/immixspace.rs b/src/policy/immix/immixspace.rs index e699443800..65405a8ab2 100644 --- a/src/policy/immix/immixspace.rs +++ b/src/policy/immix/immixspace.rs @@ -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::{ @@ -91,8 +91,8 @@ impl SFT for ImmixSpace { return None; } - if ForwardingWord::is_forwarded::(object) { - Some(ForwardingWord::read_forwarding_pointer::(object)) + if object_forwarding::is_forwarded::(object) { + Some(object_forwarding::read_forwarding_pointer::(object)) } else { None } @@ -110,7 +110,7 @@ impl SFT for ImmixSpace { } // If the object is forwarded, it is live, too. - ForwardingWord::is_forwarded::(object) + object_forwarding::is_forwarded::(object) } #[cfg(feature = "object_pinning")] fn pin_object(&self, object: ObjectReference) -> bool { @@ -581,14 +581,14 @@ impl ImmixSpace { #[cfg(feature = "vo_bit")] vo_bit::helper::on_trace_object::(object); - let forwarding_status = ForwardingWord::attempt_to_forward::(object); - if ForwardingWord::state_is_forwarded_or_being_forwarded(forwarding_status) { + let forwarding_status = object_forwarding::attempt_to_forward::(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::(object, forwarding_status); + object_forwarding::spin_and_get_forwarded_object::(object, forwarding_status); #[cfg(debug_assertions)] { if new_object == object { @@ -611,7 +611,7 @@ impl ImmixSpace { } 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::(object); + object_forwarding::clear_forwarding_bits::(object); object } else { // We won the forwarding race; actually forward and copy the object if it is not pinned @@ -620,7 +620,7 @@ impl ImmixSpace { || (!nursery_collection && self.defrag.space_exhausted()) { self.attempt_mark(object, self.mark_state); - ForwardingWord::clear_forwarding_bits::(object); + object_forwarding::clear_forwarding_bits::(object); Block::containing::(object).set_state(BlockState::Marked); #[cfg(feature = "vo_bit")] @@ -634,7 +634,7 @@ impl ImmixSpace { // Clippy complains if the "vo_bit" feature is not enabled. #[allow(clippy::let_and_return)] let new_object = - ForwardingWord::forward_object::(object, semantics, copy_context); + object_forwarding::forward_object::(object, semantics, copy_context); #[cfg(feature = "vo_bit")] vo_bit::helper::on_object_forwarded::(new_object); diff --git a/src/util/object_forwarding.rs b/src/util/object_forwarding.rs index f7a4bea239..01b3fec447 100644 --- a/src/util/object_forwarding.rs +++ b/src/util/object_forwarding.rs @@ -1,6 +1,5 @@ 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; @@ -174,7 +173,7 @@ pub fn write_forwarding_pointer( get_forwarding_status::(object), ); - trace!("GCForwardingWord::write({:#?}, {:x})\n", object, new_object); + trace!("write_forwarding_pointer({}, {})", object, new_object); VM::VMObjectModel::LOCAL_FORWARDING_POINTER_SPEC.store_atomic::( object, new_object.to_raw_address().as_usize(), From a56d128fb259eb6d6b601ecd5a9185bc6fa6f2db Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Thu, 12 Oct 2023 17:17:22 +0800 Subject: [PATCH 2/2] WIP: Supporting four-state forwarding bits --- src/util/object_forwarding.rs | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/util/object_forwarding.rs b/src/util/object_forwarding.rs index 01b3fec447..d41cdd4dc5 100644 --- a/src/util/object_forwarding.rs +++ b/src/util/object_forwarding.rs @@ -5,6 +5,52 @@ 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;