This way we can reuse one implementation for field getter and setter.

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/vm/object.h |  204 ++++++++++++++++++---------------------------------
 jit/trace-jit.c     |    2 +-
 vm/jato.c           |    4 +-
 vm/jni-interface.c  |    4 +-
 vm/object.c         |   12 ++--
 vm/reflection.c     |   17 ++---
 vm/stack-trace.c    |    4 +-
 vm/thread.c         |    8 +-
 8 files changed, 94 insertions(+), 161 deletions(-)

diff --git a/include/vm/object.h b/include/vm/object.h
index e707d35..27c5258 100644
--- a/include/vm/object.h
+++ b/include/vm/object.h
@@ -90,148 +90,86 @@ int vm_monitor_notify_all(struct vm_monitor *mon);
 struct vm_thread *vm_monitor_get_owner(struct vm_monitor *mon);
 void vm_monitor_set_owner(struct vm_monitor *mon, struct vm_thread *owner);
 
-static inline void
-field_set_int32(struct vm_object *obj, const struct vm_field *field, int32_t 
value)
-{
-       *(int32_t *) &obj->fields[field->offset] = value;
-}
-
-static inline int32_t
-field_get_int32(const struct vm_object *obj, const struct vm_field *field)
-{
-       return *(int32_t *) &obj->fields[field->offset];
-}
-
-static inline void
-field_set_int64(struct vm_object *obj, const struct vm_field *field, int64_t 
value)
-{
-       *(int64_t *) &obj->fields[field->offset] = value;
-}
-
-static inline int64_t
-field_get_int64(const struct vm_object *obj, const struct vm_field *field)
-{
-       return *(int64_t *) &obj->fields[field->offset];
-}
-
-static inline void
-field_set_object(struct vm_object *obj, const struct vm_field *field, struct 
vm_object *value)
-{
-       *(void **) &obj->fields[field->offset] = value;
-}
-
-static inline struct vm_object *
-field_get_object(const struct vm_object *obj, const struct vm_field *field)
-{
-       return *(struct vm_object **) &obj->fields[field->offset];
-}
-
-static inline void
-array_set_field_char(struct vm_object *obj, int index, uint16_t value)
-{
-       *(uint16_t *) &obj->fields[index * get_vmtype_size(J_CHAR)] = value;
-}
-
-static inline uint16_t
-array_get_field_char(struct vm_object *obj, int index)
-{
-       return *(uint16_t *) &obj->fields[index * get_vmtype_size(J_CHAR)];
-}
-
-static inline uint8_t
-array_get_field_byte(struct vm_object *obj, int index)
-{
-       return *(uint8_t *) &obj->fields[index * get_vmtype_size(J_BYTE)];
-}
-
-static inline void
-array_set_field_byte(struct vm_object *obj, int index, uint8_t value)
-{
-       *(uint8_t *) &obj->fields[index * get_vmtype_size(J_BYTE)] = value;
-}
-
-static inline void
-array_set_field_boolean(struct vm_object *obj, int index, jboolean value)
-{
-       *(jboolean *) &obj->fields[index * get_vmtype_size(J_BOOLEAN)] = value;
-}
-
-static inline jboolean
-array_get_field_boolean(struct vm_object *obj, int index)
-{
-       return *(jboolean *) &obj->fields[index * get_vmtype_size(J_BOOLEAN)];
-}
-
-static inline void
-array_set_field_short(struct vm_object *obj, int index, jshort value)
-{
-       *(jshort *) &obj->fields[index * get_vmtype_size(J_SHORT)] = value;
-}
-
-static inline jshort
-array_get_field_short(struct vm_object *obj, int index)
-{
-       return *(jshort *) &obj->fields[index * get_vmtype_size(J_SHORT)];
-}
-
-static inline void
-array_set_field_int(struct vm_object *obj, int index, jint value)
-{
-       *(jint *) &obj->fields[index * get_vmtype_size(J_INT)] = value;
-}
-
-static inline jint
-array_get_field_int(struct vm_object *obj, int index)
-{
-       return *(jint *) &obj->fields[index * get_vmtype_size(J_INT)];
-}
-
-static inline void
-array_set_field_long(struct vm_object *obj, int index, jlong value)
-{
-       *(jlong *) &obj->fields[index * get_vmtype_size(J_LONG)] = value;
-}
-
-static inline jlong
-array_get_field_long(struct vm_object *obj, int index)
-{
-       return *(jlong *) &obj->fields[index * get_vmtype_size(J_LONG)];
-}
-
-static inline void
-array_set_field_float(struct vm_object *obj, int index, jfloat value)
-{
-       *(jfloat *) &obj->fields[index * get_vmtype_size(J_FLOAT)] = value;
-}
-
-static inline jfloat
-array_get_field_float(struct vm_object *obj, int index)
-{
-       return *(jfloat *) &obj->fields[index * get_vmtype_size(J_FLOAT)];
-}
-
-static inline void
-array_set_field_double(struct vm_object *obj, int index, jdouble value)
-{
-       *(jdouble *) &obj->fields[index * get_vmtype_size(J_DOUBLE)] = value;
-}
-
-static inline jdouble
-array_get_field_double(struct vm_object *obj, int index)
-{
-       return *(jdouble *) &obj->fields[index * get_vmtype_size(J_DOUBLE)];
-}
+#define DECLARE_FIELD_SETTER(type)                                     \
+static inline void                                                     \
+field_set_ ## type (struct vm_object *obj, const struct vm_field *field,\
+                   j ## type value)                                    \
+{                                                                      \
+       *(j ## type *) &obj->fields[field->offset] = value;             \
+}
+
+#define DECLARE_FIELD_GETTER(type)                                     \
+static inline j ## type                                                        
\
+field_get_ ## type (const struct vm_object *obj, const struct vm_field *field)\
+{                                                                      \
+       return *(j ## type *) &obj->fields[field->offset];              \
+}
+
+DECLARE_FIELD_SETTER(byte);
+DECLARE_FIELD_SETTER(boolean);
+DECLARE_FIELD_SETTER(char);
+DECLARE_FIELD_SETTER(double);
+DECLARE_FIELD_SETTER(float);
+DECLARE_FIELD_SETTER(int);
+DECLARE_FIELD_SETTER(long);
+DECLARE_FIELD_SETTER(object);
+DECLARE_FIELD_SETTER(short);
+
+DECLARE_FIELD_GETTER(byte);
+DECLARE_FIELD_GETTER(boolean);
+DECLARE_FIELD_GETTER(char);
+DECLARE_FIELD_GETTER(double);
+DECLARE_FIELD_GETTER(float);
+DECLARE_FIELD_GETTER(int);
+DECLARE_FIELD_GETTER(long);
+DECLARE_FIELD_GETTER(object);
+DECLARE_FIELD_GETTER(short);
+
+#define DECLARE_ARRAY_FIELD_SETTER(type, vmtype)                       \
+static inline void                                                     \
+array_set_field_ ## type(struct vm_object *obj, int index,             \
+                        j ## type value)                               \
+{                                                                      \
+       *(j ## type *) &obj->fields[index * get_vmtype_size(vmtype)] = value; \
+}
+
+#define DECLARE_ARRAY_FIELD_GETTER(type, vmtype)                       \
+static inline j ## type                                                        
\
+array_get_field_ ## type(const struct vm_object *obj, int index)       \
+{                                                                      \
+       return *(j ## type *) &obj->fields[index * get_vmtype_size(vmtype)]; \
+}
+
+DECLARE_ARRAY_FIELD_SETTER(byte, J_BYTE);
+DECLARE_ARRAY_FIELD_SETTER(boolean, J_BOOLEAN);
+DECLARE_ARRAY_FIELD_SETTER(char, J_CHAR);
+DECLARE_ARRAY_FIELD_SETTER(double, J_DOUBLE);
+DECLARE_ARRAY_FIELD_SETTER(float, J_FLOAT);
+DECLARE_ARRAY_FIELD_SETTER(int, J_INT);
+DECLARE_ARRAY_FIELD_SETTER(long, J_LONG);
+DECLARE_ARRAY_FIELD_SETTER(object, J_REFERENCE);
+DECLARE_ARRAY_FIELD_SETTER(short, J_SHORT);
+
+DECLARE_ARRAY_FIELD_GETTER(byte, J_BYTE);
+DECLARE_ARRAY_FIELD_GETTER(boolean, J_BOOLEAN);
+DECLARE_ARRAY_FIELD_GETTER(char, J_CHAR);
+DECLARE_ARRAY_FIELD_GETTER(double, J_DOUBLE);
+DECLARE_ARRAY_FIELD_GETTER(float, J_FLOAT);
+DECLARE_ARRAY_FIELD_GETTER(int, J_INT);
+DECLARE_ARRAY_FIELD_GETTER(long, J_LONG);
+DECLARE_ARRAY_FIELD_GETTER(object, J_REFERENCE);
+DECLARE_ARRAY_FIELD_GETTER(short, J_SHORT);
 
 static inline void
 array_set_field_ptr(struct vm_object *obj, int index, void *value)
 {
-       *(void **) &obj->fields[index * get_vmtype_size(J_REFERENCE)] = value;
+       *(void **) &obj->fields[index * get_vmtype_size(J_NATIVE_PTR)] = value;
 }
 
 static inline void *
 array_get_field_ptr(struct vm_object *obj, int index)
 {
-       return *(void **) &obj->fields[index * get_vmtype_size(J_REFERENCE)];
+       return *(void **) &obj->fields[index * get_vmtype_size(J_NATIVE_PTR)];
 }
 
 #endif
diff --git a/jit/trace-jit.c b/jit/trace-jit.c
index 3b97c6e..2579e1b 100644
--- a/jit/trace-jit.c
+++ b/jit/trace-jit.c
@@ -436,7 +436,7 @@ static void print_array(struct vm_object *obj)
 
                switch (type) {
                case J_REFERENCE:
-                       trace_printf("%p", array_get_field_ptr(obj, i));
+                       trace_printf("%p", array_get_field_object(obj, i));
                        break;
                case J_BYTE:
                        trace_printf("%x", (int)array_get_field_byte(obj, i));
diff --git a/vm/jato.c b/vm/jato.c
index d95304f..aaaa553 100644
--- a/vm/jato.c
+++ b/vm/jato.c
@@ -114,7 +114,7 @@ static struct vm_object 
*native_vmstackwalker_getclasscontext(void)
        class = cu->method->class;
 
        res = vm_object_alloc_array(vm_java_lang_Class, 1);
-       array_set_field_ptr(res, 0, class->object);
+       array_set_field_object(res, 0, class->object);
 
        return res;
 }
@@ -1133,7 +1133,7 @@ do_main_class(void)
 
                arg = vm_object_alloc_string_from_c(java_args[i]);
 
-               array_set_field_ptr(args, i, arg);
+               array_set_field_object(args, i, arg);
        }
 
        void (*main_method_trampoline)(void *)
diff --git a/vm/jni-interface.c b/vm/jni-interface.c
index cb369b2..04c5319 100644
--- a/vm/jni-interface.c
+++ b/vm/jni-interface.c
@@ -724,7 +724,7 @@ vm_jni_get_static_double_field(struct vm_jni_env *env, 
jobject object,
                return 0;
        }
 
-       return field_get_int64(object, field);
+       return field_get_double(object, field);
 }
 
 static jboolean
@@ -784,7 +784,7 @@ vm_jni_new_object_array(struct vm_jni_env *env, jsize size,
        }
 
        while (size)
-               array_set_field_ptr(array, --size, initial_element);
+               array_set_field_object(array, --size, initial_element);
 
        return array;
 }
diff --git a/vm/object.c b/vm/object.c
index 889ad39..15abb54 100644
--- a/vm/object.c
+++ b/vm/object.c
@@ -295,8 +295,8 @@ vm_object_alloc_string_from_utf8(const uint8_t bytes[], 
unsigned int length)
                return NULL;
        }
 
