[kaffe] CVS kaffe (guilhem): Fixes for Boehm-GC. Deadlock problem still pending.

Kaffe CVS cvs-commits at kaffe.org
Tue Aug 3 11:42:00 PDT 2004


PatchSet 5036 
Date: 2004/08/03 18:31:08
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Fixes for Boehm-GC. Deadlock problem still pending.

        * kaffe/kaffevm/gcFuncs.c
        (walkClass): Updated function call.

        * kaffe/kaffevm/boehm-gc/gc2.c,
        kaffe/kaffevm/boehm-gc/gc2.h
        (gcMark): New field "original_object"
        (clearAndAddDescriptor): Cleaned up.
        (finalizeObject): Call destroy function after
        having finalized.
        (finaliserMan): Removed call to jthread_yield. Added a dummy
        unlockStaticMutex.
        (gcMan): Likewise.
        (KaffeGC_realloc): Really return NULL if realloc fails.
        (KaffeGC_malloc): Return NULL if alloc fails.
        (KaffeGC_markAddress): Fixed call to GC_mark_and_push.
        (onObjectMarking): Initialize original_object.
        (KaffeGC_Init): Removed dead code.
        Include gc2.h. Moved some macros and structures to gc2.h

        * kaffe/kaffevm/boehm-gc/gcRefs.c:
        (KaffeGC_addRef): Take the object base to mark the object.
        (KaffeGC_rmRef): Likewise.
        Include gc2.h

        * kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:
        (tInitSignalHandler): Define a new signal SIG_INTERRUPT to
        interrupt syscall.
        (jthread_interrupt): Use SIG_INTERRUPT.

Members: 
	ChangeLog:1.2594->1.2595 
	kaffe/kaffevm/gcFuncs.c:1.55->1.56 
	kaffe/kaffevm/boehm-gc/gc-refs.c:1.1->1.2 
	kaffe/kaffevm/boehm-gc/gc2.c:1.3->1.4 
	kaffe/kaffevm/boehm-gc/gc2.h:INITIAL->1.1 
	kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.35->1.36 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2594 kaffe/ChangeLog:1.2595
--- kaffe/ChangeLog:1.2594	Mon Aug  2 10:44:53 2004
+++ kaffe/ChangeLog	Tue Aug  3 18:31:08 2004
@@ -1,3 +1,34 @@
+2004-08-03  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* kaffe/kaffevm/gcFuncs.c
+	(walkClass): Updated function call.
+
+	* kaffe/kaffevm/boehm-gc/gc2.c,
+	kaffe/kaffevm/boehm-gc/gc2.h
+	(gcMark): New field "original_object"
+	(clearAndAddDescriptor): Cleaned up.
+	(finalizeObject): Call destroy function after
+	having finalized.
+	(finaliserMan): Removed call to jthread_yield. Added a dummy
+	unlockStaticMutex.
+	(gcMan): Likewise.
+	(KaffeGC_realloc): Really return NULL if realloc fails.
+	(KaffeGC_malloc): Return NULL if alloc fails.
+	(KaffeGC_markAddress): Fixed call to GC_mark_and_push.
+	(onObjectMarking): Initialize original_object.
+	(KaffeGC_Init): Removed dead code.
+	Include gc2.h. Moved some macros and structures to gc2.h
+
+	* kaffe/kaffevm/boehm-gc/gcRefs.c:
+	(KaffeGC_addRef): Take the object base to mark the object.
+	(KaffeGC_rmRef): Likewise.
+	Include gc2.h
+
+	* kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:
+	(tInitSignalHandler): Define a new signal SIG_INTERRUPT to
+	interrupt syscall.
+	(jthread_interrupt): Use SIG_INTERRUPT.
+	
 2004-08-02  Guilhem Lavaux  <guilhem at kaffe.org>
 
 	* kaffe/kaffevm/Makefile.am
Index: kaffe/kaffe/kaffevm/gcFuncs.c
diff -u kaffe/kaffe/kaffevm/gcFuncs.c:1.55 kaffe/kaffe/kaffevm/gcFuncs.c:1.56
--- kaffe/kaffe/kaffevm/gcFuncs.c:1.55	Mon Aug  2 10:44:56 2004
+++ kaffe/kaffe/kaffevm/gcFuncs.c	Tue Aug  3 18:31:16 2004
@@ -343,7 +343,7 @@
  * http://sourceware.cygnus.com/ml/java-discuss/1999-q4/msg00379.html
  */
 				if (FIELD_TYPE(fld) == StringClass) {
-					KGC_markAddress(collector, *faddr);
+					KGC_markAddress(collector, gc_info, *faddr);
 				} else {
 					KGC_markObject(collector, gc_info, *faddr);
 				}
Index: kaffe/kaffe/kaffevm/boehm-gc/gc-refs.c
diff -u kaffe/kaffe/kaffevm/boehm-gc/gc-refs.c:1.1 kaffe/kaffe/kaffevm/boehm-gc/gc-refs.c:1.2
--- kaffe/kaffe/kaffevm/boehm-gc/gc-refs.c:1.1	Mon Aug  2 10:44:56 2004
+++ kaffe/kaffe/kaffevm/boehm-gc/gc-refs.c	Tue Aug  3 18:31:18 2004
@@ -66,7 +66,7 @@
   if (!obj)
     return false;
 	
-  obj->mem = mem;
+  obj->mem = ALIGN_BACKWARD(mem);
   obj->ref = 1;
   obj->next = refObjects.hash[idx];
   refObjects.hash[idx] = obj;
@@ -85,6 +85,8 @@
   refObject* obj;
 
   idx = REFOBJHASH(mem);
+  mem = ALIGN_BACKWARD(mem);
+
   for (objp = &refObjects.hash[idx]; *objp != 0; objp = &obj->next) {
     obj = *objp;
     /* Found it - just decrease reference */
Index: kaffe/kaffe/kaffevm/boehm-gc/gc2.c
diff -u kaffe/kaffe/kaffevm/boehm-gc/gc2.c:1.3 kaffe/kaffe/kaffevm/boehm-gc/gc2.c:1.4
--- kaffe/kaffe/kaffevm/boehm-gc/gc2.c:1.3	Mon Aug  2 10:44:56 2004
+++ kaffe/kaffe/kaffevm/boehm-gc/gc2.c	Tue Aug  3 18:31:18 2004
@@ -1,7 +1,7 @@
 /*
  * gc2.c
  * This interfaces the VM to the Hans-J. Boehm Incremental Garbage
- * Collector (version 6.0 alpha 7).
+ * Collector (version 6.3)
  *
  * Copyright (c) 2001
  *	Transvirtual Technologies, Inc.  All rights reserved.
@@ -30,6 +30,7 @@
 #include "thread.h"
 #include "gc-refs.h"
 #include "gc-kaffe.h"
+#include "gc2.h"
 
 extern void *GC_kaffe_malloc(size_t s);
 
@@ -45,11 +46,6 @@
         int                     mem;		/* only used ifdef STATS */
 } gcFuncs;
 
-typedef struct _gcMark {
-  struct GC_ms_entry *mark_current;
-  struct GC_ms_entry *mark_limit;
-} gcMark;
-
 static iStaticLock	gcman_lock = KAFFE_STATIC_LOCK_INITIALIZER;
 static iStaticLock	gcmanend_lock = KAFFE_STATIC_LOCK_INITIALIZER;
 static iStaticLock	finman_lock = KAFFE_STATIC_LOCK_INITIALIZER;
@@ -69,24 +65,12 @@
 
 static BoehmGarbageCollector boehm_gc;
 
