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 7910 2007-05-16 08:02:52Z twisti $
36 #include "native/jni.h"
37 #include "native/native.h"
39 #include "native/include/java_lang_Boolean.h"
40 #include "native/include/java_lang_Byte.h"
41 #include "native/include/java_lang_Character.h"
42 #include "native/include/java_lang_Short.h"
43 #include "native/include/java_lang_Integer.h"
44 #include "native/include/java_lang_Long.h"
45 #include "native/include/java_lang_Float.h"
46 #include "native/include/java_lang_Double.h"
47 #include "native/include/java_lang_Object.h"
48 #include "native/include/java_lang_Class.h"
49 #include "native/include/java_lang_String.h"
51 #include "native/include/java_lang_reflect_Field.h"
53 #include "vm/access.h"
54 #include "vm/builtin.h"
55 #include "vm/exceptions.h"
56 #include "vm/global.h"
57 #include "vm/initialize.h"
58 #include "vm/stringlocal.h"
60 #include "vm/jit/stacktrace.h"
62 #include "vmcore/loader.h"
63 #include "vm/resolve.h"
64 #include "vmcore/utf8.h"
67 /* native methods implemented by this file ************************************/
69 static JNINativeMethod methods[] = {
70 { "getModifiersInternal", "()I", (void *) (ptrint) &Java_java_lang_reflect_Field_getModifiersInternal },
71 { "getType", "()Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Field_getType },
72 { "get", "(Ljava/lang/Object;)Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Field_get },
73 { "getBoolean", "(Ljava/lang/Object;)Z", (void *) (ptrint) &Java_java_lang_reflect_Field_getBoolean },
74 { "getByte", "(Ljava/lang/Object;)B", (void *) (ptrint) &Java_java_lang_reflect_Field_getByte },
75 { "getChar", "(Ljava/lang/Object;)C", (void *) (ptrint) &Java_java_lang_reflect_Field_getChar },
76 { "getShort", "(Ljava/lang/Object;)S", (void *) (ptrint) &Java_java_lang_reflect_Field_getShort },
77 { "getInt", "(Ljava/lang/Object;)I", (void *) (ptrint) &Java_java_lang_reflect_Field_getInt },
78 { "getLong", "(Ljava/lang/Object;)J", (void *) (ptrint) &Java_java_lang_reflect_Field_getLong },
79 { "getFloat", "(Ljava/lang/Object;)F", (void *) (ptrint) &Java_java_lang_reflect_Field_getFloat },
80 { "getDouble", "(Ljava/lang/Object;)D", (void *) (ptrint) &Java_java_lang_reflect_Field_getDouble },
81 { "set", "(Ljava/lang/Object;Ljava/lang/Object;)V", (void *) (ptrint) &Java_java_lang_reflect_Field_set },
82 { "setBoolean", "(Ljava/lang/Object;Z)V", (void *) (ptrint) &Java_java_lang_reflect_Field_setBoolean },
83 { "setByte", "(Ljava/lang/Object;B)V", (void *) (ptrint) &Java_java_lang_reflect_Field_setByte },
84 { "setChar", "(Ljava/lang/Object;C)V", (void *) (ptrint) &Java_java_lang_reflect_Field_setChar },
85 { "setShort", "(Ljava/lang/Object;S)V", (void *) (ptrint) &Java_java_lang_reflect_Field_setShort },
86 { "setInt", "(Ljava/lang/Object;I)V", (void *) (ptrint) &Java_java_lang_reflect_Field_setInt },
87 { "setLong", "(Ljava/lang/Object;J)V", (void *) (ptrint) &Java_java_lang_reflect_Field_setLong },
88 { "setFloat", "(Ljava/lang/Object;F)V", (void *) (ptrint) &Java_java_lang_reflect_Field_setFloat },
89 { "setDouble", "(Ljava/lang/Object;D)V", (void *) (ptrint) &Java_java_lang_reflect_Field_setDouble },
90 { "getSignature", "()Ljava/lang/String;", (void *) (ptrint) &Java_java_lang_reflect_Field_getSignature },
94 /* _Jv_java_lang_reflect_Field_init ********************************************
96 Register native functions.
98 *******************************************************************************/
100 void _Jv_java_lang_reflect_Field_init(void)
104 u = utf_new_char("java/lang/reflect/Field");
106 native_method_register(u, methods, NATIVE_METHODS_COUNT);
110 /* cacao_get_field_address *****************************************************
112 Return the address of a field of an object.
115 this.........the field (a java.lang.reflect.Field object)
116 o............the object of which to get the field
119 a pointer to the field, or
120 NULL if an exception has been thrown
122 *******************************************************************************/
124 static void *cacao_get_field_address(java_lang_reflect_Field *this,
130 c = (classinfo *) this->declaringClass;
131 f = &c->fields[this->slot];
133 /* check field access */
134 /* check if we should bypass security checks (AccessibleObject) */
136 if (this->flag == false) {
137 /* this function is always called like this:
139 java.lang.reflect.Field.xxx (Native Method)
142 if (!access_check_member(c, f->flags, 0))
146 /* get the address of the field */
148 if (f->flags & ACC_STATIC) {
149 /* initialize class if required */
151 if (!(c->state & CLASS_INITIALIZED))
152 if (!initialize_class(c))
155 /* return value address */
160 /* obj is required for not-static fields */
163 exceptions_throw_nullpointerexception();
167 if (builtin_instanceof((java_objectheader *) o, c))
168 return (void *) ((ptrint) o + f->offset);
173 exceptions_throw_illegalargumentexception();
180 * Class: java/lang/reflect/Field
181 * Method: getModifiersInternal
184 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getModifiersInternal(JNIEnv *env, java_lang_reflect_Field *this)
189 c = (classinfo *) this->declaringClass;
190 f = &(c->fields[this->slot]);
197 * Class: java/lang/reflect/Field
199 * Signature: ()Ljava/lang/Class;
201 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
207 c = (classinfo *) this->declaringClass;
208 desc = c->fields[this->slot].parseddesc;
213 if (!resolve_class_from_typedesc(desc, true, false, &ret))
216 return (java_lang_Class *) ret;
221 * Class: java/lang/reflect/Field
223 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
225 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
231 c = (classinfo *) this->declaringClass;
232 f = &c->fields[this->slot];
234 /* get address of the source field value */
236 if ((addr = cacao_get_field_address(this, o)) == NULL)
239 switch (f->parseddesc->decltype) {
240 case PRIMITIVETYPE_BOOLEAN: {
241 java_lang_Boolean *bo;
243 /* create wrapping class */
245 if (!(bo = (java_lang_Boolean *) builtin_new(class_java_lang_Boolean)))
248 /* set the object value */
250 bo->value = *((s4 *) addr);
252 /* return the wrapped object */
254 return (java_lang_Object *) bo;
257 case PRIMITIVETYPE_BYTE: {
260 if (!(bo = (java_lang_Byte *) builtin_new(class_java_lang_Byte)))
263 bo->value = *((s4 *) addr);
265 return (java_lang_Object *) bo;
268 case PRIMITIVETYPE_CHAR: {
269 java_lang_Character *co;
271 if (!(co = (java_lang_Character *) builtin_new(class_java_lang_Character)))
274 co->value = *((s4 *) addr);
276 return (java_lang_Object *) co;
279 case PRIMITIVETYPE_SHORT: {
282 if (!(so = (java_lang_Short *) builtin_new(class_java_lang_Short)))
285 so->value = (s4) *((s4 *) addr);
287 return (java_lang_Object *) so;
290 case PRIMITIVETYPE_INT: {
291 java_lang_Integer *io;
293 if (!(io = (java_lang_Integer *) builtin_new(class_java_lang_Integer)))
296 io->value = *((s4 *) addr);
298 return (java_lang_Object *) io;
301 case PRIMITIVETYPE_LONG: {
304 if (!(lo = (java_lang_Long *) builtin_new(class_java_lang_Long)))
307 lo->value = *((s8 *) addr);
309 return (java_lang_Object *) lo;
312 case PRIMITIVETYPE_FLOAT: {
315 if (!(fo = (java_lang_Float *) builtin_new(class_java_lang_Float)))
318 fo->value = *((float *) addr);
320 return (java_lang_Object *) fo;
323 case PRIMITIVETYPE_DOUBLE: {
324 java_lang_Double *_do;
326 if (!(_do = (java_lang_Double *) builtin_new(class_java_lang_Double)))
329 _do->value = *((double *) addr);
331 return (java_lang_Object *) _do;
335 return (java_lang_Object *) *((java_objectheader **) addr);
338 /* this must not happen */
342 /* keep compiler happy */
349 * Class: java/lang/reflect/Field
351 * Signature: (Ljava/lang/Object;)Z
353 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
359 /* get the class and the field */
361 c = (classinfo *) this->declaringClass;
362 f = &c->fields[this->slot];
364 /* get the address of the field with an internal helper */
366 if ((addr = cacao_get_field_address(this, o)) == NULL)
369 /* check the field type and return the value */
371 switch (f->parseddesc->decltype) {
372 case PRIMITIVETYPE_BOOLEAN:
373 return (s4) *((s4 *) addr);
375 exceptions_throw_illegalargumentexception();
382 * Class: java/lang/reflect/Field
384 * Signature: (Ljava/lang/Object;)B
386 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
392 /* get the class and the field */
394 c = (classinfo *) this->declaringClass;
395 f = &c->fields[this->slot];
397 /* get the address of the field with an internal helper */
399 if ((addr = cacao_get_field_address(this, o)) == NULL)
402 /* check the field type and return the value */
404 switch (f->parseddesc->decltype) {
405 case PRIMITIVETYPE_BYTE:
406 return (s4) *((s4 *) addr);
408 exceptions_throw_illegalargumentexception();
415 * Class: java/lang/reflect/Field
417 * Signature: (Ljava/lang/Object;)C
419 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
425 /* get the class and the field */
427 c = (classinfo *) this->declaringClass;
428 f = &c->fields[this->slot];
430 /* get the address of the field with an internal helper */
432 if ((addr = cacao_get_field_address(this, o)) == NULL)
435 /* check the field type and return the value */
437 switch (f->parseddesc->decltype) {
438 case PRIMITIVETYPE_CHAR:
439 return (s4) *((s4 *) addr);
441 exceptions_throw_illegalargumentexception();
448 * Class: java/lang/reflect/Field
450 * Signature: (Ljava/lang/Object;)S
452 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
458 /* get the class and the field */
460 c = (classinfo *) this->declaringClass;
461 f = &c->fields[this->slot];
463 /* get the address of the field with an internal helper */
465 if ((addr = cacao_get_field_address(this, o)) == NULL)
468 /* check the field type and return the value */
470 switch (f->parseddesc->decltype) {
471 case PRIMITIVETYPE_BYTE:
472 case PRIMITIVETYPE_SHORT:
473 return (s4) *((s4 *) addr);
475 exceptions_throw_illegalargumentexception();
482 * Class: java/lang/reflect/Field
484 * Signature: (Ljava/lang/Object;)I
486 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Field_getInt(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 (s4) *((s4 *) addr);
511 exceptions_throw_illegalargumentexception();
518 * Class: java/lang/reflect/Field
520 * Signature: (Ljava/lang/Object;)J
522 JNIEXPORT s8 JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
528 /* get the class and the field */
530 c = (classinfo *) this->declaringClass;
531 f = &c->fields[this->slot];
533 /* get the address of the field with an internal helper */
535 if ((addr = cacao_get_field_address(this, o)) == NULL)
538 /* check the field type and return the value */
540 switch (f->parseddesc->decltype) {
541 case PRIMITIVETYPE_BYTE:
542 case PRIMITIVETYPE_CHAR:
543 case PRIMITIVETYPE_SHORT:
544 case PRIMITIVETYPE_INT:
545 return (s8) *((s4 *) addr);
546 case PRIMITIVETYPE_LONG:
547 return (s8) *((s8 *) addr);
549 exceptions_throw_illegalargumentexception();
556 * Class: java/lang/reflect/Field
558 * Signature: (Ljava/lang/Object;)F
560 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
566 /* get the class and the field */
568 c = (classinfo *) this->declaringClass;
569 f = &c->fields[this->slot];
571 /* get the address of the field with an internal helper */
573 if ((addr = cacao_get_field_address(this, o)) == NULL)
576 /* check the field type and return the value */
578 switch (f->parseddesc->decltype) {
579 case PRIMITIVETYPE_BYTE:
580 case PRIMITIVETYPE_CHAR:
581 case PRIMITIVETYPE_SHORT:
582 case PRIMITIVETYPE_INT:
583 return (float) *((s4 *) addr);
584 case PRIMITIVETYPE_LONG:
585 return (float) *((s8 *) addr);
586 case PRIMITIVETYPE_FLOAT:
587 return (float) *((float *) addr);
589 exceptions_throw_illegalargumentexception();
596 * Class: java/lang/reflect/Field
598 * Signature: (Ljava/lang/Object;)D
600 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
606 /* get the class and the field */
608 c = (classinfo *) this->declaringClass;
609 f = &c->fields[this->slot];
611 /* get the address of the field with an internal helper */
613 if ((addr = cacao_get_field_address(this, o)) == NULL)
616 /* check the field type and return the value */
618 switch (f->parseddesc->decltype) {
619 case PRIMITIVETYPE_BYTE:
620 case PRIMITIVETYPE_CHAR:
621 case PRIMITIVETYPE_SHORT:
622 case PRIMITIVETYPE_INT:
623 return (double) *((s4 *) addr);
624 case PRIMITIVETYPE_LONG:
625 return (double) *((s8 *) addr);
626 case PRIMITIVETYPE_FLOAT:
627 return (double) *((float *) addr);
628 case PRIMITIVETYPE_DOUBLE:
629 return (double) *((double *) addr);
631 exceptions_throw_illegalargumentexception();
638 * Class: java/lang/reflect/Field
640 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
642 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, java_lang_Object *value)
650 /* get the class and the field */
652 dc = (classinfo *) this->declaringClass;
653 df = &dc->fields[this->slot];
655 /* get the address of the destination field */
657 if ((faddr = cacao_get_field_address(this, o)) == NULL)
660 /* get the source classinfo from the object */
665 sc = value->header.vftbl->class;
667 /* The fieldid is used to set the new value, for primitive
668 types the value has to be retrieved from the wrapping
671 switch (df->parseddesc->decltype) {
672 case PRIMITIVETYPE_BOOLEAN: {
675 /* determine the field to read the value */
677 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
680 switch (sf->parseddesc->decltype) {
681 case PRIMITIVETYPE_BOOLEAN:
682 val = ((java_lang_Boolean *) value)->value;
685 exceptions_throw_illegalargumentexception();
689 *((s4 *) faddr) = val;
693 case PRIMITIVETYPE_BYTE: {
696 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
699 switch (sf->parseddesc->decltype) {
700 case PRIMITIVETYPE_BYTE:
701 val = ((java_lang_Byte *) value)->value;
704 exceptions_throw_illegalargumentexception();
708 *((s4 *) faddr) = val;
712 case PRIMITIVETYPE_CHAR: {
715 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
718 switch (sf->parseddesc->decltype) {
719 case PRIMITIVETYPE_CHAR:
720 val = ((java_lang_Character *) value)->value;
723 exceptions_throw_illegalargumentexception();
727 *((s4 *) faddr) = val;
731 case PRIMITIVETYPE_SHORT: {
734 /* get field only by name, it can be one of B, S */
736 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
739 switch (sf->parseddesc->decltype) {
740 case PRIMITIVETYPE_BYTE:
741 val = ((java_lang_Byte *) value)->value;
743 case PRIMITIVETYPE_SHORT:
744 val = ((java_lang_Short *) value)->value;
747 exceptions_throw_illegalargumentexception();
751 *((s4 *) faddr) = val;
755 case PRIMITIVETYPE_INT: {
758 /* get field only by name, it can be one of B, S, C, I */
760 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
763 switch (sf->parseddesc->decltype) {
764 case PRIMITIVETYPE_BYTE:
765 val = ((java_lang_Byte *) value)->value;
767 case PRIMITIVETYPE_CHAR:
768 val = ((java_lang_Character *) value)->value;
770 case PRIMITIVETYPE_SHORT:
771 val = ((java_lang_Short *) value)->value;
773 case PRIMITIVETYPE_INT:
774 val = ((java_lang_Integer *) value)->value;
777 exceptions_throw_illegalargumentexception();
781 *((s4 *) faddr) = val;
785 case PRIMITIVETYPE_LONG: {
788 /* get field only by name, it can be one of B, S, C, I, J */
790 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
793 switch (sf->parseddesc->decltype) {
794 case PRIMITIVETYPE_BYTE:
795 val = ((java_lang_Byte *) value)->value;
797 case PRIMITIVETYPE_CHAR:
798 val = ((java_lang_Character *) value)->value;
800 case PRIMITIVETYPE_SHORT:
801 val = ((java_lang_Short *) value)->value;
803 case PRIMITIVETYPE_INT:
804 val = ((java_lang_Integer *) value)->value;
806 case PRIMITIVETYPE_LONG:
807 val = ((java_lang_Long *) value)->value;
810 exceptions_throw_illegalargumentexception();
814 *((s8 *) faddr) = val;
818 case PRIMITIVETYPE_FLOAT: {
821 /* get field only by name, it can be one of B, S, C, I, J, F */
823 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
826 switch (sf->parseddesc->decltype) {
827 case PRIMITIVETYPE_BYTE:
828 val = ((java_lang_Byte *) value)->value;
830 case PRIMITIVETYPE_CHAR:
831 val = ((java_lang_Character *) value)->value;
833 case PRIMITIVETYPE_SHORT:
834 val = ((java_lang_Short *) value)->value;
836 case PRIMITIVETYPE_INT:
837 val = ((java_lang_Integer *) value)->value;
839 case PRIMITIVETYPE_LONG:
840 val = ((java_lang_Long *) value)->value;
842 case PRIMITIVETYPE_FLOAT:
843 val = ((java_lang_Float *) value)->value;
846 exceptions_throw_illegalargumentexception();
850 *((float *) faddr) = val;
854 case PRIMITIVETYPE_DOUBLE: {
857 /* get field only by name, it can be one of B, S, C, I, J, F, D */
859 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
862 switch (sf->parseddesc->decltype) {
863 case PRIMITIVETYPE_BYTE:
864 val = ((java_lang_Byte *) value)->value;
866 case PRIMITIVETYPE_CHAR:
867 val = ((java_lang_Character *) value)->value;
869 case PRIMITIVETYPE_SHORT:
870 val = ((java_lang_Short *) value)->value;
872 case PRIMITIVETYPE_INT:
873 val = ((java_lang_Integer *) value)->value;
875 case PRIMITIVETYPE_LONG:
876 val = ((java_lang_Long *) value)->value;
878 case PRIMITIVETYPE_FLOAT:
879 val = ((java_lang_Float *) value)->value;
881 case PRIMITIVETYPE_DOUBLE:
882 val = ((java_lang_Double *) value)->value;
885 exceptions_throw_illegalargumentexception();
889 *((double *) faddr) = val;
894 /* check if value is an instance of the destination class */
897 /* if (!builtin_instanceof((java_objectheader *) value, df->class)) */
900 *((java_lang_Object **) faddr) = value;
904 /* raise exception */
906 exceptions_throw_illegalargumentexception();
911 * Class: java/lang/reflect/Field
913 * Signature: (Ljava/lang/Object;Z)V
915 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
921 /* get the class and the field */
923 c = (classinfo *) this->declaringClass;
924 f = &c->fields[this->slot];
926 /* get the address of the field with an internal helper */
928 if ((addr = cacao_get_field_address(this, o)) == NULL)
931 /* check the field type and set the value */
933 switch (f->parseddesc->decltype) {
934 case PRIMITIVETYPE_BOOLEAN:
935 *((s4 *) addr) = value;
938 exceptions_throw_illegalargumentexception();
946 * Class: java/lang/reflect/Field
948 * Signature: (Ljava/lang/Object;B)V
950 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
956 /* get the class and the field */
958 c = (classinfo *) this->declaringClass;
959 f = &c->fields[this->slot];
961 /* get the address of the field with an internal helper */
963 if ((addr = cacao_get_field_address(this, o)) == NULL)
966 /* check the field type and set the value */
968 switch (f->parseddesc->decltype) {
969 case PRIMITIVETYPE_BYTE:
970 case PRIMITIVETYPE_SHORT:
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;C)V
996 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(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_CHAR:
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;S)V
1041 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(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_SHORT:
1061 case PRIMITIVETYPE_INT:
1062 *((s4 *) addr) = value;
1064 case PRIMITIVETYPE_LONG:
1065 *((s8 *) addr) = value;
1067 case PRIMITIVETYPE_FLOAT:
1068 *((float *) addr) = value;
1070 case PRIMITIVETYPE_DOUBLE:
1071 *((double *) addr) = value;
1074 exceptions_throw_illegalargumentexception();
1082 * Class: java/lang/reflect/Field
1084 * Signature: (Ljava/lang/Object;I)V
1086 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s4 value)
1092 /* get the class and the field */
1094 c = (classinfo *) this->declaringClass;
1095 f = &c->fields[this->slot];
1097 /* get the address of the field with an internal helper */
1099 if ((addr = cacao_get_field_address(this, o)) == NULL)
1102 /* check the field type and set the value */
1104 switch (f->parseddesc->decltype) {
1105 case PRIMITIVETYPE_INT:
1106 *((s4 *) addr) = value;
1108 case PRIMITIVETYPE_LONG:
1109 *((s8 *) addr) = value;
1111 case PRIMITIVETYPE_FLOAT:
1112 *((float *) addr) = value;
1114 case PRIMITIVETYPE_DOUBLE:
1115 *((double *) addr) = value;
1118 exceptions_throw_illegalargumentexception();
1126 * Class: java/lang/reflect/Field
1128 * Signature: (Ljava/lang/Object;J)V
1130 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, s8 value)
1136 /* get the class and the field */
1138 c = (classinfo *) this->declaringClass;
1139 f = &c->fields[this->slot];
1141 /* get the address of the field with an internal helper */
1143 if ((addr = cacao_get_field_address(this, o)) == NULL)
1146 /* check the field type and set the value */
1148 switch (f->parseddesc->decltype) {
1149 case PRIMITIVETYPE_LONG:
1150 *((s8 *) addr) = value;
1152 case PRIMITIVETYPE_FLOAT:
1153 *((float *) addr) = value;
1155 case PRIMITIVETYPE_DOUBLE:
1156 *((double *) addr) = value;
1159 exceptions_throw_illegalargumentexception();
1167 * Class: java/lang/reflect/Field
1169 * Signature: (Ljava/lang/Object;F)V
1171 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, float value)
1177 /* get the class and the field */
1179 c = (classinfo *) this->declaringClass;
1180 f = &c->fields[this->slot];
1182 /* get the address of the field with an internal helper */
1184 if ((addr = cacao_get_field_address(this, o)) == NULL)
1187 /* check the field type and set the value */
1189 switch (f->parseddesc->decltype) {
1190 case PRIMITIVETYPE_FLOAT:
1191 *((float *) addr) = value;
1193 case PRIMITIVETYPE_DOUBLE:
1194 *((double *) addr) = value;
1197 exceptions_throw_illegalargumentexception();
1205 * Class: java/lang/reflect/Field
1207 * Signature: (Ljava/lang/Object;D)V
1209 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, double value)
1215 /* get the class and the field */
1217 c = (classinfo *) this->declaringClass;
1218 f = &c->fields[this->slot];
1220 /* get the address of the field with an internal helper */
1222 if ((addr = cacao_get_field_address(this, o)) == NULL)
1225 /* check the field type and set the value */
1227 switch (f->parseddesc->decltype) {
1228 case PRIMITIVETYPE_DOUBLE:
1229 *((double *) addr) = value;
1232 exceptions_throw_illegalargumentexception();
1240 * Class: java/lang/reflect/Field
1241 * Method: getSignature
1242 * Signature: ()Ljava/lang/String;
1244 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Field_getSignature(JNIEnv *env, java_lang_reflect_Field* this)
1248 java_objectheader *o;
1250 /* get the class and the field */
1252 c = (classinfo *) this->declaringClass;
1253 f = &c->fields[this->slot];
1255 if (f->signature == NULL)
1258 o = javastring_new(f->signature);
1260 /* in error case o is NULL */
1262 return (java_lang_String *) o;
1267 * These are local overrides for various environment variables in Emacs.
1268 * Please do not remove this and leave it at the end of the file, where
1269 * Emacs will automagically detect them.
1270 * ---------------------------------------------------------------------
1273 * indent-tabs-mode: t