| 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 GC_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__) \ |
| 51 |
|| (defined(__x86_64__) && !defined(__ILP32__)) \ |
| 52 |
|| defined(__alpha__) || defined(__powerpc64__) \ |
| 53 |
|| defined(__arch64__) |
| 54 |
# define GC_GRANULE_BYTES 16 |
| 55 |
# define GC_GRANULE_WORDS 2 |
| 56 |
# else |
| 57 |
# define GC_GRANULE_BYTES 8 |
| 58 |
# define GC_GRANULE_WORDS 2 |
| 59 |
# endif |
| 60 |
#endif /* !GC_GRANULE_BYTES */ |
| 61 |
|
| 62 |
#if GC_GRANULE_WORDS == 2 |
| 63 |
# define GC_WORDS_TO_GRANULES(n) ((n)>>1) |
| 64 |
#else |
| 65 |
# define GC_WORDS_TO_GRANULES(n) ((n)*sizeof(void *)/GC_GRANULE_BYTES) |
| 66 |
#endif |
| 67 |
|
| 68 |
/* A "tiny" free list header contains TINY_FREELISTS pointers to */ |
| 69 |
/* singly linked lists of objects of different sizes, the ith one */ |
| 70 |
/* containing objects i granules in size. Note that there is a list */ |
| 71 |
/* of size zero objects. */ |
| 72 |
#ifndef GC_TINY_FREELISTS |
| 73 |
# if GC_GRANULE_BYTES == 16 |
| 74 |
# define GC_TINY_FREELISTS 25 |
| 75 |
# else |
| 76 |
# define GC_TINY_FREELISTS 33 /* Up to and including 256 bytes */ |
| 77 |
# endif |
| 78 |
#endif /* !GC_TINY_FREELISTS */ |
| 79 |
|
| 80 |
/* The ith free list corresponds to size i*GC_GRANULE_BYTES */ |
| 81 |
/* Internally to the collector, the index can be computed with */ |
| 82 |
/* ROUNDED_UP_GRANULES. Externally, we don't know whether */ |
| 83 |
/* DONT_ADD_BYTE_AT_END is set, but the client should know. */ |
| 84 |
|
| 85 |
/* Convert a free list index to the actual size of objects */ |
| 86 |
/* on that list, including extra space we added. Not an */ |
| 87 |
/* inverse of the above. */ |
| 88 |
#define GC_RAW_BYTES_FROM_INDEX(i) ((i) * GC_GRANULE_BYTES) |
| 89 |
|
| 90 |
#endif /* GC_TINY_FL_H */ |