public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* libffi return value convention bug
@ 2002-10-01 10:08 Ulrich Weigand
  2002-10-01 13:01 ` Jeff Sturm
  0 siblings, 1 reply; 2+ messages in thread
From: Ulrich Weigand @ 2002-10-01 10:08 UTC (permalink / raw)
  To: java; +Cc: gcc

Hello,

after actually switching on the Java interpreter on s390(x), it appears
that my libffi implementation is still broken :-/

Unfortunately, one particular problem looks like it is not completely
my fault: the question is, how are 32-bit return values to be handled
on 64-bit (big endian) platforms?

In java/lang/reflect/natMethod.cc, it is expected that ints are returned
by ffi_call as a 'ffi_arg' type, which is defined to be an 64-bit integer
type on 64-bit machines.  However, in interpreter.cc, it is expected that
ints are returned by ffi_raw_call / ffi_java_raw_call as 'jint' type,
which is always a 32-bit integer type.

Furthermore, ffi_raw_call / ffi_java_raw_call have a default implementation
in terms of ffi_call which does not in any way convert the return value.

So, I cannot implement ffi_call to satisfy at the same time both
requirements on a 64-bit big endian machine.  Any suggestions?


Related is the question of how ffi_closure expects its target function
to handle return values.  One closure target function used by libjava,
_Jv_JNIMethod::call, simply passes the ret pointer on to ffi_raw_call,
so it would appear that ffi_closure should handle return values just
the same ways as ffi_(raw_)call.

However, the other target function, _Jv_InterpMethod::run, specifically
interprets the ret pointer as 'jint *' when returning 32-bit values.
So, if it turns out that ffi_call is supposed to return 64-bit, then
ffi_closure cannot be implemented correctly ...


(B.t.w. why aren't the return value pointers handled just the same as
the argument pointers, i.e. as void pointers interpreted to point to
exactly the type described by cif->rtype?  That sure would simplify
the issue ...)


Mit freundlichen Gruessen / Best Regards

Ulrich Weigand

--
  Dr. Ulrich Weigand
  Linux for S/390 Design & Development
  IBM Deutschland Entwicklung GmbH, Schoenaicher Str. 220, 71032 Boeblingen
  Phone: +49-7031/16-3727   ---   Email: Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: libffi return value convention bug
  2002-10-01 10:08 libffi return value convention bug Ulrich Weigand
@ 2002-10-01 13:01 ` Jeff Sturm
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Sturm @ 2002-10-01 13:01 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: java, gcc

On Tue, 1 Oct 2002, Ulrich Weigand wrote:
> So, I cannot implement ffi_call to satisfy at the same time both
> requirements on a 64-bit big endian machine.  Any suggestions?

This was discussed (but not resolved) when I posted my SPARC V9 closure
patches for comment.

http://gcc.gnu.org/ml/java-patches/2002-q3/msg00036.html
http://gcc.gnu.org/ml/java-patches/2002-q3/msg00047.html

Note that java_raw_api.c tries to handle the mismatch between _Jv_word and
ffi_arg unions, but the existing code doesn't extend nicely to 64-bit or
big endian targets.

Afterwards I realized my patch may break powerpc, which I could not test.

> (B.t.w. why aren't the return value pointers handled just the same as
> the argument pointers, i.e. as void pointers interpreted to point to
> exactly the type described by cif->rtype?  That sure would simplify
> the issue ...)

No idea.  Alpha does just that, but the powerpc and SH big endian ports
seem to expect that char/short values are returned in a (int *).

While balancing portability and efficiency, I suspect the libffi code
ended up with some of both :-(

Hans Boehm suggested the libffi API could be divided into "cooked", "raw"
and "java" models.  I don't think anyone has acted on his suggestion:

http://gcc.gnu.org/ml/java-patches/2002-q3/msg00040.html

Jeff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-10-01 19:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-01 10:08 libffi return value convention bug Ulrich Weigand
2002-10-01 13:01 ` Jeff Sturm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).