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
39 // Critical section functions.
40 static void critical_enter(void);
41 static void critical_leave(void);
46 #if defined(ENABLE_GC_CACAO)
47 # include "threads/thread.hpp"
52 * Enters a LLNI critical section which prevents the GC from moving
53 * objects around on the collected heap.
55 * There are no race conditions possible while entering such a critical
56 * section, because each thread only modifies its own thread local flag
57 * and the GC reads the flags while the world is stopped.
59 inline void GC::critical_enter()
61 #if defined(ENABLE_GC_CACAO)
65 assert(!t->gc_critical);
66 t->gc_critical = true;
71 * Leaves a LLNI critical section and allows the GC to move objects
72 * around on the collected heap again.
74 inline void GC::critical_leave()
76 #if defined(ENABLE_GC_CACAO)
80 assert(t->gc_critical);
81 t->gc_critical = false;
88 /* reference types ************************************************************/
91 GC_REFTYPE_THREADOBJECT,
92 GC_REFTYPE_CLASSLOADER,
93 GC_REFTYPE_JNI_GLOBALREF,
103 #include "vm/global.h"
104 #include "vm/method.h"
107 /* function prototypes ********************************************************/
113 void gc_init(size_t heapmaxsize, size_t heapstartsize);
115 void* heap_alloc_uncollectable(size_t size);
116 void* heap_alloc(size_t size, int references, methodinfo *finalizer, bool collect);
117 void heap_free(void *p);
119 #if defined(ENABLE_GC_CACAO)
120 void heap_init_objectheader(java_object_t *o, uint32_t size);
121 int32_t heap_get_hashcode(java_object_t *o);
123 void gc_reference_register(java_object_t **ref, int32_t reftype);
124 void gc_reference_unregister(java_object_t **ref);
126 void gc_weakreference_register(java_object_t **ref, int32_t reftype);
127 void gc_weakreference_unregister(java_object_t **ref);
131 int64_t gc_get_heap_size(void);
132 int64_t gc_get_free_bytes(void);
133 int64_t gc_get_total_bytes(void);
134 int64_t gc_get_max_heap_size(void);
135 void gc_invoke_finalizers(void);
136 void gc_finalize_all(void);
137 void* gc_out_of_memory(size_t bytes_requested);
140 /* inlined functions **********************************************************/
142 static inline int32_t heap_hashcode(java_object_t* obj)
144 #if defined(ENABLE_GC_CACAO)
145 return heap_get_hashcode(obj);
147 return (int32_t)(intptr_t) obj;
159 * These are local overrides for various environment variables in Emacs.
160 * Please do not remove this and leave it at the end of the file, where
161 * Emacs will automagically detect them.
162 * ---------------------------------------------------------------------
165 * indent-tabs-mode: t
169 * vim:noexpandtab:sw=4:ts=4: