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.
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
10 #if (defined (MLTON_GC_INTERNAL_TYPES))
13 * Stack objects have the following layout:
16 * markTop (native-pointer) ::
17 * markIndex (word32) ::
20 * ... reserved bytes ...
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".
28 typedef 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).
39 /* reserved is the number of bytes reserved for stack,
40 * i.e. its maximum size.
43 /* used is the number of bytes used by the stack.
44 * Stacks with used == reserved are continuations.
47 /* The next address is the bottom of the stack, and the following
48 * reserved bytes hold space for the stack.
52 #define GC_STACK_METADATA_SIZE (GC_HEADER_SIZE)
54 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
56 #if (defined (MLTON_GC_INTERNAL_FUNCS))
58 static void displayStack (GC_state s
, GC_stack stack
, FILE *stream
);
61 static inline bool isStackEmpty (GC_stack stack
);
62 static inline bool isStackReservedAligned (GC_state s
, size_t reserved
);
65 static inline size_t sizeofStackSlop (GC_state s
);
67 static inline pointer
getStackBottom (GC_state s
, GC_stack stack
);
68 static inline pointer
getStackTop (GC_state s
, GC_stack stack
);
69 static inline pointer
getStackLimitPlusSlop (GC_state s
, GC_stack stack
);
70 static inline pointer
getStackLimit (GC_state s
, GC_stack stack
);
71 static inline GC_frameIndex
getCachedStackTopFrameIndex (GC_state s
);
72 static inline GC_frameIndex
getStackTopFrameIndex (GC_state s
, GC_stack stack
);
73 static inline GC_frameLayout
getStackTopFrameLayout (GC_state s
, GC_stack stack
);
74 static inline uint16_t getStackTopFrameSize (GC_state s
, GC_stack stack
);
76 static inline size_t alignStackReserved (GC_state s
, size_t reserved
);
77 static inline size_t sizeofStackWithMetaData (GC_state s
, size_t reserved
);
78 static inline size_t sizeofStackInitialReserved (GC_state s
);
79 static inline size_t sizeofStackMinimumReserved (GC_state s
, GC_stack stack
);
80 static inline size_t sizeofStackGrowReserved (GC_state s
, GC_stack stack
);
81 static inline size_t sizeofStackShrinkReserved (GC_state s
, GC_stack stack
, bool current
);
83 static inline void copyStack (GC_state s
, GC_stack from
, GC_stack to
);
85 #endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */