Re: JNI incorrect conversion of C long to Java long (aka Re: SableVM on ARM fails to run HelloWorld)
Esteve Fernandez <[email protected]> Wed, 30 Nov 2005 15:40:01 +0100
| Newsgroups | gmane.comp.java.vm.sablevm.general |
|---|---|
| Organization | Scytl Secure Electronic Voting SA |
| Message-ID | <[email protected]> |
On Tuesday 29 November 2005 18:44, Chris Develder wrote: > The root cause of getting sablevm-1.12 working on our ARM device seems > to be that a long value in C is not converted correctly to a Java long > (via a JNI jlong, ie. a C long long). > > I verified that Java_java_io_VMFile_length > (sablevm-classpath-1.12/native/jni/java-io/java_io_VMFile.c) correctly > reads the file length as a long (794 for my HelloWorld.class). But > conversion to jlong (defined in jni_md.h as long long) seems to go > wrong: when inspecting the value in File.length() > (sablevm-classpath-1.12java/io/File.java), it turns out to be 0. > > Thus, something seems to go wrong when passing the long long from C to a > Java long through JNI... Any suggestions? I have experienced the same bug (http://sablevm.org/bugs/158), and since jlong values are used in such common places as System.currentTimeMillis() (which is called from almost everywhere), things like "new Date()" return funny values. It seems odd, but jlongArray data types are correctly passed to Java . You may rewrite the affected functions to return jlongArray values instead of jlong. Keep in mind that, if you're doing so, and call env->NewLogArray(), you'll have to explicitly call System.gc() so memory consume doesn't skyrocket. HTH, Esteve -- Esteve Fernàndez Gonzàlez, Software Engineer e-mail: [email protected] phone: +34 934 230 324 fax: +34 933 251 028 Scytl Secure Electronic Voting C. Entença 95 4-1 08015 Barcelona, Spain http://www.scytl.com NOTICE: The information in this e-mail and in any of its attachments is confidential and intended solely for the attention and use of the named addressee(s). If you are not the intended recipient, any disclosure, copying, distribution or retaining of this message or any part of it, without the prior written consent of Scytl Secure Electronic Voting, is prohibited and may be unlawful. If you have received this in error, please contact the sender and delete the material from any computer.