Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / gc / align.c
1 /* Copyright (C) 2016 Matthew Fluet.
2 * Copyright (C) 1999-2006 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 size_t alignWithExtra (GC_state s, size_t bytes, size_t extra) {
11 return align (bytes + extra, s->alignment) - extra;
12 }
13
14
15 #if ASSERT
16 bool isFrontierAligned (GC_state s, pointer p) {
17 return isAligned ((size_t)p + GC_NORMAL_METADATA_SIZE, s->alignment);
18 }
19 #endif
20
21 pointer alignFrontier (GC_state s, pointer p) {
22 size_t res;
23
24 res = alignWithExtra (s, (size_t)p, GC_NORMAL_METADATA_SIZE);
25 assert (isFrontierAligned (s, (pointer)res));
26 return (pointer)res;
27 }