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
34 #if defined(ENABLE_GC_CACAO)
35 # include "threads/thread.hpp"
38 #include "vm/global.h"
39 #include "vm/method.h"
46 // Critical section functions.
47 static void critical_enter(void);
48 static void critical_leave(void);
55 /* reference types ************************************************************/
58 GC_REFTYPE_THREADOBJECT,
59 GC_REFTYPE_CLASSLOADER,
60 GC_REFTYPE_JNI_GLOBALREF,
69 /* function prototypes ********************************************************/
71 void gc_init(size_t heapmaxsize, size_t heapstartsize);
73 void* heap_alloc_uncollectable(size_t size);
74 void* heap_alloc(size_t size, int references, methodinfo *finalizer, bool collect);
75 void heap_free(void *p);
77 #if defined(ENABLE_GC_CACAO)
78 void heap_init_objectheader(java_object_t *o, uint32_t size);
79 int32_t heap_get_hashcode(java_object_t *o);
81 void gc_reference_register(java_object_t **ref, int32_t reftype);
82 void gc_reference_unregister(java_object_t **ref);
84 void gc_weakreference_register(java_object_t **ref, int32_t reftype);
85 void gc_weakreference_unregister(java_object_t **ref);
89 int64_t gc_get_heap_size(void);
90 int64_t gc_get_free_bytes(void);
91 int64_t gc_get_total_bytes(void);
92 int64_t gc_get_max_heap_size(void);
93 void gc_invoke_finalizers(void);
94 void gc_finalize_all(void);
95 void* gc_out_of_memory(size_t bytes_requested);
98 /* inlined functions **********************************************************/
100 static inline int32_t heap_hashcode(java_object_t *obj)
102 #if defined(ENABLE_GC_CACAO)
103 return heap_get_hashcode(obj);
105 return (int32_t)(intptr_t) obj;
113 * Enters a LLNI critical section which prevents the GC from moving
114 * objects around on the collected heap.
116 * There are no race conditions possible while entering such a critical
117 * section, because each thread only modifies its own thread local flag
118 * and the GC reads the flags while the world is stopped.
120 inline void GC::critical_enter()
122 #if defined(ENABLE_GC_CACAO)
126 assert(!t->gc_critical);
127 t->gc_critical = true;
132 * Leaves a LLNI critical section and allows the GC to move objects
133 * around on the collected heap again.
135 inline void GC::critical_leave()
137 #if defined(ENABLE_GC_CACAO)
141 assert(t->gc_critical);
142 t->gc_critical = false;
152 * These are local overrides for various environment variables in Emacs.
153 * Please do not remove this and leave it at the end of the file, where
154 * Emacs will automagically detect them.
155 * ---------------------------------------------------------------------
158 * indent-tabs-mode: t