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