This bug might be similar to #22800. This problem occurs on ARM platform (a Nokia 770; Scratchbox 0.9.8 was used for crosscompilation). It does not occur on a x86 platform. When a float parameter is passed to a Java method from within native code, allways "0" is passed to Java instead of the correct float value. When double is used instead of float, the problem does not occur. This problem has been observed when using "CallStatic<...>Method(...)" and "Call<...>Method(...)" calls. The code below prints the following on a x86 platform (correct output): Received 100.0 Received 1234.0 Returned 100.0 The output on an ARM platform is: Received 0.0 Received 0.0 Returned 100.0 --- Code to reproduce the problem --- ----- JAVA ----- public class FloatTest { public static void main(String[] args){ System.loadLibrary("floatTest"); float myFloat=100.0f; float returned=nativeMethod( myFloat ); System.out.println("Returned "+returned); } private static void printFloat(float f){ System.out.println("Received "+f); } private static native float nativeMethod(float f); } ------- native code ------- #include <jni.h> #include "FloatTest.h" JNIEXPORT jfloat JNICALL Java_FloatTest_nativeMethod(JNIEnv *env, jclass cls, jfloat f){ env->CallStaticVoidMethod(cls, env->GetStaticMethodID(cls, "printFloat", "(F)V"), f); env->CallStaticVoidMethod(cls, env->GetStaticMethodID(cls, "printFloat", "(F)V"), (float)1234.0); return f; }
This is a runtime/JNI bug. Which runtime do you use? (gcj, cacao, jamvm, ...)
I use JamVM. I'm not sure whether this is a bug of Classpath or whether it should be reported to JamVM.
update: JamVM 1.4.1 (could not compile JamVM 1.4.2 or 1.4.3 on ARM, yet)
Subject: Re: JNI on ARM: float parameters are not correctly passed to java methods Hi Robert, This bug might be JamVM related. Could you take a look and see? http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28570
This may be the same bug? With jamvm-1.45, using the test from comment #6 of bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22800 a equals b:true a:-1.0 b:-1.0 Double.doubleToLongBits(a):-4616189618054758400 Double.doubleToLongBits(a):-4616189618054758400 Double.doubleToRawLongBits(b):-4616189618054758400 Double.doubleToRawLongBits(b):-4616189618054758400 Float.floatToRawIntBits((float)a):-1082130432 Float.floatToIntBits((float)a):-1082130432 Float.floatToRawIntBits((float)b):-1082130432 Float.floatToIntBits((float)b):-1082130432 jamvm: java_lang_VMDouble.c:430: Java_java_lang_VMDouble_toString: Assertion `least_necessary_precision <= maximal_precision' failed. Aborted However this does not happen with jamvm compiled -O0. Furthermore, starting from -O0, turning each optimization on as listed in the gcc info documentation for -O1 also works!?! Or does -O0 override later flags?
The format of floating point numbers on ARM depend on the ABI used. You don't say what configuration you have and this is important to start trying to investigate the problem
No feedback in over three years.