1 /* -----------------------------------------------------------------------------
2 * $Id: MBlock.h,v 1.15 2002/10/21 11:38:54 simonmar Exp $
4 * (c) The GHC Team, 1998-1999
6 * MegaBlock Allocator interface.
8 * ---------------------------------------------------------------------------*/
12 extern lnat mblocks_allocated;
14 extern void * getMBlock(void);
15 extern void * getMBlocks(nat n);
18 /* ToDo: Perhaps by adjusting this value we can make linking without
19 * -static work (i.e., not generate a core-dumping executable)? */
20 #if SIZEOF_VOID_P == 8
21 #define HEAP_BASE 0x180000000L
23 #error I have no idea where to begin the heap on a non-64-bit osf3 machine.
28 // we're using the generic method
33 /* -----------------------------------------------------------------------------
34 The HEAP_ALLOCED() test.
36 HEAP_ALLOCED is called FOR EVERY SINGLE CLOSURE during GC.
39 Implementation of HEAP_ALLOCED
40 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42 Since heap is allocated in chunks of megablocks (MBLOCK_SIZE), we
43 can just use a table to record which megablocks in the address
44 space belong to the heap. On a 32-bit machine, with 1Mb
45 megablocks, using 8 bits for each entry in the table, the table
46 requires 4k. Lookups during GC will be fast, because the table
47 will be quickly cached (indeed, performance measurements showed no
48 measurable difference between doing the table lookup and using a
50 -------------------------------------------------------------------------- */
52 #if SIZEOF_VOID_P == 4
54 // This is the table. Each byte is non-zero if the appropriate MBlock
55 // in the address space contains heap.
56 extern StgWord8 mblock_map[];
58 #define HEAP_ALLOCED(p) \
59 ((int)(mblock_map[((StgWord)(p) & ~MBLOCK_MASK) >> MBLOCK_SHIFT]))
61 #else // SIZEOF_VOID_P != 4
63 // on a 64-bit machine, we need to extend the above scheme to use a
64 // 2-level mapping. (ToDo)
66 #ifdef TEXT_BEFORE_HEAP
67 # define HEAP_ALLOCED(x) ((StgPtr)(x) >= (StgPtr)(HEAP_BASE))
69 #error HEAP_ALLOCED not defined
72 #endif // SIZEOF_VOID_P != 4
74 #endif // __MBLOCK_H__