[llvm-commits] CVS: llvm-java/runtime/runtime.h jni.c
Alkis Evlogimenos
alkis at cs.uiuc.edu
Sat Apr 2 18:49:56 PST 2005
Changes in directory llvm-java/runtime:
runtime.h updated: 1.3 -> 1.4
jni.c updated: 1.2 -> 1.3
---
Log message:
Implement get/set static field for JNI.
---
Diffs of the changes: (+70 -22)
jni.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++----------------
runtime.h | 15 +++++++++---
2 files changed, 70 insertions(+), 22 deletions(-)
Index: llvm-java/runtime/runtime.h
diff -u llvm-java/runtime/runtime.h:1.3 llvm-java/runtime/runtime.h:1.4
--- llvm-java/runtime/runtime.h:1.3 Sat Apr 2 19:12:05 2005
+++ llvm-java/runtime/runtime.h Sat Apr 2 20:49:44 2005
@@ -48,14 +48,23 @@
* 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. */
+ /* A null terminated array of strings describing the member 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;
+
+ /* 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
+ * same way as the static field descriptor array. */
+ void** staticFields;
};
struct llvm_java_class_record {
Index: llvm-java/runtime/jni.c
diff -u llvm-java/runtime/jni.c:1.2 llvm-java/runtime/jni.c:1.3
--- llvm-java/runtime/jni.c:1.2 Sat Apr 2 19:12:05 2005
+++ llvm-java/runtime/jni.c Sat Apr 2 20:49:44 2005
@@ -45,6 +45,45 @@
return 0;
}
+static jfieldID get_static_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 staticFieldDescriptors array and
+ * retrieve the index of the field */
+ nameLength = strlen(name);
+ for (i = 0; (fieldDescriptor = cr->typeinfo.staticFieldDescriptors[i]); ++i)
+ if (strncmp(name, fieldDescriptor, nameLength) == 0 &&
+ strcmp(sig, fieldDescriptor+nameLength) == 0)
+ return i;
+
+ return 0;
+}
+
+#define HANDLE_TYPE(TYPE) \
+ static j##TYPE get_static_##TYPE##_field(JNIEnv* env, \
+ jclass clazz, \
+ jfieldID fid) { \
+ struct llvm_java_class_record* cr = GET_CLASS_RECORD(clazz); \
+ return *(j##TYPE*) cr->typeinfo.staticFields[fid]; \
+ }
+#include "types.def"
+
+#define HANDLE_TYPE(TYPE) \
+ static void set_static_##TYPE##_field(JNIEnv* env, \
+ jclass clazz, \
+ jfieldID fid, \
+ j##TYPE value) { \
+ struct llvm_java_class_record* cr = GET_CLASS_RECORD(clazz); \
+ *(j##TYPE*) cr->typeinfo.staticFields[fid] = value; \
+ }
+#include "types.def"
+
#define HANDLE_TYPE(TYPE) \
static j##TYPE get_##TYPE##_field(JNIEnv* env, \
jobject obj, \
@@ -241,25 +280,25 @@
NULL,
NULL,
NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 150 */
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, /* 160 */
- NULL,
- NULL,
+ &get_static_fieldid,
+ &get_static_object_field,
+ &get_static_boolean_field,
+ &get_static_byte_field,
+ &get_static_char_field,
+ &get_static_short_field,
+ &get_static_int_field,
+ &get_static_long_field,
+ &get_static_float_field,
+ &get_static_double_field,
+ &set_static_object_field,
+ &set_static_boolean_field,
+ &set_static_byte_field,
+ &set_static_char_field,
+ &set_static_short_field,
+ &set_static_int_field,
+ &set_static_long_field,
+ &set_static_float_field,
+ &set_static_double_field,
NULL,
NULL,
NULL,
More information about the llvm-commits
mailing list