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
38 #if defined(ENABLE_THREADS)
39 # include "threads/native/threads.h"
41 # include "threads/none/threads.h"
47 #include "mm/memory.h"
48 #include "toolbox/logging.h"
49 #include "vm/exceptions.h"
50 #include "vm/options.h"
53 /* Development Break **********************************************************/
55 #if defined(ENABLE_THREADS)
56 # error "GC does not work with threads enabled!"
59 #if defined(ENABLE_INTRP)
60 # error "GC does not work with interpreter enabled!"
63 #if defined(ENABLE_JVMTI)
64 # error "GC does not work with JVMTI enabled!"
68 /* gc_init *********************************************************************
70 Initializes the garbage collector.
72 *******************************************************************************/
74 void gc_init(u4 heapmaxsize, u4 heapstartsize)
77 dolog("GC: Initialising with heap-size %d (max. %d)",
78 heapstartsize, heapmaxsize);
80 heap_base = malloc(heapstartsize);
82 if (heap_base == NULL)
83 exceptions_throw_outofmemory_exit();
85 /* this is needed for linear allocation */
88 heap_current_size = heapstartsize;
89 heap_maximal_size = heapmaxsize;
90 heap_free_size = heap_current_size;
95 /* gc_call *********************************************************************
97 Forces a full collection of the whole Java Heap.
98 This is the function which is called by System.VMRuntime.gc()
100 *******************************************************************************/
108 dolog("GC: Forced Collection ...");
110 /* TODO: move the following to gc_collect() */
112 /* remember start of dump memory area */
113 dumpsize = dump_size();
115 GC_LOG( heap_println_usage(); );
116 /*GC_LOG( heap_dump_region(heap_base, heap_ptr, false); );*/
118 /* find the rootset for the current thread */
119 rs = DNEW(rootset_t);
120 mark_rootset_from_thread(THREADOBJECT, rs);
122 /* mark the objects considering the given rootset */
124 GC_LOG( heap_dump_region(heap_base, heap_ptr, true); );
126 /* compact the heap */
127 /*compact_me(rs, heap_base, heap_ptr);*/
129 /* TODO: check my return value! */
130 /*heap_increase_size();*/
132 /* free dump memory area */
133 dump_release(dumpsize);
136 dolog("GC: Forced Collection finished.");
140 /* Informational getter functions *********************************************/
142 s8 gc_get_heap_size(void) { return heap_current_size; }
143 s8 gc_get_free_bytes(void) { return heap_free_size; }
144 s8 gc_get_total_bytes(void) { return heap_used_size; }
145 s8 gc_get_max_heap_size(void) { return heap_maximal_size; }
148 /* Thread specific stuff ******************************************************/
150 #if defined(ENABLE_THREADS)
164 * These are local overrides for various environment variables in Emacs.
165 * Please do not remove this and leave it at the end of the file, where
166 * Emacs will automagically detect them.
167 * ---------------------------------------------------------------------
170 * indent-tabs-mode: t
174 * vim:noexpandtab:sw=4:ts=4: