[jffi-next] 33/49: On i386 and x86_64, calculate whether a function is fast-int or fast-long capable and store it in the function/call context.
Tim Potter
tpot-guest at moszumanska.debian.org
Wed Mar 4 04:51:13 UTC 2015
This is an automated email from the git hooks/post-receive script.
tpot-guest pushed a commit to annotated tag upstream/1.0.10
in repository jffi-next.
commit 0fd45eea9b230ef9bc3870025680bdc32b02ac33
Author: Wayne Meissner <wmeissner at gmail.com>
Date: Sat Apr 23 15:26:26 2011 +1000
On i386 and x86_64, calculate whether a function is fast-int or fast-long capable and store it in the function/call context.
---
jni/jffi/CallContext.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++
jni/jffi/CallContext.h | 3 +++
jni/jffi/Function.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
jni/jffi/Function.h | 2 ++
4 files changed, 146 insertions(+)
diff --git a/jni/jffi/CallContext.c b/jni/jffi/CallContext.c
index 3570cc6..bfb56f7 100644
--- a/jni/jffi/CallContext.c
+++ b/jni/jffi/CallContext.c
@@ -92,6 +92,44 @@ Java_com_kenai_jffi_Foreign_newCallContext(JNIEnv* env, jobject self,
paramTypes = alloca(paramCount * sizeof(jlong));
(*env)->GetLongArrayRegion(env, paramArray, 0, paramCount, paramTypes);
+#if defined(__i386__) || defined(__x86_64__)
+ ctx->isFastInt = true;
+ ctx->isFastLong = true;
+
+ switch (((ffi_type *) j2p(returnType))->type) {
+ case FFI_TYPE_INT:
+ case FFI_TYPE_SINT8:
+ case FFI_TYPE_UINT8:
+ case FFI_TYPE_SINT16:
+ case FFI_TYPE_UINT16:
+ case FFI_TYPE_SINT32:
+ case FFI_TYPE_UINT32:
+#if defined(__i386__)
+ case FFI_TYPE_POINTER:
+#endif
+#if !defined(__x86_64__)
+ ctx->isFastLong = false;
+#endif
+ break;
+
+ case FFI_TYPE_SINT64:
+ case FFI_TYPE_UINT64:
+#if defined(__x86_64__)
+ case FFI_TYPE_POINTER:
+#endif
+ ctx->isFastInt = false;
+ break;
+
+ case FFI_TYPE_VOID:
+ break;
+
+ default:
+ ctx->isFastInt = false;
+ ctx->isFastLong = false;
+ break;
+ }
+#endif
+
for (i = 0; i < paramCount; ++i) {
ffi_type* type = (ffi_type *) j2p(paramTypes[i]);
if (type == NULL) {
@@ -101,6 +139,38 @@ Java_com_kenai_jffi_Foreign_newCallContext(JNIEnv* env, jobject self,
ctx->ffiParamTypes[i] = type;
ctx->rawParamOffsets[i] = rawOffset;
rawOffset += FFI_ALIGN(type->size, FFI_SIZEOF_ARG);
+#if defined(__i386__) || defined(__x86_64__)
+ switch (type->type) {
+ case FFI_TYPE_INT:
+ case FFI_TYPE_SINT8:
+ case FFI_TYPE_UINT8:
+ case FFI_TYPE_SINT16:
+ case FFI_TYPE_UINT16:
+ case FFI_TYPE_SINT32:
+ case FFI_TYPE_UINT32:
+#if defined(__i386__)
+ case FFI_TYPE_POINTER:
+#endif
+
+#if !defined(__x86_64__)
+ ctx->isFastLong = false;
+#endif
+ break;
+
+ case FFI_TYPE_SINT64:
+ case FFI_TYPE_UINT64:
+#if defined(__x86_64__)
+ case FFI_TYPE_POINTER:
+#endif
+ ctx->isFastInt = false;
+ break;
+
+ default:
+ ctx->isFastInt = false;
+ ctx->isFastLong = false;
+ break;
+ }
+#endif
}
// On win32, we might need to set the abi to stdcall - but win64 only supports cdecl/default
diff --git a/jni/jffi/CallContext.h b/jni/jffi/CallContext.h
index 897d8b7..55cfaa7 100644
--- a/jni/jffi/CallContext.h
+++ b/jni/jffi/CallContext.h
@@ -42,6 +42,9 @@ typedef struct CallContext {
ffi_type** ffiParamTypes;
int* rawParamOffsets;
bool saveErrno;
+ void* reserved0; // Function address - just used to pad this struct to match Function
+ bool isFastInt;
+ bool isFastLong;
} CallContext;
#endif /* JFFI_CALLCONTEXT_H */
diff --git a/jni/jffi/Function.c b/jni/jffi/Function.c
index b7d7595..6d7588e 100644
--- a/jni/jffi/Function.c
+++ b/jni/jffi/Function.c
@@ -92,6 +92,44 @@ Java_com_kenai_jffi_Foreign_newFunction(JNIEnv* env, jobject self,
paramTypes = alloca(paramCount * sizeof(jlong));
(*env)->GetLongArrayRegion(env, paramArray, 0, paramCount, paramTypes);
+#if defined(__i386__) || defined(__x86_64__)
+ ctx->isFastInt = true;
+ ctx->isFastLong = true;
+
+ switch (((ffi_type *) j2p(returnType))->type) {
+ case FFI_TYPE_INT:
+ case FFI_TYPE_SINT8:
+ case FFI_TYPE_UINT8:
+ case FFI_TYPE_SINT16:
+ case FFI_TYPE_UINT16:
+ case FFI_TYPE_SINT32:
+ case FFI_TYPE_UINT32:
+#if defined(__i386__)
+ case FFI_TYPE_POINTER:
+#endif
+#if !defined(__x86_64__)
+ ctx->isFastLong = false;
+#endif
+ break;
+
+ case FFI_TYPE_SINT64:
+ case FFI_TYPE_UINT64:
+#if defined(__x86_64__)
+ case FFI_TYPE_POINTER:
+#endif
+ ctx->isFastInt = false;
+ break;
+
+ case FFI_TYPE_VOID:
+ break;
+
+ default:
+ ctx->isFastInt = false;
+ ctx->isFastLong = false;
+ break;
+ }
+#endif
+
for (i = 0; i < paramCount; ++i) {
ffi_type* type = (ffi_type *) j2p(paramTypes[i]);
if (type == NULL) {
@@ -101,6 +139,39 @@ Java_com_kenai_jffi_Foreign_newFunction(JNIEnv* env, jobject self,
ctx->ffiParamTypes[i] = type;
ctx->rawParamOffsets[i] = rawOffset;
rawOffset += FFI_ALIGN(type->size, FFI_SIZEOF_ARG);
+
+#if defined(__i386__) || defined(__x86_64__)
+ switch (type->type) {
+ case FFI_TYPE_INT:
+ case FFI_TYPE_SINT8:
+ case FFI_TYPE_UINT8:
+ case FFI_TYPE_SINT16:
+ case FFI_TYPE_UINT16:
+ case FFI_TYPE_SINT32:
+ case FFI_TYPE_UINT32:
+#if defined(__i386__)
+ case FFI_TYPE_POINTER:
+#endif
+
+#if !defined(__x86_64__)
+ ctx->isFastLong = false;
+#endif
+ break;
+
+ case FFI_TYPE_SINT64:
+ case FFI_TYPE_UINT64:
+#if defined(__x86_64__)
+ case FFI_TYPE_POINTER:
+#endif
+ ctx->isFastInt = false;
+ break;
+
+ default:
+ ctx->isFastInt = false;
+ ctx->isFastLong = false;
+ break;
+ }
+#endif
}
// On win32, we might need to set the abi to stdcall - but win64 only supports cdecl/default
diff --git a/jni/jffi/Function.h b/jni/jffi/Function.h
index 3213564..2ccf64a 100644
--- a/jni/jffi/Function.h
+++ b/jni/jffi/Function.h
@@ -43,6 +43,8 @@ typedef struct Function {
int* rawParamOffsets;
bool saveErrno;
void* function;
+ bool isFastInt;
+ bool isFastLong;
} Function;
#define SAVE_ERRNO(ctx) do { \
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jffi-next.git
More information about the pkg-java-commits
mailing list