1 /* src/mm/cacao-gc/gc.c - main garbage collector methods
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Michael Starzinger
39 #if defined(ENABLE_THREADS)
40 # include "threads/native/threads.h"
42 # include "threads/none/threads.h"
48 #include "mm/memory.h"
49 #include "toolbox/logging.h"
50 #include "vm/exceptions.h"
51 #include "vm/options.h"
54 /* Development Break **********************************************************/
56 #if defined(ENABLE_THREADS)
57 # error "GC does not work with threads enabled!"
60 #if defined(ENABLE_INTRP)
61 # error "GC does not work with interpreter enabled!"
64 #if defined(ENABLE_JVMTI)
65 # error "GC does not work with JVMTI enabled!"
69 /* gc_init *********************************************************************
71 Initializes the garbage collector.
73 *******************************************************************************/
75 void gc_init(u4 heapmaxsize, u4 heapstartsize)
78 dolog("GC: Initialising with heap-size %d (max. %d)",
79 heapstartsize, heapmaxsize);
81 heap_base = malloc(heapstartsize);
83 if (heap_base == NULL)
84 exceptions_throw_outofmemory_exit();
86 /* this is needed for linear allocation */
89 heap_current_size = heapstartsize;
90 heap_maximal_size = heapmaxsize;
91 heap_free_size = heap_current_size;
96 /* gc_call *********************************************************************
98 Forces a full collection of the whole Java Heap.
99 This is the function which is called by System.VMRuntime.gc()
101 *******************************************************************************/
109 dolog("GC: Forced Collection ...");
111 /* TODO: move the following to gc_collect() */
113 /* remember start of dump memory area */
114 dumpsize = dump_size();
116 GC_LOG( heap_println_usage(); );
117 /*GC_LOG( heap_dump_region(heap_base, heap_ptr, false); );*/
119 /* find the rootset for the current thread */
120 rs = DNEW(rootset_t);
121 mark_rootset_from_thread(THREADOBJECT, rs);
123 /* mark the objects considering the given rootset */
125 GC_LOG( heap_dump_region(heap_base, heap_ptr, true); );
127 /* compact the heap */
128 /*compact_me(rs, heap_base, heap_ptr);*/
130 /* TODO: check my return value! */
131 /*heap_increase_size();*/
133 /* free dump memory area */
134 dump_release(dumpsize);
137 dolog("GC: Forced Collection finished.");
141 /* Informational getter functions *********************************************/
143 s8 gc_get_heap_size(void) { return heap_current_size; }
144 s8 gc_get_free_bytes(void) { return heap_free_size; }
145 s8 gc_get_total_bytes(void) { return heap_used_size; }
146 s8 gc_get_max_heap_size(void) { return heap_maximal_size; }
149 /* Thread specific stuff ******************************************************/
151 #if defined(ENABLE_THREADS)
165 * These are local overrides for various environment variables in Emacs.
166 * Please do not remove this and leave it at the end of the file, where
167 * Emacs will automagically detect them.
168 * ---------------------------------------------------------------------
171 * indent-tabs-mode: t
175 * vim:noexpandtab:sw=4:ts=4: