gc_tiny_fl.h 3.9 KB

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