+#ifdef USE_LIBFFI
+// We use a structure of this type to store the closure that
+// represents a missing method.
+struct method_closure
+{
+ // This field must come first, since the address of this field will
+ // be the same as the address of the overall structure. This is due
+ // to disabling interior pointers in the GC.
+ ffi_closure closure;
+ ffi_cif cif;
+ ffi_type *arg_types[1];
+};
+
+void *
+_Jv_Linker::create_error_method (_Jv_Utf8Const *class_name)
+{
+ method_closure *closure
+ = (method_closure *) _Jv_AllocBytes(sizeof (method_closure));
+
+ closure->arg_types[0] = &ffi_type_void;
+
+ // Initializes the cif and the closure. If that worked the closure
+ // is returned and can be used as a function pointer in a class'
+ // atable.
+ if ( ffi_prep_cif (&closure->cif,
+ FFI_DEFAULT_ABI,
+ 1,
+ &ffi_type_void,
+ closure->arg_types) == FFI_OK
+ && ffi_prep_closure (&closure->closure,
+ &closure->cif,
+ _Jv_ThrowNoClassDefFoundErrorTrampoline,
+ class_name) == FFI_OK)
+ return &closure->closure;
+ else
+ {
+ java::lang::StringBuffer *buffer = new java::lang::StringBuffer();
+ buffer->append(JvNewStringLatin1("Error setting up FFI closure"
+ " for static method of"
+ " missing class: "));
+ buffer->append (_Jv_NewStringUtf8Const(class_name));
+ throw new java::lang::InternalError(buffer->toString());
+ }
+}
+#else
+void *
+_Jv_Linker::create_error_method (_Jv_Utf8Const *)
+{
+ // Codepath for platforms which do not support (or want) libffi.
+ // You have to accept that it is impossible to provide the name
+ // of the missing class then.
+ return (void *) _Jv_ThrowNoClassDefFoundError;
+}
+#endif // USE_LIBFFI