CACAO
gc-none.cpp
Go to the documentation of this file.
1 /* src/mm/gc-none.cpp - allocates memory through malloc (no GC)
2 
3  Copyright (C) 1996-2013
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 #include "vm/types.hpp"
31 
32 #include "boehm-gc/include/gc.h"
33 
34 #include "mm/gc.hpp"
35 #include "mm/memory.hpp"
36 
37 #include "toolbox/logging.hpp"
38 
39 #include "vm/jit/builtin.hpp"
40 #include "vm/global.hpp"
41 #include "vm/loader.hpp"
42 #include "vm/options.hpp"
43 #include "vm/os.hpp"
44 #include "vm/vm.hpp"
45 
46 
47 /* global stuff ***************************************************************/
48 
49 #define MMAP_HEAPADDRESS 0x10000000 /* try to map the heap to this addr. */
50 #define ALIGNSIZE 8
51 
52 static void *mmapptr = NULL;
53 static int mmapsize = 0;
54 static void *mmaptop = NULL;
55 
56 
57 void* heap_alloc(size_t size, int references, methodinfo *finalizer, bool collect)
58 {
59  void *m;
60 
62 
63  m = mmapptr;
64  mmapptr = (void *) ((ptrint) mmapptr + size);
65 
66  if (mmapptr > mmaptop)
67  vm_abort("heap_alloc: out of memory");
68 
69  MSET(m, 0, u1, size);
70 
71  return m;
72 }
73 
74 
76 {
77  return heap_alloc(size, false, NULL, false);
78 }
79 
80 
81 void heap_free(void* p)
82 {
83  /* nop */
84 }
85 
86 
87 
88 void gc_init(size_t heapmaxsize, size_t heapstartsize)
89 {
90  heapmaxsize = MEMORY_ALIGN(heapmaxsize, ALIGNSIZE);
91 
92 #if defined(HAVE_MMAP)
93  mmapptr = mmap((void *) MMAP_HEAPADDRESS,
94  (size_t) heapmaxsize,
95  PROT_READ | PROT_WRITE,
96  MAP_PRIVATE |
97 # if defined(MAP_ANONYMOUS)
98  MAP_ANONYMOUS,
99 # elif defined(MAP_ANON)
100  MAP_ANON,
101 # else
102  0,
103 # endif
104  -1,
105  (off_t) 0);
106 
107  if (mmapptr == MAP_FAILED)
108  vm_abort("gc_init: out of memory");
109 #else
110  mmapptr = malloc(heapmaxsize);
111 
112  if (mmapptr == NULL)
113  vm_abort("gc_init: out of memory");
114 #endif
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 
129 {
130  return 0;
131 }
132 
133 
135 {
136  return 0;
137 }
138 
139 
141 {
142  return 0;
143 }
144 
145 
147 {
148  return 0;
149 }
150 
151 
153 {
154  /* nop */
155 }
156 
157 
158 void gc_finalize_all(void)
159 {
160  /* nop */
161 }
162 
163 
165 {
166  /* nop */
167 }
168 
170 {
171  /* nop */
172 }
173 
174 
175 /*
176  * These are local overrides for various environment variables in Emacs.
177  * Please do not remove this and leave it at the end of the file, where
178  * Emacs will automagically detect them.
179  * ---------------------------------------------------------------------
180  * Local variables:
181  * mode: c++
182  * indent-tabs-mode: t
183  * c-basic-offset: 4
184  * tab-width: 4
185  * End:
186  */
void gc_call(void)
Definition: gc.c:492
static int mmapsize
Definition: gc-none.cpp:53
void gc_unregister_current_thread()
Definition: gc-boehm.cpp:264
void gc_init(u4 heapmaxsize, u4 heapstartsize)
Definition: gc.c:75
#define MSET(ptr, byte, type, num)
Definition: memory.hpp:104
void heap_free(void *p)
Definition: heap.c:366
uint8_t u1
Definition: types.hpp:40
int64_t s8
Definition: types.hpp:48
#define MMAP_HEAPADDRESS
Definition: gc-none.cpp:49
JNIEnv jthread jobject jclass jlong size
Definition: jvmti.h:387
s8 gc_get_free_bytes(void)
Definition: gc.c:553
s8 gc_get_max_heap_size(void)
Definition: gc.c:555
void vm_abort(const char *text,...)
Definition: vm.cpp:2586
void * heap_alloc(u4 size, u4 references, methodinfo *finalizer, bool collect)
Definition: heap.c:302
void gc_invoke_finalizers(void)
Definition: gc.c:513
void * heap_alloc_uncollectable(u4 size)
Definition: heap.c:345
void gc_finalize_all(void)
Definition: gc.c:535
s8 gc_get_total_bytes(void)
Definition: gc.c:554
#define ALIGNSIZE
Definition: gc-none.cpp:50
static void * mmapptr
Definition: gc-none.cpp:52
s8 gc_get_heap_size(void)
Definition: gc.c:552
static void * mmaptop
Definition: gc-none.cpp:54
#define MEMORY_ALIGN(pos, size)
Definition: memory.hpp:37
uintptr_t ptrint
Definition: types.hpp:54
#define log_text(s)
Definition: logging.hpp:170
void gc_register_current_thread()
Definition: gc-boehm.cpp:249