[llvm-commits] CVS: llvm-java/runtime/runtime.h jni.c
Alkis Evlogimenos
alkis at cs.uiuc.edu
Fri Apr 22 17:12:25 PDT 2005
Changes in directory llvm-java/runtime:
runtime.h updated: 1.7 -> 1.8
jni.c updated: 1.6 -> 1.7
---
Log message:
Implement calls to java methods (both static and dynamic) from JNI
code.
---
Diffs of the changes: (+196 -42)
jni.c | 216 ++++++++++++++++++++++++++++++++++++++++++++++++++------------
runtime.h | 22 +++++-
2 files changed, 196 insertions(+), 42 deletions(-)
Index: llvm-java/runtime/runtime.h
diff -u llvm-java/runtime/runtime.h:1.7 llvm-java/runtime/runtime.h:1.8
--- llvm-java/runtime/runtime.h:1.7 Fri Apr 22 18:43:35 2005
+++ llvm-java/runtime/runtime.h Fri Apr 22 19:12:14 2005
@@ -55,16 +55,34 @@
/* An array of offsets to fields. This is indexed the same way as
* the field descriptor array. */
- jfieldID* fieldOffsets;
+ unsigned* fieldOffsets;
/* A null terminated array of strings describing the static fields
* of this class. A field description is the concatenation of its
* name with its descriptor. */
const char** staticFieldDescriptors;
- /* An array of pointers to static fields. This is the indexed the
+ /* An array of pointers to static fields. This is indexed the
* same way as the static field descriptor array. */
void** staticFields;
+
+ /* A null terminated array of strings describing the dynamic methods
+ of this class. A method descriptor is the concatenation of its
+ name with its descriptor. */
+ const char** methodDescriptors;
+
+ /* An array of pointers to bridge functions. This is indexed the
+ * same way as the dynamic method descriptor array. */
+ void** methodBridges;
+
+ /* A null terminated array of strings describing the static methods
+ of this class. A method descriptor is the concatenation of its
+ name with its descriptor. */
+ const char** staticMethodDescriptors;
+
+ /* An array of pointers to bridge functions. This is indexed the
+ * same way as the static method descriptor array. */
+ void** staticMethodBridges;
};
struct llvm_java_class_record {
Index: llvm-java/runtime/jni.c
diff -u llvm-java/runtime/jni.c:1.6 llvm-java/runtime/jni.c:1.7
--- llvm-java/runtime/jni.c:1.6 Sun Apr 3 18:12:43 2005
+++ llvm-java/runtime/jni.c Fri Apr 22 19:12:14 2005
@@ -84,6 +84,74 @@
/* Calling instance methods */
+static jmethodID get_methodid(JNIEnv *env,
+ jclass clazz,
+ const char *name,
+ const char *sig) {
+ int nameLength;
+ int i;
+ const char* methodDescriptor;
+ struct llvm_java_class_record* cr = GET_CLASS_RECORD(clazz);
+
+ /* lookup the name+sig in the staticFieldDescriptors array and
+ * retrieve the index of the field */
+ nameLength = strlen(name);
+ for (i = 0; (methodDescriptor = cr->typeinfo.methodDescriptors[i]); ++i)
+ if (strncmp(name, methodDescriptor, nameLength) == 0 &&
+ strcmp(sig, methodDescriptor+nameLength) == 0)
+ return i;
+
+ return 0;
+}
+
+static void call_void_method_v(JNIEnv* env,
+ jobject obj,
+ jmethodID methodID,
+ va_list args) {
+ typedef void (*BridgeFunPtr)(jobject obj, va_list);
+ struct llvm_java_class_record* cr = llvm_java_get_class_record(obj);
+
+ BridgeFunPtr f = (BridgeFunPtr) cr->typeinfo.methodBridges[methodID];
+ f(obj, args);
+}
+
+static void call_void_method(JNIEnv* env,
+ jobject obj,
+ jmethodID methodID,
+ ...) {
+ va_list args;
+ va_start(args, methodID);
+ call_void_method_v(env, obj, methodID, args);
+ va_end(args);
+}
+
+#define HANDLE_TYPE(TYPE) \
+ static j##TYPE call_##TYPE##_method_v(JNIEnv* env, \
+ jobject obj, \
+ jmethodID methodID, \
+ va_list args) { \
+ typedef j##TYPE (*BridgeFunPtr)(jobject obj, va_list); \
+ struct llvm_java_class_record* cr = llvm_java_get_class_record(obj); \
+ BridgeFunPtr f = \
+ (BridgeFunPtr) cr->typeinfo.methodBridges[methodID]; \
+ return f(obj, args); \
+ }
+#include "types.def"
+
+#define HANDLE_TYPE(TYPE) \
+ static j##TYPE call_##TYPE##_method(JNIEnv* env, \
+ jobject obj, \
+ jmethodID methodID, \
+ ...) { \
+ va_list args; \
+ va_start(args, methodID); \
+ j##TYPE result = \
+ call_##TYPE##_method_v(env, obj, methodID, args); \
+ va_end(args); \
+ return result; \
+ }
+#include "types.def"
+
/* Accessing static fields */
static jfieldID get_static_fieldid(JNIEnv *env,
@@ -127,6 +195,74 @@
/* Calling static methods */
+static jmethodID get_static_methodid(JNIEnv *env,
+ jclass clazz,
+ const char *name,
+ const char *sig) {
+ int nameLength;
+ int i;
+ const char* methodDescriptor;
+ struct llvm_java_class_record* cr = GET_CLASS_RECORD(clazz);
+
+ /* lookup the name+sig in the staticFieldDescriptors array and
+ * retrieve the index of the field */
+ nameLength = strlen(name);
+ for (i = 0; (methodDescriptor = cr->typeinfo.staticMethodDescriptors[i]); ++i)
+ if (strncmp(name, methodDescriptor, nameLength) == 0 &&
+ strcmp(sig, methodDescriptor+nameLength) == 0)
+ return i;
+
+ return 0;
+}
+
+static void call_static_void_method_v(JNIEnv* env,
+ jclass clazz,
+ jmethodID methodID,
+ va_list args) {
+ typedef void (*BridgeFunPtr)(jclass clazz, va_list);
+ struct llvm_java_class_record* cr = GET_CLASS_RECORD(clazz);
+
+ BridgeFunPtr f = (BridgeFunPtr) cr->typeinfo.staticMethodBridges[methodID];
+ f(clazz, args);
+}
+
+static void call_static_void_method(JNIEnv* env,
+ jclass clazz,
+ jmethodID methodID,
+ ...) {
+ va_list args;
+ va_start(args, methodID);
+ call_static_void_method_v(env, clazz, methodID, args);
+ va_end(args);
+}
+
+#define HANDLE_TYPE(TYPE) \
+ static j##TYPE call_static_##TYPE##_method_v(JNIEnv* env, \
+ jclass clazz, \
+ jmethodID methodID, \
+ va_list args) { \
+ typedef j##TYPE (*BridgeFunPtr)(jclass clazz, va_list); \
+ struct llvm_java_class_record* cr = GET_CLASS_RECORD(clazz); \
+ BridgeFunPtr f = \
+ (BridgeFunPtr) cr->typeinfo.staticMethodBridges[methodID]; \
+ return f(clazz, args); \
+ }
+#include "types.def"
+
+#define HANDLE_TYPE(TYPE) \
+ static j##TYPE call_static_##TYPE##_method(JNIEnv* env, \
+ jclass clazz, \
+ jmethodID methodID, \
+ ...) { \
+ va_list args; \
+ va_start(args, methodID); \
+ j##TYPE result = \
+ call_static_##TYPE##_method_v(env, clazz, methodID, args); \
+ va_end(args); \
+ return result; \
+ }
+#include "types.def"
+
/* String operations */
/* Array operations */
@@ -219,36 +355,36 @@
NULL, /* 30 */
&get_object_class,
&is_instance_of,
+ &get_methodid,
+ &call_object_method,
+ &call_object_method_v,
NULL,
+ &call_boolean_method,
+ &call_boolean_method_v,
NULL,
+ &call_byte_method,
+ &call_byte_method_v,
NULL,
+ &call_char_method,
+ &call_char_method_v,
NULL,
+ &call_short_method,
+ &call_short_method_v,
NULL,
+ &call_int_method,
+ &call_int_method_v,
NULL,
+ &call_long_method,
+ &call_long_method_v,
NULL,
- NULL, /* 40 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 50 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
+ &call_float_method,
+ &call_float_method_v,
NULL,
+ &call_double_method,
+ &call_double_method_v,
NULL, /* 60 */
- NULL,
- NULL,
+ &call_void_method,
+ &call_void_method_v,
NULL,
NULL,
NULL,
@@ -299,33 +435,33 @@
&set_long_field,
&set_float_field,
&set_double_field,
+ &get_static_methodid,
+ &call_static_object_method,
+ &call_static_object_method_v,
NULL,
+ &call_static_boolean_method,
+ &call_static_boolean_method_v,
NULL,
+ &call_static_byte_method,
+ &call_static_byte_method_v,
NULL,
+ &call_static_char_method,
+ &call_static_char_method_v,
NULL,
+ &call_static_short_method,
+ &call_static_short_method_v,
NULL,
+ &call_static_int_method,
+ &call_static_int_method_v,
NULL,
+ &call_static_long_method,
+ &call_static_long_method_v,
NULL,
- NULL, /* 120 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 130 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
+ &call_static_float_method,
+ &call_static_float_method_v,
NULL,
+ &call_static_double_method,
+ &call_static_double_method_v,
NULL, /* 140 */
NULL,
NULL,
More information about the llvm-commits
mailing list