This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix JNI failures on s390x


Hello,

we're seeing once again a libjava/libffi interaction problem that
occurs only on big-endian 64-bit systems (like s390x).

On such systems, it is really important not to mix up the ffi_raw_
functions with the ffi_java_raw_ functions ...

The problem that is causing multiple JNI test suite failures
comes from the combination of _Jv_JNIMethod::ncode (resolv.cc)
using ffi_prep_java_raw_closure to form a closure calling
_Jv_JNIMethod::call (jni.cc), and the latter function itself
using ffi_raw_call to call the JNI function.

When calling the closure, the Java arguments get translated
into the ffi_java_raw_ style of ffi_raw arguments, and passed
in that form to _Jv_JNIMethod::call.  This function simply
passes on its arguments to ffi_raw_call, but that function
expects its arguments in the ffi_raw_ style (not ffi_java_raw_
style).  This causes corruption on systems where the two
styles actually differ.

As far as I can see, this could be fixed either by using
ffi_prep_raw_closure to build the _Jv_JNIMethod::call closure,
or else by using ffi_java_raw_call within _Jv_JNIMethod::call.
I've chosen the latter method simply because it makes the use
of the ffi_java_raw_ style calls consistent throughout libjava.

Tested on s390-ibm-linux and s390x-ibm-linux, fixes all JNI
failures on s390x:
FAIL: PR15133 output - gij test
FAIL: invoke output - gij test
FAIL: overload output - gij test
FAIL: register output - gij test
FAIL: simple_int output - gij test
FAIL: throwit output - gij test

OK for mainline?

Bye,
Ulrich


ChangeLog:

	* jni.cc (_Jv_JNIMethod::call): Use ffi_java_raw_call instead of
	ffi_raw_call if FFI_NATIVE_RAW_API is not defined.

Index: libjava/jni.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni.cc,v
retrieving revision 1.87
diff -c -p -r1.87 jni.cc
*** libjava/jni.cc	28 Sep 2004 21:55:26 -0000	1.87
--- libjava/jni.cc	13 Oct 2004 22:09:35 -0000
*************** _Jv_JNIMethod::call (ffi_cif *, void *re
*** 2213,2220 ****
--- 2213,2225 ----
    memcpy (&real_args[offset], args, _this->args_raw_size);
  
    // The actual call to the JNI function.
+ #if FFI_NATIVE_RAW_API
    ffi_raw_call (&_this->jni_cif, (void (*)()) _this->function,
  		ret, real_args);
+ #else
+   ffi_java_raw_call (&_this->jni_cif, (void (*)()) _this->function,
+ 		     ret, real_args);
+ #endif
  
    if (sync != NULL)
      _Jv_MonitorExit (sync);
-- 
  Dr. Ulrich Weigand
  weigand@informatik.uni-erlangen.de


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]