1 /* src/native/vm/Field.c - java/lang/reflect/Field
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Roman Obermaiser
29 Changes: Joseph Wenninger
32 $Id: Field.c 3672 2005-11-15 23:43:17Z twisti $
42 #include "native/jni.h"
43 #include "native/native.h"
44 #include "native/include/java_lang_Boolean.h"
45 #include "native/include/java_lang_Byte.h"
46 #include "native/include/java_lang_Character.h"
47 #include "native/include/java_lang_Short.h"
48 #include "native/include/java_lang_Integer.h"
49 #include "native/include/java_lang_Long.h"
50 #include "native/include/java_lang_Float.h"
51 #include "native/include/java_lang_Double.h"
52 #include "native/include/java_lang_Object.h"
53 #include "native/include/java_lang_Class.h"
54 #include "native/include/java_lang_reflect_Field.h"
55 #include "vm/access.h"
56 #include "vm/builtin.h"
57 #include "vm/exceptions.h"
58 #include "vm/global.h"
59 #include "vm/initialize.h"
60 #include "vm/loader.h"
61 #include "vm/resolve.h"
62 #include "vm/stringlocal.h"
63 #include "vm/tables.h"
65 #include "vm/jit/stacktrace.h"
68 #define CHECKFIELDACCESS(this,fi,c,doret)
71 /* cacao_get_field_address *****************************************************
75 *******************************************************************************/
77 static void *cacao_get_field_address(java_lang_reflect_Field *this,
83 classinfo *callerclass;
85 c = (classinfo *) this->declaringClass;
86 f = &c->fields[this->slot];
88 /* check field access */
90 if (!(f->flags & ACC_PUBLIC)) {
91 /* check if we should bypass security checks (AccessibleObject) */
93 if (this->flag == false) {
94 /* get the calling class */
96 oa = cacao_createClassContextArray();
98 /* this function is always called like this:
100 java.lang.reflect.Field.xxx (Native Method)
104 callerclass = (classinfo *) oa->data[0];
106 if (!access_is_accessible_member(callerclass, c, f->flags)) {
108 new_exception(string_java_lang_IllegalAccessException);
114 /* get the address of the field */
116 if (f->flags & ACC_STATIC) {
117 /* initialize class if required */
119 if (!initialize_class(c))
122 /* return value address */
127 /* obj is required for not-static fields */
130 *exceptionptr = new_nullpointerexception();
134 if (builtin_instanceof((java_objectheader *) o, c))
135 return (void *) ((ptrint) o + f->offset);
140 *exceptionptr = new_illegalargumentexception();
147 * Class: java/lang/reflect/Field
149 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
151 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
157 c = (classinfo *) this->declaringClass;
158 f = &c->fields[this->slot];
160 /* get address of the source field value */
162 if ((addr = cacao_get_field_address(this, o)) == NULL)
165 switch (f->parseddesc->decltype) {
166 case PRIMITIVETYPE_BOOLEAN: {
167 java_lang_Boolean *bo;
169 /* create wrapping class */
171 if (!(bo = (java_lang_Boolean *) builtin_new(class_java_lang_Boolean)))
174 /* set the object value */
176 bo->value = *((s4 *) addr);
178 /* return the wrapped object */
180 return (java_lang_Object *) bo;
183 case PRIMITIVETYPE_BYTE: {
186 if (!(bo = (java_lang_Byte *) builtin_new(class_java_lang_Byte)))
189 bo->value = *((s4 *) addr);
191 return (java_lang_Object *) bo;
194 case PRIMITIVETYPE_CHAR: {
195 java_lang_Character *co;
197 if (!(co = (java_lang_Character *) builtin_new(class_java_lang_Character)))
200 co->value = *((s4 *) addr);
202 return (java_lang_Object *) co;
205 case PRIMITIVETYPE_SHORT: {
208 if (!(so = (java_lang_Short *) builtin_new(class_java_lang_Short)))
211 so->value = (s4) *((s4 *) addr);
213 return (java_lang_Object *) so;
216 case PRIMITIVETYPE_INT: {
217 java_lang_Integer *io;
219 if (!(io = (java_lang_Integer *) builtin_new(class_java_lang_Integer)))
222 io->value = *((s4 *) addr);
224 return (java_lang_Object *) io;
227 case PRIMITIVETYPE_LONG: {
230 if (!(lo = (java_lang_Long *) builtin_new(class_java_lang_Long)))
233 lo->value = *((s8 *) addr);
235 return (java_lang_Object *) lo;
238 case PRIMITIVETYPE_FLOAT: {
241 if (!(fo = (java_lang_Float *) builtin_new(class_java_lang_Float)))
244 fo->value = *((float *) addr);
246 return (java_lang_Object *) fo;
249 case PRIMITIVETYPE_DOUBLE: {
250 java_lang_Double *_do;
252 if (!(_do = (java_lang_Double *) builtin_new(class_java_lang_Double)))
255 _do->value = *((double *) addr);
257 return (java_lang_Object *) _do;
261 return (java_lang_Object *) *((java_objectheader **) addr);
264 /* this must not happen */
268 /* keep compiler happy */
275 * Class: java/lang/reflect/Field
277 * Signature: (Ljava/lang/Object;)Z
279 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
285 /* get the class and the field */
287 c = (classinfo *) this->declaringClass;
288 f = &c->fields[this->slot];
290 /* get the address of the field with an internal helper */
292 if ((addr = cacao_get_field_address(this, o)) == NULL)
295 /* check the field type and return the value */
297 switch (f->parseddesc->decltype) {
298 case PRIMITIVETYPE_BOOLEAN:
299 return (s4) *((s4 *) addr);
301 *exceptionptr = new_illegalargumentexception();
308 * Class: java/lang/reflect/Field
310 * Signature: (Ljava/lang/Object;)B
312 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
318 /* get the class and the field */
320 c = (classinfo *) this->declaringClass;
321 f = &c->fields[this->slot];
323 /* get the address of the field with an internal helper */
325 if ((addr = cacao_get_field_address(this, o)) == NULL)
328 /* check the field type and return the value */
330 switch (f->parseddesc->decltype) {
331 case PRIMITIVETYPE_BYTE:
332 return (s4) *((s4 *) addr);
334 *exceptionptr = new_illegalargumentexception();
341 * Class: java/lang/reflect/Field
343 * Signature: (Ljava/lang/Object;)C
345 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
351 /* get the class and the field */
353 c = (classinfo *) this->declaringClass;
354 f = &c->fields[this->slot];
356 /* get the address of the field with an internal helper */
358 if ((addr = cacao_get_field_address(this, o)) == NULL)
361 /* check the field type and return the value */
363 switch (f->parseddesc->decltype) {
364 case PRIMITIVETYPE_CHAR:
365 return (s4) *((s4 *) addr);
367 *exceptionptr = new_illegalargumentexception();
374 * Class: java/lang/reflect/Field
376 * Signature: (Ljava/lang/Object;)S
378 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
384 /* get the class and the field */
386 c = (classinfo *) this->declaringClass;
387 f = &c->fields[this->slot];
389 /* get the address of the field with an internal helper */
391 if ((addr = cacao_get_field_address(this, o)) == NULL)
394 /* check the field type and return the value */
396 switch (f->parseddesc->decltype) {
397 case PRIMITIVETYPE_BYTE:
398 case PRIMITIVETYPE_SHORT:
399 return (s4) *((s4 *) addr);
401 *exceptionptr = new_illegalargumentexception();
408 * Class: java/lang/reflect/Field
410 * Signature: (Ljava/lang/Object;)I
412 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
418 /* get the class and the field */
420 c = (classinfo *) this->declaringClass;
421 f = &c->fields[this->slot];
423 /* get the address of the field with an internal helper */
425 if ((addr = cacao_get_field_address(this, o)) == NULL)
428 /* check the field type and return the value */
430 switch (f->parseddesc->decltype) {
431 case PRIMITIVETYPE_BYTE:
432 case PRIMITIVETYPE_CHAR:
433 case PRIMITIVETYPE_SHORT:
434 case PRIMITIVETYPE_INT:
435 return (s4) *((s4 *) addr);
437 *exceptionptr = new_illegalargumentexception();
444 * Class: java/lang/reflect/Field
446 * Signature: (Ljava/lang/Object;)J
448 JNIEXPORT s8 JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
454 /* get the class and the field */
456 c = (classinfo *) this->declaringClass;
457 f = &c->fields[this->slot];
459 /* get the address of the field with an internal helper */
461 if ((addr = cacao_get_field_address(this, o)) == NULL)
464 /* check the field type and return the value */
466 switch (f->parseddesc->decltype) {
467 case PRIMITIVETYPE_BYTE:
468 case PRIMITIVETYPE_CHAR:
469 case PRIMITIVETYPE_SHORT:
470 case PRIMITIVETYPE_INT:
471 return (s8) *((s4 *) addr);
472 case PRIMITIVETYPE_LONG:
473 return (s8) *((s8 *) addr);
475 *exceptionptr = new_illegalargumentexception();
482 * Class: java/lang/reflect/Field
484 * Signature: (Ljava/lang/Object;)F
486 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
492 /* get the class and the field */
494 c = (classinfo *) this->declaringClass;
495 f = &c->fields[this->slot];
497 /* get the address of the field with an internal helper */
499 if ((addr = cacao_get_field_address(this, o)) == NULL)
502 /* check the field type and return the value */
504 switch (f->parseddesc->decltype) {
505 case PRIMITIVETYPE_BYTE:
506 case PRIMITIVETYPE_CHAR:
507 case PRIMITIVETYPE_SHORT:
508 case PRIMITIVETYPE_INT:
509 return (float) *((s4 *) addr);
510 case PRIMITIVETYPE_LONG:
511 return (float) *((s8 *) addr);
512 case PRIMITIVETYPE_FLOAT:
513 return (float) *((float *) addr);
515 *exceptionptr = new_illegalargumentexception();
522 * Class: java/lang/reflect/Field
524 * Signature: (Ljava/lang/Object;)D
526 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
532 /* get the class and the field */
534 c = (classinfo *) this->declaringClass;
535 f = &c->fields[this->slot];
537 /* get the address of the field with an internal helper */
539 if ((addr = cacao_get_field_address(this, o)) == NULL)
542 /* check the field type and return the value */
544 switch (f->parseddesc->decltype) {
545 case PRIMITIVETYPE_BYTE:
546 case PRIMITIVETYPE_CHAR:
547 case PRIMITIVETYPE_SHORT:
548 case PRIMITIVETYPE_INT:
549 return (double) *((s4 *) addr);
550 case PRIMITIVETYPE_LONG:
551 return (double) *((s8 *) addr);
552 case PRIMITIVETYPE_FLOAT:
553 return (double) *((float *) addr);
554 case PRIMITIVETYPE_DOUBLE:
555 return (double) *((double *) addr);
557 *exceptionptr = new_illegalargumentexception();
564 * Class: java/lang/reflect/Field
566 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
568 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, java_lang_Object *value)
576 /* get the class and the field */
578 dc = (classinfo *) this->declaringClass;
579 df = &dc->fields[this->slot];
581 /* get the address of the destination field */
583 if ((faddr = cacao_get_field_address(this, o)) == NULL)
586 /* get the source classinfo from the object */
591 sc = value->header.vftbl->class;
593 /* The fieldid is used to set the new value, for primitive
594 types the value has to be retrieved from the wrapping
597 switch (df->parseddesc->decltype) {
598 case PRIMITIVETYPE_BOOLEAN: {
601 /* determine the field to read the value */
603 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
606 switch (sf->parseddesc->decltype) {
607 case PRIMITIVETYPE_BOOLEAN:
608 val = ((java_lang_Boolean *) value)->value;
611 *exceptionptr = new_illegalargumentexception();
615 *((s4 *) faddr) = val;
619 case PRIMITIVETYPE_BYTE: {
622 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
625 switch (sf->parseddesc->decltype) {
626 case PRIMITIVETYPE_BYTE:
627 val = ((java_lang_Byte *) value)->value;
630 *exceptionptr = new_illegalargumentexception();
634 *((s4 *) faddr) = val;
638 case PRIMITIVETYPE_CHAR: {
641 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
644 switch (sf->parseddesc->decltype) {
645 case PRIMITIVETYPE_CHAR:
646 val = ((java_lang_Character *) value)->value;
649 *exceptionptr = new_illegalargumentexception();
653 *((s4 *) faddr) = val;
657 case PRIMITIVETYPE_SHORT: {
660 /* get field only by name, it can be one of B, S */
662 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
665 switch (sf->parseddesc->decltype) {
666 case PRIMITIVETYPE_BYTE:
667 val = ((java_lang_Byte *) value)->value;
669 case PRIMITIVETYPE_SHORT:
670 val = ((java_lang_Short *) value)->value;
673 *exceptionptr = new_illegalargumentexception();
677 *((s4 *) faddr) = val;
681 case PRIMITIVETYPE_INT: {
684 /* get field only by name, it can be one of B, S, C, I */
686 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
689 switch (sf->parseddesc->decltype) {
690 case PRIMITIVETYPE_BYTE:
691 val = ((java_lang_Byte *) value)->value;
693 case PRIMITIVETYPE_CHAR:
694 val = ((java_lang_Character *) value)->value;
696 case PRIMITIVETYPE_SHORT:
697 val = ((java_lang_Short *) value)->value;
699 case PRIMITIVETYPE_INT:
700 val = ((java_lang_Integer *) value)->value;
703 *exceptionptr = new_illegalargumentexception();
707 *((s4 *) faddr) = val;
711 case PRIMITIVETYPE_LONG: {
714 /* get field only by name, it can be one of B, S, C, I, J */
716 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
719 switch (sf->parseddesc->decltype) {
720 case PRIMITIVETYPE_BYTE:
721 val = ((java_lang_Byte *) value)->value;
723 case PRIMITIVETYPE_CHAR:
724 val = ((java_lang_Character *) value)->value;
726 case PRIMITIVETYPE_SHORT:
727 val = ((java_lang_Short *) value)->value;
729 case PRIMITIVETYPE_INT:
730 val = ((java_lang_Integer *) value)->value;
732 case PRIMITIVETYPE_LONG:
733 val = ((java_lang_Long *) value)->value;
736 *exceptionptr = new_illegalargumentexception();
740 *((s8 *) faddr) = val;
744 case PRIMITIVETYPE_FLOAT: {
747 /* get field only by name, it can be one of B, S, C, I, J, F */
749 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
752 switch (sf->parseddesc->decltype) {
753 case PRIMITIVETYPE_BYTE:
754 val = ((java_lang_Byte *) value)->value;
756 case PRIMITIVETYPE_CHAR:
757 val = ((java_lang_Character *) value)->value;
759 case PRIMITIVETYPE_SHORT:
760 val = ((java_lang_Short *) value)->value;
762 case PRIMITIVETYPE_INT:
763 val = ((java_lang_Integer *) value)->value;
765 case PRIMITIVETYPE_LONG:
766 val = ((java_lang_Long *) value)->value;
768 case PRIMITIVETYPE_FLOAT:
769 val = ((java_lang_Float *) value)->value;
772 *exceptionptr = new_illegalargumentexception();
776 *((float *) faddr) = val;
780 case PRIMITIVETYPE_DOUBLE: {
783 /* get field only by name, it can be one of B, S, C, I, J, F, D */
785 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
788 switch (sf->parseddesc->decltype) {
789 case PRIMITIVETYPE_BYTE:
790 val = ((java_lang_Byte *) value)->value;
792 case PRIMITIVETYPE_CHAR:
793 val = ((java_lang_Character *) value)->value;
795 case PRIMITIVETYPE_SHORT:
796 val = ((java_lang_Short *) value)->value;
798 case PRIMITIVETYPE_INT:
799 val = ((java_lang_Integer *) value)->value;
801 case PRIMITIVETYPE_LONG:
802 val = ((java_lang_Long *) value)->value;
804 case PRIMITIVETYPE_FLOAT:
805 val = ((java_lang_Float *) value)->value;
807 case PRIMITIVETYPE_DOUBLE:
808 val = ((java_lang_Double *) value)->value;
811 *exceptionptr = new_illegalargumentexception();
815 *((double *) faddr) = val;
820 /* check if value is an instance of the destination class */
823 /* if (!builtin_instanceof((java_objectheader *) value, df->class)) */
826 *((java_lang_Object **) faddr) = value;
830 /* raise exception */
832 *exceptionptr = new_illegalargumentexception();
837 * Class: java/lang/reflect/Field
839 * Signature: (Ljava/lang/Object;Z)V
841 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
847 /* get the class and the field */
849 c = (classinfo *) this->declaringClass;
850 f = &c->fields[this->slot];
852 /* get the address of the field with an internal helper */
854 if ((addr = cacao_get_field_address(this, o)) == NULL)
857 /* check the field type and set the value */
859 switch (f->parseddesc->decltype) {
860 case PRIMITIVETYPE_BOOLEAN:
861 *((s4 *) addr) = value;
864 *exceptionptr = new_illegalargumentexception();
872 * Class: java/lang/reflect/Field
874 * Signature: (Ljava/lang/Object;B)V
876 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
882 /* get the class and the field */
884 c = (classinfo *) this->declaringClass;
885 f = &c->fields[this->slot];
887 /* get the address of the field with an internal helper */
889 if ((addr = cacao_get_field_address(this, o)) == NULL)
892 /* check the field type and set the value */
894 switch (f->parseddesc->decltype) {
895 case PRIMITIVETYPE_BYTE:
896 case PRIMITIVETYPE_SHORT:
897 case PRIMITIVETYPE_INT:
898 *((s4 *) addr) = value;
900 case PRIMITIVETYPE_LONG:
901 *((s8 *) addr) = value;
903 case PRIMITIVETYPE_FLOAT:
904 *((float *) addr) = value;
906 case PRIMITIVETYPE_DOUBLE:
907 *((double *) addr) = value;
910 *exceptionptr = new_illegalargumentexception();
918 * Class: java/lang/reflect/Field
920 * Signature: (Ljava/lang/Object;C)V
922 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
928 /* get the class and the field */
930 c = (classinfo *) this->declaringClass;
931 f = &c->fields[this->slot];
933 /* get the address of the field with an internal helper */
935 if ((addr = cacao_get_field_address(this, o)) == NULL)
938 /* check the field type and set the value */
940 switch (f->parseddesc->decltype) {
941 case PRIMITIVETYPE_CHAR:
942 case PRIMITIVETYPE_INT:
943 *((s4 *) addr) = value;
945 case PRIMITIVETYPE_LONG:
946 *((s8 *) addr) = value;
948 case PRIMITIVETYPE_FLOAT:
949 *((float *) addr) = value;
951 case PRIMITIVETYPE_DOUBLE:
952 *((double *) addr) = value;
955 *exceptionptr = new_illegalargumentexception();
963 * Class: java/lang/reflect/Field
965 * Signature: (Ljava/lang/Object;S)V
967 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
973 /* get the class and the field */
975 c = (classinfo *) this->declaringClass;
976 f = &c->fields[this->slot];
978 /* get the address of the field with an internal helper */
980 if ((addr = cacao_get_field_address(this, o)) == NULL)
983 /* check the field type and set the value */
985 switch (f->parseddesc->decltype) {
986 case PRIMITIVETYPE_SHORT:
987 case PRIMITIVETYPE_INT:
988 *((s4 *) addr) = value;
990 case PRIMITIVETYPE_LONG:
991 *((s8 *) addr) = value;
993 case PRIMITIVETYPE_FLOAT:
994 *((float *) addr) = value;
996 case PRIMITIVETYPE_DOUBLE:
997 *((double *) addr) = value;
1000 *exceptionptr = new_illegalargumentexception();
1008 * Class: java/lang/reflect/Field
1010 * Signature: (Ljava/lang/Object;I)V
1012 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
1018 /* get the class and the field */
1020 c = (classinfo *) this->declaringClass;
1021 f = &c->fields[this->slot];
1023 /* get the address of the field with an internal helper */
1025 if ((addr = cacao_get_field_address(this, o)) == NULL)
1028 /* check the field type and set the value */
1030 switch (f->parseddesc->decltype) {
1031 case PRIMITIVETYPE_INT:
1032 *((s4 *) addr) = value;
1034 case PRIMITIVETYPE_LONG:
1035 *((s8 *) addr) = value;
1037 case PRIMITIVETYPE_FLOAT:
1038 *((float *) addr) = value;
1040 case PRIMITIVETYPE_DOUBLE:
1041 *((double *) addr) = value;
1044 *exceptionptr = new_illegalargumentexception();
1052 * Class: java/lang/reflect/Field
1054 * Signature: (Ljava/lang/Object;J)V
1056 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s8 value)
1062 /* get the class and the field */
1064 c = (classinfo *) this->declaringClass;
1065 f = &c->fields[this->slot];
1067 /* get the address of the field with an internal helper */
1069 if ((addr = cacao_get_field_address(this, o)) == NULL)
1072 /* check the field type and set the value */
1074 switch (f->parseddesc->decltype) {
1075 case PRIMITIVETYPE_LONG:
1076 *((s8 *) addr) = value;
1078 case PRIMITIVETYPE_FLOAT:
1079 *((float *) addr) = value;
1081 case PRIMITIVETYPE_DOUBLE:
1082 *((double *) addr) = value;
1085 *exceptionptr = new_illegalargumentexception();
1093 * Class: java/lang/reflect/Field
1095 * Signature: (Ljava/lang/Object;F)V
1097 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, float value)
1103 /* get the class and the field */
1105 c = (classinfo *) this->declaringClass;
1106 f = &c->fields[this->slot];
1108 /* get the address of the field with an internal helper */
1110 if ((addr = cacao_get_field_address(this, o)) == NULL)
1113 /* check the field type and set the value */
1115 switch (f->parseddesc->decltype) {
1116 case PRIMITIVETYPE_FLOAT:
1117 *((float *) addr) = value;
1119 case PRIMITIVETYPE_DOUBLE:
1120 *((double *) addr) = value;
1123 *exceptionptr = new_illegalargumentexception();
1131 * Class: java/lang/reflect/Field
1133 * Signature: (Ljava/lang/Object;D)V
1135 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, double value)
1141 /* get the class and the field */
1143 c = (classinfo *) this->declaringClass;
1144 f = &c->fields[this->slot];
1146 /* get the address of the field with an internal helper */
1148 if ((addr = cacao_get_field_address(this, o)) == NULL)
1151 /* check the field type and set the value */
1153 switch (f->parseddesc->decltype) {
1154 case PRIMITIVETYPE_DOUBLE:
1155 *((double *) addr) = value;
1158 *exceptionptr = new_illegalargumentexception();
1166 * Class: java/lang/reflect/Field
1168 * Signature: ()Ljava/lang/Class;
1170 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
1176 c = (classinfo *) this->declaringClass;
1177 desc = c->fields[this->slot].parseddesc;
1182 if (!resolve_class_from_typedesc(desc, true, false, &ret))
1185 if (!use_class_as_object(ret))
1188 return (java_lang_Class *) ret;
1193 * Class: java_lang_reflect_Field
1194 * Method: getModifiers
1197 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getModifiers(JNIEnv *env, java_lang_reflect_Field *this)
1201 c = (classinfo *) this->declaringClass;
1203 return c->fields[this->slot].flags;
1208 * These are local overrides for various environment variables in Emacs.
1209 * Please do not remove this and leave it at the end of the file, where
1210 * Emacs will automagically detect them.
1211 * ---------------------------------------------------------------------
1214 * indent-tabs-mode: t