* src/vm/jit/i386/darwin/md-os.c (md_replace_executionstate_read):
[cacao.git] / src / native / vm / gnu / java_lang_reflect_Field.c
index a58447c3993e5ae280d67c35c1c59a70be15f5d1..0dcc8c7e351f883c71b81120512327c19a751965 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: java_lang_reflect_Field.c 8305 2007-08-15 13:49:26Z panzi $
-
 */
 
 
@@ -51,6 +49,7 @@
 #include "native/include/java_lang_reflect_Field.h"
 
 #if defined(ENABLE_ANNOTATIONS)
+#include "native/include/java_util_Map.h"
 #include "native/include/sun_reflect_ConstantPool.h"
 #include "native/vm/reflect.h"
 #endif
@@ -116,78 +115,147 @@ void _Jv_java_lang_reflect_Field_init(void)
 }
 
 
-/* cacao_get_field_address *****************************************************
-
-   Return the address of a field of an object.
+/* _field_access_check *********************************************************
 
-   IN:
-      this.........the field (a java.lang.reflect.Field object)
-         o............the object of which to get the field
+   Checks if the field can be accessed.
 
    RETURN VALUE:
-      a pointer to the field, or
-         NULL if an exception has been thrown
+      true......field can be accessed, or
+      false.....otherwise (maybe an Exception was thrown).
 
 *******************************************************************************/
 
-static void *cacao_get_field_address(java_lang_reflect_Field *this,
-                                                                        java_lang_Object *o)
+static bool _field_access_check(java_lang_reflect_Field *this,
+                                                               fieldinfo *f, classinfo *c, java_handle_t *o)
 {
-       classinfo *c;
-       fieldinfo *f;
-       int32_t    slot;
-       int32_t    flag;
-
-       LLNI_field_get_cls(this, clazz, c);
-       LLNI_field_get_val(this, slot , slot);
-       f = &c->fields[slot];
+       int32_t flag;
 
-       /* check field access */
        /* check if we should bypass security checks (AccessibleObject) */
 
        LLNI_field_get_val(this, flag, flag);
        if (flag == false) {
                /* this function is always called like this:
-
                           java.lang.reflect.Field.xxx (Native Method)
                   [0] <caller>
                */
                if (!access_check_field(f, 0))
-                       return NULL;
+                       return false;
        }
 
-       /* get the address of the field */
+       /* some general checks */
 
        if (f->flags & ACC_STATIC) {
                /* initialize class if required */
 
                if (!(c->state & CLASS_INITIALIZED))
                        if (!initialize_class(c))
-                               return NULL;
+                               return false;
 
-               /* return value pointer */
+               /* everything is ok */
 
-               return f->value;
+               return true;
 
        } else {
                /* obj is required for not-static fields */
 
                if (o == NULL) {
                        exceptions_throw_nullpointerexception();
-                       return NULL;
+                       return false;
                }
        
-               if (builtin_instanceof((java_handle_t *) o, c))
-                       return (void *) (((intptr_t) o) + f->offset);
+               if (builtin_instanceof(o, c))
+                       return true;
        }
 
        /* exception path */
 
        exceptions_throw_illegalargumentexception();
+       return false;
+}
+
+
+/* _field_get_type *************************************************************
+
+   Returns the content of the given field.
+
+*******************************************************************************/
+
+#define _FIELD_GET_TYPE(name, type, uniontype) \
+static inline type _field_get_##name(fieldinfo *f, java_lang_Object *o) \
+{ \
+       type ret; \
+       if (f->flags & ACC_STATIC) { \
+               ret = f->value->uniontype; \
+       } else { \
+               LLNI_CRITICAL_START; \
+               ret = *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset); \
+               LLNI_CRITICAL_END; \
+       } \
+       return ret; \
+}
+
+static inline java_handle_t *_field_get_handle(fieldinfo *f, java_lang_Object *o)
+{
+       java_object_t *obj;
+       java_handle_t *hdl;
+
+       LLNI_CRITICAL_START;
+
+       if (f->flags & ACC_STATIC) {
+               obj = f->value->a;
+       } else {
+               obj = *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset);
+       }
+
+       hdl = LLNI_WRAP(obj);
+
+       LLNI_CRITICAL_END;
+
+       return hdl;
+}
+
+_FIELD_GET_TYPE(int,    int32_t, i)
+_FIELD_GET_TYPE(long,   int64_t, l)
+_FIELD_GET_TYPE(float,  float,   f)
+_FIELD_GET_TYPE(double, double,  d)
+
+
+/* _field_set_type *************************************************************
+
+   Sets the content of the given field to the given value.
+
+*******************************************************************************/
+
+#define _FIELD_SET_TYPE(name, type, uniontype) \
+static inline void _field_set_##name(fieldinfo *f, java_lang_Object *o, type value) \
+{ \
+       if (f->flags & ACC_STATIC) { \
+               f->value->uniontype = value; \
+       } else { \
+               LLNI_CRITICAL_START; \
+               *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = value; \
+               LLNI_CRITICAL_END; \
+       } \
+}
+
+static inline void _field_set_handle(fieldinfo *f, java_lang_Object *o, java_handle_t *value)
+{
+       LLNI_CRITICAL_START;
+
+       if (f->flags & ACC_STATIC) {
+               f->value->a = LLNI_DIRECT(value);
+       } else {
+               *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = LLNI_DIRECT(value);
+       }
 
-       return NULL;
+       LLNI_CRITICAL_END;
 }
 
+_FIELD_SET_TYPE(int,    int32_t, i)
+_FIELD_SET_TYPE(long,   int64_t, l)
+_FIELD_SET_TYPE(float,  float,   f)
+_FIELD_SET_TYPE(double, double,  d)
+
 
 /*
  * Class:     java/lang/reflect/Field
@@ -230,7 +298,7 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *
        if (!resolve_class_from_typedesc(desc, true, false, &ret))
                return NULL;
        
-       return (java_lang_Class *) ret;
+       return LLNI_classinfo_wrap(ret);
 }
 
 
@@ -239,22 +307,21 @@ JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *
  * Method:    get
  * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
  */
-JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *object)
+JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
        imm_union  value;
-       java_handle_t *o;
+       java_handle_t *object;
 
        LLNI_field_get_cls(this, clazz, c);
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get address of the source field value */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, object)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return NULL;
 
        switch (f->parseddesc->decltype) {
@@ -263,31 +330,30 @@ JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env
        case PRIMITIVETYPE_CHAR:
        case PRIMITIVETYPE_SHORT:
        case PRIMITIVETYPE_INT:
-               value.i = *((int32_t *) addr);
+               value.i = _field_get_int(f, o);
                break;
 
        case PRIMITIVETYPE_LONG:
-               value.l = *((int64_t *) addr);
+               value.l = _field_get_long(f, o);
                break;
 
        case PRIMITIVETYPE_FLOAT:
-               value.f = *((float *) addr);
+               value.f = _field_get_float(f, o);
                break;
 
        case PRIMITIVETYPE_DOUBLE:
-               value.d = *((double *) addr);
+               value.d = _field_get_double(f, o);
                break;
 
        case TYPE_ADR:
-#warning this whole thing needs to be inside a critical section!
-               return (java_lang_Object *) *((java_handle_t **) addr);
+               return (java_lang_Object *) _field_get_handle(f, o);
        }
 
        /* Now box the primitive types. */
 
-       o = primitive_box(f->parseddesc->decltype, value);
+       object = primitive_box(f->parseddesc->decltype, value);
 
-       return (java_lang_Object *) o;
+       return (java_lang_Object *) object;
 }
 
 
@@ -300,7 +366,6 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, j
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -309,16 +374,16 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, j
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return 0;
 
        /* check the field type and return the value */
 
        switch (f->parseddesc->decltype) {
        case PRIMITIVETYPE_BOOLEAN:
-               return (int32_t) *((int32_t *) addr);
+               return (int32_t) _field_get_int(f, o);
        default:
                exceptions_throw_illegalargumentexception();
                return 0;
@@ -335,7 +400,6 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -344,16 +408,16 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return 0;
 
        /* check the field type and return the value */
 
        switch (f->parseddesc->decltype) {
        case PRIMITIVETYPE_BYTE:
-               return (int32_t) *((int32_t *) addr);
+               return (int32_t) _field_get_int(f, o);
        default:
                exceptions_throw_illegalargumentexception();
                return 0;
@@ -370,7 +434,6 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -379,16 +442,16 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return 0;
 
        /* check the field type and return the value */
 
        switch (f->parseddesc->decltype) {
        case PRIMITIVETYPE_CHAR:
-               return (int32_t) *((int32_t *) addr);
+               return (int32_t) _field_get_int(f, o);
        default:
                exceptions_throw_illegalargumentexception();
                return 0;
@@ -405,7 +468,6 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, jav
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -414,9 +476,9 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, jav
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return 0;
 
        /* check the field type and return the value */
@@ -424,7 +486,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, jav
        switch (f->parseddesc->decltype) {
        case PRIMITIVETYPE_BYTE:
        case PRIMITIVETYPE_SHORT:
-               return (int32_t) *((int32_t *) addr);
+               return (int32_t) _field_get_int(f, o);
        default:
                exceptions_throw_illegalargumentexception();
                return 0;
@@ -441,7 +503,6 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -450,9 +511,9 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return 0;
 
        /* check the field type and return the value */
@@ -462,7 +523,7 @@ JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java
        case PRIMITIVETYPE_CHAR:
        case PRIMITIVETYPE_SHORT:
        case PRIMITIVETYPE_INT:
-               return (int32_t) *((int32_t *) addr);
+               return (int32_t) _field_get_int(f, o);
        default:
                exceptions_throw_illegalargumentexception();
                return 0;
@@ -479,7 +540,6 @@ JNIEXPORT int64_t JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -488,9 +548,9 @@ JNIEXPORT int64_t JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return 0;
 
        /* check the field type and return the value */
@@ -500,9 +560,9 @@ JNIEXPORT int64_t JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java
        case PRIMITIVETYPE_CHAR:
        case PRIMITIVETYPE_SHORT:
        case PRIMITIVETYPE_INT:
-               return (int64_t) *((int32_t *) addr);
+               return (int64_t) _field_get_int(f, o);
        case PRIMITIVETYPE_LONG:
-               return (int64_t) *((int64_t *) addr);
+               return (int64_t) _field_get_long(f, o);
        default:
                exceptions_throw_illegalargumentexception();
                return 0;
@@ -519,7 +579,6 @@ JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -528,9 +587,9 @@ JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return 0;
 
        /* check the field type and return the value */
@@ -540,11 +599,11 @@ JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_
        case PRIMITIVETYPE_CHAR:
        case PRIMITIVETYPE_SHORT:
        case PRIMITIVETYPE_INT:
-               return (float) *((int32_t *) addr);
+               return (float) _field_get_int(f, o);
        case PRIMITIVETYPE_LONG:
-               return (float) *((int64_t *) addr);
+               return (float) _field_get_long(f, o);
        case PRIMITIVETYPE_FLOAT:
-               return (float) *((float *) addr);
+               return (float) _field_get_float(f, o);
        default:
                exceptions_throw_illegalargumentexception();
                return 0;
@@ -561,7 +620,6 @@ JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , ja
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -570,9 +628,9 @@ JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , ja
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return 0;
 
        /* check the field type and return the value */
@@ -582,13 +640,13 @@ JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , ja
        case PRIMITIVETYPE_CHAR:
        case PRIMITIVETYPE_SHORT:
        case PRIMITIVETYPE_INT:
-               return (double) *((int32_t *) addr);
+               return (double) _field_get_int(f, o);
        case PRIMITIVETYPE_LONG:
-               return (double) *((int64_t *) addr);
+               return (double) _field_get_long(f, o);
        case PRIMITIVETYPE_FLOAT:
-               return (double) *((float *) addr);
+               return (double) _field_get_float(f, o);
        case PRIMITIVETYPE_DOUBLE:
-               return (double) *((double *) addr);
+               return (double) _field_get_double(f, o);
        default:
                exceptions_throw_illegalargumentexception();
                return 0;
@@ -607,7 +665,6 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_r
        classinfo *dc;
        fieldinfo *sf;
        fieldinfo *df;
-       void      *faddr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -616,9 +673,9 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_r
        LLNI_field_get_val(this, slot , slot);
        df = &dc->fields[slot];
 
-       /* get the address of the destination field */
+       /* check if the field can be accessed */
 
-       if ((faddr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, df, dc, (java_handle_t *) o))
                return;
 
        /* get the source classinfo from the object */
@@ -650,7 +707,7 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_r
                        return;
                }
 
-               *((int32_t *) faddr) = val;
+               _field_set_int(df, o, val);
                return;
        }
 
@@ -669,7 +726,7 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_r
                        return;
                }
 
-               *((int32_t *) faddr) = val;
+               _field_set_int(df, o, val);
                return;
        }
 
@@ -688,7 +745,7 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_r
                        return;
                }
 
