[kaffe] CVS kaffe (guilhem): Thread fix when starting daemon + more debug info for pthreads.

Kaffe CVS cvs-commits at kaffe.org
Sun Oct 17 07:42:45 PDT 2004


PatchSet 5304 
Date: 2004/10/17 14:38:27
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Thread fix when starting daemon + more debug info for pthreads.

        * kaffe/kaffevm/thread.c
        (startSpecialThread): Save the content of pointer_args before
        locking.

        * kaffe/kaffevm/systems/unix-pthreads/thread-impl.c
        (protectThreadList, unprotectThreadList, tDump):
        In debug mode, we store the thread which is locking the thread list.

Members: 
	ChangeLog:1.2856->1.2857 
	kaffe/kaffevm/thread.c:1.75->1.76 
	kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.46->1.47 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2856 kaffe/ChangeLog:1.2857
--- kaffe/ChangeLog:1.2856	Sat Oct 16 17:24:16 2004
+++ kaffe/ChangeLog	Sun Oct 17 14:38:27 2004
@@ -1,3 +1,13 @@
+2004-10-17  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* kaffe/kaffevm/thread.c
+	(startSpecialThread): Save the content of pointer_args before
+	locking.
+
+	* kaffe/kaffevm/systems/unix-pthreads/thread-impl.c
+	(protectThreadList, unprotectThreadList, tDump):
+	In debug mode, we store the thread which is locking the thread list.
+	
 2004-10-16  Dalibor Topic <robilad at kaffe.org>
 
 	* libraries/clib/awt/classpath-gtk/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c,
Index: kaffe/kaffe/kaffevm/thread.c
diff -u kaffe/kaffe/kaffevm/thread.c:1.75 kaffe/kaffe/kaffevm/thread.c:1.76
--- kaffe/kaffe/kaffevm/thread.c:1.75	Tue Oct 12 19:55:59 2004
+++ kaffe/kaffe/kaffevm/thread.c	Sun Oct 17 14:38:30 2004
@@ -290,12 +290,16 @@
 
 	ksemInit(&THREAD_DATA()->sem);
 
+	/* We save the value before the lock so we are sure
+	 * pointer_args is still a valid pointer on the stack.
+	 */
+	func = (void(*)(void*))pointer_args[0];
+	argument = pointer_args[1];
+
 	lockStaticMutex(&thread_start_lock);
 	signalStaticCond(&thread_start_lock);
 	unlockStaticMutex(&thread_start_lock);
 
-	func = (void(*)(void*))pointer_args[0];
-	argument = pointer_args[1];
 	THREAD_DATA()->exceptObj = NULL;
 
 	func(argument);
Index: kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c
diff -u kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.46 kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.47
--- kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.46	Thu Oct 14 12:48:02 2004
+++ kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c	Sun Oct 17 14:38:31 2004
@@ -148,10 +148,17 @@
 /** Signal set which contains important signals for suspending threads. */
 static sigset_t		suspendSet;
 
-/* an optional deadlock watchdog thread (not in the activeThread list),
- * activated by KAFFE_VMDEBUG topic JTHREAD */
 #ifdef KAFFE_VMDEBUG
+/** an optional deadlock watchdog thread (not in the activeThread list),
+ * activated by KAFFE_VMDEBUG topic JTHREAD */
 static pthread_t	deadlockWatchdog;
+
+/**
+ * This is a debugging variable to analyze possible deadlock when dumping thread states.
+ * It retains a pointer to the thread holding the thread list lock.
+ */
+static jthread_t        threadListOwner;
+
 #endif /* KAFFE_VMDEBUG */
 
 static void suspend_signal_handler ( int sig );
@@ -166,11 +173,17 @@
 {
   cur->blockState |= BS_THREAD;
   jmutex_lock(&activeThreadsLock);
+#ifdef KAFFE_VMDEBUG
+  threadListOwner = cur;
+#endif
 }
 
 static inline void
 unprotectThreadList(jthread_t cur)
 {
+#ifdef KAFFE_VMDEBUG
+  threadListOwner = NULL;
+#endif
   jmutex_unlock(&activeThreadsLock);
   cur->blockState &= ~BS_THREAD;
 }
@@ -219,10 +232,12 @@
   DBG(JTHREAD, {
 	jthread_t	cur = jthread_current();
 
-	protectThreadList(cur);
-
 	dprintf("\n======================== thread dump =========================\n");
 
+	dprintf("thread list lock owner: %p (name=%s)\n", threadListOwner);
+
+	protectThreadList(cur);
+
 	dprintf("state:  nonDaemons: %d, critSection: %d\n",
 					 nonDaemons, critSection);
 
@@ -232,9 +247,9 @@
 	dprintf("\ncached threads:\n");
 	tDumpList( cur, cache);
 
-	dprintf("====================== end thread dump =======================\n");
-
 	unprotectThreadList(cur);
+
+	dprintf("====================== end thread dump =======================\n");
   })
 }
 
@@ -1246,7 +1261,7 @@
 		    {
 		      DBG( JTHREAD, dprintf("error sending RESUME signal to %p: %d\n", t, status))
 		    }		  
-		  /* ack wait workaround, see TentercritSect remarks */
+		  /* ack wait workaround, see jthread_suspendall remarks */
 		  sem_wait( &critSem);
 		}
 	      else




More information about the kaffe mailing list