Date: Thu, 24 Jun 1999 17:03:37 -0700 From: Steve Heller <sheller@PaymentNet.com> To: "'freebsd-gnats-submit@freebsd.org'" <freebsd-gnats-submit@freebsd.org>, Steve Heller <sheller@PaymentNet.com> Cc: "'freebsd-java@freebsd.org'" <freebsd-java@freebsd.org> Subject: Re: i386/12286: Segmentation violation when invoking JNI call to C from Java with PTHREADS Message-ID: <1B1A79237E23D21181B4006008280032497A7A@mail.paymentnet.com>
next in thread | raw e-mail | index | archive | help
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 <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#ifdef _THREAD_SAFE
#include <pthread.h>
#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: <unowned>
Name and type hash table lock: <unowned>
String intern lock: <unowned>
JNI pinning lock: <unowned>
JNI global reference lock: <unowned>
BinClass lock: <unowned>
Class loading lock: <unowned>
Java stack lock: <unowned>
Code rewrite lock: <unowned>
Heap lock: <unowned>
Has finalization queue lock: <unowned>
Finalize me queue lock: <unowned>
Monitor IO lock: <unowned>
Child death monitor: <unowned>
Event monitor: <unowned>
I/O monitor: <unowned>
Alarm monitor: <unowned>
Waiting to be notified:
"Clock" (0x291f5f00)
Memory allocation lock: <unowned>
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-java" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1B1A79237E23D21181B4006008280032497A7A>
