Skip to main content

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
20pub use super::DRC_HEADER_IN_OVER_APPROX_LIST_BIT as HEADER_IN_OVER_APPROX_LIST_BIT;
21pub use super::DRC_HEADER_MARK_BIT as HEADER_MARK_BIT;
22pub use super::DRC_MIN_OVER_APPROX_STACK_ROOTS_GC_THRESHOLD as MIN_OVER_APPROX_STACK_ROOTS_GC_THRESHOLD;
23
24/// The layout of Wasm GC objects in the deferred reference-counting collector.
25#[derive(Default)]
26pub struct DrcTypeLayouts;
27
28impl GcTypeLayouts for DrcTypeLayouts {
29    fn array_length_field_offset(&self) -> u32 {
30        ARRAY_LENGTH_OFFSET
31    }
32
33    fn exception_tag_instance_offset(&self) -> u32 {
34        EXCEPTION_TAG_INSTANCE_OFFSET
35    }
36
37    fn exception_tag_defined_offset(&self) -> u32 {
38        EXCEPTION_TAG_DEFINED_OFFSET
39    }
40
41    fn array_layout(&self, ty: &WasmArrayType) -> GcArrayLayout {
42        common_array_layout(ty, HEADER_SIZE, HEADER_ALIGN, ARRAY_LENGTH_OFFSET)
43    }
44
45    fn struct_layout(&self, ty: &WasmStructType) -> Result<GcStructLayout, OutOfMemory> {
46        common_struct_layout(ty, HEADER_SIZE, HEADER_ALIGN)
47    }
48
49    fn exn_layout(&self, ty: &WasmExnType) -> Result<GcStructLayout, OutOfMemory> {
50        common_exn_layout(ty, HEADER_SIZE, HEADER_ALIGN)
51    }
52}