Back to index

plt-scheme  4.2.1
dbg_mlc.h
Go to the documentation of this file.
00001 /* 
00002  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
00003  * Copyright (c) 1991-1995 by Xerox Corporation.  All rights reserved.
00004  * Copyright (c) 1997 by Silicon Graphics.  All rights reserved.
00005  * Copyright (c) 1999 by Hewlett-Packard Company.  All rights reserved.
00006  *
00007  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
00008  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
00009  *
00010  * Permission is hereby granted to use or copy this program
00011  * for any purpose,  provided the above notices are retained on all copies.
00012  * Permission to modify the code and to distribute modified code is granted,
00013  * provided the above notices are retained, and a notice that the code was
00014  * modified is included with the above copyright notice.
00015  */
00016 
00017 /*
00018  * This is mostly an internal header file.  Typical clients should
00019  * not use it.  Clients that define their own object kinds with
00020  * debugging allocators will probably want to include this, however.
00021  * No attempt is made to keep the namespace clean.  This should not be
00022  * included from header files that are frequently included by clients.
00023  */
00024 
00025 #ifndef _DBG_MLC_H
00026 
00027 #define _DBG_MLC_H
00028 
00029 # define I_HIDE_POINTERS
00030 # include "gc_priv.h"
00031 # ifdef KEEP_BACK_PTRS
00032 #   include "gc_backptr.h"
00033 # endif
00034 
00035 #ifndef HIDE_POINTER
00036   /* Gc.h was previously included, and hence the I_HIDE_POINTERS      */
00037   /* definition had no effect.  Repeat the gc.h definitions here to   */
00038   /* get them anyway.                                                 */
00039     typedef GC_word GC_hidden_pointer;
00040 #   define HIDE_POINTER(p) (~(GC_hidden_pointer)(p))
00041 #   define REVEAL_POINTER(p) ((GC_PTR)(HIDE_POINTER(p)))
00042 #endif /* HIDE_POINTER */
00043 
00044 # define START_FLAG ((word)0xfedcedcb)
00045 # define END_FLAG ((word)0xbcdecdef)
00046        /* Stored both one past the end of user object, and one before */
00047        /* the end of the object as seen by the allocator.             */
00048 
00049 # if defined(KEEP_BACK_PTRS) || defined(PRINT_BLACK_LIST) \
00050      || defined(MAKE_BACK_GRAPH)
00051     /* Pointer "source"s that aren't real locations.    */
00052     /* Used in oh_back_ptr fields and as "source"       */
00053     /* argument to some marking functions.              */
00054 #      define NOT_MARKED (ptr_t)(0)
00055 #      define MARKED_FOR_FINALIZATION (ptr_t)(2)
00056            /* Object was marked because it is finalizable.     */
00057 #      define MARKED_FROM_REGISTER (ptr_t)(4)
00058            /* Object was marked from a rgister.  Hence the     */
00059            /* source of the reference doesn't have an address. */
00060 # endif /* KEEP_BACK_PTRS || PRINT_BLACK_LIST */
00061 
00062 /* Object header */
00063 typedef struct {
00064 #   if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
00065        /* We potentially keep two different kinds of back      */
00066        /* pointers.  KEEP_BACK_PTRS stores a single back       */
00067        /* pointer in each reachable object to allow reporting  */
00068        /* of why an object was retained.  MAKE_BACK_GRAPH      */
00069        /* builds a graph containing the inverse of all  */
00070        /* "points-to" edges including those involving          */
00071        /* objects that have just become unreachable. This      */
00072        /* allows detection of growing chains of unreachable    */
00073        /* objects.  It may be possible to eventually combine   */
00074        /* both, but for now we keep them separate.  Both       */
00075        /* kinds of back pointers are hidden using the          */
00076        /* following macros.  In both cases, the plain version  */
00077        /* is constrained to have an least significant bit of 1,*/
00078        /* to allow it to be distinguished from a free list     */
00079        /* link.  This means the plain version must have an     */
00080        /* lsb of 0.                                     */
00081        /* Note that blocks dropped by black-listing will       */
00082        /* also have the lsb clear once debugging has           */
00083        /* started.                                      */
00084        /* We're careful never to overwrite a value with lsb 0. */
00085 #       if ALIGNMENT == 1
00086          /* Fudge back pointer to be even.  */
00087 #        define HIDE_BACK_PTR(p) HIDE_POINTER(~1 & (GC_word)(p))
00088 #      else
00089 #        define HIDE_BACK_PTR(p) HIDE_POINTER(p)
00090 #      endif
00091        
00092 #       ifdef KEEP_BACK_PTRS
00093          GC_hidden_pointer oh_back_ptr;
00094 #      endif
00095 #      ifdef MAKE_BACK_GRAPH
00096          GC_hidden_pointer oh_bg_ptr;
00097 #      endif
00098 #      if defined(ALIGN_DOUBLE) && \
00099            (defined(KEEP_BACK_PTRS) != defined(MAKE_BACK_GRAPH))
00100          word oh_dummy;
00101 #      endif
00102 #   endif
00103     GC_CONST char * oh_string;     /* object descriptor string */
00104     word oh_int;            /* object descriptor integers      */
00105 #   ifdef NEED_CALLINFO
00106       struct callinfo oh_ci[NFRAMES];
00107 #   endif
00108 #   ifndef SHORT_DBG_HDRS
00109       word oh_sz;                  /* Original malloc arg.            */
00110       word oh_sf;                  /* start flag */
00111 #   endif /* SHORT_DBG_HDRS */
00112 } oh;
00113 /* The size of the above structure is assumed not to dealign things,  */
00114 /* and to be a multiple of the word length.                           */
00115 
00116 #ifdef SHORT_DBG_HDRS
00117 #   define DEBUG_BYTES (sizeof (oh))
00118 #   define UNCOLLECTABLE_DEBUG_BYTES DEBUG_BYTES
00119 #else
00120     /* Add space for END_FLAG, but use any extra space that was already      */
00121     /* added to catch off-the-end pointers.                           */
00122     /* For uncollectable objects, the extra byte is not added.        */
00123 #   define UNCOLLECTABLE_DEBUG_BYTES (sizeof (oh) + sizeof (word))
00124 #   define DEBUG_BYTES (UNCOLLECTABLE_DEBUG_BYTES - EXTRA_BYTES)
00125 #endif
00126 
00127 /* Round bytes to words without adding extra byte at end.      */
00128 #define SIMPLE_ROUNDED_UP_WORDS(n) BYTES_TO_WORDS((n) + WORDS_TO_BYTES(1) - 1)
00129 
00130 /* ADD_CALL_CHAIN stores a (partial) call chain into an object */
00131 /* header.  It may be called with or without the allocation    */
00132 /* lock.                                                */
00133 /* PRINT_CALL_CHAIN prints the call chain stored in an object  */
00134 /* to stderr.  It requires that we do not hold the lock.       */
00135 #ifdef SAVE_CALL_CHAIN
00136 #   define ADD_CALL_CHAIN(base, ra) GC_save_callers(((oh *)(base)) -> oh_ci)
00137 #   define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
00138 #else
00139 # ifdef GC_ADD_CALLER
00140 #   define ADD_CALL_CHAIN(base, ra) ((oh *)(base)) -> oh_ci[0].ci_pc = (ra)
00141 #   define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
00142 # else
00143 #   define ADD_CALL_CHAIN(base, ra)
00144 #   define PRINT_CALL_CHAIN(base)
00145 # endif
00146 #endif
00147 
00148 # ifdef GC_ADD_CALLER
00149 #   define OPT_RA ra,
00150 # else
00151 #   define OPT_RA
00152 # endif
00153 
00154 
00155 /* Check whether object with base pointer p has debugging info */ 
00156 /* p is assumed to point to a legitimate object in our part    */
00157 /* of the heap.                                                */
00158 #ifdef SHORT_DBG_HDRS
00159 # define GC_has_other_debug_info(p) TRUE
00160 #else
00161   GC_bool GC_has_other_debug_info(/* p */);
00162 #endif
00163 
00164 #if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
00165 # define GC_HAS_DEBUG_INFO(p) \
00166        ((*((word *)p) & 1) && GC_has_other_debug_info(p))
00167 #else
00168 # define GC_HAS_DEBUG_INFO(p) GC_has_other_debug_info(p)
00169 #endif
00170 
00171 /* Store debugging info into p.  Return displaced pointer. */
00172 /* Assumes we don't hold allocation lock.           */
00173 ptr_t GC_store_debug_info(/* p, sz, string, integer */);
00174 
00175 #endif /* _DBG_MLC_H */