-               *((int32_t *) faddr) = val;
+               _field_set_int(df, o, val);
                return;
        }
 
@@ -712,7 +769,7 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_r
                        return;
                }
 
-               *((int32_t *) faddr) = val;
+               _field_set_int(df, o, val);
                return;
        }
 
@@ -742,7 +799,7 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_r
                        return;
                }
 
-               *((int32_t *) faddr) = val;
+               _field_set_int(df, o, val);
                return;
        }
 
@@ -775,7 +832,7 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_r
                        return;
                }
 
-               *((int64_t *) faddr) = val;
+               _field_set_long(df, o, val);
                return;
        }
 
@@ -811,7 +868,7 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_r
                        return;
                }
 
-               *((float *) faddr) = val;
+               _field_set_float(df, o, val);
                return;
        }
 
@@ -850,7 +907,7 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_r
                        return;
                }
 
-               *((double *) faddr) = val;
+               _field_set_double(df, o, val);
                return;
        }
 
@@ -861,7 +918,7 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_r
                /*                      if (!builtin_instanceof((java_handle_t *) value, df->class)) */
                /*                              break; */
 
-               *((java_lang_Object **) faddr) = value;
+               _field_set_handle(df, o, (java_handle_t *) value);
                return;
        }
 
@@ -880,7 +937,6 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -889,16 +945,16 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return;
 
        /* check the field type and set the value */
 
        switch (f->parseddesc->decltype) {
        case PRIMITIVETYPE_BOOLEAN:
-               *((int32_t *) addr) = value;
+               _field_set_int(f, o, value);
                break;
        default:
                exceptions_throw_illegalargumentexception();
@@ -917,7 +973,6 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_la
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -926,9 +981,9 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_la
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return;
 
        /* check the field type and set the value */
@@ -937,16 +992,16 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_la
        case PRIMITIVETYPE_BYTE:
        case PRIMITIVETYPE_SHORT:
        case PRIMITIVETYPE_INT:
-               *((int32_t *) addr) = value;
+               _field_set_int(f, o, value);
                break;
        case PRIMITIVETYPE_LONG:
-               *((int64_t *) addr) = value;
+               _field_set_long(f, o, value);
                break;
        case PRIMITIVETYPE_FLOAT:
-               *((float *) addr) = value;
+               _field_set_float(f, o, value);
                break;
        case PRIMITIVETYPE_DOUBLE:
-               *((double *) addr) = value;
+               _field_set_double(f, o, value);
                break;
        default:
                exceptions_throw_illegalargumentexception();
@@ -965,7 +1020,6 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_la
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -974,9 +1028,9 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_la
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return;
 
        /* check the field type and set the value */
@@ -984,16 +1038,16 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_la
        switch (f->parseddesc->decltype) {
        case PRIMITIVETYPE_CHAR:
        case PRIMITIVETYPE_INT:
-               *((int32_t *) addr) = value;
+               _field_set_int(f, o, value);
                break;
        case PRIMITIVETYPE_LONG:
-               *((int64_t *) addr) = value;
+               _field_set_long(f, o, value);
                break;
        case PRIMITIVETYPE_FLOAT:
-               *((float *) addr) = value;
+               _field_set_float(f, o, value);
                break;
        case PRIMITIVETYPE_DOUBLE:
-               *((double *) addr) = value;
+               _field_set_double(f, o, value);
                break;
        default:
                exceptions_throw_illegalargumentexception();
@@ -1012,7 +1066,6 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_l
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -1021,9 +1074,9 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_l
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return;
 
        /* check the field type and set the value */
@@ -1031,16 +1084,16 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_l
        switch (f->parseddesc->decltype) {
        case PRIMITIVETYPE_SHORT:
        case PRIMITIVETYPE_INT:
-               *((int32_t *) addr) = value;
+               _field_set_int(f, o, value);
                break;
        case PRIMITIVETYPE_LONG:
-               *((int64_t *) addr) = value;
+               _field_set_long(f, o, value);
                break;
        case PRIMITIVETYPE_FLOAT:
-               *((float *) addr) = value;
+               _field_set_float(f, o, value);
                break;
        case PRIMITIVETYPE_DOUBLE:
-               *((double *) addr) = value;
+               _field_set_double(f, o, value);
                break;
        default:
                exceptions_throw_illegalargumentexception();
@@ -1059,7 +1112,6 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lan
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -1068,25 +1120,25 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lan
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return;
 
        /* check the field type and set the value */
 
        switch (f->parseddesc->decltype) {
        case PRIMITIVETYPE_INT:
-               *((int32_t *) addr) = value;
+               _field_set_int(f, o, value);
                break;
        case PRIMITIVETYPE_LONG:
-               *((int64_t *) addr) = value;
+               _field_set_long(f, o, value);
                break;
        case PRIMITIVETYPE_FLOAT:
-               *((float *) addr) = value;
+               _field_set_float(f, o, value);
                break;
        case PRIMITIVETYPE_DOUBLE:
-               *((double *) addr) = value;
+               _field_set_double(f, o, value);
                break;
        default:
                exceptions_throw_illegalargumentexception();
@@ -1105,7 +1157,6 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_la
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -1114,22 +1165,22 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_la
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return;
 
        /* check the field type and set the value */
 
        switch (f->parseddesc->decltype) {
        case PRIMITIVETYPE_LONG:
-               *((int64_t *) addr) = value;
+               _field_set_long(f, o, value);
                break;
        case PRIMITIVETYPE_FLOAT:
-               *((float *) addr) = value;
+               _field_set_float(f, o, value);
                break;
        case PRIMITIVETYPE_DOUBLE:
-               *((double *) addr) = value;
+               _field_set_double(f, o, value);
                break;
        default:
                exceptions_throw_illegalargumentexception();
@@ -1148,7 +1199,6 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_l
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -1157,19 +1207,19 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_l
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return;
 
        /* check the field type and set the value */
 
        switch (f->parseddesc->decltype) {
        case PRIMITIVETYPE_FLOAT:
-               *((float *) addr) = value;
+               _field_set_float(f, o, value);
                break;
        case PRIMITIVETYPE_DOUBLE:
-               *((double *) addr) = value;
+               _field_set_double(f, o, value);
                break;
        default:
                exceptions_throw_illegalargumentexception();
@@ -1188,7 +1238,6 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_
 {
        classinfo *c;
        fieldinfo *f;
-       void      *addr;
        int32_t    slot;
 
        /* get the class and the field */
@@ -1197,16 +1246,16 @@ JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_
        LLNI_field_get_val(this, slot , slot);
        f = &c->fields[slot];
 
-       /* get the address of the field with an internal helper */
+       /* check if the field can be accessed */
 
-       if ((addr = cacao_get_field_address(this, o)) == NULL)
+       if (!_field_access_check(this, f, c, (java_handle_t *) o))
                return;
 
        /* check the field type and set the value */
 
        switch (f->parseddesc->decltype) {
        case PRIMITIVETYPE_DOUBLE:
-               *((double *) addr) = value;
+               _field_set_double(f, o, value);
                break;
        default:
                exceptions_throw_illegalargumentexception();
@@ -1251,25 +1300,23 @@ JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Field_getSignature(JN
  * Method:    declaredAnnotations
  * Signature: ()Ljava/util/Map;
  */
-JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Field_declaredAnnotations(JNIEnv *env, struct java_lang_reflect_Field* this)
+JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Field_declaredAnnotations(JNIEnv *env, java_lang_reflect_Field *this)
 {
-       java_handle_t        *o                   = (java_handle_t*)this;
-       struct java_util_Map *declaredAnnotations = NULL;
-       java_bytearray       *annotations         = NULL;
-       java_lang_Class      *declaringClass      = NULL;
-
-       if (this == NULL) {
-               exceptions_throw_nullpointerexception();
-               return NULL;
-       }
+       java_util_Map           *declaredAnnotations = NULL; /* parsed annotations                                */
+       java_handle_bytearray_t *annotations         = NULL; /* unparsed annotations                              */
+       java_lang_Class         *declaringClass      = NULL; /* the constant pool of this class is used           */
+       classinfo               *referer             = NULL; /* class, which calles the annotation parser         */
+                                                            /* (for the parameter 'referer' of vm_call_method()) */
 
        LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
 
+       /* are the annotations parsed yet? */
        if (declaredAnnotations == NULL) {
-               LLNI_field_get_val(this, annotations, annotations);
+               LLNI_field_get_ref(this, annotations, annotations);
                LLNI_field_get_ref(this, clazz, declaringClass);
+               LLNI_class_get(this, referer);
 
-               declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, o->vftbl->class);
+               declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
 
                LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
        }
@@ -1290,4 +1337,5 @@ JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Field_declaredAnn
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */