public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcj/13212] New: AttachCurrentThread() not working
@ 2003-11-27 13:25 alessio at itapac dot net
  2005-09-11  2:59 ` [Bug libgcj/13212] JNI/CNI AttachCurrentThread does not register thread with garbage collector david at jpackage dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 32+ messages in thread
From: alessio at itapac dot net @ 2003-11-27 13:25 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2006-09-01 16:16 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-13212-7355@http.gcc.gnu.org/bugzilla/>
2005-10-07 13:49 ` [Bug libgcj/13212] JNI/CNI AttachCurrentThread does not register thread with garbage collector stewart at neuron dot com
2005-10-12 18:11 ` tromey at gcc dot gnu dot org
2005-10-12 20:29 ` stewart at neuron dot com
2005-10-22 20:58 ` arno at heho dot snv dot jussieu dot fr
2005-10-23  0:21 ` arno at heho dot snv dot jussieu dot fr
2005-10-23  0:22 ` arno at heho dot snv dot jussieu dot fr
2005-10-23  0:24 ` arno at heho dot snv dot jussieu dot fr
2005-10-23  0:28 ` arno at heho dot snv dot jussieu dot fr
2005-10-23 10:44 ` greenrd at gcc dot gnu dot org
2005-10-23 23:38 ` arno at heho dot snv dot jussieu dot fr
2006-01-09 17:25 ` aph at gcc dot gnu dot org
2006-01-09 17:32 ` greenrd at gcc dot gnu dot org
2006-01-09 17:41 ` jakub at gcc dot gnu dot org
2006-01-09 17:43 ` jakub at gcc dot gnu dot org
2006-01-09 18:21 ` cagney at redhat dot com
2006-01-13 22:44 ` tromey at gcc dot gnu dot org
2006-03-24 14:08 ` rguenth at gcc dot gnu dot org
2006-03-24 15:36 ` rguenth at gcc dot gnu dot org
2006-03-24 17:41 ` aph at gcc dot gnu dot org
2006-03-25  1:07 ` matz at suse dot de
2006-03-30  7:00 ` mckinlay at redhat dot com
2006-03-30 15:48 ` rguenth at gcc dot gnu dot org
2006-03-30 15:51 ` mckinlay at redhat dot com
2006-05-22 16:16 ` rguenth at gcc dot gnu dot org
2006-06-10 18:01 ` arno at heho dot snv dot jussieu dot fr
2006-07-14 14:02 ` davidf at sjsoft dot com
2006-08-21 22:08 ` tromey at gcc dot gnu dot org
2006-08-21 22:09 ` tromey at gcc dot gnu dot org
2006-09-01 16:16 ` tromey at gcc dot gnu dot org
2003-11-27 13:25 [Bug libgcj/13212] New: AttachCurrentThread() not working alessio at itapac dot net
2005-09-11  2:59 ` [Bug libgcj/13212] JNI/CNI AttachCurrentThread does not register thread with garbage collector david at jpackage dot org
2005-09-11  3:02 ` billy dot biggs at gmail dot com
2005-09-15  0:27 ` greenrd at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).