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 8284 2007-08-10 08:58:39Z michi $
35 #include "native/jni.h"
36 #include "native/llni.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 #if defined(ENABLE_ANNOTATIONS)
54 #include "native/include/sun_reflect_ConstantPool.h"
55 #include "native/vm/reflect.h"
58 #include "vm/access.h"
59 #include "vm/builtin.h"
60 #include "vm/exceptions.h"
61 #include "vm/global.h"
62 #include "vm/initialize.h"
63 #include "vm/resolve.h"
64 #include "vm/stringlocal.h"
66 #include "vm/jit/stacktrace.h"
68 #include "vmcore/loader.h"
69 #include "vmcore/primitive.h"
70 #include "vmcore/utf8.h"
73 /* native methods implemented by this file ************************************/
75 static JNINativeMethod methods[] = {
76 { "getModifiersInternal", "()I", (void *) (intptr_t) &Java_java_lang_reflect_Field_getModifiersInternal },
77 { "getType", "()Ljava/lang/Class;", (void *) (intptr_t) &Java_java_lang_reflect_Field_getType },
78 { "get", "(Ljava/lang/Object;)Ljava/lang/Object;", (void *) (intptr_t) &Java_java_lang_reflect_Field_get },
79 { "getBoolean", "(Ljava/lang/Object;)Z", (void *) (intptr_t) &Java_java_lang_reflect_Field_getBoolean },
80 { "getByte", "(Ljava/lang/Object;)B", (void *) (intptr_t) &Java_java_lang_reflect_Field_getByte },
81 { "getChar", "(Ljava/lang/Object;)C", (void *) (intptr_t) &Java_java_lang_reflect_Field_getChar },
82 { "getShort", "(Ljava/lang/Object;)S", (void *) (intptr_t) &Java_java_lang_reflect_Field_getShort },
83 { "getInt", "(Ljava/lang/Object;)I", (void *) (intptr_t) &Java_java_lang_reflect_Field_getInt },
84 { "getLong", "(Ljava/lang/Object;)J", (void *) (intptr_t) &Java_java_lang_reflect_Field_getLong },
85 { "getFloat", "(Ljava/lang/Object;)F", (void *) (intptr_t) &Java_java_lang_reflect_Field_getFloat },
86 { "getDouble", "(Ljava/lang/Object;)D", (void *) (intptr_t) &Java_java_lang_reflect_Field_getDouble },
87 { "set", "(Ljava/lang/Object;Ljava/lang/Object;)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_set },
88 { "setBoolean", "(Ljava/lang/Object;Z)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setBoolean },
89 { "setByte", "(Ljava/lang/Object;B)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setByte },
90 { "setChar", "(Ljava/lang/Object;C)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setChar },
91 { "setShort", "(Ljava/lang/Object;S)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setShort },
92 { "setInt", "(Ljava/lang/Object;I)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setInt },
93 { "setLong", "(Ljava/lang/Object;J)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setLong },
94 { "setFloat", "(Ljava/lang/Object;F)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setFloat },
95 { "setDouble", "(Ljava/lang/Object;D)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setDouble },
96 { "getSignature", "()Ljava/lang/String;", (void *) (intptr_t) &Java_java_lang_reflect_Field_getSignature },
97 #if defined(ENABLE_ANNOTATIONS)
98 { "declaredAnnotations", "()Ljava/util/Map;", (void *) (intptr_t) &Java_java_lang_reflect_Field_declaredAnnotations },
103 /* _Jv_java_lang_reflect_Field_init ********************************************
105 Register native functions.
107 *******************************************************************************/
109 void _Jv_java_lang_reflect_Field_init(void)
113 u = utf_new_char("java/lang/reflect/Field");
115 native_method_register(u, methods, NATIVE_METHODS_COUNT);
119 /* cacao_get_field_address *****************************************************
121 Return the address of a field of an object.
124 this.........the field (a java.lang.reflect.Field object)
125 o............the object of which to get the field
128 a pointer to the field, or
129 NULL if an exception has been thrown
131 *******************************************************************************/
133 static void *cacao_get_field_address(java_lang_reflect_Field *this,
141 LLNI_field_get_cls(this, clazz, c);
142 LLNI_field_get_val(this, slot , slot);
143 f = &c->fields[slot];
145 /* check field access */
146 /* check if we should bypass security checks (AccessibleObject) */
148 LLNI_field_get_val(this, flag, flag);
150 /* this function is always called like this:
152 java.lang.reflect.Field.xxx (Native Method)
155 if (!access_check_field(f, 0))
159 /* get the address of the field */
161 if (f->flags & ACC_STATIC) {
162 /* initialize class if required */
164 if (!(c->state & CLASS_INITIALIZED))
165 if (!initialize_class(c))
168 /* return value pointer */
173 /* obj is required for not-static fields */
176 exceptions_throw_nullpointerexception();
180 if (builtin_instanceof((java_objectheader *) o, c))
181 return (void *) (((intptr_t) o) + f->offset);
186 exceptions_throw_illegalargumentexception();
193 * Class: java/lang/reflect/Field
194 * Method: getModifiersInternal
197 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getModifiersInternal(JNIEnv *env, java_lang_reflect_Field *this)
203 LLNI_field_get_cls(this, clazz, c);
204 LLNI_field_get_val(this, slot , slot);
205 f = &(c->fields[slot]);
212 * Class: java/lang/reflect/Field
214 * Signature: ()Ljava/lang/Class;
216 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
223 LLNI_field_get_cls(this, clazz, c);
224 LLNI_field_get_val(this, slot , slot);
225 desc = c->fields[slot].parseddesc;
230 if (!resolve_class_from_typedesc(desc, true, false, &ret))
233 return (java_lang_Class *) ret;
238 * Class: java/lang/reflect/Field
240 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
242 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
249 LLNI_field_get_cls(this, clazz, c);
250 LLNI_field_get_val(this, slot , slot);
251 f = &c->fields[slot];
253 /* get address of the source field value */
255 if ((addr = cacao_get_field_address(this, o)) == NULL)
258 switch (f->parseddesc->decltype) {
259 case PRIMITIVETYPE_BOOLEAN: {
260 java_lang_Boolean *bo;
262 /* create wrapping class */
264 if (!(bo = (java_lang_Boolean *) builtin_new(class_java_lang_Boolean)))
267 /* set the object value */
269 LLNI_field_set_val(bo, value, *((int32_t *) addr));
271 /* return the wrapped object */
273 return (java_lang_Object *) bo;
276 case PRIMITIVETYPE_BYTE: {
279 if (!(bo = (java_lang_Byte *) builtin_new(class_java_lang_Byte)))
282 LLNI_field_set_val(bo, value, *((int32_t *) addr));
284 return (java_lang_Object *) bo;
287 case PRIMITIVETYPE_CHAR: {
288 java_lang_Character *co;
290 if (!(co = (java_lang_Character *) builtin_new(class_java_lang_Character)))
293 LLNI_field_set_val(co, value, *((int32_t *) addr));
295 return (java_lang_Object *) co;
298 case PRIMITIVETYPE_SHORT: {
301 if (!(so = (java_lang_Short *) builtin_new(class_java_lang_Short)))
304 LLNI_field_set_val(so, value, (int32_t) *((int32_t *) addr));
306 return (java_lang_Object *) so;
309 case PRIMITIVETYPE_INT: {
310 java_lang_Integer *io;
312 if (!(io = (java_lang_Integer *) builtin_new(class_java_lang_Integer)))
315 LLNI_field_set_val(io, value, *((int32_t *) addr));
317 return (java_lang_Object *) io;
320 case PRIMITIVETYPE_LONG: {
323 if (!(lo = (java_lang_Long *) builtin_new(class_java_lang_Long)))
326 LLNI_field_set_val(lo, value, *((int64_t *) addr));
328 return (java_lang_Object *) lo;
331 case PRIMITIVETYPE_FLOAT: {
334 if (!(fo = (java_lang_Float *) builtin_new(class_java_lang_Float)))
337 LLNI_field_set_val(fo, value, *((float *) addr));
339 return (java_lang_Object *) fo;
342 case PRIMITIVETYPE_DOUBLE: {
343 java_lang_Double *_do;
345 if (!(_do = (java_lang_Double *) builtin_new(class_java_lang_Double)))
348 LLNI_field_set_val(_do, value, *((double *) addr));
350 return (java_lang_Object *) _do;
354 return (java_lang_Object *) *((java_objectheader **) addr);
357 /* this must not happen */
361 /* keep compiler happy */
368 * Class: java/lang/reflect/Field
370 * Signature: (Ljava/lang/Object;)Z
372 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
379 /* get the class and the field */
381 LLNI_field_get_cls(this, clazz, c);
382 LLNI_field_get_val(this, slot , slot);
383 f = &c->fields[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_BOOLEAN:
394 return (int32_t) *((int32_t *) addr);
396 exceptions_throw_illegalargumentexception();
403 * Class: java/lang/reflect/Field
405 * Signature: (Ljava/lang/Object;)B
407 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
414 /* get the class and the field */
416 LLNI_field_get_cls(this, clazz, c);
417 LLNI_field_get_val(this, slot , slot);
418 f = &c->fields[slot];
420 /* get the address of the field with an internal helper */
422 if ((addr = cacao_get_field_address(this, o)) == NULL)
425 /* check the field type and return the value */
427 switch (f->parseddesc->decltype) {
428 case PRIMITIVETYPE_BYTE:
429 return (int32_t) *((int32_t *) addr);
431 exceptions_throw_illegalargumentexception();
438 * Class: java/lang/reflect/Field
440 * Signature: (Ljava/lang/Object;)C
442 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
449 /* get the class and the field */
451 LLNI_field_get_cls(this, clazz, c);
452 LLNI_field_get_val(this, slot , slot);
453 f = &c->fields[slot];
455 /* get the address of the field with an internal helper */
457 if ((addr = cacao_get_field_address(this, o)) == NULL)
460 /* check the field type and return the value */
462 switch (f->parseddesc->decltype) {
463 case PRIMITIVETYPE_CHAR:
464 return (int32_t) *((int32_t *) addr);
466 exceptions_throw_illegalargumentexception();
473 * Class: java/lang/reflect/Field
475 * Signature: (Ljava/lang/Object;)S
477 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
484 /* get the class and the field */
486 LLNI_field_get_cls(this, clazz, c);
487 LLNI_field_get_val(this, slot , slot);
488 f = &c->fields[slot];
490 /* get the address of the field with an internal helper */
492 if ((addr = cacao_get_field_address(this, o)) == NULL)
495 /* check the field type and return the value */
497 switch (f->parseddesc->decltype) {
498 case PRIMITIVETYPE_BYTE:
499 case PRIMITIVETYPE_SHORT:
500 return (int32_t) *((int32_t *) addr);
502 exceptions_throw_illegalargumentexception();
509 * Class: java/lang/reflect/Field
511 * Signature: (Ljava/lang/Object;)I
513 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
520 /* get the class and the field */
522 LLNI_field_get_cls(this, clazz, c);
523 LLNI_field_get_val(this, slot , slot);
524 f = &c->fields[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 (int32_t) *((int32_t *) addr);
540 exceptions_throw_illegalargumentexception();
547 * Class: java/lang/reflect/Field
549 * Signature: (Ljava/lang/Object;)J
551 JNIEXPORT int64_t JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
558 /* get the class and the field */
560 LLNI_field_get_cls(this, clazz, c);
561 LLNI_field_get_val(this, slot , slot);
562 f = &c->fields[slot];
564 /* get the address of the field with an internal helper */
566 if ((addr = cacao_get_field_address(this, o)) == NULL)
569 /* check the field type and return the value */
571 switch (f->parseddesc->decltype) {
572 case PRIMITIVETYPE_BYTE:
573 case PRIMITIVETYPE_CHAR:
574 case PRIMITIVETYPE_SHORT:
575 case PRIMITIVETYPE_INT:
576 return (int64_t) *((int32_t *) addr);
577 case PRIMITIVETYPE_LONG:
578 return (int64_t) *((int64_t *) addr);
580 exceptions_throw_illegalargumentexception();
587 * Class: java/lang/reflect/Field
589 * Signature: (Ljava/lang/Object;)F
591 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
598 /* get the class and the field */
600 LLNI_field_get_cls(this, clazz, c);
601 LLNI_field_get_val(this, slot , slot);
602 f = &c->fields[slot];
604 /* get the address of the field with an internal helper */
606 if ((addr = cacao_get_field_address(this, o)) == NULL)
609 /* check the field type and return the value */
611 switch (f->parseddesc->decltype) {
612 case PRIMITIVETYPE_BYTE:
613 case PRIMITIVETYPE_CHAR:
614 case PRIMITIVETYPE_SHORT:
615 case PRIMITIVETYPE_INT:
616 return (float) *((int32_t *) addr);
617 case PRIMITIVETYPE_LONG:
618 return (float) *((int64_t *) addr);
619 case PRIMITIVETYPE_FLOAT:
620 return (float) *((float *) addr);
622 exceptions_throw_illegalargumentexception();
629 * Class: java/lang/reflect/Field
631 * Signature: (Ljava/lang/Object;)D
633 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
640 /* get the class and the field */
642 LLNI_field_get_cls(this, clazz, c);
643 LLNI_field_get_val(this, slot , slot);
644 f = &c->fields[slot];
646 /* get the address of the field with an internal helper */
648 if ((addr = cacao_get_field_address(this, o)) == NULL)
651 /* check the field type and return the value */
653 switch (f->parseddesc->decltype) {
654 case PRIMITIVETYPE_BYTE:
655 case PRIMITIVETYPE_CHAR:
656 case PRIMITIVETYPE_SHORT:
657 case PRIMITIVETYPE_INT:
658 return (double) *((int32_t *) addr);
659 case PRIMITIVETYPE_LONG:
660 return (double) *((int64_t *) addr);
661 case PRIMITIVETYPE_FLOAT:
662 return (double) *((float *) addr);
663 case PRIMITIVETYPE_DOUBLE:
664 return (double) *((double *) addr);
666 exceptions_throw_illegalargumentexception();
673 * Class: java/lang/reflect/Field
675 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
677 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, java_lang_Object *value)
686 /* get the class and the field */
688 LLNI_field_get_cls(this, clazz, dc);
689 LLNI_field_get_val(this, slot , slot);
690 df = &dc->fields[slot];
692 /* get the address of the destination field */
694 if ((faddr = cacao_get_field_address(this, o)) == NULL)
697 /* get the source classinfo from the object */
702 LLNI_class_get(value, sc);
704 /* The fieldid is used to set the new value, for primitive
705 types the value has to be retrieved from the wrapping
708 switch (df->parseddesc->decltype) {
709 case PRIMITIVETYPE_BOOLEAN: {
712 /* determine the field to read the value */
714 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
717 switch (sf->parseddesc->decltype) {
718 case PRIMITIVETYPE_BOOLEAN:
719 LLNI_field_get_val((java_lang_Boolean *) value, value, val);
722 exceptions_throw_illegalargumentexception();
726 *((int32_t *) faddr) = val;
730 case PRIMITIVETYPE_BYTE: {
733 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
736 switch (sf->parseddesc->decltype) {
737 case PRIMITIVETYPE_BYTE:
738 LLNI_field_get_val((java_lang_Byte *) value, value, val);
741 exceptions_throw_illegalargumentexception();
745 *((int32_t *) faddr) = val;
749 case PRIMITIVETYPE_CHAR: {
752 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
755 switch (sf->parseddesc->decltype) {
756 case PRIMITIVETYPE_CHAR:
757 LLNI_field_get_val((java_lang_Character *) value, value, val);
760 exceptions_throw_illegalargumentexception();
764 *((int32_t *) faddr) = val;
768 case PRIMITIVETYPE_SHORT: {
771 /* get field only by name, it can be one of B, S */
773 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
776 switch (sf->parseddesc->decltype) {
777 case PRIMITIVETYPE_BYTE:
778 LLNI_field_get_val((java_lang_Byte *) value, value, val);
780 case PRIMITIVETYPE_SHORT:
781 LLNI_field_get_val((java_lang_Short *) value, value, val);
784 exceptions_throw_illegalargumentexception();
788 *((int32_t *) faddr) = val;
792 case PRIMITIVETYPE_INT: {
795 /* get field only by name, it can be one of B, S, C, I */
797 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
800 switch (sf->parseddesc->decltype) {
801 case PRIMITIVETYPE_BYTE:
802 LLNI_field_get_val((java_lang_Byte *) value, value, val);
804 case PRIMITIVETYPE_CHAR:
805 LLNI_field_get_val((java_lang_Character *) value, value, val);
807 case PRIMITIVETYPE_SHORT:
808 LLNI_field_get_val((java_lang_Short *) value, value, val);
810 case PRIMITIVETYPE_INT:
811 LLNI_field_get_val((java_lang_Integer *) value, value, val);
814 exceptions_throw_illegalargumentexception();
818 *((int32_t *) faddr) = val;
822 case PRIMITIVETYPE_LONG: {
825 /* get field only by name, it can be one of B, S, C, I, J */
827 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
830 switch (sf->parseddesc->decltype) {
831 case PRIMITIVETYPE_BYTE:
832 LLNI_field_get_val((java_lang_Byte *) value, value, val);
834 case PRIMITIVETYPE_CHAR:
835 LLNI_field_get_val((java_lang_Character *) value, value, val);
837 case PRIMITIVETYPE_SHORT:
838 LLNI_field_get_val((java_lang_Short *) value, value, val);
840 case PRIMITIVETYPE_INT:
841 LLNI_field_get_val((java_lang_Integer *) value, value, val);
843 case PRIMITIVETYPE_LONG:
844 LLNI_field_get_val((java_lang_Long *) value, value, val);
847 exceptions_throw_illegalargumentexception();
851 *((int64_t *) faddr) = val;
855 case PRIMITIVETYPE_FLOAT: {
858 /* get field only by name, it can be one of B, S, C, I, J, F */
860 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
863 switch (sf->parseddesc->decltype) {
864 case PRIMITIVETYPE_BYTE:
865 LLNI_field_get_val((java_lang_Byte *) value, value, val);
867 case PRIMITIVETYPE_CHAR:
868 LLNI_field_get_val((java_lang_Character *) value, value, val);
870 case PRIMITIVETYPE_SHORT:
871 LLNI_field_get_val((java_lang_Short *) value, value, val);
873 case PRIMITIVETYPE_INT:
874 LLNI_field_get_val((java_lang_Integer *) value, value, val);
876 case PRIMITIVETYPE_LONG:
877 LLNI_field_get_val((java_lang_Long *) value, value, val);
879 case PRIMITIVETYPE_FLOAT:
880 LLNI_field_get_val((java_lang_Float *) value, value, val);
883 exceptions_throw_illegalargumentexception();
887 *((float *) faddr) = val;
891 case PRIMITIVETYPE_DOUBLE: {
894 /* get field only by name, it can be one of B, S, C, I, J, F, D */
896 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
899 switch (sf->parseddesc->decltype) {
900 case PRIMITIVETYPE_BYTE:
901 LLNI_field_get_val((java_lang_Byte *) value, value, val);
903 case PRIMITIVETYPE_CHAR:
904 LLNI_field_get_val((java_lang_Character *) value, value, val);
906 case PRIMITIVETYPE_SHORT:
907 LLNI_field_get_val((java_lang_Short *) value, value, val);
909 case PRIMITIVETYPE_INT:
910 LLNI_field_get_val((java_lang_Integer *) value, value, val);
912 case PRIMITIVETYPE_LONG:
913 LLNI_field_get_val((java_lang_Long *) value, value, val);
915 case PRIMITIVETYPE_FLOAT:
916 LLNI_field_get_val((java_lang_Float *) value, value, val);
918 case PRIMITIVETYPE_DOUBLE:
919 LLNI_field_get_val((java_lang_Double *) value, value, val);
922 exceptions_throw_illegalargumentexception();
926 *((double *) faddr) = val;
931 /* check if value is an instance of the destination class */
934 /* if (!builtin_instanceof((java_objectheader *) value, df->class)) */
937 *((java_lang_Object **) faddr) = value;
941 /* raise exception */
943 exceptions_throw_illegalargumentexception();
948 * Class: java/lang/reflect/Field
950 * Signature: (Ljava/lang/Object;Z)V
952 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
959 /* get the class and the field */
961 LLNI_field_get_cls(this, clazz, c);
962 LLNI_field_get_val(this, slot , slot);
963 f = &c->fields[slot];
965 /* get the address of the field with an internal helper */
967 if ((addr = cacao_get_field_address(this, o)) == NULL)
970 /* check the field type and set the value */
972 switch (f->parseddesc->decltype) {
973 case PRIMITIVETYPE_BOOLEAN:
974 *((int32_t *) addr) = value;
977 exceptions_throw_illegalargumentexception();
985 * Class: java/lang/reflect/Field
987 * Signature: (Ljava/lang/Object;B)V
989 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
996 /* get the class and the field */
998 LLNI_field_get_cls(this, clazz, c);
999 LLNI_field_get_val(this, slot , slot);
1000 f = &c->fields[slot];
1002 /* get the address of the field with an internal helper */
1004 if ((addr = cacao_get_field_address(this, o)) == NULL)
1007 /* check the field type and set the value */
1009 switch (f->parseddesc->decltype) {
1010 case PRIMITIVETYPE_BYTE:
1011 case PRIMITIVETYPE_SHORT:
1012 case PRIMITIVETYPE_INT:
1013 *((int32_t *) addr) = value;
1015 case PRIMITIVETYPE_LONG:
1016 *((int64_t *) addr) = value;
1018 case PRIMITIVETYPE_FLOAT:
1019 *((float *) addr) = value;
1021 case PRIMITIVETYPE_DOUBLE:
1022 *((double *) addr) = value;
1025 exceptions_throw_illegalargumentexception();
1033 * Class: java/lang/reflect/Field
1035 * Signature: (Ljava/lang/Object;C)V
1037 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1044 /* get the class and the field */
1046 LLNI_field_get_cls(this, clazz, c);
1047 LLNI_field_get_val(this, slot , slot);
1048 f = &c->fields[slot];
1050 /* get the address of the field with an internal helper */
1052 if ((addr = cacao_get_field_address(this, o)) == NULL)
1055 /* check the field type and set the value */
1057 switch (f->parseddesc->decltype) {
1058 case PRIMITIVETYPE_CHAR:
1059 case PRIMITIVETYPE_INT:
1060 *((int32_t *) addr) = value;
1062 case PRIMITIVETYPE_LONG:
1063 *((int64_t *) addr) = value;
1065 case PRIMITIVETYPE_FLOAT:
1066 *((float *) addr) = value;
1068 case PRIMITIVETYPE_DOUBLE:
1069 *((double *) addr) = value;
1072 exceptions_throw_illegalargumentexception();
1080 * Class: java/lang/reflect/Field
1082 * Signature: (Ljava/lang/Object;S)V
1084 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1091 /* get the class and the field */
1093 LLNI_field_get_cls(this, clazz, c);
1094 LLNI_field_get_val(this, slot , slot);
1095 f = &c->fields[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_SHORT:
1106 case PRIMITIVETYPE_INT:
1107 *((int32_t *) addr) = value;
1109 case PRIMITIVETYPE_LONG:
1110 *((int64_t *) addr) = value;
1112 case PRIMITIVETYPE_FLOAT:
1113 *((float *) addr) = value;
1115 case PRIMITIVETYPE_DOUBLE:
1116 *((double *) addr) = value;
1119 exceptions_throw_illegalargumentexception();
1127 * Class: java/lang/reflect/Field
1129 * Signature: (Ljava/lang/Object;I)V
1131 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1138 /* get the class and the field */
1140 LLNI_field_get_cls(this, clazz, c);
1141 LLNI_field_get_val(this, slot , slot);
1142 f = &c->fields[slot];
1144 /* get the address of the field with an internal helper */
1146 if ((addr = cacao_get_field_address(this, o)) == NULL)
1149 /* check the field type and set the value */
1151 switch (f->parseddesc->decltype) {
1152 case PRIMITIVETYPE_INT:
1153 *((int32_t *) addr) = value;
1155 case PRIMITIVETYPE_LONG:
1156 *((int64_t *) addr) = value;
1158 case PRIMITIVETYPE_FLOAT:
1159 *((float *) addr) = value;
1161 case PRIMITIVETYPE_DOUBLE:
1162 *((double *) addr) = value;
1165 exceptions_throw_illegalargumentexception();
1173 * Class: java/lang/reflect/Field
1175 * Signature: (Ljava/lang/Object;J)V
1177 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int64_t value)
1184 /* get the class and the field */
1186 LLNI_field_get_cls(this, clazz, c);
1187 LLNI_field_get_val(this, slot , slot);
1188 f = &c->fields[slot];
1190 /* get the address of the field with an internal helper */
1192 if ((addr = cacao_get_field_address(this, o)) == NULL)
1195 /* check the field type and set the value */
1197 switch (f->parseddesc->decltype) {
1198 case PRIMITIVETYPE_LONG:
1199 *((int64_t *) addr) = value;
1201 case PRIMITIVETYPE_FLOAT:
1202 *((float *) addr) = value;
1204 case PRIMITIVETYPE_DOUBLE:
1205 *((double *) addr) = value;
1208 exceptions_throw_illegalargumentexception();
1216 * Class: java/lang/reflect/Field
1218 * Signature: (Ljava/lang/Object;F)V
1220 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, float value)
1227 /* get the class and the field */
1229 LLNI_field_get_cls(this, clazz, c);
1230 LLNI_field_get_val(this, slot , slot);
1231 f = &c->fields[slot];
1233 /* get the address of the field with an internal helper */
1235 if ((addr = cacao_get_field_address(this, o)) == NULL)
1238 /* check the field type and set the value */
1240 switch (f->parseddesc->decltype) {
1241 case PRIMITIVETYPE_FLOAT:
1242 *((float *) addr) = value;
1244 case PRIMITIVETYPE_DOUBLE:
1245 *((double *) addr) = value;
1248 exceptions_throw_illegalargumentexception();
1256 * Class: java/lang/reflect/Field
1258 * Signature: (Ljava/lang/Object;D)V
1260 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, double value)
1267 /* get the class and the field */
1269 LLNI_field_get_cls(this, clazz, c);
1270 LLNI_field_get_val(this, slot , slot);
1271 f = &c->fields[slot];
1273 /* get the address of the field with an internal helper */
1275 if ((addr = cacao_get_field_address(this, o)) == NULL)
1278 /* check the field type and set the value */
1280 switch (f->parseddesc->decltype) {
1281 case PRIMITIVETYPE_DOUBLE:
1282 *((double *) addr) = value;
1285 exceptions_throw_illegalargumentexception();
1293 * Class: java/lang/reflect/Field
1294 * Method: getSignature
1295 * Signature: ()Ljava/lang/String;
1297 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Field_getSignature(JNIEnv *env, java_lang_reflect_Field* this)
1301 java_objectheader *o;
1304 /* get the class and the field */
1306 LLNI_field_get_cls(this, clazz, c);
1307 LLNI_field_get_val(this, slot , slot);
1308 f = &c->fields[slot];
1310 if (f->signature == NULL)
1313 o = javastring_new(f->signature);
1315 /* in error case o is NULL */
1317 return (java_lang_String *) o;
1321 #if defined(ENABLE_ANNOTATIONS)
1323 * Class: java/lang/reflect/Field
1324 * Method: declaredAnnotations
1325 * Signature: ()Ljava/util/Map;
1327 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Field_declaredAnnotations(JNIEnv *env, struct java_lang_reflect_Field* this)
1329 java_objectheader *o = (java_objectheader*)this;
1332 exceptions_throw_nullpointerexception();
1336 return reflect_get_declaredannotatios(&(this->declaredAnnotations), this->annotations, this->clazz, o->vftbl->class);
1342 * These are local overrides for various environment variables in Emacs.
1343 * Please do not remove this and leave it at the end of the file, where
1344 * Emacs will automagically detect them.
1345 * ---------------------------------------------------------------------
1348 * indent-tabs-mode: t