This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libgcj/13212] New: AttachCurrentThread() not working
- From: "alessio at itapac dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 27 Nov 2003 13:25:33 -0000
- Subject: [Bug libgcj/13212] New: AttachCurrentThread() not working
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Every version of GCC with Java support <= 3.3.2 I have tried (3.3.2, 3.3.1, 3.1)
doesn't handle the AttachCurrentThread call working with native code. The bug is
similar to the one reported for Kaffe that can be found searching on google.
Here's a gcc -v:
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/specs
Configured with: /var/tmp/portage/gcc-3.3.2-r2/work/gcc-3.3.2/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.3
--includedir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3/info --enable-shared
--host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --with-system-zlib
--enable-languages=c,c++,f77,objc,java --enable-threads=posix --enable-long-long
--disable-checking --enable-cstdio=stdio --enable-clocale=generic
--enable-__cxa_atexit --enable-version-specific-runtime-libs
--with-gxx-include-dir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.2/include/g++-v3
--with-local-prefix=/usr/local --enable-shared --disable-nls
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib
--enable-interpreter --enable-java-awt=xlib --with-x --disable-multilib
Thread model: posix
gcc version 3.3.2 20031022 (Gentoo Linux 3.3.2-r2, propolice)
The behaviour is simple to reproduce: try using this (anyway the bug applies to
JNI interface too)
--hello.cc start--
#include <gcj/cni.h>
#include "hello.h"
#include <iostream>
#include <pthread.h>
using namespace std;
using namespace java::lang;
static pthread_t attachable;
void * subStart(void *th) {
cerr << "Before attach" << endl;
jstring threadName = (jstring)th;
Thread *tp = JvAttachCurrentThread(NULL, NULL);
cerr << "I am attached" << endl;
int i = 0;
while(1) {
cerr << "detached for " << i++ << " quarters" <<endl;
usleep(50000);
}
}
void *subStop(void *null) {
JvDetachCurrentThread();
cerr << "I am detached" << endl;
}
void ::hello::start() {
cerr << "I am in start()" << endl;
cerr << "Result is " << (int)JvCreateJavaVM(NULL) << endl;
jstring zocchia = JvNewStringUTF("suka");
JvAttachCurrentThread(NULL, NULL);
pthread_create(&attachable, NULL, subStart, (void *)zocchia);
}
void ::hello::stop() {
cerr << "I am in stop()" << endl;
pthread_cancel(attachable);
pthread_join(attachable, NULL);
cerr << "Joined!"<< endl;
}
--hello.cc stop--
--hello.java start--
import java.io.*;
class hello {
public native void start();
public native void stop();
static {
// System.loadLibrary("hello");
}
public static void main(String[] argv) throws Exception {
hello z = new hello();
z.start();
Thread.sleep(2000);
z.stop();
System.out.println("Thread stopped");
}
}
--hello.java stop--
Upon AttachCurrentThread the program gets killed by a SIGSEGV.
GDB session detectes the problem is:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1102085424 (LWP 17776)]
GC_local_malloc_atomic (bytes=32)
at ../../../gcc-3.3.2/boehm-gc/linux_threads.c:361
361 ptr_t my_entry = *my_fl;
(gdb) bt
#0 GC_local_malloc_atomic (bytes=32)
at ../../../gcc-3.3.2/boehm-gc/linux_threads.c:361
#1 0x40448d9e in _Jv_AllocPtrFreeObject (klass=0x4, size=32) at java-gc.h:53
#2 0x40470180 in _Jv_AllocString (len=16)
at ../../../gcc-3.3.2/libjava/java/lang/natString.cc:399
#3 0x404701c2 in _Jv_NewString (chars=0x4, len=16)
at ../../../gcc-3.3.2/libjava/java/lang/natString.cc:414
#4 0x4047257c in java::lang::Thread::gen_name() () at cni.h:52
#5 0x4047271b in _Jv_AttachCurrentThread (name=0x0, group=0x0)
at ../../../gcc-3.3.2/libjava/java/lang/natThread.cc:406
#6 0x08049196 in JvAttachCurrentThread(java::lang::String*,
java::lang::ThreadGroup*) ()
#7 0x08048f00 in subStart(void*) ()
#8 0x408e1332 in start_thread () from /lib/tls/libpthread.so
--
Summary: AttachCurrentThread() not working
Product: gcc
Version: 3.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libgcj
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: alessio at itapac dot net
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-linux-gnu
GCC host triplet: i686-linux-gnu
GCC target triplet: i686-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13212