summaryrefslogtreecommitdiff
path: root/rts/sm/CNF.h
blob: 6482130d2b3a2421c0b622edae1aa90c9f5a3dab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* -----------------------------------------------------------------------------
 *
 * (c) The GHC Team 1998-2014
 *
 * GC support for immutable non-GCed structures
 *
 * Documentation on the architecture of the Garbage Collector can be
 * found in the online commentary:
 *
 *   http://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Storage/GC
 *
 * ---------------------------------------------------------------------------*/

#pragma once

#include "BeginPrivate.h"

void              initCompact  (void);
void              exitCompact  (void);

StgCompactNFData *compactNew   (Capability      *cap,
                                StgWord          size);
void              compactResize(Capability       *cap,
                                StgCompactNFData *str,
                                StgWord           new_size);
void              compactFree  (StgCompactNFData *str);
void              compactMarkKnown(StgCompactNFData *str);
StgWord           compactContains(StgCompactNFData *str,
                                  StgPtr            what);
StgWord           countCompactBlocks(bdescr *outer);

#if defined(DEBUG)
StgWord           countAllocdCompactBlocks(bdescr *outer);
#endif

StgCompactNFDataBlock *compactAllocateBlock(Capability            *cap,
                                            StgWord                size,
                                            StgCompactNFDataBlock *previous);
StgPtr                 compactFixupPointers(StgCompactNFData      *str,
                                            StgClosure            *root);

// Go from an arbitrary pointer into any block of a compact chain, to the
// StgCompactNFDataBlock at the beginning of the block.
INLINE_HEADER StgCompactNFDataBlock *objectGetCompactBlock (StgClosure *closure);
INLINE_HEADER StgCompactNFDataBlock *objectGetCompactBlock (StgClosure *closure)
{
    bdescr *object_block, *head_block;

    object_block = Bdescr((StgPtr)closure);

    ASSERT((object_block->flags & BF_COMPACT) != 0);

    if (object_block->blocks == 0)
        head_block = object_block->link;
    else
        head_block = object_block;

    ASSERT((head_block->flags & BF_COMPACT) != 0);

    return (StgCompactNFDataBlock*)(head_block->start);
}

// Go from an arbitrary pointer into any block of a compact chain, to the
// StgCompactNFData for the whole compact chain.
INLINE_HEADER StgCompactNFData *objectGetCompact (StgClosure *closure);
INLINE_HEADER StgCompactNFData *objectGetCompact (StgClosure *closure)
{
    StgCompactNFDataBlock *block = objectGetCompactBlock (closure);
    return block->owner;
}

extern void *allocateForCompact (Capability *cap,
                                 StgCompactNFData *str,
                                 StgWord sizeW);

extern void insertCompactHash (Capability *cap,
                               StgCompactNFData *str,
                               StgClosure *p, StgClosure *to);

extern void verifyCompact (StgCompactNFData *str);

#include "EndPrivate.h"