No finalizers yet
[cacao.git] / src / mm / boehm.c
1 /* boehm.c *********************************************************************
2
3         Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
4
5         See file COPYRIGHT for information on usage and disclaimer of warranties
6
7         Contains main() and variables for the global options.
8         This module does the following tasks:
9            - Interface to the Boehm GC
10
11         Authors: Reinhard Grafl      EMAIL: cacao@complang.tuwien.ac.at
12         Changes: Andi Krall          EMAIL: cacao@complang.tuwien.ac.at
13                  Mark Probst         EMAIL: cacao@complang.tuwien.ac.at
14                          Philipp Tomsich     EMAIL: cacao@complang.tuwien.ac.at
15
16         Last Change: $Id: boehm.c 210 2003-02-03 13:05:24Z stefan $
17
18 *******************************************************************************/
19
20 #include "global.h"
21 #include "threads/thread.h"
22
23 #include "gc.h"
24
25 void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, void *);
26
27 struct otherstackcall;
28
29 typedef void *(*calltwoargs)(void *, u4);
30
31 struct otherstackcall {
32         calltwoargs p2;
33         void *p;
34         u4 l;
35 };
36
37 static void *stackcall_twoargs(struct otherstackcall *p)
38 {
39         return (*p->p2)(p->p, p->l);
40 }
41
42 static void *stackcall_malloc(void *p, u4 bytelength)
43 {
44         return GC_MALLOC(bytelength);
45 }
46
47 static void *stackcall_malloc_atomic(void *p, u4 bytelength)
48 {
49         return GC_MALLOC_ATOMIC(bytelength);
50 }
51
52 static void *stackcall_malloc_uncollectable(void *p, u4 bytelength)
53 {
54         return GC_MALLOC_UNCOLLECTABLE(bytelength);
55 }
56
57 static void *stackcall_realloc(void *p, u4 bytelength)
58 {
59         return GC_REALLOC(p, bytelength);
60 }
61
62 #define MAINTHREADCALL(r,m,pp,ll) \
63         if (currentThread == NULL || currentThread == mainThread) { \
64                 r = m(pp, ll); \
65         } else { \
66                 struct otherstackcall sc; \
67                 sc.p2 = m; \
68                 sc.p = pp; \
69                 sc.l = ll; \
70                 r = (*asm_switchstackandcall)(CONTEXT(mainThread).usedStackTop, \
71                                 stackcall_twoargs, \
72                                 (void**)&(CONTEXT(currentThread).usedStackTop), &sc); \
73         }
74
75 void *heap_alloc_uncollectable(u4 bytelength)
76 {
77         void *result;
78         MAINTHREADCALL(result, stackcall_malloc_uncollectable, NULL, bytelength);
79         return result;
80 }
81
82 void *heap_allocate (u4 bytelength, bool references, methodinfo *finalizer)
83 {
84         void *result;
85         if (references, 1)
86                 { MAINTHREADCALL(result, stackcall_malloc, NULL, bytelength); }
87         else
88                 { MAINTHREADCALL(result, stackcall_malloc_atomic, NULL, bytelength); }
89         return (u1*) result;
90 }
91
92 void *heap_reallocate(void *p, u4 bytelength)
93 {
94         void *result;
95         MAINTHREADCALL(result, stackcall_realloc, p, bytelength);
96         return result;
97 }
98
99 void heap_init (u4 size, u4 startsize, void **stackbottom)
100 {
101 }
102
103 void heap_close()
104 {
105 }
106
107 void heap_addreference (void **reflocation)
108 {
109 }
110
111 int collectverbose;
112
113 void gc_init()
114 {
115 }
116
117 void gc_call()
118 {
119         GC_gcollect();
120 }
121
122 /*
123  * These are local overrides for various environment variables in Emacs.
124  * Please do not remove this and leave it at the end of the file, where
125  * Emacs will automagically detect them.
126  * ---------------------------------------------------------------------
127  * Local variables:
128  * mode: c
129  * indent-tabs-mode: t
130  * c-basic-offset: 4
131  * tab-width: 4
132  * End:
133  */