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
34 #include "mm/memory.h"
35 #include "toolbox/logging.h"
38 /* region_init *****************************************************************
40 Allocates the memory for a heap region and initiates the regioninfo struct
43 *******************************************************************************/
45 void *region_create(regioninfo_t *region, u4 size)
49 /* some sanity check */
52 /* allocate memory for the region */
58 /* initiate structure */
60 region->end = ptr + size;
65 #if defined(ENABLE_THREADS)
66 /* initiate the header for locking */
67 lock_init_object_lock((java_objectheader *) region);
70 #if defined(ENABLE_MEMCHECK)
71 /* poison this region */
72 /* TODO: this should really be done MNEW above! */
73 region_invalidate(region);
76 GC_LOG( dolog("GC: Region allocated at [ %p ; %p ]", region->base, region->end); );
82 u4 region_resize(regioninfo_t *region, u4 size)
88 /* reallocate memory for the region */
89 ptr = MREALLOC(region->base, u1, region->size, size);
92 vm_abort("region_resize: realloc failed!");
94 /* was the region moved? */
95 offset = ptr - region->base;
96 used = region->size - region->free;
98 /* update structure */
100 region->end = ptr + size;
101 region->ptr = ptr + used;
103 region->free = size - used;
105 #if defined(ENABLE_MEMCHECK)
106 /* poison this region */
107 region_invalidate(region);
110 GC_LOG( dolog("GC: Region resized to [ %p ; %p ]", region->base, region->end); );
116 /* region_invalidate ***********************************************************
118 Invalidates the free memory area inside a heap region by overwriting it with
121 REMEMBER: The region has to be compacted for this to work properly.
123 *******************************************************************************/
125 #if defined(ENABLE_MEMCHECK)
126 void region_invalidate(regioninfo_t *region)
128 /* some sanity check */
129 GC_ASSERT(region->free == region->end - region->ptr);
131 /* invalidate free memory */
132 memset(region->ptr, MEMORY_CLEAR_BYTE, region->free);
134 #endif /* defined(ENABLE_MEMCHECK) */
138 * These are local overrides for various environment variables in Emacs.
139 * Please do not remove this and leave it at the end of the file, where
140 * Emacs will automagically detect them.
141 * ---------------------------------------------------------------------
144 * indent-tabs-mode: t
148 * vim:noexpandtab:sw=4:ts=4: