This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: JNI bug?
- From: Andrew Haley <aph at redhat dot com>
- To: Marco Trudel <mtrudel at gmx dot ch>
- Cc: GCC Java <java at gcc dot gnu dot org>
- Date: Mon, 29 Jan 2007 17:56:31 +0000
- Subject: Re: JNI bug?
- References: <45BE32E7.1030203@gmx.ch>
Marco Trudel writes:
> Hey all
>
> Here's an interesting one where GCJ sometimes isn't doing the same as a
> Sun JDK (no no Andrew, don't stop reading ;-)). Check out this little
> Java class:
>
> public class NativeBooleanTest
> {
> public static void main(String[] args)
> {
> System.loadLibrary("nativeBoolean");
> nativePrintBoolean(false);
> nativePrintBooleanAsInt(false);
> }
>
> private static native void nativePrintBoolean(boolean b);
> private static native void nativePrintBooleanAsInt(boolean b);
> }
>
> Now this c code:
>
> #include <jni.h>
>
> JNIEXPORT void JNICALL Java_NativeBooleanTest_nativePrintBoolean
> (JNIEnv *env, jclass c, jboolean b)
> {
> printf("nativePrintBoolean: %d\n", b);
> }
>
> JNIEXPORT void JNICALL Java_NativeBooleanTest_nativePrintBooleanAsInt
> (JNIEnv *env, jclass c, jint b)
> {
> printf("nativePrintBooleanAsInt: %d\n", b);
> }
>
>
> On a sun JVM, the output will be:
> nativePrintBoolean: 0
> nativePrintBooleanAsInt: 0
>
> On GCJ, in this minimalistic sample, it will always be:
> nativePrintBoolean: 0
> nativePrintBooleanAsInt: 10084864
>
> In a huge library I debugged for this, GCJ 4.3 gives twice 0 if
> optimization is disabled and also "10084864" as soon as optimization is
> enabled. GCJ 4.2 gives twice 0 in -O3 mode, GCJ 4.3 no longer.
>
>
> So,what do others think? What is the problem? Should there be an
> implicit cast? Is the code wrong? If yes, should it be attended so that
> the Sun RE is met?
> Unfortunately, this seems to go into the same unpleasant RE topic as my
> Arrays patch... But it also might be a GCJ bug. I don't know for sure.
zorro:~ $ ~/gcc/trunk/install/bin/gcj NativeBooleanTest.java --main=NativeBooleanTest -fjni -O2
zorro:~ $ ~/gcc/trunk/install/bin/gcc -fpic -shared -o libnativeBoolean.so nativeBoolean.c
zorro:~ $ LD_LIBRARY_PATH=.:~/gcc/trunk/install/lib64 ./a.out
nativePrintBoolean: 0
nativePrintBooleanAsInt: 0
zorro:~ $ ~/gcc/trunk/install/bin/gcj NativeBooleanTest.java --main=NativeBooleanTest -fjni -O3
zorro:~ $ LD_LIBRARY_PATH=.:~/gcc/trunk/install/lib64 ./a.out
nativePrintBoolean: 0
nativePrintBooleanAsInt: 0
zorro:~ $ ~/gcc/trunk/install/bin/gcc -fpic -shared -o libnativeBoolean.so nativeBoolean.c -O2
zorro:~ $ LD_LIBRARY_PATH=.:~/gcc/trunk/install/lib64 ./a.out
nativePrintBoolean: 0
nativePrintBooleanAsInt: 0