Deadlock in JNI program that loads Kaffe

Mo DeJong kaffe@rufus.w3.org
Sat, 3 Jun 2000 05:12:36 -0700 (PDT)


Hi all.

I finally managed to get my JNI application to load Kaffe.
The trick seemed to be setting the KAFFELIBRARYPATH env
var to include $install/lib and $install/lib/kaffe.
The Sun JDK seems to be better at determining default
JVM arguments.

At any rate, Kaffe deadlocking when called from a JNI
method. I am using unix-pthreads on a Red Hat 6.2 box.

Here are the stack traces for the JVM.

"finalizer man" Thread

#0  0x40107deb in __sigsuspend (set=0xbf7ffbd4) at 
../sysdeps/unix/sysv/linux/sigsuspend.c:48
#1  0x4020dc82 in __pthread_wait_for_restart_signal (self=0xbf7ffe40) at 
pthread.c:785
#2  0x4020a960 in pthread_cond_wait (cond=0x81e1488, mutex=0x81e1470) at 
restart.h:26
#3  0x402645fa in jcondvar_wait (cv=0x81e1488, mux=0x81e1470, timeout=0) 
at /home/mo/project/kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c:39
#4  0x40244b1c in _waitCond (lkp=0x402725e8, timeout=0) at 
/home/mo/project/kaffe/kaffe/kaffevm/ksem.h:87
#5  0x40235006 in finaliserMan (arg=0x40271e80) at 
/home/mo/project/kaffe/kaffe/kaffevm/mem/gc-incremental.c:761
#6  0x4024b902 in startSpecialThread (arg=0x81f97c0) at 
/home/mo/project/kaffe/kaffe/kaffevm/thread.c:304
#7  0x40265ccb in tRun (p=0x81f9830) at 
/home/mo/project/kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:550
#8  0x4020bb85 in pthread_start_thread (arg=0xbf7ffe40) at manager.c:241


"gc man" Thread

#0  0x40107deb in __sigsuspend (set=0xbf5ffbe0) at 
../sysdeps/unix/sysv/linux/sigsuspend.c:48
#1  0x4020dc82 in __pthread_wait_for_restart_signal (self=0xbf5ffe40) at 
pthread.c:785
#2  0x4020a960 in pthread_cond_wait (cond=0x81e14b8, mutex=0x81e14a0) at 
restart.h:26
#3  0x402645fa in jcondvar_wait (cv=0x81e14b8, mux=0x81e14a0, timeout=0) 
at /home/mo/project/kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c:39
#4  0x40244b1c in _waitCond (lkp=0x402725ec, timeout=0) at 
/home/mo/project/kaffe/kaffe/kaffevm/ksem.h:87
#5  0x40234873 in gcMan (arg=0x40271e80) at 
/home/mo/project/kaffe/kaffe/kaffevm/mem/gc-incremental.c:431
#6  0x4024b902 in startSpecialThread (arg=0x81f98a0) at 
/home/mo/project/kaffe/kaffe/kaffevm/thread.c:304
#7  0x40265ccb in tRun (p=0x81f9910) at 
/home/mo/project/kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:550
#8  0x4020bb85 in pthread_start_thread (arg=0xbf5ffe40) at manager.c:241



My application's thread


