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
33 #include "native/jni.h"
34 #include "native/llni.h"
35 #include "native/native.h"
37 #include "native/include/java_lang_Boolean.h"
38 #include "native/include/java_lang_Byte.h"
39 #include "native/include/java_lang_Character.h"
40 #include "native/include/java_lang_Short.h"
41 #include "native/include/java_lang_Integer.h"
42 #include "native/include/java_lang_Long.h"
43 #include "native/include/java_lang_Float.h"
44 #include "native/include/java_lang_Double.h"
45 #include "native/include/java_lang_Object.h"
46 #include "native/include/java_lang_Class.h"
47 #include "native/include/java_lang_String.h"
49 #include "native/include/java_lang_reflect_Field.h"
51 #if defined(ENABLE_ANNOTATIONS)
52 #include "native/include/java_util_Map.h"
53 #include "native/include/sun_reflect_ConstantPool.h"
54 #include "native/vm/reflect.h"
57 #include "vm/access.h"
58 #include "vm/builtin.h"
59 #include "vm/exceptions.h"
60 #include "vm/global.h"
61 #include "vm/initialize.h"
62 #include "vm/primitive.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/utf8.h"
72 /* native methods implemented by this file ************************************/
74 static JNINativeMethod methods[] = {
75 { "getModifiersInternal", "()I", (void *) (intptr_t) &Java_java_lang_reflect_Field_getModifiersInternal },
76 { "getType", "()Ljava/lang/Class;", (void *) (intptr_t) &Java_java_lang_reflect_Field_getType },
77 { "get", "(Ljava/lang/Object;)Ljava/lang/Object;", (void *) (intptr_t) &Java_java_lang_reflect_Field_get },
78 { "getBoolean", "(Ljava/lang/Object;)Z", (void *) (intptr_t) &Java_java_lang_reflect_Field_getBoolean },
79 { "getByte", "(Ljava/lang/Object;)B", (void *) (intptr_t) &Java_java_lang_reflect_Field_getByte },
80 { "getChar", "(Ljava/lang/Object;)C", (void *) (intptr_t) &Java_java_lang_reflect_Field_getChar },
81 { "getShort", "(Ljava/lang/Object;)S", (void *) (intptr_t) &Java_java_lang_reflect_Field_getShort },
82 { "getInt", "(Ljava/lang/Object;)I", (void *) (intptr_t) &Java_java_lang_reflect_Field_getInt },
83 { "getLong", "(Ljava/lang/Object;)J", (void *) (intptr_t) &Java_java_lang_reflect_Field_getLong },
84 { "getFloat", "(Ljava/lang/Object;)F", (void *) (intptr_t) &Java_java_lang_reflect_Field_getFloat },
85 { "getDouble", "(Ljava/lang/Object;)D", (void *) (intptr_t) &Java_java_lang_reflect_Field_getDouble },
86 { "set", "(Ljava/lang/Object;Ljava/lang/Object;)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_set },
87 { "setBoolean", "(Ljava/lang/Object;Z)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setBoolean },
88 { "setByte", "(Ljava/lang/Object;B)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setByte },
89 { "setChar", "(Ljava/lang/Object;C)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setChar },
90 { "setShort", "(Ljava/lang/Object;S)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setShort },
91 { "setInt", "(Ljava/lang/Object;I)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setInt },
92 { "setLong", "(Ljava/lang/Object;J)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setLong },
93 { "setFloat", "(Ljava/lang/Object;F)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setFloat },
94 { "setDouble", "(Ljava/lang/Object;D)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setDouble },
95 { "getSignature", "()Ljava/lang/String;", (void *) (intptr_t) &Java_java_lang_reflect_Field_getSignature },
96 #if defined(ENABLE_ANNOTATIONS)
97 { "declaredAnnotations", "()Ljava/util/Map;", (void *) (intptr_t) &Java_java_lang_reflect_Field_declaredAnnotations },
102 /* _Jv_java_lang_reflect_Field_init ********************************************
104 Register native functions.
106 *******************************************************************************/
108 void _Jv_java_lang_reflect_Field_init(void)
112 u = utf_new_char("java/lang/reflect/Field");
114 native_method_register(u, methods, NATIVE_METHODS_COUNT);
118 /* cacao_get_field_address *****************************************************
120 Return the address of a field of an object.
123 this.........the field (a java.lang.reflect.Field object)
124 o............the object of which to get the field
127 a pointer to the field, or
128 NULL if an exception has been thrown
130 *******************************************************************************/
132 static void *cacao_get_field_address(java_lang_reflect_Field *this,
140 LLNI_field_get_cls(this, clazz, c);
141 LLNI_field_get_val(this, slot , slot);
142 f = &c->fields[slot];
144 /* check field access */
145 /* check if we should bypass security checks (AccessibleObject) */
147 LLNI_field_get_val(this, flag, flag);
149 /* this function is always called like this:
151 java.lang.reflect.Field.xxx (Native Method)
154 if (!access_check_field(f, 0))
158 /* get the address of the field */
160 if (f->flags & ACC_STATIC) {
161 /* initialize class if required */
163 if (!(c->state & CLASS_INITIALIZED))
164 if (!initialize_class(c))
167 /* return value pointer */
172 /* obj is required for not-static fields */
175 exceptions_throw_nullpointerexception();
179 if (builtin_instanceof((java_handle_t *) o, c))
180 return (void *) (((intptr_t) o) + f->offset);
185 exceptions_throw_illegalargumentexception();
192 * Class: java/lang/reflect/Field
193 * Method: getModifiersInternal
196 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getModifiersInternal(JNIEnv *env, java_lang_reflect_Field *this)
202 LLNI_field_get_cls(this, clazz, c);
203 LLNI_field_get_val(this, slot , slot);
204 f = &(c->fields[slot]);
211 * Class: java/lang/reflect/Field
213 * Signature: ()Ljava/lang/Class;
215 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
222 LLNI_field_get_cls(this, clazz, c);
223 LLNI_field_get_val(this, slot , slot);
224 desc = c->fields[slot].parseddesc;
229 if (!resolve_class_from_typedesc(desc, true, false, &ret))
232 return LLNI_classinfo_wrap(ret);
237 * Class: java/lang/reflect/Field
239 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
241 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *object)
250 LLNI_field_get_cls(this, clazz, c);
251 LLNI_field_get_val(this, slot , slot);
252 f = &c->fields[slot];
254 /* get address of the source field value */
256 if ((addr = cacao_get_field_address(this, object)) == NULL)
259 switch (f->parseddesc->decltype) {
260 case PRIMITIVETYPE_BOOLEAN:
261 case PRIMITIVETYPE_BYTE:
262 case PRIMITIVETYPE_CHAR:
263 case PRIMITIVETYPE_SHORT:
264 case PRIMITIVETYPE_INT:
265 value.i = *((int32_t *) addr);
268 case PRIMITIVETYPE_LONG:
269 value.l = *((int64_t *) addr);
272 case PRIMITIVETYPE_FLOAT:
273 value.f = *((float *) addr);
276 case PRIMITIVETYPE_DOUBLE:
277 value.d = *((double *) addr);
281 #warning this whole thing needs to be inside a critical section!
282 return (java_lang_Object *) *((java_handle_t **) addr);
285 /* Now box the primitive types. */
287 o = primitive_box(f->parseddesc->decltype, value);
289 return (java_lang_Object *) o;
294 * Class: java/lang/reflect/Field
296 * Signature: (Ljava/lang/Object;)Z
298 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
305 /* get the class and the field */
307 LLNI_field_get_cls(this, clazz, c);
308 LLNI_field_get_val(this, slot , slot);
309 f = &c->fields[slot];
311 /* get the address of the field with an internal helper */
313 if ((addr = cacao_get_field_address(this, o)) == NULL)
316 /* check the field type and return the value */
318 switch (f->parseddesc->decltype) {
319 case PRIMITIVETYPE_BOOLEAN:
320 return (int32_t) *((int32_t *) addr);
322 exceptions_throw_illegalargumentexception();
329 * Class: java/lang/reflect/Field
331 * Signature: (Ljava/lang/Object;)B
333 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
340 /* get the class and the field */
342 LLNI_field_get_cls(this, clazz, c);
343 LLNI_field_get_val(this, slot , slot);
344 f = &c->fields[slot];
346 /* get the address of the field with an internal helper */
348 if ((addr = cacao_get_field_address(this, o)) == NULL)
351 /* check the field type and return the value */
353 switch (f->parseddesc->decltype) {
354 case PRIMITIVETYPE_BYTE:
355 return (int32_t) *((int32_t *) addr);
357 exceptions_throw_illegalargumentexception();
364 * Class: java/lang/reflect/Field
366 * Signature: (Ljava/lang/Object;)C
368 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
375 /* get the class and the field */
377 LLNI_field_get_cls(this, clazz, c);
378 LLNI_field_get_val(this, slot , slot);
379 f = &c->fields[slot];
381 /* get the address of the field with an internal helper */
383 if ((addr = cacao_get_field_address(this, o)) == NULL)
386 /* check the field type and return the value */
388 switch (f->parseddesc->decltype) {
389 case PRIMITIVETYPE_CHAR:
390 return (int32_t) *((int32_t *) addr);
392 exceptions_throw_illegalargumentexception();
399 * Class: java/lang/reflect/Field
401 * Signature: (Ljava/lang/Object;)S
403 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
410 /* get the class and the field */
412 LLNI_field_get_cls(this, clazz, c);
413 LLNI_field_get_val(this, slot , slot);
414 f = &c->fields[slot];
416 /* get the address of the field with an internal helper */
418 if ((addr = cacao_get_field_address(this, o)) == NULL)
421 /* check the field type and return the value */
423 switch (f->parseddesc->decltype) {
424 case PRIMITIVETYPE_BYTE:
425 case PRIMITIVETYPE_SHORT:
426 return (int32_t) *((int32_t *) addr);
428 exceptions_throw_illegalargumentexception();
435 * Class: java/lang/reflect/Field
437 * Signature: (Ljava/lang/Object;)I
439 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
446 /* get the class and the field */
448 LLNI_field_get_cls(this, clazz, c);
449 LLNI_field_get_val(this, slot , slot);
450 f = &c->fields[slot];
452 /* get the address of the field with an internal helper */
454 if ((addr = cacao_get_field_address(this, o)) == NULL)
457 /* check the field type and return the value */
459 switch (f->parseddesc->decltype) {
460 case PRIMITIVETYPE_BYTE:
461 case PRIMITIVETYPE_CHAR:
462 case PRIMITIVETYPE_SHORT:
463 case PRIMITIVETYPE_INT:
464 return (int32_t) *((int32_t *) addr);
466 exceptions_throw_illegalargumentexception();
473 * Class: java/lang/reflect/Field
475 * Signature: (Ljava/lang/Object;)J
477 JNIEXPORT int64_t JNICALL Java_java_lang_reflect_Field_getLong(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_CHAR:
500 case PRIMITIVETYPE_SHORT:
501 case PRIMITIVETYPE_INT:
502 return (int64_t) *((int32_t *) addr);
503 case PRIMITIVETYPE_LONG:
504 return (int64_t) *((int64_t *) addr);
506 exceptions_throw_illegalargumentexception();
513 * Class: java/lang/reflect/Field
515 * Signature: (Ljava/lang/Object;)F
517 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
524 /* get the class and the field */
526 LLNI_field_get_cls(this, clazz, c);
527 LLNI_field_get_val(this, slot , slot);
528 f = &c->fields[slot];
530 /* get the address of the field with an internal helper */
532 if ((addr = cacao_get_field_address(this, o)) == NULL)
535 /* check the field type and return the value */
537 switch (f->parseddesc->decltype) {
538 case PRIMITIVETYPE_BYTE:
539 case PRIMITIVETYPE_CHAR:
540 case PRIMITIVETYPE_SHORT:
541 case PRIMITIVETYPE_INT:
542 return (float) *((int32_t *) addr);
543 case PRIMITIVETYPE_LONG:
544 return (float) *((int64_t *) addr);
545 case PRIMITIVETYPE_FLOAT:
546 return (float) *((float *) addr);
548 exceptions_throw_illegalargumentexception();
555 * Class: java/lang/reflect/Field
557 * Signature: (Ljava/lang/Object;)D
559 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
566 /* get the class and the field */
568 LLNI_field_get_cls(this, clazz, c);
569 LLNI_field_get_val(this, slot , slot);
570 f = &c->fields[slot];
572 /* get the address of the field with an internal helper */
574 if ((addr = cacao_get_field_address(this, o)) == NULL)
577 /* check the field type and return the value */
579 switch (f->parseddesc->decltype) {
580 case PRIMITIVETYPE_BYTE:
581 case PRIMITIVETYPE_CHAR:
582 case PRIMITIVETYPE_SHORT:
583 case PRIMITIVETYPE_INT:
584 return (double) *((int32_t *) addr);
585 case PRIMITIVETYPE_LONG:
586 return (double) *((int64_t *) addr);
587 case PRIMITIVETYPE_FLOAT:
588 return (double) *((float *) addr);
589 case PRIMITIVETYPE_DOUBLE:
590 return (double) *((double *) addr);
592 exceptions_throw_illegalargumentexception();
599 * Class: java/lang/reflect/Field
601 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
603 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, java_lang_Object *value)
612 /* get the class and the field */
614 LLNI_field_get_cls(this, clazz, dc);
615 LLNI_field_get_val(this, slot , slot);
616 df = &dc->fields[slot];
618 /* get the address of the destination field */
620 if ((faddr = cacao_get_field_address(this, o)) == NULL)
623 /* get the source classinfo from the object */
628 LLNI_class_get(value, sc);
630 /* The fieldid is used to set the new value, for primitive
631 types the value has to be retrieved from the wrapping
634 switch (df->parseddesc->decltype) {
635 case PRIMITIVETYPE_BOOLEAN: {
638 /* determine the field to read the value */
640 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
643 switch (sf->parseddesc->decltype) {
644 case PRIMITIVETYPE_BOOLEAN:
645 LLNI_field_get_val((java_lang_Boolean *) value, value, val);
648 exceptions_throw_illegalargumentexception();
652 *((int32_t *) faddr) = val;
656 case PRIMITIVETYPE_BYTE: {
659 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
662 switch (sf->parseddesc->decltype) {
663 case PRIMITIVETYPE_BYTE:
664 LLNI_field_get_val((java_lang_Byte *) value, value, val);
667 exceptions_throw_illegalargumentexception();
671 *((int32_t *) faddr) = val;
675 case PRIMITIVETYPE_CHAR: {
678 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
681 switch (sf->parseddesc->decltype) {
682 case PRIMITIVETYPE_CHAR:
683 LLNI_field_get_val((java_lang_Character *) value, value, val);
686 exceptions_throw_illegalargumentexception();
690 *((int32_t *) faddr) = val;
694 case PRIMITIVETYPE_SHORT: {
697 /* get field only by name, it can be one of B, S */
699 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
702 switch (sf->parseddesc->decltype) {
703 case PRIMITIVETYPE_BYTE:
704 LLNI_field_get_val((java_lang_Byte *) value, value, val);
706 case PRIMITIVETYPE_SHORT:
707 LLNI_field_get_val((java_lang_Short *) value, value, val);
710 exceptions_throw_illegalargumentexception();
714 *((int32_t *) faddr) = val;
718 case PRIMITIVETYPE_INT: {
721 /* get field only by name, it can be one of B, S, C, I */
723 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
726 switch (sf->parseddesc->decltype) {
727 case PRIMITIVETYPE_BYTE:
728 LLNI_field_get_val((java_lang_Byte *) value, value, val);
730 case PRIMITIVETYPE_CHAR:
731 LLNI_field_get_val((java_lang_Character *) value, value, val);
733 case PRIMITIVETYPE_SHORT:
734 LLNI_field_get_val((java_lang_Short *) value, value, val);
736 case PRIMITIVETYPE_INT:
737 LLNI_field_get_val((java_lang_Integer *) value, value, val);
740 exceptions_throw_illegalargumentexception();
744 *((int32_t *) faddr) = val;
748 case PRIMITIVETYPE_LONG: {
751 /* get field only by name, it can be one of B, S, C, I, J */
753 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
756 switch (sf->parseddesc->decltype) {
757 case PRIMITIVETYPE_BYTE:
758 LLNI_field_get_val((java_lang_Byte *) value, value, val);
760 case PRIMITIVETYPE_CHAR:
761 LLNI_field_get_val((java_lang_Character *) value, value, val);
763 case PRIMITIVETYPE_SHORT:
764 LLNI_field_get_val((java_lang_Short *) value, value, val);
766 case PRIMITIVETYPE_INT:
767 LLNI_field_get_val((java_lang_Integer *) value, value, val);
769 case PRIMITIVETYPE_LONG:
770 LLNI_field_get_val((java_lang_Long *) value, value, val);
773 exceptions_throw_illegalargumentexception();
777 *((int64_t *) faddr) = val;
781 case PRIMITIVETYPE_FLOAT: {
784 /* get field only by name, it can be one of B, S, C, I, J, F */
786 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
789 switch (sf->parseddesc->decltype) {
790 case PRIMITIVETYPE_BYTE:
791 LLNI_field_get_val((java_lang_Byte *) value, value, val);
793 case PRIMITIVETYPE_CHAR:
794 LLNI_field_get_val((java_lang_Character *) value, value, val);
796 case PRIMITIVETYPE_SHORT:
797 LLNI_field_get_val((java_lang_Short *) value, value, val);
799 case PRIMITIVETYPE_INT:
800 LLNI_field_get_val((java_lang_Integer *) value, value, val);
802 case PRIMITIVETYPE_LONG:
803 LLNI_field_get_val((java_lang_Long *) value, value, val);
805 case PRIMITIVETYPE_FLOAT:
806 LLNI_field_get_val((java_lang_Float *) value, value, val);
809 exceptions_throw_illegalargumentexception();
813 *((float *) faddr) = val;
817 case PRIMITIVETYPE_DOUBLE: {
820 /* get field only by name, it can be one of B, S, C, I, J, F, D */
822 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
825 switch (sf->parseddesc->decltype) {
826 case PRIMITIVETYPE_BYTE:
827 LLNI_field_get_val((java_lang_Byte *) value, value, val);
829 case PRIMITIVETYPE_CHAR:
830 LLNI_field_get_val((java_lang_Character *) value, value, val);
832 case PRIMITIVETYPE_SHORT:
833 LLNI_field_get_val((java_lang_Short *) value, value, val);
835 case PRIMITIVETYPE_INT:
836 LLNI_field_get_val((java_lang_Integer *) value, value, val);
838 case PRIMITIVETYPE_LONG:
839 LLNI_field_get_val((java_lang_Long *) value, value, val);
841 case PRIMITIVETYPE_FLOAT:
842 LLNI_field_get_val((java_lang_Float *) value, value, val);
844 case PRIMITIVETYPE_DOUBLE:
845 LLNI_field_get_val((java_lang_Double *) value, value, val);
848 exceptions_throw_illegalargumentexception();
852 *((double *) faddr) = val;
857 /* check if value is an instance of the destination class */
860 /* if (!builtin_instanceof((java_handle_t *) value, df->class)) */
863 *((java_lang_Object **) faddr) = value;
867 /* raise exception */
869 exceptions_throw_illegalargumentexception();
874 * Class: java/lang/reflect/Field
876 * Signature: (Ljava/lang/Object;Z)V
878 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
885 /* get the class and the field */
887 LLNI_field_get_cls(this, clazz, c);
888 LLNI_field_get_val(this, slot , slot);
889 f = &c->fields[slot];
891 /* get the address of the field with an internal helper */
893 if ((addr = cacao_get_field_address(this, o)) == NULL)
896 /* check the field type and set the value */
898 switch (f->parseddesc->decltype) {
899 case PRIMITIVETYPE_BOOLEAN:
900 *((int32_t *) addr) = value;
903 exceptions_throw_illegalargumentexception();
911 * Class: java/lang/reflect/Field
913 * Signature: (Ljava/lang/Object;B)V
915 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
922 /* get the class and the field */
924 LLNI_field_get_cls(this, clazz, c);
925 LLNI_field_get_val(this, slot , slot);
926 f = &c->fields[slot];
928 /* get the address of the field with an internal helper */
930 if ((addr = cacao_get_field_address(this, o)) == NULL)
933 /* check the field type and set the value */
935 switch (f->parseddesc->decltype) {
936 case PRIMITIVETYPE_BYTE:
937 case PRIMITIVETYPE_SHORT:
938 case PRIMITIVETYPE_INT:
939 *((int32_t *) addr) = value;
941 case PRIMITIVETYPE_LONG:
942 *((int64_t *) addr) = value;
944 case PRIMITIVETYPE_FLOAT:
945 *((float *) addr) = value;
947 case PRIMITIVETYPE_DOUBLE:
948 *((double *) addr) = value;
951 exceptions_throw_illegalargumentexception();
959 * Class: java/lang/reflect/Field
961 * Signature: (Ljava/lang/Object;C)V
963 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
970 /* get the class and the field */
972 LLNI_field_get_cls(this, clazz, c);
973 LLNI_field_get_val(this, slot , slot);
974 f = &c->fields[slot];
976 /* get the address of the field with an internal helper */
978 if ((addr = cacao_get_field_address(this, o)) == NULL)
981 /* check the field type and set the value */
983 switch (f->parseddesc->decltype) {
984 case PRIMITIVETYPE_CHAR:
985 case PRIMITIVETYPE_INT:
986 *((int32_t *) addr) = value;
988 case PRIMITIVETYPE_LONG:
989 *((int64_t *) addr) = value;
991 case PRIMITIVETYPE_FLOAT:
992 *((float *) addr) = value;
994 case PRIMITIVETYPE_DOUBLE:
995 *((double *) addr) = value;
998 exceptions_throw_illegalargumentexception();
1006 * Class: java/lang/reflect/Field
1008 * Signature: (Ljava/lang/Object;S)V
1010 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1017 /* get the class and the field */
1019 LLNI_field_get_cls(this, clazz, c);
1020 LLNI_field_get_val(this, slot , slot);
1021 f = &c->fields[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_SHORT:
1032 case PRIMITIVETYPE_INT:
1033 *((int32_t *) addr) = value;
1035 case PRIMITIVETYPE_LONG:
1036 *((int64_t *) addr) = value;
1038 case PRIMITIVETYPE_FLOAT:
1039 *((float *) addr) = value;
1041 case PRIMITIVETYPE_DOUBLE:
1042 *((double *) addr) = value;
1045 exceptions_throw_illegalargumentexception();
1053 * Class: java/lang/reflect/Field
1055 * Signature: (Ljava/lang/Object;I)V
1057 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1064 /* get the class and the field */
1066 LLNI_field_get_cls(this, clazz, c);
1067 LLNI_field_get_val(this, slot , slot);
1068 f = &c->fields[slot];
1070 /* get the address of the field with an internal helper */
1072 if ((addr = cacao_get_field_address(this, o)) == NULL)
1075 /* check the field type and set the value */
1077 switch (f->parseddesc->decltype) {
1078 case PRIMITIVETYPE_INT:
1079 *((int32_t *) addr) = value;
1081 case PRIMITIVETYPE_LONG:
1082 *((int64_t *) addr) = value;
1084 case PRIMITIVETYPE_FLOAT:
1085 *((float *) addr) = value;
1087 case PRIMITIVETYPE_DOUBLE:
1088 *((double *) addr) = value;
1091 exceptions_throw_illegalargumentexception();
1099 * Class: java/lang/reflect/Field
1101 * Signature: (Ljava/lang/Object;J)V
1103 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int64_t value)
1110 /* get the class and the field */
1112 LLNI_field_get_cls(this, clazz, c);
1113 LLNI_field_get_val(this, slot , slot);
1114 f = &c->fields[slot];
1116 /* get the address of the field with an internal helper */
1118 if ((addr = cacao_get_field_address(this, o)) == NULL)
1121 /* check the field type and set the value */
1123 switch (f->parseddesc->decltype) {
1124 case PRIMITIVETYPE_LONG:
1125 *((int64_t *) addr) = value;
1127 case PRIMITIVETYPE_FLOAT:
1128 *((float *) addr) = value;
1130 case PRIMITIVETYPE_DOUBLE:
1131 *((double *) addr) = value;
1134 exceptions_throw_illegalargumentexception();
1142 * Class: java/lang/reflect/Field
1144 * Signature: (Ljava/lang/Object;F)V
1146 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, float value)
1153 /* get the class and the field */
1155 LLNI_field_get_cls(this, clazz, c);
1156 LLNI_field_get_val(this, slot , slot);
1157 f = &c->fields[slot];
1159 /* get the address of the field with an internal helper */
1161 if ((addr = cacao_get_field_address(this, o)) == NULL)
1164 /* check the field type and set the value */
1166 switch (f->parseddesc->decltype) {
1167 case PRIMITIVETYPE_FLOAT:
1168 *((float *) addr) = value;
1170 case PRIMITIVETYPE_DOUBLE:
1171 *((double *) addr) = value;
1174 exceptions_throw_illegalargumentexception();
1182 * Class: java/lang/reflect/Field
1184 * Signature: (Ljava/lang/Object;D)V
1186 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, double value)
1193 /* get the class and the field */
1195 LLNI_field_get_cls(this, clazz, c);
1196 LLNI_field_get_val(this, slot , slot);
1197 f = &c->fields[slot];
1199 /* get the address of the field with an internal helper */
1201 if ((addr = cacao_get_field_address(this, o)) == NULL)
1204 /* check the field type and set the value */
1206 switch (f->parseddesc->decltype) {
1207 case PRIMITIVETYPE_DOUBLE:
1208 *((double *) addr) = value;
1211 exceptions_throw_illegalargumentexception();
1219 * Class: java/lang/reflect/Field
1220 * Method: getSignature
1221 * Signature: ()Ljava/lang/String;
1223 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Field_getSignature(JNIEnv *env, java_lang_reflect_Field* this)
1230 /* get the class and the field */
1232 LLNI_field_get_cls(this, clazz, c);
1233 LLNI_field_get_val(this, slot , slot);
1234 f = &c->fields[slot];
1236 if (f->signature == NULL)
1239 o = javastring_new(f->signature);
1241 /* in error case o is NULL */
1243 return (java_lang_String *) o;
1247 #if defined(ENABLE_ANNOTATIONS)
1249 * Class: java/lang/reflect/Field
1250 * Method: declaredAnnotations
1251 * Signature: ()Ljava/util/Map;
1253 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Field_declaredAnnotations(JNIEnv *env, java_lang_reflect_Field *this)
1255 java_util_Map *declaredAnnotations = NULL;
1256 java_handle_bytearray_t *annotations = NULL;
1257 java_lang_Class *declaringClass = NULL;
1258 classinfo *referer = NULL;
1260 LLNI_field_get_ref(this, declaredAnnotations, declaredAnnotations);
1262 if (declaredAnnotations == NULL) {
1263 LLNI_field_get_ref(this, annotations, annotations);
1264 LLNI_field_get_ref(this, clazz, declaringClass);
1265 LLNI_class_get(this, referer);
1267 declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
1269 LLNI_field_set_ref(this, declaredAnnotations, declaredAnnotations);
1272 return declaredAnnotations;
1278 * These are local overrides for various environment variables in Emacs.
1279 * Please do not remove this and leave it at the end of the file, where
1280 * Emacs will automagically detect them.
1281 * ---------------------------------------------------------------------
1284 * indent-tabs-mode: t