/vendor/gc/include/gc_tiny_fl.h

http://github.com/feyeleanor/RubyGoLightly · C++ Header · 89 lines · 28 code · 7 blank · 54 comment · 11 complexity · 9a85f18cef7921669c9dbc84a24b2ef0 MD5 · raw file

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