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.
7 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
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.
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.
29 # define I_HIDE_POINTERS
31 # ifdef KEEP_BACK_PTRS
32 # include "gc_backptr.h"
36 /* Gc.h was previously included, and hence the I_HIDE_POINTERS */
37 /* definition had no effect. Repeat the gc.h definitions here to */
38 /* get them anyway. */
39 typedef GC_word GC_hidden_pointer;
40 # define HIDE_POINTER(p) (~(GC_hidden_pointer)(p))
41 # define REVEAL_POINTER(p) ((GC_PTR)(HIDE_POINTER(p)))
42 #endif /* HIDE_POINTER */
44 # define START_FLAG ((word)0xfedcedcb)
45 # define END_FLAG ((word)0xbcdecdef)
46 /* Stored both one past the end of user object, and one before */
47 /* the end of the object as seen by the allocator. */
49 # if defined(KEEP_BACK_PTRS) || defined(PRINT_BLACK_LIST)
50 /* Pointer "source"s that aren't real locations. */
51 /* Used in oh_back_ptr fields and as "source" */
52 /* argument to some marking functions. */
53 # define NOT_MARKED (ptr_t)(0)
54 # define MARKED_FOR_FINALIZATION (ptr_t)(2)
55 /* Object was marked because it is finalizable. */
56 # define MARKED_FROM_REGISTER (ptr_t)(4)
57 /* Object was marked from a rgister. Hence the */
58 /* source of the reference doesn't have an address. */
59 # endif /* KEEP_BACK_PTRS || PRINT_BLACK_LIST */
63 # ifdef KEEP_BACK_PTRS
64 GC_hidden_pointer oh_back_ptr;
65 /* We make sure that we only store even valued */
66 /* pointers here, so that the hidden version has */
67 /* the least significant bit set. We never */
68 /* overwrite a value with the least significant */
69 /* bit clear, thus ensuring that we never overwrite */
70 /* a free list link field. */
71 /* Note that blocks dropped by black-listing will */
72 /* also have the lsb clear once debugging has */
74 /* The following are special back pointer values. */
75 /* Note that the "hidden" (i.e. bitwise */
76 /* complemented version) of these is actually */
79 /* Fudge back pointer to be even. */
80 # define HIDE_BACK_PTR(p) HIDE_POINTER(~1 & (GC_word)(p))
82 # define HIDE_BACK_PTR(p) HIDE_POINTER(p)
88 GC_CONST char * oh_string; /* object descriptor string */
89 word oh_int; /* object descriptor integers */
91 struct callinfo oh_ci[NFRAMES];
93 # ifndef SHORT_DBG_HDRS
94 word oh_sz; /* Original malloc arg. */
95 word oh_sf; /* start flag */
96 # endif /* SHORT_DBG_HDRS */
98 /* The size of the above structure is assumed not to dealign things, */
99 /* and to be a multiple of the word length. */
101 #ifdef SHORT_DBG_HDRS
102 # define DEBUG_BYTES (sizeof (oh))
104 /* Add space for END_FLAG, but use any extra space that was already */
105 /* added to catch off-the-end pointers. */
106 # define DEBUG_BYTES (sizeof (oh) + sizeof (word) - EXTRA_BYTES)
108 #define USR_PTR_FROM_BASE(p) ((ptr_t)(p) + sizeof(oh))
110 /* Round bytes to words without adding extra byte at end. */
111 #define SIMPLE_ROUNDED_UP_WORDS(n) BYTES_TO_WORDS((n) + WORDS_TO_BYTES(1) - 1)
113 #ifdef SAVE_CALL_CHAIN
114 # define ADD_CALL_CHAIN(base, ra) GC_save_callers(((oh *)(base)) -> oh_ci)
115 # define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
117 # ifdef GC_ADD_CALLER
118 # define ADD_CALL_CHAIN(base, ra) ((oh *)(base)) -> oh_ci[0].ci_pc = (ra)
119 # define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
121 # define ADD_CALL_CHAIN(base, ra)
122 # define PRINT_CALL_CHAIN(base)
126 # ifdef GC_ADD_CALLER
133 /* Check whether object with base pointer p has debugging info */
134 /* p is assumed to point to a legitimate object in our part */
136 #ifdef SHORT_DBG_HDRS
137 # define GC_has_other_debug_info(p) TRUE
139 GC_bool GC_has_other_debug_info(/* p */);
142 #ifdef KEEP_BACK_PTRS
143 # define GC_HAS_DEBUG_INFO(p) \
144 ((((oh *)p)->oh_back_ptr & 1) && GC_has_other_debug_info(p))
146 # define GC_HAS_DEBUG_INFO(p) GC_has_other_debug_info(p)
149 /* Store debugging info into p. Return displaced pointer. */
150 /* Assumes we don't hold allocation lock. */
151 ptr_t GC_store_debug_info(/* p, sz, string, integer */);
153 #endif /* _DBG_MLC_H */