1 /* boehm.c *********************************************************************
3 Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
5 See file COPYRIGHT for information on usage and disclaimer of warranties
7 Contains the interface to the Boehm GC
9 Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at
10 Changes: Andi Krall EMAIL: cacao@complang.tuwien.ac.at
11 Mark Probst EMAIL: cacao@complang.tuwien.ac.at
12 Philipp Tomsich EMAIL: cacao@complang.tuwien.ac.at
14 Last Change: $Id: boehm.c 487 2003-10-20 17:23:21Z twisti $
16 *******************************************************************************/
19 #include "threads/thread.h"
24 void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, void *);
26 struct otherstackcall;
28 typedef void *(*calltwoargs)(void *, u4);
30 struct otherstackcall {
36 static void *stackcall_twoargs(struct otherstackcall *p)
38 return (*p->p2)(p->p, p->l);
41 static void *stackcall_malloc(void *p, u4 bytelength)
43 return GC_MALLOC(bytelength);
46 static void *stackcall_malloc_atomic(void *p, u4 bytelength)
48 return GC_MALLOC_ATOMIC(bytelength);
51 static void *stackcall_malloc_uncollectable(void *p, u4 bytelength)
53 return GC_MALLOC_UNCOLLECTABLE(bytelength);
56 static void *stackcall_realloc(void *p, u4 bytelength)
58 return GC_REALLOC(p, bytelength);
62 #define MAINTHREADCALL(r,m,pp,ll) \
63 if (currentThread == NULL || currentThread == mainThread) { \
66 struct otherstackcall sc; \
70 r = (*asm_switchstackandcall)(CONTEXT(mainThread).usedStackTop, \
72 (void**)&(CONTEXT(currentThread).usedStackTop), &sc); \
75 #define MAINTHREADCALL(r,m,pp,ll) \
79 void *heap_alloc_uncollectable(u4 bytelength)
82 MAINTHREADCALL(result, stackcall_malloc_uncollectable, NULL, bytelength);
86 void runboehmfinalizer(void *o, void *p)
88 java_objectheader *ob = (java_objectheader *) o;
89 asm_calljavamethod(ob->vftbl->class->finalizer, ob, NULL, NULL, NULL);
92 void *heap_allocate (u4 bytelength, bool references, methodinfo *finalizer)
96 { MAINTHREADCALL(result, stackcall_malloc, NULL, bytelength); }
98 { MAINTHREADCALL(result, stackcall_malloc_atomic, NULL, bytelength); }
100 GC_REGISTER_FINALIZER(result, runboehmfinalizer, 0, 0, 0);
104 void *heap_reallocate(void *p, u4 bytelength)
107 MAINTHREADCALL(result, stackcall_realloc, p, bytelength);
111 void heap_init (u4 size, u4 startsize, void **stackbottom)
120 void heap_addreference (void **reflocation)
132 if (collectverbose) {
133 sprintf(logtext, "Garbage Collection: previous/now = %d / %d ",
142 * These are local overrides for various environment variables in Emacs.
143 * Please do not remove this and leave it at the end of the file, where
144 * Emacs will automagically detect them.
145 * ---------------------------------------------------------------------
148 * indent-tabs-mode: t