-       field_set_int32(string, vm_java_lang_String_offset, 0);
-       field_set_int32(string, vm_java_lang_String_count, array->array_length);
+       field_set_int(string, vm_java_lang_String_offset, 0);
+       field_set_int(string, vm_java_lang_String_count, array->array_length);
        field_set_object(string, vm_java_lang_String_value, array);
 
        return string;
@@ -328,8 +328,8 @@ vm_object_alloc_string_from_c(const char *bytes)
                array_set_field_char(array, i, bytes[i]);
        }
 
-       field_set_int32(string, vm_java_lang_String_offset, 0);
-       field_set_int32(string, vm_java_lang_String_count, array->array_length);
+       field_set_int(string, vm_java_lang_String_offset, 0);
+       field_set_int(string, vm_java_lang_String_count, array->array_length);
        field_set_object(string, vm_java_lang_String_value, array);
 
        return string;
@@ -536,8 +536,8 @@ char *vm_string_to_cstr(const struct vm_object *string_obj)
        int32_t count;
        char *result;
 
-       offset = field_get_int32(string_obj, vm_java_lang_String_offset);
-       count = field_get_int32(string_obj, vm_java_lang_String_count);
+       offset = field_get_int(string_obj, vm_java_lang_String_offset);
+       count = field_get_int(string_obj, vm_java_lang_String_count);
        array_object = field_get_object(string_obj, vm_java_lang_String_value);
 
        str = alloc_str();
