1 /* src/mm/cacao-gc/gc.h - main garbage collector header
3 Copyright (C) 2006, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
27 # error Why is the BoehmGC header included???
38 #include "threads/thread.h"
40 #include "toolbox/list.h"
41 #include "vm/jit/replace.h"
44 /* Configuration Switches *****************************************************/
46 #define GCCONF_FINALIZER
47 /*#define GCCONF_HDRFLAG_REFERENCING*/
50 /* Debugging ******************************************************************/
53 /*#define GC_DEBUGGING2*/
55 #if !defined(NDEBUG) && defined(GC_DEBUGGING)
57 # include "vmcore/options.h"
58 # define GC_LOG(code) if (opt_verbosegc) { code; }
59 # define GC_ASSERT(assertion) assert(assertion)
62 # define GC_ASSERT(assertion)
65 #if !defined(NDEBUG) && defined(GC_DEBUGGING2)
66 # define GC_LOG2(code) GC_LOG(code)
68 # define GC_LOG2(code)
72 /* Development Break **********************************************************/
74 #if 0 && defined(ENABLE_THREADS)
75 # error "GC does not work with threads enabled!"
78 #if 1 && defined(ENABLE_INTRP)
79 # error "GC does not work with interpreter enabled!"
82 #if 1 && defined(ENABLE_JVMTI)
83 # error "GC does not work with JVMTI enabled!"
86 #if 1 && !defined(ENABLE_REPLACEMENT)
87 # error "GC does only work with replacement enabled!"
90 #if 1 && !defined(ENABLE_HANDLES)
91 # error "GC does only work with handles (indirection cells) enabled!"
94 #if 1 && !defined(__ALPHA__) && !defined(__ARM__) && !defined(__I386__) && !defined(__POWERPC__) && !defined(__X86_64__) && !defined(__M68K__) && !defined(__SPARC_64__)
95 # error "GC was only ported to some architectures so far!"
99 /* Helper Macros **************************************************************/
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))
105 #define POINTS_INTO(ptr, ptr_start, ptr_end) \
106 ((void *) (ptr) >= (ptr_start) && (void *) (ptr) < (ptr_end))
108 #define GC_ALIGN_SIZE SIZEOF_VOID_P
109 #define GC_ALIGN(val,size) ((((val) + (size) - 1) / (size)) * (size))
112 /* Global Variables ***********************************************************/
114 extern bool gc_pending;
115 extern bool gc_notify_finalizer;
117 extern list_t *gc_reflist_strong;
118 extern list_t *gc_reflist_weak;
121 /* Structures *****************************************************************/
123 typedef struct list_gcref_entry_t list_gcref_entry_t;
125 struct list_gcref_entry_t {
134 /* Global GC mutext stuff *****************************************************/
136 #if defined(ENABLE_THREADS)
137 # define GC_MUTEX_LOCK threads_mutex_gc_lock()
138 # define GC_MUTEX_UNLOCK threads_mutex_gc_unlock()
140 # define GC_MUTEX_LOCK
141 # define GC_MUTEX_UNLOCK
145 /* No-Thread specific stuff ***************************************************/
147 #if defined(ENABLE_THREADS)
148 # define GC_EXECUTIONSTATE (thread->es)
149 # define GC_SOURCESTATE (thread->ss)
151 # define GC_EXECUTIONSTATE (_no_threads_executionstate)
152 # define GC_SOURCESTATE (_no_threads_sourcestate)
154 extern executionstate_t *_no_threads_executionstate;
155 extern sourcestate_t *_no_threads_sourcestate;
160 /* Prototypes *****************************************************************/
162 void gc_collect(s4 level);
164 #if defined(ENABLE_THREADS)
165 bool gc_suspend(threadobject *thread, u1 *pc, u1 *sp);
169 /* Statistics *****************************************************************/
171 #if defined(ENABLE_STATISTICS)
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); }
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;
184 void gcstat_println();
186 #else /* defined(ENABLE_STATISTICS) */
188 #define GCSTAT_INIT(cnt)
189 #define GCSTAT_COUNT(cnt)
190 #define GCSTAT_DEC(cnt)
191 #define GCSTAT_COUNT_MAX(cnt,max)
193 #endif /* defined(ENABLE_STATISTICS) */
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 * ---------------------------------------------------------------------
205 * indent-tabs-mode: t
209 * vim:noexpandtab:sw=4:ts=4: