Merging 7971:887db7d64bc9 with 7970:21b063622472.
[cacao.git] / src / mm / cacao-gc / gc.h
1 /* src/mm/cacao-gc/gc.h - main garbage collector header
2
3    Copyright (C) 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #ifdef GC_CONST
29 # error Why is the BoehmGC header included???
30 #endif
31
32
33 #ifndef _GC_H
34 #define _GC_H
35
36
37 #include "config.h"
38 #include "vm/types.h"
39
40 #if defined(ENABLE_THREADS)
41 # include "threads/native/threads.h"
42 #endif
43
44 #include "toolbox/list.h"
45 #include "vm/jit/replace.h"
46
47
48 /* Configuration Switches *****************************************************/
49
50 #define GCCONF_FINALIZER
51 /*#define GCCONF_HDRFLAG_REFERENCING*/
52
53
54 /* Debugging ******************************************************************/
55
56 #define GC_DEBUGGING
57 /*#define GC_DEBUGGING2*/
58
59 #if !defined(NDEBUG) && defined(GC_DEBUGGING)
60 # include <assert.h>
61 # include "vmcore/options.h"
62 # define GC_LOG(code) if (opt_verbosegc) { code; }
63 # define GC_ASSERT(assertion) assert(assertion)
64 #else
65 # define GC_LOG(code)
66 # define GC_ASSERT(assertion)
67 #endif
68
69 #if !defined(NDEBUG) && defined(GC_DEBUGGING2)
70 # define GC_LOG2(code) GC_LOG(code)
71 #else
72 # define GC_LOG2(code)
73 #endif
74
75
76 /* Development Break **********************************************************/
77
78 #if 0 && defined(ENABLE_THREADS)
79 # error "GC does not work with threads enabled!"
80 #endif
81
82 #if 1 && defined(ENABLE_INTRP)
83 # error "GC does not work with interpreter enabled!"
84 #endif
85
86 #if 1 && defined(ENABLE_JVMTI)
87 # error "GC does not work with JVMTI enabled!"
88 #endif
89
90 #if 1 && !defined(ENABLE_REPLACEMENT)
91 # error "GC does only work with replacement enabled!"
92 #endif
93
94 #if 1 && !defined(ENABLE_HANDLES)
95 # error "GC does only work with handles (indirection cells) enabled!"
96 #endif
97
98 #if 1 && !defined(__ALPHA__) && !defined(__ARM__) && !defined(__I386__) && !defined(__POWERPC__) && !defined(__X86_64__) && !defined(__M68K__) && !defined(__SPARC_64__)
99 # error "GC was only ported to some architectures so far!"
100 #endif
101
102
103 /* Helper Macros **************************************************************/
104
105 #define GC_SET_FLAGS(obj, flags)   ((obj)->hdrflags |=  (flags))
106 #define GC_CLEAR_FLAGS(obj, flags) ((obj)->hdrflags &= ~(flags))
107 #define GC_TEST_FLAGS(obj, flags)  ((obj)->hdrflags  &  (flags))
108
109 #define POINTS_INTO(ptr, ptr_start, ptr_end) \
110         ((void *) (ptr) >= (ptr_start) && (void *) (ptr) < (ptr_end))
111
112 #define GC_ALIGN_SIZE SIZEOF_VOID_P
113 #define GC_ALIGN(val,size) ((((val) + (size) - 1) / (size)) * (size))
114
115
116 /* Global Variables ***********************************************************/
117
118 extern bool gc_pending;
119 extern bool gc_notify_finalizer;
120
121 extern list_t *gc_reflist_strong;
122 extern list_t *gc_reflist_weak;
123
124
125 /* Structures *****************************************************************/
126
127 typedef struct list_gcref_entry_t list_gcref_entry_t;
128
129 struct list_gcref_entry_t {
130         listnode_t      linkage;
131         java_object_t **ref;
132 #if !defined(NDEBUG)
133         s4              reftype;
134 #endif
135 };
136
137
138 /* Global GC mutext stuff *****************************************************/
139
140 #if defined(ENABLE_THREADS)
141 # define GC_MUTEX_LOCK   threads_mutex_gc_lock()
142 # define GC_MUTEX_UNLOCK threads_mutex_gc_unlock()
143 #else
144 # define GC_MUTEX_LOCK
145 # define GC_MUTEX_UNLOCK
146 #endif
147
148
149 /* No-Thread specific stuff ***************************************************/
150
151 #if defined(ENABLE_THREADS)
152 # define GC_EXECUTIONSTATE (thread->es)
153 # define GC_SOURCESTATE    (thread->ss)
154 #else
155 # define GC_EXECUTIONSTATE (_no_threads_executionstate)
156 # define GC_SOURCESTATE    (_no_threads_sourcestate)
157
158 extern executionstate_t *_no_threads_executionstate;
159 extern sourcestate_t    *_no_threads_sourcestate;
160
161 #endif
162
163
164 /* Prototypes *****************************************************************/
165
166 void gc_collect(s4 level);
167
168 #if defined(ENABLE_THREADS)
169 bool gc_suspend(threadobject *thread, u1 *pc, u1 *sp);
170 #endif
171
172
173 /* Statistics *****************************************************************/
174
175 #if defined(ENABLE_STATISTICS)
176
177 #define GCSTAT_INIT(cnt)  { (cnt) = 0; }
178 #define GCSTAT_COUNT(cnt) { (cnt)++; }
179 #define GCSTAT_DEC(cnt)   { (cnt)--; GC_ASSERT((cnt) >= 0); }
180 #define GCSTAT_COUNT_MAX(cnt,max) { (cnt)++; if ((cnt) > (max)) (max) = (cnt); }
181
182 extern int gcstat_collections;
183 extern int gcstat_collections_forced;
184 extern int gcstat_mark_depth;
185 extern int gcstat_mark_depth_max;
186 extern int gcstat_mark_count;
187
188 void gcstat_println();
189
190 #else /* defined(ENABLE_STATISTICS) */
191
192 #define GCSTAT_INIT(cnt)
193 #define GCSTAT_COUNT(cnt)
194 #define GCSTAT_DEC(cnt)
195 #define GCSTAT_COUNT_MAX(cnt,max)
196
197 #endif /* defined(ENABLE_STATISTICS) */
198
199
200 #endif /* _GC_H */
201
202 /*
203  * These are local overrides for various environment variables in Emacs.
204  * Please do not remove this and leave it at the end of the file, where
205  * Emacs will automagically detect them.
206  * ---------------------------------------------------------------------
207  * Local variables:
208  * mode: c
209  * indent-tabs-mode: t
210  * c-basic-offset: 4
211  * tab-width: 4
212  * End:
213  * vim:noexpandtab:sw=4:ts=4:
214  */