#0  0x40107deb in __sigsuspend (set=0xbfffd984) at 
../sysdeps/unix/sysv/linux/sigsuspend.c:48
#1  0x4020dc82 in __pthread_wait_for_restart_signal (self=0x40215940) at 
pthread.c:785
#2  0x4020a960 in pthread_cond_wait (cond=0x8183b48, mutex=0x8183b30) at 
restart.h:26
#3  0x402645fa in jcondvar_wait (cv=0x8183b48, mux=0x8183b30, timeout=0) 
at /home/mo/project/kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c:39
#4  0x40244724 in slowLockMutex (lkp=0x81fe528, where=0xbfffdae0) at 
/home/mo/project/kaffe/kaffe/kaffevm/ksem.h:87
#5  0x40244e27 in _lockMutex (lkp=0x81fe528, where=0xbfffdae0) at 
/home/mo/project/kaffe/kaffe/kaffevm/locks.c:471
#6  0x40245193 in getClass (idx=305, this=0x8207048, einfo=0xbfffe08c) at 
/home/mo/project/kaffe/kaffe/kaffevm/lookup.c:162
#7  0x40244ff1 in getMethodSignatureClass (idx=304, this=0x8207048, 
loadClass=true, isSpecial=0, call=0xbfffdd2c, einfo=0xbfffe08c) at 
/home/mo/project/kaffe/kaffe/kaffevm/lookup.c:80
#8  0x40230f54 in verifyBasicBlock (codeInfo=0x8244bc8, meth=0x81aca60, 
pc=3, einfo=0xbfffe08c) at 
/home/mo/project/kaffe/kaffe/kaffevm/code-analyse.c:1637
#9  0x4022e209 in verifyMethod (meth=0x81aca60, pcodeinfo=0xbfffe008, 
einfo=0xbfffe08c) at /home/mo/project/kaffe/kaffe/kaffevm/code-analyse.c:319
#10 0x4025bee3 in translate (xmeth=0x81aca60, einfo=0xbfffe08c) at 
/home/mo/project/kaffe/kaffe/kaffevm/jit3/machine.c:156
#11 0x40248950 in soft_fixup_trampoline (_data=0x81ad6bd) at 
/home/mo/project/kaffe/kaffe/kaffevm/soft.c:560
#12 0x40263525 in i386_do_fixup_trampoline () at 
/home/mo/project/kaffe/kaffe/kaffevm/jit3/machine.c:1013
#13 0x4023b7e4 in Kaffe_CallIntMethodV (env=0x4026c410, obj=0x82045a0, 
meth=0x81aca60, args=0xbfffe544) at 
/home/mo/project/kaffe/kaffe/kaffevm/jni.c:845
#14 0x4023b868 in Kaffe_CallIntMethod (env=0x4026c410, obj=0x82045a0, 
meth=0x81aca60) at /home/mo/project/kaffe/kaffe/kaffevm/jni.c:861
#15 0x401faa1b in JavaCmdProc (clientData=0x821a3e8, interp=0x804bc28, 
objc=3, objv=0x804cc88) at 
/home/mo/project/tcljava/src/native/javaInterp.c:1145
#16 0x4005fc16 in TclExecuteByteCode (interp=0x804bc28, 
codePtr=0x8058580) at /home/mo/project/tcl/unix/../generic/tclExecute.c:847
#17 0x400387ca in Tcl_EvalObjEx (interp=0x804bc28, objPtr=0x8054300, 
flags=0) at /home/mo/project/tcl/unix/../generic/tclBasic.c:2733
#18 0x4003d6d5 in Tcl_CatchObjCmd (dummy=0x0, interp=0x804bc28, objc=3, 
objv=0xbfffea2c) at /home/mo/project/tcl/unix/../generic/tclCmdAH.c:261
#19 0x4008acdf in EvalObjv (interp=0x804bc28, objc=3, objv=0xbfffea2c, 
command=0x8059bb5 "catch {java::call Test isOK} res\n\nif {$res == 
\"OK\"} {\n  puts \"Installed program is working correctly\"\n  exit 0\n} 
else {\n  puts stderr \"Installed program is not working correctly, 
please recheck instal"..., length=340, flags=0) at 
/home/mo/project/tcl/unix/../generic/tclParse.c:945
#20 0x4008b5d4 in Tcl_EvalEx (interp=0x804bc28, script=0x8059ad8 "puts 
\"Testing installed program\"\nflush stdout\n\nif {[catch {\npackage 
require java\n} err]} {\n  puts stderr \"\\\"package require java\\\" 
failed with the following error\"\n  puts stderr $err\n  exit 
-1\n}\n\nset "..., numBytes=561, flags=0) at 
/home/mo/project/tcl/unix/../generic/tclParse.c:1406
#21 0x40080074 in Tcl_EvalFile (interp=0x804bc28, fileName=0xbfffee70 
"Test.tcl") at /home/mo/project/tcl/unix/../generic/tclIOUtil.c:330
#22 0x40083cda in Tcl_Main (argc=1, argv=0xbffff3b8, 
appInitProc=0x8048758 <Tcl_AppInit>) at 
/home/mo/project/tcl/unix/../generic/tclMain.c:198
#23 0x8048746 in main (argc=2, argv=0xbffff3b4) at 
/home/mo/project/tcl/unix/../unix/tclAppInit.c:99
#24 0x401019cb in __libc_start_main (main=0x8048720 <main>, argc=2, 
argv=0xbffff3b4, init=0x80485a4 <_init>, fini=0x80487dc <_fini>, 
rtld_fini=0x4000ae60 <_dl_fini>, stack_end=0xbffff3ac) at 
../sysdeps/generic/libc-start.c:92




Kaffe seems to be getting while loading a class.
This call is from lookup.c


78		if (loadClass == true) {
79			ci = METHODREF_CLASS(idx, pool);
80			class = getClass(ci, this, einfo);
81			if (class == NULL) {
82				call->cname = WORD2UTF(pool->data[ci]);
83				countInsAndOuts(sig->data, &call->in, 
&call->out, &call->rettype);
84				return (false);
85			}
86			assert(class->state >= CSTATE_LINKED);


Line 80 call the getClass() method in the same file.


157		case CONSTANT_Class:
158			/* The class may be resolved by another thread so 
we better
159			 * lock and get the tag & name again just in 
case.  If we
160			 * have been resolved then we just return the answer.
161			 */
162			lockClass(this);


This call to lockClass() is where things get deadlocked. I guess I just 
do not understand how this thread is going to be woken up after it goes 
to sleep with no timeout.

Any ideas?
Mo DeJong
Red Hat Inc