/vendor/gc/include/private/gc_hdrs.h

http://github.com/feyeleanor/RubyGoLightly · C++ Header · 206 lines · 117 code · 24 blank · 65 comment · 14 complexity · b0ccc90c8c3d54389a86dd85b80a0223 MD5 · raw file

  1. /*
  2. * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
  3. * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
  4. *
  5. * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  6. * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
  7. *
  8. * Permission is hereby granted to use or copy this program
  9. * for any purpose, provided the above notices are retained on all copies.
  10. * Permission to modify the code and to distribute modified code is granted,
  11. * provided the above notices are retained, and a notice that the code was
  12. * modified is included with the above copyright notice.
  13. */
  14. /* Boehm, July 11, 1995 11:54 am PDT */
  15. # ifndef GC_HEADERS_H
  16. # define GC_HEADERS_H
  17. typedef struct hblkhdr hdr;
  18. # if CPP_WORDSZ != 32 && CPP_WORDSZ < 36
  19. --> Get a real machine.
  20. # endif
  21. /*
  22. * The 2 level tree data structure that is used to find block headers.
  23. * If there are more than 32 bits in a pointer, the top level is a hash
  24. * table.
  25. *
  26. * This defines HDR, GET_HDR, and SET_HDR, the main macros used to
  27. * retrieve and set object headers.
  28. *
  29. * We take advantage of a header lookup
  30. * cache. This is a locally declared direct mapped cache, used inside
  31. * the marker. The HC_GET_HDR macro uses and maintains this
  32. * cache. Assuming we get reasonable hit rates, this shaves a few
  33. * memory references from each pointer validation.
  34. */
  35. # if CPP_WORDSZ > 32
  36. # define HASH_TL
  37. # endif
  38. /* Define appropriate out-degrees for each of the two tree levels */
  39. # ifdef SMALL_CONFIG
  40. # define LOG_BOTTOM_SZ 11
  41. /* Keep top index size reasonable with smaller blocks. */
  42. # else
  43. # define LOG_BOTTOM_SZ 10
  44. # endif
  45. # ifndef HASH_TL
  46. # define LOG_TOP_SZ (WORDSZ - LOG_BOTTOM_SZ - LOG_HBLKSIZE)
  47. # else
  48. # define LOG_TOP_SZ 11
  49. # endif
  50. # define TOP_SZ (1 << LOG_TOP_SZ)
  51. # define BOTTOM_SZ (1 << LOG_BOTTOM_SZ)
  52. #ifndef SMALL_CONFIG
  53. # define USE_HDR_CACHE
  54. #endif
  55. /* #define COUNT_HDR_CACHE_HITS */
  56. # ifdef COUNT_HDR_CACHE_HITS
  57. extern word GC_hdr_cache_hits;
  58. extern word GC_hdr_cache_misses;
  59. # define HC_HIT() ++GC_hdr_cache_hits
  60. # define HC_MISS() ++GC_hdr_cache_misses
  61. # else
  62. # define HC_HIT()
  63. # define HC_MISS()
  64. # endif
  65. typedef struct hce {
  66. word block_addr; /* right shifted by LOG_HBLKSIZE */
  67. hdr * hce_hdr;
  68. } hdr_cache_entry;
  69. # define HDR_CACHE_SIZE 8 /* power of 2 */
  70. # define DECLARE_HDR_CACHE \
  71. hdr_cache_entry hdr_cache[HDR_CACHE_SIZE]
  72. # define INIT_HDR_CACHE BZERO(hdr_cache, sizeof(hdr_cache))
  73. # define HCE(h) hdr_cache + (((word)(h) >> LOG_HBLKSIZE) & (HDR_CACHE_SIZE-1))
  74. # define HCE_VALID_FOR(hce,h) ((hce) -> block_addr == \
  75. ((word)(h) >> LOG_HBLKSIZE))
  76. # define HCE_HDR(h) ((hce) -> hce_hdr)
  77. #ifdef PRINT_BLACK_LIST
  78. hdr * GC_header_cache_miss(ptr_t p, hdr_cache_entry *hce, ptr_t source);
  79. # define HEADER_CACHE_MISS(p, hce, source) \
  80. GC_header_cache_miss(p, hce, source)
  81. #else
  82. hdr * GC_header_cache_miss(ptr_t p, hdr_cache_entry *hce);
  83. # define HEADER_CACHE_MISS(p, hce, source) GC_header_cache_miss(p, hce)
  84. #endif
  85. /* Set hhdr to the header for p. Analogous to GET_HDR below, */
  86. /* except that in the case of large objects, it */
  87. /* gets the header for the object beginning, if GC_all_interior_ptrs */
  88. /* is set. */
  89. /* Returns zero if p points to somewhere other than the first page */
  90. /* of an object, and it is not a valid pointer to the object. */
  91. # define HC_GET_HDR(p, hhdr, source, exit_label) \
  92. { \
  93. hdr_cache_entry * hce = HCE(p); \
  94. if (EXPECT(HCE_VALID_FOR(hce, p), 1)) { \
  95. HC_HIT(); \
  96. hhdr = hce -> hce_hdr; \
  97. } else { \
  98. hhdr = HEADER_CACHE_MISS(p, hce, source); \
  99. if (0 == hhdr) goto exit_label; \
  100. } \
  101. }
  102. typedef struct bi {
  103. hdr * index[BOTTOM_SZ];
  104. /*
  105. * The bottom level index contains one of three kinds of values:
  106. * 0 means we're not responsible for this block,
  107. * or this is a block other than the first one in a free block.
  108. * 1 < (long)X <= MAX_JUMP means the block starts at least
  109. * X * HBLKSIZE bytes before the current address.
  110. * A valid pointer points to a hdr structure. (The above can't be
  111. * valid pointers due to the GET_MEM return convention.)
  112. */
  113. struct bi * asc_link; /* All indices are linked in */
  114. /* ascending order... */
  115. struct bi * desc_link; /* ... and in descending order. */
  116. word key; /* high order address bits. */
  117. # ifdef HASH_TL
  118. struct bi * hash_link; /* Hash chain link. */
  119. # endif
  120. } bottom_index;
  121. /* extern bottom_index GC_all_nils; - really part of GC_arrays */
  122. /* extern bottom_index * GC_top_index []; - really part of GC_arrays */
  123. /* Each entry points to a bottom_index. */
  124. /* On a 32 bit machine, it points to */
  125. /* the index for a set of high order */
  126. /* bits equal to the index. For longer */
  127. /* addresses, we hash the high order */
  128. /* bits to compute the index in */
  129. /* GC_top_index, and each entry points */
  130. /* to a hash chain. */
  131. /* The last entry in each chain is */
  132. /* GC_all_nils. */
  133. # define MAX_JUMP (HBLKSIZE - 1)
  134. # define HDR_FROM_BI(bi, p) \
  135. ((bi)->index[((word)(p) >> LOG_HBLKSIZE) & (BOTTOM_SZ - 1)])
  136. # ifndef HASH_TL
  137. # define BI(p) (GC_top_index \
  138. [(word)(p) >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE)])
  139. # define HDR_INNER(p) HDR_FROM_BI(BI(p),p)
  140. # ifdef SMALL_CONFIG
  141. # define HDR(p) GC_find_header((ptr_t)(p))
  142. # else
  143. # define HDR(p) HDR_INNER(p)
  144. # endif
  145. # define GET_BI(p, bottom_indx) (bottom_indx) = BI(p)
  146. # define GET_HDR(p, hhdr) (hhdr) = HDR(p)
  147. # define SET_HDR(p, hhdr) HDR_INNER(p) = (hhdr)
  148. # define GET_HDR_ADDR(p, ha) (ha) = &(HDR_INNER(p))
  149. # else /* hash */
  150. /* Hash function for tree top level */
  151. # define TL_HASH(hi) ((hi) & (TOP_SZ - 1))
  152. /* Set bottom_indx to point to the bottom index for address p */
  153. # define GET_BI(p, bottom_indx) \
  154. { \
  155. register word hi = \
  156. (word)(p) >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE); \
  157. register bottom_index * _bi = GC_top_index[TL_HASH(hi)]; \
  158. \
  159. while (_bi -> key != hi && _bi != GC_all_nils) \
  160. _bi = _bi -> hash_link; \
  161. (bottom_indx) = _bi; \
  162. }
  163. # define GET_HDR_ADDR(p, ha) \
  164. { \
  165. register bottom_index * bi; \
  166. \
  167. GET_BI(p, bi); \
  168. (ha) = &(HDR_FROM_BI(bi, p)); \
  169. }
  170. # define GET_HDR(p, hhdr) { register hdr ** _ha; GET_HDR_ADDR(p, _ha); \
  171. (hhdr) = *_ha; }
  172. # define SET_HDR(p, hhdr) { register hdr ** _ha; GET_HDR_ADDR(p, _ha); \
  173. *_ha = (hhdr); }
  174. # define HDR(p) GC_find_header((ptr_t)(p))
  175. # endif
  176. /* Is the result a forwarding address to someplace closer to the */
  177. /* beginning of the block or NIL? */
  178. # define IS_FORWARDING_ADDR_OR_NIL(hhdr) ((size_t) (hhdr) <= MAX_JUMP)
  179. /* Get an HBLKSIZE aligned address closer to the beginning of the block */
  180. /* h. Assumes hhdr == HDR(h) and IS_FORWARDING_ADDR(hhdr). */
  181. # define FORWARDED_ADDR(h, hhdr) ((struct hblk *)(h) - (size_t)(hhdr))
  182. # endif /* GC_HEADERS_H */