d888b0ce31dd956e48d88350e0b6c7a08fb36718
[ghc.git] / rts / sm / CNF.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team 1998-2014
4 *
5 * GC support for immutable non-GCed structures
6 *
7 * Documentation on the architecture of the Garbage Collector can be
8 * found in the online commentary:
9 *
10 * http://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/GC
11 *
12 * ---------------------------------------------------------------------------*/
13
14 #ifndef SM_CNF_H
15 #define SM_CNF_H
16
17 #include "BeginPrivate.h"
18
19 void initCompact (void);
20 void exitCompact (void);
21
22 StgCompactNFData *compactNew (Capability *cap,
23 StgWord size);
24 void compactResize(Capability *cap,
25 StgCompactNFData *str,
26 StgWord new_size);
27 void compactFree (StgCompactNFData *str);
28 void compactMarkKnown(StgCompactNFData *str);
29 StgWord compactContains(StgCompactNFData *str,
30 StgPtr what);
31 StgWord countCompactBlocks(bdescr *outer);
32
33 #ifdef DEBUG
34 StgWord countAllocdCompactBlocks(bdescr *outer);
35 #endif
36
37 StgCompactNFDataBlock *compactAllocateBlock(Capability *cap,
38 StgWord size,
39 StgCompactNFDataBlock *previous);
40 StgPtr compactFixupPointers(StgCompactNFData *str,
41 StgClosure *root);
42
43 // Go from an arbitrary pointer into any block of a compact chain, to the
44 // StgCompactNFDataBlock at the beginning of the block.
45 INLINE_HEADER StgCompactNFDataBlock *objectGetCompactBlock (StgClosure *closure);
46 INLINE_HEADER StgCompactNFDataBlock *objectGetCompactBlock (StgClosure *closure)
47 {
48 bdescr *object_block, *head_block;
49
50 object_block = Bdescr((StgPtr)closure);
51
52 ASSERT ((object_block->flags & BF_COMPACT) != 0);
53
54 if (object_block->blocks == 0)
55 head_block = object_block->link;
56 else
57 head_block = object_block;
58
59 ASSERT ((head_block->flags & BF_COMPACT) != 0);
60
61 return (StgCompactNFDataBlock*)(head_block->start);
62 }
63
64 // Go from an arbitrary pointer into any block of a compact chain, to the
65 // StgCompactNFData for the whole compact chain.
66 INLINE_HEADER StgCompactNFData *objectGetCompact (StgClosure *closure);
67 INLINE_HEADER StgCompactNFData *objectGetCompact (StgClosure *closure)
68 {
69 StgCompactNFDataBlock *block = objectGetCompactBlock (closure);
70 return block->owner;
71 }
72
73 extern void *allocateForCompact (Capability *cap,
74 StgCompactNFData *str,
75 StgWord sizeW);
76
77 extern void insertCompactHash (Capability *cap,
78 StgCompactNFData *str,
79 StgClosure *p, StgClosure *to);
80
81 extern void verifyCompact (StgCompactNFData *str);
82
83 #include "EndPrivate.h"
84
85 #endif // SM_COMPACT_H