]>
Commit | Line | Data |
---|---|---|
05513b45 | 1 | /* Garbage collection for the GNU compiler. |
c849df63 | 2 | Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
05513b45 | 3 | |
f12b58b3 | 4 | This file is part of GCC. |
02e7a332 | 5 | |
f12b58b3 | 6 | GCC is free software; you can redistribute it and/or modify it under |
7 | the terms of the GNU General Public License as published by the Free | |
8 | Software Foundation; either version 2, or (at your option) any later | |
9 | version. | |
02e7a332 | 10 | |
f12b58b3 | 11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
02e7a332 | 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 | for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
f12b58b3 | 17 | along with GCC; see the file COPYING. If not, write to the Free |
02e7a332 | 18 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
19 | 02111-1307, USA. */ | |
05513b45 | 20 | |
769177ac | 21 | #include "varray.h" |
1f3233d1 | 22 | #include "gtype-desc.h" |
05513b45 | 23 | |
24 | /* Symbols are marked with `ggc' for `gcc gc' so as not to interfere with | |
25 | an external gc library that might be linked in. */ | |
26 | ||
0f4dbfb9 | 27 | /* Constants for general use. */ |
ec6cb94a | 28 | extern const char empty_string[]; /* empty string */ |
29 | extern const char digit_vector[]; /* "0" .. "9" */ | |
30 | #define digit_string(d) (digit_vector + ((d) * 2)) | |
0f4dbfb9 | 31 | |
a60d09cf | 32 | /* Manipulate global roots that are needed between calls to gc. |
33 | THIS ROUTINE IS OBSOLETE, do not use it for new code. */ | |
15d769aa | 34 | extern void ggc_add_root PARAMS ((void *base, int nelt, |
35 | int size, void (*)(void *))); | |
1f3233d1 | 36 | |
3cfec666 | 37 | /* Structures for the easy way to mark roots. |
1f3233d1 | 38 | In an array, terminated by having base == NULL.*/ |
39 | struct ggc_root_tab { | |
40 | void *base; | |
41 | size_t nelt; | |
42 | size_t stride; | |
43 | void (*cb) PARAMS ((void *)); | |
44 | }; | |
45 | #define LAST_GGC_ROOT_TAB { NULL, 0, 0, NULL } | |
46 | /* Pointers to arrays of ggc_root_tab, terminated by NULL. */ | |
47 | extern const struct ggc_root_tab * const gt_ggc_rtab[]; | |
48 | extern const struct ggc_root_tab * const gt_ggc_deletable_rtab[]; | |
49 | ||
50 | /* Structure for hash table cache marking. */ | |
51 | struct htab; | |
52 | struct ggc_cache_tab { | |
53 | struct htab * *base; | |
54 | size_t nelt; | |
55 | size_t stride; | |
56 | void (*cb) PARAMS ((void *)); | |
57 | int (*marked_p) PARAMS ((const void *)); | |
58 | }; | |
59 | #define LAST_GGC_CACHE_TAB { NULL, 0, 0, NULL, NULL } | |
60 | /* Pointers to arrays of ggc_cache_tab, terminated by NULL. */ | |
61 | extern const struct ggc_cache_tab * const gt_ggc_cache_rtab[]; | |
62 | ||
15d769aa | 63 | extern void ggc_mark_roots PARAMS ((void)); |
0046a2c2 | 64 | |
f7cb0e39 | 65 | /* If EXPR is not NULL and previously unmarked, mark it and evaluate |
66 | to true. Otherwise evaluate to false. */ | |
67 | #define ggc_test_and_set_mark(EXPR) \ | |
1f3233d1 | 68 | ((EXPR) != NULL && ((void *) (EXPR)) != (void *) 1 && ! ggc_set_mark (EXPR)) |
f7cb0e39 | 69 | |
c849df63 | 70 | #define ggc_mark_rtx gt_ggc_m_7rtx_def |
71 | #define ggc_mark_tree gt_ggc_m_9tree_node | |
0046a2c2 | 72 | |
71661611 | 73 | #define ggc_mark(EXPR) \ |
74 | do { \ | |
182b8a5c | 75 | const void *const a__ = (EXPR); \ |
1f3233d1 | 76 | if (a__ != NULL && a__ != (void *) 1) \ |
71661611 | 77 | ggc_set_mark (a__); \ |
78 | } while (0) | |
79 | ||
bebb7b68 | 80 | /* A GC implementation must provide these functions. */ |
81 | ||
a7dce381 | 82 | /* Initialize the garbage collector. */ |
15d769aa | 83 | extern void init_ggc PARAMS ((void)); |
84 | extern void init_stringpool PARAMS ((void)); | |
05513b45 | 85 | |
c788feb1 | 86 | /* Start a new GGC context. Memory allocated in previous contexts |
87 | will not be collected while the new context is active. */ | |
15d769aa | 88 | extern void ggc_push_context PARAMS ((void)); |
bebb7b68 | 89 | |
c788feb1 | 90 | /* Finish a GC context. Any uncollected memory in the new context |
91 | will be merged with the old context. */ | |
15d769aa | 92 | extern void ggc_pop_context PARAMS ((void)); |
c788feb1 | 93 | |
05513b45 | 94 | /* Allocation. */ |
71661611 | 95 | |
96 | /* The internal primitive. */ | |
15d769aa | 97 | extern void *ggc_alloc PARAMS ((size_t)); |
791ceafe | 98 | /* Like ggc_alloc, but allocates cleared memory. */ |
15d769aa | 99 | extern void *ggc_alloc_cleared PARAMS ((size_t)); |
1f3233d1 | 100 | /* Resize a block. */ |
101 | extern void *ggc_realloc PARAMS ((void *, size_t)); | |
102 | /* Like ggc_alloc_cleared, but performs a multiplication. */ | |
103 | extern void *ggc_calloc PARAMS ((size_t, size_t)); | |
71661611 | 104 | |
791ceafe | 105 | #define ggc_alloc_rtx(NSLOTS) \ |
106 | ((struct rtx_def *) ggc_alloc (sizeof (struct rtx_def) \ | |
107 | + ((NSLOTS) - 1) * sizeof (rtunion))) | |
71661611 | 108 | |
109 | #define ggc_alloc_rtvec(NELT) \ | |
791ceafe | 110 | ((struct rtvec_def *) ggc_alloc (sizeof (struct rtvec_def) \ |
111 | + ((NELT) - 1) * sizeof (rtx))) | |
71661611 | 112 | |
791ceafe | 113 | #define ggc_alloc_tree(LENGTH) ((union tree_node *) ggc_alloc (LENGTH)) |
71661611 | 114 | |
1f3233d1 | 115 | #define htab_create_ggc(SIZE, HASH, EQ, DEL) \ |
116 | htab_create_alloc (SIZE, HASH, EQ, DEL, ggc_calloc, NULL) | |
117 | ||
44acf429 | 118 | /* Allocate a gc-able string, and fill it with LENGTH bytes from CONTENTS. |
119 | If LENGTH is -1, then CONTENTS is assumed to be a | |
120 | null-terminated string and the memory sized accordingly. */ | |
15d769aa | 121 | extern const char *ggc_alloc_string PARAMS ((const char *contents, |
122 | int length)); | |
05513b45 | 123 | |
a4e59c31 | 124 | /* Make a copy of S, in GC-able memory. */ |
125 | #define ggc_strdup(S) ggc_alloc_string((S), -1) | |
126 | ||
3915b59e | 127 | /* Invoke the collector. Garbage collection occurs only when this |
128 | function is called, not during allocations. */ | |
15d769aa | 129 | extern void ggc_collect PARAMS ((void)); |
05513b45 | 130 | |
bebb7b68 | 131 | /* Actually set the mark on a particular region of memory, but don't |
71661611 | 132 | follow pointers. This function is called by ggc_mark_*. It |
6ef828f9 | 133 | returns zero if the object was not previously marked; nonzero if |
71661611 | 134 | the object was already marked, or if, for any other reason, |
135 | pointers in this data structure should not be traversed. */ | |
15d769aa | 136 | extern int ggc_set_mark PARAMS ((const void *)); |
137 | ||
3cfec666 | 138 | /* Return 1 if P has been marked, zero otherwise. |
15d769aa | 139 | P must have been allocated by the GC allocator; it mustn't point to |
140 | static objects, stack variables, or memory allocated with malloc. */ | |
141 | extern int ggc_marked_p PARAMS ((const void *)); | |
05513b45 | 142 | |
4e00b6fd | 143 | /* Statistics. */ |
144 | ||
145 | /* This structure contains the statistics common to all collectors. | |
146 | Particular collectors can extend this structure. */ | |
3cfec666 | 147 | typedef struct ggc_statistics |
4e00b6fd | 148 | { |
149 | /* The Ith element is the number of nodes allocated with code I. */ | |
150 | unsigned num_trees[256]; | |
3cfec666 | 151 | /* The Ith element is the number of bytes allocated by nodes with |
4e00b6fd | 152 | code I. */ |
153 | size_t size_trees[256]; | |
154 | /* The Ith element is the number of nodes allocated with code I. */ | |
155 | unsigned num_rtxs[256]; | |
3cfec666 | 156 | /* The Ith element is the number of bytes allocated by nodes with |
4e00b6fd | 157 | code I. */ |
158 | size_t size_rtxs[256]; | |
4e00b6fd | 159 | /* The total size of the tree nodes allocated. */ |
160 | size_t total_size_trees; | |
4e00b6fd | 161 | /* The total size of the RTL nodes allocated. */ |
162 | size_t total_size_rtxs; | |
9ffd5d6d | 163 | /* The total number of tree nodes allocated. */ |
164 | unsigned total_num_trees; | |
165 | /* The total number of RTL nodes allocated. */ | |
166 | unsigned total_num_rtxs; | |
4e00b6fd | 167 | } ggc_statistics; |
168 | ||
169 | /* Return the number of bytes allocated at the indicated address. */ | |
15d769aa | 170 | extern size_t ggc_get_size PARAMS ((const void *)); |
4e00b6fd | 171 | |
172 | /* Used by the various collectors to gather and print statistics that | |
173 | do not depend on the collector in use. */ | |
15d769aa | 174 | extern void ggc_print_common_statistics PARAMS ((FILE *, ggc_statistics *)); |
74647769 | 175 | |
176 | /* Print allocation statistics. */ | |
15d769aa | 177 | extern void ggc_print_statistics PARAMS ((void)); |
178 | extern void stringpool_statistics PARAMS ((void)); |