IBM's JNI fails where Sun's JNI works

Discussion in 'Java' started by Alex Hunsley, Nov 3, 2003.

  1. Alex Hunsley

    Alex Hunsley Guest

    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
    Alex Hunsley, Nov 3, 2003
    #1
    1. Advertising

  2. On Mon, 03 Nov 2003 14:58:34 +0000, Alex Hunsley wrote:
    > 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

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Nov 3, 2003
    #2
    1. Advertising

  3. Alex Hunsley

    Alex Hunsley Guest

    Gordon Beaton wrote:

    > On Mon, 03 Nov 2003 14:58:34 +0000, Alex Hunsley wrote:
    >
    >>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
    >


    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
    Alex Hunsley, Nov 3, 2003
    #3
  4. Alex Hunsley <> wrote:
    > 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...

    --
    Craig West Ph: (416) 666-1645 | It's not a bug,
    | It's a feature...
    A. Craig West, Nov 3, 2003
    #4
  5. Alex Hunsley

    Alex Hunsley Guest

    A. Craig West wrote:
    > Alex Hunsley <> wrote:
    >
    >>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...


    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
    Alex Hunsley, Nov 4, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian J. Sayatovic

    IBM/Sun SSL Headaches

    Brian J. Sayatovic, Oct 16, 2003, in forum: Java
    Replies:
    3
    Views:
    5,393
    Sudsy
    Oct 16, 2003
  2. Alex Hunsley
    Replies:
    9
    Views:
    379
    Alex Hunsley
    Nov 6, 2003
  3. Replies:
    0
    Views:
    2,846
  4. Robert Wells
    Replies:
    4
    Views:
    636
    Default User
    Jun 24, 2008
  5. Qu0ll
    Replies:
    42
    Views:
    1,191
    Thufir Hawat
    Apr 13, 2009
Loading...

Share This Page