As noted in: http://gcc.gnu.org/ml/gcc-testresults/2007-09/msg00818.html With this configuration: ../trunk/configure --prefix=/home/ddaney/gccsvn/trunk-install --target=mipsel-linux --build=mipsel-linux --host=mipsel-linux --with-gmp=/home/ddaney/mp --with-mpfr=/home/ddaney/mp --with-arch=sb1 --disable-java-awt --without-x --enable-__cxa_atexit --disable-jvmpi --disable-static The SyncTest test fails sometimes.
SyncTest never completes. When it gets into this state the threads are in the followin state: (gdb) thread 6 [Switching to thread 6 (Thread 758265024 (LWP 29566))]#0 0x2ce68fac in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/libpthread.so.0 (gdb) bt #0 0x2ce68fac in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/libpthread.so.0 #1 0x2b7190fc in _Jv_CondWait (cv=0x2cd84e00, mu=0x2cd84de0, millis=<value optimized out>, nanos=0) at ../../../trunk/libjava/posix-threads.cc:212 #2 0x2b6f37c8 in gnu::gcj::runtime::FinalizerThread::run ( this=<value optimized out>) at ../../../trunk/libjava/gnu/gcj/runtime/natFinalizerThread.cc:57 #3 0x2b70cb78 in _Jv_ThreadRun (thread=0x2d086f50) at ../../../trunk/libjava/java/lang/natThread.cc:335 #4 0x2b718838 in really_start (x=0x2d04bb68) at ../../../trunk/libjava/posix-threads.cc:616 #5 0x2c389e18 in GC_start_routine (arg=<value optimized out>) at ../../../trunk/boehm-gc/pthread_support.c:1301 #6 0x2ce62130 in start_thread () from /lib/libpthread.so.0 #7 0x2cf9ef48 in ?? () from /lib/libc.so.6 (gdb) thread 5 [Switching to thread 5 (Thread 760362176 (LWP 29567))]#0 0x2cf5d820 in nanosleep () from /lib/libc.so.6 (gdb) bt #0 0x2cf5d820 in nanosleep () from /lib/libc.so.6 #1 0x2cf9678c in usleep () from /lib/libc.so.6 #2 0x2b706d28 in wait_unlocked (he=0x2cd861d0) at ../../../trunk/libjava/java/lang/natObject.cc:634 #3 0x2b7079a0 in _Jv_MonitorEnter (obj=0x411870) at ../../../trunk/libjava/java/lang/natObject.cc:966 #4 0x00401070 in SyncTest.run()void (this=<value optimized out>) at SyncTest.java:10 #5 0x2bc40420 in java.lang.Thread.run()void (this=<value optimized out>) at /home/ddaney/gccsvn/trunk/libjava/java/lang/Thread.java:755 #6 0x2b70cb78 in _Jv_ThreadRun (thread=0x2d086f00) at ../../../trunk/libjava/java/lang/natThread.cc:335 #7 0x2b718838 in really_start (x=0x2d04bb40) at ../../../trunk/libjava/posix-threads.cc:616 #8 0x2c389e18 in GC_start_routine (arg=<value optimized out>) at ../../../trunk/boehm-gc/pthread_support.c:1301 #9 0x2ce62130 in start_thread () from /lib/libpthread.so.0 (gdb) thread 4 [Switching to thread 4 (Thread 762459328 (LWP 29568))]#0 0x2cf5d820 in nanosleep () from /lib/libc.so.6 (gdb) bt #0 0x2cf5d820 in nanosleep () from /lib/libc.so.6 #1 0x2cf9678c in usleep () from /lib/libc.so.6 #2 0x2b706d28 in wait_unlocked (he=0x2cd861d0) at ../../../trunk/libjava/java/lang/natObject.cc:634 #3 0x2b7079a0 in _Jv_MonitorEnter (obj=0x411870) at ../../../trunk/libjava/java/lang/natObject.cc:966 #4 0x00401070 in SyncTest.run()void (this=<value optimized out>) at SyncTest.java:10 #5 0x2bc40420 in java.lang.Thread.run()void (this=<value optimized out>) at /home/ddaney/gccsvn/trunk/libjava/java/lang/Thread.java:755 #6 0x2b70cb78 in _Jv_ThreadRun (thread=0x2d086eb0) at ../../../trunk/libjava/java/lang/natThread.cc:335 #7 0x2b718838 in really_start (x=0x2d04bb38) at ../../../trunk/libjava/posix-threads.cc:616 #8 0x2c389e18 in GC_start_routine (arg=<value optimized out>) at ../../../trunk/boehm-gc/pthread_support.c:1301 #9 0x2ce62130 in start_thread () from /lib/libpthread.so.0 (gdb) thread 3 [Switching to thread 3 (Thread 764556480 (LWP 29569))]#0 0x2cf5d820 in nanosleep () from /lib/libc.so.6 (gdb) bt #0 0x2cf5d820 in nanosleep () from /lib/libc.so.6 #1 0x2cf9678c in usleep () from /lib/libc.so.6 #2 0x2b706d28 in wait_unlocked (he=0x2cd861d0) at ../../../trunk/libjava/java/lang/natObject.cc:634 #3 0x2b7079a0 in _Jv_MonitorEnter (obj=0x411870) at ../../../trunk/libjava/java/lang/natObject.cc:966 #4 0x00401070 in SyncTest.run()void (this=<value optimized out>) at SyncTest.java:10 #5 0x2bc40420 in java.lang.Thread.run()void (this=<value optimized out>) at /home/ddaney/gccsvn/trunk/libjava/java/lang/Thread.java:755 #6 0x2b70cb78 in _Jv_ThreadRun (thread=0x2d086e60) at ../../../trunk/libjava/java/lang/natThread.cc:335 #7 0x2b718838 in really_start (x=0x2d04bb30) at ../../../trunk/libjava/posix-threads.cc:616 #8 0x2c389e18 in GC_start_routine (arg=<value optimized out>) at ../../../trunk/boehm-gc/pthread_support.c:1301 #9 0x2ce62130 in start_thread () from /lib/libpthread.so.0 (gdb) thread 2 [Switching to thread 2 (Thread 766653632 (LWP 29570))]#0 0x2cf5d820 in nanosleep () from /lib/libc.so.6 (gdb) bt #0 0x2cf5d820 in nanosleep () from /lib/libc.so.6 #1 0x2cf9678c in usleep () from /lib/libc.so.6 #2 0x2b706d28 in wait_unlocked (he=0x2cd861d0) at ../../../trunk/libjava/java/lang/natObject.cc:634 #3 0x2b7079a0 in _Jv_MonitorEnter (obj=0x411870) at ../../../trunk/libjava/java/lang/natObject.cc:966 #4 0x00401070 in SyncTest.run()void (this=<value optimized out>) at SyncTest.java:10 #5 0x2bc40420 in java.lang.Thread.run()void (this=<value optimized out>) at /home/ddaney/gccsvn/trunk/libjava/java/lang/Thread.java:755 #6 0x2b70cb78 in _Jv_ThreadRun (thread=0x2d086e10) at ../../../trunk/libjava/java/lang/natThread.cc:335 #7 0x2b718838 in really_start (x=0x2d04bb28) at ../../../trunk/libjava/posix-threads.cc:616 #8 0x2c389e18 in GC_start_routine (arg=<value optimized out>) at ../../../trunk/boehm-gc/pthread_support.c:1301 #9 0x2ce62130 in start_thread () from /lib/libpthread.so.0 (gdb) thread 1 [Switching to thread 1 (Thread 755130368 (LWP 29565))]#0 0x2ce68fac in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/libpthread.so.0 (gdb) bt #0 0x2ce68fac in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/libpthread.so.0 #1 0x2b7190fc in _Jv_CondWait (cv=0x2d078c24, mu=0x2d078c04, millis=<value optimized out>, nanos=0) at ../../../trunk/libjava/posix-threads.cc:212 #2 0x2b70ce94 in java::lang::Thread::join (this=0x2d086f00, millis=0, nanos=0) at ../../../trunk/libjava/java/lang/natThread.cc:160 #3 0x2bc40374 in java.lang.Thread.join()void (this=0x2d078c24) at /home/ddaney/gccsvn/trunk/libjava/java/lang/Thread.java:677 #4 0x00401268 in SyncTest.main(java.lang.String[])void ( args=<value optimized out>) at SyncTest.java:26 #5 0x2b6f5304 in gnu::java::lang::MainThread::call_main (this=0x2d11ef60) at ../../../trunk/libjava/gnu/java/lang/natMainThread.cc:54 #6 0x2b70cb78 in _Jv_ThreadRun (thread=0x2d11ef60) at ../../../trunk/libjava/java/lang/natThread.cc:335 #7 0x2b6acb5c in _Jv_RunMain (vm_args=<value optimized out>, klass=0x411870, name=0x0, argc=<value optimized out>, argv=0x7fc39b24, is_jar=false) at ../../../trunk/libjava/prims.cc:1789 #8 0x2b6acd54 in _Jv_RunMain (klass=0x2d026000, name=0xa <Address 0xa out of bounds>, argc=0, argv=<value optimized out>, is_jar=false) at ../../../trunk/libjava/prims.cc:1814 #9 0x2b6acde4 in JvRunMain (klass=0x2d078c24, argc=755130368, argv=0x7fc39b24) at ../../../trunk/libjava/prims.cc:1820 #10 0x2cecb2e0 in __libc_start_main () from /lib/libc.so.6
I assume the LOCKED bit in *he is actually set when gdb looks at it? What does the rest of the hash entry look like? That might give you a hint as to the culprit. Clearly someone sets the LOCKED bit on a hash entry and neglects to clear it. If a compare_and_swap succeeded but returned failure anyway, that might explain it. A misimplementation of release_set might also cause the problem. I don't immediately see how this can be explained by a memory ordering issue.
The LOCKED bit is set. All the other fields in the hash entry are zero. I think adding a memory barrier at the end of compare_and_swap fixes the problem. Currently I have: inline static bool compare_and_swap(volatile obj_addr_t *addr, obj_addr_t old, obj_addr_t new_val) { bool b = __sync_bool_compare_and_swap(addr, old, new_val); __sync_synchronize(); return b; } inline static bool compare_and_swap_release(volatile obj_addr_t *addr, obj_addr_t old, obj_addr_t new_val) { return __sync_bool_compare_and_swap(addr, old, new_val); } I would have thought that the 'sc' instruction emitted by __sync_bool_compare_and_swap made the swap visible to other CPUs, but it appears that the 'sync' emitted by __sync_synchronize() is required. Hmm.
Created attachment 14227 [details] Proposed patch. I am testing this patch.
Subject: Bug 33479 Author: daney Date: Wed Sep 26 16:45:39 2007 New Revision: 128821 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128821 Log: 2007-09-26 David Daney <ddaney@avtrex.com> PR target/33479 * config/mips/mips.md (sync_compare_and_swap<mode>, sync_old_add<mode>, sync_new_add<mode>, sync_old_<optab><mode>, sync_new_<optab><mode>, sync_old_nand<mode>, sync_new_nand<mode>, sync_lock_test_and_set<mode>): Fix '&' constraint modifiers. Update length attributes. (sync_add<mode>, sync_sub<mode>, sync_old_sub<mode>, sync_new_sub<mode>, sync_<optab><mode>, sync_nand<mode>): Update length attributes. * config/mips/mips.h (MIPS_COMPARE_AND_SWAP, MIPS_SYNC_OP, MIPS_SYNC_OLD_OP, MIPS_SYNC_NEW_OP, MIPS_SYNC_NAND, MIPS_SYNC_OLD_NAND, MIPS_SYNC_NEW_NAND, MIPS_SYNC_EXCHANGE): Add post-loop sync. Modified: trunk/gcc/ChangeLog trunk/gcc/config/mips/mips.h trunk/gcc/config/mips/mips.md
Fixed now.