jni and static libgcj and friends? (Finally success!)

Martin Kahlert martin.kahlert@infineon.com
Fri Mar 8 06:51:00 GMT 2002


Hi Alexandre and Jeff!
Thanks a lot for all your help.
To make that all work was a bit more effort than i thought.
It is *not* enough to add -prefer-pic to the --mode=compile commands
in libjava but in all needed packages (boehm-gc, zlib, libffi...).
I finally put it into every Makefile.in i found.
Then the only way to make that work was with --disable-shared
When i tried --enable-shared=libstdc++ instead, something went amok:
Error messages were like this: no rule to make target java/i
Seems like some sed scripts would need improvements here.
In order to make my application work correctly on Solaris i used the appended patch.
(Originally from the mailing list but i had to update it for void support)
How is the libffi issue handled, now? I saw Tom suggested some fix and probably
did something in libffi, but does it work now?
gcc-20020218 was the last snapshot, which worked for me. So i cannot tell
about the actual state.
Thanks a lot again,
Martin.
diff -ur gcc-20020218.old/libjava/java/lang/reflect/natMethod.cc gcc-20020218/libjava/java/lang/reflect/natMethod.cc
--- gcc-20020218.old/libjava/java/lang/reflect/natMethod.cc	Tue Jan 8 21:00:50 2002
+++ gcc-20020218/libjava/java/lang/reflect/natMethod.cc	Tue Feb 19 11:51:27 2002
@@ -145,6 +145,39 @@
 
 return r;
 }
+
+static inline ffi_type *
+get_ffi_return_type (jclass klass)
+{
+ // A special case.
+ if (klass == NULL)
+ return &ffi_type_pointer;
+
+ ffi_type *r;
+ if (klass == JvPrimClass (byte))
+ r = &ffi_type_sint32;
+ else if (klass == JvPrimClass (short))
+ r = &ffi_type_sint32;
+ else if (klass == JvPrimClass (int))
+ r = &ffi_type_sint32;
+ else if (klass == JvPrimClass (long))
+ r = &ffi_type_sint64;
+ else if (klass == JvPrimClass (float))
+ r = &ffi_type_float;
+ else if (klass == JvPrimClass (double))
+ r = &ffi_type_double;
+ else if (klass == JvPrimClass (boolean))
+ r = &ffi_type_sint32;
+ else if (klass == JvPrimClass (char))
+ r = &ffi_type_uint32;
+ else
+ {
+ JvAssert (! klass->isPrimitive());
+ r = &ffi_type_pointer;
+ }
+
+ return r;
+}
 #endif // USE_LIBFFI
 
 jobject
@@ -343,7 +376,9 @@
 if (is_constructor || return_type == JvPrimClass (void))
 rtype = &ffi_type_void;
 else
- rtype = get_ffi_type (return_type);
+ // Return type must be at least one word, so get_ffi_return_type
+ // guarantees this.
+ rtype = get_ffi_return_type (return_type);
 ffi_type **argtypes = (ffi_type **) __builtin_alloca (param_count
 							* sizeof (ffi_type *));
 
@@ -416,6 +451,8 @@
 p += tsize;
 }
 
+ jvalue result_word;
+
 // FIXME: initialize class here.
 
 using namespace java::lang;
@@ -425,7 +462,7 @@
 
 try
 {
- ffi_call (&cif, (void (*)()) meth->ncode, result, values);
+ ffi_call (&cif, (void (*)()) meth->ncode, &result_word, values);
 }
 catch (Throwable *ex2)
 {
@@ -436,8 +473,20 @@
 ex = new InvocationTargetException (ex2);
 }
 
+ // Handle return type. Constructor return values are faked, and
+ // subword return types must be narrowed to the proper jvalue element.
 if (is_constructor)
 result->l = obj;
+ else if (return_type == JvPrimClass (byte))
+ result->b = (jbyte)result_word.i;
+ else if (return_type == JvPrimClass (short))
+ result->s = (jshort)result_word.i;
+ else if (return_type == JvPrimClass (boolean))
+ result->z = (jboolean)result_word.i;
+ else if (return_type == JvPrimClass (char))
+ result->c = (jchar)result_word.i;
+ else if (return_type != JvPrimClass(void))
+ memcpy (result, &result_word, sizeof (jvalue));
 
 return ex;
 #else
-- 
The early bird catches the worm. If you want something else for 
breakfast, get up later.


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /