Object header is now 32-bit on 32-bit targets

This commit is contained in:
playX18 2025-02-15 19:51:12 +07:00
parent 228513a638
commit 5518088601
4 changed files with 34 additions and 26 deletions

View file

@ -462,21 +462,21 @@ static CONSERVATIVE_METADATA: GCMetadata<BDWGC> = GCMetadata {
}), }),
}; };
impl FromBitfield<u64> for BDWGCMetadata { impl FromBitfield<usize> for BDWGCMetadata {
fn from_bitfield(value: u64) -> Self { fn from_bitfield(value: usize) -> Self {
Self { Self {
meta: value as usize, meta: value as usize,
} }
} }
fn from_i64(value: i64) -> Self { fn from_i64(value: i64) -> Self {
Self::from_bitfield(value as u64) Self::from_bitfield(value as usize)
} }
} }
impl ToBitfield<u64> for BDWGCMetadata { impl ToBitfield<usize> for BDWGCMetadata {
fn to_bitfield(self) -> u64 { fn to_bitfield(self) -> usize {
self.meta as u64 self.meta as usize
} }
fn one() -> Self { fn one() -> Self {

View file

@ -1 +1,9 @@
fn main() {} use easy_bitfield::BitFieldTrait;
use vmkit::object_model::header::{HashState, HashStateField};
fn main() {
let encoded = HashStateField::encode(HashState::HashedAndMoved);
println!("{:x}", encoded);
println!("{}", HashStateField::NEXT_BIT);
println!("{:?}", HashStateField::decode(encoded));
}

View file

@ -11,10 +11,10 @@ pub const OBJECT_REF_OFFSET: isize = 8;
pub const OBJECT_HEADER_OFFSET: isize = -OBJECT_REF_OFFSET; pub const OBJECT_HEADER_OFFSET: isize = -OBJECT_REF_OFFSET;
pub const HASHCODE_OFFSET: isize = -(OBJECT_REF_OFFSET + size_of::<usize>() as isize); pub const HASHCODE_OFFSET: isize = -(OBJECT_REF_OFFSET + size_of::<usize>() as isize);
pub const METADATA_BIT_LIMIT: usize = if ADDRESS_BASED_HASHING { 60 } else { 63 }; pub const METADATA_BIT_LIMIT: usize = if ADDRESS_BASED_HASHING { usize::BITS as usize - 2 } else { usize::BITS as usize };
pub type MetadataField = BitField<u64, usize, 0, METADATA_BIT_LIMIT, false>; pub type MetadataField = BitField<usize, usize, 0, METADATA_BIT_LIMIT, false>;
pub type HashStateField = BitField<u64, HashState, { MetadataField::NEXT_BIT }, 2, false>; pub type HashStateField = BitField<usize, HashState, { MetadataField::NEXT_BIT }, 2, false>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HashState { pub enum HashState {
@ -23,8 +23,8 @@ pub enum HashState {
HashedAndMoved, HashedAndMoved,
} }
impl FromBitfield<u64> for HashState { impl FromBitfield<usize> for HashState {
fn from_bitfield(value: u64) -> Self { fn from_bitfield(value: usize) -> Self {
match value { match value {
0 => Self::Unhashed, 0 => Self::Unhashed,
1 => Self::Hashed, 1 => Self::Hashed,
@ -43,8 +43,8 @@ impl FromBitfield<u64> for HashState {
} }
} }
impl ToBitfield<u64> for HashState { impl ToBitfield<usize> for HashState {
fn to_bitfield(self) -> u64 { fn to_bitfield(self) -> usize {
match self { match self {
Self::Unhashed => 0, Self::Unhashed => 0,
Self::Hashed => 1, Self::Hashed => 1,
@ -62,7 +62,7 @@ impl ToBitfield<u64> for HashState {
} }
pub struct HeapObjectHeader<VM: VirtualMachine> { pub struct HeapObjectHeader<VM: VirtualMachine> {
pub metadata: AtomicBitfieldContainer<u64>, pub metadata: AtomicBitfieldContainer<usize>,
pub marker: PhantomData<VM>, pub marker: PhantomData<VM>,
} }

View file

@ -32,7 +32,7 @@ pub enum TraceCallback<VM: VirtualMachine> {
/// ///
/// Types which implement `Metadata` must also be convertible to and from bitfields. /// Types which implement `Metadata` must also be convertible to and from bitfields.
pub trait Metadata<VM: VirtualMachine>: pub trait Metadata<VM: VirtualMachine>:
ToBitfield<u64> + FromBitfield<u64> + ToSlot<VM::Slot> ToBitfield<usize> + FromBitfield<usize> + ToSlot<VM::Slot>
{ {
/// Size of the metadata in bits. Must be `<= 62`. /// Size of the metadata in bits. Must be `<= 62`.
const METADATA_BIT_SIZE: usize; const METADATA_BIT_SIZE: usize;
@ -82,16 +82,16 @@ macro_rules! make_uncooperative_metadata {
unreachable!() unreachable!()
} }
} }
impl<VM: $crate::VirtualMachine> $crate::object_model::metadata::ToBitfield<u64> for $name { impl<VM: $crate::VirtualMachine> $crate::object_model::metadata::ToBitfield<usize> for $name {
fn to_bitfield(self) -> u64 { fn to_bitfield(self) -> usize {
self.wsize as u64 self.wsize as usize
} }
} }
impl<VM: $crate::VirtualMachine> $crate::object_model::metadata::FromBitfield<u64> impl<VM: $crate::VirtualMachine> $crate::object_model::metadata::FromBitfield<usize>
for $name for $name
{ {
fn from_bitfield(value: u64) -> Self { fn from_bitfield(value: usize) -> Self {
Self { Self {
wsize: value as usize, wsize: value as usize,
} }
@ -100,9 +100,9 @@ macro_rules! make_uncooperative_metadata {
}; };
} }
impl<VM: VirtualMachine> ToBitfield<u64> for &'static GCMetadata<VM> { impl<VM: VirtualMachine> ToBitfield<usize> for &'static GCMetadata<VM> {
fn to_bitfield(self) -> u64 { fn to_bitfield(self) -> usize {
let res = self as *const GCMetadata<VM> as usize as u64; let res = self as *const GCMetadata<VM> as usize as usize;
res res
} }
@ -115,8 +115,8 @@ impl<VM: VirtualMachine> ToBitfield<u64> for &'static GCMetadata<VM> {
} }
} }
impl<VM: VirtualMachine> FromBitfield<u64> for &'static GCMetadata<VM> { impl<VM: VirtualMachine> FromBitfield<usize> for &'static GCMetadata<VM> {
fn from_bitfield(value: u64) -> Self { fn from_bitfield(value: usize) -> Self {
unsafe { &*(value as usize as *const GCMetadata<VM>) } unsafe { &*(value as usize as *const GCMetadata<VM>) }
} }