[kaffe] Lock patch

Guilhem Lavaux guilhem at kaffe.org
Mon Mar 7 11:25:53 PST 2005


Hi,

I've just finished a functional patch for the locking system. I don't 
know yet how much slower it is. But I've already had some interesting 
results with some private app which was not working previously. If noone 
is against  I will commit it on wednesday...

Cheers,

Guilhem.

P.S.: I've also put some warning fixes here and there.
-------------- next part --------------
? build
? build_intrp
? config/powerpc/darwin/md.h.new
? kaffe/kaffevm/locks.c.v2
? libraries/javalib/Klasses.jar.bootstrap.save
? libraries/javalib/l
? po/fr.gmo
? po/zh_TW.gmo
? test/regression/RefTest
? test/regression/l
Index: config/alpha/osf/md.c
===================================================================
RCS file: /cvs/kaffe/kaffe/config/alpha/osf/md.c,v
retrieving revision 1.8
diff -u -B -b -r1.8 md.c
--- config/alpha/osf/md.c	8 Jul 2003 07:33:48 -0000	1.8
+++ config/alpha/osf/md.c	7 Mar 2005 19:00:46 -0000
@@ -87,7 +87,6 @@
 
 void __alpha_osf_firstFrame (exceptionFrame *frame)
 {
-	int iLockRoot;
 
 	/* Retreive caller frame as current one will be invalidate
            after function exit. */
@@ -104,7 +103,6 @@
 
 exceptionFrame * __alpha_osf_nextFrame (exceptionFrame *frame)
 {
-	int iLockRoot;
 
 	DBG(STACKTRACE,
 	    dprintf("__alpha_osf_nextFrame(0x%p) pc 0x%p fp 0x%p sp 0x%p\n", frame,
@@ -140,7 +138,6 @@
 /* Construct JIT Exception information and register it.  */
 void __alpha_osf_register_jit_exc (void *methblock, void *codebase, void *codeend)
 {
-	int iLockRoot;
 	extern int maxLocal, maxStack, maxTemp, maxArgs, maxPush;
 	struct {
 		pdsc_crd crd[2];
@@ -209,7 +206,6 @@
 
 void __alpha_osf_unregister_jit_exc (void *methblock, void *codebase, void *codeend)
 {
-	int iLockRoot;
 	int codelen = codeend - codebase;
 
 	DBG(STACKTRACE,
Index: config/i386/jit.h
===================================================================
RCS file: /cvs/kaffe/kaffe/config/i386/jit.h,v
retrieving revision 1.25
diff -u -B -b -r1.25 jit.h
--- config/i386/jit.h	20 Dec 2004 00:55:13 -0000	1.25
+++ config/i386/jit.h	7 Mar 2005 19:00:47 -0000
@@ -112,7 +112,7 @@
 #define LABEL_Lframe(P,D,L)						\
 	{								\
 		int framesize = SLOTSIZE * (maxLocal + maxStack +	\
-			maxTemp - maxArgs);				\
+			maxTemp - maxArgs + 1);				\
 		*(uint32*)(P) = framesize;				\
 	}
 #define LABEL_Llong8(P,V,L)	*(char*)(P) = (V)
Index: config/i386/jit3-icode.h
===================================================================
RCS file: /cvs/kaffe/kaffe/config/i386/jit3-icode.h,v
retrieving revision 1.9
diff -u -B -b -r1.9 jit3-icode.h
--- config/i386/jit3-icode.h	17 Jun 2001 16:39:10 -0000	1.9
+++ config/i386/jit3-icode.h	7 Mar 2005 19:00:47 -0000
@@ -223,8 +223,8 @@
 
 #define HAVE_call_indirect_const	call_ind_xCC
 
-#define	HAVE_mon_enter			monenter_xxRCC
-#define	HAVE_mon_exit			monexit_xxRCC
+//#define	HAVE_mon_enter			monenter_xxRCC
+//#define	HAVE_mon_exit			monexit_xxRCC
 
 #define HAVE_get_arg_ptr		get_arg_ptr_R
 
Index: include/errors.h
===================================================================
RCS file: /cvs/kaffe/kaffe/include/errors.h,v
retrieving revision 1.16
diff -u -B -b -r1.16 errors.h
--- include/errors.h	19 Dec 2004 22:13:08 -0000	1.16
+++ include/errors.h	7 Mar 2005 19:00:48 -0000
@@ -36,7 +36,7 @@
 typedef struct _errorInfo {
 	int type;		/* type of error */
 	const char* classname;	/* full dotted name of exception/error class */
-	char* mess;		/* accompanying msg */
+	const char* mess;		/* accompanying msg */
 	struct Hjava_lang_Throwable* throwable;	/* a throwable */
 } errorInfo;
 
Index: kaffe/kaffevm/classMethod.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/classMethod.c,v
retrieving revision 1.135
diff -u -B -b -r1.135 classMethod.c
--- kaffe/kaffevm/classMethod.c	16 Feb 2005 13:35:20 -0000	1.135
+++ kaffe/kaffevm/classMethod.c	7 Mar 2005 19:00:49 -0000
@@ -115,7 +115,6 @@
 	static int depth;
 #endif /* !(defined(NDEBUG) || !defined(KAFFE_VMDEBUG)) */
 	static Method *object_fin;
-	int iLockRoot;
 
 	/* If this class is initialised to the required point, quit now */
 	if (class->state >= tostate) {
@@ -750,7 +749,6 @@
 static bool
 resolveInterfaces(Hjava_lang_Class *class, errorInfo *einfo)
 {
-	int iLockRoot;
 	int i, j, k;
 	int totalilen;
 	Hjava_lang_Class** newifaces;
@@ -1539,7 +1537,6 @@
 	errorInfo info;
 	Utf8Const *utf8;
 	classEntry* centry;
-	int iLockRoot;
 	bool refAdded;
 
 	utf8 = utf8ConstNew(name, -1);
@@ -1618,7 +1615,6 @@
 {
 	Hjava_lang_Class* clas;
 	const char* name;
-	int iLockRoot;
 
 	/* Avoid locking if we can */
 	if (FIELD_RESOLVED(fld)) {
@@ -2230,7 +2226,6 @@
 	int found_i;
 	bool rc = false;
 	Hjava_lang_Class** ifcs;
-	int iLockRoot;
 
 	/* find an impl_index for this class
 	 * Note that we only find a suitable impl_index with regard to the
@@ -2429,7 +2424,6 @@
 	Utf8Const* utf8;
 	Hjava_lang_String* str = NULL;
 	constants* pool;
-	int iLockRoot;
 
 	pool = CLASS_CONSTANTS(clazz);
 
@@ -2768,7 +2762,6 @@
 	classEntry* centry;
 	Hjava_lang_Class* arr_class;
 	int arr_flags;
-	int iLockRoot;
 
 	/* If we couldn't resolve the element type, there's no way we can
 	 * construct the array type.
Index: kaffe/kaffevm/classPool.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/classPool.c,v
retrieving revision 1.33
diff -u -B -b -r1.33 classPool.c
--- kaffe/kaffevm/classPool.c	4 Feb 2005 10:36:14 -0000	1.33
+++ kaffe/kaffevm/classPool.c	7 Mar 2005 19:00:49 -0000
@@ -30,7 +30,7 @@
 #include "md.h"
 
 #define	CLASSHASHSZ	256	/* Must be a power of two */
-static iStaticLock	classHashLock = KAFFE_STATIC_LOCK_INITIALIZER;
+static iStaticLock	classHashLock;
 static classEntry* classEntryPool[CLASSHASHSZ];
 #if defined(KAFFE_STATS)
 statobject classStats;
@@ -65,7 +65,6 @@
 {
 	classEntry* entry;
 	classEntry** entryp;
-	int iLockRoot;
 	static int f = 0;
 
         if (f == 0) {
@@ -194,7 +193,6 @@
 	classEntry* entry;
 	int ipool;
 	int totalent = 0;
-	int iLockRoot;
 
         lockStaticMutex(&classHashLock);
 	for (ipool = CLASSHASHSZ;  --ipool >= 0; ) {
@@ -252,7 +250,7 @@
 }
 
 static nameDependency *dependencies;
-static iStaticLock	mappingLock = KAFFE_STATIC_LOCK_INITIALIZER;
+static iStaticLock	mappingLock;
 
 static
 nameDependency *findNameDependency(jthread_t jt)
@@ -273,7 +271,6 @@
 int addNameDependency(nameDependency *nd)
 {
 	int retval = 1;
-	int iLockRoot;
 
 	assert(nd != 0);
 
@@ -301,7 +298,6 @@
 static
 void remNameDependency(classEntry *ce)
 {
-	int iLockRoot;
 
 	assert(ce != 0);
 	
@@ -331,7 +327,6 @@
 	int done = 0, retval = 1;
 	nameDependency nd;
 	jthread_t jt;
-	int iLockRoot;
 
 	jt = KTHREAD(current)();
 	while( !done )
@@ -403,7 +398,6 @@
 	int done = 0, retval = 1;
 	nameDependency nd;
 	jthread_t jt;
-	int iLockRoot;
 
 	*out_cl = NULL;
 	jt = KTHREAD(current)();
@@ -465,7 +459,6 @@
 Hjava_lang_Class *classMappingLoaded(classEntry *ce, Hjava_lang_Class *cl)
 {
 	Hjava_lang_Class *retval = NULL;
-	int iLockRoot;
 
 	assert(ce != 0);
 	assert(cl != 0);
@@ -502,7 +495,6 @@
 
 void setClassMappingState(classEntry *ce, name_mapping_state_t nms)
 {
-	int iLockRoot;
 	
 	assert(ce != 0);
 	
Index: kaffe/kaffevm/exception.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/exception.c,v
retrieving revision 1.93
diff -u -B -b -r1.93 exception.c
--- kaffe/kaffevm/exception.c	7 Feb 2005 01:27:59 -0000	1.93
+++ kaffe/kaffevm/exception.c	7 Mar 2005 19:00:49 -0000
@@ -85,7 +85,7 @@
 {
 	assert(eh != NULL);
 	assert(eh->meth == VMEXCEPTHANDLER_KAFFEJNI_HANDLER);
-	assert(fp != NULL);
+	assert(fp != (JNIFrameAddress)0);
 
 	return (eh->frame.jni.fp == fp);
 }
@@ -94,7 +94,7 @@
 vmExcept_setJNIFrame(VmExceptHandler* eh, JNIFrameAddress fp)
 {
 	assert(eh != NULL);
-	assert(fp != NULL);
+	assert(fp != (JNIFrameAddress)0);
 
 	eh->meth = VMEXCEPTHANDLER_KAFFEJNI_HANDLER;
 	eh->frame.jni.fp = fp;
@@ -181,6 +181,8 @@
 	case KERR_OUT_OF_MEMORY:
 		err = gc_throwOOM();
 		break;
+	default:
+	        assert(!!!"Unexpected error info mask");
 	}
 
 	discardErrorInfo(einfo);
@@ -292,7 +294,7 @@
 discardErrorInfo(errorInfo *einfo)
 {
 	if (einfo->type & KERR_FREE_MESSAGE) {
-		KFREE(einfo->mess);
+		KFREE((void *)einfo->mess);
 		einfo->type &= ~KERR_FREE_MESSAGE;
 	}
 }
@@ -461,7 +463,7 @@
 
 		/* If not here, exit monitor if synchronised. */
 		if (frame->meth->accflags & ACC_SYNCHRONISED) {
-			locks_internal_slowUnlockMutexIfHeld(&obj->lock, (void *)frame->fp, NULL);
+			locks_internal_slowUnlockMutexIfHeld(&obj->lock);
 		}	    
 
 		/* If method found and profiler enable, fix self+children time */
Index: kaffe/kaffevm/external.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/external.c,v
retrieving revision 1.78
diff -u -B -b -r1.78 external.c
--- kaffe/kaffevm/external.c	10 Jan 2005 12:43:19 -0000	1.78
+++ kaffe/kaffevm/external.c	7 Mar 2005 19:00:49 -0000
@@ -72,7 +72,7 @@
 	Hjava_lang_ClassLoader*		loader;
 } libHandle[MAXLIBS];
 
-static iStaticLock	libraryLock = KAFFE_STATIC_LOCK_INITIALIZER; /* mutex on all intern operations */
+static iStaticLock	libraryLock; /* mutex on all intern operations */
 static char *libraryPath = NULL;
 
 extern JavaVM Kaffe_JavaVM;
@@ -201,7 +201,6 @@
 	struct _libHandle *lib;
 	int libIndex;
 	void *func;
-	int iLockRoot;
 
 	lockStaticMutex(&libraryLock);
 
@@ -311,7 +310,6 @@
 unloadNativeLibraries(struct Hjava_lang_ClassLoader* loader)
 {
 	int libIndex;
-	int iLockRoot;
 
 	lockStaticMutex(&libraryLock);
 
@@ -349,7 +347,6 @@
 {
   int i = 0;
   void* func = NULL;
-  int iLockRoot;
 
   lockStaticMutex(&libraryLock);
   
Index: kaffe/kaffevm/findInJar.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/findInJar.c,v
retrieving revision 1.65
diff -u -B -b -r1.65 findInJar.c
--- kaffe/kaffevm/findInJar.c	4 Feb 2005 10:36:14 -0000	1.65
+++ kaffe/kaffevm/findInJar.c	7 Mar 2005 19:00:49 -0000
@@ -184,11 +184,10 @@
 {
 	char *buf;
 	int fp;
-	static iStaticLock	jarlock = KAFFE_STATIC_LOCK_INITIALIZER;
+	static iStaticLock	jarlock;
 	classpathEntry* ptr;
 	int i;
 	int rc;
-	int iLockRoot;
 
 	/* Look for the class */
 DBG(CLASSLOOKUP,  dprintf("Scanning for element %s\n", cname); );
Index: kaffe/kaffevm/jar.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/jar.c,v
retrieving revision 1.36
diff -u -B -b -r1.36 jar.c
--- kaffe/kaffevm/jar.c	8 Jan 2005 00:31:46 -0000	1.36
+++ kaffe/kaffevm/jar.c	7 Mar 2005 19:00:50 -0000
@@ -75,12 +75,7 @@
 	unsigned int count;
 };
 
-static struct _jarCache jarCache = {
-#if !defined(KAFFEH)
-	KAFFE_STATIC_LOCK_INITIALIZER,
-#endif
-	NULL, 0
-};
+static struct _jarCache jarCache;
 
 /*
  * Hash a file name, the hash value is stored in what `hash' points to.
@@ -105,9 +100,6 @@
 static jarFile *findCachedJarFile(char *name)
 {
 	jarFile *curr, **prev, *retval = NULL;
-#if !defined(KAFFEH)
-	int iLockRoot;
-#endif
 
 	assert(name != NULL);
 	
@@ -200,9 +192,6 @@
 {
 	jarFile *curr, **prev, **lru = NULL, *dead_jar = NULL, *retval = jf;
 	int already_cached = 0;
-#if !defined(KAFFEH)
-	int iLockRoot;
-#endif
 
 	assert(jf != 0);
 	assert(!(jf->flags & JFF_CACHED));
@@ -330,9 +319,6 @@
 static void removeJarFile(jarFile *jf)
 {
 	jarFile *curr, **prev;
-#if !defined(KAFFEH)
-	int iLockRoot;
-#endif
 
 	assert(jf != NULL);
 
@@ -364,9 +350,6 @@
 void flushJarCache(void)
 {
 	jarFile **prev, *curr, *next;
-#if !defined(KAFFEH)
-	int iLockRoot;
-#endif
 
 	lockStaticMutex(&jarCache.lock);
 	curr = jarCache.files;
@@ -951,9 +934,6 @@
 {
 	uint8 *buf = NULL, *retval = NULL;
 	jarLocalHeader lh;
-#if !defined(KAFFEH)
-	int iLockRoot;
-#endif
 
 	assert(jf != 0);
 	assert(je != 0);
@@ -1018,9 +998,6 @@
 			if( jar_stat.st_mtime == jf->lastModified )
 			{
 #endif /* !defined(STATIC_JAR_FILES) */
-#if !defined(KAFFEH)
-				int iLockRoot;
-#endif
 				
 				/* Only set the fd in the structure here */
 				lockMutex(jf);
@@ -1196,9 +1173,6 @@
 {
 	if( jf )
 	{
-#if !defined(KAFFEH)
-		int iLockRoot;
-#endif
 
 		lockStaticMutex(&jarCache.lock);
 		jf->users--;
Index: kaffe/kaffevm/ksem.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/ksem.c,v
retrieving revision 1.12
diff -u -B -b -r1.12 ksem.c
--- kaffe/kaffevm/ksem.c	30 Jan 2005 18:21:38 -0000	1.12
+++ kaffe/kaffevm/ksem.c	7 Mar 2005 19:00:50 -0000
@@ -63,15 +63,15 @@
 	}
 
 	/* Use a stored wakeup if available. */
-	if (sem->count == 1) {
-		sem->count = 0;
+	if (sem->count > 0) {
+	  sem->count--;
 		r = true;
 	}
 	else {
 		/* Still no stored wakeup means we waited and timedout. */
 		r = false;
 	}
-	assert(sem->count == 0);
+	assert(sem->count >= 0);
 	KMUTEX(unlock)(&sem->mux);
 	return (r);
 }
@@ -85,7 +85,7 @@
 {
 	assert(sem != NULL);
 	KMUTEX(lock)(&sem->mux);
-        sem->count = 1;
+        sem->count++;
 	KCONDVAR(signal)(&sem->cv, &sem->mux);
 	KMUTEX(unlock)(&sem->mux);
 }
Index: kaffe/kaffevm/ksem.h
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/ksem.h,v
retrieving revision 1.10
diff -u -B -b -r1.10 ksem.h
Index: kaffe/kaffevm/locks.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/locks.c,v
retrieving revision 1.56
diff -u -B -b -r1.56 locks.c
--- kaffe/kaffevm/locks.c	6 Feb 2005 15:38:47 -0000	1.56
+++ kaffe/kaffevm/locks.c	7 Mar 2005 19:00:50 -0000
@@ -24,6 +24,7 @@
 #include "debug.h"
 #include "gc.h"
 #include "jvmpi_kaffe.h"
+#include "stats.h"
 
 /*
  * If we don't have an atomic compare and exchange defined then make
@@ -50,9 +51,6 @@
 #endif
 #endif
 
-/* Count number of backoffs.  XXX move into the STAT infrastructure. */
-int backoffcount = 0;
-
 /*
  * Initialise the locking system.
  */
@@ -61,70 +59,89 @@
 {
 }
 
+static timespent heavyLockTime;
+static timespent locksTime;
+
 /*
  * Get a heavy lock for the object and hold it.  If the object doesn't
  * have a heavy lock then we create one.
  */
-static
-iLock*
-getHeavyLock(iLock* volatile * lkp, iLock *heavyLock)
+static iLock *
+getHeavyLock(iLock* volatile * lkp)
 {
-	iLock* old;
-	iLock* lk;
-	jlong timeout;
+  volatile iLock lock_in_progress;
+  int i;
+  iLock *lk;
 
-DBG(SLOWLOCKS,
-    	dprintf("  getHeavyLock(**lkp=%p, *lk=%p, th=%p)\n",
-		lkp, *lkp, KTHREAD(current)());
-);
+  DBG(SLOWLOCKS,
+      dprintf("  getHeavyLock(lk=%p, th=%p)\n",
+	      *lkp, KTHREAD(current)());
+      );
  
-	lk = heavyLock;
-	timeout = 1;
-	for (;;) {
-		/* Get the current lock and replace it with LOCKINPROGRESS to indicate
-		 * changes are in progress.
-		 */
-		old = *lkp;
-		if (old == LOCKINPROGRESS || !COMPARE_AND_EXCHANGE(lkp, old, LOCKINPROGRESS)) {
-			/* Someone else put the lock in LOCKINPROGRESS state */
-			backoffcount++;
-			KSEM(get)(&THREAD_DATA()->sem, timeout);
-			/* Back off */
-			timeout = (timeout << 1)|timeout;
-			continue;
-		}
+  lk = *lkp;
 
-		/* If bottom bit is set, strip off and use pointer as pointer to heavy lock */
-		if ((((uintp)old) & 1) == 1) {
-DBG(SLOWLOCKS,
-    			dprintf("    got cached lock\n");
-);
-			if (lk != heavyLock) {
-				gc_free (lk);
-			}
-
-			lk = (iLock*)(((uintp)old) & (uintp)-2);
-		}
-		else {
-			if (lk == LOCKFREE) {
-				/* Release the lock before we go into malloc.
-				 * We have to reclaim the lock afterwards (at beginning
-				 * of loop)
+  /* Check if it has been allocated, if not acquire the lock by putting our
+   * temporary structure.
 				 */
-				*lkp = old;
+  if (lk == LOCKFREE || !lk->allocated)
+    {
+      startTiming(&heavylockTime, "heavylock-handling");
+      /* Build a temporary lock */
+      lock_in_progress.sem = &THREAD_DATA()->heavy_sem;
+      lock_in_progress.in_progress = 1;
+      lock_in_progress.num_wait = 0;
+      
+      /* Try to put it if that fails it means another thread has beaten us
+       * and so we only have wasted a few cpu cycles.
+       * N.B.: This is done once in the case of a static heavyLock.
+       */
+      if (COMPARE_AND_EXCHANGE(lkp, lk, &lock_in_progress))
+	{
+	  /* Build a real lock object. If lk is a static lock it is already allocated.
+	   */
+	  if (lk == NULL)
+	    {
 				lk = (iLock*)gc_malloc(sizeof(iLock), KGC_ALLOC_LOCK);
-				/* if that fails we're in trouble!! */
-				assert(lk != 0);
-				continue;
+	      assert(lk != NULL);
 			}
-DBG(SLOWLOCKS,
-			dprintf("    got %s lock\n",
-				(lk != heavyLock) ? "new" : "special");
-);
-			lk->holder = (void*)old;
+
+	  lk->allocated = 1;
+	  lk->in_progress = 1;
 			lk->mux = NULL;
 			lk->cv = NULL;
+	  lk->num_wait = 0;
+	  KSEM(init)(&lk->real_sem);
+	  lk->sem = &lk->real_sem;
+
+	  /* Put the real heavylock structure in place */
+	  *lkp = lk;
+      
+	  /* Wake up all threads which are locked on the lock_in_progress.
+	   * That way they will refresh the semaphore pointer. */
+	  for (i = 0; i < lock_in_progress.num_wait; i++)
+	    KSEM(put)(lock_in_progress.sem);
+
+	  /* Now the lock is acquired by this thread and ready to use for the others.
+	   */
+	  stopTiming(&heavyLockTime);
+	  return lk;
+	}
+      stopTiming(&heavyLockTime);
 		}
+  else assert(lk->allocated == 1);
+  
+  /* The lock is allocated and ready to use. */
+  for (;;) {
+    lk = *lkp;
+    /* Try to acquire the lock. */
+    if (!COMPARE_AND_EXCHANGE(&(lk->in_progress), 0, 1))
+      {
+	lk->num_wait++;
+	KSEM(get)(lk->sem, (jlong)0);
+	lk->num_wait--;
+	continue;
+      }
+
 		return (lk);
 	}
 }
@@ -135,21 +152,24 @@
  */
 static
 void
-putHeavyLock(iLock** lkp, iLock* lk)
+putHeavyLock(volatile iLock* lk)
 {
-	assert(*lkp == LOCKINPROGRESS);
-
-DBG(SLOWLOCKS,
-	dprintf("  putHeavyLock(**lkp=%p, *lk=%p, th=%p)\n", 
-		lkp, lk, KTHREAD(current)());
-);
-
-	if (lk == LOCKFREE) {
-		*lkp = LOCKFREE;
-	}
-	else {
-		*lkp = (iLock*)(1|(uintp)lk);
-	}
+  DBG(SLOWLOCKS,
+      dprintf("  putHeavyLock(lk=%p, th=%p)\n", 
+	      lk, KTHREAD(current)());
+      );
+
+  assert(lk->allocated == 1);
+  assert(lk->in_progress == 1);
+  
+  lk->in_progress = 0;
+  /*
+   * This is safe as we have just put in_progress to 0 num_wait cannot grow.
+   * This prevents us from invoking unnecessarily the thread layer and this is needed
+   * at the initialization time when the thread system is not yet initialized.
+   */
+  if (lk->num_wait != 0)
+    KSEM(put)(lk->sem);
 }
 
 /*
@@ -157,40 +177,52 @@
  * If we can't lock it we suspend until we can.
  */
 static void
-slowLockMutex(iLock** lkp, void* where, iLock *heavyLock)
+slowLockMutex(iLock** lkp)
 {
-	iLock* lk;
+  volatile iLock* lk;
 	jthread_t cur = KTHREAD(current) ();
+  threadData *tdata;
 
 DBG(SLOWLOCKS,
-    	dprintf("slowLockMutex(**lkp=%p, where=%p, th=%p)\n",
-	       lkp, where, KTHREAD(current)());
-);
+    dprintf("slowLockMutex(lk=%p, th=%p)\n",
+	    *lkp, KTHREAD(current)());
+    );
 	KTHREAD(disable_stop)(); /* protect the heavy lock, and its queues */
 
+ tdata = KTHREAD(get_data)(cur);
 	for (;;) {
-		lk = getHeavyLock(lkp, heavyLock);
+   lk = getHeavyLock(lkp);
 
+   startTiming(&lockTime, "slowlocks-time");
 		/* If I hold the heavy lock then just keep on going */
-		if (KTHREAD(on_current_stack)(lk->holder)) {
-			putHeavyLock(lkp, lk);
+   if (cur == lk->holder) {
+     lk->lockCount++;
+     putHeavyLock(lk);
+     stopTiming(&lockTime);
 			KTHREAD(enable_stop)();
 			return;
 		}
 
 		/* If no one holds the heavy lock then claim it */
-		if (lk->holder == 0) {
-			lk->holder = where;
-			putHeavyLock(lkp, lk);
+   if (lk->holder == NULL) {
+     if (lk->lockCount != 0) {
+	     dprintf("Lockcount should be 0 for %p\n", lk);
+       abort();
+     }
+     lk->holder = cur;
+     lk->lockCount++;
+     stopTiming(&lockTime);
+     putHeavyLock(lk);
 			KTHREAD(enable_stop)();
 			return;
 		}
 
 		/* Otherwise wait for holder to release it */
-		KTHREAD(get_data)(cur)->nextlk = lk->mux;
+   tdata->nextlk = lk->mux;
 		lk->mux = cur;
-		putHeavyLock(lkp, lk);
-		KSEM(get)(&KTHREAD(get_data)(cur)->sem, (jlong)0);
+   putHeavyLock(lk);
+   stopTiming(&lockTime);
+   KSEM(get)(&tdata->sem, (jlong)0);
 	}
 }
 
@@ -200,32 +232,36 @@
  * a fast thin lock.
  */
 static void
-slowUnlockMutex(iLock** lkp, void* where, iLock *heavyLock)
+slowUnlockMutex(iLock** lkp)
 {
-	iLock* lk;
+  volatile iLock* lk;
 	jthread_t tid;
+  jthread_t cur = KTHREAD(current)();
 
-DBG(SLOWLOCKS,
-    	dprintf("slowUnlockMutex(**lkp=%p, where=%p, th=%p)\n",
-	       lkp, where, KTHREAD(current)());
-);
+  DBG(SLOWLOCKS,
+      dprintf("slowUnlockMutex(lk=%p, th=%p)\n",
+	      *lkp, KTHREAD(current)());
+      );
 	KTHREAD(disable_stop)(); /* protect the heavy lock, and its queues */
-	lk = getHeavyLock(lkp, heavyLock);
+  lk = getHeavyLock(lkp);
+
+  startTiming(&locksTime, "slowlocks-time");
 
 	/* Only the lock holder can be doing an unlock */
-	if (!KTHREAD(on_current_stack)(lk->holder)) {
-		putHeavyLock(lkp, lk);
+  if (cur != lk->holder) {
+    putHeavyLock(lk);
 		KTHREAD(enable_stop)();
+    stopTiming(&locksTime);
 		throwException(IllegalMonitorStateException);
 	}
 
+  assert(lk->lockCount > 0);
+
 	/* If holder isn't where we are now then this isn't the final unlock */
-#if defined(STACK_GROWS_UP)
-	if (lk->holder < where) {
-#else
-	if (lk->holder > where) {
-#endif
-		putHeavyLock(lkp, lk);
+  lk->lockCount--;
+  if (lk->lockCount != 0) {
+    putHeavyLock(lk);
+    stopTiming(&locksTime);
 		KTHREAD(enable_stop)();
 		return;
 	}
@@ -234,182 +270,192 @@
 	 * time to tell them.
 	 */
 	if (lk->mux != NULL) {
+    threadData *tdata;
+
 		tid = lk->mux;
-		lk->mux = KTHREAD(get_data)(tid)->nextlk;
-		KTHREAD(get_data)(tid)->nextlk = NULL;
+    tdata = KTHREAD(get_data)(tid);
+    lk->mux = tdata->nextlk;
+    tdata->nextlk = NULL;
 		lk->holder = NULL;
-		putHeavyLock(lkp, lk);
-		KSEM(put)(&KTHREAD(get_data)(tid)->sem);
+    putHeavyLock(lk);
+    KSEM(put)(&tdata->sem);
 	}
 	/* If someone's waiting to be signaled keep the heavy in place */
 	else if (lk->cv != NULL) {
 		lk->holder = NULL;
-		putHeavyLock(lkp, lk);
-	}
-	else {
-		if (lk != heavyLock) {
-			gc_free(lk);
+    putHeavyLock(lk);
 		}
 		else {
 			lk->holder = NULL;
-		}
-		putHeavyLock(lkp, LOCKFREE);
+    putHeavyLock(lk);
 	}
 	KTHREAD(enable_stop)();
+  stopTiming(&locksTime);
 }
 
 void
-locks_internal_slowUnlockMutexIfHeld(iLock** lkp, void* where, iLock *heavyLock)
+locks_internal_slowUnlockMutexIfHeld(iLock** lkp)
 {
 	iLock* lk;
 	void* holder;
+  jthread_t cur = KTHREAD(current)();
 
-DBG(SLOWLOCKS,
-    	dprintf("slowUnlockMutexIfHeld(**lkp=%p, where=%p, th=%p)\n",
-	       lkp, where, KTHREAD(current)());
-);
-	holder = *lkp;
+  DBG(SLOWLOCKS,
+      dprintf("slowUnlockMutexIfHeld(lkp=%p, th=%p)\n",
+	      *lkp, KTHREAD(current)());
+      );
+  lk = *lkp;
+  /* Even if the lock is not allocated the holder is NULL. */
+  holder = (lk == NULL) ? NULL : (*lkp)->holder;
 
 	/* nothing to do if the lock is free */
-	if (holder == LOCKFREE) {
+  if (holder == NULL) {
 		return;
 	}
 
 	/* if it's a thin lock and this thread owns it,
 	 * try to free it the easy way
 	 */
-	if (KTHREAD(on_current_stack)(holder) &&
-	    COMPARE_AND_EXCHANGE(lkp, holder, LOCKFREE)) {
-		return;
-	}
+  //  if (holder == cur &&
+  //    COMPARE_AND_EXCHANGE(&(lk->holder), holder, LOCKFREE)) {
+  //  return;
+  //}
 
 	/* ok, it is a heavy lock */
-	lk = getHeavyLock(lkp, heavyLock);
+  lk = getHeavyLock(lkp);
 	holder = lk->holder;
-	putHeavyLock(lkp, lk);
+  putHeavyLock(lk);
 
-	if (KTHREAD(on_current_stack)(holder)) {
-		slowUnlockMutex(lkp, where, heavyLock);
+  if (holder == cur) {
+    slowUnlockMutex(lkp);
 	}
 }
 
 jboolean
-locks_internal_waitCond(iLock** lkp, jlong timeout, iLock *heavyLock)
+locks_internal_waitCond(iLock** lkp, jlong timeout)
 {
-	iLock* lk;
+  volatile iLock* lk;
 	void* holder;
 	jthread_t cur = KTHREAD(current)();
 	jthread_t *ptr;
 	jboolean r;
+  threadData *tdata;
 
-DBG(SLOWLOCKS,
-    	dprintf("_waitCond(**lkp=%p, timeout=%ld, th=%p)\n",
-	       lkp, (long)timeout, KTHREAD(current)());
-);
+  DBG(SLOWLOCKS,
+      dprintf("_waitCond(lk=%p, timeout=%ld, th=%p)\n",
+	      *lkp, (long)timeout, KTHREAD(current)());
+      );
 
-	lk = getHeavyLock(lkp, heavyLock);
+  lk = getHeavyLock(lkp);
 	holder = lk->holder;
 
 	/* I must be holding the damn thing */
-	if (!KTHREAD(on_current_stack)(holder)) {
-		putHeavyLock(lkp, holder);
+  if (holder != cur) {
+    putHeavyLock(lk);
 		throwException(IllegalMonitorStateException);
 	}
 
-	KTHREAD(get_data)(cur)->nextlk = lk->cv;
+  tdata = KTHREAD(get_data)(cur);
+  tdata->nextlk = lk->cv;
 	lk->cv = cur;
-	putHeavyLock(lkp, lk);
-	slowUnlockMutex(lkp, holder, heavyLock);
-	r = KSEM(get)(&KTHREAD(get_data)(cur)->sem, timeout);
+
+  putHeavyLock(lk);
+  slowUnlockMutex(lkp);
+  r = KSEM(get)(&tdata->sem, timeout);
 
 	/* Timeout */
 	if (r == false) {
-		lk = getHeavyLock(lkp, heavyLock);
+    lk = getHeavyLock(lkp);
 		/* Remove myself from CV or MUX queue - if I'm * not on either
 		 * then I should wait on myself to remove any pending signal.
 		 */
 		for (ptr = &lk->cv; *ptr != 0; ptr = &KTHREAD(get_data)(*ptr)->nextlk) {
 			if ((*ptr) == cur) {
-				*ptr = KTHREAD(get_data)(cur)->nextlk;
+	*ptr = tdata->nextlk;
 				goto found;
 			}
 		}
 		for (ptr = &lk->mux; *ptr != 0; ptr = &KTHREAD(get_data)(*ptr)->nextlk) {
 			if ((*ptr) == cur) {
-				*ptr = KTHREAD(get_data)(cur)->nextlk;
+	*ptr = tdata->nextlk;
 				goto found;
 			}
 		}
 		/* Not on list - so must have been signalled after all -
 		 * decrease the semaphore to avoid problems.
 		 */
-		KSEM(get)(&KTHREAD(get_data)(cur)->sem, (jlong)0);
+    KSEM(get)(&tdata->sem, (jlong)0);
 
 		found:;
-		putHeavyLock(lkp, lk);
+    putHeavyLock(lk);
 	}
 
-	slowLockMutex(lkp, holder, heavyLock);
+  slowLockMutex(lkp);
 
 	return (r);
 }
 
 void
-locks_internal_signalCond(iLock** lkp, iLock *heavyLock)
+locks_internal_signalCond(iLock** lkp)
 {
-	iLock* lk;
+  volatile iLock* lk;
 	jthread_t tid;
 
-DBG(SLOWLOCKS,
-    	dprintf("_signalCond(**lkp=%p, th=%p)\n",
-	       lkp, KTHREAD(current)());
-);
+  DBG(SLOWLOCKS,
+      dprintf("_signalCond(lk=%p, th=%p)\n",
+	      *lkp, KTHREAD(current)());
+      );
 
-	lk = getHeavyLock(lkp, heavyLock);
+  lk = getHeavyLock(lkp);
 
-	if (!KTHREAD(on_current_stack)(lk->holder)) {
-		putHeavyLock(lkp, lk);
+  if (lk->holder != KTHREAD(current)()) {
+    putHeavyLock(lk);
 		throwException(IllegalMonitorStateException);
 	}
 
 	/* Move one CV's onto the MUX */
 	tid = lk->cv;
 	if (tid != 0) {
-		lk->cv = KTHREAD(get_data)(tid)->nextlk;
-		KTHREAD(get_data)(tid)->nextlk = lk->mux;
+    threadData *tdata = KTHREAD(get_data)(tid);
+
+    lk->cv = tdata->nextlk;
+    tdata->nextlk = lk->mux;
 		lk->mux = tid;
 	}
 
-	putHeavyLock(lkp, lk);
+  putHeavyLock(lk);
 }
 
 void
-locks_internal_broadcastCond(iLock** lkp, iLock *heavyLock)
+locks_internal_broadcastCond(iLock** lkp)
 {
 	iLock* lk;
 	jthread_t tid;
 
-DBG(SLOWLOCKS,
-    	dprintf("_broadcastCond(**lkp=%p, th=%p)\n",
-	       lkp, KTHREAD(current)());
-);
+  DBG(SLOWLOCKS,
+      dprintf("_broadcastCond(lk=%p, th=%p)\n",
+	      *lkp, KTHREAD(current)());
+      );
 
-	lk = getHeavyLock(lkp, heavyLock);
+  lk = getHeavyLock(lkp);
 
-	if (!KTHREAD(on_current_stack)(lk->holder)) {
-		putHeavyLock(lkp, lk);
+  if (lk->holder != KTHREAD(current)()) {
+    putHeavyLock(lk);
 		throwException(IllegalMonitorStateException);
 	}
 
 	/* Move all the CV's onto the MUX */
 	while (lk->cv != 0) {
+    threadData *tdata;
+
 		tid = lk->cv;
-		lk->cv = KTHREAD(get_data)(tid)->nextlk;
-		KTHREAD(get_data)(tid)->nextlk = lk->mux;
+    tdata = KTHREAD(get_data)(tid);
+    lk->cv = tdata->nextlk;
+    tdata->nextlk = lk->mux;
 		lk->mux = tid;
 	}
 
-	putHeavyLock(lkp, lk);
+  putHeavyLock(lk);
 }
 
 /*
@@ -418,21 +464,27 @@
  * contention then fall back on a slow lock.
  */
 void
-locks_internal_lockMutex(iLock** lkp, void* where, iLock *heavyLock)
+locks_internal_lockMutex(iLock** lkp, iLock *heavyLock)
 {
-	uintp val;
-
-	val = (uintp)*lkp;
+  COMPARE_AND_EXCHANGE(lkp, LOCKFREE, heavyLock);
+  /* This small checking may speed up things on most locks */
+#if 0
+  if (*lkp != NULL && (*lkp)->allocated && COMPARE_AND_EXCHANGE(&(*lkp)->in_progress, 0, 1))
+    {
+      iLock *lk = *lkp;
+      /* If the thread system is not yet initialized, this call will return NULL.
+       * so no harm is done.
+       * TODO: Avoid the call to KTHREAD(current).
+       */
+      jthread_t cur = KTHREAD(current)();
 
-	if (val == 0) {
-		if (!COMPARE_AND_EXCHANGE(lkp, 0, (iLock*)where)) {
-			slowLockMutex(lkp, where, heavyLock);
-		}
-	}
-	else if (!KTHREAD(on_current_stack)((void *)val)) {
-		/* XXX count this in the stats area */
-		slowLockMutex(lkp, where, heavyLock);
+      lk->holder = cur;
+      lk->lockCount++;
+      putHeavyLock(lk);
 	}
+  else
+#endif
+    slowLockMutex(lkp);
 }
 
 /*
@@ -440,35 +492,26 @@
  * we've got contention so fall back on a slow lock.
  */
 void
-locks_internal_unlockMutex(iLock** lkp, void* where, iLock *heavyLock)
+locks_internal_unlockMutex(iLock** lkp)
 {
-	uintp val;
-
-	val = (uintp)*lkp;
-
-	if ((val & 1) != 0) {
-		slowUnlockMutex(lkp, where, heavyLock);
-	}
-	else if ((val == (uintp)where) /* XXX squirrely bit */
-		&& !COMPARE_AND_EXCHANGE(lkp, (iLock*)where, LOCKFREE)) {
-		slowUnlockMutex(lkp, where, heavyLock);
-	}
+  /* slowUnlockMutex should be fast enough. */
+  slowUnlockMutex(lkp);
 }
 
 void
 lockObject(Hjava_lang_Object* obj)
 {
-	locks_internal_lockMutex(&obj->lock, &obj, NULL);
+  locks_internal_lockMutex(&obj->lock, NULL);
 }
 
 void
 unlockObject(Hjava_lang_Object* obj)
 {
-	locks_internal_unlockMutex(&obj->lock, &obj, NULL);
+  locks_internal_unlockMutex(&obj->lock);
 }
 
 void
-slowLockObject(Hjava_lang_Object* obj, void* where)
+slowLockObject(Hjava_lang_Object* obj)
 {
 #if defined(ENABLE_JVMPI)
 	if( JVMPI_EVENT_ISENABLED(JVMPI_EVENT_MONITOR_CONTENDED_ENTER) )
@@ -480,7 +523,7 @@
 		jvmpiPostEvent(&ev);
 	}
 #endif
-	slowLockMutex(&obj->lock, where, NULL);
+  slowLockMutex(&obj->lock);
 #if defined(ENABLE_JVMPI)
 	if( JVMPI_EVENT_ISENABLED(JVMPI_EVENT_MONITOR_CONTENDED_ENTERED) )
 	{
@@ -494,7 +537,7 @@
 }
 
 void
-slowUnlockObject(Hjava_lang_Object* obj, void* where)
+slowUnlockObject(Hjava_lang_Object* obj)
 {
 #if defined(ENABLE_JVMPI)
 	if( JVMPI_EVENT_ISENABLED(JVMPI_EVENT_MONITOR_CONTENDED_EXIT) )
@@ -506,7 +549,7 @@
 		jvmpiPostEvent(&ev);
 	}
 #endif
-	slowUnlockMutex(&obj->lock, where, NULL);
+  slowUnlockMutex(&obj->lock);
 }
 
 void
Index: kaffe/kaffevm/locks.h
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/locks.h,v
retrieving revision 1.27
diff -u -B -b -r1.27 locks.h
--- kaffe/kaffevm/locks.h	17 Dec 2004 17:47:35 -0000	1.27
+++ kaffe/kaffevm/locks.h	7 Mar 2005 19:00:50 -0000
@@ -17,25 +17,26 @@
 
 #include "md.h"
 #include "support.h"
+#include "ksem.h"
 
 struct _iLock;
 
 #define	LOCKOBJECT			struct _iLock**
-#define	lockMutex(O)			(KTHREAD(disable_stop)(), locks_internal_lockMutex(&(O)->lock, &iLockRoot, NULL))
-#define	unlockMutex(O)			do { locks_internal_unlockMutex(&(O)->lock, &iLockRoot, NULL); KTHREAD(enable_stop)(); } while (0)
-#define	waitCond(O,T)			locks_internal_waitCond(&(O)->lock, (T), NULL)
-#define	signalCond(O)			locks_internal_signalCond(&(O)->lock, NULL)
-#define	broadcastCond(O)		locks_internal_broadcastCond(&(O)->lock, NULL)
-
-#define	lockStaticMutex(THING)		(KTHREAD(disable_stop)(), locks_internal_lockMutex(&(THING)->lock, &iLockRoot, &(THING)->heavyLock))
-#define	unlockStaticMutex(THING)	do { locks_internal_unlockMutex(&(THING)->lock, &iLockRoot, &(THING)->heavyLock); KTHREAD(enable_stop)(); } while(0)
-#define	waitStaticCond(THING, TIME)	locks_internal_waitCond(&(THING)->lock, (TIME), &(THING)->heavyLock)
-#define	signalStaticCond(THING)		locks_internal_signalCond(&(THING)->lock, &(THING)->heavyLock)
-#define	broadcastStaticCond(THING)	locks_internal_broadcastCond(&(THING)->lock, &(THING)->heavyLock)
+#define	lockMutex(O)			(KTHREAD(disable_stop)(), locks_internal_lockMutex(&(O)->lock, NULL))
+#define	unlockMutex(O)			do { locks_internal_unlockMutex(&(O)->lock); KTHREAD(enable_stop)(); } while (0)
+#define	waitCond(O,T)			locks_internal_waitCond(&(O)->lock, (T))
+#define	signalCond(O)			locks_internal_signalCond(&(O)->lock)
+#define	broadcastCond(O)		locks_internal_broadcastCond(&(O)->lock)
+
+#define	lockStaticMutex(THING)		(KTHREAD(disable_stop)(), locks_internal_lockMutex(&(THING)->lock, &(THING)->heavyLock))
+#define	unlockStaticMutex(THING)	do { locks_internal_unlockMutex(&(THING)->lock); KTHREAD(enable_stop)(); } while(0)
+#define	waitStaticCond(THING, TIME)	locks_internal_waitCond(&(THING)->lock, (TIME))
+#define	signalStaticCond(THING)		locks_internal_signalCond(&(THING)->lock)
+#define	broadcastStaticCond(THING)	locks_internal_broadcastCond(&(THING)->lock)
 
 struct Hjava_lang_Object;
 
-/*
+/**
  * The "heavy" alternative when fast-locking encounters true
  * contention, and for some of the global locks.  The _iLock
  * works like a monitor (i.e. Java locks).  The "holder" field
@@ -44,9 +45,16 @@
  * unlock and for distinguishing recursive invocations).
  */
 typedef struct _iLock {
+  /* It is important this one to be the first */
+  uintp         allocated;
+  uint8         in_progress;
+  uint16        num_wait;
+  uint8         lockCount;
 	void*		holder;
 	jthread_t	mux;
 	jthread_t	cv;
+  Ksem       *sem;
+  Ksem        real_sem;
 } iLock;
 
 typedef struct _iStaticLock {
@@ -54,10 +62,8 @@
 	iLock	heavyLock; 
 } iStaticLock;
 
-#define KAFFE_STATIC_LOCK_INITIALIZER { NULL, { NULL, (jthread_t)0, (jthread_t)0 } }
-
-#define	LOCKINPROGRESS	((iLock*)-1)
 #define	LOCKFREE	((iLock*)0)
+#define INIT_LOCKVAR
 
 extern void	initLocking(void);
 
@@ -66,15 +72,15 @@
  */
 extern void	lockObject(struct Hjava_lang_Object*);
 extern void	unlockObject(struct Hjava_lang_Object*);
-extern void 	slowLockObject(struct Hjava_lang_Object*, void*);
-extern void 	slowUnlockObject(struct Hjava_lang_Object*, void*);
+extern void 	slowLockObject(struct Hjava_lang_Object*);
+extern void 	slowUnlockObject(struct Hjava_lang_Object*);
 
-extern void	locks_internal_lockMutex(LOCKOBJECT, void*, iLock *heavyLock);
-extern void	locks_internal_unlockMutex(LOCKOBJECT, void*, iLock *heavyLock);
-extern jboolean	locks_internal_waitCond(LOCKOBJECT, jlong, iLock *heavyLock);
-extern void	locks_internal_signalCond(LOCKOBJECT, iLock *heavyLock);
-extern void	locks_internal_broadcastCond(LOCKOBJECT, iLock *heavyLock);
-extern void	locks_internal_slowUnlockMutexIfHeld(LOCKOBJECT, void*, iLock *heavyLock);
+extern void	locks_internal_lockMutex(LOCKOBJECT, iLock *heavyLock);
+extern void	locks_internal_unlockMutex(LOCKOBJECT);
+extern jboolean	locks_internal_waitCond(LOCKOBJECT, jlong);
+extern void	locks_internal_signalCond(LOCKOBJECT);
+extern void	locks_internal_broadcastCond(LOCKOBJECT);
+extern void	locks_internal_slowUnlockMutexIfHeld(LOCKOBJECT);
 
 extern void	dumpLocks(void);
 
Index: kaffe/kaffevm/lookup.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/lookup.c,v
retrieving revision 1.42
diff -u -B -b -r1.42 lookup.c
--- kaffe/kaffevm/lookup.c	20 Dec 2004 02:12:53 -0000	1.42
+++ kaffe/kaffevm/lookup.c	7 Mar 2005 19:00:50 -0000
@@ -155,7 +155,6 @@
 	Utf8Const *name;
 	Hjava_lang_Class* class;
 	int tag;
-	int iLockRoot;
 
 	pool = CLASS_CONSTANTS(this);
 
Index: kaffe/kaffevm/reference.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/reference.c,v
retrieving revision 1.2
diff -u -B -b -r1.2 reference.c
--- kaffe/kaffevm/reference.c	30 Jan 2005 18:21:38 -0000	1.2
+++ kaffe/kaffevm/reference.c	7 Mar 2005 19:00:50 -0000
@@ -33,7 +33,7 @@
   referenceLinkList *references;
 } referenceLinkListHead;
 
-static iStaticLock referencesLock = KAFFE_STATIC_LOCK_INITIALIZER;
+static iStaticLock referencesLock;
 static hashtab_t referencesHashTable;
 static uint32 referentOffset = ~((uint32)0);
 
@@ -69,7 +69,6 @@
 
 void KaffeVM_registerObjectReference(jobject reference, jobject obj, kgc_reference_type reftype)
 {
-  int iLockRoot;
   referenceLinkList *ll;
   referenceLinkListHead *head, *temp;
 
@@ -123,7 +122,6 @@
 
 bool KaffeVM_isReferenced(jobject obj)
 {
-  int iLockRoot;
   referenceLinkListHead *ref;
 
   lockStaticMutex(&referencesLock);
@@ -154,7 +152,6 @@
 static void
 referenceObjectFinalizer(jobject ob)
 {
-  int iLockRoot;
   referenceLinkListHead *head;
   referenceLinkList *ll;
   referenceLinkListHead search_ref;
@@ -200,7 +197,6 @@
 static void
 referenceFinalizer(jobject ref)
 {
-  int iLockRoot;
   void *referent;
   referenceLinkList **ll;
   referenceLinkListHead *head;
Index: kaffe/kaffevm/string.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/string.c,v
retrieving revision 1.39
diff -u -B -b -r1.39 string.c
--- kaffe/kaffevm/string.c	21 Dec 2004 08:06:37 -0000	1.39
+++ kaffe/kaffevm/string.c	7 Mar 2005 19:00:51 -0000
@@ -23,8 +23,7 @@
 
 /* Internal variables */
 static hashtab_t	hashTable;	/* intern hash table */
-static iStaticLock	stringLock = KAFFE_STATIC_LOCK_INITIALIZER; /* mutex on all intern operations */
-static int *            stringLockRoot = NULL;	/* the string lock is not a monitor */
+static iStaticLock	stringLock; /* mutex on all intern operations */
 
 /* Internal functions */
 static int		stringHashValue(void *ptr);
@@ -278,26 +277,21 @@
 stringAlloc(size_t sz)
 {
 	void* p;
-	int *myRoot = stringLockRoot;
 
 	/* XXX assumes stringLock isn't acquired recursively (which it isn't) */
-	locks_internal_unlockMutex(&stringLock.lock, myRoot, &stringLock.heavyLock);
+	unlockStaticMutex(&stringLock);
 	p = gc_malloc(sz, KGC_ALLOC_FIXED);
-	locks_internal_lockMutex(&stringLock.lock, myRoot, &stringLock.heavyLock);
-	stringLockRoot = myRoot;
-	return (p);
+	lockStaticMutex(&stringLock);
+	return p;
 }
 
 static void
 stringFree(const void *ptr)
 {
-	int *myRoot = stringLockRoot;
-
 	/* XXX assumes stringLock isn't acquired recursively (which it isn't) */
-	locks_internal_unlockMutex(&stringLock.lock, myRoot, &stringLock.heavyLock);
+        unlockStaticMutex(&stringLock);	
 	KFREE(ptr);
-	locks_internal_lockMutex(&stringLock.lock, myRoot, &stringLock.heavyLock);
-	stringLockRoot = myRoot;
+	lockStaticMutex(&stringLock);
 }
 
 /*
@@ -307,12 +301,10 @@
 const Hjava_lang_String *
 stringInternString(Hjava_lang_String *string)
 {
-	int iLockRoot;
 	const Hjava_lang_String *temp;
 
 	/* Lock intern table */
 	lockStaticMutex(&stringLock);
-	stringLockRoot = &iLockRoot;
 
 	/* See if string is already in the table */
 	if (hashTable != NULL) {
@@ -348,7 +340,6 @@
 void
 stringUninternString(Hjava_lang_String* string)
 {
-	int iLockRoot;
 
 	lockStaticMutex(&stringLock);
 	if (!unhand(string)->interned)
@@ -356,7 +347,6 @@
 	  unlockStaticMutex(&stringLock);
 	  return;
 	}
-	stringLockRoot = &iLockRoot;
 	hashRemove(hashTable, string);
 	unhand(string)->interned = false;
 	unlockStaticMutex(&stringLock);
@@ -426,7 +416,6 @@
 	Hjava_lang_String *string;
 	HArrayOfChar *ary;
 	errorInfo info;
-	int iLockRoot;
 
 	/* Lock intern table 
 	 * NB: we must not hold stringLock when we call KMALLOC/KFREE!
@@ -458,7 +447,6 @@
 
 		/* Return existing copy of this string, if any */
 		lockStaticMutex(&stringLock);
-		stringLockRoot = &iLockRoot;
 		string = hashFind(hashTable, &fakeString);
 		unlockStaticMutex(&stringLock);
 
Index: kaffe/kaffevm/thread.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/thread.c,v
retrieving revision 1.92
diff -u -B -b -r1.92 thread.c
--- kaffe/kaffevm/thread.c	30 Jan 2005 18:21:38 -0000	1.92
+++ kaffe/kaffevm/thread.c	7 Mar 2005 19:00:51 -0000
@@ -282,8 +282,10 @@
 	void **pointer_args = (void **)arg;
 	void *argument;
 	jthread_t calling_thread;
+	threadData *thread_data = THREAD_DATA();
 
-	KSEM(init)(&THREAD_DATA()->sem);
+	KSEM(init)(&thread_data->sem);
+	KSEM(init)(&thread_data->heavy_sem);
 
 	/* We save the value before the lock so we are sure
 	 * pointer_args is still a valid pointer on the stack.
@@ -297,9 +299,9 @@
 	/* We have now to wait the parent to synchronize the data
 	 * and link the thread to the Java VM.
 	 */
-	KSEM(get)(&THREAD_DATA()->sem, (jlong)0);
+	KSEM(get)(&thread_data->sem, (jlong)0);
 
-	THREAD_DATA()->exceptObj = NULL;
+	thread_data->exceptObj = NULL;
 
 	func(argument);
 }
@@ -388,18 +390,21 @@
 	JNIEnv *env;
 	jmethodID runmethod;
 	jthread_t calling_thread = (jthread_t) arg;
+	threadData *thread_data;
 
 	cur = KTHREAD(current)();
+	thread_data = KTHREAD(get_data)(cur);
 
-	KSEM(init)(&KTHREAD(get_data)(cur)->sem);
+	KSEM(init)(&thread_data->sem);
+	KSEM(init)(&thread_data->heavy_sem);
 
 	/* We acknowledge the parent thread that this thread has been started. */
 	KSEM(put)(&KTHREAD(get_data)(calling_thread)->sem);
 	/* Now we must wait the parent to link the thread to the Java VM. */
-	KSEM(get)(&KTHREAD(get_data)(cur)->sem, (jlong)0);
+	KSEM(get)(&thread_data->sem, (jlong)0);
  
-	tid = (Hjava_lang_VMThread *)(KTHREAD(get_data)(cur)->jlThread);
-	env = &KTHREAD(get_data)(cur)->jniEnv;
+	tid = (Hjava_lang_VMThread *)(thread_data->jlThread);
+	env = &thread_data->jniEnv;
 
 #if defined(ENABLE_JVMPI)
 	if( JVMPI_EVENT_ISENABLED(JVMPI_EVENT_THREAD_START) )
@@ -552,7 +557,6 @@
 {
         Hjava_lang_VMThread *vmtid = (Hjava_lang_VMThread *)jlThread;
 	Hjava_lang_Thread *tid = unhand(vmtid)->thread;
-	int iLockRoot;
 
         /* Notify on the object just in case anyone is waiting */
         lockMutex(&tid->base);
@@ -723,6 +727,7 @@
 	thread_data = THREAD_DATA(); 
 
 	KSEM(init)(&thread_data->sem);
+	KSEM(init)(&thread_data->heavy_sem);
 
 	thread_data->jnireferences = NULL;
 	thread_data->jniEnv = &Kaffe_JNINativeInterface;
Index: kaffe/kaffevm/threadData.h
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/threadData.h,v
retrieving revision 1.6
diff -u -B -b -r1.6 threadData.h
--- kaffe/kaffevm/threadData.h	30 Jan 2005 12:42:41 -0000	1.6
+++ kaffe/kaffevm/threadData.h	7 Mar 2005 19:00:51 -0000
@@ -27,6 +27,7 @@
 
 	/* things required by the locking subsystem */
 	struct Ksem	sem;
+  struct Ksem     heavy_sem;
 	struct _jthread	*nextlk;
 
 
Index: kaffe/kaffevm/utf8const.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/utf8const.c,v
retrieving revision 1.45
diff -u -B -b -r1.45 utf8const.c
--- kaffe/kaffevm/utf8const.c	30 Jan 2005 12:42:41 -0000	1.45
+++ kaffe/kaffevm/utf8const.c	7 Mar 2005 19:00:51 -0000
@@ -38,7 +38,7 @@
 /* Internal variables */
 #ifndef KAFFEH				/* Yuk! */
 static hashtab_t	hashTable;
-static iStaticLock	utf8Lock = KAFFE_STATIC_LOCK_INITIALIZER;	/* mutex on all intern operations */
+static iStaticLock	utf8Lock;	/* mutex on all intern operations */
 
 /*
  * Used to keep track of the current utf8Lock holder's stack
@@ -49,61 +49,26 @@
  * Also used by debugging code to assert that the utf8Lock is never
  * recursively acquired.
  */
-static int *utfLockRoot = NULL;
 
-static inline void do_lockUTF(int *where)
-{
-	KTHREAD(disable_stop)();
-	locks_internal_lockMutex(&utf8Lock.lock, where, &utf8Lock.heavyLock);
-	DBGIF(assert(utfLockRoot == NULL));
-	utfLockRoot = where;
-}
-
-static inline void do_unlockUTF(int *where)
-{
-	DBGIF(assert(utfLockRoot != NULL));
-	DBGIF(utfLockRoot = NULL);
-	locks_internal_unlockMutex(&utf8Lock.lock, where, &utf8Lock.heavyLock);
-	KTHREAD(enable_stop)();
-}
-
-/* convenience macros which assume the iLockRoot local variable */
-#define lockUTF()   do_lockUTF(&iLockRoot)
-#define unlockUTF() do_unlockUTF(&iLockRoot)
+#define lockUTF() lockStaticMutex(&utf8Lock)
+#define unlockUTF() unlockStaticMutex(&utf8Lock)
 
 static inline void *UTFmalloc(size_t size)
 {
 	void *ret;
-	int *myRoot;
-
-	DBGIF(assert(utfLockRoot != NULL));
-	myRoot = utfLockRoot;
-	DBGIF(utfLockRoot = NULL);
-	locks_internal_unlockMutex(&utf8Lock.lock, myRoot, &utf8Lock.heavyLock);
 
+	unlockStaticMutex(&utf8Lock);
 	ret = gc_malloc(size, KGC_ALLOC_UTF8CONST);
-
-	locks_internal_lockMutex(&utf8Lock.lock, myRoot, &utf8Lock.heavyLock);
-	DBGIF(assert(utfLockRoot == NULL));
-	utfLockRoot = myRoot;
+	lockStaticMutex(&utf8Lock);
 
 	return ret;
 }
 
 static inline void UTFfree(const void *mem)
 {
-	int *myRoot;
-
-	DBGIF(assert(utfLockRoot != NULL));
-	myRoot = utfLockRoot;
-	DBGIF(utfLockRoot = NULL);
-	locks_internal_unlockMutex(&utf8Lock.lock, myRoot, &utf8Lock.heavyLock);
-
+        unlockStaticMutex(&utf8Lock);
 	gc_free((void *)mem);
-
-	locks_internal_lockMutex(&utf8Lock.lock, myRoot, &utf8Lock.heavyLock);
-	DBGIF(assert(utfLockRoot == NULL));
-	utfLockRoot = myRoot;
+	lockStaticMutex(&utf8Lock);
 }
 #else /* KAFFEH replacements: */
 static hashtab_t	hashTable = (hashtab_t)1;
@@ -131,7 +96,6 @@
 	Utf8Const *fake;
 	char buf[200];
 #if !defined(KAFFEH)
-	int iLockRoot;
 #endif
 
 	/* Automatic length finder */
@@ -235,7 +199,6 @@
 utf8ConstAddRef(Utf8Const *utf8)
 {
 #if !defined(KAFFEH)
-	int iLockRoot;
 #endif
 	lockUTF();
 	assert(utf8->nrefs >= 1);
@@ -250,7 +213,6 @@
 utf8ConstRelease(Utf8Const *utf8)
 {
 #if !defined(KAFFEH)
-	int iLockRoot;
 #endif
 	/* NB: we ignore zero utf8s here in order to not having to do it at
 	 * the call sites, such as when destroying half-processed class 
@@ -406,7 +368,6 @@
 utf8ConstInit(void)
 {
 #if !defined(KAFFEH)
-	int iLockRoot;
 #endif
 	DBG(INIT, dprintf("utf8ConstInit()\n"); );
 
Index: kaffe/kaffevm/boehm-gc/gc2.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/boehm-gc/gc2.c,v
retrieving revision 1.8
diff -u -B -b -r1.8 gc2.c
--- kaffe/kaffevm/boehm-gc/gc2.c	25 Dec 2004 19:09:14 -0000	1.8
+++ kaffe/kaffevm/boehm-gc/gc2.c	7 Mar 2005 19:00:51 -0000
@@ -44,9 +44,9 @@
         int                     mem;		/* only used ifdef STATS */
 } gcFuncs;
 
-static iStaticLock	gcman_lock = KAFFE_STATIC_LOCK_INITIALIZER;
-static iStaticLock	gcmanend_lock = KAFFE_STATIC_LOCK_INITIALIZER;
-static iStaticLock	finman_lock = KAFFE_STATIC_LOCK_INITIALIZER;
+static iStaticLock	gcman_lock;
+static iStaticLock	gcmanend_lock;
+static iStaticLock	finman_lock;
 static volatile int finalRunning = -1; 
 static volatile int gcRunning = -1;
 static volatile int gcDisabled = 0;
@@ -154,7 +154,6 @@
 static void NONRETURNING
 finaliserMan(void* arg UNUSED)
 {
-  int iLockRoot;
 
   lockStaticMutex(&finman_lock);
   for (;;) {
@@ -178,7 +177,6 @@
 void
 KaffeGC_SignalFinalizer(void)
 {
-  int iLockRoot;
 
   lockStaticMutex(&finman_lock);
   if (finalRunning == 0) {
@@ -207,7 +205,6 @@
 void
 KaffeGC_InvokeGC(Collector* gcif UNUSED, int mustgc)
 {
-  int iLockRoot;
 
   while (gcRunning < 0)
     KTHREAD(yield)();
@@ -231,7 +228,6 @@
 static void NONRETURNING
 gcMan(UNUSED void* arg)
 {
-  int iLockRoot;
 
   lockStaticMutex(&gcman_lock);
   gcRunning = 0;
@@ -253,7 +249,6 @@
 static void
 KaffeGC_EnableGC(Collector* gcif UNUSED)
 {
-  int iLockRoot;
 
   lockStaticMutex(&gcman_lock);
   gcDisabled -= 1;
@@ -265,7 +260,6 @@
 static void
 KaffeGC_DisableGC(Collector* gcif UNUSED)
 {
-  int iLockRoot;
 
   lockStaticMutex(&gcman_lock);
   gcDisabled += 1;
Index: kaffe/kaffevm/intrp/machine.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/intrp/machine.c,v
retrieving revision 1.48
diff -u -B -b -r1.48 machine.c
--- kaffe/kaffevm/intrp/machine.c	6 Feb 2005 13:51:30 -0000	1.48
+++ kaffe/kaffevm/intrp/machine.c	7 Mar 2005 19:00:55 -0000
@@ -220,7 +220,7 @@
 			mobj = (Hjava_lang_Object*)lcl[0].v.taddr;
 		}
 		/* this lock is safe for Thread.stop() */
-		locks_internal_lockMutex(&mobj->lock, &mjbuf, 0);
+		locks_internal_lockMutex(&mobj->lock, 0);
 
 		/*
 		 * We must store the object on which we synchronized
@@ -237,7 +237,7 @@
  end:
 	/* Unsync. if required */
 	if (mobj != 0) {
-		locks_internal_unlockMutex(&mobj->lock, &mjbuf, 0); 
+		locks_internal_unlockMutex(&mobj->lock); 
 	}
 
 	cleanupExceptionHandling(&mjbuf, thread_data);
Index: kaffe/kaffevm/jit/machine.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/jit/machine.c,v
retrieving revision 1.75
diff -u -B -b -r1.75 machine.c
--- kaffe/kaffevm/jit/machine.c	10 Jan 2005 10:30:19 -0000	1.75
+++ kaffe/kaffevm/jit/machine.c	7 Mar 2005 19:00:55 -0000
@@ -202,7 +202,6 @@
 	int64 tms = 0;
 	int64 tme;
 
-	int iLockRoot;
 
 	static Method* jitting = NULL;	/* DEBUG */
 
Index: kaffe/kaffevm/jit/native-wrapper.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/jit/native-wrapper.c,v
retrieving revision 1.7
diff -u -B -b -r1.7 native-wrapper.c
--- kaffe/kaffevm/jit/native-wrapper.c	30 Jan 2005 12:42:42 -0000	1.7
+++ kaffe/kaffevm/jit/native-wrapper.c	7 Mar 2005 19:00:55 -0000
@@ -89,7 +89,6 @@
 	bool success = true;
 	int j;
 	int an;
-	int iLockRoot;
 
 	isStatic = METHOD_IS_STATIC(xmeth) ? 1 : 0;
 	count = sizeofSigMethod(xmeth, false);
Index: kaffe/kaffevm/jit3/machine.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/jit3/machine.c,v
retrieving revision 1.71
diff -u -B -b -r1.71 machine.c
--- kaffe/kaffevm/jit3/machine.c	14 Jan 2005 16:52:00 -0000	1.71
+++ kaffe/kaffevm/jit3/machine.c	7 Mar 2005 19:00:56 -0000
@@ -180,7 +180,6 @@
 	static bool reinvoke = false;
 
 	jboolean success = true;
-	int iLockRoot;
 
 	lockClass(xmeth->class);
 
Index: kaffe/kaffevm/kaffe-gc/gc-incremental.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c,v
retrieving revision 1.19
diff -u -B -b -r1.19 gc-incremental.c
--- kaffe/kaffevm/kaffe-gc/gc-incremental.c	13 Feb 2005 16:51:37 -0000	1.19
+++ kaffe/kaffevm/kaffe-gc/gc-incremental.c	7 Mar 2005 19:00:56 -0000
@@ -168,11 +168,11 @@
         gcStats.markedmem += size;
 } 
 
-static iStaticLock	gcman = KAFFE_STATIC_LOCK_INITIALIZER;
-static iStaticLock	finman = KAFFE_STATIC_LOCK_INITIALIZER;
-static iStaticLock	gcmanend = KAFFE_STATIC_LOCK_INITIALIZER;
-static iStaticLock	finmanend = KAFFE_STATIC_LOCK_INITIALIZER;
-static iStaticLock	gc_lock = KAFFE_STATIC_LOCK_INITIALIZER;	/* allocator mutex */
+static iStaticLock	gcman; 
+static iStaticLock	finman;
+static iStaticLock	gcmanend;
+static iStaticLock	finmanend;
+static iStaticLock	gc_lock;	/* allocator mutex */
 
 static void gcFree(Collector* gcif, void* mem);
 
@@ -386,7 +386,6 @@
 {
 	int idx;
 	gc_block* info;
-	int iLockRoot;
 
 	/* quickly reject pointers that are not part of this heap */
 	if (!IS_A_HEAP_POINTER(mem)) {
@@ -504,7 +503,6 @@
 	gc_block* info;
 	uintp idx;
 	Collector *gcif = (Collector*)arg;
-	int iLockRoot;
 
 	lockStaticMutex(&gcman);
 	gcRunning = 0;
@@ -840,7 +838,6 @@
 void
 startFinalizer(void)
 {
-	int iLockRoot;
 	int start;
 
         start = 0;
@@ -867,7 +864,7 @@
  * the objects in turn.  An object is only finalised once after which
  * it is deleted.
  */
-static void finaliserJob(Collector *gcif, int *where)
+static void finaliserJob(Collector *gcif)
 {
   gc_block* info = NULL;
   gc_unit* unit = NULL;
@@ -939,7 +936,6 @@
 finaliserMan(void* arg)
 {
   Collector *gcif = (Collector*)arg;
-  int iLockRoot;
     
   lockStaticMutex(&finman);
   for (;;) {
@@ -949,7 +945,7 @@
     }
     assert(finalRunning == true);
     
-    finaliserJob(gcif, &iLockRoot);
+    finaliserJob(gcif);
     
     /* Wake up anyone waiting for the finalizer to finish */
     lockStaticMutex(&finmanend);
@@ -963,7 +959,6 @@
 void
 gcEnableGC(Collector* gcif UNUSED)
 {
-	int iLockRoot;
 
 	lockStaticMutex(&gcman);
 	gcDisabled -= 1;
@@ -976,7 +971,6 @@
 void
 gcDisableGC(Collector* gcif UNUSED)
 {
-	int iLockRoot;
 
 	lockStaticMutex(&gcman);
 	gcDisabled += 1;
@@ -990,7 +984,6 @@
 void
 gcInvokeGC(Collector* gcif UNUSED, int mustgc)
 {
-	int iLockRoot;
 
 	while (gcRunning < 0)
 		KTHREAD(yield)();
@@ -1018,7 +1011,6 @@
 void
 gcInvokeFinalizer(Collector* gcif)
 {
-	int iLockRoot;
 
 	/* First invoke the GC */
 	KGC_invoke(gcif, 1);
@@ -1055,7 +1047,6 @@
 	void * volatile mem;	/* needed on SGI, see comment below */
 	int i;
 	size_t bsz;
-	int iLockRoot;
 	int times = 0;
 
 	assert(gc_init != 0);
@@ -1189,7 +1180,6 @@
 {
 	Hjava_lang_Throwable *ret = NULL;
 	int reffed;
-	int iLockRoot;
 
 	/*
 	 * Make sure we are the only thread to use this exception
@@ -1236,7 +1226,6 @@
 	void* newmem;
 	gc_unit* unit;
 	size_t osize;
-	int iLockRoot;
 
 	assert(gcFunctions[fidx].final == KGC_OBJECT_FIXED);
 
@@ -1281,7 +1270,6 @@
 	gc_block* info;
 	int idx;
 	gc_unit* unit;
-	int iLockRoot;
 
 	if (mem != NULL) {
 		lockStaticMutex(&gc_lock);
Index: kaffe/kaffevm/kaffe-gc/gc-mem.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c,v
retrieving revision 1.24
diff -u -B -b -r1.24 gc-mem.c
--- kaffe/kaffevm/kaffe-gc/gc-mem.c	16 Jan 2005 09:09:01 -0000	1.24
+++ kaffe/kaffevm/kaffe-gc/gc-mem.c	7 Mar 2005 19:00:56 -0000
@@ -354,7 +354,6 @@
 	gc_block** mptr;
 	gc_block* blk;
 	size_t nsz;
-	int iLockRoot;
 
 	lockStaticMutex(&gc_heap_lock);
 
@@ -453,7 +452,6 @@
 	int lnr;
 	int msz;
 	int idx;
-	int iLockRoot;
 
 	info = gc_mem2block(mem);
 	idx = GCMEM2IDX(info, mem);
@@ -1183,7 +1181,6 @@
 gc_heap_grow(size_t sz)
 {
 	gc_block* blk;
-	int iLockRoot;
 
 	if (KGC_SMALL_OBJECT(sz)) {
 		sz = gc_pgsize;
Index: kaffe/kaffevm/kaffe-gc/gc-refs.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/kaffe-gc/gc-refs.c,v
retrieving revision 1.11
diff -u -B -b -r1.11 gc-refs.c
--- kaffe/kaffevm/kaffe-gc/gc-refs.c	30 Jan 2005 12:42:44 -0000	1.11
+++ kaffe/kaffevm/kaffe-gc/gc-refs.c	7 Mar 2005 19:00:56 -0000
@@ -52,8 +52,8 @@
 
 static strongRefTable			strongRefObjects;
 static weakRefTable                     weakRefObjects;
-static iStaticLock                      strongRefLock = KAFFE_STATIC_LOCK_INITIALIZER;
-static iStaticLock                      weakRefLock = KAFFE_STATIC_LOCK_INITIALIZER;
+static iStaticLock                      strongRefLock;
+static iStaticLock                      weakRefLock;
 
 /* This is a bit homemade.  We need a 7-bit hash from the address here */
 #define	REFOBJHASH(V)	((((uintp)(V) >> 2) ^ ((uintp)(V) >> 9))%REFOBJHASHSZ)
@@ -64,7 +64,6 @@
 bool
 KaffeGC_addRef(Collector *collector, const void* mem)
 {
-  int iLockRoot;
   uint32 idx;
   strongRefObject* obj;
 
@@ -99,7 +98,6 @@
 bool
 KaffeGC_rmRef(Collector *collector, void* mem)
 {
-  int iLockRoot;
   uint32 idx;
   strongRefObject** objp;
   strongRefObject* obj;
@@ -128,7 +126,6 @@
 bool
 KaffeGC_addWeakRef(Collector *collector, void* mem, void** refobj)
 {
-  int iLockRoot;
   int idx;
   weakRefObject* obj;
 
@@ -173,7 +170,6 @@
 bool
 KaffeGC_rmWeakRef(Collector *collector, void* mem, void** refobj)
 {
-  int iLockRoot;
   uint32 idx;
   weakRefObject** objp;
   weakRefObject* obj;
@@ -314,7 +310,6 @@
 {
   int i;
   strongRefObject* robj;
-  int iLockRoot;
   
 DBG(GCWALK,
     dprintf("Walking gc roots...\n");
@@ -359,7 +354,6 @@
   weakRefObject** objp;
   weakRefObject* obj;
   unsigned int i;
-  int iLockRoot;
 
   idx = REFOBJHASH(mem);
 
Index: kaffe/xprof/debugFile.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/xprof/debugFile.c,v
retrieving revision 1.7
diff -u -B -b -r1.7 debugFile.c
--- kaffe/xprof/debugFile.c	14 Dec 2004 08:23:00 -0000	1.7
+++ kaffe/xprof/debugFile.c	7 Mar 2005 19:00:58 -0000
@@ -412,7 +412,7 @@
 int addDebugInfo(struct debug_file *df, df_tag_t tag, ...)
 {
 	int retval = 1;
-	int iLockRoot;
+	INIT_LOCKVAR;
 	va_list args;
 
 #if defined(KAFFE_XPROFILER)
Index: kaffe/xprof/feedback.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/xprof/feedback.c,v
retrieving revision 1.4
diff -u -B -b -r1.4 feedback.c
--- kaffe/xprof/feedback.c	18 Sep 2004 20:48:17 -0000	1.4
+++ kaffe/xprof/feedback.c	7 Mar 2005 19:00:58 -0000
@@ -238,7 +238,8 @@
 {
 	struct section_file_data *sfd;
 	struct jit_section_data *jsd;
-	int retval = 0, iLockRoot;
+	int retval = 0;
+        INIT_LOCKVAR;
 
 	if( !kaffe_feedback_file )
 		return( 0 );
@@ -274,7 +275,8 @@
 int feedbackLibrary(char *name, int preload)
 {
 	struct section_file_data *sfd;
-	int retval = 0, iLockRoot;
+	int retval = 0;
+        INIT_LOCKVAR;
 
 	if( !kaffe_feedback_file )
 		return( 0 );
Index: kaffe/xprof/sectionFile.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/xprof/sectionFile.c,v
retrieving revision 1.6
diff -u -B -b -r1.6 sectionFile.c
--- kaffe/xprof/sectionFile.c	18 Sep 2004 20:48:17 -0000	1.6
+++ kaffe/xprof/sectionFile.c	7 Mar 2005 19:00:58 -0000
@@ -1082,7 +1082,7 @@
 
 int syncSectionFile(struct section_file *sf)
 {
-	int iLockRoot, retval;
+	INIT_LOCKVAR, retval;
 
 	lockMutex(sf);
 	retval = syncFile(0, sf, sf->sf_filename);
@@ -1119,7 +1119,7 @@
 
 void addSectionToFile(struct section_file *sf, struct section_file_data *sfd)
 {
-	int iLockRoot, hash;
+	INIT_LOCKVAR, hash;
 
 	hash = hashName(sfd->sfd_name, SECTION_FILE_HASH_SIZE);
 	lockMutex(sf);
@@ -1143,7 +1143,7 @@
 					    char *name)
 {
 	struct section_file_data *retval = 0, *sfd;
-	int iLockRoot, hash;
+	INIT_LOCKVAR, hash;
 
 	lockMutex(sf);
 	hash = hashName(name, SECTION_FILE_HASH_SIZE);
@@ -1166,7 +1166,7 @@
 		     void *arg)
 {
 	struct section_file_data *sfd;
-	int iLockRoot, retval = 1;
+	INIT_LOCKVAR, retval = 1;
 
 	if( !sf )
 		return( 0 );
Index: libraries/clib/net/InetAddressImpl.c
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/clib/net/InetAddressImpl.c,v
retrieving revision 1.28
diff -u -B -b -r1.28 InetAddressImpl.c
--- libraries/clib/net/InetAddressImpl.c	20 Dec 2004 03:40:03 -0000	1.28
+++ libraries/clib/net/InetAddressImpl.c	7 Mar 2005 19:01:02 -0000
@@ -103,7 +103,6 @@
   static iStaticLock	hostLock;
 	
   struct Hjava_lang_String *retval = NULL;
-  int iLockRoot;
 	
   lockStaticMutex(&hostLock);
   if( gethostname(hostname, HOSTNMSZ - 1) < 0 )
@@ -131,7 +130,6 @@
   jsize count = 0;
   struct addrinfo hints, *ai = NULL, *curr;
   HArrayOfArray *retval = NULL;
-  int iLockRoot;
   errorInfo einfo;
   char *name;
 
@@ -369,7 +367,6 @@
 #endif
   struct sockaddr_in *sain = (struct sockaddr_in *)&sa_buf;
   int rc, retryCount = 5;
-  int iLockRoot;
   errorInfo einfo;
   char *hostname;
   unsigned int sin_len;
@@ -501,7 +498,6 @@
   int family, rc = 0;
   const char *msg;
   errorInfo einfo;
-  int iLockRoot;
 	
   switch( obj_length(addr) )
     {


More information about the kaffe mailing list