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