1 /* src/native/vm/gnu/java_lang_reflect_Field.c
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: java_lang_reflect_Field.c 7720 2007-04-16 15:49:09Z twisti $
36 #include "native/jni.h"
37 #include "native/native.h"
38 #include "native/include/java_lang_Boolean.h"
39 #include "native/include/java_lang_Byte.h"
40 #include "native/include/java_lang_Character.h"
41 #include "native/include/java_lang_Short.h"
42 #include "native/include/java_lang_Integer.h"
43 #include "native/include/java_lang_Long.h"
44 #include "native/include/java_lang_Float.h"
45 #include "native/include/java_lang_Double.h"
46 #include "native/include/java_lang_Object.h"
47 #include "native/include/java_lang_Class.h"
48 #include "native/include/java_lang_String.h"
49 #include "native/include/java_lang_reflect_Field.h"
51 #include "vm/access.h"
52 #include "vm/builtin.h"
53 #include "vm/exceptions.h"
54 #include "vm/global.h"
55 #include "vm/initialize.h"
56 #include "vm/stringlocal.h"
58 #include "vm/jit/stacktrace.h"
60 #include "vmcore/loader.h"
61 #include "vm/resolve.h"
62 #include "vmcore/utf8.h"
65 /* cacao_get_field_address *****************************************************
67 Return the address of a field of an object.
70 this.........the field (a java.lang.reflect.Field object)
71 o............the object of which to get the field
74 a pointer to the field, or
75 NULL if an exception has been thrown
77 *******************************************************************************/
79 static void *cacao_get_field_address(java_lang_reflect_Field *this,
85 c = (classinfo *) this->declaringClass;
86 f = &c->fields[this->slot];
88 /* check field access */
89 /* check if we should bypass security checks (AccessibleObject) */
91 if (this->flag == false) {
92 /* this function is always called like this:
94 java.lang.reflect.Field.xxx (Native Method)
97 if (!access_check_member(c, f->flags, 0))
101 /* get the address of the field */
103 if (f->flags & ACC_STATIC) {
104 /* initialize class if required */
106 if (!(c->state & CLASS_INITIALIZED))
107 if (!initialize_class(c))
110 /* return value address */
115 /* obj is required for not-static fields */
118 exceptions_throw_nullpointerexception();
122 if (builtin_instanceof((java_objectheader *) o, c))
123 return (void *) ((ptrint) o + f->offset);
128 exceptions_throw_illegalargumentexception();
135 * Class: java/lang/reflect/Field
136 * Method: getModifiersInternal
139 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getModifiersInternal(JNIEnv *env, java_lang_reflect_Field *this)
144 c = (classinfo *) this->declaringClass;
145 f = &(c->fields[this->slot]);
152 * Class: java/lang/reflect/Field
154 * Signature: ()Ljava/lang/Class;
156 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
162 c = (classinfo *) this->declaringClass;
163 desc = c->fields[this->slot].parseddesc;
168 if (!resolve_class_from_typedesc(desc, true, false, &ret))
171 return (java_lang_Class *) ret;
176 * Class: java/lang/reflect/Field
178 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
180 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
186 c = (classinfo *) this->declaringClass;
187 f = &c->fields[this->slot];
189 /* get address of the source field value */
191 if ((addr = cacao_get_field_address(this, o)) == NULL)
194 switch (f->parseddesc->decltype) {
195 case PRIMITIVETYPE_BOOLEAN: {
196 java_lang_Boolean *bo;
198 /* create wrapping class */
200 if (!(bo = (java_lang_Boolean *) builtin_new(class_java_lang_Boolean)))
203 /* set the object value */
205 bo->value = *((s4 *) addr);
207 /* return the wrapped object */
209 return (java_lang_Object *) bo;
212 case PRIMITIVETYPE_BYTE: {
215 if (!(bo = (java_lang_Byte *) builtin_new(class_java_lang_Byte)))
218 bo->value = *((s4 *) addr);
220 return (java_lang_Object *) bo;
223 case PRIMITIVETYPE_CHAR: {
224 java_lang_Character *co;
226 if (!(co = (java_lang_Character *) builtin_new(class_java_lang_Character)))
229 co->value = *((s4 *) addr);
231 return (java_lang_Object *) co;
234 case PRIMITIVETYPE_SHORT: {
237 if (!(so = (java_lang_Short *) builtin_new(class_java_lang_Short)))
240 so->value = (s4) *((s4 *) addr);
242 return (java_lang_Object *) so;
245 case PRIMITIVETYPE_INT: {
246 java_lang_Integer *io;
248 if (!(io = (java_lang_Integer *) builtin_new(class_java_lang_Integer)))
251 io->value = *((s4 *) addr);
253 return (java_lang_Object *) io;
256 case PRIMITIVETYPE_LONG: {
259 if (!(lo = (java_lang_Long *) builtin_new(class_java_lang_Long)))
262 lo->value = *((s8 *) addr);
264 return (java_lang_Object *) lo;
267 case PRIMITIVETYPE_FLOAT: {
270 if (!(fo = (java_lang_Float *) builtin_new(class_java_lang_Float)))
273 fo->value = *((float *) addr);
275 return (java_lang_Object *) fo;
278 case PRIMITIVETYPE_DOUBLE: {
279 java_lang_Double *_do;
281 if (!(_do = (java_lang_Double *) builtin_new(class_java_lang_Double)))
284 _do->value = *((double *) addr);
286 return (java_lang_Object *) _do;
290 return (java_lang_Object *) *((java_objectheader **) addr);
293 /* this must not happen */
297 /* keep compiler happy */
304 * Class: java/lang/reflect/Field
306 * Signature: (Ljava/lang/Object;)Z
308 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
314 /* get the class and the field */
316 c = (classinfo *) this->declaringClass;
317 f = &c->fields[this->slot];
319 /* get the address of the field with an internal helper */
321 if ((addr = cacao_get_field_address(this, o)) == NULL)
324 /* check the field type and return the value */
326 switch (f->parseddesc->decltype) {
327 case PRIMITIVETYPE_BOOLEAN:
328 return (s4) *((s4 *) addr);
330 exceptions_throw_illegalargumentexception();
337 * Class: java/lang/reflect/Field
339 * Signature: (Ljava/lang/Object;)B
341 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
347 /* get the class and the field */
349 c = (classinfo *) this->declaringClass;
350 f = &c->fields[this->slot];
352 /* get the address of the field with an internal helper */
354 if ((addr = cacao_get_field_address(this, o)) == NULL)
357 /* check the field type and return the value */
359 switch (f->parseddesc->decltype) {
360 case PRIMITIVETYPE_BYTE:
361 return (s4) *((s4 *) addr);
363 exceptions_throw_illegalargumentexception();
370 * Class: java/lang/reflect/Field
372 * Signature: (Ljava/lang/Object;)C
374 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
380 /* get the class and the field */
382 c = (classinfo *) this->declaringClass;
383 f = &c->fields[this->slot];
385 /* get the address of the field with an internal helper */
387 if ((addr = cacao_get_field_address(this, o)) == NULL)
390 /* check the field type and return the value */
392 switch (f->parseddesc->decltype) {
393 case PRIMITIVETYPE_CHAR:
394 return (s4) *((s4 *) addr);
396 exceptions_throw_illegalargumentexception();
403 * Class: java/lang/reflect/Field
405 * Signature: (Ljava/lang/Object;)S
407 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
413 /* get the class and the field */
415 c = (classinfo *) this->declaringClass;
416 f = &c->fields[this->slot];
418 /* get the address of the field with an internal helper */
420 if ((addr = cacao_get_field_address(this, o)) == NULL)
423 /* check the field type and return the value */
425 switch (f->parseddesc->decltype) {
426 case PRIMITIVETYPE_BYTE:
427 case PRIMITIVETYPE_SHORT:
428 return (s4) *((s4 *) addr);
430 exceptions_throw_illegalargumentexception();
437 * Class: java/lang/reflect/Field
439 * Signature: (Ljava/lang/Object;)I
441 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
447 /* get the class and the field */
449 c = (classinfo *) this->declaringClass;
450 f = &c->fields[this->slot];
452 /* get the address of the field with an internal helper */
454 if ((addr = cacao_get_field_address(this, o)) == NULL)
457 /* check the field type and return the value */
459 switch (f->parseddesc->decltype) {
460 case PRIMITIVETYPE_BYTE:
461 case PRIMITIVETYPE_CHAR:
462 case PRIMITIVETYPE_SHORT:
463 case PRIMITIVETYPE_INT:
464 return (s4) *((s4 *) addr);
466 exceptions_throw_illegalargumentexception();
473 * Class: java/lang/reflect/Field
475 * Signature: (Ljava/lang/Object;)J
477 JNIEXPORT s8 JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
483 /* get the class and the field */
485 c = (classinfo *) this->declaringClass;
486 f = &c->fields[this->slot];
488 /* get the address of the field with an internal helper */
490 if ((addr = cacao_get_field_address(this, o)) == NULL)
493 /* check the field type and return the value */
495 switch (f->parseddesc->decltype) {
496 case PRIMITIVETYPE_BYTE:
497 case PRIMITIVETYPE_CHAR:
498 case PRIMITIVETYPE_SHORT:
499 case PRIMITIVETYPE_INT:
500 return (s8) *((s4 *) addr);
501 case PRIMITIVETYPE_LONG:
502 return (s8) *((s8 *) addr);
504 exceptions_throw_illegalargumentexception();
511 * Class: java/lang/reflect/Field
513 * Signature: (Ljava/lang/Object;)F
515 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
521 /* get the class and the field */
523 c = (classinfo *) this->declaringClass;
524 f = &c->fields[this->slot];
526 /* get the address of the field with an internal helper */
528 if ((addr = cacao_get_field_address(this, o)) == NULL)
531 /* check the field type and return the value */
533 switch (f->parseddesc->decltype) {
534 case PRIMITIVETYPE_BYTE:
535 case PRIMITIVETYPE_CHAR:
536 case PRIMITIVETYPE_SHORT:
537 case PRIMITIVETYPE_INT:
538 return (float) *((s4 *) addr);
539 case PRIMITIVETYPE_LONG:
540 return (float) *((s8 *) addr);
541 case PRIMITIVETYPE_FLOAT:
542 return (float) *((float *) addr);
544 exceptions_throw_illegalargumentexception();
551 * Class: java/lang/reflect/Field
553 * Signature: (Ljava/lang/Object;)D
555 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
561 /* get the class and the field */
563 c = (classinfo *) this->declaringClass;
564 f = &c->fields[this->slot];
566 /* get the address of the field with an internal helper */
568 if ((addr = cacao_get_field_address(this, o)) == NULL)
571 /* check the field type and return the value */
573 switch (f->parseddesc->decltype) {
574 case PRIMITIVETYPE_BYTE:
575 case PRIMITIVETYPE_CHAR:
576 case PRIMITIVETYPE_SHORT:
577 case PRIMITIVETYPE_INT:
578 return (double) *((s4 *) addr);
579 case PRIMITIVETYPE_LONG:
580 return (double) *((s8 *) addr);
581 case PRIMITIVETYPE_FLOAT:
582 return (double) *((float *) addr);
583 case PRIMITIVETYPE_DOUBLE:
584 return (double) *((double *) addr);
586 exceptions_throw_illegalargumentexception();
593 * Class: java/lang/reflect/Field
595 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
597 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, java_lang_Object *value)
605 /* get the class and the field */
607 dc = (classinfo *) this->declaringClass;
608 df = &dc->fields[this->slot];
610 /* get the address of the destination field */
612 if ((faddr = cacao_get_field_address(this, o)) == NULL)
615 /* get the source classinfo from the object */
620 sc = value->header.vftbl->class;
622 /* The fieldid is used to set the new value, for primitive
623 types the value has to be retrieved from the wrapping
626 switch (df->parseddesc->decltype) {
627 case PRIMITIVETYPE_BOOLEAN: {
630 /* determine the field to read the value */
632 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
635 switch (sf->parseddesc->decltype) {
636 case PRIMITIVETYPE_BOOLEAN:
637 val = ((java_lang_Boolean *) value)->value;
640 exceptions_throw_illegalargumentexception();
644 *((s4 *) faddr) = val;
648 case PRIMITIVETYPE_BYTE: {
651 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
654 switch (sf->parseddesc->decltype) {
655 case PRIMITIVETYPE_BYTE:
656 val = ((java_lang_Byte *) value)->value;
659 exceptions_throw_illegalargumentexception();
663 *((s4 *) faddr) = val;
667 case PRIMITIVETYPE_CHAR: {
670 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
673 switch (sf->parseddesc->decltype) {
674 case PRIMITIVETYPE_CHAR:
675 val = ((java_lang_Character *) value)->value;
678 exceptions_throw_illegalargumentexception();
682 *((s4 *) faddr) = val;
686 case PRIMITIVETYPE_SHORT: {
689 /* get field only by name, it can be one of B, S */
691 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
694 switch (sf->parseddesc->decltype) {
695 case PRIMITIVETYPE_BYTE:
696 val = ((java_lang_Byte *) value)->value;
698 case PRIMITIVETYPE_SHORT:
699 val = ((java_lang_Short *) value)->value;
702 exceptions_throw_illegalargumentexception();
706 *((s4 *) faddr) = val;
710 case PRIMITIVETYPE_INT: {
713 /* get field only by name, it can be one of B, S, C, I */
715 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
718 switch (sf->parseddesc->decltype) {
719 case PRIMITIVETYPE_BYTE:
720 val = ((java_lang_Byte *) value)->value;
722 case PRIMITIVETYPE_CHAR:
723 val = ((java_lang_Character *) value)->value;
725 case PRIMITIVETYPE_SHORT:
726 val = ((java_lang_Short *) value)->value;
728 case PRIMITIVETYPE_INT:
729 val = ((java_lang_Integer *) value)->value;
732 exceptions_throw_illegalargumentexception();
736 *((s4 *) faddr) = val;
740 case PRIMITIVETYPE_LONG: {
743 /* get field only by name, it can be one of B, S, C, I, J */
745 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
748 switch (sf->parseddesc->decltype) {
749 case PRIMITIVETYPE_BYTE:
750 val = ((java_lang_Byte *) value)->value;
752 case PRIMITIVETYPE_CHAR:
753 val = ((java_lang_Character *) value)->value;
755 case PRIMITIVETYPE_SHORT:
756 val = ((java_lang_Short *) value)->value;
758 case PRIMITIVETYPE_INT:
759 val = ((java_lang_Integer *) value)->value;
761 case PRIMITIVETYPE_LONG:
762 val = ((java_lang_Long *) value)->value;
765 exceptions_throw_illegalargumentexception();
769 *((s8 *) faddr) = val;
773 case PRIMITIVETYPE_FLOAT: {
776 /* get field only by name, it can be one of B, S, C, I, J, F */
778 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
781 switch (sf->parseddesc->decltype) {
782 case PRIMITIVETYPE_BYTE:
783 val = ((java_lang_Byte *) value)->value;
785 case PRIMITIVETYPE_CHAR:
786 val = ((java_lang_Character *) value)->value;
788 case PRIMITIVETYPE_SHORT:
789 val = ((java_lang_Short *) value)->value;
791 case PRIMITIVETYPE_INT:
792 val = ((java_lang_Integer *) value)->value;
794 case PRIMITIVETYPE_LONG:
795 val = ((java_lang_Long *) value)->value;
797 case PRIMITIVETYPE_FLOAT:
798 val = ((java_lang_Float *) value)->value;
801 exceptions_throw_illegalargumentexception();
805 *((float *) faddr) = val;
809 case PRIMITIVETYPE_DOUBLE: {
812 /* get field only by name, it can be one of B, S, C, I, J, F, D */
814 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
817 switch (sf->parseddesc->decltype) {
818 case PRIMITIVETYPE_BYTE:
819 val = ((java_lang_Byte *) value)->value;
821 case PRIMITIVETYPE_CHAR:
822 val = ((java_lang_Character *) value)->value;
824 case PRIMITIVETYPE_SHORT:
825 val = ((java_lang_Short *) value)->value;
827 case PRIMITIVETYPE_INT:
828 val = ((java_lang_Integer *) value)->value;
830 case PRIMITIVETYPE_LONG:
831 val = ((java_lang_Long *) value)->value;
833 case PRIMITIVETYPE_FLOAT:
834 val = ((java_lang_Float *) value)->value;
836 case PRIMITIVETYPE_DOUBLE:
837 val = ((java_lang_Double *) value)->value;
840 exceptions_throw_illegalargumentexception();
844 *((double *) faddr) = val;
849 /* check if value is an instance of the destination class */
852 /* if (!builtin_instanceof((java_objectheader *) value, df->class)) */
855 *((java_lang_Object **) faddr) = value;
859 /* raise exception */
861 exceptions_throw_illegalargumentexception();
866 * Class: java/lang/reflect/Field
868 * Signature: (Ljava/lang/Object;Z)V
870 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
876 /* get the class and the field */
878 c = (classinfo *) this->declaringClass;
879 f = &c->fields[this->slot];
881 /* get the address of the field with an internal helper */
883 if ((addr = cacao_get_field_address(this, o)) == NULL)
886 /* check the field type and set the value */
888 switch (f->parseddesc->decltype) {
889 case PRIMITIVETYPE_BOOLEAN:
890 *((s4 *) addr) = value;
893 exceptions_throw_illegalargumentexception();
901 * Class: java/lang/reflect/Field
903 * Signature: (Ljava/lang/Object;B)V
905 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
911 /* get the class and the field */
913 c = (classinfo *) this->declaringClass;
914 f = &c->fields[this->slot];
916 /* get the address of the field with an internal helper */
918 if ((addr = cacao_get_field_address(this, o)) == NULL)
921 /* check the field type and set the value */
923 switch (f->parseddesc->decltype) {
924 case PRIMITIVETYPE_BYTE:
925 case PRIMITIVETYPE_SHORT:
926 case PRIMITIVETYPE_INT:
927 *((s4 *) addr) = value;
929 case PRIMITIVETYPE_LONG:
930 *((s8 *) addr) = value;
932 case PRIMITIVETYPE_FLOAT:
933 *((float *) addr) = value;
935 case PRIMITIVETYPE_DOUBLE:
936 *((double *) addr) = value;
939 exceptions_throw_illegalargumentexception();
947 * Class: java/lang/reflect/Field
949 * Signature: (Ljava/lang/Object;C)V
951 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
957 /* get the class and the field */
959 c = (classinfo *) this->declaringClass;
960 f = &c->fields[this->slot];
962 /* get the address of the field with an internal helper */
964 if ((addr = cacao_get_field_address(this, o)) == NULL)
967 /* check the field type and set the value */
969 switch (f->parseddesc->decltype) {
970 case PRIMITIVETYPE_CHAR:
971 case PRIMITIVETYPE_INT:
972 *((s4 *) addr) = value;
974 case PRIMITIVETYPE_LONG:
975 *((s8 *) addr) = value;
977 case PRIMITIVETYPE_FLOAT:
978 *((float *) addr) = value;
980 case PRIMITIVETYPE_DOUBLE:
981 *((double *) addr) = value;
984 exceptions_throw_illegalargumentexception();
992 * Class: java/lang/reflect/Field
994 * Signature: (Ljava/lang/Object;S)V
996 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
1002 /* get the class and the field */
1004 c = (classinfo *) this->declaringClass;
1005 f = &c->fields[this->slot];
1007 /* get the address of the field with an internal helper */
1009 if ((addr = cacao_get_field_address(this, o)) == NULL)
1012 /* check the field type and set the value */
1014 switch (f->parseddesc->decltype) {
1015 case PRIMITIVETYPE_SHORT:
1016 case PRIMITIVETYPE_INT:
1017 *((s4 *) addr) = value;
1019 case PRIMITIVETYPE_LONG:
1020 *((s8 *) addr) = value;
1022 case PRIMITIVETYPE_FLOAT:
1023 *((float *) addr) = value;
1025 case PRIMITIVETYPE_DOUBLE:
1026 *((double *) addr) = value;
1029 exceptions_throw_illegalargumentexception();
1037 * Class: java/lang/reflect/Field
1039 * Signature: (Ljava/lang/Object;I)V
1041 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
1047 /* get the class and the field */
1049 c = (classinfo *) this->declaringClass;
1050 f = &c->fields[this->slot];
1052 /* get the address of the field with an internal helper */
1054 if ((addr = cacao_get_field_address(this, o)) == NULL)
1057 /* check the field type and set the value */
1059 switch (f->parseddesc->decltype) {
1060 case PRIMITIVETYPE_INT:
1061 *((s4 *) addr) = value;
1063 case PRIMITIVETYPE_LONG:
1064 *((s8 *) addr) = value;
1066 case PRIMITIVETYPE_FLOAT:
1067 *((float *) addr) = value;
1069 case PRIMITIVETYPE_DOUBLE:
1070 *((double *) addr) = value;
1073 exceptions_throw_illegalargumentexception();
1081 * Class: java/lang/reflect/Field
1083 * Signature: (Ljava/lang/Object;J)V
1085 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s8 value)
1091 /* get the class and the field */
1093 c = (classinfo *) this->declaringClass;
1094 f = &c->fields[this->slot];
1096 /* get the address of the field with an internal helper */
1098 if ((addr = cacao_get_field_address(this, o)) == NULL)
1101 /* check the field type and set the value */
1103 switch (f->parseddesc->decltype) {
1104 case PRIMITIVETYPE_LONG:
1105 *((s8 *) addr) = value;
1107 case PRIMITIVETYPE_FLOAT:
1108 *((float *) addr) = value;
1110 case PRIMITIVETYPE_DOUBLE:
1111 *((double *) addr) = value;
1114 exceptions_throw_illegalargumentexception();
1122 * Class: java/lang/reflect/Field
1124 * Signature: (Ljava/lang/Object;F)V
1126 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, float value)
1132 /* get the class and the field */
1134 c = (classinfo *) this->declaringClass;
1135 f = &c->fields[this->slot];
1137 /* get the address of the field with an internal helper */
1139 if ((addr = cacao_get_field_address(this, o)) == NULL)
1142 /* check the field type and set the value */
1144 switch (f->parseddesc->decltype) {
1145 case PRIMITIVETYPE_FLOAT:
1146 *((float *) addr) = value;
1148 case PRIMITIVETYPE_DOUBLE:
1149 *((double *) addr) = value;
1152 exceptions_throw_illegalargumentexception();
1160 * Class: java/lang/reflect/Field
1162 * Signature: (Ljava/lang/Object;D)V
1164 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, double value)
1170 /* get the class and the field */
1172 c = (classinfo *) this->declaringClass;
1173 f = &c->fields[this->slot];
1175 /* get the address of the field with an internal helper */
1177 if ((addr = cacao_get_field_address(this, o)) == NULL)
1180 /* check the field type and set the value */
1182 switch (f->parseddesc->decltype) {
1183 case PRIMITIVETYPE_DOUBLE:
1184 *((double *) addr) = value;
1187 exceptions_throw_illegalargumentexception();
1195 * Class: java/lang/reflect/Field
1196 * Method: getSignature
1197 * Signature: ()Ljava/lang/String;
1199 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Field_getSignature(JNIEnv *env, java_lang_reflect_Field* this)
1203 java_objectheader *o;
1205 /* get the class and the field */
1207 c = (classinfo *) this->declaringClass;
1208 f = &c->fields[this->slot];
1210 if (f->signature == NULL)
1213 o = javastring_new(f->signature);
1215 /* in error case o is NULL */
1217 return (java_lang_String *) o;
1222 * These are local overrides for various environment variables in Emacs.
1223 * Please do not remove this and leave it at the end of the file, where
1224 * Emacs will automagically detect them.
1225 * ---------------------------------------------------------------------
1228 * indent-tabs-mode: t