1 /* mm/boehm.c - interface for boehm gc
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5 M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6 P. Tomsich, J. Wenninger
8 This file is part of CACAO.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
29 $Id: boehm.c 838 2004-01-05 00:27:00Z twisti $
39 #include "threads/thread.h"
40 #include "toolbox/loging.h"
42 /* this is temporary workaround */
43 #if defined(__X86_64__)
50 static void *stackcall_twoargs(struct otherstackcall *p)
52 return (*p->p2)(p->p, p->l);
56 static void *stackcall_malloc(void *p, u4 bytelength)
58 return GC_MALLOC(bytelength);
62 static void *stackcall_malloc_atomic(void *p, u4 bytelength)
64 return GC_MALLOC_ATOMIC(bytelength);
68 static void *stackcall_malloc_uncollectable(void *p, u4 bytelength)
70 return GC_MALLOC_UNCOLLECTABLE(bytelength);
74 static void *stackcall_realloc(void *p, u4 bytelength)
76 return GC_REALLOC(p, bytelength);
79 static void *stackcall_free(void *p, u4 bytelength)
87 #define MAINTHREADCALL(r,m,pp,ll) \
88 if (currentThread == NULL || currentThread == mainThread) { \
91 struct otherstackcall sc; \
95 r = (*asm_switchstackandcall)(CONTEXT(mainThread).usedStackTop, \
97 (void**)&(CONTEXT(currentThread).usedStackTop), &sc); \
100 #define MAINTHREADCALL(r,m,pp,ll) \
105 void *heap_alloc_uncollectable(u4 bytelength)
108 MAINTHREADCALL(result, stackcall_malloc_uncollectable, NULL, bytelength);
113 void runboehmfinalizer(void *o, void *p)
115 java_objectheader *ob = (java_objectheader *) o;
116 asm_calljavafunction(ob->vftbl->class->finalizer, ob, NULL, NULL, NULL);
118 /* if we had an exception in the finalizer, ignore it */
123 void *heap_allocate(u4 bytelength, bool references, methodinfo *finalizer)
128 MAINTHREADCALL(result, stackcall_malloc, NULL, bytelength);
131 MAINTHREADCALL(result, stackcall_malloc_atomic, NULL, bytelength);
135 GC_REGISTER_FINALIZER(result, runboehmfinalizer, 0, 0, 0);
141 void *heap_reallocate(void *p, u4 bytelength)
145 MAINTHREADCALL(result, stackcall_realloc, p, bytelength);
150 void heap_free(void *p)
154 MAINTHREADCALL(result, stackcall_free, p, 0);
158 void heap_init(u4 size, u4 startsize, void **stackbottom)
177 dolog("Garbage Collection: previous/now = %d / %d ",
185 * These are local overrides for various environment variables in Emacs.
186 * Please do not remove this and leave it at the end of the file, where
187 * Emacs will automagically detect them.
188 * ---------------------------------------------------------------------
191 * indent-tabs-mode: t