* src/mm/cacao-gc/gc.h: Added GC_EXECUTIONSTATE and GC_SOURCESTATE defines.
[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    Contact: cacao@cacaojvm.org
26
27    Authors: Michael Starzinger
28
29    $Id$
30
31 */
32
33
34 #ifdef GC_CONST
35 # error Why is the BoehmGC header included???
36 #endif
37
38
39 #ifndef _GC_H
40 #define _GC_H
41
42
43 #include "config.h"
44 #include "vm/types.h"
45
46 #if defined(ENABLE_THREADS)
47 # include "threads/native/threads.h"
48 #endif
49
50 #include "vm/jit/replace.h"
51
52
53 /* Configuration Switches *****************************************************/
54
55 #define GCCONF_FINALIZER
56 /*#define GCCONF_HDRFLAG_REFERENCING*/
57
58
59 /* Debugging ******************************************************************/
60
61 #define GC_DEBUGGING
62 /*#define GC_DEBUGGING2*/
63
64 #if !defined(NDEBUG) && defined(GC_DEBUGGING)
65 # include <assert.h>
66 # include "vmcore/options.h"
67 # define GC_LOG(code) if (opt_verbosegc) { code; }
68 # define GC_ASSERT(assertion) assert(assertion)
69 #else
70 # define GC_LOG(code)
71 # define GC_ASSERT(assertion)
72 #endif
73
74 #if !defined(NDEBUG) && defined(GC_DEBUGGING2)
75 # define GC_LOG2(code) GC_LOG(code)
76 #else
77 # define GC_LOG2(code)
78 #endif
79
80
81 /* Development Break **********************************************************/
82
83 #if 0 && defined(ENABLE_THREADS)
84 # error "GC does not work with threads enabled!"
85 #endif
86
87 #if 1 && defined(ENABLE_INTRP)
88 # error "GC does not work with interpreter enabled!"
89 #endif
90
91 #if 1 && defined(ENABLE_JVMTI)
92 # error "GC does not work with JVMTI enabled!"
93 #endif
94
95 #if 1 && !defined(ENABLE_REPLACEMENT)
96 # error "GC does only work with replacement enabled!"
97 #endif
98
99 #if 1 && !defined(__I386__)
100 # error "GC was only ported to i386 so far!"
101 #endif
102
103
104 /* Helper Macros **************************************************************/
105
106 #define GC_SET_FLAGS(obj, flags)   ((obj)->hdrflags |=  (flags))
107 #define GC_CLEAR_FLAGS(obj, flags) ((obj)->hdrflags &= ~(flags))
108 #define GC_TEST_FLAGS(obj, flags)  ((obj)->hdrflags  &  (flags))
109
110 #define POINTS_INTO(ptr, ptr_start, ptr_end) \
111         ((void *) (ptr) >= (ptr_start) && (void *) (ptr) < (ptr_end))
112
113
114 /* Global Variables ***********************************************************/
115
116 extern bool gc_pending;
117 extern bool gc_notify_finalizer;
118
119
120 /* No-Thread specific stuff ***************************************************/
121
122 #if defined(ENABLE_THREADS)
123 # define GC_EXECUTIONSTATE (thread->es)
124 # define GC_SOURCESTATE    (thread->ss)
125 #else
126 # define GC_EXECUTIONSTATE (_no_threads_executionstate)
127 # define GC_SOURCESTATE    (_no_threads_sourcestate)
128
129 extern executionstate_t *_no_threads_executionstate;
130 extern sourcestate_t    *_no_threads_sourcestate;
131
132 #endif
133
134
135 /* Prototypes *****************************************************************/
136
137 #if defined(ENABLE_THREADS)
138 bool gc_suspend(threadobject *thread, u1 *pc, u1 *sp);
139 #endif
140
141
142 /* Statistics *****************************************************************/
143
144 #if defined(ENABLE_STATISTICS)
145
146 #define GCSTAT_INIT(cnt)  { (cnt) = 0; }
147 #define GCSTAT_COUNT(cnt) { (cnt)++; }
148 #define GCSTAT_DEC(cnt)   { (cnt)--; GC_ASSERT((cnt) >= 0); }
149 #define GCSTAT_COUNT_MAX(cnt,max) { (cnt)++; if ((cnt) > (max)) (max) = (cnt); }
150
151 extern int gcstat_mark_depth;
152 extern int gcstat_mark_depth_max;
153 extern int gcstat_mark_count;
154
155 void gcstat_println();
156
157 #endif /* defined(ENABLE_STATISTICS) */
158
159
160 #endif /* _GC_H */
161
162 /*
163  * These are local overrides for various environment variables in Emacs.
164  * Please do not remove this and leave it at the end of the file, where
165  * Emacs will automagically detect them.
166  * ---------------------------------------------------------------------
167  * Local variables:
168  * mode: c
169  * indent-tabs-mode: t
170  * c-basic-offset: 4
171  * tab-width: 4
172  * End:
173  * vim:noexpandtab:sw=4:ts=4:
174  */