-/* mm/boehm.c - interface for boehm gc
+/* src/mm/boehm.c - interface for boehm gc
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
- R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
- M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
- P. Tomsich, J. Wenninger
+ Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+ R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+ C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+ Institut f. Computersprachen - TU Wien
This file is part of CACAO.
Authors: Stefan Ring
- $Id: boehm.c 862 2004-01-06 23:42:01Z stefan $
+ Changes: Christian Thalinger
+
+ $Id: boehm.c 2896 2005-07-04 20:38:33Z twisti $
*/
+#if defined(USE_THREADS) && defined(NATIVE_THREADS) && defined(__LINUX__)
+#define GC_LINUX_THREADS
+#endif
+#if defined(USE_THREADS) && defined(NATIVE_THREADS) && defined(__IRIX__)
+#define GC_IRIX_THREADS
+#endif
-#include "main.h"
-#include "boehm.h"
-#include "global.h"
-#include "native.h"
-#include "asmpart.h"
-#include "builtin.h"
-#include "threads/thread.h"
-#include "toolbox/loging.h"
+#include "boehm-gc/include/gc.h"
+#include "mm/boehm.h"
-/* this is temporary workaround */
-#if defined(__X86_64__)
-#define GC_DEBUG
+#if defined(USE_THREADS)
+# if defined(NATIVE_THREADS)
+# include "threads/native/threads.h"
+# else
+# include "threads/green/threads.h"
+# endif
#endif
-#include "gc.h"
+#include "toolbox/logging.h"
+#include "vm/options.h"
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
+#include "vm/global.h"
+#include "vm/loader.h"
+#include "vm/stringlocal.h"
+#include "vm/tables.h"
+#include "vm/jit/asmpart.h"
+
+static bool in_gc_out_of_memory = false; /* is GC out of memory? */
-static void *stackcall_twoargs(struct otherstackcall *p)
+
+static void
+#ifdef __GNUC__
+ __attribute__ ((unused))
+#endif
+*stackcall_twoargs(struct otherstackcall *p)
{
return (*p->p2)(p->p, p->l);
}
}
-#ifdef USE_THREADS
+#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
#define MAINTHREADCALL(r,m,pp,ll) \
if (currentThread == NULL || currentThread == mainThread) { \
r = m(pp, ll); \
void runboehmfinalizer(void *o, void *p)
{
java_objectheader *ob = (java_objectheader *) o;
+
asm_calljavafunction(ob->vftbl->class->finalizer, ob, NULL, NULL, NULL);
/* if we had an exception in the finalizer, ignore it */
MAINTHREADCALL(result, stackcall_malloc_atomic, NULL, bytelength);
}
+ if (!result) {
+ return NULL;
+ }
+
if (finalizer)
GC_REGISTER_FINALIZER(result, runboehmfinalizer, 0, 0, 0);
MAINTHREADCALL(result, stackcall_free, p, 0);
}
+static void gc_ignore_warnings(char *msg, GC_word arg)
+{
+}
-void heap_init(u4 size, u4 startsize, void **stackbottom)
+void gc_init(u4 heapmaxsize, u4 heapstartsize)
{
+ size_t heapcurrentsize;
+
GC_INIT();
+
+ /* set the maximal heap size */
+ GC_set_max_heap_size(heapmaxsize);
+
+ /* set the initial heap size */
+ heapcurrentsize = GC_get_heap_size();
+ if (heapstartsize > heapcurrentsize) {
+ GC_expand_hp(heapstartsize - heapcurrentsize);
+ }
+
+ /* define OOM function */
+ GC_oom_fn = gc_out_of_memory;
+
+ /* suppress warnings */
+ GC_set_warn_proc(gc_ignore_warnings);
}
-void heap_close()
+void gc_call(void)
{
+ if (opt_verbosegc)
+ dolog("Garbage Collection: previous/now = %d / %d ",
+ 0, 0);
+
+ GC_gcollect();
}
-void gc_init()
+s8 gc_get_heap_size(void)
{
+ return GC_get_heap_size();
}
-void gc_call()
+s8 gc_get_free_bytes(void)
{
- if (collectverbose)
- dolog("Garbage Collection: previous/now = %d / %d ",
- 0, 0);
+ return GC_get_free_bytes();
+}
- GC_gcollect();
+
+s8 gc_get_max_heap_size(void)
+{
+ return GC_get_max_heap_size();
+}
+
+
+void gc_invoke_finalizers(void)
+{
+ GC_invoke_finalizers();
+}
+
+
+void gc_finalize_all(void)
+{
+ GC_finalize_all();
+}
+
+
+/* gc_out_of_memory ************************************************************
+
+ This function is called when boehm detects that it is OOM.
+
+*******************************************************************************/
+
+void *gc_out_of_memory(size_t bytes_requested)
+{
+ /* if this happens, we are REALLY out of memory */
+
+ if (in_gc_out_of_memory) {
+ /* this is all we can do... */
+ throw_cacao_exception_exit(string_java_lang_InternalError,
+ "Out of memory");
+ }
+
+ in_gc_out_of_memory = true;
+
+ /* try to release some memory */
+
+ gc_call();
+
+ /* now instantiate the exception */
+
+ *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
+
+ in_gc_out_of_memory = false;
+
+ return NULL;
}