[llvm-commits] CVS: llvm-java/runtime/runtime.h jni.c
Alkis Evlogimenos
alkis at cs.uiuc.edu
Sat Apr 2 17:12:17 PST 2005
Changes in directory llvm-java/runtime:
runtime.h updated: 1.2 -> 1.3
jni.c updated: 1.1 -> 1.2
---
Log message:
Implement GetFieldId, Get<Type>Field, Set<Type>Field JNI functions.
---
Diffs of the changes: (+66 -19)
jni.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++----------------
runtime.h | 9 +++++++
2 files changed, 66 insertions(+), 19 deletions(-)
Index: llvm-java/runtime/runtime.h
diff -u llvm-java/runtime/runtime.h:1.2 llvm-java/runtime/runtime.h:1.3
--- llvm-java/runtime/runtime.h:1.2 Sat Apr 2 14:02:55 2005
+++ llvm-java/runtime/runtime.h Sat Apr 2 19:12:05 2005
@@ -47,6 +47,15 @@
/* If an array the size of its elements, otherwise 0 for classes, -1
* for interfaces and -2 for primitive classes. */
jint elementSize;
+
+ /* A null terminated array of strings describing the fields of this
+ * class. A field description is the concatenation of its name with
+ * its descriptor. */
+ const char** fieldDescriptors;
+
+ /* An array of offsets to fields. This is indexed the same way as
+ * the field descriptor array. */
+ jfieldID* fieldOffsets;
};
struct llvm_java_class_record {
Index: llvm-java/runtime/jni.c
diff -u llvm-java/runtime/jni.c:1.1 llvm-java/runtime/jni.c:1.2
--- llvm-java/runtime/jni.c:1.1 Sat Apr 2 14:17:41 2005
+++ llvm-java/runtime/jni.c Sat Apr 2 19:12:05 2005
@@ -25,6 +25,44 @@
return llvm_java_is_instance_of(obj, GET_CLASS_RECORD(c));
}
+static jfieldID get_fieldid(JNIEnv *env,
+ jclass clazz,
+ const char *name,
+ const char *sig) {
+ int nameLength;
+ int i;
+ const char* fieldDescriptor;
+ struct llvm_java_class_record* cr = GET_CLASS_RECORD(clazz);
+
+ /* lookup the name+sig in the fieldDescriptors array and retrieve
+ * the offset of the field */
+ nameLength = strlen(name);
+ for (i = 0; (fieldDescriptor = cr->typeinfo.fieldDescriptors[i]); ++i)
+ if (strncmp(name, fieldDescriptor, nameLength) == 0 &&
+ strcmp(sig, fieldDescriptor+nameLength) == 0)
+ return cr->typeinfo.fieldOffsets[i];
+
+ return 0;
+}
+
+#define HANDLE_TYPE(TYPE) \
+ static j##TYPE get_##TYPE##_field(JNIEnv* env, \
+ jobject obj, \
+ jfieldID fid) { \
+ return *(j##TYPE*) (((char*)obj) + fid); \
+ }
+#include "types.def"
+
+#define HANDLE_TYPE(TYPE) \
+ static void set_##TYPE##_field(JNIEnv* env, \
+ jobject obj, \
+ jfieldID fid, \
+ j##TYPE value) { \
+ *(j##TYPE*) (((char*)obj) + fid) = value; \
+ }
+#include "types.def"
+
+
static jint get_array_length(JNIEnv* env, jarray array) {
return ((struct llvm_java_booleanarray*) array)->length;
}
@@ -153,25 +191,25 @@
NULL,
NULL,
NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 100 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 110 */
- NULL,
- NULL,
+ &get_fieldid,
+ &get_object_field,
+ &get_boolean_field,
+ &get_byte_field,
+ &get_char_field,
+ &get_short_field,
+ &get_int_field,
+ &get_long_field,
+ &get_float_field,
+ &get_double_field,
+ &set_object_field,
+ &set_boolean_field,
+ &set_byte_field,
+ &set_char_field,
+ &set_short_field,
+ &set_int_field,
+ &set_long_field,
+ &set_float_field,
+ &set_double_field,
NULL,
NULL,
NULL,
More information about the llvm-commits
mailing list