mmtk/util/metadata/
log_bit.rs1use crate::util::constants::LOG_BITS_IN_BYTE;
2use crate::util::Address;
3use crate::util::ObjectReference;
4use crate::vm::ObjectModel;
5use crate::vm::VMBinding;
6use crate::vm::VMGlobalFieldUnlogBitSpec;
7use crate::vm::VMGlobalLogBitSpec;
8use std::sync::atomic::Ordering;
9
10use super::MetadataSpec;
11
12pub const UNLOGGED_VALUE: u8 = 0b1;
15
16pub const LOGGED_VALUE: u8 = 0b0;
19
20impl VMGlobalLogBitSpec {
21 pub fn clear<VM: VMBinding>(&self, object: ObjectReference, order: Ordering) {
23 self.store_atomic::<VM, u8>(object, LOGGED_VALUE, None, order)
24 }
25
26 pub fn bulk_mark_as_logged(&self, start: Address, size: usize) {
28 if let MetadataSpec::OnSide(side) = self.as_spec() {
29 side.bzero_metadata(start, size);
30 }
31 }
32
33 pub fn mark_as_unlogged<VM: VMBinding>(&self, object: ObjectReference, order: Ordering) {
35 self.store_atomic::<VM, u8>(object, UNLOGGED_VALUE, None, order)
36 }
37
38 pub fn mark_byte_as_unlogged<VM: VMBinding>(&self, object: ObjectReference, order: Ordering) {
43 match self.as_spec() {
44 MetadataSpec::InHeader(_) => self.mark_as_unlogged::<VM>(object, order),
46 MetadataSpec::OnSide(spec) => unsafe {
50 spec.set_raw_byte_atomic(object.to_raw_address(), order)
51 },
52 }
53 }
54
55 pub fn is_unlogged<VM: VMBinding>(&self, object: ObjectReference, order: Ordering) -> bool {
57 self.load_atomic::<VM, u8>(object, None, order) == UNLOGGED_VALUE
58 }
59}
60
61impl VMGlobalFieldUnlogBitSpec {
62 pub(crate) const fn log_heap_bytes_per_unlog_byte(&self) -> usize {
64 let spec = self.as_spec().extract_side_spec();
65 spec.log_bytes_in_region + LOG_BITS_IN_BYTE as usize - spec.log_num_of_bits
66 }
67
68 pub(crate) const fn heap_bytes_per_unlog_byte(&self) -> usize {
70 1 << self.log_heap_bytes_per_unlog_byte()
71 }
72}
73
74impl MetadataSpec {
75 pub fn mark_as_unlogged<VM: VMBinding>(&self, object: ObjectReference, order: Ordering) {
77 self.store_atomic::<VM, u8>(object, UNLOGGED_VALUE, None, order)
78 }
79}
80
81#[derive(Clone, Copy, PartialEq, Eq)]
83pub(crate) enum UnlogBitsOperation {
84 NoOp,
86 BulkSet,
88 BulkClear,
90}
91
92impl UnlogBitsOperation {
93 pub(crate) fn execute<VM: VMBinding>(&self, start: Address, size: usize) {
95 if let MetadataSpec::OnSide(ref unlog_bits) = *VM::VMObjectModel::GLOBAL_LOG_BIT_SPEC {
96 match self {
97 UnlogBitsOperation::NoOp => {}
98 UnlogBitsOperation::BulkSet => {
99 unlog_bits.bset_metadata(start, size);
100 }
101 UnlogBitsOperation::BulkClear => {
102 unlog_bits.bzero_metadata(start, size);
103 }
104 }
105 }
106 }
107}