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