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 void GC_pack (GC_state s
) {
14 if (DEBUG
or s
->controls
.messages
)
16 "[GC: Packing heap at "FMTPTR
" of size %s bytes.]\n",
17 (uintptr_t)(s
->heap
.start
),
18 uintmaxToCommaString(s
->heap
.size
));
19 /* Could put some code here to skip the GC if there hasn't been much
20 * allocated since the last collection. But you would still need to
21 * do a minor GC to make all objects contiguous.
23 performGC (s
, 0, 0, TRUE
, FALSE
);
24 keep
= (size_t)(s
->heap
.oldGenSize
* 1.1);
25 if (keep
<= s
->heap
.size
) {
26 shrinkHeap (s
, &s
->heap
, keep
);
27 setCardMapAndCrossMap (s
);
28 setGCStateCurrentHeap (s
, 0, 0);
29 setGCStateCurrentThreadAndStack (s
);
31 releaseHeap (s
, &s
->secondaryHeap
);
32 if (DEBUG
or s
->controls
.messages
)
34 "[GC: Packed heap at "FMTPTR
" to size %s bytes.]\n",
35 (uintptr_t)(s
->heap
.start
),
36 uintmaxToCommaString(s
->heap
.size
));
40 void GC_unpack (GC_state s
) {
42 if (DEBUG
or s
->controls
.messages
)
44 "[GC: Unpacking heap at "FMTPTR
" of size %s bytes.]\n",
45 (uintptr_t)(s
->heap
.start
),
46 uintmaxToCommaString(s
->heap
.size
));
47 /* The enterGC is needed here because minorGC and resizeHeap might
48 * move the stack, and the SIGPROF catcher would then see a bogus
49 * stack. The leaveGC has to happen after the setStack.
53 resizeHeap (s
, s
->heap
.oldGenSize
);
54 setCardMapAndCrossMap (s
);
55 resizeHeapSecondary (s
);
56 setGCStateCurrentHeap (s
, 0, 0);
57 setGCStateCurrentThreadAndStack (s
);
59 if (DEBUG
or s
->controls
.messages
)
61 "[GC: Unpacked heap at "FMTPTR
" to size %s bytes.]\n",
62 (uintptr_t)(s
->heap
.start
),
63 uintmaxToCommaString(s
->heap
.size
));