diff --git a/vm/reflection.c b/vm/reflection.c
index 3357f9e..e4076c5 100644
--- a/vm/reflection.c
+++ b/vm/reflection.c
@@ -116,8 +116,7 @@ native_vmclass_get_declared_fields(struct vm_object *clazz,
                                 clazz);
                field_set_object(field, vm_java_lang_reflect_Field_name,
                                 name_object);
-               field_set_int32(field, vm_java_lang_reflect_Field_slot,
-                               i);
+               field_set_int(field, vm_java_lang_reflect_Field_slot, i);
 
                array_set_field_ptr(array, index++, field);
        }
@@ -186,8 +185,7 @@ native_vmclass_get_declared_methods(struct vm_object *clazz,
                                 clazz);
                field_set_object(method, vm_java_lang_reflect_Method_name,
                                 name_object);
-               field_set_int32(method, vm_java_lang_reflect_Method_slot,
-                               i);
+               field_set_int(method, vm_java_lang_reflect_Method_slot, i);
 
                array_set_field_ptr(array, index++, method);
        }
@@ -243,8 +241,7 @@ native_vmclass_get_declared_constructors(struct vm_object 
*clazz,
 
                field_set_object(ctor, vm_java_lang_reflect_Constructor_clazz,
                                 clazz);
-               field_set_int32(ctor, vm_java_lang_reflect_Constructor_slot,
-                               i);
+               field_set_int(ctor, vm_java_lang_reflect_Constructor_slot, i);
 
                array_set_field_ptr(array, index++, ctor);
        }
@@ -331,7 +328,7 @@ native_method_get_parameter_types(struct vm_object *method)
        }
 
        clazz = field_get_object(method, 
vm_java_lang_reflect_Method_declaringClass);
-       slot = field_get_int32(method, vm_java_lang_reflect_Method_slot);
+       slot = field_get_int(method, vm_java_lang_reflect_Method_slot);
 
        class = vm_class_get_class_from_class_object(clazz);
        vmm = &class->methods[slot];
@@ -353,7 +350,7 @@ native_constructor_get_parameter_types(struct vm_object 
*ctor)
        }
 
        clazz = field_get_object(ctor, vm_java_lang_reflect_Constructor_clazz);
-       slot = field_get_int32(ctor, vm_java_lang_reflect_Constructor_slot);
+       slot = field_get_int(ctor, vm_java_lang_reflect_Constructor_slot);
 
        class = vm_class_get_class_from_class_object(clazz);
        vmm = &class->methods[slot];
@@ -374,7 +371,7 @@ jint native_constructor_get_modifiers_internal(struct 
vm_object *ctor)
        }
 
        clazz = field_get_object(ctor, vm_java_lang_reflect_Constructor_clazz);
-       slot = field_get_int32(ctor, vm_java_lang_reflect_Constructor_slot);
+       slot = field_get_int(ctor, vm_java_lang_reflect_Constructor_slot);
 
        class = vm_class_get_class_from_class_object(clazz);
        vmm = &class->methods[slot];
