* src/mm/nogc.c: Fixed includes and exceptions.
[cacao.git] / src / mm / nogc.c
1 /* src/mm/nogc.c - allocates memory through malloc (no GC)
2
3    Copyright (C) 1996-2005, 2006 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    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: nogc.c 7516 2007-03-14 12:00:07Z michi $
32
33 */
34
35
36 #include "config.h"
37
38 #include <stdlib.h>
39 #include <sys/mman.h>
40
41 #include "vm/types.h"
42
43 #include "boehm-gc/include/gc.h"
44
45 #include "mm/gc-common.h"
46 #include "mm/memory.h"
47 #include "toolbox/logging.h"
48 #include "vm/builtin.h"
49 #include "vm/exceptions.h"
50 #include "vm/global.h"
51 #include "vm/stringlocal.h"
52 #include "vmcore/loader.h"
53 #include "vmcore/options.h"
54
55
56 /* global stuff ***************************************************************/
57
58 #define MMAP_HEAPADDRESS    0x10000000  /* try to map the heap to this addr.  */
59 #define ALIGNSIZE           8
60
61 static void *mmapptr = NULL;
62 static int mmapsize = 0;
63 static void *mmaptop = NULL;
64
65
66 void *heap_allocate(u4 size, bool references, methodinfo *finalizer)
67 {
68         void *m;
69
70         mmapptr = (void *) MEMORY_ALIGN((ptrint) mmapptr, ALIGNSIZE);
71         
72         m = mmapptr;
73         mmapptr = (void *) ((ptrint) mmapptr + size);
74
75         if (mmapptr > mmaptop)
76                 vm_abort("heap_allocate: out of memory");
77
78         MSET(m, 0, u1, size);
79
80         return m;
81 }
82
83
84 void *heap_alloc_uncollectable(u4 size)
85 {
86         return heap_allocate(size, false, NULL);
87 }
88
89
90 void heap_free(void *p)
91 {
92         /* nop */
93 }
94
95
96
97 void gc_init(u4 heapmaxsize, u4 heapstartsize)
98 {
99         heapmaxsize = MEMORY_ALIGN(heapmaxsize, ALIGNSIZE);
100
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
118         mmapsize = heapmaxsize;
119         mmaptop = (void *) ((ptrint) mmapptr + mmapsize);
120 }
121
122
123 void gc_call(void)
124 {
125         log_text("GC call: nothing done...");
126         /* nop */
127 }
128
129
130 s8 gc_get_heap_size(void)
131 {
132         return 0;
133 }
134
135
136 s8 gc_get_free_bytes(void)
137 {
138         return 0;
139 }
140
141
142 s8 gc_get_total_bytes(void)
143 {
144         return 0;
145 }
146
147
148 s8 gc_get_max_heap_size(void)
149 {
150         return 0;
151 }
152
153
154 void gc_invoke_finalizers(void)
155 {
156         /* nop */
157 }
158
159
160 void gc_finalize_all(void)
161 {
162         /* nop */
163 }
164
165
166 /*
167  * These are local overrides for various environment variables in Emacs.
168  * Please do not remove this and leave it at the end of the file, where
169  * Emacs will automagically detect them.
170  * ---------------------------------------------------------------------
171  * Local variables:
172  * mode: c
173  * indent-tabs-mode: t
174  * c-basic-offset: 4
175  * tab-width: 4
176  * End:
177  */