1 /* src/mm/gc.hpp - gc independant interface for heap managment
3 Copyright (C) 1996-2005, 2006, 2007, 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
43 * Critical section for the GC.
45 class GCCriticalSection {
47 GCCriticalSection() { enter(); }
48 ~GCCriticalSection() { leave(); }
50 inline static void enter ();
51 inline static void leave ();
52 inline static bool inside();
57 #if defined(ENABLE_GC_CACAO)
58 # include "threads/thread.hpp"
63 * Enters a LLNI critical section which prevents the GC from moving
64 * objects around on the collected heap.
66 * There are no race conditions possible while entering such a critical
67 * section, because each thread only modifies its own thread local flag
68 * and the GC reads the flags while the world is stopped.
70 void GCCriticalSection::enter()
72 #if defined(ENABLE_GC_CACAO)
73 threadobject* t = thread_get_current();
76 assert(t->gc_critical == false);
78 t->gc_critical = true;
83 * Leaves a LLNI critical section and allows the GC to move objects
84 * around on the collected heap again.
86 void GCCriticalSection::leave()
88 #if defined(ENABLE_GC_CACAO)
89 threadobject* t = thread_get_current();
92 assert(t->gc_critical == true);
94 t->gc_critical = false;
100 * Checks if the calling thread is inside a GC critical section.
102 * @return true if inside, false otherwise.
104 bool GCCriticalSection::inside()
106 #if defined(ENABLE_GC_CACAO)
107 threadobject* t = thread_get_current();
108 return t->gc_critical;
117 /* reference types ************************************************************/
120 GC_REFTYPE_THREADOBJECT,
121 GC_REFTYPE_CLASSLOADER,
122 GC_REFTYPE_JNI_GLOBALREF,
123 GC_REFTYPE_FINALIZER,
127 GC_REFTYPE_LOCKRECORD
132 #include "vm/global.h"
133 #include "vm/method.h"
136 /* function prototypes ********************************************************/
142 void gc_init(size_t heapmaxsize, size_t heapstartsize);
144 void* heap_alloc_uncollectable(size_t size);
145 void* heap_alloc(size_t size, int references, methodinfo *finalizer, bool collect);
146 void heap_free(void *p);
148 #if defined(ENABLE_GC_CACAO)
149 void heap_init_objectheader(java_object_t *o, uint32_t size);
150 int32_t heap_get_hashcode(java_object_t *o);
152 void gc_reference_register(java_object_t **ref, int32_t reftype);
153 void gc_reference_unregister(java_object_t **ref);
155 void gc_weakreference_register(java_object_t **ref, int32_t reftype);
156 void gc_weakreference_unregister(java_object_t **ref);
160 int64_t gc_get_heap_size(void);
161 int64_t gc_get_free_bytes(void);
162 int64_t gc_get_total_bytes(void);
163 int64_t gc_get_max_heap_size(void);
164 void gc_invoke_finalizers(void);
165 void gc_finalize_all(void);
166 void* gc_out_of_memory(size_t bytes_requested);
169 /* inlined functions **********************************************************/
171 static inline int32_t heap_hashcode(java_object_t* obj)
173 #if defined(ENABLE_GC_CACAO)
174 return heap_get_hashcode(obj);
176 return (int32_t)(intptr_t) obj;
188 * These are local overrides for various environment variables in Emacs.
189 * Please do not remove this and leave it at the end of the file, where
190 * Emacs will automagically detect them.
191 * ---------------------------------------------------------------------
194 * indent-tabs-mode: t
198 * vim:noexpandtab:sw=4:ts=4: