Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / gc / frame.h
CommitLineData
7f918cf1
CE
1/* Copyright (C) 1999-2006 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 * The "... reserved bytes ..." of a stack object constitute a linear
13 * sequence of frames. For the purposes of garbage collection, we
14 * must be able to recover the size and offsets of live heap-pointers
15 * for each frame. This data is declared as follows:
16 *
17 * GC_frameLayout *frameLayouts;
18 *
19 * The frameLayouts pointer is initialized to point to a static array
20 * of frame layouts that is emitted for each compiled program. The
21 * kind field identifies whether or not the frame is for a C call.
22 * (Note: The ML stack is distinct from the system stack. A C call
23 * executes on the system stack. The frame left on the ML stack is
24 * just a marker.) The size field indicates the size of the frame,
25 * including space for the return address. The offsets field points
26 * to an array (the zeroeth element recording the size of the array)
27 * whose elements record byte offsets from the bottom of the frame at
28 * which live heap pointers are located.
29 */
30typedef uint16_t *GC_frameOffsets;
31
32typedef enum {
33 C_FRAME,
34 ML_FRAME
35} GC_frameKind;
36
37typedef struct GC_frameLayout {
38 GC_frameKind kind;
39 GC_frameOffsets offsets;
40 uint16_t size;
41} *GC_frameLayout;
42typedef uint32_t GC_frameIndex;
43#define PRIFI PRIu32
44#define FMTFI "%"PRIFI
45
46typedef uintptr_t GC_returnAddress;
47#define GC_RETURNADDRESS_SIZE sizeof(GC_returnAddress)
48#define FMTRA "0x%016"PRIxPTR
49
50#endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
51
52#if (defined (MLTON_GC_INTERNAL_FUNCS))
53
54static inline GC_frameIndex getFrameIndexFromReturnAddress (GC_state s, GC_returnAddress ra);
55static inline GC_frameLayout getFrameLayoutFromFrameIndex (GC_state s, GC_frameIndex findex);
56static inline GC_frameLayout getFrameLayoutFromReturnAddress (GC_state s, GC_returnAddress ra);
57
58#endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */