Merged with tip.
[cacao.git] / src / mm / cacao-gc / gc.h
index 760ae51f90903b2caed006ca6e816a3e0938bac2..31060381d73868057a9a8dcbfb33960a0ee6cf40 100644 (file)
@@ -1,9 +1,7 @@
 /* src/mm/cacao-gc/gc.h - main garbage collector header
 
-   Copyright (C) 2006 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
+   Copyright (C) 2006, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Michael Starzinger
-
-   $Id$
-
 */
 
 
 #include "config.h"
 #include "vm/types.h"
 
-#if defined(ENABLE_THREADS)
-# include "threads/native/threads.h"
-#endif
+#include "threads/thread.h"
 
+#include "toolbox/list.h"
 #include "vm/jit/replace.h"
 
 
 # error "GC does only work with replacement enabled!"
 #endif
 
-#if 1 && !defined(__I386__)
-# error "GC was only ported to i386 so far!"
+#if 1 && !defined(ENABLE_HANDLES)
+# error "GC does only work with handles (indirection cells) enabled!"
+#endif
+
+#if 1 && !defined(__ALPHA__) && !defined(__ARM__) && !defined(__I386__) && !defined(__POWERPC__) && !defined(__X86_64__) && !defined(__M68K__) && !defined(__SPARC_64__)
+# error "GC was only ported to some architectures so far!"
 #endif
 
 
 #define POINTS_INTO(ptr, ptr_start, ptr_end) \
        ((void *) (ptr) >= (ptr_start) && (void *) (ptr) < (ptr_end))
 
+#define GC_ALIGN_SIZE SIZEOF_VOID_P
+#define GC_ALIGN(val,size) ((((val) + (size) - 1) / (size)) * (size))
+
 
 /* Global Variables ***********************************************************/
 
 extern bool gc_pending;
 extern bool gc_notify_finalizer;
 
+extern list_t *gc_reflist_strong;
+extern list_t *gc_reflist_weak;
+
+
+/* Structures *****************************************************************/
+
+typedef struct list_gcref_entry_t list_gcref_entry_t;
+
+struct list_gcref_entry_t {
+       listnode_t      linkage;
+       java_object_t **ref;
+#if !defined(NDEBUG)
+       s4              reftype;
+#endif
+};
+
+
+/* Global GC mutext stuff *****************************************************/
+
+#if defined(ENABLE_THREADS)
+# define GC_MUTEX_LOCK   threads_mutex_gc_lock()
+# define GC_MUTEX_UNLOCK threads_mutex_gc_unlock()
+#else
+# define GC_MUTEX_LOCK
+# define GC_MUTEX_UNLOCK
+#endif
+
 
 /* No-Thread specific stuff ***************************************************/
 
@@ -134,6 +159,8 @@ extern sourcestate_t    *_no_threads_sourcestate;
 
 /* Prototypes *****************************************************************/
 
+void gc_collect(s4 level);
+
 #if defined(ENABLE_THREADS)
 bool gc_suspend(threadobject *thread, u1 *pc, u1 *sp);
 #endif
@@ -148,12 +175,21 @@ bool gc_suspend(threadobject *thread, u1 *pc, u1 *sp);
 #define GCSTAT_DEC(cnt)   { (cnt)--; GC_ASSERT((cnt) >= 0); }
 #define GCSTAT_COUNT_MAX(cnt,max) { (cnt)++; if ((cnt) > (max)) (max) = (cnt); }
 
+extern int gcstat_collections;
+extern int gcstat_collections_forced;
 extern int gcstat_mark_depth;
 extern int gcstat_mark_depth_max;
 extern int gcstat_mark_count;
 
 void gcstat_println();
 
+#else /* defined(ENABLE_STATISTICS) */
+
+#define GCSTAT_INIT(cnt)
+#define GCSTAT_COUNT(cnt)
+#define GCSTAT_DEC(cnt)
+#define GCSTAT_COUNT_MAX(cnt,max)
+
 #endif /* defined(ENABLE_STATISTICS) */