f59032492a1725db170d6a38e76e369e8affd1f6
[cacao.git] / src / mm / nogc.c
1 /* src/mm/nogc.c - allocates memory through malloc (no GC)
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25 */
26
27
28 #include "config.h"
29
30 #include <stdlib.h>
31
32 #if defined(HAVE_SYS_MMAN_H)
33 # include <sys/mman.h>
34 #endif
35
36 #include "vm/types.h"
37
38 #include "boehm-gc/include/gc.h"
39
40 #include "mm/gc.hpp"
41 #include "mm/memory.h"
42
43 #include "toolbox/logging.h"
44
45 #include "vm/builtin.h"
46 #include "vm/exceptions.h"
47 #include "vm/global.h"
48 #include "vm/stringlocal.h"
49 #include "vm/vm.h"
50
51 #include "vmcore/loader.h"
52 #include "vmcore/options.h"
53
54
55 /* global stuff ***************************************************************/
56
57 #define MMAP_HEAPADDRESS    0x10000000  /* try to map the heap to this addr.  */
58 #define ALIGNSIZE           8
59
60 static void *mmapptr = NULL;
61 static int mmapsize = 0;
62 static void *mmaptop = NULL;
63
64
65 void *heap_alloc(u4 size, u4 references, methodinfo *finalizer, bool collect)
66 {
67         void *m;
68
69         mmapptr = (void *) MEMORY_ALIGN((ptrint) mmapptr, ALIGNSIZE);
70         
71         m = mmapptr;
72         mmapptr = (void *) ((ptrint) mmapptr + size);
73
74         if (mmapptr > mmaptop)
75                 vm_abort("heap_alloc: out of memory");
76
77         MSET(m, 0, u1, size);
78
79         return m;
80 }
81
82
83 void *heap_alloc_uncollectable(u4 size)
84 {
85         return heap_alloc(size, false, NULL, false);
86 }
87
88
89 void heap_free(void *p)
90 {
91         /* nop */
92 }
93
94
95
96 void gc_init(u4 heapmaxsize, u4 heapstartsize)
97 {
98         heapmaxsize = MEMORY_ALIGN(heapmaxsize, ALIGNSIZE);
99
100 #if defined(HAVE_MMAP)
101         mmapptr = mmap((void *) MMAP_HEAPADDRESS,
102                                    (size_t) heapmaxsize,
103                                    PROT_READ | PROT_WRITE,
104                                    MAP_PRIVATE |
105 # if defined(MAP_ANONYMOUS)
106                                    MAP_ANONYMOUS,
107 # elif defined(MAP_ANON)
108                                    MAP_ANON,
109 # else
110                                    0,
111 # endif
112                                    -1,
113                                    (off_t) 0);
114
115         if (mmapptr == MAP_FAILED)
116                 vm_abort("gc_init: out of memory");
117 #else
118         mmapptr = malloc(heapmaxsize);
119
120         if (mmapptr == NULL)
121                 vm_abort("gc_init: out of memory");
122 #endif
123
124         mmapsize = heapmaxsize;
125         mmaptop = (void *) ((ptrint) mmapptr + mmapsize);
126 }
127
128
129 void gc_call(void)
130 {
131         log_text("GC call: nothing done...");
132         /* nop */
133 }
134
135
136 s8 gc_get_heap_size(void)
137 {
138         return 0;
139 }
140
141
142 s8 gc_get_free_bytes(void)
143 {
144         return 0;
145 }
146
147
148 s8 gc_get_total_bytes(void)
149 {
150         return 0;
151 }
152
153
154 s8 gc_get_max_heap_size(void)
155 {
156         return 0;
157 }
158
159
160 void gc_invoke_finalizers(void)
161 {
162         /* nop */
163 }
164
165
166 void gc_finalize_all(void)
167 {
168         /* nop */
169 }
170
171
172 /*
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  * ---------------------------------------------------------------------
177  * Local variables:
178  * mode: c
179  * indent-tabs-mode: t
180  * c-basic-offset: 4
181  * tab-width: 4
182  * End:
183  */