Upgrade Boehm GC to 7.2alpha4.
[cacao.git] / src / mm / boehm-gc / include / private / dbg_mlc.h
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 # define START_FLAG ((word)0xfedcedcb)
34 # define END_FLAG ((word)0xbcdecdef)
35         /* Stored both one past the end of user object, and one before  */
36         /* the end of the object as seen by the allocator.              */
37
38 # if defined(KEEP_BACK_PTRS) || defined(PRINT_BLACK_LIST) \
39      || defined(MAKE_BACK_GRAPH)
40     /* Pointer "source"s that aren't real locations.    */
41     /* Used in oh_back_ptr fields and as "source"       */
42     /* argument to some marking functions.              */
43 #       define NOT_MARKED (ptr_t)(0)
44 #       define MARKED_FOR_FINALIZATION ((ptr_t)(word)2)
45             /* Object was marked because it is finalizable.     */
46 #       define MARKED_FROM_REGISTER ((ptr_t)(word)4)
47             /* Object was marked from a register.  Hence the    */
48             /* source of the reference doesn't have an address. */
49 # endif /* KEEP_BACK_PTRS || PRINT_BLACK_LIST */
50
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 & (GC_word)(p))
77 #       else
78 #         define HIDE_BACK_PTR(p) GC_HIDE_POINTER(p)
79 #       endif
80
81 #       ifdef KEEP_BACK_PTRS
82           GC_hidden_pointer oh_back_ptr;
83 #       endif
84 #       ifdef MAKE_BACK_GRAPH
85           GC_hidden_pointer oh_bg_ptr;
86 #       endif
87 #       if defined(KEEP_BACK_PTRS) != defined(MAKE_BACK_GRAPH)
88           /* Keep double-pointer-sized alignment.       */
89           word oh_dummy;
90 #       endif
91 #   endif
92     const char * oh_string;     /* object descriptor string     */
93     word oh_int;                /* object descriptor integers   */
94 #   ifdef NEED_CALLINFO
95       struct callinfo oh_ci[NFRAMES];
96 #   endif
97 #   ifndef SHORT_DBG_HDRS
98       word oh_sz;                       /* Original malloc arg.         */
99       word oh_sf;                       /* start flag */
100 #   endif /* SHORT_DBG_HDRS */
101 } oh;
102 /* The size of the above structure is assumed not to de-align things,   */
103 /* and to be a multiple of the word length.                             */
104
105 #ifdef SHORT_DBG_HDRS
106 #   define DEBUG_BYTES (sizeof (oh))
107 #   define UNCOLLECTABLE_DEBUG_BYTES DEBUG_BYTES
108 #else
109     /* Add space for END_FLAG, but use any extra space that was already */
110     /* added to catch off-the-end pointers.                             */
111     /* For uncollectable objects, the extra byte is not added.          */
112 #   define UNCOLLECTABLE_DEBUG_BYTES (sizeof (oh) + sizeof (word))
113 #   define DEBUG_BYTES (UNCOLLECTABLE_DEBUG_BYTES - EXTRA_BYTES)
114 #endif
115
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
119 /* ADD_CALL_CHAIN stores a (partial) call chain into an object  */
120 /* header.  It may be called with or without the allocation     */
121 /* lock.                                                        */
122 /* PRINT_CALL_CHAIN prints the call chain stored in an object   */
123 /* to stderr.  It requires that we do not hold the lock.        */
124 #if defined(SAVE_CALL_CHAIN)
125     struct callinfo;
126     GC_INNER void GC_save_callers(struct callinfo info[NFRAMES]);
127     GC_INNER void GC_print_callers(struct callinfo info[NFRAMES]);
128 #   define ADD_CALL_CHAIN(base, ra) GC_save_callers(((oh *)(base)) -> oh_ci)
129 #   define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
130 #elif defined(GC_ADD_CALLER)
131     struct callinfo;
132     GC_INNER void GC_print_callers(struct callinfo info[NFRAMES]);
133 #   define ADD_CALL_CHAIN(base, ra) ((oh *)(base)) -> oh_ci[0].ci_pc = (ra)
134 #   define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
135 #else
136 #   define ADD_CALL_CHAIN(base, ra)
137 #   define PRINT_CALL_CHAIN(base)
138 #endif
139
140 # ifdef GC_ADD_CALLER
141 #   define OPT_RA ra,
142 # else
143 #   define OPT_RA
144 # endif
145
146
147 /* Check whether object with base pointer p has debugging info  */
148 /* p is assumed to point to a legitimate object in our part     */
149 /* of the heap.                                                 */
150 #ifdef SHORT_DBG_HDRS
151 # define GC_has_other_debug_info(p) TRUE
152 #else
153   GC_INNER GC_bool GC_has_other_debug_info(ptr_t p);
154 #endif
155
156 #if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
157 # define GC_HAS_DEBUG_INFO(p) \
158         ((*((word *)p) & 1) && GC_has_other_debug_info(p))
159 #else
160 # define GC_HAS_DEBUG_INFO(p) GC_has_other_debug_info(p)
161 #endif
162
163 /* Store debugging info into p.  Return displaced pointer. */
164 /* Assumes we don't hold allocation lock.                  */
165 GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str,
166                                    word integer);
167
168 #endif /* _DBG_MLC_H */