Bug 28570 - JNI on ARM: float parameters are not correctly passed to java methods
Summary: JNI on ARM: float parameters are not correctly passed to java methods
Status: RESOLVED WORKSFORME
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: 0.91
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-02 11:42 UTC by N. d'Heureuse
Modified: 2013-08-05 22:46 UTC (History)
3 users (show)

See Also:
Host:
Target: arm
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description N. d'Heureuse 2006-08-02 11:42:17 UTC
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;
}
Comment 1 Mark Wielaard 2006-08-06 21:13:43 UTC
This is a runtime/JNI bug. Which runtime do you use? (gcj, cacao, jamvm, ...)
Comment 2 N. d'Heureuse 2006-08-07 06:52:06 UTC
I use JamVM. I'm not sure whether this is a bug of Classpath or whether it should be reported to JamVM.
Comment 3 N. d'Heureuse 2006-08-07 06:56:59 UTC
update: JamVM 1.4.1 (could not compile JamVM 1.4.2 or 1.4.3 on ARM, yet)
Comment 4 Mark Wielaard 2006-08-08 09:24:56 UTC
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

Comment 5 Steven Newbury 2007-08-22 11:10:48 UTC
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?
Comment 6 Richard Earnshaw 2010-04-10 08:52:24 UTC
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
Comment 7 Richard Earnshaw 2013-08-05 22:46:01 UTC
No feedback in over three years.