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 offset of the tag-instance-index field in an exception header.
15pub const EXCEPTION_TAG_INSTANCE_OFFSET: u32 = HEADER_SIZE;
16
17/// The offset of the tag-defined-index field in an exception header.
18pub const EXCEPTION_TAG_DEFINED_OFFSET: u32 = HEADER_SIZE + 4;
19
20/// The bit within a `VMDrcHeader`'s reserved bits that is the mark
21/// bit. Collectively, this bit in all the heap's objects' headers implements
22/// the precise-stack-roots set.
23pub const HEADER_MARK_BIT: u32 = 1 << 0;
24
25/// The bit within a `VMDrcHeader`'s reserved bits that is the
26/// in-the-over-approximated-stack-roots list bit.
27pub const HEADER_IN_OVER_APPROX_LIST_BIT: u32 = 1 << 1;
28
29/// The layout of Wasm GC objects in the deferred reference-counting collector.
30#[derive(Default)]
31pub struct DrcTypeLayouts;
32
33impl GcTypeLayouts for DrcTypeLayouts {
34    fn array_length_field_offset(&self) -> u32 {
35        ARRAY_LENGTH_OFFSET
36    }
37
38    fn exception_tag_instance_offset(&self) -> u32 {
39        EXCEPTION_TAG_INSTANCE_OFFSET
40    }
41
42    fn exception_tag_defined_offset(&self) -> u32 {
43        EXCEPTION_TAG_DEFINED_OFFSET
44    }
45
46    fn array_layout(&self, ty: &WasmArrayType) -> GcArrayLayout {
47        common_array_layout(ty, HEADER_SIZE, HEADER_ALIGN, ARRAY_LENGTH_OFFSET)
48    }
49
50    fn struct_layout(&self, ty: &WasmStructType) -> GcStructLayout {
51        common_struct_layout(ty, HEADER_SIZE, HEADER_ALIGN)
52    }
53
54    fn exn_layout(&self, ty: &WasmExnType) -> GcStructLayout {
55        common_exn_layout(ty, HEADER_SIZE, HEADER_ALIGN)
56    }
57}