/libs/headers/gc/private/dbg_mlc.h

http://github.com/nddrylliog/ooc · C++ Header · 178 lines · 88 code · 18 blank · 72 comment · 11 complexity · 085689f9b887e98957dbc95417de4952 MD5 · raw file

  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. # define I_HIDE_POINTERS
  26. # include "gc_priv.h"
  27. # ifdef KEEP_BACK_PTRS
  28. # include "gc_backptr.h"
  29. # endif
  30. #ifndef HIDE_POINTER
  31. /* Gc.h was previously included, and hence the I_HIDE_POINTERS */
  32. /* definition had no effect. Repeat the gc.h definitions here to */
  33. /* get them anyway. */
  34. typedef GC_word GC_hidden_pointer;
  35. # define HIDE_POINTER(p) (~(GC_hidden_pointer)(p))
  36. # define REVEAL_POINTER(p) ((void *)(HIDE_POINTER(p)))
  37. #endif /* HIDE_POINTER */
  38. # define START_FLAG ((word)0xfedcedcb)
  39. # define END_FLAG ((word)0xbcdecdef)
  40. /* Stored both one past the end of user object, and one before */
  41. /* the end of the object as seen by the allocator. */
  42. # if defined(KEEP_BACK_PTRS) || defined(PRINT_BLACK_LIST) \
  43. || defined(MAKE_BACK_GRAPH)
  44. /* Pointer "source"s that aren't real locations. */
  45. /* Used in oh_back_ptr fields and as "source" */
  46. /* argument to some marking functions. */
  47. # define NOT_MARKED (ptr_t)(0)
  48. # define MARKED_FOR_FINALIZATION (ptr_t)(2)
  49. /* Object was marked because it is finalizable. */
  50. # define MARKED_FROM_REGISTER (ptr_t)(4)
  51. /* Object was marked from a rgister. Hence the */
  52. /* source of the reference doesn't have an address. */
  53. # endif /* KEEP_BACK_PTRS || PRINT_BLACK_LIST */
  54. /* Object header */
  55. typedef struct {
  56. # if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
  57. /* We potentially keep two different kinds of back */
  58. /* pointers. KEEP_BACK_PTRS stores a single back */
  59. /* pointer in each reachable object to allow reporting */
  60. /* of why an object was retained. MAKE_BACK_GRAPH */
  61. /* builds a graph containing the inverse of all */
  62. /* "points-to" edges including those involving */
  63. /* objects that have just become unreachable. This */
  64. /* allows detection of growing chains of unreachable */
  65. /* objects. It may be possible to eventually combine */
  66. /* both, but for now we keep them separate. Both */
  67. /* kinds of back pointers are hidden using the */
  68. /* following macros. In both cases, the plain version */
  69. /* is constrained to have an least significant bit of 1,*/
  70. /* to allow it to be distinguished from a free list */
  71. /* link. This means the plain version must have an */
  72. /* lsb of 0. */
  73. /* Note that blocks dropped by black-listing will */
  74. /* also have the lsb clear once debugging has */
  75. /* started. */
  76. /* We're careful never to overwrite a value with lsb 0. */
  77. # if ALIGNMENT == 1
  78. /* Fudge back pointer to be even. */
  79. # define HIDE_BACK_PTR(p) HIDE_POINTER(~1 & (GC_word)(p))
  80. # else
  81. # define HIDE_BACK_PTR(p) HIDE_POINTER(p)
  82. # endif
  83. # ifdef KEEP_BACK_PTRS
  84. GC_hidden_pointer oh_back_ptr;
  85. # endif
  86. # ifdef MAKE_BACK_GRAPH
  87. GC_hidden_pointer oh_bg_ptr;
  88. # endif
  89. # if defined(KEEP_BACK_PTRS) != defined(MAKE_BACK_GRAPH)
  90. /* Keep double-pointer-sized alignment. */
  91. word oh_dummy;
  92. # endif
  93. # endif
  94. const char * oh_string; /* object descriptor string */
  95. word oh_int; /* object descriptor integers */
  96. # ifdef NEED_CALLINFO
  97. struct callinfo oh_ci[NFRAMES];
  98. # endif
  99. # ifndef SHORT_DBG_HDRS
  100. word oh_sz; /* Original malloc arg. */
  101. word oh_sf; /* start flag */
  102. # endif /* SHORT_DBG_HDRS */
  103. } oh;
  104. /* The size of the above structure is assumed not to dealign things, */
  105. /* and to be a multiple of the word length. */
  106. #ifdef SHORT_DBG_HDRS
  107. # define DEBUG_BYTES (sizeof (oh))
  108. # define UNCOLLECTABLE_DEBUG_BYTES DEBUG_BYTES
  109. #else
  110. /* Add space for END_FLAG, but use any extra space that was already */
  111. /* added to catch off-the-end pointers. */
  112. /* For uncollectable objects, the extra byte is not added. */
  113. # define UNCOLLECTABLE_DEBUG_BYTES (sizeof (oh) + sizeof (word))
  114. # define DEBUG_BYTES (UNCOLLECTABLE_DEBUG_BYTES - EXTRA_BYTES)
  115. #endif
  116. /* Round bytes to words without adding extra byte at end. */
  117. #define SIMPLE_ROUNDED_UP_WORDS(n) BYTES_TO_WORDS((n) + WORDS_TO_BYTES(1) - 1)
  118. /* ADD_CALL_CHAIN stores a (partial) call chain into an object */
  119. /* header. It may be called with or without the allocation */
  120. /* lock. */
  121. /* PRINT_CALL_CHAIN prints the call chain stored in an object */
  122. /* to stderr. It requires that we do not hold the lock. */
  123. #if defined(SAVE_CALL_CHAIN)
  124. struct callinfo;
  125. void GC_save_callers(struct callinfo info[NFRAMES]);
  126. void GC_print_callers(struct callinfo info[NFRAMES]);
  127. # define ADD_CALL_CHAIN(base, ra) GC_save_callers(((oh *)(base)) -> oh_ci)
  128. # define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
  129. #elif defined(GC_ADD_CALLER)
  130. struct callinfo;
  131. void GC_print_callers(struct callinfo info[NFRAMES]);
  132. # define ADD_CALL_CHAIN(base, ra) ((oh *)(base)) -> oh_ci[0].ci_pc = (ra)
  133. # define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
  134. #else
  135. # define ADD_CALL_CHAIN(base, ra)
  136. # define PRINT_CALL_CHAIN(base)
  137. #endif
  138. # ifdef GC_ADD_CALLER
  139. # define OPT_RA ra,
  140. # else
  141. # define OPT_RA
  142. # endif
  143. /* Check whether object with base pointer p has debugging info */
  144. /* p is assumed to point to a legitimate object in our part */
  145. /* of the heap. */
  146. #ifdef SHORT_DBG_HDRS
  147. # define GC_has_other_debug_info(p) TRUE
  148. #else
  149. GC_bool GC_has_other_debug_info(/* p */);
  150. #endif
  151. #if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
  152. # define GC_HAS_DEBUG_INFO(p) \
  153. ((*((word *)p) & 1) && GC_has_other_debug_info(p))
  154. #else
  155. # define GC_HAS_DEBUG_INFO(p) GC_has_other_debug_info(p)
  156. #endif
  157. /* Store debugging info into p. Return displaced pointer. */
  158. /* Assumes we don't hold allocation lock. */
  159. ptr_t GC_store_debug_info(/* p, sz, string, integer */);
  160. #endif /* _DBG_MLC_H */