CACAO
gc.hpp
Go to the documentation of this file.
1 /* src/mm/gc.hpp - 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_HPP
27 #define _GC_HPP
28 
29 #include <stddef.h> // for size_t
30 #include <stdint.h> // for int32_t, etc.
31 #include "threads/thread.hpp"
32 #include "vm/global.hpp" // for java_object_t
33 
34 class GC {
35 public:
36 };
37 
38 
39 /**
40  * Critical section for the GC.
41  */
43 public:
46 
47  inline static void enter ();
48  inline static void leave ();
49  inline static bool inside();
50 };
51 
52 /**
53  * Enters a LLNI critical section which prevents the GC from moving
54  * objects around on the collected heap.
55  *
56  * There are no race conditions possible while entering such a critical
57  * section, because each thread only modifies its own thread local flag
58  * and the GC reads the flags while the world is stopped.
59  */
61 {
62 #if defined(ENABLE_GC_CACAO)
64 
65  // Sanity check.
66  assert(t->gc_critical == false);
67 
68  t->gc_critical = true;
69 #endif
70 }
71 
72 /**
73  * Leaves a LLNI critical section and allows the GC to move objects
74  * around on the collected heap again.
75  */
77 {
78 #if defined(ENABLE_GC_CACAO)
80 
81  // Sanity check.
82  assert(t->gc_critical == true);
83 
84  t->gc_critical = false;
85 #endif
86 }
87 
88 
89 /**
90  * Checks if the calling thread is inside a GC critical section.
91  *
92  * @return true if inside, false otherwise.
93  */
95 {
96 #if defined(ENABLE_GC_CACAO)
98  return t->gc_critical;
99 #else
100  return true;
101 #endif
102 }
103 
104 /* reference types ************************************************************/
105 
106 enum {
115 };
116 
117 /* function prototypes ********************************************************/
118 
119 void gc_init(size_t heapmaxsize, size_t heapstartsize);
120 
121 void* heap_alloc_uncollectable(size_t size);
122 void* heap_alloc(size_t size, int references, methodinfo *finalizer, bool collect);
123 void heap_free(void *p);
124 
125 #if defined(ENABLE_GC_CACAO)
126 void heap_init_objectheader(java_object_t *o, uint32_t size);
127 int32_t heap_get_hashcode(java_object_t *o);
128 
129 void gc_reference_register(java_object_t **ref, int32_t reftype);
131 
132 void gc_weakreference_register(java_object_t **ref, int32_t reftype);
134 #endif
135 
136 void gc_call(void);
137 int64_t gc_get_heap_size(void);
138 int64_t gc_get_free_bytes(void);
139 int64_t gc_get_total_bytes(void);
140 int64_t gc_get_max_heap_size(void);
141 void gc_invoke_finalizers(void);
142 void gc_finalize_all(void);
143 void* gc_out_of_memory(size_t bytes_requested);
144 
147 
148 /* inlined functions **********************************************************/
149 
150 static inline int32_t heap_hashcode(java_object_t* obj)
151 {
152 #if defined(ENABLE_GC_CACAO)
153  return heap_get_hashcode(obj);
154 #else
155  return (int32_t)(intptr_t) obj;
156 #endif
157 }
158 
159 #endif // _GC_HPP
160 
161 
162 /*
163  * These are local overrides for various environment variables in Emacs.
164  * Please do not remove this and leave it at the end of the file, where
165  * Emacs will automagically detect them.
166  * ---------------------------------------------------------------------
167  * Local variables:
168  * mode: c++
169  * indent-tabs-mode: t
170  * c-basic-offset: 4
171  * tab-width: 4
172  * End:
173  * vim:noexpandtab:sw=4:ts=4:
174  */
void gc_call(void)
Definition: gc.c:492
void gc_unregister_current_thread()
Definition: gc-boehm.cpp:264
void gc_init(u4 heapmaxsize, u4 heapstartsize)
Definition: gc.c:75
void gc_weakreference_unregister(java_object_t **ref)
Definition: gc.c:214
void heap_free(void *p)
Definition: heap.c:366
Definition: gc.hpp:34
void gc_weakreference_register(java_object_t **ref, int32_t reftype)
Definition: gc.c:169
s4 heap_get_hashcode(java_object_t *o)
Definition: heap.c:204
static int32_t heap_hashcode(java_object_t *obj)
Definition: gc.hpp:150
JNIEnv jthread jobject jclass jlong size
Definition: jvmti.h:387
s8 gc_get_free_bytes(void)
Definition: gc.c:553
static void leave()
Leaves a LLNI critical section and allows the GC to move objects around on the collected heap again...
Definition: gc.hpp:76
s8 gc_get_max_heap_size(void)
Definition: gc.c:555
static bool inside()
Checks if the calling thread is inside a GC critical section.
Definition: gc.hpp:94
void * heap_alloc(u4 size, u4 references, methodinfo *finalizer, bool collect)
Definition: heap.c:302
void gc_invoke_finalizers(void)
Definition: gc.c:513
void * heap_alloc_uncollectable(u4 size)
Definition: heap.c:345
static void enter()
Enters a LLNI critical section which prevents the GC from moving objects around on the collected heap...
Definition: gc.hpp:60
Critical section for the GC.
Definition: gc.hpp:42
void gc_finalize_all(void)
Definition: gc.c:535
s8 gc_get_total_bytes(void)
Definition: gc.c:554
void * gc_out_of_memory(size_t bytes_requested)
Definition: gc-boehm.cpp:225
GCCriticalSection()
Definition: gc.hpp:44
void gc_reference_register(java_object_t **ref, int32_t reftype)
Definition: gc.c:164
static threadobject * thread_get_current()
Return the threadobject for the current thread.
Definition: thread-none.hpp:56
s8 gc_get_heap_size(void)
Definition: gc.c:552
void heap_init_objectheader(java_object_t *o, u4 bytelength)
Definition: heap.c:56
~GCCriticalSection()
Definition: gc.hpp:45
void gc_reference_unregister(java_object_t **ref)
Definition: gc.c:209
void gc_register_current_thread()
Definition: gc-boehm.cpp:249