MIPS deadlock bug fix

Slegers, Walter Walter.Slegers at nl2.vdogrp.de
Tue Jan 9 06:11:13 PST 2001


I ran into Kaffe deadlocks when using multiple threads
on my MIPS R3000 target. This did not occur when I
ran the same program on the same Kaffe version on a
PC architecture.

I've traced it back to the COMPARE_AND_EXCHANGE macro.
This macro is used in kaffe-1.0.6/kaffe/kaffevm/locks.c and
defined in kaffe-1.0.6/config/i386/common.h. This macro should
provide an atomic compare and exchange operation. The default
definition of this macro (for other architectures) is not atomic.
It seems that this caused the JVM to detect 'deadlocks' in the
Java threads in 5 to 10% of all my tests.

I could solve this by the following work around. I have changed
kaffe-1.0.6/kaffe/kaffevm/locks.c to include:

	/* non-atomic version removed
	 *         (*(A) == (O) ? *(A) = (N), 1 : 0)


	int my_compare_and_exchange(iLock** a, iLock* o,
	                            iLock *n) 
		int val = 0;

		jthread_suspendall(); /* do not schedule */
		if (*a == o)
			*a = n;
			val = 1;
		return val;

With this fix I seem to have no more unexpected deadlocks.
Just to be on the safe side, does anyone know of similar
"supposed to be atomic" operations?

Kind regards,
    Walter Slegers

This Mail has been checked for Viruses
Attention: Encrypted Mails can NOT be checked !


Diese Mail wurde auf Viren ueberprueft
Hinweis: Verschluesselte Mails koennen NICHT geprueft werden!

More information about the kaffe mailing list