J
James Ly
Hi,
I am having a very intermittent problem with JNI (tried with Java
versions 1.3.1_09/1.4.1_02/1.4.2_02) on Linux 8.0 (kernel 2.4.18).
From a C program, I am first starting up a JVM. Here is the relevant
C-code for this:
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 2;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm,(void **) &env,&vm_args);
if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");
//exit(1);
}
Once the JVM is created, I load one of the Java class (Test). Here is
the C-code for that:
char *className = "Test";
// Find the Test class
testClass = (*env)->FindClass (env, className);
// If not found, return error.
if (testClass == 0) {
exp = (*env)->ExceptionOccurred (env);
if (exp) {
(*env)->ExceptionDescribe (env);
}
fprintf (stderr, "Can't find the %s class\n", className);
}
In the Java world, there are 2 relevant classes for the problem:
* PeggingThread: PeggingThread class sends a peg of user info to track
usage. It listens for requests coming into it and then opens a socket
and sends a message over that socket for each of the requests. The
reason for doing this as a thread is that I don't want to block the
application while opening/sending msg to the socket.
* Test: The Test class has a static variable for the PeggingThread,
and has a static block which sends a request to the PeggingThread.
private static final PeggingThread peggingThread = new
PeggingThread();
static {
if (Test.sentRunningInfo == false) {
Test.peggingThread.receiveRequest("");
Test.sentRunningInfo = true;
}
}
The interminttent problem that I am seeing is that when running the
above code, I get the following error and the application quits almost
half the time:
An unexpected exception has been detected in native code outside the
VM.
Unexpected Signal : 11 occurred at PC=0x40628ff0
Function name=(N/A)
Library=/lib/i686/libpthread.so.0
NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for
possible
reason and solutions.
and then a list of all the shared libraries that were loaded.
Going through the core file that gets generated using gdb, backtrace
indicates different places where the crash heppened. So, it doesn't
help much. If I remove the static block from the Test class, ie. no
sending of the peg for user info, I don't see any crashes and the
application runs fine.
Would anyone out there know why I am seeing such an issue. To me it
looks like there is some race condition, but this never happens when I
run in a pure Java environment (Java code not using JNI). Any info
would help. I have been struggling with this for about 2 weeks now.
Thanks.
James Ly
I am having a very intermittent problem with JNI (tried with Java
versions 1.3.1_09/1.4.1_02/1.4.2_02) on Linux 8.0 (kernel 2.4.18).
From a C program, I am first starting up a JVM. Here is the relevant
C-code for this:
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 2;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm,(void **) &env,&vm_args);
if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");
//exit(1);
}
Once the JVM is created, I load one of the Java class (Test). Here is
the C-code for that:
char *className = "Test";
// Find the Test class
testClass = (*env)->FindClass (env, className);
// If not found, return error.
if (testClass == 0) {
exp = (*env)->ExceptionOccurred (env);
if (exp) {
(*env)->ExceptionDescribe (env);
}
fprintf (stderr, "Can't find the %s class\n", className);
}
In the Java world, there are 2 relevant classes for the problem:
* PeggingThread: PeggingThread class sends a peg of user info to track
usage. It listens for requests coming into it and then opens a socket
and sends a message over that socket for each of the requests. The
reason for doing this as a thread is that I don't want to block the
application while opening/sending msg to the socket.
* Test: The Test class has a static variable for the PeggingThread,
and has a static block which sends a request to the PeggingThread.
private static final PeggingThread peggingThread = new
PeggingThread();
static {
if (Test.sentRunningInfo == false) {
Test.peggingThread.receiveRequest("");
Test.sentRunningInfo = true;
}
}
The interminttent problem that I am seeing is that when running the
above code, I get the following error and the application quits almost
half the time:
An unexpected exception has been detected in native code outside the
VM.
Unexpected Signal : 11 occurred at PC=0x40628ff0
Function name=(N/A)
Library=/lib/i686/libpthread.so.0
NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for
possible
reason and solutions.
and then a list of all the shared libraries that were loaded.
Going through the core file that gets generated using gdb, backtrace
indicates different places where the crash heppened. So, it doesn't
help much. If I remove the static block from the Test class, ie. no
sending of the peg for user info, I don't see any crashes and the
application runs fine.
Would anyone out there know why I am seeing such an issue. To me it
looks like there is some race condition, but this never happens when I
run in a pure Java environment (Java code not using JNI). Any info
would help. I have been struggling with this for about 2 weeks now.
Thanks.
James Ly