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