Libffi (and hopefully PowerPC) support

Pavel Roskin pavel_roskin at geocities.com
Sun Jan 23 12:43:03 PST 2000


Hello!

The attached patch makes it possible to use libffi together with Kaffe.
sysdepCallMethod has been implemented using libffi calls.

libffi can be downloaded from http://sourceware.cygnus.com/libffi/

You should specify --with-libffi explicitly in order to use this code. No
attempts are made yet to guess if libffi should be used on a particular
platform.

This patch has only been tested on i386 and is known to pass almost all
tests including TestNative. However, it needs testing on other platforms,
on PowerPC in the first place.

The only test that fails is InvTarExcTest.java. I have no idea why it
fails. The only difference is that following line doesn't appear in th
output:

	at java.lang.reflect.Method.invoke(Method.java:native)

Pavel Roskin

=== cut here ===
diff -ur --exclude-from=excl kaffe/ChangeLog kaffe.new/ChangeLog
--- kaffe/ChangeLog	Thu Jan 20 23:05:18 2000
+++ kaffe.new/ChangeLog	Sun Jan 23 15:38:41 2000
@@ -1,3 +1,10 @@
+Sun Jan 23 15:34:03 EST 2000  Pavel Roskin <pavel_roskin at geocities.com>
+
+	* configure.in: If --with-libffi is specified, check for libffi
+	and use it if found
+	* kaffe/kaffevm/support.c: If HAVE_LIBFFI is defined use
+	sysdepCallMethod implemented using libffi calls
+
 Thu Jan 20 13:40:56 PST 2000  Archie Cobbs <archie at whistle.com>
 
 	* libraries/clib/awt/X/img.c: remove unused function
diff -ur --exclude-from=excl kaffe/configure.in kaffe.new/configure.in
--- kaffe/configure.in	Fri Jan 14 21:20:36 2000
+++ kaffe.new/configure.in	Sun Jan 23 14:57:38 2000
@@ -516,6 +516,13 @@
 
 AC_SUBST(M_LIBS)
 
+dnl If there is no native sysdepCallMethod, let's use libffi
+
+AC_ARG_WITH(libffi,[  --with-libffi           Use libffi for sysdepCallMethod])
+if test x"$with_libffi" = x"yes" ; then
+	AC_CHECK_LIBRARY(ffi,ffi_call,VM_LIBS)
+fi
+
 dnl Checks for libraries for vm library.
 dnl Include work around FreeBSD modulo bug.
 
diff -ur --exclude-from=excl kaffe/kaffe/kaffevm/support.c kaffe.new/kaffe/kaffevm/support.c
--- kaffe/kaffe/kaffevm/support.c	Sat Nov 13 20:48:29 1999
+++ kaffe.new/kaffe/kaffevm/support.c	Sun Jan 23 15:20:59 2000
@@ -26,7 +26,9 @@
 #include "exception.h"
 #include "slots.h"
 #include "support.h"
-#define NEED_sysdepCallMethod 1
+#ifndef HAVE_LIBFFI
+# define NEED_sysdepCallMethod 1
+#endif /* HAVE_LIBFFI */
 #include "classMethod.h"
 #include "machine.h"
 #include "md.h"
@@ -54,6 +56,60 @@
 
 extern struct JNIEnv_ Kaffe_JNIEnv;
 
+#ifdef HAVE_LIBFFI
+#include <ffi.h>
+static inline ffi_type *j2ffi(char type)
+{
+	ffi_type *ftype;
+
+	switch (type) {
+	case 'J':
+		ftype = &ffi_type_sint64;
+		break;
+	case 'D':
+		ftype = &ffi_type_double;
+		break;
+	case 'F':
+		ftype = &ffi_type_float;
+		break;
+	default:
+		ftype = &ffi_type_uint;
+	}
+	return ftype;
+}
+
+#define sysdepCallMethod(CALL)						\
+do {									\
+	int i;								\
+	ffi_cif cif;							\
+	ffi_type *rtype;						\
+	ffi_type *argtypes[(CALL)->nrargs + 1];				\
+	void *argvals[(CALL)->nrargs + 1];				\
+	int fargs = 0;							\
+	for (i = 0; i < (CALL)->nrargs; i++) {				\
+		switch ((CALL)->callsize[i]) {				\
+		case 1:							\
+			argtypes[fargs] = j2ffi((CALL)->calltype[i]);	\
+			argvals[fargs] = &((CALL)->args[i].i);		\
+			fargs++;					\
+			break;						\
+		case 2:							\
+			argtypes[fargs] = j2ffi((CALL)->calltype[i]);	\
+			argvals[fargs] = &((CALL)->args[i].j);		\
+			fargs++;					\
+		default:						\
+			break;						\
+		}							\
+	}								\
+	rtype = j2ffi ((CALL)->rettype);				\
+	if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, fargs,			\
+	    rtype, argtypes) == FFI_OK) {				\
+		ffi_call(&cif, (CALL)->function, (CALL)->ret, argvals);	\
+	}								\
+	else								\
+		ABORT();						\
+} while (0);
+#endif /* HAVE_LIBFFI */
 
 /*
  * Call a Java method from native code.
=== cut here ===



More information about the kaffe mailing list