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/sun_reflect_ConstantPool.h"
53 #include "native/vm/reflect.h"
56 #include "vm/access.h"
57 #include "vm/builtin.h"
58 #include "vm/exceptions.h"
59 #include "vm/global.h"
60 #include "vm/initialize.h"
61 #include "vm/primitive.h"
62 #include "vm/resolve.h"
63 #include "vm/stringlocal.h"
65 #include "vm/jit/stacktrace.h"
67 #include "vmcore/loader.h"
68 #include "vmcore/utf8.h"
71 /* native methods implemented by this file ************************************/
73 static JNINativeMethod methods[] = {
74 { "getModifiersInternal", "()I", (void *) (intptr_t) &Java_java_lang_reflect_Field_getModifiersInternal },
75 { "getType", "()Ljava/lang/Class;", (void *) (intptr_t) &Java_java_lang_reflect_Field_getType },
76 { "get", "(Ljava/lang/Object;)Ljava/lang/Object;", (void *) (intptr_t) &Java_java_lang_reflect_Field_get },
77 { "getBoolean", "(Ljava/lang/Object;)Z", (void *) (intptr_t) &Java_java_lang_reflect_Field_getBoolean },
78 { "getByte", "(Ljava/lang/Object;)B", (void *) (intptr_t) &Java_java_lang_reflect_Field_getByte },
79 { "getChar", "(Ljava/lang/Object;)C", (void *) (intptr_t) &Java_java_lang_reflect_Field_getChar },
80 { "getShort", "(Ljava/lang/Object;)S", (void *) (intptr_t) &Java_java_lang_reflect_Field_getShort },
81 { "getInt", "(Ljava/lang/Object;)I", (void *) (intptr_t) &Java_java_lang_reflect_Field_getInt },
82 { "getLong", "(Ljava/lang/Object;)J", (void *) (intptr_t) &Java_java_lang_reflect_Field_getLong },
83 { "getFloat", "(Ljava/lang/Object;)F", (void *) (intptr_t) &Java_java_lang_reflect_Field_getFloat },
84 { "getDouble", "(Ljava/lang/Object;)D", (void *) (intptr_t) &Java_java_lang_reflect_Field_getDouble },
85 { "set", "(Ljava/lang/Object;Ljava/lang/Object;)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_set },
86 { "setBoolean", "(Ljava/lang/Object;Z)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setBoolean },
87 { "setByte", "(Ljava/lang/Object;B)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setByte },
88 { "setChar", "(Ljava/lang/Object;C)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setChar },
89 { "setShort", "(Ljava/lang/Object;S)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setShort },
90 { "setInt", "(Ljava/lang/Object;I)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setInt },
91 { "setLong", "(Ljava/lang/Object;J)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setLong },
92 { "setFloat", "(Ljava/lang/Object;F)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setFloat },
93 { "setDouble", "(Ljava/lang/Object;D)V", (void *) (intptr_t) &Java_java_lang_reflect_Field_setDouble },
94 { "getSignature", "()Ljava/lang/String;", (void *) (intptr_t) &Java_java_lang_reflect_Field_getSignature },
95 #if defined(ENABLE_ANNOTATIONS)
96 { "declaredAnnotations", "()Ljava/util/Map;", (void *) (intptr_t) &Java_java_lang_reflect_Field_declaredAnnotations },
101 /* _Jv_java_lang_reflect_Field_init ********************************************
103 Register native functions.
105 *******************************************************************************/
107 void _Jv_java_lang_reflect_Field_init(void)
111 u = utf_new_char("java/lang/reflect/Field");
113 native_method_register(u, methods, NATIVE_METHODS_COUNT);
117 /* cacao_get_field_address *****************************************************
119 Return the address of a field of an object.
122 this.........the field (a java.lang.reflect.Field object)
123 o............the object of which to get the field
126 a pointer to the field, or
127 NULL if an exception has been thrown
129 *******************************************************************************/
131 static void *cacao_get_field_address(java_lang_reflect_Field *this,
139 LLNI_field_get_cls(this, clazz, c);
140 LLNI_field_get_val(this, slot , slot);
141 f = &c->fields[slot];
143 /* check field access */
144 /* check if we should bypass security checks (AccessibleObject) */
146 LLNI_field_get_val(this, flag, flag);
148 /* this function is always called like this:
150 java.lang.reflect.Field.xxx (Native Method)
153 if (!access_check_field(f, 0))
157 /* get the address of the field */
159 if (f->flags & ACC_STATIC) {
160 /* initialize class if required */
162 if (!(c->state & CLASS_INITIALIZED))
163 if (!initialize_class(c))
166 /* return value pointer */
171 /* obj is required for not-static fields */
174 exceptions_throw_nullpointerexception();
178 if (builtin_instanceof((java_handle_t *) o, c))
179 return (void *) (((intptr_t) o) + f->offset);
184 exceptions_throw_illegalargumentexception();
191 * Class: java/lang/reflect/Field
192 * Method: getModifiersInternal
195 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getModifiersInternal(JNIEnv *env, java_lang_reflect_Field *this)
201 LLNI_field_get_cls(this, clazz, c);
202 LLNI_field_get_val(this, slot , slot);
203 f = &(c->fields[slot]);
210 * Class: java/lang/reflect/Field
212 * Signature: ()Ljava/lang/Class;
214 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Field_getType(JNIEnv *env, java_lang_reflect_Field *this)
221 LLNI_field_get_cls(this, clazz, c);
222 LLNI_field_get_val(this, slot , slot);
223 desc = c->fields[slot].parseddesc;
228 if (!resolve_class_from_typedesc(desc, true, false, &ret))
231 return LLNI_classinfo_wrap(ret);
236 * Class: java/lang/reflect/Field
238 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
240 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Field_get(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *object)
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, object)) == NULL)
258 switch (f->parseddesc->decltype) {
259 case PRIMITIVETYPE_BOOLEAN:
260 case PRIMITIVETYPE_BYTE:
261 case PRIMITIVETYPE_CHAR:
262 case PRIMITIVETYPE_SHORT:
263 case PRIMITIVETYPE_INT:
264 value.i = *((int32_t *) addr);
267 case PRIMITIVETYPE_LONG:
268 value.l = *((int64_t *) addr);
271 case PRIMITIVETYPE_FLOAT:
272 value.f = *((float *) addr);
275 case PRIMITIVETYPE_DOUBLE:
276 value.d = *((double *) addr);
280 #warning this whole thing needs to be inside a critical section!
281 return (java_lang_Object *) *((java_handle_t **) addr);
284 /* Now box the primitive types. */
286 o = primitive_box(f->parseddesc->decltype, value);
288 return (java_lang_Object *) o;
293 * Class: java/lang/reflect/Field
295 * Signature: (Ljava/lang/Object;)Z
297 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
304 /* get the class and the field */
306 LLNI_field_get_cls(this, clazz, c);
307 LLNI_field_get_val(this, slot , slot);
308 f = &c->fields[slot];
310 /* get the address of the field with an internal helper */
312 if ((addr = cacao_get_field_address(this, o)) == NULL)
315 /* check the field type and return the value */
317 switch (f->parseddesc->decltype) {
318 case PRIMITIVETYPE_BOOLEAN:
319 return (int32_t) *((int32_t *) addr);
321 exceptions_throw_illegalargumentexception();
328 * Class: java/lang/reflect/Field
330 * Signature: (Ljava/lang/Object;)B
332 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
339 /* get the class and the field */
341 LLNI_field_get_cls(this, clazz, c);
342 LLNI_field_get_val(this, slot , slot);
343 f = &c->fields[slot];
345 /* get the address of the field with an internal helper */
347 if ((addr = cacao_get_field_address(this, o)) == NULL)
350 /* check the field type and return the value */
352 switch (f->parseddesc->decltype) {
353 case PRIMITIVETYPE_BYTE:
354 return (int32_t) *((int32_t *) addr);
356 exceptions_throw_illegalargumentexception();
363 * Class: java/lang/reflect/Field
365 * Signature: (Ljava/lang/Object;)C
367 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
374 /* get the class and the field */
376 LLNI_field_get_cls(this, clazz, c);
377 LLNI_field_get_val(this, slot , slot);
378 f = &c->fields[slot];
380 /* get the address of the field with an internal helper */
382 if ((addr = cacao_get_field_address(this, o)) == NULL)
385 /* check the field type and return the value */
387 switch (f->parseddesc->decltype) {
388 case PRIMITIVETYPE_CHAR:
389 return (int32_t) *((int32_t *) addr);
391 exceptions_throw_illegalargumentexception();
398 * Class: java/lang/reflect/Field
400 * Signature: (Ljava/lang/Object;)S
402 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
409 /* get the class and the field */
411 LLNI_field_get_cls(this, clazz, c);
412 LLNI_field_get_val(this, slot , slot);
413 f = &c->fields[slot];
415 /* get the address of the field with an internal helper */
417 if ((addr = cacao_get_field_address(this, o)) == NULL)
420 /* check the field type and return the value */
422 switch (f->parseddesc->decltype) {
423 case PRIMITIVETYPE_BYTE:
424 case PRIMITIVETYPE_SHORT:
425 return (int32_t) *((int32_t *) addr);
427 exceptions_throw_illegalargumentexception();
434 * Class: java/lang/reflect/Field
436 * Signature: (Ljava/lang/Object;)I
438 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_Field_getInt(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
445 /* get the class and the field */
447 LLNI_field_get_cls(this, clazz, c);
448 LLNI_field_get_val(this, slot , slot);
449 f = &c->fields[slot];
451 /* get the address of the field with an internal helper */
453 if ((addr = cacao_get_field_address(this, o)) == NULL)
456 /* check the field type and return the value */
458 switch (f->parseddesc->decltype) {
459 case PRIMITIVETYPE_BYTE:
460 case PRIMITIVETYPE_CHAR:
461 case PRIMITIVETYPE_SHORT:
462 case PRIMITIVETYPE_INT:
463 return (int32_t) *((int32_t *) addr);
465 exceptions_throw_illegalargumentexception();
472 * Class: java/lang/reflect/Field
474 * Signature: (Ljava/lang/Object;)J
476 JNIEXPORT int64_t JNICALL Java_java_lang_reflect_Field_getLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
483 /* get the class and the field */
485 LLNI_field_get_cls(this, clazz, c);
486 LLNI_field_get_val(this, slot , slot);
487 f = &c->fields[slot];
489 /* get the address of the field with an internal helper */
491 if ((addr = cacao_get_field_address(this, o)) == NULL)
494 /* check the field type and return the value */
496 switch (f->parseddesc->decltype) {
497 case PRIMITIVETYPE_BYTE:
498 case PRIMITIVETYPE_CHAR:
499 case PRIMITIVETYPE_SHORT:
500 case PRIMITIVETYPE_INT:
501 return (int64_t) *((int32_t *) addr);
502 case PRIMITIVETYPE_LONG:
503 return (int64_t) *((int64_t *) addr);
505 exceptions_throw_illegalargumentexception();
512 * Class: java/lang/reflect/Field
514 * Signature: (Ljava/lang/Object;)F
516 JNIEXPORT float JNICALL Java_java_lang_reflect_Field_getFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o)
523 /* get the class and the field */
525 LLNI_field_get_cls(this, clazz, c);
526 LLNI_field_get_val(this, slot , slot);
527 f = &c->fields[slot];
529 /* get the address of the field with an internal helper */
531 if ((addr = cacao_get_field_address(this, o)) == NULL)
534 /* check the field type and return the value */
536 switch (f->parseddesc->decltype) {
537 case PRIMITIVETYPE_BYTE:
538 case PRIMITIVETYPE_CHAR:
539 case PRIMITIVETYPE_SHORT:
540 case PRIMITIVETYPE_INT:
541 return (float) *((int32_t *) addr);
542 case PRIMITIVETYPE_LONG:
543 return (float) *((int64_t *) addr);
544 case PRIMITIVETYPE_FLOAT:
545 return (float) *((float *) addr);
547 exceptions_throw_illegalargumentexception();
554 * Class: java/lang/reflect/Field
556 * Signature: (Ljava/lang/Object;)D
558 JNIEXPORT double JNICALL Java_java_lang_reflect_Field_getDouble(JNIEnv *env , java_lang_reflect_Field *this, java_lang_Object *o)
565 /* get the class and the field */
567 LLNI_field_get_cls(this, clazz, c);
568 LLNI_field_get_val(this, slot , slot);
569 f = &c->fields[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 (double) *((int32_t *) addr);
584 case PRIMITIVETYPE_LONG:
585 return (double) *((int64_t *) addr);
586 case PRIMITIVETYPE_FLOAT:
587 return (double) *((float *) addr);
588 case PRIMITIVETYPE_DOUBLE:
589 return (double) *((double *) addr);
591 exceptions_throw_illegalargumentexception();
598 * Class: java/lang/reflect/Field
600 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
602 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_set(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, java_lang_Object *value)
611 /* get the class and the field */
613 LLNI_field_get_cls(this, clazz, dc);
614 LLNI_field_get_val(this, slot , slot);
615 df = &dc->fields[slot];
617 /* get the address of the destination field */
619 if ((faddr = cacao_get_field_address(this, o)) == NULL)
622 /* get the source classinfo from the object */
627 LLNI_class_get(value, sc);
629 /* The fieldid is used to set the new value, for primitive
630 types the value has to be retrieved from the wrapping
633 switch (df->parseddesc->decltype) {
634 case PRIMITIVETYPE_BOOLEAN: {
637 /* determine the field to read the value */
639 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
642 switch (sf->parseddesc->decltype) {
643 case PRIMITIVETYPE_BOOLEAN:
644 LLNI_field_get_val((java_lang_Boolean *) value, value, val);
647 exceptions_throw_illegalargumentexception();
651 *((int32_t *) faddr) = val;
655 case PRIMITIVETYPE_BYTE: {
658 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
661 switch (sf->parseddesc->decltype) {
662 case PRIMITIVETYPE_BYTE:
663 LLNI_field_get_val((java_lang_Byte *) value, value, val);
666 exceptions_throw_illegalargumentexception();
670 *((int32_t *) faddr) = val;
674 case PRIMITIVETYPE_CHAR: {
677 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
680 switch (sf->parseddesc->decltype) {
681 case PRIMITIVETYPE_CHAR:
682 LLNI_field_get_val((java_lang_Character *) value, value, val);
685 exceptions_throw_illegalargumentexception();
689 *((int32_t *) faddr) = val;
693 case PRIMITIVETYPE_SHORT: {
696 /* get field only by name, it can be one of B, S */
698 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
701 switch (sf->parseddesc->decltype) {
702 case PRIMITIVETYPE_BYTE:
703 LLNI_field_get_val((java_lang_Byte *) value, value, val);
705 case PRIMITIVETYPE_SHORT:
706 LLNI_field_get_val((java_lang_Short *) value, value, val);
709 exceptions_throw_illegalargumentexception();
713 *((int32_t *) faddr) = val;
717 case PRIMITIVETYPE_INT: {
720 /* get field only by name, it can be one of B, S, C, I */
722 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
725 switch (sf->parseddesc->decltype) {
726 case PRIMITIVETYPE_BYTE:
727 LLNI_field_get_val((java_lang_Byte *) value, value, val);
729 case PRIMITIVETYPE_CHAR:
730 LLNI_field_get_val((java_lang_Character *) value, value, val);
732 case PRIMITIVETYPE_SHORT:
733 LLNI_field_get_val((java_lang_Short *) value, value, val);
735 case PRIMITIVETYPE_INT:
736 LLNI_field_get_val((java_lang_Integer *) value, value, val);
739 exceptions_throw_illegalargumentexception();
743 *((int32_t *) faddr) = val;
747 case PRIMITIVETYPE_LONG: {
750 /* get field only by name, it can be one of B, S, C, I, J */
752 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
755 switch (sf->parseddesc->decltype) {
756 case PRIMITIVETYPE_BYTE:
757 LLNI_field_get_val((java_lang_Byte *) value, value, val);
759 case PRIMITIVETYPE_CHAR:
760 LLNI_field_get_val((java_lang_Character *) value, value, val);
762 case PRIMITIVETYPE_SHORT:
763 LLNI_field_get_val((java_lang_Short *) value, value, val);
765 case PRIMITIVETYPE_INT:
766 LLNI_field_get_val((java_lang_Integer *) value, value, val);
768 case PRIMITIVETYPE_LONG:
769 LLNI_field_get_val((java_lang_Long *) value, value, val);
772 exceptions_throw_illegalargumentexception();
776 *((int64_t *) faddr) = val;
780 case PRIMITIVETYPE_FLOAT: {
783 /* get field only by name, it can be one of B, S, C, I, J, F */
785 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
788 switch (sf->parseddesc->decltype) {
789 case PRIMITIVETYPE_BYTE:
790 LLNI_field_get_val((java_lang_Byte *) value, value, val);
792 case PRIMITIVETYPE_CHAR:
793 LLNI_field_get_val((java_lang_Character *) value, value, val);
795 case PRIMITIVETYPE_SHORT:
796 LLNI_field_get_val((java_lang_Short *) value, value, val);
798 case PRIMITIVETYPE_INT:
799 LLNI_field_get_val((java_lang_Integer *) value, value, val);
801 case PRIMITIVETYPE_LONG:
802 LLNI_field_get_val((java_lang_Long *) value, value, val);
804 case PRIMITIVETYPE_FLOAT:
805 LLNI_field_get_val((java_lang_Float *) value, value, val);
808 exceptions_throw_illegalargumentexception();
812 *((float *) faddr) = val;
816 case PRIMITIVETYPE_DOUBLE: {
819 /* get field only by name, it can be one of B, S, C, I, J, F, D */
821 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
824 switch (sf->parseddesc->decltype) {
825 case PRIMITIVETYPE_BYTE:
826 LLNI_field_get_val((java_lang_Byte *) value, value, val);
828 case PRIMITIVETYPE_CHAR:
829 LLNI_field_get_val((java_lang_Character *) value, value, val);
831 case PRIMITIVETYPE_SHORT:
832 LLNI_field_get_val((java_lang_Short *) value, value, val);
834 case PRIMITIVETYPE_INT:
835 LLNI_field_get_val((java_lang_Integer *) value, value, val);
837 case PRIMITIVETYPE_LONG:
838 LLNI_field_get_val((java_lang_Long *) value, value, val);
840 case PRIMITIVETYPE_FLOAT:
841 LLNI_field_get_val((java_lang_Float *) value, value, val);
843 case PRIMITIVETYPE_DOUBLE:
844 LLNI_field_get_val((java_lang_Double *) value, value, val);
847 exceptions_throw_illegalargumentexception();
851 *((double *) faddr) = val;
856 /* check if value is an instance of the destination class */
859 /* if (!builtin_instanceof((java_handle_t *) value, df->class)) */
862 *((java_lang_Object **) faddr) = value;
866 /* raise exception */
868 exceptions_throw_illegalargumentexception();
873 * Class: java/lang/reflect/Field
875 * Signature: (Ljava/lang/Object;Z)V
877 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setBoolean(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
884 /* get the class and the field */
886 LLNI_field_get_cls(this, clazz, c);
887 LLNI_field_get_val(this, slot , slot);
888 f = &c->fields[slot];
890 /* get the address of the field with an internal helper */
892 if ((addr = cacao_get_field_address(this, o)) == NULL)
895 /* check the field type and set the value */
897 switch (f->parseddesc->decltype) {
898 case PRIMITIVETYPE_BOOLEAN:
899 *((int32_t *) addr) = value;
902 exceptions_throw_illegalargumentexception();
910 * Class: java/lang/reflect/Field
912 * Signature: (Ljava/lang/Object;B)V
914 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setByte(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
921 /* get the class and the field */
923 LLNI_field_get_cls(this, clazz, c);
924 LLNI_field_get_val(this, slot , slot);
925 f = &c->fields[slot];
927 /* get the address of the field with an internal helper */
929 if ((addr = cacao_get_field_address(this, o)) == NULL)
932 /* check the field type and set the value */
934 switch (f->parseddesc->decltype) {
935 case PRIMITIVETYPE_BYTE:
936 case PRIMITIVETYPE_SHORT:
937 case PRIMITIVETYPE_INT:
938 *((int32_t *) addr) = value;
940 case PRIMITIVETYPE_LONG:
941 *((int64_t *) addr) = value;
943 case PRIMITIVETYPE_FLOAT:
944 *((float *) addr) = value;
946 case PRIMITIVETYPE_DOUBLE:
947 *((double *) addr) = value;
950 exceptions_throw_illegalargumentexception();
958 * Class: java/lang/reflect/Field
960 * Signature: (Ljava/lang/Object;C)V
962 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setChar(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
969 /* get the class and the field */
971 LLNI_field_get_cls(this, clazz, c);
972 LLNI_field_get_val(this, slot , slot);
973 f = &c->fields[slot];
975 /* get the address of the field with an internal helper */
977 if ((addr = cacao_get_field_address(this, o)) == NULL)
980 /* check the field type and set the value */
982 switch (f->parseddesc->decltype) {
983 case PRIMITIVETYPE_CHAR:
984 case PRIMITIVETYPE_INT:
985 *((int32_t *) addr) = value;
987 case PRIMITIVETYPE_LONG:
988 *((int64_t *) addr) = value;
990 case PRIMITIVETYPE_FLOAT:
991 *((float *) addr) = value;
993 case PRIMITIVETYPE_DOUBLE:
994 *((double *) addr) = value;
997 exceptions_throw_illegalargumentexception();
1005 * Class: java/lang/reflect/Field
1007 * Signature: (Ljava/lang/Object;S)V
1009 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setShort(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1016 /* get the class and the field */
1018 LLNI_field_get_cls(this, clazz, c);
1019 LLNI_field_get_val(this, slot , slot);
1020 f = &c->fields[slot];
1022 /* get the address of the field with an internal helper */
1024 if ((addr = cacao_get_field_address(this, o)) == NULL)
1027 /* check the field type and set the value */
1029 switch (f->parseddesc->decltype) {
1030 case PRIMITIVETYPE_SHORT:
1031 case PRIMITIVETYPE_INT:
1032 *((int32_t *) addr) = value;
1034 case PRIMITIVETYPE_LONG:
1035 *((int64_t *) addr) = value;
1037 case PRIMITIVETYPE_FLOAT:
1038 *((float *) addr) = value;
1040 case PRIMITIVETYPE_DOUBLE:
1041 *((double *) addr) = value;
1044 exceptions_throw_illegalargumentexception();
1052 * Class: java/lang/reflect/Field
1054 * Signature: (Ljava/lang/Object;I)V
1056 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setInt(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int32_t value)
1063 /* get the class and the field */
1065 LLNI_field_get_cls(this, clazz, c);
1066 LLNI_field_get_val(this, slot , slot);
1067 f = &c->fields[slot];
1069 /* get the address of the field with an internal helper */
1071 if ((addr = cacao_get_field_address(this, o)) == NULL)
1074 /* check the field type and set the value */
1076 switch (f->parseddesc->decltype) {
1077 case PRIMITIVETYPE_INT:
1078 *((int32_t *) addr) = value;
1080 case PRIMITIVETYPE_LONG:
1081 *((int64_t *) addr) = value;
1083 case PRIMITIVETYPE_FLOAT:
1084 *((float *) addr) = value;
1086 case PRIMITIVETYPE_DOUBLE:
1087 *((double *) addr) = value;
1090 exceptions_throw_illegalargumentexception();
1098 * Class: java/lang/reflect/Field
1100 * Signature: (Ljava/lang/Object;J)V
1102 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setLong(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, int64_t value)
1109 /* get the class and the field */
1111 LLNI_field_get_cls(this, clazz, c);
1112 LLNI_field_get_val(this, slot , slot);
1113 f = &c->fields[slot];
1115 /* get the address of the field with an internal helper */
1117 if ((addr = cacao_get_field_address(this, o)) == NULL)
1120 /* check the field type and set the value */
1122 switch (f->parseddesc->decltype) {
1123 case PRIMITIVETYPE_LONG:
1124 *((int64_t *) addr) = value;
1126 case PRIMITIVETYPE_FLOAT:
1127 *((float *) addr) = value;
1129 case PRIMITIVETYPE_DOUBLE:
1130 *((double *) addr) = value;
1133 exceptions_throw_illegalargumentexception();
1141 * Class: java/lang/reflect/Field
1143 * Signature: (Ljava/lang/Object;F)V
1145 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setFloat(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, float value)
1152 /* get the class and the field */
1154 LLNI_field_get_cls(this, clazz, c);
1155 LLNI_field_get_val(this, slot , slot);
1156 f = &c->fields[slot];
1158 /* get the address of the field with an internal helper */
1160 if ((addr = cacao_get_field_address(this, o)) == NULL)
1163 /* check the field type and set the value */
1165 switch (f->parseddesc->decltype) {
1166 case PRIMITIVETYPE_FLOAT:
1167 *((float *) addr) = value;
1169 case PRIMITIVETYPE_DOUBLE:
1170 *((double *) addr) = value;
1173 exceptions_throw_illegalargumentexception();
1181 * Class: java/lang/reflect/Field
1183 * Signature: (Ljava/lang/Object;D)V
1185 JNIEXPORT void JNICALL Java_java_lang_reflect_Field_setDouble(JNIEnv *env, java_lang_reflect_Field *this, java_lang_Object *o, double value)
1192 /* get the class and the field */
1194 LLNI_field_get_cls(this, clazz, c);
1195 LLNI_field_get_val(this, slot , slot);
1196 f = &c->fields[slot];
1198 /* get the address of the field with an internal helper */
1200 if ((addr = cacao_get_field_address(this, o)) == NULL)
1203 /* check the field type and set the value */
1205 switch (f->parseddesc->decltype) {
1206 case PRIMITIVETYPE_DOUBLE:
1207 *((double *) addr) = value;
1210 exceptions_throw_illegalargumentexception();
1218 * Class: java/lang/reflect/Field
1219 * Method: getSignature
1220 * Signature: ()Ljava/lang/String;
1222 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Field_getSignature(JNIEnv *env, java_lang_reflect_Field* this)
1229 /* get the class and the field */
1231 LLNI_field_get_cls(this, clazz, c);
1232 LLNI_field_get_val(this, slot , slot);
1233 f = &c->fields[slot];
1235 if (f->signature == NULL)
1238 o = javastring_new(f->signature);
1240 /* in error case o is NULL */
1242 return (java_lang_String *) o;
1246 #if defined(ENABLE_ANNOTATIONS)
1248 * Class: java/lang/reflect/Field
1249 * Method: declaredAnnotations
1250 * Signature: ()Ljava/util/Map;
1252 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_Field_declaredAnnotations(JNIEnv *env, java_lang_reflect_Field *this)
1254 java_handle_t *o = (java_handle_t*)this;
1255 struct 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_val(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