JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix 5.3

Discussion in 'Java' started by TsanChung, Sep 17, 2008.

  1. TsanChung

    TsanChung Guest

    My JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix 5.3.
    Why?
    32 bit is ok:
    $ /usr/java6/jre/bin/java -d32 -jar jMultidevice.jar

    64 bit fails:
    $ /usr/java6_64/jre/bin/java -d64 -jar jMultidevice.jar
    SSL Connect is failing
    Exception in thread "main" com.mycomp.crypto.HwCryptokiException:
    function 'C_Initialize' returns 0x30
    at
    com.mycomp.crypto.HwCryptokiException.ThrowNew(HwCryptokiException.java:
    57)
    at com.mycomp.crypto.HwAPI.Initialize(Native Method)
    at com.mycomp.crypto.HwTokenManager.<init>(HwTokenManager.java:
    107)
    at
    com.mycomp.crypto.HwTokenManager.getInstance(HwTokenManager.java:62)
    at jMultidevice.jMultidevice.<init>(jMultidevice.java:32)
    at jMultidevice.jMultidevice.main(jMultidevice.java:805)
     
    TsanChung, Sep 17, 2008
    #1
    1. Advertising

  2. TsanChung wrote:

    > 64 bit fails:
    > $ /usr/java6_64/jre/bin/java -d64 -jar jMultidevice.jar
    > SSL Connect is failing
    > Exception in thread "main" com.mycomp.crypto.HwCryptokiException:
    > function 'C_Initialize' returns 0x30


    Most likely you cast a pointer to a jint. Without knowing
    C_Initialize nobody can tell for sure.


    Regards, Lothar
    --
    Lothar Kimmeringer E-Mail:
    PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

    Always remember: The answer is forty-two, there can only be wrong
    questions!
     
    Lothar Kimmeringer, Sep 17, 2008
    #2
    1. Advertising

  3. TsanChung

    Roedy Green Guest

    On Wed, 17 Sep 2008 07:00:39 -0700 (PDT), TsanChung
    <> wrote, quoted or indirectly quoted someone
    who said :

    >My JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix 5.3.


    I would assume you have to redo the Javah, and code to 64 bit C++, and
    compile with a 64bit C++ compiler. It will be passing you 64 bit
    addresses.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Sep 17, 2008
    #3
  4. TsanChung

    TsanChung Guest

    Re: JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix5.3

    On Sep 17, 1:55 pm, Roedy Green <>
    wrote:
    > On Wed, 17 Sep 2008 07:00:39 -0700 (PDT), TsanChung
    > <> wrote, quoted or indirectly quoted someone
    > who said :
    >
    > >My JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix 5.3.

    >
    > I would assume you have to redo the Javah, and code to 64 bit C++, and
    > compile with a 64bit C++ compiler. It will be passing you 64 bit
    > addresses.
    > --
    >
    > Roedy Green Canadian Mind Products
    > The Java Glossaryhttp://mindprod.com


    This JNI program in C++ & jdk 6 work on 32-bit and 64-bit linux.
    It is working on 32-bit aix. I am trying to make it to work on 64-bit
    aix.
    compile option is:
    -I../../../cryptoki_vob/source/subdir -c -q64 -qwarn64 -I/usr/java6_64/
    include -L/usr/lib -L/lib -L/usr/java6_64/jre/bin/classic -L/usr/
    java6_64/jre/bin -I/usr/java/include -I/usr/java6/include -DOS_UNIX -
    DOS_AIX -DUSE_PTHREADS -DLUNA_BIG_ENDIAN -DPKCS11_2_0 -DNDEBUG ./
    HwAPI.cpp -o ./HwAPI.o -lj


    "./HwAPI.cpp", line 1054.38: 1540-5334 (I) 64-bit portability :
    possible difference in results if value is negative.

    "./HwAPI.cpp", line 1072.24: 1540-5328 (I) 64-bit portability :
    possible loss of digits through conversion of long type into int type

    "./HwAPI.cpp", line 1073.24: 1540-5328 (I) 64-bit portability :
    possible loss of digits through conversion of long type into int type


    //line 1054:
    retCode = C_GenerateKeyPair( hSession, &mech,
    pubTemplate, sizeof(pubTemplate)/
    sizeof(pubTemplate[0]),
    privTemplate,
    sizeof(privTemplate)/sizeof(privTemplate[0]),
    &hPub, &hPriv);

    env->ReleaseByteArrayElements(p, pbP, 0);
    if( qLen )
    env->ReleaseByteArrayElements(q, pbQ, 0);
    if( gLen )
    env->ReleaseByteArrayElements(g, pbG, 0);

    if (retCode != CKR_OK) {
    ThrowCryptokiException(env, "C_GenerateKeyPair", retCode);
    return NULL;
    }

    jintArray returnValue = env->NewIntArray(2);
    jint *piReturnValue = env->GetIntArrayElements(returnValue, 0);
    //line 1072:
    piReturnValue[0] = hPub;
    //line 1073:
    piReturnValue[1] = hPriv;
     
    TsanChung, Sep 18, 2008
    #4
  5. TsanChung

    TsanChung Guest

    Re: JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix5.3

    On Sep 17, 10:55 am, Lothar Kimmeringer <>
    wrote:
    > TsanChung wrote:
    > > 64 bit fails:
    > > $ /usr/java6_64/jre/bin/java -d64 -jar jMultidevice.jar
    > > SSL Connect is failing
    > > Exception in thread "main" com.mycomp.crypto.HwCryptokiException:
    > > function 'C_Initialize' returns 0x30

    >
    > Most likely you cast a pointer to a jint. Without knowing
    > C_Initialize nobody can tell for sure.
    >
    > Regards, Lothar
    > --
    > Lothar Kimmeringer                E-Mail:
    >                PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
    >
    > Always remember: The answer is forty-two, there can only be wrong
    >                  questions!


    There are a lot of source code so it is hard to post them.
    Do you mean
    "cast a pointer to a jint" is to check the different size of variables
    when casting?

    jint is equal to "signed 32 bits"
    but size of pointer varies.
     
    TsanChung, Sep 18, 2008
    #5
  6. Re: JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix 5.3

    TsanChung wrote:

    > On Sep 17, 10:55 am, Lothar Kimmeringer <>
    > wrote:
    >> Most likely you cast a pointer to a jint. Without knowing
    >> C_Initialize nobody can tell for sure.

    >
    > There are a lot of source code so it is hard to post them.


    I didn't ask for the source ;-) But you might be able to
    track down the place when checking when an error-code 0x30
    is actually returned. Refactoring the C-source might help
    as well or simply add printfs for a start (don't forget
    to flush, otherwise you see the messages only at the end
    of the lifetime of the virtual machine).

    > Do you mean
    > "cast a pointer to a jint" is to check the different size of variables
    > when casting?


    I'm talking of a line like this:

    jbyte *arr = env->GetByteArrayElements(aByteArray, 0);
    return (jint) arr;

    On 32-Bit-Systems this works, on 64-Bit-Systems it's breaking
    because you lose half of the address. A solution (until you
    have to deal with 128 Bit systems) is using jlong (that was
    my solution for jCapi where I was in exactly that situation.

    > jint is equal to "signed 32 bits"
    > but size of pointer varies.


    I know, but as long the size is < 32 Bit it doesn't matter.

    Another reason might be that a library your JNI-library is
    using is having the same problem. With a debugger or printfs
    you should be able to track that down as well.


    Regards, Lothar
    --
    Lothar Kimmeringer E-Mail:
    PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

    Always remember: The answer is forty-two, there can only be wrong
    questions!
     
    Lothar Kimmeringer, Sep 18, 2008
    #6
  7. Re: JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix 5.3

    TsanChung wrote:

    > "./HwAPI.cpp", line 1072.24: 1540-5328 (I) 64-bit portability :
    > possible loss of digits through conversion of long type into int type
    >
    > "./HwAPI.cpp", line 1073.24: 1540-5328 (I) 64-bit portability :
    > possible loss of digits through conversion of long type into int type

    [...]
    > &hPub, &hPriv);


    What type is hPub and hPriv? I assume it's the address to a
    structure containing a BigInteger (I interpret the prefix
    h to be some kind of "handle").

    > //line 1072:
    > piReturnValue[0] = hPub;
    > //line 1073:
    > piReturnValue[1] = hPriv;


    And here you cast an address to a jint.


    Regards, Lothar
    --
    Lothar Kimmeringer E-Mail:
    PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

    Always remember: The answer is forty-two, there can only be wrong
    questions!
     
    Lothar Kimmeringer, Sep 18, 2008
    #7
  8. TsanChung

    TsanChung Guest

    Re: JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix5.3

    On Sep 18, 4:59 am, Lothar Kimmeringer <>
    wrote:
    > TsanChung wrote:
    > > "./HwAPI.cpp", line 1072.24: 1540-5328 (I) 64-bit portability :
    > > possible loss of digits through conversion of long type into int type

    >
    > > "./HwAPI.cpp", line 1073.24: 1540-5328 (I) 64-bit portability :
    > > possible loss of digits through conversion of long type into int type

    > [...]
    > >                                      &hPub, &hPriv);

    >
    > What type is hPub and hPriv? I assume it's the address to a
    > structure containing a BigInteger (I interpret the prefix
    > h to be some kind of "handle").
    >
    > > //line 1072:
    > >     piReturnValue[0] = hPub;
    > > //line 1073:
    > >  piReturnValue[1] = hPriv;

    >
    > And here you cast an address to a jint.
    >
    > Regards, Lothar
    > --
    > Lothar Kimmeringer                E-Mail:
    >                PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
    >
    > Always remember: The answer is forty-two, there can only be wrong
    >                  questions!


    hPub and hPriv are of type "unsigned long int" which is not defined in
    JNI.
    jint is "signed 32 bits" and
    jlong is "signed 64 bits", so use jlong instead of jint.
     
    TsanChung, Sep 18, 2008
    #8
    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. Mike
    Replies:
    0
    Views:
    738
  2. Replies:
    3
    Views:
    541
    NOBODY
    Nov 12, 2005
  3. Replies:
    4
    Views:
    8,037
    tungjty
    Jun 22, 2011
  4. TsanChung
    Replies:
    2
    Views:
    471
    TsanChung
    Sep 18, 2008
  5. TsanChung
    Replies:
    4
    Views:
    1,112
    TsanChung
    Sep 26, 2008
Loading...

Share This Page