-typedef struct {
-	uint8 memtype;
-	size_t memsize;
-} MemDescriptor;
-
-#define SIZEOF_DESC (((sizeof(MemDescriptor) + ALIGNMENTOF_VOIDP - 1) / ALIGNMENTOF_VOIDP) * ALIGNMENTOF_VOIDP)
-
-#define SYSTEM_SIZE(s) ((s) + SIZEOF_DESC)
-#define USER_SIZE(s) ((s) - SIZEOF_DESC)
-#define ALIGN_FORWARD(p) ((void *)((uintp)(p) + SIZEOF_DESC))
-#define ALIGN_BACKWARD(p) ((void *)((uintp)(p) - SIZEOF_DESC))
-
 static inline void
 clearAndAddDescriptor(void *mem, MemDescriptor *desc)
 {
     MemDescriptor *idx = (MemDescriptor *)mem;
-    idx[0] = *desc;
-    memset(&idx[1], 0, desc->memsize);
+    *idx = *desc;
+    memset(ALIGN_FORWARD(idx), 0, desc->memsize);
 }
 
 static void KaffeGC_InvokeGC(Collector* gcif, int mustgc);
@@ -154,8 +138,13 @@
 finalizeObject(void* ob, UNUSED void* descriptor)
 {
   MemDescriptor *desc = (MemDescriptor *)ob;
+  gcFuncs *f = &gcFunctions[desc->memtype];
+  
+  if (f->final != KGC_OBJECT_NORMAL && f->final != NULL)
+    f->final(&boehm_gc.collector, ALIGN_FORWARD(ob));
 
-  gcFunctions[desc->memtype].final(&boehm_gc.collector, ALIGN_FORWARD(ob));
+  if (f->destroy != NULL)
+    f->destroy(&boehm_gc.collector, ALIGN_FORWARD(ob));
 }
 
 static void NONRETURNING
@@ -169,7 +158,6 @@
     finalRunning = 0;
     while (finalRunning == 0) {
       waitStaticCond(&finman_lock, (jlong)0);
-      jthread_yield();
     }
     assert(finalRunning == 1);
 
@@ -178,6 +166,7 @@
     /* Wake up anyone waiting for the finalizer to finish */
     broadcastStaticCond(&finman_lock);
   }
+  unlockStaticMutex(&finman_lock);
 }
 
 
@@ -231,7 +220,6 @@
   unlockStaticMutex(&gcman_lock);
   while (gcRunning != 0) {
     waitStaticCond(&gcmanend_lock, (jlong)0);
-    jthread_yield();
   }
   unlockStaticMutex(&gcmanend_lock);
 }
@@ -301,9 +289,11 @@
     }
     desc->memtype = type;
     desc->memsize = sz;
+
+    return ALIGN_FORWARD(new_ptr);
   }
 
-  return ALIGN_FORWARD(new_ptr);
+  return NULL;
 }
 
 static void
@@ -337,17 +327,19 @@
   else
     mem = GC_kaffe_malloc(SYSTEM_SIZE(sz));
 
-  clearAndAddDescriptor(mem, &desc);
-	  
   // Attach finalizer
   if (mem != 0) {
-    if (gcFunctions[type].final != KGC_OBJECT_FIXED && 
-	gcFunctions[type].final != KGC_OBJECT_NORMAL) {
-      GC_REGISTER_FINALIZER_NO_ORDER(mem, finalizeObject, &gcFunctions[type], 0, 0);
+    clearAndAddDescriptor(mem, &desc);
+	  
+    if ( gcFunctions[type].final != KGC_OBJECT_FIXED
+	 && (gcFunctions[type].final != KGC_OBJECT_NORMAL
+	     || gcFunctions[type].destroy != NULL)) {
+      GC_REGISTER_FINALIZER_NO_ORDER(mem, finalizeObject, 0, 0, 0);
     }
+    return ALIGN_FORWARD(mem);
   }
 
-  return ALIGN_FORWARD(mem);
+  return NULL;
 }
 
 
@@ -448,7 +440,7 @@
 
   info_mark->mark_current =
     GC_mark_and_push(ALIGN_BACKWARD(mem), info_mark->mark_current, info_mark->mark_limit,
-		     (GC_PTR *)&mem);
+		     (GC_PTR *) info_mark->original_object);
 }
 
 static struct GC_ms_entry *
@@ -462,6 +454,7 @@
   
   info_mark.mark_current = mark_stack_ptr;
   info_mark.mark_limit = mark_stack_limit;
+  info_mark.original_object = addr;
 
   walkf = gcFunctions[type].walk;
   if (walkf != NULL)
