2007-12-06 David Daney <ddaney@avtrex.com>
+ * include/ffi.h.in (FFI_SIZEOF_JAVA_RAW): Define if not already
+ defined.
+ (ffi_java_raw): New typedef.
+ (ffi_java_raw_call, ffi_java_ptrarray_to_raw,
+ ffi_java_raw_to_ptrarray): Change parameter types from ffi_raw to
+ ffi_java_raw.
+ (ffi_java_raw_closure) : Same.
+ (ffi_prep_java_raw_closure, ffi_prep_java_raw_closure_loc): Change
+ parameter types.
+ * src/java_raw_api.c (ffi_java_raw_size): Replace FFI_SIZEOF_ARG with
+ FFI_SIZEOF_JAVA_RAW.
+ (ffi_java_raw_to_ptrarray): Change type of raw to ffi_java_raw.
+ Replace FFI_SIZEOF_ARG with FFI_SIZEOF_JAVA_RAW. Use
+ sizeof(ffi_java_raw) for alignment calculations.
+ (ffi_java_ptrarray_to_raw): Same.
+ (ffi_java_rvalue_to_raw): Add special handling for FFI_TYPE_POINTER
+ if FFI_SIZEOF_JAVA_RAW == 4.
+ (ffi_java_raw_to_rvalue): Same.
+ (ffi_java_raw_call): Change type of raw to ffi_java_raw.
+ (ffi_java_translate_args): Same.
+ (ffi_prep_java_raw_closure_loc, ffi_prep_java_raw_closure): Change
+ parameter types.
+ * src/mips/ffitarget.h (FFI_SIZEOF_JAVA_RAW): Define for N32 ABI.
+
+2007-12-06 David Daney <ddaney@avtrex.com>
+
* src/mips/n32.S (ffi_closure_N32): Use 64-bit add instruction on
pointer values.
# endif
#endif
+#ifndef FFI_SIZEOF_JAVA_RAW
+# define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG
+#endif
+
typedef union {
ffi_sarg sint;
ffi_arg uint;
void* ptr;
} ffi_raw;
+#if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8
+/* This is a special case for mips64/n32 ABI (and perhaps others) where
+ sizeof(void *) is 4 and FFI_SIZEOF_ARG is 8. */
+typedef union {
+ signed int sint;
+ unsigned int uint;
+ float flt;
+ char data[FFI_SIZEOF_JAVA_RAW];
+ void* ptr;
+} ffi_java_raw;
+#else
+typedef ffi_raw ffi_java_raw;
+#endif
+
+
void ffi_raw_call (ffi_cif *cif,
void (*fn)(),
void *rvalue,
void ffi_java_raw_call (ffi_cif *cif,
void (*fn)(),
void *rvalue,
- ffi_raw *avalue);
+ ffi_java_raw *avalue);
-void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
-void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
+void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw);
+void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args);
size_t ffi_java_raw_size (ffi_cif *cif);
/* ---- Definitions for closures ----------------------------------------- */
} ffi_raw_closure;
+typedef struct {
+ char tramp[FFI_TRAMPOLINE_SIZE];
+
+ ffi_cif *cif;
+
+#if !FFI_NATIVE_RAW_API
+
+ /* if this is enabled, then a raw closure has the same layout
+ as a regular closure. We use this to install an intermediate
+ handler to do the transaltion, void** -> ffi_raw*. */
+
+ void (*translate_args)(ffi_cif*,void*,void**,void*);
+ void *this_closure;
+
+#endif
+
+ void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*);
+ void *user_data;
+
+} ffi_java_raw_closure;
+
ffi_status
ffi_prep_raw_closure (ffi_raw_closure*,
ffi_cif *cif,
void *codeloc);
ffi_status
-ffi_prep_java_raw_closure (ffi_raw_closure*,
+ffi_prep_java_raw_closure (ffi_java_raw_closure*,
ffi_cif *cif,
- void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
+ void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
void *user_data);
ffi_status
-ffi_prep_java_raw_closure_loc (ffi_raw_closure*,
+ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*,
ffi_cif *cif,
- void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
+ void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
void *user_data,
void *codeloc);
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
case FFI_TYPE_DOUBLE:
- result += 2 * FFI_SIZEOF_ARG;
+ result += 2 * FFI_SIZEOF_JAVA_RAW;
break;
case FFI_TYPE_STRUCT:
/* No structure parameters in Java. */
abort();
default:
- result += FFI_SIZEOF_ARG;
+ result += FFI_SIZEOF_JAVA_RAW;
}
}
void
-ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args)
+ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args)
{
unsigned i;
ffi_type **tp = cif->arg_types;
*args = (void*) ((char*)(raw++) + 2);
break;
-#if FFI_SIZEOF_ARG == 8
+#if FFI_SIZEOF_JAVA_RAW == 8
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
case FFI_TYPE_DOUBLE:
default:
*args = raw;
- raw += ALIGN ((*tp)->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
+ raw +=
+ ALIGN ((*tp)->size, sizeof(ffi_java_raw)) / sizeof(ffi_java_raw);
}
}
/* then assume little endian */
for (i = 0; i < cif->nargs; i++, tp++, args++)
{
-#if FFI_SIZEOF_ARG == 8
+#if FFI_SIZEOF_JAVA_RAW == 8
switch((*tp)->type) {
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
default:
*args = (void*) raw++;
}
-#else /* FFI_SIZEOF_ARG != 8 */
+#else /* FFI_SIZEOF_JAVA_RAW != 8 */
*args = (void*) raw;
- raw += ALIGN ((*tp)->size, sizeof (void*)) / sizeof (void*);
-#endif /* FFI_SIZEOF_ARG == 8 */
+ raw +=
+ ALIGN ((*tp)->size, sizeof(ffi_java_raw)) / sizeof(ffi_java_raw);
+#endif /* FFI_SIZEOF_JAVA_RAW == 8 */
}
#else
}
void
-ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw)
+ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw)
{
unsigned i;
ffi_type **tp = cif->arg_types;
(raw++)->flt = *(FLOAT32*) (*args);
break;
-#if FFI_SIZEOF_ARG == 8
+#if FFI_SIZEOF_JAVA_RAW == 8
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
case FFI_TYPE_DOUBLE:
break;
default:
-#if FFI_SIZEOF_ARG == 8
+#if FFI_SIZEOF_JAVA_RAW == 8
FFI_ASSERT(0); /* Should have covered all cases */
#else
memcpy ((void*) raw->data, (void*)*args, (*tp)->size);
- raw += ALIGN ((*tp)->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
+ raw +=
+ ALIGN ((*tp)->size, sizeof(ffi_java_raw)) / sizeof(ffi_java_raw);
#endif
}
}
case FFI_TYPE_SINT16:
case FFI_TYPE_SINT32:
case FFI_TYPE_INT:
+#if FFI_SIZEOF_JAVA_RAW == 4
+ case FFI_TYPE_POINTER:
+#endif
*(SINT64 *)rvalue <<= 32;
break;
case FFI_TYPE_SINT16:
case FFI_TYPE_SINT32:
case FFI_TYPE_INT:
+#if FFI_SIZEOF_JAVA_RAW == 4
+ case FFI_TYPE_POINTER:
+#endif
*(SINT64 *)rvalue >>= 32;
break;
* these following couple of functions will handle the translation forth
* and back automatically. */
-void ffi_java_raw_call (ffi_cif *cif, void (*fn)(), void *rvalue, ffi_raw *raw)
+void ffi_java_raw_call (ffi_cif *cif, void (*fn)(), void *rvalue,
+ ffi_java_raw *raw)
{
void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
ffi_java_raw_to_ptrarray (cif, raw, avalue);
ffi_java_translate_args (ffi_cif *cif, void *rvalue,
void **avalue, void *user_data)
{
- ffi_raw *raw = (ffi_raw*)alloca (ffi_java_raw_size (cif));
+ ffi_java_raw *raw = (ffi_java_raw*)alloca (ffi_java_raw_size (cif));
ffi_raw_closure *cl = (ffi_raw_closure*)user_data;
ffi_java_ptrarray_to_raw (cif, avalue, raw);
}
ffi_status
-ffi_prep_java_raw_closure_loc (ffi_raw_closure* cl,
+ffi_prep_java_raw_closure_loc (ffi_java_raw_closure* cl,
ffi_cif *cif,
- void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
+ void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
void *user_data,
void *codeloc)
{
* the pointer-array format, to the raw format */
ffi_status
-ffi_prep_java_raw_closure (ffi_raw_closure* cl,
+ffi_prep_java_raw_closure (ffi_java_raw_closure* cl,
ffi_cif *cif,
- void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
+ void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
void *user_data)
{
return ffi_prep_java_raw_closure_loc (cl, cif, fun, user_data, cl);
#ifdef FFI_MIPS_O32
/* O32 stack frames have 32bit integer args */
-#define FFI_SIZEOF_ARG 4
+# define FFI_SIZEOF_ARG 4
#else
/* N32 and N64 frames have 64bit integer args */
-#define FFI_SIZEOF_ARG 8
+# define FFI_SIZEOF_ARG 8
+# if _MIPS_SIM == _ABIN32
+# define FFI_SIZEOF_JAVA_RAW 4
+# endif
#endif
#define FFI_FLAG_BITS 2
+2007-12-06 David Daney <ddaney@avtrex.com>
+
+ * interpret.cc: Replace ffi_raw with INTERP_FFI_RAW_TYPE throughout.
+ (ncode_closure, ffi_closure_fun): Define versions for
+ non-FFI_NATIVE_RAW_API case.
+ * include/java-interp.h (INTERP_FFI_RAW_TYPE): Define and use to
+ replace ffi_raw throughout.
+ * jni.cc, interpret-run.cc: Replace ffi_raw with INTERP_FFI_RAW_TYPE
+ throughout.
+
2007-12-06 Andreas Tobler <a.tobler@schweiz.org>
* testsuite/libjava.jni/jni.exp (gcj_jni_get_cxxflags_invocation): Make
void *ncode (jclass);
void compile (const void * const *);
- static void run_normal (ffi_cif*, void*, ffi_raw*, void*);
- static void run_synch_object (ffi_cif*, void*, ffi_raw*, void*);
- static void run_class (ffi_cif*, void*, ffi_raw*, void*);
- static void run_synch_class (ffi_cif*, void*, ffi_raw*, void*);
-
- static void run_normal_debug (ffi_cif*, void*, ffi_raw*, void*);
- static void run_synch_object_debug (ffi_cif*, void*, ffi_raw*, void*);
- static void run_class_debug (ffi_cif*, void*, ffi_raw*, void*);
- static void run_synch_class_debug (ffi_cif*, void*, ffi_raw*, void*);
+#if FFI_NATIVE_RAW_API
+# define INTERP_FFI_RAW_TYPE ffi_raw
+#else
+# define INTERP_FFI_RAW_TYPE ffi_java_raw
+#endif
- static void run (void *, ffi_raw *, _Jv_InterpMethod *);
- static void run_debug (void *, ffi_raw *, _Jv_InterpMethod *);
+ static void run_normal (ffi_cif*, void*, INTERP_FFI_RAW_TYPE*, void*);
+ static void run_synch_object (ffi_cif*, void*, INTERP_FFI_RAW_TYPE*, void*);
+ static void run_class (ffi_cif*, void*, INTERP_FFI_RAW_TYPE*, void*);
+ static void run_synch_class (ffi_cif*, void*, INTERP_FFI_RAW_TYPE*, void*);
+
+ static void run_normal_debug (ffi_cif*, void*, INTERP_FFI_RAW_TYPE*, void*);
+ static void run_synch_object_debug (ffi_cif*, void*, INTERP_FFI_RAW_TYPE*,
+ void*);
+ static void run_class_debug (ffi_cif*, void*, INTERP_FFI_RAW_TYPE*, void*);
+ static void run_synch_class_debug (ffi_cif*, void*, INTERP_FFI_RAW_TYPE*,
+ void*);
+
+ static void run (void *, INTERP_FFI_RAW_TYPE *, _Jv_InterpMethod *);
+ static void run_debug (void *, INTERP_FFI_RAW_TYPE *, _Jv_InterpMethod *);
ffi_type **jni_arg_types;
// This function is used when making a JNI call from the interpreter.
- static void call (ffi_cif *, void *, ffi_raw *, void *);
+ static void call (ffi_cif *, void *, INTERP_FFI_RAW_TYPE *, void *);
void *ncode (jclass);
{
/* here goes the magic again... */
ffi_cif *cif = &rmeth->cif;
- ffi_raw *raw = (ffi_raw*) sp;
+ INTERP_FFI_RAW_TYPE *raw = (INTERP_FFI_RAW_TYPE *) sp;
_Jv_value rvalue;
void
_Jv_InterpMethod::run_normal (ffi_cif *,
void *ret,
- ffi_raw *args,
+ INTERP_FFI_RAW_TYPE *args,
void *__this)
{
_Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
void
_Jv_InterpMethod::run_normal_debug (ffi_cif *,
void *ret,
- ffi_raw *args,
+ INTERP_FFI_RAW_TYPE *args,
void *__this)
{
_Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
void
_Jv_InterpMethod::run_synch_object (ffi_cif *,
void *ret,
- ffi_raw *args,
+ INTERP_FFI_RAW_TYPE *args,
void *__this)
{
_Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
void
_Jv_InterpMethod::run_synch_object_debug (ffi_cif *,
void *ret,
- ffi_raw *args,
+ INTERP_FFI_RAW_TYPE *args,
void *__this)
{
_Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
void
_Jv_InterpMethod::run_class (ffi_cif *,
void *ret,
- ffi_raw *args,
+ INTERP_FFI_RAW_TYPE *args,
void *__this)
{
_Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
void
_Jv_InterpMethod::run_class_debug (ffi_cif *,
void *ret,
- ffi_raw *args,
+ INTERP_FFI_RAW_TYPE *args,
void *__this)
{
_Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
void
_Jv_InterpMethod::run_synch_class (ffi_cif *,
void *ret,
- ffi_raw *args,
+ INTERP_FFI_RAW_TYPE *args,
void *__this)
{
_Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
void
_Jv_InterpMethod::run_synch_class_debug (ffi_cif *,
void *ret,
- ffi_raw *args,
+ INTERP_FFI_RAW_TYPE *args,
void *__this)
{
_Jv_InterpMethod *_this = (_Jv_InterpMethod *) __this;
/* Run the given method.
When args is NULL, don't run anything -- just compile it. */
void
-_Jv_InterpMethod::run (void *retp, ffi_raw *args, _Jv_InterpMethod *meth)
+_Jv_InterpMethod::run (void *retp, INTERP_FFI_RAW_TYPE *args,
+ _Jv_InterpMethod *meth)
{
#undef DEBUG
#undef DEBUG_LOCALS_INSN
}
void
-_Jv_InterpMethod::run_debug (void *retp, ffi_raw *args, _Jv_InterpMethod *meth)
+_Jv_InterpMethod::run_debug (void *retp, INTERP_FFI_RAW_TYPE *args,
+ _Jv_InterpMethod *meth)
{
#define DEBUG
#undef DEBUG_LOCALS_INSN
return item_count;
}
-#if FFI_NATIVE_RAW_API
-# define FFI_PREP_RAW_CLOSURE ffi_prep_raw_closure_loc
-# define FFI_RAW_SIZE ffi_raw_size
-#else
-# define FFI_PREP_RAW_CLOSURE ffi_prep_java_raw_closure_loc
-# define FFI_RAW_SIZE ffi_java_raw_size
-#endif
-
/* we put this one here, and not in interpret.cc because it
* calls the utility routines _Jv_count_arguments
* which are static to this module. The following struct defines the
* layout we use for the stubs, it's only used in the ncode method. */
+#if FFI_NATIVE_RAW_API
+# define FFI_PREP_RAW_CLOSURE ffi_prep_raw_closure_loc
+# define FFI_RAW_SIZE ffi_raw_size
typedef struct {
ffi_raw_closure closure;
_Jv_ClosureList list;
ffi_cif cif;
ffi_type *arg_types[0];
} ncode_closure;
-
-typedef void (*ffi_closure_fun) (ffi_cif*,void*,ffi_raw*,void*);
+typedef void (*ffi_closure_fun) (ffi_cif*,void*,INTERP_FFI_RAW_TYPE*,void*);
+#else
+# define FFI_PREP_RAW_CLOSURE ffi_prep_java_raw_closure_loc
+# define FFI_RAW_SIZE ffi_java_raw_size
+typedef struct {
+ ffi_java_raw_closure closure;
+ _Jv_ClosureList list;
+ ffi_cif cif;
+ ffi_type *arg_types[0];
+} ncode_closure;
+typedef void (*ffi_closure_fun) (ffi_cif*,void*,ffi_java_raw*,void*);
+#endif
void *
_Jv_InterpMethod::ncode (jclass klass)
// This function is the stub which is used to turn an ordinary (CNI)
// method call into a JNI call.
void
-_Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this)
+_Jv_JNIMethod::call (ffi_cif *, void *ret, INTERP_FFI_RAW_TYPE *args,
+ void *__this)
{
_Jv_JNIMethod* _this = (_Jv_JNIMethod *) __this;
}
}
- JvAssert (_this->args_raw_size % sizeof (ffi_raw) == 0);
- ffi_raw real_args[2 + _this->args_raw_size / sizeof (ffi_raw)];
+ JvAssert (_this->args_raw_size % sizeof (INTERP_FFI_RAW_TYPE) == 0);
+ INTERP_FFI_RAW_TYPE
+ real_args[2 + _this->args_raw_size / sizeof (INTERP_FFI_RAW_TYPE)];
int offset = 0;
// First argument is always the environment pointer.