Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JNI program work with 32bit but not 64bit JVM on jdk 1.6 & aix 5.3

Reply
Thread Tools

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

 
 
TsanChung
Guest
Posts: n/a
 
      09-17-2008
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(HwC ryptokiException.java:
57)
at com.mycomp.crypto.HwAPI.Initialize(Native Method)
at com.mycomp.crypto.HwTokenManager.<init>(HwTokenMan ager.java:
107)
at
com.mycomp.crypto.HwTokenManager.getInstance(HwTok enManager.java:62)
at jMultidevice.jMultidevice.<init>(jMultidevice.java :32)
at jMultidevice.jMultidevice.main(jMultidevice.java:8 05)
 
Reply With Quote
 
 
 
 
Lothar Kimmeringer
Guest
Posts: n/a
 
      09-17-2008
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: http://www.velocityreviews.com/forums/(E-Mail Removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-17-2008
On Wed, 17 Sep 2008 07:00:39 -0700 (PDT), TsanChung
<(E-Mail Removed)> 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
 
Reply With Quote
 
TsanChung
Guest
Posts: n/a
 
      09-18-2008
On Sep 17, 1:55*pm, Roedy Green <(E-Mail Removed)>
wrote:
> On Wed, 17 Sep 2008 07:00:39 -0700 (PDT), TsanChung
> <(E-Mail Removed)> 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;


 
Reply With Quote
 
TsanChung
Guest
Posts: n/a
 
      09-18-2008
On Sep 17, 10:55*am, Lothar Kimmeringer <(E-Mail Removed)>
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: (E-Mail Removed)
> * * * * * * * *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.
 
Reply With Quote
 
Lothar Kimmeringer
Guest
Posts: n/a
 
      09-18-2008
TsanChung wrote:

> On Sep 17, 10:55*am, Lothar Kimmeringer <(E-Mail Removed)>
> 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: (E-Mail Removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
Reply With Quote
 
Lothar Kimmeringer
Guest
Posts: n/a
 
      09-18-2008
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: (E-Mail Removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
Reply With Quote
 
TsanChung
Guest
Posts: n/a
 
      09-18-2008
On Sep 18, 4:59*am, Lothar Kimmeringer <(E-Mail Removed)>
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: (E-Mail Removed)
> * * * * * * * *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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JNI 64bit JVM, load 32bit native library mark.faine@gmail.com Java 4 06-22-2011 07:34 AM
JNI program work with jdk 5 but not jdk6 on aix 5.3 TsanChung Java 4 09-26-2008 02:43 PM
debugger for JNI apps jdk 6.0 on aix 5.3 TsanChung Java 2 09-18-2008 03:02 AM
jvm core dump with jni c++ on AIX only Mike Java 0 12-09-2003 05:15 PM
how jni invoke jvm in jdk 1.4 -any sample code Roedy Green Java 4 08-04-2003 10:49 PM



Advertisments