A
Alex Hunsley
I've refined my problem using JNI under IBM's JVM1.4.1 (in Linux) to the
following scenario:
I have two java classes, X and Y, that have native methods in them. X
and Y use different .so native library files (on a redhat linux system)
for their native functionality.
Now, if my main code reads as follows:
X xInstance = new X();
Y yInstance = new Y();
result = yInstance.nativeMethod("a string");
.... then I crash out with Segmentation fault/javacore dump when my
native code for Y calls NewStringUTF or GetStringUTF. Calls to native
code in X work though.
If I rearrange my code as follows:
// swapped - make a new Y *before* a new X!
Y yInstance = new Y();
X xInstance = new X();
result = yInstance.nativeMethod("a string");
... then my native code in Y works! (but any calls to native code in X
that use NewStringUTF or GetStringUTF are now not working.)
So the problem appears to be that the first native library that is
loaded works fine, any after that are broken and can't call GetStringUTF
etc.
I don't have these problems when using the Sun JVM, but I'm constrained
at the minute to use the IBM JVM, so I'd like to find the problem if
possible!
alex
p.s. the native library files (.so files) are loaded due to the
following static section in classes X and Y:
static
{
try
{
System.loadLibrary("myLibrary");
}
catch(UnsatisfiedLinkError unsatisfiedlinkerror)
{
System.err.println("myLibrary was not found.\n\n");
unsatisfiedlinkerror.printStackTrace();
}
}
following scenario:
I have two java classes, X and Y, that have native methods in them. X
and Y use different .so native library files (on a redhat linux system)
for their native functionality.
Now, if my main code reads as follows:
X xInstance = new X();
Y yInstance = new Y();
result = yInstance.nativeMethod("a string");
.... then I crash out with Segmentation fault/javacore dump when my
native code for Y calls NewStringUTF or GetStringUTF. Calls to native
code in X work though.
If I rearrange my code as follows:
// swapped - make a new Y *before* a new X!
Y yInstance = new Y();
X xInstance = new X();
result = yInstance.nativeMethod("a string");
... then my native code in Y works! (but any calls to native code in X
that use NewStringUTF or GetStringUTF are now not working.)
So the problem appears to be that the first native library that is
loaded works fine, any after that are broken and can't call GetStringUTF
etc.
I don't have these problems when using the Sun JVM, but I'm constrained
at the minute to use the IBM JVM, so I'd like to find the problem if
possible!
alex
p.s. the native library files (.so files) are loaded due to the
following static section in classes X and Y:
static
{
try
{
System.loadLibrary("myLibrary");
}
catch(UnsatisfiedLinkError unsatisfiedlinkerror)
{
System.err.println("myLibrary was not found.\n\n");
unsatisfiedlinkerror.printStackTrace();
}
}