86d3951ff84635b8b622c689655990ee26751455
[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 5868 2006-10-30 11:21:36Z edwin $
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/boehm.h"
46 #include "mm/memory.h"
47 #include "toolbox/logging.h"
48 #include "vm/options.h"
49 #include "vm/builtin.h"
50 #include "vm/exceptions.h"
51 #include "vm/global.h"
52 #include "vm/loader.h"
53 #include "vm/stringlocal.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                 exceptions_throw_outofmemory_exit();
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 *nogc_realloc(void *src, s4 len1, s4 len2)
91 {
92         void *p;
93
94         p = heap_allocate(len2, false, NULL);
95
96         MCOPY(p, src, u1, len1);
97
98         return p;
99 }
100
101
102 void heap_free(void *p)
103 {
104         /* nop */
105 }
106
107
108
109 void nogc_init(u4 heapmaxsize, u4 heapstartsize)
110 {
111         heapmaxsize = MEMORY_ALIGN(heapmaxsize, ALIGNSIZE);
112
113         mmapptr = mmap((void *) MMAP_HEAPADDRESS,
114                                    (size_t) heapmaxsize,
115                                    PROT_READ | PROT_WRITE,
116                                    MAP_PRIVATE | MAP_ANONYMOUS,
117                                    -1,
118                                    (off_t) 0);
119
120         if (mmapptr == MAP_FAILED)
121                 exceptions_throw_outofmemory_exit();
122
123         mmapsize = heapmaxsize;
124         mmaptop = (void *) ((ptrint) mmapptr + mmapsize);
125 }
126
127
128 void gc_init(u4 heapmaxsize, u4 heapstartsize)
129 {
130         /* nop */
131 }
132
133
134 void gc_call(void)
135 {
136         log_text("GC call: nothing done...");
137         /* nop */
138 }
139
140
141 s8 gc_get_heap_size(void)
142 {
143         return 0;
144 }
145
146
147 s8 gc_get_free_bytes(void)
148 {
149         return 0;
150 }
151
152
153 s8 gc_get_max_heap_size(void)
154 {
155         return 0;
156 }
157
158
159 void gc_invoke_finalizers(void)
160 {
161         /* nop */
162 }
163
164
165 void gc_finalize_all(void)
166 {
167         /* nop */
168 }
169
170
171 /*
172  * These are local overrides for various environment variables in Emacs.
173  * Please do not remove this and leave it at the end of the file, where
174  * Emacs will automagically detect them.
175  * ---------------------------------------------------------------------
176  * Local variables:
177  * mode: c
178  * indent-tabs-mode: t
179  * c-basic-offset: 4
180  * tab-width: 4
181  * End:
182  */