wasmtime_environ/gc/
drc.rs

1//! Layout of Wasm GC objects in the deferred reference-counting collector.
2
3use super::*;
4
5/// The size of the `VMDrcHeader` header for GC objects.
6pub const HEADER_SIZE: u32 = 24;
7
8/// The align of the `VMDrcHeader` header for GC objects.
9pub const HEADER_ALIGN: u32 = 8;
10
11/// The offset of the length field in a `VMDrcArrayHeader`.
12pub const ARRAY_LENGTH_OFFSET: u32 = HEADER_SIZE;
13
14/// The bit within a `VMDrcHeader`'s reserved bits that is the mark
15/// bit. Collectively, this bit in all the heap's objects' headers implements
16/// the precise-stack-roots set.
17pub const HEADER_MARK_BIT: u32 = 1 << 0;
18
19/// The bit within a `VMDrcHeader`'s reserved bits that is the
20/// in-the-over-approximated-stack-roots list bit.
21pub const HEADER_IN_OVER_APPROX_LIST_BIT: u32 = 1 << 1;
22
23/// The layout of Wasm GC objects in the deferred reference-counting collector.
24#[derive(Default)]
25pub struct DrcTypeLayouts;
26
27impl GcTypeLayouts for DrcTypeLayouts {
28    fn array_length_field_offset(&self) -> u32 {
29        ARRAY_LENGTH_OFFSET
30    }
31
32    fn array_layout(&self, ty: &WasmArrayType) -> GcArrayLayout {
33        common_array_layout(ty, HEADER_SIZE, HEADER_ALIGN, ARRAY_LENGTH_OFFSET)
34    }
35
36    fn struct_layout(&self, ty: &WasmStructType) -> GcStructLayout {
37        common_struct_layout(ty, HEADER_SIZE, HEADER_ALIGN)
38    }
39}