IBM's JNI fails where Sun's JNI works

A

Alex Hunsley

I'm dealing with a problem where the some java code, that uses a native
library (under linux) works fine under Sun's JVM, but as soon as we use
IBMs VM (1.3.1) things go horribly wrong in the native library.

Things appear to be going wrong in a call to
((*theEnv)->NewStringUTF(theEnv, utf));

Is there any particular reason why IBM's JNI should fail where Sun's
doesn't? I have heard that IBMs VM is more strict with how it does
thing, but I've also checked the native javaglue code for errors, such
as not calling release on newly created strings etc., but I can't find any!

thanks
alex
 
G

Gordon Beaton

I'm dealing with a problem where the some java code, that uses a
native library (under linux) works fine under Sun's JVM, but as soon
as we use IBMs VM (1.3.1) things go horribly wrong in the native
library.

Exactly what happens when things go wrong?

Do you have the same problem with *any* applications that use native
code, or just with a particular one? Do you see similar problems if
you use different JVMs from Sun?

If you have the same problem with other applications, I would check
things in the build or runtime environment such as compiler and
library versions. When you change JVMs, do you recompile your native
code to use the corresponding header files?

Otherwise, suspect your code. Even though you've checked it, generally
this kind of problem is due to programming error. A pointer error,
overwritten struct or uninitialized variable can result in very subtle
failures that may not occur in all situations. When you load your
library in a different JVM, the memory layout is different and you can
see failures that did not show up previously.

/gordon
 
A

Alex Hunsley

Gordon said:
Exactly what happens when things go wrong?

Do you have the same problem with *any* applications that use native
code, or just with a particular one? Do you see similar problems if
you use different JVMs from Sun?

If you have the same problem with other applications, I would check
things in the build or runtime environment such as compiler and
library versions. When you change JVMs, do you recompile your native
code to use the corresponding header files?

Otherwise, suspect your code. Even though you've checked it, generally
this kind of problem is due to programming error. A pointer error,
overwritten struct or uninitialized variable can result in very subtle
failures that may not occur in all situations. When you load your
library in a different JVM, the memory layout is different and you can
see failures that did not show up previously.

/gordon

I think I've spotted the problem. The native code we're calling is
returning a null string, which I think is a no-no as far as JNI goes.
The sun vm wasn't minding too much, but the IBM vm hated it.
I found this out when I ran the problem class with the Xcheck:jni java
parameter - it told me about the null string usage and complained.

alex
 
A

A. Craig West

Alex Hunsley said:
I think I've spotted the problem. The native code we're calling is
returning a null string, which I think is a no-no as far as JNI goes.
The sun vm wasn't minding too much, but the IBM vm hated it.
I found this out when I ran the problem class with the Xcheck:jni java
parameter - it told me about the null string usage and complained.

How do you mean, returning a null string? JNI code should be able to return
NULL and have it work properly, that is, after all, a valid return value. I
suspect I'm not understanding what you mean when you say null string...
 
A

Alex Hunsley

A. Craig West said:
How do you mean, returning a null string? JNI code should be able to return
NULL and have it work properly, that is, after all, a valid return value. I
suspect I'm not understanding what you mean when you say null string...

What I mean is that I'm getting this thrown when I run with -Xcheck:jni:


JVMCI161: FATAL ERROR in native method: JNI received a null string
at a.b.c.ClassName.MethodName(Native Method)

(package + class obscured!)

I'm looking more closely at what's going on in the native code....
alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top