Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: java_lang_reflect_Field.c 8132 2007-06-22 11:15:47Z twisti $
-
*/
#include <stdint.h>
#include "native/jni.h"
+#include "native/llni.h"
#include "native/native.h"
#include "native/include/java_lang_Boolean.h"
#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
+
#include "vm/access.h"
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/global.h"
#include "vm/initialize.h"
+#include "vm/primitive.h"
#include "vm/resolve.h"
#include "vm/stringlocal.h"
#include "vm/jit/stacktrace.h"
#include "vmcore/loader.h"
-#include "vmcore/primitive.h"
#include "vmcore/utf8.h"
{ "setFloat", "(Ljava/lang/Object;F)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setFloat },
{ "setDouble", "(Ljava/lang/Object;D)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setDouble },
{ "getSignature", "()Ljava/lang/String;", (void *) (intptr_t) &Java_java_lang_reflect_Field_getSignature },
+#if defined(ENABLE_ANNOTATIONS)
+ { "declaredAnnotations", "()Ljava/util/Map;", (void *) (intptr_t) &Java_java_lang_reflect_Field_declaredAnnotations },
+#endif
};
}
-/* cacao_get_field_address *****************************************************
+/* _field_access_check *********************************************************
- Return the address of a field of an object.
-
- 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;
-
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ int32_t flag;
- /* check field access */
/* check if we should bypass security checks (AccessibleObject) */
- if (this->flag == false) {
+ 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 address */
+ /* 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_objectheader *) o, c))
- return (void *) ((intptr_t) o + f->offset);
+ if (builtin_instanceof(o, c))
+ return true;
}
/* exception path */
exceptions_throw_illegalargumentexception();
+ return false;
+}
- return NULL;
+
+/* _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);
+ }
+
+ 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
{
classinfo *c;
fieldinfo *f;
+ int32_t slot;
- c = (classinfo *) this->clazz;
- f = &(c->fields[this->slot]);
+ LLNI_field_get_cls(this, clazz, c);
+ LLNI_field_get_val(this, slot , slot);
+ f = &(c->fields[slot]);
return f->flags;
}
classinfo *c;
typedesc *desc;
classinfo *ret;
+ int32_t slot;
- c = (classinfo *) this->clazz;
- desc = c->fields[this->slot].parseddesc;
+ LLNI_field_get_cls(this, clazz, c);
+ LLNI_field_get_val(this, slot , slot);
+ desc = c->fields[slot].parseddesc;
if (desc == NULL)
return NULL;
if (!resolve_class_from_typedesc(desc, true, false, &ret))
return NULL;
- return (java_lang_Class *) ret;
+ return LLNI_classinfo_wrap(ret);
}
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
+ imm_union value;
+ java_handle_t *object;
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ 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, o)) == NULL)
+ if (!_field_access_check(this, f, c, (java_handle_t *) o))
return NULL;
switch (f->parseddesc->decltype) {
- case PRIMITIVETYPE_BOOLEAN: {
- java_lang_Boolean *bo;
-
- /* create wrapping class */
-
- if (!(bo = (java_lang_Boolean *) builtin_new(class_java_lang_Boolean)))
- return NULL;
-
- /* set the object value */
-
- bo->value = *((int32_t *) addr);
-
- /* return the wrapped object */
-
- return (java_lang_Object *) bo;
- }
-
- case PRIMITIVETYPE_BYTE: {
- java_lang_Byte *bo;
-
- if (!(bo = (java_lang_Byte *) builtin_new(class_java_lang_Byte)))
- return NULL;
-
- bo->value = *((int32_t *) addr);
-
- return (java_lang_Object *) bo;
- }
-
- case PRIMITIVETYPE_CHAR: {
- java_lang_Character *co;
-
- if (!(co = (java_lang_Character *) builtin_new(class_java_lang_Character)))
- return NULL;
-
- co->value = *((int32_t *) addr);
-
- return (java_lang_Object *) co;
- }
-
- case PRIMITIVETYPE_SHORT: {
- java_lang_Short *so;
-
- if (!(so = (java_lang_Short *) builtin_new(class_java_lang_Short)))
- return NULL;
-
- so->value = (int32_t) *((int32_t *) addr);
-
- return (java_lang_Object *) so;
- }
-
- case PRIMITIVETYPE_INT: {
- java_lang_Integer *io;
-
- if (!(io = (java_lang_Integer *) builtin_new(class_java_lang_Integer)))
- return NULL;
-
- io->value = *((int32_t *) addr);
-
- return (java_lang_Object *) io;
- }
-
- case PRIMITIVETYPE_LONG: {
- java_lang_Long *lo;
-
- if (!(lo = (java_lang_Long *) builtin_new(class_java_lang_Long)))
- return NULL;
-
- lo->value = *((int64_t *) addr);
-
- return (java_lang_Object *) lo;
- }
-
- case PRIMITIVETYPE_FLOAT: {
- java_lang_Float *fo;
-
- if (!(fo = (java_lang_Float *) builtin_new(class_java_lang_Float)))
- return NULL;
-
- fo->value = *((float *) addr);
-
- return (java_lang_Object *) fo;
- }
-
- case PRIMITIVETYPE_DOUBLE: {
- java_lang_Double *_do;
+ case PRIMITIVETYPE_BOOLEAN:
+ case PRIMITIVETYPE_BYTE:
+ case PRIMITIVETYPE_CHAR:
+ case PRIMITIVETYPE_SHORT:
+ case PRIMITIVETYPE_INT:
+ value.i = _field_get_int(f, o);
+ break;
- if (!(_do = (java_lang_Double *) builtin_new(class_java_lang_Double)))
- return NULL;
+ case PRIMITIVETYPE_LONG:
+ value.l = _field_get_long(f, o);
+ break;
- _do->value = *((double *) addr);
+ case PRIMITIVETYPE_FLOAT:
+ value.f = _field_get_float(f, o);
+ break;
- return (java_lang_Object *) _do;
- }
+ case PRIMITIVETYPE_DOUBLE:
+ value.d = _field_get_double(f, o);
+ break;
case TYPE_ADR:
- return (java_lang_Object *) *((java_objectheader **) addr);
+ return (java_lang_Object *) _field_get_handle(f, o);
}
- /* this must not happen */
+ /* Now box the primitive types. */
- assert(0);
+ object = primitive_box(f->parseddesc->decltype, value);
- /* keep compiler happy */
-
- return NULL;
+ return (java_lang_Object *) object;
}
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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;
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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;
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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;
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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:
case PRIMITIVETYPE_SHORT:
- return (int32_t) *((int32_t *) addr);
+ return (int32_t) _field_get_int(f, o);
default:
exceptions_throw_illegalargumentexception();
return 0;
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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 */
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;
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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 */
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;
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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 */
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;
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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 */
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;
classinfo *dc;
fieldinfo *sf;
fieldinfo *df;
- void *faddr;
+ int32_t slot;
/* get the class and the field */
- dc = (classinfo *) this->clazz;
- df = &dc->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, dc);
+ 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 */
if (value == NULL)
sc = NULL;
else
- sc = value->header.vftbl->class;
+ LLNI_class_get(value, sc);
/* The fieldid is used to set the new value, for primitive
types the value has to be retrieved from the wrapping
switch (sf->parseddesc->decltype) {
case PRIMITIVETYPE_BOOLEAN:
- val = ((java_lang_Boolean *) value)->value;
+ LLNI_field_get_val((java_lang_Boolean *) value, value, val);
break;
default:
exceptions_throw_illegalargumentexception();
return;
}
- *((int32_t *) faddr) = val;
+ _field_set_int(df, o, val);
return;
}
switch (sf->parseddesc->decltype) {
case PRIMITIVETYPE_BYTE:
- val = ((java_lang_Byte *) value)->value;
+ LLNI_field_get_val((java_lang_Byte *) value, value, val);
break;
default:
exceptions_throw_illegalargumentexception();
return;
}
- *((int32_t *) faddr) = val;
+ _field_set_int(df, o, val);
return;
}
switch (sf->parseddesc->decltype) {
case PRIMITIVETYPE_CHAR:
- val = ((java_lang_Character *) value)->value;
+ LLNI_field_get_val((java_lang_Character *) value, value, val);
break;
default:
exceptions_throw_illegalargumentexception();
return;
}
- *((int32_t *) faddr) = val;
+ _field_set_int(df, o, val);
return;
}
switch (sf->parseddesc->decltype) {
case PRIMITIVETYPE_BYTE:
- val = ((java_lang_Byte *) value)->value;
+ LLNI_field_get_val((java_lang_Byte *) value, value, val);
break;
case PRIMITIVETYPE_SHORT:
- val = ((java_lang_Short *) value)->value;
+ LLNI_field_get_val((java_lang_Short *) value, value, val);
break;
default:
exceptions_throw_illegalargumentexception();
return;
}
- *((int32_t *) faddr) = val;
+ _field_set_int(df, o, val);
return;
}
switch (sf->parseddesc->decltype) {
case PRIMITIVETYPE_BYTE:
- val = ((java_lang_Byte *) value)->value;
+ LLNI_field_get_val((java_lang_Byte *) value, value, val);
break;
case PRIMITIVETYPE_CHAR:
- val = ((java_lang_Character *) value)->value;
+ LLNI_field_get_val((java_lang_Character *) value, value, val);
break;
case PRIMITIVETYPE_SHORT:
- val = ((java_lang_Short *) value)->value;
+ LLNI_field_get_val((java_lang_Short *) value, value, val);
break;
case PRIMITIVETYPE_INT:
- val = ((java_lang_Integer *) value)->value;
+ LLNI_field_get_val((java_lang_Integer *) value, value, val);
break;
default:
exceptions_throw_illegalargumentexception();
return;
}
- *((int32_t *) faddr) = val;
+ _field_set_int(df, o, val);
return;
}
switch (sf->parseddesc->decltype) {
case PRIMITIVETYPE_BYTE:
- val = ((java_lang_Byte *) value)->value;
+ LLNI_field_get_val((java_lang_Byte *) value, value, val);
break;
case PRIMITIVETYPE_CHAR:
- val = ((java_lang_Character *) value)->value;
+ LLNI_field_get_val((java_lang_Character *) value, value, val);
break;
case PRIMITIVETYPE_SHORT:
- val = ((java_lang_Short *) value)->value;
+ LLNI_field_get_val((java_lang_Short *) value, value, val);
break;
case PRIMITIVETYPE_INT:
- val = ((java_lang_Integer *) value)->value;
+ LLNI_field_get_val((java_lang_Integer *) value, value, val);
break;
case PRIMITIVETYPE_LONG:
- val = ((java_lang_Long *) value)->value;
+ LLNI_field_get_val((java_lang_Long *) value, value, val);
break;
default:
exceptions_throw_illegalargumentexception();
return;
}
- *((int64_t *) faddr) = val;
+ _field_set_long(df, o, val);
return;
}
switch (sf->parseddesc->decltype) {
case PRIMITIVETYPE_BYTE:
- val = ((java_lang_Byte *) value)->value;
+ LLNI_field_get_val((java_lang_Byte *) value, value, val);
break;
case PRIMITIVETYPE_CHAR:
- val = ((java_lang_Character *) value)->value;
+ LLNI_field_get_val((java_lang_Character *) value, value, val);
break;
case PRIMITIVETYPE_SHORT:
- val = ((java_lang_Short *) value)->value;
+ LLNI_field_get_val((java_lang_Short *) value, value, val);
break;
case PRIMITIVETYPE_INT:
- val = ((java_lang_Integer *) value)->value;
+ LLNI_field_get_val((java_lang_Integer *) value, value, val);
break;
case PRIMITIVETYPE_LONG:
- val = ((java_lang_Long *) value)->value;
+ LLNI_field_get_val((java_lang_Long *) value, value, val);
break;
case PRIMITIVETYPE_FLOAT:
- val = ((java_lang_Float *) value)->value;
+ LLNI_field_get_val((java_lang_Float *) value, value, val);
break;
default:
exceptions_throw_illegalargumentexception();
return;
}
- *((float *) faddr) = val;
+ _field_set_float(df, o, val);
return;
}
switch (sf->parseddesc->decltype) {
case PRIMITIVETYPE_BYTE:
- val = ((java_lang_Byte *) value)->value;
+ LLNI_field_get_val((java_lang_Byte *) value, value, val);
break;
case PRIMITIVETYPE_CHAR:
- val = ((java_lang_Character *) value)->value;
+ LLNI_field_get_val((java_lang_Character *) value, value, val);
break;
case PRIMITIVETYPE_SHORT:
- val = ((java_lang_Short *) value)->value;
+ LLNI_field_get_val((java_lang_Short *) value, value, val);
break;
case PRIMITIVETYPE_INT:
- val = ((java_lang_Integer *) value)->value;
+ LLNI_field_get_val((java_lang_Integer *) value, value, val);
break;
case PRIMITIVETYPE_LONG:
- val = ((java_lang_Long *) value)->value;
+ LLNI_field_get_val((java_lang_Long *) value, value, val);
break;
case PRIMITIVETYPE_FLOAT:
- val = ((java_lang_Float *) value)->value;
+ LLNI_field_get_val((java_lang_Float *) value, value, val);
break;
case PRIMITIVETYPE_DOUBLE:
- val = ((java_lang_Double *) value)->value;
+ LLNI_field_get_val((java_lang_Double *) value, value, val);
break;
default:
exceptions_throw_illegalargumentexception();
return;
}
- *((double *) faddr) = val;
+ _field_set_double(df, o, val);
return;
}
/* check if value is an instance of the destination class */
/* XXX TODO */
- /* if (!builtin_instanceof((java_objectheader *) value, df->class)) */
+ /* 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;
}
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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();
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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 */
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();
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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_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();
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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_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();
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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();
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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();
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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();
{
classinfo *c;
fieldinfo *f;
- void *addr;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ 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();
*/
JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Field_getSignature(JNIEnv *env, java_lang_reflect_Field* this)
{
- classinfo *c;
- fieldinfo *f;
- java_objectheader *o;
+ classinfo *c;
+ fieldinfo *f;
+ java_handle_t *o;
+ int32_t slot;
/* get the class and the field */
- c = (classinfo *) this->clazz;
- f = &c->fields[this->slot];
+ LLNI_field_get_cls(this, clazz, c);
+ LLNI_field_get_val(this, slot , slot);
+ f = &c->fields[slot];
if (f->signature == NULL)
return NULL;
}
+#if defined(ENABLE_ANNOTATIONS)
+/*
+ * Class: java/lang/reflect/Field
+ * Method: declaredAnnotations
+ * Signature: ()Ljava/util/Map;
+ */
+JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Field_declaredAnnotations(JNIEnv *env, java_lang_reflect_Field *this)
+{
+ 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_ref(this, annotations, annotations);
+ LLNI_field_get_ref(this, clazz, declaringClass);
+ LLNI_class_get(this, referer);
+
+ declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
+
+ LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
+ }
+
+ return declaredAnnotations;
+}
+#endif
+
+
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/