1 /* Copyright (C) 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))
13 * All ML objects (including ML execution stacks) are allocated in a
14 * contiguous heap. The heap has the following general layout:
16 * -------------------------------------------------------------------------
17 * | old generation | | nursery | cardMap | crossMap |
18 * -------------------------------------------------------------------------
19 * |------oldGenSize------|
20 * |-----------------------size-----------------------|
23 * |------------------------------withMapsSize-----------------------------|
26 typedef struct GC_heap
{
27 pointer nursery
; /* start of nursery */
28 size_t oldGenSize
; /* size of old generation */
29 size_t size
; /* size of heap */
30 pointer start
; /* start of heap (and old generation) */
31 size_t withMapsSize
; /* size of heap with card/cross maps */
34 #define GC_HEAP_LIMIT_SLOP 512
36 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
38 #if (defined (MLTON_GC_INTERNAL_FUNCS))
40 static inline bool isPointerInOldGen (GC_state s
, pointer p
);
41 static inline bool isPointerInNursery (GC_state s
, pointer p
);
43 static inline bool isObjptrInOldGen (GC_state s
, objptr op
);
45 static inline bool isObjptrInNursery (GC_state s
, objptr op
);
47 static inline bool isObjptrInFromSpace (GC_state s
, objptr op
);
49 static inline bool hasHeapBytesFree (GC_state s
, size_t oldGen
, size_t nursery
);
50 static inline bool isHeapInit (GC_heap h
);
52 static void displayHeap (GC_state s
, GC_heap heap
, FILE *stream
);
54 static inline void initHeap (GC_state s
, GC_heap h
);
55 static inline size_t sizeofHeapDesired (GC_state s
, size_t live
, size_t currentSize
);
57 static inline void releaseHeap (GC_state s
, GC_heap h
);
58 static void shrinkHeap (GC_state s
, GC_heap h
, size_t keepSize
);
59 static bool createHeap (GC_state s
, GC_heap h
, size_t desiredSize
, size_t minSize
);
60 static bool createHeapSecondary (GC_state s
, size_t desiredSize
);
61 static bool remapHeap (GC_state s
, GC_heap h
, size_t desiredSize
, size_t minSize
);
62 static void growHeap (GC_state s
, size_t desiredSize
, size_t minSize
);
63 static void resizeHeap (GC_state s
, size_t minSize
);
64 static void resizeHeapSecondary (GC_state s
);
66 #endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */