dbg_mlc.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
  3. * Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
  4. * Copyright (c) 1997 by Silicon Graphics. All rights reserved.
  5. * Copyright (c) 1999 by Hewlett-Packard Company. All rights reserved.
  6. *
  7. * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  8. * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
  9. *
  10. * Permission is hereby granted to use or copy this program
  11. * for any purpose, provided the above notices are retained on all copies.
  12. * Permission to modify the code and to distribute modified code is granted,
  13. * provided the above notices are retained, and a notice that the code was
  14. * modified is included with the above copyright notice.
  15. */
  16. /*
  17. * This is mostly an internal header file. Typical clients should
  18. * not use it. Clients that define their own object kinds with
  19. * debugging allocators will probably want to include this, however.
  20. * No attempt is made to keep the namespace clean. This should not be
  21. * included from header files that are frequently included by clients.
  22. */
  23. #ifndef _DBG_MLC_H
  24. #define _DBG_MLC_H
  25. #include "gc_priv.h"
  26. #ifdef KEEP_BACK_PTRS
  27. # include "gc_backptr.h"
  28. #endif
  29. EXTERN_C_BEGIN
  30. #if CPP_WORDSZ == 32
  31. # define START_FLAG (word)0xfedcedcb
  32. # define END_FLAG (word)0xbcdecdef
  33. #else
  34. # define START_FLAG GC_WORD_C(0xFEDCEDCBfedcedcb)
  35. # define END_FLAG GC_WORD_C(0xBCDECDEFbcdecdef)
  36. #endif
  37. /* Stored both one past the end of user object, and one before */
  38. /* the end of the object as seen by the allocator. */
  39. #if defined(KEEP_BACK_PTRS) || defined(PRINT_BLACK_LIST) \
  40. || defined(MAKE_BACK_GRAPH)
  41. /* Pointer "source"s that aren't real locations. */
  42. /* Used in oh_back_ptr fields and as "source" */
  43. /* argument to some marking functions. */
  44. # define NOT_MARKED (ptr_t)0
  45. # define MARKED_FOR_FINALIZATION ((ptr_t)(word)2)
  46. /* Object was marked because it is finalizable. */
  47. # define MARKED_FROM_REGISTER ((ptr_t)(word)4)
  48. /* Object was marked from a register. Hence the */
  49. /* source of the reference doesn't have an address. */
  50. #endif /* KEEP_BACK_PTRS || PRINT_BLACK_LIST */
  51. /* Object header */
  52. typedef struct {
  53. # if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
  54. /* We potentially keep two different kinds of back */
  55. /* pointers. KEEP_BACK_PTRS stores a single back */
  56. /* pointer in each reachable object to allow reporting */
  57. /* of why an object was retained. MAKE_BACK_GRAPH */
  58. /* builds a graph containing the inverse of all */
  59. /* "points-to" edges including those involving */
  60. /* objects that have just become unreachable. This */
  61. /* allows detection of growing chains of unreachable */
  62. /* objects. It may be possible to eventually combine */
  63. /* both, but for now we keep them separate. Both */
  64. /* kinds of back pointers are hidden using the */
  65. /* following macros. In both cases, the plain version */
  66. /* is constrained to have an least significant bit of 1, */
  67. /* to allow it to be distinguished from a free list */
  68. /* link. This means the plain version must have an */
  69. /* lsb of 0. */
  70. /* Note that blocks dropped by black-listing will */
  71. /* also have the lsb clear once debugging has */
  72. /* started. */
  73. /* We're careful never to overwrite a value with lsb 0. */
  74. # if ALIGNMENT == 1
  75. /* Fudge back pointer to be even. */
  76. # define HIDE_BACK_PTR(p) GC_HIDE_POINTER(~1 & (word)(p))
  77. # else
  78. # define HIDE_BACK_PTR(p) GC_HIDE_POINTER(p)
  79. # endif
  80. # ifdef KEEP_BACK_PTRS
  81. GC_hidden_pointer oh_back_ptr;
  82. # endif
  83. # ifdef MAKE_BACK_GRAPH
  84. GC_hidden_pointer oh_bg_ptr;
  85. # endif
  86. # if defined(KEEP_BACK_PTRS) != defined(MAKE_BACK_GRAPH)
  87. /* Keep double-pointer-sized alignment. */
  88. word oh_dummy;
  89. # endif
  90. # endif
  91. const char * oh_string; /* object descriptor string */
  92. word oh_int; /* object descriptor integers */
  93. # ifdef NEED_CALLINFO
  94. struct callinfo oh_ci[NFRAMES];
  95. # endif
  96. # ifndef SHORT_DBG_HDRS
  97. word oh_sz; /* Original malloc arg. */
  98. word oh_sf; /* start flag */
  99. # endif /* SHORT_DBG_HDRS */
  100. } oh;
  101. /* The size of the above structure is assumed not to de-align things, */
  102. /* and to be a multiple of the word length. */
  103. #ifdef SHORT_DBG_HDRS
  104. # define DEBUG_BYTES (sizeof (oh))
  105. # define UNCOLLECTABLE_DEBUG_BYTES DEBUG_BYTES
  106. #else
  107. /* Add space for END_FLAG, but use any extra space that was already */
  108. /* added to catch off-the-end pointers. */
  109. /* For uncollectible objects, the extra byte is not added. */
  110. # define UNCOLLECTABLE_DEBUG_BYTES (sizeof (oh) + sizeof (word))
  111. # define DEBUG_BYTES (UNCOLLECTABLE_DEBUG_BYTES - EXTRA_BYTES)
  112. #endif
  113. /* Round bytes to words without adding extra byte at end. */
  114. #define SIMPLE_ROUNDED_UP_WORDS(n) BYTES_TO_WORDS((n) + WORDS_TO_BYTES(1) - 1)
  115. /* ADD_CALL_CHAIN stores a (partial) call chain into an object */
  116. /* header; it should be called with the allocation lock held. */
  117. /* PRINT_CALL_CHAIN prints the call chain stored in an object */
  118. /* to stderr. It requires that we do not hold the lock. */
  119. #if defined(SAVE_CALL_CHAIN)
  120. struct callinfo;
  121. GC_INNER void GC_save_callers(struct callinfo info[NFRAMES]);
  122. GC_INNER void GC_print_callers(struct callinfo info[NFRAMES]);
  123. # define ADD_CALL_CHAIN(base, ra) GC_save_callers(((oh *)(base)) -> oh_ci)
  124. # define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
  125. #elif defined(GC_ADD_CALLER)
  126. struct callinfo;
  127. GC_INNER void GC_print_callers(struct callinfo info[NFRAMES]);
  128. # define ADD_CALL_CHAIN(base, ra) ((oh *)(base)) -> oh_ci[0].ci_pc = (ra)
  129. # define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
  130. #else
  131. # define ADD_CALL_CHAIN(base, ra)
  132. # define PRINT_CALL_CHAIN(base)
  133. #endif
  134. #ifdef GC_ADD_CALLER
  135. # define OPT_RA ra,
  136. #else
  137. # define OPT_RA
  138. #endif
  139. /* Check whether object with base pointer p has debugging info */
  140. /* p is assumed to point to a legitimate object in our part */
  141. /* of the heap. */
  142. #ifdef SHORT_DBG_HDRS
  143. # define GC_has_other_debug_info(p) 1
  144. #else
  145. GC_INNER int GC_has_other_debug_info(ptr_t p);
  146. #endif
  147. #if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
  148. # ifdef SHORT_DBG_HDRS
  149. # error Non-ptr stored in object results in GC_HAS_DEBUG_INFO malfunction
  150. /* We may mistakenly conclude that p has a debugging wrapper. */
  151. # endif
  152. # if defined(PARALLEL_MARK) && defined(KEEP_BACK_PTRS)
  153. # define GC_HAS_DEBUG_INFO(p) \
  154. ((AO_load((volatile AO_t *)(p)) & 1) != 0 \
  155. && GC_has_other_debug_info(p) > 0)
  156. /* Atomic load is used as GC_store_back_pointer */
  157. /* stores oh_back_ptr atomically (p might point */
  158. /* to the field); this prevents a TSan warning. */
  159. # else
  160. # define GC_HAS_DEBUG_INFO(p) \
  161. ((*(word *)(p) & 1) && GC_has_other_debug_info(p) > 0)
  162. # endif
  163. #else
  164. # define GC_HAS_DEBUG_INFO(p) (GC_has_other_debug_info(p) > 0)
  165. #endif /* !KEEP_BACK_PTRS && !MAKE_BACK_GRAPH */
  166. EXTERN_C_END
  167. #endif /* _DBG_MLC_H */