@@ -486,7 +479,6 @@
 static void
 KaffeGC_Init(Collector *collector UNUSED)
 {
-  //  KGC_init = 1;
   GC_all_interior_pointers = 0;
   GC_finalizer_notifier = KaffeGC_SignalFinalizer;
   GC_java_finalization = 1;
@@ -499,7 +491,6 @@
     GC_expand_hp( Kaffe_JavaVMArgs.minHeapSize - GC_get_heap_size());
 
   GC_kaffe_init(onObjectMarking);
-  // KGC_init = 0;
 }
 
 
===================================================================
Checking out kaffe/kaffe/kaffevm/boehm-gc/gc2.h
RCS:  /home/cvs/kaffe/kaffe/kaffe/kaffevm/boehm-gc/gc2.h,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/kaffe/kaffevm/boehm-gc/gc2.h	Tue Aug  3 18:41:59 2004
@@ -0,0 +1,37 @@
+/*
+ * gc2.h
+ * This interfaces the VM to the Hans-J. Boehm Incremental Garbage
+ * Collector (version 6.0 alpha 7).
+ * Copyright (c) 2004
+ *      The Kaffe.org's developers. All rights reserved. 
+ *      See ChangeLog for details.
+ *
+ * See the file "license.terms" for information on usage and redistribution 
+ * of this file. 
+ */
+
+#ifndef _KAFFE_BOEHM_GC_H
+#define _KAFFE_BOEHM_GC_H
+
+#include "boehm/include/gc.h"
+#include "boehm/include/gc_mark.h"
+
+typedef struct _gcMark {
+  struct GC_ms_entry *mark_current;
+  struct GC_ms_entry *mark_limit;
+  GC_PTR original_object;
+} gcMark;
+
+typedef struct {
+	uint8 memtype;
+	size_t memsize;
+} MemDescriptor;
+
+#define SIZEOF_DESC (((sizeof(MemDescriptor) + ALIGNMENTOF_VOIDP - 1) / ALIGNMENTOF_VOIDP) * ALIGNMENTOF_VOIDP)
+
+#define SYSTEM_SIZE(s) ((s) + SIZEOF_DESC)
+#define USER_SIZE(s) ((s) - SIZEOF_DESC)
+#define ALIGN_FORWARD(p) ((void *)((uintp)(p) + SIZEOF_DESC))
+#define ALIGN_BACKWARD(p) ((void *)((uintp)(p) - SIZEOF_DESC))
+
+#endif
Index: kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c
diff -u kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.35 kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.36
--- kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.35	Mon Aug  2 10:45:05 2004
+++ kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c	Tue Aug  3 18:31:19 2004
@@ -114,6 +114,8 @@
 
 #endif
 
+#define SIG_INTERRUPT (__SIGRTMIN+2)
+
 
 /***********************************************************************
  * global data
@@ -328,7 +330,7 @@
 void
 tInitSignalHandlers (void)
 {
-  struct sigaction sigSuspend, sigResume, sigDump;
+  struct sigaction sigSuspend, sigResume, sigInterrupt, sigDump;
   unsigned int flags = 0;
 
 #if defined(SA_RESTART)
@@ -362,6 +364,11 @@
   sigaction( SIG_RESUME, &sigResume, NULL);
 #endif
 
+  sigInterrupt.sa_flags = flags;
+  sigInterrupt.sa_handler = SIG_IGN;
+  sigemptyset(&sigInterrupt.sa_mask);
+  sigaction( SIG_INTERRUPT, &sigInterrupt, NULL);
+
 #if defined(SIG_DUMP)
   sigDump.sa_flags = flags;
   sigDump.sa_handler = dump_signal_handler;
@@ -517,7 +524,7 @@
 {
   tid->interrupting = 1;
   /* We need to send some signal to interrupt syscalls. */
-  pthread_kill(tid->tid, SIG_RESUME);
+  pthread_kill(tid->tid, SIG_INTERRUPT);
 }
 
 int jthread_is_interrupted(jthread_t jt)




More information about the kaffe mailing list