9ea7fefba726eebacc92df63c5a80f6da6495729
[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    $Id: nogc.c 8168 2007-06-30 12:20:48Z twisti $
26
27 */
28
29
30 #include "config.h"
31
32 #include <stdlib.h>
33 #include <sys/mman.h>
34
35 #include "vm/types.h"
36
37 #include "boehm-gc/include/gc.h"
38
39 #include "mm/gc-common.h"
40 #include "mm/memory.h"
41
42 #include "toolbox/logging.h"
43
44 #include "vm/builtin.h"
45 #include "vm/exceptions.h"
46 #include "vm/global.h"
47 #include "vm/stringlocal.h"
48 #include "vm/vm.h"
49
50 #include "vmcore/loader.h"
51 #include "vmcore/options.h"
52
53
54 /* global stuff ***************************************************************/
55
56 #define MMAP_HEAPADDRESS    0x10000000  /* try to map the heap to this addr.  */
57 #define ALIGNSIZE           8
58
59 static void *mmapptr = NULL;
60 static int mmapsize = 0;
61 static void *mmaptop = NULL;
62
63
64 void *heap_allocate(u4 size, bool references, methodinfo *finalizer)
65 {
66         void *m;
67
68         mmapptr = (void *) MEMORY_ALIGN((ptrint) mmapptr, ALIGNSIZE);
69         
70         m = mmapptr;
71         mmapptr = (void *) ((ptrint) mmapptr + size);
72
73         if (mmapptr > mmaptop)
74                 vm_abort("heap_allocate: out of memory");
75
76         MSET(m, 0, u1, size);
77
78         return m;
79 }
80
81
82 void *heap_alloc_uncollectable(u4 size)
83 {
84         return heap_allocate(size, false, NULL);
85 }
86
87
88 void heap_free(void *p)
89 {
90         /* nop */
91 }
92
93
94
95 void gc_init(u4 heapmaxsize, u4 heapstartsize)
96 {
97         heapmaxsize = MEMORY_ALIGN(heapmaxsize, ALIGNSIZE);
98
99         mmapptr = mmap((void *) MMAP_HEAPADDRESS,
100                                    (size_t) heapmaxsize,
101                                    PROT_READ | PROT_WRITE,
102                                    MAP_PRIVATE |
103 # if defined(MAP_ANONYMOUS)
104                                    MAP_ANONYMOUS,
105 # elif defined(MAP_ANON)
106                                    MAP_ANON,
107 # else
108                                    0,
109 # endif
110                                    -1,
111                                    (off_t) 0);
112
113         if (mmapptr == MAP_FAILED)
114                 vm_abort("gc_init: out of memory");
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  */