Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / gc / generational.h
CommitLineData
7f918cf1
CE
1/* Copyright (C) 2009,2012 Matthew Fluet.
2 * Copyright (C) 1999-2008 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/* must agree w/ cardSizeLog2 in ssa-to-rssa.fun */
13#define CARD_SIZE_LOG2 8
14#define CARD_SIZE TWOPOWER(CARD_SIZE_LOG2)
15
16typedef uint8_t GC_cardMapElem;
17typedef uint8_t GC_crossMapElem;
18
19typedef GC_cardMapElem *GC_cardMap;
20typedef GC_crossMapElem *GC_crossMap;
21
22typedef size_t GC_cardMapIndex;
23typedef size_t GC_crossMapIndex;
24#define CARD_MAP_ELEM_SIZE sizeof(GC_cardMapElem)
25#define CROSS_MAP_ELEM_SIZE sizeof(GC_crossMapElem)
26#define CROSS_MAP_EMPTY ((GC_crossMapElem)255)
27#define CROSS_MAP_OFFSET_SCALE 4
28#define FMTCME "%"PRIu8
29
30struct GC_generationalMaps {
31 /* cardMap is an array with cardinality equal to the size of the
32 * heap divided by card size. Each element in the array is
33 * interpreted as a boolean; true indicates that some mutable field
34 * of some object in the corresponding card in the heap has been
35 * written since the last minor GC; hence, the corresponding card
36 * must be traced at the next minor GC.
37 */
38 GC_cardMap cardMap;
39 GC_cardMap cardMapAbsolute;
40 GC_cardMapIndex cardMapLength;
41 /* crossMap is an array with cardinality equal to the size of the
42 * heap divided by card size. Each element in the array is
43 * interpreted as a byte offset (scaled by CARD_MAP_OFFSET_SCALE);
44 * the offset indicates the start of the last object in the
45 * corresponding card from the start of the card.
46 */
47 GC_crossMap crossMap;
48 GC_crossMapIndex crossMapLength;
49 /* crossMapValidSize the size of the prefix of the old generation
50 * for which the crossMap is valid.
51 */
52 size_t crossMapValidSize;
53};
54
55#endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
56
57#if (defined (MLTON_GC_INTERNAL_FUNCS))
58
59static void displayGenerationalMaps (GC_state s,
60 struct GC_generationalMaps *generational,
61 FILE *stream);
62
63static inline GC_cardMapIndex sizeToCardMapIndex (size_t z);
64static inline size_t cardMapIndexToSize (GC_cardMapIndex i);
65static inline GC_cardMapIndex pointerToCardMapIndexAbsolute (pointer p);
66static inline GC_cardMapElem *pointerToCardMapAddr (GC_state s, pointer p);
67
68static inline GC_crossMapIndex sizeToCrossMapIndex (size_t z);
69
70#if ASSERT
71static inline bool isCardMarked (GC_state s, pointer p);
72#endif
73static inline void markCard (GC_state s, pointer p);
74static inline void markIntergenerationalPointer (GC_state s, pointer *pp);
75static inline void markIntergenerationalObjptr (GC_state s, objptr *opp);
76
77static inline void setCardMapAbsolute (GC_state s);
78#if ASSERT
79static inline pointer getCrossMapCardStart (GC_state s, pointer p);
80#endif
81
82static inline size_t sizeofCardMap (GC_state s, size_t heapSize);
83static inline GC_cardMapIndex lenofCardMap (GC_state s, size_t cardMapSize);
84static inline size_t sizeofCrossMap (GC_state s, size_t heapSize);
85static inline GC_crossMapIndex lenofCrossMap (GC_state s, size_t crossMapSize);
86static size_t sizeofCardMapAndCrossMap (GC_state s, size_t heapSize);
87static size_t invertSizeofCardMapAndCrossMap (GC_state s, size_t heapWithMapsSize);
88
89static inline void clearCardMap (GC_state s);
90static inline void clearCrossMap (GC_state s);
91static inline void clearCardMapAndCrossMap (GC_state s);
92static void setCardMapAndCrossMap (GC_state s);
93
94#if ASSERT
95static bool isCrossMapOk (GC_state s);
96#endif
97static void updateCrossMap (GC_state s);
98
99#endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */