This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Finalizer deadlock
- From: "Gladish, Jacob" <Jacob dot Gladish at netapp dot com>
- To: <java at gcc dot gnu dot org>
- Date: Wed, 8 Sep 2004 15:20:21 -0400
- Subject: Finalizer deadlock
This was proposed about two months ago:
> Yes, we could rewrite it using _Jv_CondWait/_Jv_CondNotify and other
>thread primitives defined in the thread headers.
>
>I'm also not sure this peice of code in FinalizerThread is safe:
>public static void finalizerReady ()
> {
> synchronized (lock)
> {
> if (! thread_started)
> runFinalizers ();
>
>Isn't there a race here? Unlikely to happen, perhaps, but it seems like
if >a finalizer needs to be run before the finalizer thread has finished
>starting, we'll try to run finalizers from the inside the GC's thread.
>
>Regards
>
>Bryce
>
Is this that case? The two threads are deadlocked. The finalizer is
waiting for a monitor on the PlainSocketImpl. The internal data
structures indicate that the second thread holds the mutex, but I don't
see how that could be. The second thread is stuck waiting on the
finalizer monitor. Could the bug you described somehow manifest itself
into this state? I'm running with hash-sync off.
(gdb) bt
#0 0x2b5599b6 in __sigsuspend (set=0x7f7ff84c) at
../sysdeps/unix/sysv/linux/sigsuspend.c:45
#1 0x2b19bf59 in __pthread_wait_for_restart_signal (self=0x7f7ffc00) at
pthread.c:969
#2 0x2b19da59 in __pthread_alt_lock (lock=0x2b4f4c30, self=0x0) at
restart.h:34
#3 0x2b19a9fe in __pthread_mutex_lock (mutex=0x2b4f4c20) at mutex.c:120
#4 0x2afebbf6 in java::lang::Object::sync_init() (this=0x41be02a0) at
include/java-threads.h:147
#5 0x2afebfaf in _Jv_MonitorEnter (obj=0x41be02a0) at
../../../libjava/java/lang/natObject.cc:250
#6 0x2b0c9b65 in java.net.PlainSocketImpl.finalize() (this=0x41be02a0)
at ../../../libjava/java/net/PlainSocketImpl.java:128
#7 0x2afebb81 in _Jv_FinalizeObject(java::lang::Object*)
(obj=0x41be02a0)
at ../../../libjava/java/lang/natObject.cc:114
#8 0x2afc54ff in call_finalizer(void*, void*) (obj=0x41be02a0,
client_data=0x2afebb60) at ../../../libjava/boehm.cc:390
#9 0x2b180e65 in GC_invoke_finalizers () at
../../../boehm-gc/finalize.c:796
#10 0x2afc5579 in _Jv_RunFinalizers() () at
../../../libjava/boehm.cc:403
#11 0x2afe2d69 in gnu::gcj::runtime::FinalizerThread::runFinalizers() ()
at ../../../libjava/gnu/gcj/runtime/natFinalizerThread.cc:21
#12 0x2b0656ec in gnu.gcj.runtime.FinalizerThread.run()
(this=0x400cabb8)
at ../../../libjava/gnu/gcj/runtime/FinalizerThread.java:69
#13 0x2aff065c in _Jv_ThreadRun(java::lang::Thread*) (thread=0x400cabb8)
at ../../../libjava/java/lang/natThread.cc:292
#14 0x2afc6080 in really_start(void*) (x=0x400ddff8) at
../../../libjava/posix-threads.cc:392
#15 0x2b1834be in GC_start_routine (arg=0x40092f60) at
../../../boehm-gc/linux_threads.c:1375
#16 0x2b199d37 in pthread_start_thread (arg=0x7f7ffc00) at manager.c:284
#0 0x2b5599b6 in __sigsuspend (set=0x7c9ff50c) at
../sysdeps/unix/sysv/linux/sigsuspend.c:45
#1 0x2b19bf59 in __pthread_wait_for_restart_signal (self=0x7c9ffc00) at
pthread.c:969
#2 0x2b19da59 in __pthread_alt_lock (lock=0x400e3fdc, self=0x0) at
restart.h:34
#3 0x2b19a9fe in __pthread_mutex_lock (mutex=0x400e3fcc) at mutex.c:120
#4 0x2afebf8b in _Jv_MonitorEnter (obj=0x4003afc0) at
include/java-threads.h:147
#5 0x2b065648 in gnu.gcj.runtime.FinalizerThread.finalizerReady() ()
at ../../../libjava/gnu/gcj/runtime/FinalizerThread.java:38
#6 0x2b180ee0 in GC_notify_or_invoke_finalizers () at
../../../boehm-gc/finalize.c:825
#7 0x2b18488f in GC_generic_malloc_many (lb=40, k=0, result=0x41048030)
at ../../../boehm-gc/mallocx.c:357
#8 0x2b182398 in GC_local_malloc_atomic (bytes=36) at
../../../boehm-gc/linux_threads.c:370
#9 0x2afc5435 in _Jv_AllocBytes(int) (size=36) at
../../../libjava/boehm.cc:339
#10 0x2afebc51 in java::lang::Object::sync_init() (this=0x421774b0) at
../../../libjava/java/lang/natObject.cc:176
#11 0x2afebfaf in _Jv_MonitorEnter (obj=0x421774b0) at
../../../libjava/java/lang/natObject.cc:250
#12 0x2b00b5c9 in java.lang.StringBuffer.append(char) (this=0x421774b0,
ch=40)
at ../../../libjava/java/lang/StringBuffer.java:101
#13 0x2afe6c7b in
java::lang::Class::getSignature(JArray<java::lang::Class*>*, bool)
(param_types=0x409bcc50,
is_constructor=0 '\0') at ../../../libjava/java/lang/natClass.cc:321
#14 0x2afe7347 in java::lang::Class::_getMethod(java::lang::String*,
JArray<java::lang::Class*>*) (this=0x8ac6c00,
name=0x41086230, param_types=0x409bcc50) at
../../../libjava/java/lang/natClass.cc:513
#15 0x2affa0f6 in java.lang.Class.getMethod(java.lang.String,
java.lang.Class[]) (this=0x8ac6c00,
methodName=0x41086230, parameterTypes=0x409bcc50) at
../../../libjava/java/lang/Class.java:163