*** empty log message ***
[cacao.git] / mm / allocator.h
1 /*
2  * cacao/mm/allocator.h
3  * $Id: allocator.h 105 1998-12-10 17:48:53Z phil $
4  */
5
6 #ifndef __allocator_h_
7 #define __allocator_h_
8
9 #include "bitmap2.h"
10
11 #ifndef YES
12 #       define YES              1
13 #endif
14 #ifndef NO
15 #       define NO           0
16 #endif
17
18 #define COUNT_ALLOCATIONS       NO
19
20 #define FASTER_FAIL     NO
21
22 #define PRINTF                          NO
23 #define SMALL_TABLES            YES
24 #define MSB_TO_LSB_SEARCH       NO
25
26 #define ADDRESS 64
27 //#define ADDRESS 32
28
29 #if ADDRESS == 64
30 #  define SIZE  unsigned long long
31 #else
32 #  define SIZE  unsigned long
33 #endif
34
35 #define ALIGN   3       /* 64bit alignment */
36 //#define ALIGN 2       /* 32bit allignment */
37
38 #define EXACT_TOP_BIT  8    /* usually somewhere in the range [8..10]
39                                                            the largest exact chunk is 1 << EXACT_TOP_BIT bytes large &
40                                                            there'll be 1 << (EXACT_TOP_BIT - ALIGN) exact bins 
41                                                            
42                                                            Supported values are between 0 and 16...
43                                                            ...any value less than ALIGN mean "no exact bins"...
44                                                            ...actually, there'll be a very small first bin containing
45                                                            chunks exactly allocationblock sized.
46                                    
47                                                            Setting EXACT_TOP_BIT to anything less than (SUBBIT + ALIGN)
48                                                            doesn't really make sense either, but is possible...
49                                                         */
50
51 /* check EXACT_TOP_BIT early ... */
52
53 #if (EXACT_TOP_BIT > 16)
54 #       warning "EXACT_TOP_BIT > 16: bad idea & unsupported value; using 16"
55 #   undef EXACT_TOP_BIT
56 #       define EXACT_TOP_BIT 16
57 #endif
58
59
60 #if EXACT_TOP_BIT >= ALIGN
61 # define EXACT  (EXACT_TOP_BIT - ALIGN)
62 #else
63 # define EXACT  0
64 #endif
65 #define LARGE   (ADDRESS - EXACT - ALIGN)
66
67 #define SUBBIT  0       /* set this to 0 to disable the additional hashing for the large bins;
68                                            otherwise, good values are in the range [3..5]; the best setting for
69                                            a particular application is highly dependent on the VM's heap-size 
70                                            and the cache sizes. Remember, the allocator will create 
71                                            (LARGE << SUBBIT) sorted bins. In the case of a 64bit machine with
72                                            256 exact bins (EXACT_TOP_BIT == 9), a SUBBIT setting of 3 will
73                                            create 64-9=55 bins consisting of 2^3=8 subbins; thus, a pointer
74                                            array with 55*8 fields will be allocated, eating up 3520 bytes. */
75
76 /* check config */
77
78 #if (SUBBIT < 0)
79 #       warning "SUBBIT < 0: using 0."
80 #       undef SUBBIT
81 #       define SUBBIT   0
82 #endif
83
84 #if (SUBBIT > (EXACT_TOP_BIT - ALIGN))
85 #  warning "SUBBIT > (EXACT_TOP_BIT - ALIGN): wasting subbins!"
86 #endif
87
88 #if (((LARGE << SUBBIT) << ALIGN) > (1 << 16))
89 #  warning "((LARGE << SUBBIT) << ALIGN) > 64K: are you sure you want it this big??" 
90 #endif
91
92 typedef struct freeblock_exact {
93         struct freeblock_exact* next;
94 } FREE_EXACT;
95
96 typedef struct freeblock_large {
97         SIZE                                    size;
98         struct freeblock_large* next;
99 } FREE_LARGE;
100
101
102 void allocator_free(void* chunk, SIZE size);
103 void* allocator_alloc(SIZE size);
104 void allocator_init(void);
105 void allocator_reset(void);
106
107 void allocator_mark_free_kludge(BITBLOCK* bitmap);
108
109 unsigned char find_highest(SIZE bits);
110
111 #endif /* !defined(__allocator_h_) */
112
113
114 /*
115  * These are local overrides for various environment variables in Emacs.
116  * Please do not remove this and leave it at the end of the file, where
117  * Emacs will automagically detect them.
118  * ---------------------------------------------------------------------
119  * Local variables:
120  * mode: c
121  * indent-tabs-mode: t
122  * c-basic-offset: 4
123  * tab-width: 4
124  * End:
125  */
126