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