1 /* -----------------------------------------------------------------------------
2 * $Id: MBlock.h,v 1.16 2002/11/22 06:54:05 matthewc 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 extern StgWord8 mblock_map[];
54 #if SIZEOF_VOID_P == 4
55 /* On a 32-bit machine a 4KB table is always sufficient */
56 # define MBLOCK_MAP_SIZE 4096
57 # define MBLOCK_MAP_ENTRY(p) ((StgWord)(p) >> MBLOCK_SHIFT)
58 # define HEAP_ALLOCED(p) mblock_map[MBLOCK_MAP_ENTRY(p)]
59 # define MARK_HEAP_ALLOCED(p) (mblock_map[MBLOCK_MAP_ENTRY(p)] = 1)
61 #elif defined(ia64_TARGET_ARCH)
62 /* Instead of trying to cover the whole 64-bit address space (which would
63 * require a better data structure), we assume that mmap allocates mappings
64 * from the bottom of region 1, and track some portion of address space from
65 * there upwards (currently 4GB). */
66 # define MBLOCK_MAP_SIZE 4096
67 # define MBLOCK_MAP_ENTRY(p) (((StgWord)(p) - (1UL << 61)) >> MBLOCK_SHIFT)
68 # define HEAP_ALLOCED(p) ((MBLOCK_MAP_ENTRY(p) < MBLOCK_MAP_SIZE) \
69 && mblock_map[MBLOCK_MAP_ENTRY(p)])
70 # define MARK_HEAP_ALLOCED(p) ((MBLOCK_MAP_ENTRY(p) < MBLOCK_MAP_SIZE) \
71 && (mblock_map[MBLOCK_MAP_ENTRY(p)] = 1))
73 #elif defined(TEXT_BEFORE_HEAP)
74 /* Fall back to old method - assume heap above HEAP_BASE */
75 # define HEAP_ALLOCED(p) ((StgPtr)(p) >= (StgPtr)(HEAP_BASE))
76 # define MARK_HEAP_ALLOCED(p) do {} while(0)
79 # error HEAP_ALLOCED not defined
82 #endif // __MBLOCK_H__