Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / runtime / gc / stack.h
CommitLineData
7f918cf1
CE
1/* Copyright (C) 2012,2016 Matthew Fluet.
2 * Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 * Copyright (C) 1997-2000 NEC Research Institute.
5 *
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
8 */
9
10#if (defined (MLTON_GC_INTERNAL_TYPES))
11
12/*
13 * Stack objects have the following layout:
14 *
15 * header ::
16 * markTop (native-pointer) ::
17 * markIndex (word32) ::
18 * reserved ::
19 * used ::
20 * ... reserved bytes ...
21 *
22 * The markTop and markIndex are used by the mark-compact GC. The
23 * reserved size gives the number of bytes for the stack (before the
24 * next ML object). The used size gives the number of bytes currently
25 * used by the stack. The sequence of reserved bytes correspond to ML
26 * stack frames, which will be discussed in more detail in "frame.h".
27*/
28typedef struct GC_stack {
29 /* markTop and markIndex are only used during marking. They record
30 * the current pointer in the stack that is being followed. markTop
31 * points to the top of the stack frame containing the pointer and
32 * markIndex is the index in that frame's frameOffsets of the pointer
33 * slot. So, when the GC pointer reversal gets back to the stack,
34 * it can continue with the next pointer (either in the current
35 * frame or the next frame).
36 */
37 pointer markTop;
38 uint32_t markIndex;
39 /* reserved is the number of bytes reserved for stack,
40 * i.e. its maximum size.
41 */
42 size_t reserved;
43 /* used is the number of bytes used by the stack.
44 * Stacks with used == reserved are continuations.
45 */
46 size_t used;
47 /* The next address is the bottom of the stack, and the following
48 * reserved bytes hold space for the stack.
49 */
50} *GC_stack;
51
52#define GC_STACK_METADATA_SIZE (GC_HEADER_SIZE)
53
54#endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
55
56#if (defined (MLTON_GC_INTERNAL_FUNCS))
57
58static void displayStack (GC_state s, GC_stack stack, FILE *stream);
59
60#if ASSERT
61static inline bool isStackEmpty (GC_stack stack);
62static inline bool isStackReservedAligned (GC_state s, size_t reserved);
63#endif
64
65static inline size_t sizeofStackSlop (GC_state s);
66
67static inline pointer getStackBottom (GC_state s, GC_stack stack);
68static inline pointer getStackTop (GC_state s, GC_stack stack);
69static inline pointer getStackLimitPlusSlop (GC_state s, GC_stack stack);
70static inline pointer getStackLimit (GC_state s, GC_stack stack);
71static inline GC_frameIndex getCachedStackTopFrameIndex (GC_state s);
72static inline GC_frameIndex getStackTopFrameIndex (GC_state s, GC_stack stack);
73static inline GC_frameLayout getStackTopFrameLayout (GC_state s, GC_stack stack);
74static inline uint16_t getStackTopFrameSize (GC_state s, GC_stack stack);
75
76static inline size_t alignStackReserved (GC_state s, size_t reserved);
77static inline size_t sizeofStackWithMetaData (GC_state s, size_t reserved);
78static inline size_t sizeofStackInitialReserved (GC_state s);
79static inline size_t sizeofStackMinimumReserved (GC_state s, GC_stack stack);
80static inline size_t sizeofStackGrowReserved (GC_state s, GC_stack stack);
81static inline size_t sizeofStackShrinkReserved (GC_state s, GC_stack stack, bool current);
82
83static inline void copyStack (GC_state s, GC_stack from, GC_stack to);
84
85#endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */