/* src/mm/boehm.c - interface for boehm gc
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ Copyright (C) 1996-2005, 2006, 2007 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
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Contact: cacao@cacaojvm.org
-
- Authors: Stefan Ring
-
- Changes: Christian Thalinger
-
- $Id: boehm.c 4921 2006-05-15 14:24:36Z twisti $
-
*/
#endif
#include "boehm-gc/include/gc.h"
-#include "mm/boehm.h"
+#include "mm/gc-common.h"
#include "mm/memory.h"
-#if defined(ENABLE_THREADS)
-# include "threads/native/threads.h"
-#endif
-
#include "toolbox/logging.h"
-#include "vm/options.h"
+
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/finalizer.h"
#include "vm/global.h"
-#include "vm/loader.h"
#include "vm/stringlocal.h"
-#include "vm/jit/asmpart.h"
+#include "vm/vm.h"
+
+#include "vmcore/loader.h"
+#include "vmcore/options.h"
/* global variables ***********************************************************/
{
size_t heapcurrentsize;
- GC_INIT();
+ /* just to be sure (should be set to 1 by JAVA_FINALIZATION macro) */
- /* set the maximal heap size */
+ GC_java_finalization = 1;
- GC_set_max_heap_size(heapmaxsize);
+ /* Ignore pointers that do not point to the start of an object. */
- /* set the initial heap size */
+ GC_all_interior_pointers = 0;
- heapcurrentsize = GC_get_heap_size();
+ /* suppress warnings */
- if (heapstartsize > heapcurrentsize) {
- GC_expand_hp(heapstartsize - heapcurrentsize);
- }
+ GC_set_warn_proc(gc_ignore_warnings);
+
+ /* install a GC notifier */
+
+ GC_finalize_on_demand = 1;
+ GC_finalizer_notifier = finalizer_notify;
/* define OOM function */
GC_oom_fn = gc_out_of_memory;
- /* just to be sure (should be set to 1 by JAVA_FINALIZATION macro) */
+ GC_INIT();
- GC_java_finalization = 1;
+ /* set the maximal heap size */
- /* suppress warnings */
+ GC_set_max_heap_size(heapmaxsize);
- GC_set_warn_proc(gc_ignore_warnings);
+ /* set the initial heap size */
- /* install a GC notifier */
+ heapcurrentsize = GC_get_heap_size();
- GC_finalize_on_demand = 1;
- GC_finalizer_notifier = finalizer_notify;
+ if (heapstartsize > heapcurrentsize)
+ GC_expand_hp(heapstartsize - heapcurrentsize);
}
{
}
-static void *stackcall_malloc_atomic(void *p, u4 bytelength)
-{
- return GC_MALLOC_ATOMIC(bytelength);
-}
-
-
-static void *stackcall_malloc_uncollectable(void *p, u4 bytelength)
-{
- return GC_MALLOC_UNCOLLECTABLE(bytelength);
-}
-
void *heap_alloc_uncollectable(u4 bytelength)
{
- void *result;
+ void *p;
- result = stackcall_malloc_uncollectable(NULL, bytelength);
+ p = GC_MALLOC_UNCOLLECTABLE(bytelength);
/* clear allocated memory region */
- MSET(result, 0, u1, bytelength);
+ MSET(p, 0, u1, bytelength);
- return result;
+ return p;
}
-void *heap_allocate(u4 bytelength, bool references, methodinfo *finalizer)
+/* heap_allocate ***************************************************************
+
+ Allocates memory on the Java heap.
+
+*******************************************************************************/
+
+void *heap_allocate(u4 bytelength, u4 references, methodinfo *finalizer)
{
- void *result;
+ void *p;
+
+ /* We can't use a bool here for references, as it's passed as a
+ bitmask in builtin_new. Thus we check for != 0. */
- if (references)
- result = GC_MALLOC(bytelength);
+ if (references != 0)
+ p = GC_MALLOC(bytelength);
else
- result = stackcall_malloc_atomic(NULL, bytelength);
+ p = GC_MALLOC_ATOMIC(bytelength);
- if (!result)
+ if (p == NULL)
return NULL;
- if (finalizer)
- GC_REGISTER_FINALIZER(result, finalizer_run, 0, 0, 0);
+ if (finalizer != NULL)
+ GC_REGISTER_FINALIZER_NO_ORDER(p, finalizer_run, 0, 0, 0);
/* clear allocated memory region */
- MSET(result, 0, u1, bytelength);
+ MSET(p, 0, u1, bytelength);
- return (u1 *) result;
+ return p;
}
}
+/* gc_get_total_bytes **********************************************************
+
+ Returns the number of total bytes currently used on the Java heap.
+
+*******************************************************************************/
+
+s8 gc_get_total_bytes(void)
+{
+ return GC_get_total_bytes();
+}
+
+
s8 gc_get_max_heap_size(void)
{
return GC_get_max_heap_size();
if (in_gc_out_of_memory) {
/* this is all we can do... */
- exceptions_throw_outofmemory_exit();
+ vm_abort("gc_out_of_memory: out of memory");
}
in_gc_out_of_memory = true;
/* now instantiate the exception */
- *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
+ exceptions_throw_outofmemoryerror();
in_gc_out_of_memory = false;