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.
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
10 #if (defined (MLTON_GC_INTERNAL_TYPES))
12 /* must agree w/ cardSizeLog2 in ssa-to-rssa.fun */
13 #define CARD_SIZE_LOG2 8
14 #define CARD_SIZE TWOPOWER(CARD_SIZE_LOG2)
16 typedef uint8_t GC_cardMapElem
;
17 typedef uint8_t GC_crossMapElem
;
19 typedef GC_cardMapElem
*GC_cardMap
;
20 typedef GC_crossMapElem
*GC_crossMap
;
22 typedef size_t GC_cardMapIndex
;
23 typedef 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
30 struct 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.
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.
48 GC_crossMapIndex crossMapLength
;
49 /* crossMapValidSize the size of the prefix of the old generation
50 * for which the crossMap is valid.
52 size_t crossMapValidSize
;
55 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
57 #if (defined (MLTON_GC_INTERNAL_FUNCS))
59 static void displayGenerationalMaps (GC_state s
,
60 struct GC_generationalMaps
*generational
,
63 static inline GC_cardMapIndex
sizeToCardMapIndex (size_t z
);
64 static inline size_t cardMapIndexToSize (GC_cardMapIndex i
);
65 static inline GC_cardMapIndex
pointerToCardMapIndexAbsolute (pointer p
);
66 static inline GC_cardMapElem
*pointerToCardMapAddr (GC_state s
, pointer p
);
68 static inline GC_crossMapIndex
sizeToCrossMapIndex (size_t z
);
71 static inline bool isCardMarked (GC_state s
, pointer p
);
73 static inline void markCard (GC_state s
, pointer p
);
74 static inline void markIntergenerationalPointer (GC_state s
, pointer
*pp
);
75 static inline void markIntergenerationalObjptr (GC_state s
, objptr
*opp
);
77 static inline void setCardMapAbsolute (GC_state s
);
79 static inline pointer
getCrossMapCardStart (GC_state s
, pointer p
);
82 static inline size_t sizeofCardMap (GC_state s
, size_t heapSize
);
83 static inline GC_cardMapIndex
lenofCardMap (GC_state s
, size_t cardMapSize
);
84 static inline size_t sizeofCrossMap (GC_state s
, size_t heapSize
);
85 static inline GC_crossMapIndex
lenofCrossMap (GC_state s
, size_t crossMapSize
);
86 static size_t sizeofCardMapAndCrossMap (GC_state s
, size_t heapSize
);
87 static size_t invertSizeofCardMapAndCrossMap (GC_state s
, size_t heapWithMapsSize
);
89 static inline void clearCardMap (GC_state s
);
90 static inline void clearCrossMap (GC_state s
);
91 static inline void clearCardMapAndCrossMap (GC_state s
);
92 static void setCardMapAndCrossMap (GC_state s
);
95 static bool isCrossMapOk (GC_state s
);
97 static void updateCrossMap (GC_state s
);
99 #endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */