1 /* mm/cacao-gc/region.c - GC module for region management
3 Copyright (C) 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
32 #include "mm/memory.h"
33 #include "toolbox/logging.hpp"
36 /* region_init *****************************************************************
38 Allocates the memory for a heap region and initiates the regioninfo struct
41 *******************************************************************************/
43 void *region_create(regioninfo_t *region, u4 size)
47 /* some sanity check */
50 /* allocate memory for the region */
56 /* initiate structure */
58 region->end = ptr + size;
63 #if defined(ENABLE_THREADS)
64 /* initiate the header for locking */
65 lock_init_object_lock((java_object_t *) region);
68 #if defined(ENABLE_MEMCHECK)
69 /* poison this region */
70 /* TODO: this should really be done MNEW above! */
71 region_invalidate(region);
74 GC_LOG( dolog("GC: Region allocated at [ %p ; %p ]", region->base, region->end); );
80 u4 region_resize(regioninfo_t *region, u4 size)
86 /* reallocate memory for the region */
87 ptr = MREALLOC(region->base, u1, region->size, size);
90 vm_abort("region_resize: realloc failed!");
92 /* was the region moved? */
93 offset = ptr - region->base;
94 used = region->size - region->free;
96 /* update structure */
98 region->end = ptr + size;
99 region->ptr = ptr + used;
101 region->free = size - used;
103 #if defined(ENABLE_MEMCHECK)
104 /* poison this region */
105 region_invalidate(region);
108 GC_LOG( dolog("GC: Region resized to [ %p ; %p ]", region->base, region->end); );
114 /* region_invalidate ***********************************************************
116 Invalidates the free memory area inside a heap region by overwriting it with
119 REMEMBER: The region has to be compacted for this to work properly.
121 *******************************************************************************/
123 #if defined(ENABLE_MEMCHECK)
124 void region_invalidate(regioninfo_t *region)
126 /* some sanity check */
127 GC_ASSERT(region->free == region->end - region->ptr);
129 /* invalidate free memory */
130 memset(region->ptr, MEMORY_CLEAR_BYTE, region->free);
132 #endif /* defined(ENABLE_MEMCHECK) */
136 * These are local overrides for various environment variables in Emacs.
137 * Please do not remove this and leave it at the end of the file, where
138 * Emacs will automagically detect them.
139 * ---------------------------------------------------------------------
142 * indent-tabs-mode: t
146 * vim:noexpandtab:sw=4:ts=4: