* configure.ac: Added check for sys/utsname.h header.
[cacao.git] / src / mm / gc-none.cpp
1 /* src/mm/gc-none.cpp - allocates memory through malloc (no GC)
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <stdlib.h>
29
30 #include "vm/types.h"
31
32 #include "boehm-gc/include/gc.h"
33
34 #include "mm/gc.hpp"
35 #include "mm/memory.hpp"
36
37 #include "toolbox/logging.hpp"
38
39 #include "vm/jit/builtin.hpp"
40 #include "vm/global.h"
41 #include "vm/loader.hpp"
42 #include "vm/options.h"
43 #include "vm/os.hpp"
44 #include "vm/vm.hpp"
45
46
47 /* global stuff ***************************************************************/
48
49 #define MMAP_HEAPADDRESS    0x10000000  /* try to map the heap to this addr.  */
50 #define ALIGNSIZE           8
51
52 static void *mmapptr = NULL;
53 static int mmapsize = 0;
54 static void *mmaptop = NULL;
55
56
57 void* heap_alloc(size_t size, int references, methodinfo *finalizer, bool collect)
58 {
59         void *m;
60
61         mmapptr = (void *) MEMORY_ALIGN((ptrint) mmapptr, ALIGNSIZE);
62         
63         m = mmapptr;
64         mmapptr = (void *) ((ptrint) mmapptr + size);
65
66         if (mmapptr > mmaptop)
67                 vm_abort("heap_alloc: out of memory");
68
69         MSET(m, 0, u1, size);
70
71         return m;
72 }
73
74
75 void* heap_alloc_uncollectable(size_t size)
76 {
77         return heap_alloc(size, false, NULL, false);
78 }
79
80
81 void heap_free(void* p)
82 {
83         /* nop */
84 }
85
86
87
88 void gc_init(size_t heapmaxsize, size_t heapstartsize)
89 {
90         heapmaxsize = MEMORY_ALIGN(heapmaxsize, ALIGNSIZE);
91
92 #if defined(HAVE_MMAP)
93         mmapptr = mmap((void *) MMAP_HEAPADDRESS,
94                                    (size_t) heapmaxsize,
95                                    PROT_READ | PROT_WRITE,
96                                    MAP_PRIVATE |
97 # if defined(MAP_ANONYMOUS)
98                                    MAP_ANONYMOUS,
99 # elif defined(MAP_ANON)
100                                    MAP_ANON,
101 # else
102                                    0,
103 # endif
104                                    -1,
105                                    (off_t) 0);
106
107         if (mmapptr == MAP_FAILED)
108                 vm_abort("gc_init: out of memory");
109 #else
110         mmapptr = malloc(heapmaxsize);
111
112         if (mmapptr == NULL)
113                 vm_abort("gc_init: out of memory");
114 #endif
115
116         mmapsize = heapmaxsize;
117         mmaptop = (void *) ((ptrint) mmapptr + mmapsize);
118 }
119
120
121 void gc_call(void)
122 {
123         log_text("GC call: nothing done...");
124         /* nop */
125 }
126
127
128 s8 gc_get_heap_size(void)
129 {
130         return 0;
131 }
132
133
134 s8 gc_get_free_bytes(void)
135 {
136         return 0;
137 }
138
139
140 s8 gc_get_total_bytes(void)
141 {
142         return 0;
143 }
144
145
146 s8 gc_get_max_heap_size(void)
147 {
148         return 0;
149 }
150
151
152 void gc_invoke_finalizers(void)
153 {
154         /* nop */
155 }
156
157
158 void gc_finalize_all(void)
159 {
160         /* nop */
161 }
162
163
164 /*
165  * These are local overrides for various environment variables in Emacs.
166  * Please do not remove this and leave it at the end of the file, where
167  * Emacs will automagically detect them.
168  * ---------------------------------------------------------------------
169  * Local variables:
170  * mode: c
171  * indent-tabs-mode: t
172  * c-basic-offset: 4
173  * tab-width: 4
174  * End:
175  */