1 /* src/native/vm/gnu/java_lang_reflect_VMField.c
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 #include "native/jni.h"
32 #include "native/llni.h"
33 #include "native/native.h"
35 #include "native/include/java_lang_Boolean.h"
36 #include "native/include/java_lang_Byte.h"
37 #include "native/include/java_lang_Character.h"
38 #include "native/include/java_lang_Short.h"
39 #include "native/include/java_lang_Integer.h"
40 #include "native/include/java_lang_Long.h"
41 #include "native/include/java_lang_Float.h"
42 #include "native/include/java_lang_Double.h"
43 #include "native/include/java_lang_Object.h"
44 #include "native/include/java_lang_Class.h"
45 #include "native/include/java_lang_String.h"
47 #include "native/include/java_lang_reflect_Field.h"
48 #include "native/include/java_lang_reflect_VMField.h"
50 #if defined(ENABLE_ANNOTATIONS)
51 #include "native/include/java_util_Map.h"
52 #include "native/include/sun_reflect_ConstantPool.h"
53 #include "native/vm/reflect.h"
56 #include "vm/access.h"
57 #include "vm/builtin.h"
58 #include "vm/exceptions.h"
59 #include "vm/global.h"
60 #include "vm/initialize.h"
61 #include "vm/primitive.h"
62 #include "vm/resolve.h"
63 #include "vm/stringlocal.h"
65 #include "vm/jit/stacktrace.h"
67 #include "vmcore/loader.h"
68 #include "vmcore/utf8.h"
71 /* native methods implemented by this file ************************************/
73 static JNINativeMethod methods[] = {
74 { "getModifiersInternal", "()I", (void *) (intptr_t) &Java_java_lang_reflect_VMField_getModifiersInternal },
75 { "getType", "()Ljava/lang/Class;", (void *) (intptr_t) &Java_java_lang_reflect_VMField_getType },
76 { "get", "(Ljava/lang/Object;)Ljava/lang/Object;", (void *) (intptr_t) &Java_java_lang_reflect_VMField_get },
77 { "getBoolean", "(Ljava/lang/Object;)Z", (void *) (intptr_t) &Java_java_lang_reflect_VMField_getBoolean },
78 { "getByte", "(Ljava/lang/Object;)B", (void *) (intptr_t) &Java_java_lang_reflect_VMField_getByte },
79 { "getChar", "(Ljava/lang/Object;)C", (void *) (intptr_t) &Java_java_lang_reflect_VMField_getChar },
80 { "getShort", "(Ljava/lang/Object;)S", (void *) (intptr_t) &Java_java_lang_reflect_VMField_getShort },
81 { "getInt", "(Ljava/lang/Object;)I", (void *) (intptr_t) &Java_java_lang_reflect_VMField_getInt },
82 { "getLong", "(Ljava/lang/Object;)J", (void *) (intptr_t) &Java_java_lang_reflect_VMField_getLong },
83 { "getFloat", "(Ljava/lang/Object;)F", (void *) (intptr_t) &Java_java_lang_reflect_VMField_getFloat },
84 { "getDouble", "(Ljava/lang/Object;)D", (void *) (intptr_t) &Java_java_lang_reflect_VMField_getDouble },
85 { "set", "(Ljava/lang/Object;Ljava/lang/Object;)V", (void *) (intptr_t) &Java_java_lang_reflect_VMField_set },
86 { "setBoolean", "(Ljava/lang/Object;Z)V", (void *) (intptr_t) &Java_java_lang_reflect_VMField_setBoolean },
87 { "setByte", "(Ljava/lang/Object;B)V", (void *) (intptr_t) &Java_java_lang_reflect_VMField_setByte },
88 { "setChar", "(Ljava/lang/Object;C)V", (void *) (intptr_t) &Java_java_lang_reflect_VMField_setChar },
89 { "setShort", "(Ljava/lang/Object;S)V", (void *) (intptr_t) &Java_java_lang_reflect_VMField_setShort },
90 { "setInt", "(Ljava/lang/Object;I)V", (void *) (intptr_t) &Java_java_lang_reflect_VMField_setInt },
91 { "setLong", "(Ljava/lang/Object;J)V", (void *) (intptr_t) &Java_java_lang_reflect_VMField_setLong },
92 { "setFloat", "(Ljava/lang/Object;F)V", (void *) (intptr_t) &Java_java_lang_reflect_VMField_setFloat },
93 { "setDouble", "(Ljava/lang/Object;D)V", (void *) (intptr_t) &Java_java_lang_reflect_VMField_setDouble },
94 { "getSignature", "()Ljava/lang/String;", (void *) (intptr_t) &Java_java_lang_reflect_VMField_getSignature },
95 #if defined(ENABLE_ANNOTATIONS)
96 { "declaredAnnotations", "()Ljava/util/Map;", (void *) (intptr_t) &Java_java_lang_reflect_VMField_declaredAnnotations },
101 /* _Jv_java_lang_reflect_VMField_init ******************************************
103 Register native functions.
105 *******************************************************************************/
107 void _Jv_java_lang_reflect_VMField_init(void)
111 u = utf_new_char("java/lang/reflect/VMField");
113 native_method_register(u, methods, NATIVE_METHODS_COUNT);
117 /* _field_access_check *********************************************************
119 Checks if the field can be accessed.
122 true......field can be accessed, or
123 false.....otherwise (maybe an Exception was thrown).
125 *******************************************************************************/
127 static bool _field_access_check(java_lang_reflect_VMField *this,
128 fieldinfo *f, classinfo *c, java_handle_t *o)
130 java_lang_reflect_Field *rf;
133 /* check if we should bypass security checks (AccessibleObject) */
135 LLNI_field_get_ref(this, f, rf);
136 LLNI_field_get_val(rf, flag, flag);
139 /* This function is always called like this:
140 [0] java.lang.reflect.VMField.xxx (Native Method)
141 [1] java.lang.reflect.Field.xxx
145 if (!access_check_field(f, 2))
149 /* some general checks */
151 if (f->flags & ACC_STATIC) {
152 /* initialize class if required */
154 if (!(c->state & CLASS_INITIALIZED))
155 if (!initialize_class(c))
158 /* everything is ok */
163 /* obj is required for not-static fields */
166 exceptions_throw_nullpointerexception();
170 if (builtin_instanceof(o, c))
176 exceptions_throw_illegalargumentexception();
181 /* _field_get_type *************************************************************
183 Returns the content of the given field.
185 *******************************************************************************/
187 #define _FIELD_GET_TYPE(name, type, uniontype) \
188 static inline type _field_get_##name(fieldinfo *f, java_lang_Object *o) \
191 if (f->flags & ACC_STATIC) { \
192 ret = f->value->uniontype; \
194 LLNI_CRITICAL_START; \
195 ret = *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset); \
201 static inline java_handle_t *_field_get_handle(fieldinfo *f, java_lang_Object *o)
208 if (f->flags & ACC_STATIC) {
211 obj = *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset);
214 hdl = LLNI_WRAP(obj);
221 _FIELD_GET_TYPE(int, int32_t, i)
222 _FIELD_GET_TYPE(long, int64_t, l)
223 _FIELD_GET_TYPE(float, float, f)
224 _FIELD_GET_TYPE(double, double, d)
227 /* _field_set_type *************************************************************
229 Sets the content of the given field to the given value.
231 *******************************************************************************/
233 #define _FIELD_SET_TYPE(name, type, uniontype) \
234 static inline void _field_set_##name(fieldinfo *f, java_lang_Object *o, type value) \
236 if (f->flags & ACC_STATIC) { \
237 f->value->uniontype = value; \
239 LLNI_CRITICAL_START; \
240 *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = value; \
245 static inline void _field_set_handle(fieldinfo *f, java_lang_Object *o, java_handle_t *value)
249 if (f->flags & ACC_STATIC) {
250 f->value->a = LLNI_DIRECT(value);
252 *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = LLNI_DIRECT(value);
258 _FIELD_SET_TYPE(int, int32_t, i)
259 _FIELD_SET_TYPE(long, int64_t, l)
260 _FIELD_SET_TYPE(float, float, f)
261 _FIELD_SET_TYPE(double, double, d)
265 * Class: java/lang/reflect/VMField
266 * Method: getModifiersInternal
269 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getModifiersInternal(JNIEnv *env, java_lang_reflect_VMField *this)
275 LLNI_field_get_cls(this, clazz, c);
276 LLNI_field_get_val(this, slot , slot);
277 f = &(c->fields[slot]);
284 * Class: java/lang/reflect/VMField
286 * Signature: ()Ljava/lang/Class;
288 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_VMField_getType(JNIEnv *env, java_lang_reflect_VMField *this)
295 LLNI_field_get_cls(this, clazz, c);
296 LLNI_field_get_val(this, slot , slot);
297 desc = c->fields[slot].parseddesc;
302 if (!resolve_class_from_typedesc(desc, true, false, &ret))
305 return LLNI_classinfo_wrap(ret);
310 * Class: java/lang/reflect/VMField
312 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
314 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_VMField_get(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o)
320 java_handle_t *object;
322 LLNI_field_get_cls(this, clazz, c);
323 LLNI_field_get_val(this, slot , slot);
324 f = &c->fields[slot];
326 /* check if the field can be accessed */
328 if (!_field_access_check(this, f, c, (java_handle_t *) o))
331 switch (f->parseddesc->decltype) {
332 case PRIMITIVETYPE_BOOLEAN:
333 case PRIMITIVETYPE_BYTE:
334 case PRIMITIVETYPE_CHAR:
335 case PRIMITIVETYPE_SHORT:
336 case PRIMITIVETYPE_INT:
337 value.i = _field_get_int(f, o);
340 case PRIMITIVETYPE_LONG:
341 value.l = _field_get_long(f, o);
344 case PRIMITIVETYPE_FLOAT:
345 value.f = _field_get_float(f, o);
348 case PRIMITIVETYPE_DOUBLE:
349 value.d = _field_get_double(f, o);
353 return (java_lang_Object *) _field_get_handle(f, o);
356 /* Now box the primitive types. */
358 object = primitive_box(f->parseddesc->decltype, value);
360 return (java_lang_Object *) object;
365 * Class: java/lang/reflect/VMField
367 * Signature: (Ljava/lang/Object;)Z
369 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getBoolean(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o)
375 /* get the class and the field */
377 LLNI_field_get_cls(this, clazz, c);
378 LLNI_field_get_val(this, slot , slot);
379 f = &c->fields[slot];
381 /* check if the field can be accessed */
383 if (!_field_access_check(this, f, c, (java_handle_t *) o))
386 /* check the field type and return the value */
388 switch (f->parseddesc->decltype) {
389 case PRIMITIVETYPE_BOOLEAN:
390 return (int32_t) _field_get_int(f, o);
392 exceptions_throw_illegalargumentexception();
399 * Class: java/lang/reflect/VMField
401 * Signature: (Ljava/lang/Object;)B
403 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getByte(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o)
409 /* get the class and the field */
411 LLNI_field_get_cls(this, clazz, c);
412 LLNI_field_get_val(this, slot , slot);
413 f = &c->fields[slot];
415 /* check if the field can be accessed */
417 if (!_field_access_check(this, f, c, (java_handle_t *) o))
420 /* check the field type and return the value */
422 switch (f->parseddesc->decltype) {
423 case PRIMITIVETYPE_BYTE:
424 return (int32_t) _field_get_int(f, o);
426 exceptions_throw_illegalargumentexception();
433 * Class: java/lang/reflect/VMField
435 * Signature: (Ljava/lang/Object;)C
437 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getChar(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o)
443 /* get the class and the field */
445 LLNI_field_get_cls(this, clazz, c);
446 LLNI_field_get_val(this, slot , slot);
447 f = &c->fields[slot];
449 /* check if the field can be accessed */
451 if (!_field_access_check(this, f, c, (java_handle_t *) o))
454 /* check the field type and return the value */
456 switch (f->parseddesc->decltype) {
457 case PRIMITIVETYPE_CHAR:
458 return (int32_t) _field_get_int(f, o);
460 exceptions_throw_illegalargumentexception();
467 * Class: java/lang/reflect/VMField
469 * Signature: (Ljava/lang/Object;)S
471 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getShort(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o)
477 /* get the class and the field */
479 LLNI_field_get_cls(this, clazz, c);
480 LLNI_field_get_val(this, slot , slot);
481 f = &c->fields[slot];
483 /* check if the field can be accessed */
485 if (!_field_access_check(this, f, c, (java_handle_t *) o))
488 /* check the field type and return the value */
490 switch (f->parseddesc->decltype) {
491 case PRIMITIVETYPE_BYTE:
492 case PRIMITIVETYPE_SHORT:
493 return (int32_t) _field_get_int(f, o);
495 exceptions_throw_illegalargumentexception();
502 * Class: java/lang/reflect/VMField
504 * Signature: (Ljava/lang/Object;)I
506 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getInt(JNIEnv *env , java_lang_reflect_VMField *this, java_lang_Object *o)
512 /* get the class and the field */
514 LLNI_field_get_cls(this, clazz, c);
515 LLNI_field_get_val(this, slot , slot);
516 f = &c->fields[slot];
518 /* check if the field can be accessed */
520 if (!_field_access_check(this, f, c, (java_handle_t *) o))
523 /* check the field type and return the value */
525 switch (f->parseddesc->decltype) {
526 case PRIMITIVETYPE_BYTE:
527 case PRIMITIVETYPE_CHAR:
528 case PRIMITIVETYPE_SHORT:
529 case PRIMITIVETYPE_INT:
530 return (int32_t) _field_get_int(f, o);
532 exceptions_throw_illegalargumentexception();
539 * Class: java/lang/reflect/VMField
541 * Signature: (Ljava/lang/Object;)J
543 JNIEXPORT int64_t JNICALL Java_java_lang_reflect_VMField_getLong(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o)
549 /* get the class and the field */
551 LLNI_field_get_cls(this, clazz, c);
552 LLNI_field_get_val(this, slot , slot);
553 f = &c->fields[slot];
555 /* check if the field can be accessed */
557 if (!_field_access_check(this, f, c, (java_handle_t *) o))
560 /* check the field type and return the value */
562 switch (f->parseddesc->decltype) {
563 case PRIMITIVETYPE_BYTE:
564 case PRIMITIVETYPE_CHAR:
565 case PRIMITIVETYPE_SHORT:
566 case PRIMITIVETYPE_INT:
567 return (int64_t) _field_get_int(f, o);
568 case PRIMITIVETYPE_LONG:
569 return (int64_t) _field_get_long(f, o);
571 exceptions_throw_illegalargumentexception();
578 * Class: java/lang/reflect/VMField
580 * Signature: (Ljava/lang/Object;)F
582 JNIEXPORT float JNICALL Java_java_lang_reflect_VMField_getFloat(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o)
588 /* get the class and the field */
590 LLNI_field_get_cls(this, clazz, c);
591 LLNI_field_get_val(this, slot , slot);
592 f = &c->fields[slot];
594 /* check if the field can be accessed */
596 if (!_field_access_check(this, f, c, (java_handle_t *) o))
599 /* check the field type and return the value */
601 switch (f->parseddesc->decltype) {
602 case PRIMITIVETYPE_BYTE:
603 case PRIMITIVETYPE_CHAR:
604 case PRIMITIVETYPE_SHORT:
605 case PRIMITIVETYPE_INT:
606 return (float) _field_get_int(f, o);
607 case PRIMITIVETYPE_LONG:
608 return (float) _field_get_long(f, o);
609 case PRIMITIVETYPE_FLOAT:
610 return (float) _field_get_float(f, o);
612 exceptions_throw_illegalargumentexception();
619 * Class: java/lang/reflect/VMField
621 * Signature: (Ljava/lang/Object;)D
623 JNIEXPORT double JNICALL Java_java_lang_reflect_VMField_getDouble(JNIEnv *env , java_lang_reflect_VMField *this, java_lang_Object *o)
629 /* get the class and the field */
631 LLNI_field_get_cls(this, clazz, c);
632 LLNI_field_get_val(this, slot , slot);
633 f = &c->fields[slot];
635 /* check if the field can be accessed */
637 if (!_field_access_check(this, f, c, (java_handle_t *) o))
640 /* check the field type and return the value */
642 switch (f->parseddesc->decltype) {
643 case PRIMITIVETYPE_BYTE:
644 case PRIMITIVETYPE_CHAR:
645 case PRIMITIVETYPE_SHORT:
646 case PRIMITIVETYPE_INT:
647 return (double) _field_get_int(f, o);
648 case PRIMITIVETYPE_LONG:
649 return (double) _field_get_long(f, o);
650 case PRIMITIVETYPE_FLOAT:
651 return (double) _field_get_float(f, o);
652 case PRIMITIVETYPE_DOUBLE:
653 return (double) _field_get_double(f, o);
655 exceptions_throw_illegalargumentexception();
662 * Class: java/lang/reflect/VMField
664 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
666 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o, java_lang_Object *value)
674 /* get the class and the field */
676 LLNI_field_get_cls(this, clazz, dc);
677 LLNI_field_get_val(this, slot , slot);
678 df = &dc->fields[slot];
680 /* check if the field can be accessed */
682 if (!_field_access_check(this, df, dc, (java_handle_t *) o))
685 /* get the source classinfo from the object */
690 LLNI_class_get(value, sc);
692 /* The fieldid is used to set the new value, for primitive
693 types the value has to be retrieved from the wrapping
696 switch (df->parseddesc->decltype) {
697 case PRIMITIVETYPE_BOOLEAN: {
700 /* determine the field to read the value */
702 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
705 switch (sf->parseddesc->decltype) {
706 case PRIMITIVETYPE_BOOLEAN:
707 LLNI_field_get_val((java_lang_Boolean *) value, value, val);
710 exceptions_throw_illegalargumentexception();
714 _field_set_int(df, o, val);
718 case PRIMITIVETYPE_BYTE: {
721 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
724 switch (sf->parseddesc->decltype) {
725 case PRIMITIVETYPE_BYTE:
726 LLNI_field_get_val((java_lang_Byte *) value, value, val);
729 exceptions_throw_illegalargumentexception();
733 _field_set_int(df, o, val);
737 case PRIMITIVETYPE_CHAR: {
740 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
743 switch (sf->parseddesc->decltype) {
744 case PRIMITIVETYPE_CHAR:
745 LLNI_field_get_val((java_lang_Character *) value, value, val);
748 exceptions_throw_illegalargumentexception();
752 _field_set_int(df, o, val);
756 case PRIMITIVETYPE_SHORT: {
759 /* get field only by name, it can be one of B, S */
761 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
764 switch (sf->parseddesc->decltype) {
765 case PRIMITIVETYPE_BYTE:
766 LLNI_field_get_val((java_lang_Byte *) value, value, val);
768 case PRIMITIVETYPE_SHORT:
769 LLNI_field_get_val((java_lang_Short *) value, value, val);
772 exceptions_throw_illegalargumentexception();
776 _field_set_int(df, o, val);
780 case PRIMITIVETYPE_INT: {
783 /* get field only by name, it can be one of B, S, C, I */
785 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
788 switch (sf->parseddesc->decltype) {
789 case PRIMITIVETYPE_BYTE:
790 LLNI_field_get_val((java_lang_Byte *) value, value, val);
792 case PRIMITIVETYPE_CHAR:
793 LLNI_field_get_val((java_lang_Character *) value, value, val);
795 case PRIMITIVETYPE_SHORT:
796 LLNI_field_get_val((java_lang_Short *) value, value, val);
798 case PRIMITIVETYPE_INT:
799 LLNI_field_get_val((java_lang_Integer *) value, value, val);
802 exceptions_throw_illegalargumentexception();
806 _field_set_int(df, o, val);
810 case PRIMITIVETYPE_LONG: {
813 /* get field only by name, it can be one of B, S, C, I, J */
815 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
818 switch (sf->parseddesc->decltype) {
819 case PRIMITIVETYPE_BYTE:
820 LLNI_field_get_val((java_lang_Byte *) value, value, val);
822 case PRIMITIVETYPE_CHAR:
823 LLNI_field_get_val((java_lang_Character *) value, value, val);
825 case PRIMITIVETYPE_SHORT:
826 LLNI_field_get_val((java_lang_Short *) value, value, val);
828 case PRIMITIVETYPE_INT:
829 LLNI_field_get_val((java_lang_Integer *) value, value, val);
831 case PRIMITIVETYPE_LONG:
832 LLNI_field_get_val((java_lang_Long *) value, value, val);
835 exceptions_throw_illegalargumentexception();
839 _field_set_long(df, o, val);
843 case PRIMITIVETYPE_FLOAT: {
846 /* get field only by name, it can be one of B, S, C, I, J, F */
848 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
851 switch (sf->parseddesc->decltype) {
852 case PRIMITIVETYPE_BYTE:
853 LLNI_field_get_val((java_lang_Byte *) value, value, val);
855 case PRIMITIVETYPE_CHAR:
856 LLNI_field_get_val((java_lang_Character *) value, value, val);
858 case PRIMITIVETYPE_SHORT:
859 LLNI_field_get_val((java_lang_Short *) value, value, val);
861 case PRIMITIVETYPE_INT:
862 LLNI_field_get_val((java_lang_Integer *) value, value, val);
864 case PRIMITIVETYPE_LONG:
865 LLNI_field_get_val((java_lang_Long *) value, value, val);
867 case PRIMITIVETYPE_FLOAT:
868 LLNI_field_get_val((java_lang_Float *) value, value, val);
871 exceptions_throw_illegalargumentexception();
875 _field_set_float(df, o, val);
879 case PRIMITIVETYPE_DOUBLE: {
882 /* get field only by name, it can be one of B, S, C, I, J, F, D */
884 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
887 switch (sf->parseddesc->decltype) {
888 case PRIMITIVETYPE_BYTE:
889 LLNI_field_get_val((java_lang_Byte *) value, value, val);
891 case PRIMITIVETYPE_CHAR:
892 LLNI_field_get_val((java_lang_Character *) value, value, val);
894 case PRIMITIVETYPE_SHORT:
895 LLNI_field_get_val((java_lang_Short *) value, value, val);
897 case PRIMITIVETYPE_INT:
898 LLNI_field_get_val((java_lang_Integer *) value, value, val);
900 case PRIMITIVETYPE_LONG:
901 LLNI_field_get_val((java_lang_Long *) value, value, val);
903 case PRIMITIVETYPE_FLOAT:
904 LLNI_field_get_val((java_lang_Float *) value, value, val);
906 case PRIMITIVETYPE_DOUBLE:
907 LLNI_field_get_val((java_lang_Double *) value, value, val);
910 exceptions_throw_illegalargumentexception();
914 _field_set_double(df, o, val);
919 /* check if value is an instance of the destination class */
922 /* if (!builtin_instanceof((java_handle_t *) value, df->class)) */
925 _field_set_handle(df, o, (java_handle_t *) value);
929 /* raise exception */
931 exceptions_throw_illegalargumentexception();
936 * Class: java/lang/reflect/VMField
938 * Signature: (Ljava/lang/Object;Z)V
940 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setBoolean(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o, int32_t value)
946 /* get the class and the field */
948 LLNI_field_get_cls(this, clazz, c);
949 LLNI_field_get_val(this, slot , slot);
950 f = &c->fields[slot];
952 /* check if the field can be accessed */
954 if (!_field_access_check(this, f, c, (java_handle_t *) o))
957 /* check the field type and set the value */
959 switch (f->parseddesc->decltype) {
960 case PRIMITIVETYPE_BOOLEAN:
961 _field_set_int(f, o, value);
964 exceptions_throw_illegalargumentexception();
972 * Class: java/lang/reflect/VMField
974 * Signature: (Ljava/lang/Object;B)V
976 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setByte(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o, int32_t value)
982 /* get the class and the field */
984 LLNI_field_get_cls(this, clazz, c);
985 LLNI_field_get_val(this, slot , slot);
986 f = &c->fields[slot];
988 /* check if the field can be accessed */
990 if (!_field_access_check(this, f, c, (java_handle_t *) o))
993 /* check the field type and set the value */
995 switch (f->parseddesc->decltype) {
996 case PRIMITIVETYPE_BYTE:
997 case PRIMITIVETYPE_SHORT:
998 case PRIMITIVETYPE_INT:
999 _field_set_int(f, o, value);
1001 case PRIMITIVETYPE_LONG:
1002 _field_set_long(f, o, value);
1004 case PRIMITIVETYPE_FLOAT:
1005 _field_set_float(f, o, value);
1007 case PRIMITIVETYPE_DOUBLE:
1008 _field_set_double(f, o, value);
1011 exceptions_throw_illegalargumentexception();
1019 * Class: java/lang/reflect/VMField
1021 * Signature: (Ljava/lang/Object;C)V
1023 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setChar(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o, int32_t value)
1029 /* get the class and the field */
1031 LLNI_field_get_cls(this, clazz, c);
1032 LLNI_field_get_val(this, slot , slot);
1033 f = &c->fields[slot];
1035 /* check if the field can be accessed */
1037 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1040 /* check the field type and set the value */
1042 switch (f->parseddesc->decltype) {
1043 case PRIMITIVETYPE_CHAR:
1044 case PRIMITIVETYPE_INT:
1045 _field_set_int(f, o, value);
1047 case PRIMITIVETYPE_LONG:
1048 _field_set_long(f, o, value);
1050 case PRIMITIVETYPE_FLOAT:
1051 _field_set_float(f, o, value);
1053 case PRIMITIVETYPE_DOUBLE:
1054 _field_set_double(f, o, value);
1057 exceptions_throw_illegalargumentexception();
1065 * Class: java/lang/reflect/VMField
1067 * Signature: (Ljava/lang/Object;S)V
1069 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setShort(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o, int32_t value)
1075 /* get the class and the field */
1077 LLNI_field_get_cls(this, clazz, c);
1078 LLNI_field_get_val(this, slot , slot);
1079 f = &c->fields[slot];
1081 /* check if the field can be accessed */
1083 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1086 /* check the field type and set the value */
1088 switch (f->parseddesc->decltype) {
1089 case PRIMITIVETYPE_SHORT:
1090 case PRIMITIVETYPE_INT:
1091 _field_set_int(f, o, value);
1093 case PRIMITIVETYPE_LONG:
1094 _field_set_long(f, o, value);
1096 case PRIMITIVETYPE_FLOAT:
1097 _field_set_float(f, o, value);
1099 case PRIMITIVETYPE_DOUBLE:
1100 _field_set_double(f, o, value);
1103 exceptions_throw_illegalargumentexception();
1111 * Class: java/lang/reflect/VMField
1113 * Signature: (Ljava/lang/Object;I)V
1115 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setInt(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o, int32_t value)
1121 /* get the class and the field */
1123 LLNI_field_get_cls(this, clazz, c);
1124 LLNI_field_get_val(this, slot , slot);
1125 f = &c->fields[slot];
1127 /* check if the field can be accessed */
1129 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1132 /* check the field type and set the value */
1134 switch (f->parseddesc->decltype) {
1135 case PRIMITIVETYPE_INT:
1136 _field_set_int(f, o, value);
1138 case PRIMITIVETYPE_LONG:
1139 _field_set_long(f, o, value);
1141 case PRIMITIVETYPE_FLOAT:
1142 _field_set_float(f, o, value);
1144 case PRIMITIVETYPE_DOUBLE:
1145 _field_set_double(f, o, value);
1148 exceptions_throw_illegalargumentexception();
1156 * Class: java/lang/reflect/VMField
1158 * Signature: (Ljava/lang/Object;J)V
1160 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setLong(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o, int64_t value)
1166 /* get the class and the field */
1168 LLNI_field_get_cls(this, clazz, c);
1169 LLNI_field_get_val(this, slot , slot);
1170 f = &c->fields[slot];
1172 /* check if the field can be accessed */
1174 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1177 /* check the field type and set the value */
1179 switch (f->parseddesc->decltype) {
1180 case PRIMITIVETYPE_LONG:
1181 _field_set_long(f, o, value);
1183 case PRIMITIVETYPE_FLOAT:
1184 _field_set_float(f, o, value);
1186 case PRIMITIVETYPE_DOUBLE:
1187 _field_set_double(f, o, value);
1190 exceptions_throw_illegalargumentexception();
1198 * Class: java/lang/reflect/VMField
1200 * Signature: (Ljava/lang/Object;F)V
1202 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setFloat(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o, float value)
1208 /* get the class and the field */
1210 LLNI_field_get_cls(this, clazz, c);
1211 LLNI_field_get_val(this, slot , slot);
1212 f = &c->fields[slot];
1214 /* check if the field can be accessed */
1216 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1219 /* check the field type and set the value */
1221 switch (f->parseddesc->decltype) {
1222 case PRIMITIVETYPE_FLOAT:
1223 _field_set_float(f, o, value);
1225 case PRIMITIVETYPE_DOUBLE:
1226 _field_set_double(f, o, value);
1229 exceptions_throw_illegalargumentexception();
1237 * Class: java/lang/reflect/VMField
1239 * Signature: (Ljava/lang/Object;D)V
1241 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setDouble(JNIEnv *env, java_lang_reflect_VMField *this, java_lang_Object *o, double value)
1247 /* get the class and the field */
1249 LLNI_field_get_cls(this, clazz, c);
1250 LLNI_field_get_val(this, slot , slot);
1251 f = &c->fields[slot];
1253 /* check if the field can be accessed */
1255 if (!_field_access_check(this, f, c, (java_handle_t *) o))
1258 /* check the field type and set the value */
1260 switch (f->parseddesc->decltype) {
1261 case PRIMITIVETYPE_DOUBLE:
1262 _field_set_double(f, o, value);
1265 exceptions_throw_illegalargumentexception();
1273 * Class: java/lang/reflect/VMField
1274 * Method: getSignature
1275 * Signature: ()Ljava/lang/String;
1277 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_VMField_getSignature(JNIEnv *env, java_lang_reflect_VMField* this)
1284 /* get the class and the field */
1286 LLNI_field_get_cls(this, clazz, c);
1287 LLNI_field_get_val(this, slot , slot);
1288 f = &c->fields[slot];
1290 if (f->signature == NULL)
1293 o = javastring_new(f->signature);
1295 /* in error case o is NULL */
1297 return (java_lang_String *) o;
1301 #if defined(ENABLE_ANNOTATIONS)
1303 * Class: java/lang/reflect/VMField
1304 * Method: declaredAnnotations
1305 * Signature: ()Ljava/util/Map;
1307 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_VMField_declaredAnnotations(JNIEnv *env, java_lang_reflect_VMField *this)
1309 java_util_Map *declaredAnnotations = NULL; /* parsed annotations */
1310 java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
1311 java_lang_Class *declaringClass = NULL; /* the constant pool of this class is used */
1312 classinfo *referer = NULL; /* class, which calles the annotation parser */
1313 /* (for the parameter 'referer' of vm_call_method()) */
1315 LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
1317 /* are the annotations parsed yet? */
1318 if (declaredAnnotations == NULL) {
1319 LLNI_field_get_ref(this, annotations, annotations);
1320 LLNI_field_get_ref(this, clazz, declaringClass);
1321 LLNI_class_get(this, referer);
1323 declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
1325 LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
1328 return declaredAnnotations;
1334 * These are local overrides for various environment variables in Emacs.
1335 * Please do not remove this and leave it at the end of the file, where
1336 * Emacs will automagically detect them.
1337 * ---------------------------------------------------------------------
1340 * indent-tabs-mode: t
1344 * vim:noexpandtab:sw=4:ts=4: