* Dummy commit to fix conversion problems with some files.
[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    $Id$
26
27 */
28
29
30 #ifdef GC_CONST
31 # error Why is the BoehmGC header included???
32 #endif
33
34
35 #ifndef _GC_H
36 #define _GC_H
37
38
39 #include "config.h"
40 #include "vm/types.h"
41
42 #if defined(ENABLE_THREADS)
43 # include "threads/native/threads.h"
44 #endif
45
46 #include "toolbox/list.h"
47 #include "vm/jit/replace.h"
48
49
50 /* Configuration Switches *****************************************************/
51
52 #define GCCONF_FINALIZER
53 /*#define GCCONF_HDRFLAG_REFERENCING*/
54
55
56 /* Debugging ******************************************************************/
57
58 #define GC_DEBUGGING
59 /*#define GC_DEBUGGING2*/
60
61 #if !defined(NDEBUG) && defined(GC_DEBUGGING)
62 # include <assert.h>
63 # include "vmcore/options.h"
64 # define GC_LOG(code) if (opt_verbosegc) { code; }
65 # define GC_ASSERT(assertion) assert(assertion)
66 #else
67 # define GC_LOG(code)
68 # define GC_ASSERT(assertion)
69 #endif
70
71 #if !defined(NDEBUG) && defined(GC_DEBUGGING2)
72 # define GC_LOG2(code) GC_LOG(code)
73 #else
74 # define GC_LOG2(code)
75 #endif
76
77
78 /* Development Break **********************************************************/
79
80 #if 0 && defined(ENABLE_THREADS)
81 # error "GC does not work with threads enabled!"
82 #endif
83
84 #if 1 && defined(ENABLE_INTRP)
85 # error "GC does not work with interpreter enabled!"
86 #endif
87
88 #if 1 && defined(ENABLE_JVMTI)
89 # error "GC does not work with JVMTI enabled!"
90 #endif
91
92 #if 1 && !defined(ENABLE_REPLACEMENT)
93 # error "GC does only work with replacement enabled!"
94 #endif
95
96 #if 1 && !defined(ENABLE_HANDLES)
97 # error "GC does only work with handles (indirection cells) enabled!"
98 #endif
99
100 #if 1 && !defined(__ALPHA__) && !defined(__ARM__) && !defined(__I386__) && !defined(__POWERPC__) && !defined(__X86_64__) && !defined(__M68K__) && !defined(__SPARC_64__)
101 # error "GC was only ported to some architectures so far!"
102 #endif
103
104
105 /* Helper Macros **************************************************************/
106
107 #define GC_SET_FLAGS(obj, flags)   ((obj)->hdrflags |=  (flags))
108 #define GC_CLEAR_FLAGS(obj, flags) ((obj)->hdrflags &= ~(flags))
109 #define GC_TEST_FLAGS(obj, flags)  ((obj)->hdrflags  &  (flags))
110
111 #define POINTS_INTO(ptr, ptr_start, ptr_end) \
112         ((void *) (ptr) >= (ptr_start) && (void *) (ptr) < (ptr_end))
113
114 #define GC_ALIGN_SIZE SIZEOF_VOID_P
115 #define GC_ALIGN(val,size) ((((val) + (size) - 1) / (size)) * (size))
116
117
118 /* Global Variables ***********************************************************/
119
120 extern bool gc_pending;
121 extern bool gc_notify_finalizer;
122
123 extern list_t *gc_reflist;
124
125
126 /* Structures *****************************************************************/
127
128 typedef struct list_gcref_entry_t list_gcref_entry_t;
129
130 struct list_gcref_entry_t {
131         listnode_t      linkage;
132         java_object_t **ref;
133 #if !defined(NDEBUG)
134         s4              reftype;
135 #endif
136 };
137
138
139 /* No-Thread specific stuff ***************************************************/
140
141 #if defined(ENABLE_THREADS)
142 # define GC_EXECUTIONSTATE (thread->es)
143 # define GC_SOURCESTATE    (thread->ss)
144 #else
145 # define GC_EXECUTIONSTATE (_no_threads_executionstate)
146 # define GC_SOURCESTATE    (_no_threads_sourcestate)
147
148 extern executionstate_t *_no_threads_executionstate;
149 extern sourcestate_t    *_no_threads_sourcestate;
150
151 #endif
152
153
154 /* Prototypes *****************************************************************/
155
156 void gc_collect(s4 level);
157
158 #if defined(ENABLE_THREADS)
159 bool gc_suspend(threadobject *thread, u1 *pc, u1 *sp);
160 #endif
161
162
163 /* Statistics *****************************************************************/
164
165 #if defined(ENABLE_STATISTICS)
166
167 #define GCSTAT_INIT(cnt)  { (cnt) = 0; }
168 #define GCSTAT_COUNT(cnt) { (cnt)++; }
169 #define GCSTAT_DEC(cnt)   { (cnt)--; GC_ASSERT((cnt) >= 0); }
170 #define GCSTAT_COUNT_MAX(cnt,max) { (cnt)++; if ((cnt) > (max)) (max) = (cnt); }
171
172 extern int gcstat_collections;
173 extern int gcstat_collections_forced;
174 extern int gcstat_mark_depth;
175 extern int gcstat_mark_depth_max;
176 extern int gcstat_mark_count;
177
178 void gcstat_println();
179
180 #else /* defined(ENABLE_STATISTICS) */
181
182 #define GCSTAT_INIT(cnt)
183 #define GCSTAT_COUNT(cnt)
184 #define GCSTAT_DEC(cnt)
185 #define GCSTAT_COUNT_MAX(cnt,max)
186
187 #endif /* defined(ENABLE_STATISTICS) */
188
189
190 #endif /* _GC_H */
191
192 /*
193  * These are local overrides for various environment variables in Emacs.
194  * Please do not remove this and leave it at the end of the file, where
195  * Emacs will automagically detect them.
196  * ---------------------------------------------------------------------
197  * Local variables:
198  * mode: c
199  * indent-tabs-mode: t
200  * c-basic-offset: 4
201  * tab-width: 4
202  * End:
203  * vim:noexpandtab:sw=4:ts=4:
204  */