This commit introduces C++ support.
[cacao.git] / src / mm / gc-common.h
1 /* src/mm/gc-common.h - gc independant interface for heap managment
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
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 #ifndef _GC_COMMON_H
27 #define _GC_COMMON_H
28
29 #include "config.h"
30
31 #include <stdint.h>
32
33 #include "vm/global.h"
34
35 #include "vmcore/method.h"
36
37
38 /* reference types ************************************************************/
39
40 enum {
41         GC_REFTYPE_THREADOBJECT,
42         GC_REFTYPE_CLASSLOADER,
43         GC_REFTYPE_JNI_GLOBALREF,
44         GC_REFTYPE_FINALIZER,
45         GC_REFTYPE_LOCALREF,
46         GC_REFTYPE_STACK,
47         GC_REFTYPE_CLASSREF,
48         GC_REFTYPE_LOCKRECORD
49 };
50
51
52 /* function prototypes ********************************************************/
53
54 void    gc_init(size_t heapmaxsize, size_t heapstartsize);
55
56 void*   heap_alloc_uncollectable(size_t size);
57 void*   heap_alloc(size_t size, int references, methodinfo *finalizer, bool collect);
58 void    heap_free(void *p);
59
60 #if defined(ENABLE_GC_CACAO)
61 void    heap_init_objectheader(java_object_t *o, uint32_t size);
62 int32_t heap_get_hashcode(java_object_t *o);
63
64 void    gc_reference_register(java_object_t **ref, int32_t reftype);
65 void    gc_reference_unregister(java_object_t **ref);
66
67 void    gc_weakreference_register(java_object_t **ref, int32_t reftype);
68 void    gc_weakreference_unregister(java_object_t **ref);
69 #endif
70
71 void    gc_call(void);
72 int64_t gc_get_heap_size(void);
73 int64_t gc_get_free_bytes(void);
74 int64_t gc_get_total_bytes(void);
75 int64_t gc_get_max_heap_size(void);
76 void    gc_invoke_finalizers(void);
77 void    gc_finalize_all(void);
78 void*   gc_out_of_memory(size_t bytes_requested);
79
80
81 /* inlined functions **********************************************************/
82
83 static inline int32_t heap_hashcode(java_object_t *obj)
84 {
85 #if defined(ENABLE_GC_CACAO)
86         return heap_get_hashcode(obj);
87 #else
88         return (int32_t)(intptr_t) obj;
89 #endif
90 }
91
92 #endif /* _GC_COMMON_H */
93
94
95 /*
96  * These are local overrides for various environment variables in Emacs.
97  * Please do not remove this and leave it at the end of the file, where
98  * Emacs will automagically detect them.
99  * ---------------------------------------------------------------------
100  * Local variables:
101  * mode: c
102  * indent-tabs-mode: t
103  * c-basic-offset: 4
104  * tab-width: 4
105  * End:
106  */