mmtk/util/metadata/
pin_bit.rs

1use crate::util::ObjectReference;
2use crate::vm::VMBinding;
3use crate::vm::VMLocalPinningBitSpec;
4use std::sync::atomic::Ordering;
5
6impl VMLocalPinningBitSpec {
7    /// Pin an object by setting the pinning bit to 1.
8    /// Return true if the object is pinned in this operation.
9    pub fn pin_object<VM: VMBinding>(&self, object: ObjectReference) -> bool {
10        let res = self.compare_exchange_metadata::<VM, u8>(
11            object,
12            0,
13            1,
14            None,
15            Ordering::SeqCst,
16            Ordering::SeqCst,
17        );
18
19        res.is_ok()
20    }
21
22    /// Unpin an object by clearing the pinning bit to 0.
23    /// Return true if the object is unpinned in this operation.
24    pub fn unpin_object<VM: VMBinding>(&self, object: ObjectReference) -> bool {
25        let res = self.compare_exchange_metadata::<VM, u8>(
26            object,
27            1,
28            0,
29            None,
30            Ordering::SeqCst,
31            Ordering::SeqCst,
32        );
33
34        res.is_ok()
35    }
36
37    /// Check if an object is pinned.
38    pub fn is_object_pinned<VM: VMBinding>(&self, object: ObjectReference) -> bool {
39        if unsafe { self.load::<VM, u8>(object, None) == 1 } {
40            return true;
41        }
42
43        false
44    }
45}