Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / gc / weak.h
CommitLineData
7f918cf1
CE
1/* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 * Copyright (C) 1997-2000 NEC Research Institute.
4 *
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
7 */
8
9#if (defined (MLTON_GC_INTERNAL_TYPES))
10
11/*
12 * Weak objects have the following layout:
13 *
14 * header ::
15 * padding ::
16 * link (native-pointer) ::
17 * objptr (object-pointer)
18 *
19 * The object type indexed by the header determines whether the weak
20 * is valid or not. If the type has numObjptrs == 1, then the weak
21 * pointer is valid. Otherwise, the type has numObjptrs == 0 and the
22 * weak pointer is not valid.
23 *
24 * There may be zero or more bytes of padding for alignment purposes.
25 *
26 * The link native-pointer is used to chain the live weaks together
27 * during a copying/mark-compact gc and is otherwise unused.
28 *
29 * The final component is the weak object-pointer.
30 *
31 * Note that the order of the fields is important. The non-objptr
32 * field must be first, because a weak object is sometimes treated as
33 * a normal object.
34 */
35typedef struct GC_weak {
36 struct GC_weak *link;
37 objptr objptr;
38} __attribute__ ((packed)) *GC_weak;
39
40COMPILE_TIME_ASSERT(GC_weak__packed,
41 sizeof(struct GC_weak) ==
42 sizeof(struct GC_weak*)
43 + sizeof(objptr));
44
45#endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
46
47#if (defined (MLTON_GC_INTERNAL_FUNCS))
48
49static inline size_t sizeofWeak (GC_state s);
50static inline size_t offsetofWeak (GC_state s);
51
52#endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */
53
54#if (defined (MLTON_GC_INTERNAL_BASIS))
55
56PRIVATE uint32_t GC_weakCanGet (GC_state s, pointer p);
57PRIVATE pointer GC_weakGet (GC_state s, pointer p);
58PRIVATE pointer GC_weakNew (GC_state s, GC_header header, pointer p);
59
60#endif /* (defined (MLTON_GC_INTERNAL_BASIS)) */