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