From owner-freebsd-bugs Thu Jun 24 17:10:10 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id CEA1B154FC for ; Thu, 24 Jun 1999 17:10:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id RAA81692; Thu, 24 Jun 1999 17:10:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Date: Thu, 24 Jun 1999 17:10:01 -0700 (PDT) Message-Id: <199906250010.RAA81692@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Steve Heller Subject: Re: i386/12286: Segmentation violation when invoking JNI call to C from Java with PTHREADS Reply-To: Steve Heller Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR i386/12286; it has been noted by GNATS. From: Steve Heller To: "'freebsd-gnats-submit@freebsd.org'" , Steve Heller Cc: "'freebsd-java@freebsd.org'" Subject: Re: i386/12286: Segmentation violation when invoking JNI call to C from Java with PTHREADS Date: Thu, 24 Jun 1999 17:03:37 -0700 Ok, I have done some more investigation into this. I think there may be some problem in the mutual exclusion/locking in the kernel (since I think that is where the call to _thread_sys_connect() resolves to as I cannot find it anywhere in the libraries): 1) I pulled down the source for stable, which I thought was 3.2 STABLE, which had a date of 5/18/99 from the ftp site. Then I did a make world and reboot, and noticed that uname still shows 3.1 RELEASE, but the problem changed to an indication of an illegal instruction with JNI and multi-threading. 2) Then I reviewed the freebsd-stable mailing list, and found that on 6/22/99, there was a message about thread patches since the thread libraries in stable's libc_r were broken. This indicated a replacement at: ftp://ftp.pcnet.com/users/eischen/FreeBSD/uthread.tgz (I renamed this file to uthread.tar.gz, then did tar xvzf on it). I pulled this file down and rebuilt libc_r and copied it to /usr/lib, after placing some debug printf statements in uthread_connect.c to make sure its version of connect was being called (it was). The result is that when I use multithreading and make calls to socket(), connect(), shutdown() and read(), without using JNI, everything works fine. But when I make calls to socket(), connect(), shutdown() and read() through JNI, I get the same error that I originally reported. For the case of connect(), I changed calls to socket() to _thread_sys_socket() and shutdown() to _thread_sys_shutdown(), and added debug printf's to the connect code, and ran it. From the debug output, it made it past the _FD_LOCK() call, but not past the _thread_sys_connect() call before the Abort trap - core dumped message. Following is 1) the uthread_connect.c source code with debug printf's, and 2) the debug output when the problem occurred with JNI: 1) Here is my version of the uthread_connect.c source code with debug printf's: #include #include #include #include #ifdef _THREAD_SAFE #include #include "pthread_private.h" int connect(int fd, const struct sockaddr * name, int namelen) { struct sockaddr tmpname; int errnolen, ret, tmpnamelen; printf("libc_r connect: Entered...\n"); if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { printf("libc_r connect: After _FD_LOCK()...\n"); if ((ret = _thread_sys_connect(fd, name, namelen)) < 0) { printf("libc_r connect: After _thread_sys_connect()...\n"); if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EINPROGRESS) || (errno == EALREADY) || (errno == EAGAIN))) { printf("libc_r connect: After _thread_fd_table()...\n"); _thread_run->data.fd.fd = fd; /* Set the timeout: */ _thread_kern_set_timeout(NULL); _thread_kern_sched_state(PS_FDW_WAIT, __FILE__, __LINE__); tmpnamelen = sizeof(tmpname); /* 0 now lets see if it really worked */ if (((ret = _thread_sys_getpeername(fd, &tmpname , &tmpnamelen)) < 0) && (errno == ENOTCONN)) { /* * Get the error, this function * should not fail */ errnolen = sizeof(errno); _thread_sys_getsockopt(fd, SOL_SOCKET, S O_ERROR, &errno, &errnolen); } } else { ret = -1; } } _FD_UNLOCK(fd, FD_RDWR); } printf("libc_r connect: Exiting...\n"); return (ret); } #endif 2) Here is the corresponding debug output: (cd jni; java pntransjava 167.216.177.37 443 "TRXTYPE=S&TENDER=C&PWD=g0edel1685& USER=pnprodtest&ACCT=5105105105105100&EXPDATE=1299&AMT=27.33" 30; cd ..) SIGSEGV 11* segmentation violation Full thread dump: "Finalizer thread" (TID:0x28454210, sys_thread_t:0x29258f00, state:R) prio=1 "Async Garbage Collector" (TID:0x28454258, sys_thread_t:0x29237f00, state:R) prio=1 "Idle thread" (TID:0x284542a0, sys_thread_t:0x29216f00, state:R) prio=0 "Clock" (TID:0x28454088, sys_thread_t:0x291f5f00, state:CW) prio=12 "main" (TID:0x284540b0, sys_thread_t:0x8067700, state:R) prio=5 *current thr ead* pntransjava.main(pntransjava.java:59) Monitor Cache Dump: Registered Monitor Dump: Thread queue lock: Name and type hash table lock: String intern lock: JNI pinning lock: JNI global reference lock: BinClass lock: Class loading lock: Java stack lock: Code rewrite lock: Heap lock: Has finalization queue lock: Finalize me queue lock: Monitor IO lock: Child death monitor: Event monitor: I/O monitor: Alarm monitor: Waiting to be notified: "Clock" (0x291f5f00) Memory allocation lock: Monitor registry: owner "main" (0x8067700, 1 entry) Thread Alarm Q: ProcessPNTransaction() entered... About to call CommonProcessTransaction()... CommonProcessTransaction() entered... About to call inet_addr()... Returned from call to inet_addr()... ipaddr: 632412327... sock:7 finish setsockopt call connect. libc_r connect: Entered... libc_r connect: After _FD_LOCK()... Abort trap - core dumped *** Error code 134 Stop. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message