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 8393 2007-08-22 01:10:09Z panzi $
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/primitive.h"
64 #include "vm/resolve.h"
65 #include "vm/stringlocal.h"
67 #include "vm/jit/stacktrace.h"
69 #include "vmcore/loader.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_handle_t *) 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 LLNI_classinfo_wrap(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 *object)
251 LLNI_field_get_cls(this, clazz, c);
252 LLNI_field_get_val(this, slot , slot);
253 f = &c->fields[slot];
255 /* get address of the source field value */
257 if ((addr = cacao_get_field_address(this, object)) == NULL)
260 switch (f->parseddesc->decltype) {
261 case PRIMITIVETYPE_BOOLEAN:
262 case PRIMITIVETYPE_BYTE:
263 case PRIMITIVETYPE_CHAR:
264 case PRIMITIVETYPE_SHORT:
265 case PRIMITIVETYPE_INT:
266 value.i = *((int32_t *) addr);
269 case PRIMITIVETYPE_LONG:
270 value.l = *((int64_t *) addr);
273 case PRIMITIVETYPE_FLOAT:
274 value.f = *((float *) addr);
277 case PRIMITIVETYPE_DOUBLE:
278 value.d = *((double *) addr);
282 #warning this whole thing needs to be inside a critical section!
283 return (java_lang_Object *) *((java_handle_t **) addr);
286 /* Now box the primitive types. */
288 o = primitive_box(f->parseddesc->decltype, value);
290 return (java_lang_Object *) o;
295 * Class: java/lang/reflect/Field
297 * Signature: (Ljava/lang/Object;)Z
299 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
306 /* get the class and the field */
308 LLNI_field_get_cls(this, clazz, c);
309 LLNI_field_get_val(this, slot , slot);
310 f = &c->fields[slot];
312 /* get the address of the field with an internal helper */
314 if ((addr = cacao_get_field_address(this, o)) == NULL)
317 /* check the field type and return the value */
319 switch (f->parseddesc->decltype) {
320 case PRIMITIVETYPE_BOOLEAN:
321 return (int32_t) *((int32_t *) addr);
323 exceptions_throw_illegalargumentexception();
330 * Class: java/lang/reflect/Field
332 * Signature: (Ljava/lang/Object;)B
334 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
341 /* get the class and the field */
343 LLNI_field_get_cls(this, clazz, c);
344 LLNI_field_get_val(this, slot , slot);
345 f = &c->fields[slot];
347 /* get the address of the field with an internal helper */
349 if ((addr = cacao_get_field_address(this, o)) == NULL)
352 /* check the field type and return the value */
354 switch (f->parseddesc->decltype) {
355 case PRIMITIVETYPE_BYTE:
356 return (int32_t) *((int32_t *) addr);
358 exceptions_throw_illegalargumentexception();
365 * Class: java/lang/reflect/Field
367 * Signature: (Ljava/lang/Object;)C
369 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
376 /* get the class and the field */
378 LLNI_field_get_cls(this, clazz, c);
379 LLNI_field_get_val(this, slot , slot);
380 f = &c->fields[slot];
382 /* get the address of the field with an internal helper */
384 if ((addr = cacao_get_field_address(this, o)) == NULL)
387 /* check the field type and return the value */
389 switch (f->parseddesc->decltype) {
390 case PRIMITIVETYPE_CHAR:
391 return (int32_t) *((int32_t *) addr);
393 exceptions_throw_illegalargumentexception();
400 * Class: java/lang/reflect/Field
402 * Signature: (Ljava/lang/Object;)S
404 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
411 /* get the class and the field */
413 LLNI_field_get_cls(this, clazz, c);
414 LLNI_field_get_val(this, slot , slot);
415 f = &c->fields[slot];
417 /* get the address of the field with an internal helper */
419 if ((addr = cacao_get_field_address(this, o)) == NULL)
422 /* check the field type and return the value */
424 switch (f->parseddesc->decltype) {
425 case PRIMITIVETYPE_BYTE:
426 case PRIMITIVETYPE_SHORT:
427 return (int32_t) *((int32_t *) addr);
429 exceptions_throw_illegalargumentexception();
436 * Class: java/lang/reflect/Field
438 * Signature: (Ljava/lang/Object;)I
440 JNIEXPORT int32_t 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 LLNI_field_get_cls(this, clazz, c);
450 LLNI_field_get_val(this, slot , slot);
451 f = &c->fields[slot];
453 /* get the address of the field with an internal helper */
455 if ((addr = cacao_get_field_address(this, o)) == NULL)
458 /* check the field type and return the value */
460 switch (f->parseddesc->decltype) {
461 case PRIMITIVETYPE_BYTE:
462 case PRIMITIVETYPE_CHAR:
463 case PRIMITIVETYPE_SHORT:
464 case PRIMITIVETYPE_INT:
465 return (int32_t) *((int32_t *) addr);
467 exceptions_throw_illegalargumentexception();
474 * Class: java/lang/reflect/Field
476 * Signature: (Ljava/lang/Object;)J
478 JNIEXPORT int64_t JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
485 /* get the class and the field */
487 LLNI_field_get_cls(this, clazz, c);
488 LLNI_field_get_val(this, slot , slot);
489 f = &c->fields[slot];
491 /* get the address of the field with an internal helper */
493 if ((addr = cacao_get_field_address(this, o)) == NULL)
496 /* check the field type and return the value */
498 switch (f->parseddesc->decltype) {
499 case PRIMITIVETYPE_BYTE:
500 case PRIMITIVETYPE_CHAR:
501 case PRIMITIVETYPE_SHORT:
502 case PRIMITIVETYPE_INT:
503 return (int64_t) *((int32_t *) addr);
504 case PRIMITIVETYPE_LONG:
505 return (int64_t) *((int64_t *) addr);
507 exceptions_throw_illegalargumentexception();
514 * Class: java/lang/reflect/Field
516 * Signature: (Ljava/lang/Object;)F
518 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
525 /* get the class and the field */
527 LLNI_field_get_cls(this, clazz, c);
528 LLNI_field_get_val(this, slot , slot);
529 f = &c->fields[slot];
531 /* get the address of the field with an internal helper */
533 if ((addr = cacao_get_field_address(this, o)) == NULL)
536 /* check the field type and return the value */
538 switch (f->parseddesc->decltype) {
539 case PRIMITIVETYPE_BYTE:
540 case PRIMITIVETYPE_CHAR:
541 case PRIMITIVETYPE_SHORT:
542 case PRIMITIVETYPE_INT:
543 return (float) *((int32_t *) addr);
544 case PRIMITIVETYPE_LONG:
545 return (float) *((int64_t *) addr);
546 case PRIMITIVETYPE_FLOAT:
547 return (float) *((float *) addr);
549 exceptions_throw_illegalargumentexception();
556 * Class: java/lang/reflect/Field
558 * Signature: (Ljava/lang/Object;)D
560 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
567 /* get the class and the field */
569 LLNI_field_get_cls(this, clazz, c);
570 LLNI_field_get_val(this, slot , slot);
571 f = &c->fields[slot];
573 /* get the address of the field with an internal helper */
575 if ((addr = cacao_get_field_address(this, o)) == NULL)
578 /* check the field type and return the value */
580 switch (f->parseddesc->decltype) {
581 case PRIMITIVETYPE_BYTE:
582 case PRIMITIVETYPE_CHAR:
583 case PRIMITIVETYPE_SHORT:
584 case PRIMITIVETYPE_INT:
585 return (double) *((int32_t *) addr);
586 case PRIMITIVETYPE_LONG:
587 return (double) *((int64_t *) addr);
588 case PRIMITIVETYPE_FLOAT:
589 return (double) *((float *) addr);
590 case PRIMITIVETYPE_DOUBLE:
591 return (double) *((double *) addr);
593 exceptions_throw_illegalargumentexception();
600 * Class: java/lang/reflect/Field
602 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
604 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, java_lang_Object *value)
613 /* get the class and the field */
615 LLNI_field_get_cls(this, clazz, dc);
616 LLNI_field_get_val(this, slot , slot);
617 df = &dc->fields[slot];
619 /* get the address of the destination field */
621 if ((faddr = cacao_get_field_address(this, o)) == NULL)
624 /* get the source classinfo from the object */
629 LLNI_class_get(value, sc);
631 /* The fieldid is used to set the new value, for primitive
632 types the value has to be retrieved from the wrapping
635 switch (df->parseddesc->decltype) {
636 case PRIMITIVETYPE_BOOLEAN: {
639 /* determine the field to read the value */
641 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
644 switch (sf->parseddesc->decltype) {
645 case PRIMITIVETYPE_BOOLEAN:
646 LLNI_field_get_val((java_lang_Boolean *) value, value, val);
649 exceptions_throw_illegalargumentexception();
653 *((int32_t *) faddr) = val;
657 case PRIMITIVETYPE_BYTE: {
660 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
663 switch (sf->parseddesc->decltype) {
664 case PRIMITIVETYPE_BYTE:
665 LLNI_field_get_val((java_lang_Byte *) value, value, val);
668 exceptions_throw_illegalargumentexception();
672 *((int32_t *) faddr) = val;
676 case PRIMITIVETYPE_CHAR: {
679 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
682 switch (sf->parseddesc->decltype) {
683 case PRIMITIVETYPE_CHAR:
684 LLNI_field_get_val((java_lang_Character *) value, value, val);
687 exceptions_throw_illegalargumentexception();
691 *((int32_t *) faddr) = val;
695 case PRIMITIVETYPE_SHORT: {
698 /* get field only by name, it can be one of B, S */
700 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
703 switch (sf->parseddesc->decltype) {
704 case PRIMITIVETYPE_BYTE:
705 LLNI_field_get_val((java_lang_Byte *) value, value, val);
707 case PRIMITIVETYPE_SHORT:
708 LLNI_field_get_val((java_lang_Short *) value, value, val);
711 exceptions_throw_illegalargumentexception();
715 *((int32_t *) faddr) = val;
719 case PRIMITIVETYPE_INT: {
722 /* get field only by name, it can be one of B, S, C, I */
724 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
727 switch (sf->parseddesc->decltype) {
728 case PRIMITIVETYPE_BYTE:
729 LLNI_field_get_val((java_lang_Byte *) value, value, val);
731 case PRIMITIVETYPE_CHAR:
732 LLNI_field_get_val((java_lang_Character *) value, value, val);
734 case PRIMITIVETYPE_SHORT:
735 LLNI_field_get_val((java_lang_Short *) value, value, val);
737 case PRIMITIVETYPE_INT:
738 LLNI_field_get_val((java_lang_Integer *) value, value, val);
741 exceptions_throw_illegalargumentexception();
745 *((int32_t *) faddr) = val;
749 case PRIMITIVETYPE_LONG: {
752 /* get field only by name, it can be one of B, S, C, I, J */
754 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
757 switch (sf->parseddesc->decltype) {
758 case PRIMITIVETYPE_BYTE:
759 LLNI_field_get_val((java_lang_Byte *) value, value, val);
761 case PRIMITIVETYPE_CHAR:
762 LLNI_field_get_val((java_lang_Character *) value, value, val);
764 case PRIMITIVETYPE_SHORT:
765 LLNI_field_get_val((java_lang_Short *) value, value, val);
767 case PRIMITIVETYPE_INT:
768 LLNI_field_get_val((java_lang_Integer *) value, value, val);
770 case PRIMITIVETYPE_LONG:
771 LLNI_field_get_val((java_lang_Long *) value, value, val);
774 exceptions_throw_illegalargumentexception();
778 *((int64_t *) faddr) = val;
782 case PRIMITIVETYPE_FLOAT: {
785 /* get field only by name, it can be one of B, S, C, I, J, F */
787 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
790 switch (sf->parseddesc->decltype) {
791 case PRIMITIVETYPE_BYTE:
792 LLNI_field_get_val((java_lang_Byte *) value, value, val);
794 case PRIMITIVETYPE_CHAR:
795 LLNI_field_get_val((java_lang_Character *) value, value, val);
797 case PRIMITIVETYPE_SHORT:
798 LLNI_field_get_val((java_lang_Short *) value, value, val);
800 case PRIMITIVETYPE_INT:
801 LLNI_field_get_val((java_lang_Integer *) value, value, val);
803 case PRIMITIVETYPE_LONG:
804 LLNI_field_get_val((java_lang_Long *) value, value, val);
806 case PRIMITIVETYPE_FLOAT:
807 LLNI_field_get_val((java_lang_Float *) value, value, val);
810 exceptions_throw_illegalargumentexception();
814 *((float *) faddr) = val;
818 case PRIMITIVETYPE_DOUBLE: {
821 /* get field only by name, it can be one of B, S, C, I, J, F, D */
823 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
826 switch (sf->parseddesc->decltype) {
827 case PRIMITIVETYPE_BYTE:
828 LLNI_field_get_val((java_lang_Byte *) value, value, val);
830 case PRIMITIVETYPE_CHAR:
831 LLNI_field_get_val((java_lang_Character *) value, value, val);
833 case PRIMITIVETYPE_SHORT:
834 LLNI_field_get_val((java_lang_Short *) value, value, val);
836 case PRIMITIVETYPE_INT:
837 LLNI_field_get_val((java_lang_Integer *) value, value, val);
839 case PRIMITIVETYPE_LONG:
840 LLNI_field_get_val((java_lang_Long *) value, value, val);
842 case PRIMITIVETYPE_FLOAT:
843 LLNI_field_get_val((java_lang_Float *) value, value, val);
845 case PRIMITIVETYPE_DOUBLE:
846 LLNI_field_get_val((java_lang_Double *) value, value, val);
849 exceptions_throw_illegalargumentexception();
853 *((double *) faddr) = val;
858 /* check if value is an instance of the destination class */
861 /* if (!builtin_instanceof((java_handle_t *) value, df->class)) */
864 *((java_lang_Object **) faddr) = value;
868 /* raise exception */
870 exceptions_throw_illegalargumentexception();
875 * Class: java/lang/reflect/Field
877 * Signature: (Ljava/lang/Object;Z)V
879 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
886 /* get the class and the field */
888 LLNI_field_get_cls(this, clazz, c);
889 LLNI_field_get_val(this, slot , slot);
890 f = &c->fields[slot];
892 /* get the address of the field with an internal helper */
894 if ((addr = cacao_get_field_address(this, o)) == NULL)
897 /* check the field type and set the value */
899 switch (f->parseddesc->decltype) {
900 case PRIMITIVETYPE_BOOLEAN:
901 *((int32_t *) addr) = value;
904 exceptions_throw_illegalargumentexception();
912 * Class: java/lang/reflect/Field
914 * Signature: (Ljava/lang/Object;B)V
916 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
923 /* get the class and the field */
925 LLNI_field_get_cls(this, clazz, c);
926 LLNI_field_get_val(this, slot , slot);
927 f = &c->fields[slot];
929 /* get the address of the field with an internal helper */
931 if ((addr = cacao_get_field_address(this, o)) == NULL)
934 /* check the field type and set the value */
936 switch (f->parseddesc->decltype) {
937 case PRIMITIVETYPE_BYTE:
938 case PRIMITIVETYPE_SHORT:
939 case PRIMITIVETYPE_INT:
940 *((int32_t *) addr) = value;
942 case PRIMITIVETYPE_LONG:
943 *((int64_t *) addr) = value;
945 case PRIMITIVETYPE_FLOAT:
946 *((float *) addr) = value;
948 case PRIMITIVETYPE_DOUBLE:
949 *((double *) addr) = value;
952 exceptions_throw_illegalargumentexception();
960 * Class: java/lang/reflect/Field
962 * Signature: (Ljava/lang/Object;C)V
964 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
971 /* get the class and the field */
973 LLNI_field_get_cls(this, clazz, c);
974 LLNI_field_get_val(this, slot , slot);
975 f = &c->fields[slot];
977 /* get the address of the field with an internal helper */
979 if ((addr = cacao_get_field_address(this, o)) == NULL)
982 /* check the field type and set the value */
984 switch (f->parseddesc->decltype) {
985 case PRIMITIVETYPE_CHAR:
986 case PRIMITIVETYPE_INT:
987 *((int32_t *) addr) = value;
989 case PRIMITIVETYPE_LONG:
990 *((int64_t *) addr) = value;
992 case PRIMITIVETYPE_FLOAT:
993 *((float *) addr) = value;
995 case PRIMITIVETYPE_DOUBLE:
996 *((double *) addr) = value;
999 exceptions_throw_illegalargumentexception();
1007 * Class: java/lang/reflect/Field
1009 * Signature: (Ljava/lang/Object;S)V
1011 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1018 /* get the class and the field */
1020 LLNI_field_get_cls(this, clazz, c);
1021 LLNI_field_get_val(this, slot , slot);
1022 f = &c->fields[slot];
1024 /* get the address of the field with an internal helper */
1026 if ((addr = cacao_get_field_address(this, o)) == NULL)
1029 /* check the field type and set the value */
1031 switch (f->parseddesc->decltype) {
1032 case PRIMITIVETYPE_SHORT:
1033 case PRIMITIVETYPE_INT:
1034 *((int32_t *) addr) = value;
1036 case PRIMITIVETYPE_LONG:
1037 *((int64_t *) addr) = value;
1039 case PRIMITIVETYPE_FLOAT:
1040 *((float *) addr) = value;
1042 case PRIMITIVETYPE_DOUBLE:
1043 *((double *) addr) = value;
1046 exceptions_throw_illegalargumentexception();
1054 * Class: java/lang/reflect/Field
1056 * Signature: (Ljava/lang/Object;I)V
1058 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1065 /* get the class and the field */
1067 LLNI_field_get_cls(this, clazz, c);
1068 LLNI_field_get_val(this, slot , slot);
1069 f = &c->fields[slot];
1071 /* get the address of the field with an internal helper */
1073 if ((addr = cacao_get_field_address(this, o)) == NULL)
1076 /* check the field type and set the value */
1078 switch (f->parseddesc->decltype) {
1079 case PRIMITIVETYPE_INT:
1080 *((int32_t *) addr) = value;
1082 case PRIMITIVETYPE_LONG:
1083 *((int64_t *) addr) = value;
1085 case PRIMITIVETYPE_FLOAT:
1086 *((float *) addr) = value;
1088 case PRIMITIVETYPE_DOUBLE:
1089 *((double *) addr) = value;
1092 exceptions_throw_illegalargumentexception();
1100 * Class: java/lang/reflect/Field
1102 * Signature: (Ljava/lang/Object;J)V
1104 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int64_t value)
1111 /* get the class and the field */
1113 LLNI_field_get_cls(this, clazz, c);
1114 LLNI_field_get_val(this, slot , slot);
1115 f = &c->fields[slot];
1117 /* get the address of the field with an internal helper */
1119 if ((addr = cacao_get_field_address(this, o)) == NULL)
1122 /* check the field type and set the value */
1124 switch (f->parseddesc->decltype) {
1125 case PRIMITIVETYPE_LONG:
1126 *((int64_t *) addr) = value;
1128 case PRIMITIVETYPE_FLOAT:
1129 *((float *) addr) = value;
1131 case PRIMITIVETYPE_DOUBLE:
1132 *((double *) addr) = value;
1135 exceptions_throw_illegalargumentexception();
1143 * Class: java/lang/reflect/Field
1145 * Signature: (Ljava/lang/Object;F)V
1147 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, float value)
1154 /* get the class and the field */
1156 LLNI_field_get_cls(this, clazz, c);
1157 LLNI_field_get_val(this, slot , slot);
1158 f = &c->fields[slot];
1160 /* get the address of the field with an internal helper */
1162 if ((addr = cacao_get_field_address(this, o)) == NULL)
1165 /* check the field type and set the value */
1167 switch (f->parseddesc->decltype) {
1168 case PRIMITIVETYPE_FLOAT:
1169 *((float *) addr) = value;
1171 case PRIMITIVETYPE_DOUBLE:
1172 *((double *) addr) = value;
1175 exceptions_throw_illegalargumentexception();
1183 * Class: java/lang/reflect/Field
1185 * Signature: (Ljava/lang/Object;D)V
1187 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, double value)
1194 /* get the class and the field */
1196 LLNI_field_get_cls(this, clazz, c);
1197 LLNI_field_get_val(this, slot , slot);
1198 f = &c->fields[slot];
1200 /* get the address of the field with an internal helper */
1202 if ((addr = cacao_get_field_address(this, o)) == NULL)
1205 /* check the field type and set the value */
1207 switch (f->parseddesc->decltype) {
1208 case PRIMITIVETYPE_DOUBLE:
1209 *((double *) addr) = value;
1212 exceptions_throw_illegalargumentexception();
1220 * Class: java/lang/reflect/Field
1221 * Method: getSignature
1222 * Signature: ()Ljava/lang/String;
1224 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Field_getSignature(JNIEnv *env, java_lang_reflect_Field* this)
1231 /* get the class and the field */
1233 LLNI_field_get_cls(this, clazz, c);
1234 LLNI_field_get_val(this, slot , slot);
1235 f = &c->fields[slot];
1237 if (f->signature == NULL)
1240 o = javastring_new(f->signature);
1242 /* in error case o is NULL */
1244 return (java_lang_String *) o;
1248 #if defined(ENABLE_ANNOTATIONS)
1250 * Class: java/lang/reflect/Field
1251 * Method: declaredAnnotations
1252 * Signature: ()Ljava/util/Map;
1254 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Field_declaredAnnotations(JNIEnv *env, java_lang_reflect_Field *this)
1256 java_handle_t *o = (java_handle_t*)this;
1257 struct java_util_Map *declaredAnnotations = NULL;
1258 java_handle_bytearray_t *annotations = NULL;
1259 java_lang_Class *declaringClass = NULL;
1260 classinfo *referer = NULL;
1262 LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
1264 if (declaredAnnotations == NULL) {
1265 LLNI_field_get_val(this, annotations, annotations);
1266 LLNI_field_get_ref(this, clazz, declaringClass);
1267 LLNI_class_get(this, referer);
1269 declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
1271 LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
1274 return declaredAnnotations;
1280 * These are local overrides for various environment variables in Emacs.
1281 * Please do not remove this and leave it at the end of the file, where
1282 * Emacs will automagically detect them.
1283 * ---------------------------------------------------------------------
1286 * indent-tabs-mode: t