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