1 /* src/mm/nogc.c - allocates memory through malloc (no GC)
3 Copyright (C) 1996-2005, 2006, 2007 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 #if defined(HAVE_SYS_MMAN_H)
33 # include <sys/mman.h>
38 #include "boehm-gc/include/gc.h"
41 #include "mm/memory.h"
43 #include "toolbox/logging.h"
45 #include "vm/builtin.h"
46 #include "vm/exceptions.h"
47 #include "vm/global.h"
48 #include "vm/stringlocal.h"
51 #include "vmcore/loader.h"
52 #include "vmcore/options.h"
55 /* global stuff ***************************************************************/
57 #define MMAP_HEAPADDRESS 0x10000000 /* try to map the heap to this addr. */
60 static void *mmapptr = NULL;
61 static int mmapsize = 0;
62 static void *mmaptop = NULL;
65 void *heap_alloc(u4 size, u4 references, methodinfo *finalizer, bool collect)
69 mmapptr = (void *) MEMORY_ALIGN((ptrint) mmapptr, ALIGNSIZE);
72 mmapptr = (void *) ((ptrint) mmapptr + size);
74 if (mmapptr > mmaptop)
75 vm_abort("heap_alloc: out of memory");
83 void *heap_alloc_uncollectable(u4 size)
85 return heap_alloc(size, false, NULL, false);
89 void heap_free(void *p)
96 void gc_init(u4 heapmaxsize, u4 heapstartsize)
98 heapmaxsize = MEMORY_ALIGN(heapmaxsize, ALIGNSIZE);
100 #if defined(HAVE_MMAP)
101 mmapptr = mmap((void *) MMAP_HEAPADDRESS,
102 (size_t) heapmaxsize,
103 PROT_READ | PROT_WRITE,
105 # if defined(MAP_ANONYMOUS)
107 # elif defined(MAP_ANON)
115 if (mmapptr == MAP_FAILED)
116 vm_abort("gc_init: out of memory");
118 mmapptr = malloc(heapmaxsize);
121 vm_abort("gc_init: out of memory");
124 mmapsize = heapmaxsize;
125 mmaptop = (void *) ((ptrint) mmapptr + mmapsize);
131 log_text("GC call: nothing done...");
136 s8 gc_get_heap_size(void)
142 s8 gc_get_free_bytes(void)
148 s8 gc_get_total_bytes(void)
154 s8 gc_get_max_heap_size(void)
160 void gc_invoke_finalizers(void)
166 void gc_finalize_all(void)
173 * These are local overrides for various environment variables in Emacs.
174 * Please do not remove this and leave it at the end of the file, where
175 * Emacs will automagically detect them.
176 * ---------------------------------------------------------------------
179 * indent-tabs-mode: t