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 256 2003-03-17 11:48:18Z stefan $
16 *******************************************************************************/
19 #include "threads/thread.h"
23 void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, void *);
25 struct otherstackcall;
27 typedef void *(*calltwoargs)(void *, u4);
29 struct otherstackcall {
35 static void *stackcall_twoargs(struct otherstackcall *p)
37 return (*p->p2)(p->p, p->l);
40 static void *stackcall_malloc(void *p, u4 bytelength)
42 return GC_MALLOC(bytelength);
45 static void *stackcall_malloc_atomic(void *p, u4 bytelength)
47 return GC_MALLOC_ATOMIC(bytelength);
50 static void *stackcall_malloc_uncollectable(void *p, u4 bytelength)
52 return GC_MALLOC_UNCOLLECTABLE(bytelength);
55 static void *stackcall_realloc(void *p, u4 bytelength)
57 return GC_REALLOC(p, bytelength);
61 #define MAINTHREADCALL(r,m,pp,ll) \
62 if (currentThread == NULL || currentThread == mainThread) { \
65 struct otherstackcall sc; \
69 r = (*asm_switchstackandcall)(CONTEXT(mainThread).usedStackTop, \
71 (void**)&(CONTEXT(currentThread).usedStackTop), &sc); \
74 #define MAINTHREADCALL(r,m,pp,ll) \
78 void *heap_alloc_uncollectable(u4 bytelength)
81 MAINTHREADCALL(result, stackcall_malloc_uncollectable, NULL, bytelength);
85 void runboehmfinalizer(void *o, void *p)
87 java_objectheader *ob = (java_objectheader *) o;
88 asm_calljavamethod(ob->vftbl->class->finalizer, ob, NULL, NULL, NULL);
91 void *heap_allocate (u4 bytelength, bool references, methodinfo *finalizer)
95 { MAINTHREADCALL(result, stackcall_malloc, NULL, bytelength); }
97 { MAINTHREADCALL(result, stackcall_malloc_atomic, NULL, bytelength); }
99 GC_REGISTER_FINALIZER(result, runboehmfinalizer, 0, 0, 0);
103 void *heap_reallocate(void *p, u4 bytelength)
106 MAINTHREADCALL(result, stackcall_realloc, p, bytelength);
110 void heap_init (u4 size, u4 startsize, void **stackbottom)
118 void heap_addreference (void **reflocation)
134 * These are local overrides for various environment variables in Emacs.
135 * Please do not remove this and leave it at the end of the file, where
136 * Emacs will automagically detect them.
137 * ---------------------------------------------------------------------
140 * indent-tabs-mode: t