JavaVM.AttachCurrentThread produces segfault

Enno Brehm enno at
Thu Sep 20 11:12:51 PDT 2001


I've got some problems with the attachment of a thread to the VM: I need
a thread (on the native side) which does some work concurrently to the
rest of the application. This thread will need to make some callbacks
into Java objects. When I create a a thread (java.lang.Thread) on the
java side and use it, everything seems fine. but actually I want to
create the thread during some native initialization routine using the
pthread-library (my kaffe is compiled to use unix-pthreads). When this
thread then wants to call back into java, it tries to attach to the
running VM using AttachCurrentThread form the InvocationInterface to
acquire a valid JNIEnv. It *will get* a pointer, but when it really
tries to use it (say, call 'FindClass' on it), I will cause a
segmentation fault. (As far as I can see this is due to the fact that
somehow the following function from

static inline
jthread_getcookie(jthread_t tid)
        return (tid->thread);

gets called with an actual value of NULL, causing the crash. This seems
to happen inside the macro BEGIN_EXCEPTION_HANDLING(X), which contains a
call to getCurrentThread()). When I do the same with the thread that
originally came from the java side, everything works fine (even if it
uses AttachCurrentThread)

Reading the JNI-Spec, I found, that the VM is supposed to create a
java.lang.Thread-Object whenever some new threads attaches itself using
AttachCurrentThread(...), but all that this function will do is to pass
out a pointer to some global JNIEnv - I expected it to create some
thread-specific structures ... anybody able to comment this? I don't
think I am doing wrong here, because it run's quite well with
JRE1.3.1, JDK1.1.8 (SUN), JDK1.3 (IBM). I am using the CVS-version of
kaffe 1.0.6 on SuSE linux 7.2 with kernel version 2.4.6.

Attached you will find a small test program that reproduces this bug
(, Threads.c). The command I used to compile the c-file was
gcc -g -I /usr/local/include/kaffe -lpthread -s -o  

Thanks for any help.

Enno Brehm

enno brehm
convergence integrated media gmbh

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Threads.c
Type: text/x-c
Size: 1473 bytes
Desc: not available
Url : 
-------------- next part --------------
A non-text attachment was scrubbed...
Type: text/x-java
Size: 290 bytes
Desc: not available
Url : 

More information about the kaffe mailing list