Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / gc / hash-cons.h
1 /* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 * Copyright (C) 1997-2000 NEC Research Institute.
4 *
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
7 */
8
9 #if (defined (MLTON_GC_INTERNAL_TYPES))
10
11 /* ---------------------------------------------------------------- */
12 /* Object hash consing */
13 /* ---------------------------------------------------------------- */
14
15 typedef uint32_t GC_hash;
16 #define GC_HASH_SIZE sizeof(GC_hash)
17 #define PRIxHASH PRIx32
18 #define FMTHASH "0x%08"PRIxHASH
19
20 typedef struct GC_objectHashElement {
21 GC_hash hash;
22 pointer object;
23 } *GC_objectHashElement;
24
25 typedef struct GC_objectHashTable {
26 struct GC_objectHashElement *elements;
27 bool elementsIsInHeap;
28 uint32_t elementsLengthCur;
29 uint32_t elementsLengthMax;
30 uint32_t elementsLengthMaxLog2;
31 bool mayInsert;
32 } *GC_objectHashTable;
33
34 #endif /* (defined (MLTON_GC_INTERNAL_TYPES)) */
35
36 #if (defined (MLTON_GC_INTERNAL_FUNCS))
37
38 static inline GC_objectHashTable allocHashTable (GC_state s);
39 static inline void freeHashTable (GC_objectHashTable t);
40
41 static inline pointer insertHashTableElem (GC_state s,
42 GC_objectHashTable t, GC_hash hash,
43 pointer object, pointer max, bool mightBeThere);
44 static inline void growHashTableMaybe (GC_state s, GC_objectHashTable t);
45
46 static pointer hashConsPointer (GC_state s, pointer object, bool countBytesHashConsed);
47 static inline void shareObjptr (GC_state s, objptr *opp);
48
49 static void printBytesHashConsedMessage (size_t bytesHashConsed, size_t bytesExamined);
50
51 #endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */