]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | * Copyright (c) 1999-2005 Hewlett-Packard Development Company, L.P. | |
3 | * | |
4 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED | |
5 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. | |
6 | * | |
7 | * Permission is hereby granted to use or copy this program | |
8 | * for any purpose, provided the above notices are retained on all copies. | |
9 | * Permission to modify the code and to distribute modified code is granted, | |
10 | * provided the above notices are retained, and a notice that the code was | |
11 | * modified is included with the above copyright notice. | |
12 | */ | |
13 | ||
14 | #ifndef GC_TINY_FL_H | |
15 | #define GC_TINY_FL_H | |
16 | /* | |
17 | * Constants and data structures for "tiny" free lists. | |
18 | * These are used for thread-local allocation or in-lined allocators. | |
19 | * Each global free list also essentially starts with one of these. | |
20 | * However, global free lists are known to the GC. "Tiny" free lists | |
21 | * are basically private to the client. Their contents are viewed as | |
22 | * "in use" and marked accordingly by the core of the GC. | |
23 | * | |
24 | * Note that inlined code might know about the layout of these and the constants | |
25 | * involved. Thus any change here may invalidate clients, and such changes should | |
26 | * be avoided. Hence we keep this as simple as possible. | |
27 | */ | |
28 | ||
29 | /* | |
30 | * We always set GRANULE_BYTES to twice the length of a pointer. | |
31 | * This means that all allocation requests are rounded up to the next | |
32 | * multiple of 16 on 64-bit architectures or 8 on 32-bit architectures. | |
33 | * This appears to be a reasonable compromise between fragmentation overhead | |
34 | * and space usage for mark bits (usually mark bytes). | |
35 | * On many 64-bit architectures some memory references require 16-byte | |
36 | * alignment, making this necessary anyway. | |
37 | * For a few 32-bit architecture (e.g. x86), we may also need 16-byte alignment | |
38 | * for certain memory references. But currently that does not seem to be the | |
39 | * default for all conventional malloc implementations, so we ignore that | |
40 | * problem. | |
41 | * It would always be safe, and often useful, to be able to allocate very | |
42 | * small objects with smaller alignment. But that would cost us mark bit | |
43 | * space, so we no longer do so. | |
44 | */ | |
45 | #ifndef GC_GRANULE_BYTES | |
46 | /* GC_GRANULE_BYTES should not be overridden in any instances of the GC */ | |
47 | /* library that may be shared between applications, since it affects */ | |
48 | /* the binary interface to the library. */ | |
49 | # if defined(__LP64__) || defined (_LP64) || defined(_WIN64) \ | |
50 | || defined(__s390x__) || defined(__x86_64__) \ | |
51 | || defined(__alpha__) || defined(__powerpc64__) \ | |
52 | || defined(__arch64__) | |
53 | # define GC_GRANULE_BYTES 16 | |
54 | # define GC_GRANULE_WORDS 2 | |
55 | # else | |
56 | # define GC_GRANULE_BYTES 8 | |
57 | # define GC_GRANULE_WORDS 2 | |
58 | # endif | |
59 | #endif /* !GC_GRANULE_BYTES */ | |
60 | ||
61 | #if GC_GRANULE_WORDS == 2 | |
62 | # define GC_WORDS_TO_GRANULES(n) ((n)>>1) | |
63 | #else | |
64 | # define GC_WORDS_TO_GRANULES(n) ((n)*sizeof(void *)/GRANULE_BYTES) | |
65 | #endif | |
66 | ||
67 | /* A "tiny" free list header contains TINY_FREELISTS pointers to */ | |
68 | /* singly linked lists of objects of different sizes, the ith one */ | |
69 | /* containing objects i granules in size. Note that there is a list */ | |
70 | /* of size zero objects. */ | |
71 | #ifndef GC_TINY_FREELISTS | |
72 | # if GC_GRANULE_BYTES == 16 | |
73 | # define GC_TINY_FREELISTS 25 | |
74 | # else | |
75 | # define GC_TINY_FREELISTS 33 /* Up to and including 256 bytes */ | |
76 | # endif | |
77 | #endif /* !GC_TINY_FREELISTS */ | |
78 | ||
79 | /* The ith free list corresponds to size i*GRANULE_BYTES */ | |
80 | /* Internally to the collector, the index can be computed with */ | |
81 | /* ROUNDED_UP_GRANULES. Externally, we don't know whether */ | |
82 | /* DONT_ADD_BYTE_AT_END is set, but the client should know. */ | |
83 | ||
84 | /* Convert a free list index to the actual size of objects */ | |
85 | /* on that list, including extra space we added. Not an */ | |
86 | /* inverse of the above. */ | |
87 | #define RAW_BYTES_FROM_INDEX(i) ((i) * GC_GRANULE_BYTES) | |
88 | ||
89 | #endif /* GC_TINY_FL_H */ |