@@ -538,7 +535,7 @@ struct vm_object *native_field_get(struct vm_object *this, 
struct vm_object *o)
        }
 
        clazz = field_get_object(this, 
vm_java_lang_reflect_Field_declaringClass);
-       slot = field_get_int32(this, vm_java_lang_reflect_Field_slot);
+       slot = field_get_int(this, vm_java_lang_reflect_Field_slot);
 
        vmc = vm_class_get_class_from_class_object(clazz);
 
diff --git a/vm/stack-trace.c b/vm/stack-trace.c
index c0c1ca1..fc5be9a 100644
--- a/vm/stack-trace.c
+++ b/vm/stack-trace.c
@@ -377,7 +377,6 @@ static struct vm_object *get_intermediate_stack_trace(void)
        struct stack_trace_elem st_elem;
        struct compilation_unit *cu;
        struct vm_object *array;
-       int array_type;
        int depth;
        int i;
 
@@ -396,8 +395,7 @@ static struct vm_object *get_intermediate_stack_trace(void)
        if (depth == 0)
                return NULL;
 
-       array_type = sizeof(unsigned long) == 4 ? T_INT : T_LONG;
-       array = vm_object_alloc_primitive_array(array_type, depth * 2);
+       array = vm_object_alloc_primitive_array(J_NATIVE_PTR, depth * 2);
        if (!array)
                return NULL;
 
diff --git a/vm/thread.c b/vm/thread.c
index e752b2a..c2fefbf 100644
--- a/vm/thread.c
+++ b/vm/thread.c
@@ -100,7 +100,7 @@ static bool vm_thread_is_daemon(struct vm_thread *thread)
        struct vm_object *jthread;
 
        jthread = vm_thread_get_java_thread(thread);
-       return field_get_int32(jthread, vm_java_lang_Thread_daemon) != 0;
+       return field_get_int(jthread, vm_java_lang_Thread_daemon) != 0;
 }
 
 void vm_thread_set_state(struct vm_thread *thread, enum vm_thread_state state)
@@ -173,15 +173,15 @@ int init_threading(void) {
 
        vm_get_exec_env()->thread = main_thread;
 
-       field_set_int32(thread, vm_java_lang_Thread_priority, 5);
-       field_set_int32(thread, vm_java_lang_Thread_daemon, 0);
+       field_set_int(thread, vm_java_lang_Thread_priority, 5);
+       field_set_int(thread, vm_java_lang_Thread_daemon, 0);
        field_set_object(thread, vm_java_lang_Thread_name, thread_name);
        field_set_object(thread, vm_java_lang_Thread_group, main_thread_group);
        field_set_object(thread, vm_java_lang_Thread_vmThread, vmthread);
 
        field_set_object(thread,
                vm_java_lang_Thread_contextClassLoader, NULL);
-       field_set_int32(thread,
+       field_set_int(thread,
                vm_java_lang_Thread_contextClassLoaderIsSystemClassLoader, 1);
 
        field_set_object(vmthread,
-- 
1.6.0.6


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to