1 /* src/native/vm/gnuclasspath/java_lang_reflect_VMField.cpp
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 #include "native/jni.h"
32 #include "native/llni.h"
33 #include "native/native.h"
35 #include "native/include/java_lang_Boolean.h"
36 #include "native/include/java_lang_Byte.h"
37 #include "native/include/java_lang_Character.h"
38 #include "native/include/java_lang_Short.h"
39 #include "native/include/java_lang_Integer.h"
40 #include "native/include/java_lang_Long.h"
41 #include "native/include/java_lang_Float.h"
42 #include "native/include/java_lang_Double.h"
43 #include "native/include/java_lang_Object.h"
44 #include "native/include/java_lang_Class.h"
45 #include "native/include/java_lang_String.h"
47 #include "native/include/java_lang_reflect_Field.h"
51 #include "native/include/java_lang_reflect_VMField.h"
54 #if defined(ENABLE_ANNOTATIONS)
55 #include "native/include/java_util_Map.h"
56 #include "native/include/sun_reflect_ConstantPool.h"
57 #include "native/vm/reflect.h"
60 #include "vm/access.h"
61 #include "vm/builtin.h"
62 #include "vm/exceptions.hpp"
63 #include "vm/global.h"
64 #include "vm/initialize.h"
65 #include "vm/primitive.hpp"
66 #include "vm/resolve.h"
67 #include "vm/string.hpp"
69 #include "vmcore/loader.h"
70 #include "vmcore/utf8.h"
73 /* native methods implemented by this file ************************************/
75 static const JNINativeMethod methods[] = {
76 { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getModifiersInternal },
77 { (char*) "getType", (char*) "()Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getType },
78 { (char*) "get", (char*) "(Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_get },
79 { (char*) "getBoolean", (char*) "(Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getBoolean },
80 { (char*) "getByte", (char*) "(Ljava/lang/Object;)B", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getByte },
81 { (char*) "getChar", (char*) "(Ljava/lang/Object;)C", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getChar },
82 { (char*) "getShort", (char*) "(Ljava/lang/Object;)S", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getShort },
83 { (char*) "getInt", (char*) "(Ljava/lang/Object;)I", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getInt },
84 { (char*) "getLong", (char*) "(Ljava/lang/Object;)J", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getLong },
85 { (char*) "getFloat", (char*) "(Ljava/lang/Object;)F", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getFloat },
86 { (char*) "getDouble", (char*) "(Ljava/lang/Object;)D", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getDouble },
87 { (char*) "set", (char*) "(Ljava/lang/Object;Ljava/lang/Object;)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_set },
88 { (char*) "setBoolean", (char*) "(Ljava/lang/Object;Z)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setBoolean },
89 { (char*) "setByte", (char*) "(Ljava/lang/Object;B)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setByte },
90 { (char*) "setChar", (char*) "(Ljava/lang/Object;C)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setChar },
91 { (char*) "setShort", (char*) "(Ljava/lang/Object;S)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setShort },
92 { (char*) "setInt", (char*) "(Ljava/lang/Object;I)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setInt },
93 { (char*) "setLong", (char*) "(Ljava/lang/Object;J)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setLong },
94 { (char*) "setFloat", (char*) "(Ljava/lang/Object;F)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setFloat },
95 { (char*) "setDouble", (char*) "(Ljava/lang/Object;D)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setDouble },
96 { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getSignature },
97 #if defined(ENABLE_ANNOTATIONS)
98 { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_declaredAnnotations },
103 /* _Jv_java_lang_reflect_VMField_init ******************************************
105 Register native functions.
107 *******************************************************************************/
111 void _Jv_java_lang_reflect_VMField_init(void)
115 u = utf_new_char("java/lang/reflect/VMField");
117 native_method_register(u, methods, NATIVE_METHODS_COUNT);
122 /* _field_access_check *********************************************************
124 Checks if the field can be accessed.
127 true......field can be accessed, or
128 false.....otherwise (maybe an Exception was thrown).
130 *******************************************************************************/
132 static bool _field_access_check(java_lang_reflect_VMField *_this,
133 fieldinfo *f, java_handle_t *o)
135 java_lang_reflect_Field *rf;
138 /* check if we should bypass security checks (AccessibleObject) */
140 LLNI_field_get_ref(_this, f, rf);
141 LLNI_field_get_val(rf, flag, flag);
144 /* This function is always called like this:
145 [0] java.lang.reflect.VMField.xxx (Native Method)
146 [1] java.lang.reflect.Field.xxx
150 if (!access_check_field(f, 2))
154 /* some general checks */
156 if (f->flags & ACC_STATIC) {
157 /* initialize class if required */
159 if (!(f->clazz->state & CLASS_INITIALIZED))
160 if (!initialize_class(f->clazz))
163 /* everything is ok */
168 /* obj is required for not-static fields */
171 exceptions_throw_nullpointerexception();
175 if (builtin_instanceof(o, f->clazz))
181 exceptions_throw_illegalargumentexception();
186 /* _field_get_type *************************************************************
188 Returns the content of the given field.
190 *******************************************************************************/
192 #define _FIELD_GET_TYPE(name, type, uniontype) \
193 static inline type _field_get_##name(fieldinfo *f, java_lang_Object *o) \
196 if (f->flags & ACC_STATIC) { \
197 ret = f->value->uniontype; \
199 LLNI_CRITICAL_START; \
200 ret = *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset); \
206 static inline java_handle_t *_field_get_handle(fieldinfo *f, java_lang_Object *o)
213 if (f->flags & ACC_STATIC) {
214 obj = (java_object_t*) f->value->a;
216 obj = *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset);
219 hdl = LLNI_WRAP(obj);
226 _FIELD_GET_TYPE(int, int32_t, i)
227 _FIELD_GET_TYPE(long, int64_t, l)
228 _FIELD_GET_TYPE(float, float, f)
229 _FIELD_GET_TYPE(double, double, d)
232 /* _field_set_type *************************************************************
234 Sets the content of the given field to the given value.
236 *******************************************************************************/
238 #define _FIELD_SET_TYPE(name, type, uniontype) \
239 static inline void _field_set_##name(fieldinfo *f, java_lang_Object *o, type value) \
241 if (f->flags & ACC_STATIC) { \
242 f->value->uniontype = value; \
244 LLNI_CRITICAL_START; \
245 *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = value; \
250 static inline void _field_set_handle(fieldinfo *f, java_lang_Object *o, java_handle_t *value)
254 if (f->flags & ACC_STATIC) {
255 f->value->a = LLNI_DIRECT(value);
257 *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = LLNI_DIRECT(value);
263 _FIELD_SET_TYPE(int, int32_t, i)
264 _FIELD_SET_TYPE(long, int64_t, l)
265 _FIELD_SET_TYPE(float, float, f)
266 _FIELD_SET_TYPE(double, double, d)
269 // Native functions are exported as C functions.
273 * Class: java/lang/reflect/VMField
274 * Method: getModifiersInternal
277 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getModifiersInternal(JNIEnv *env, java_lang_reflect_VMField *_this)
283 LLNI_field_get_cls(_this, clazz, c);
284 LLNI_field_get_val(_this, slot , slot);
285 f = &(c->fields[slot]);
292 * Class: java/lang/reflect/VMField
294 * Signature: ()Ljava/lang/Class;
296 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_VMField_getType(JNIEnv *env, java_lang_reflect_VMField *_this)
303 LLNI_field_get_cls(_this, clazz, c);
304 LLNI_field_get_val(_this, slot , slot);
305 desc = c->fields[slot].parseddesc;
310 if (!resolve_class_from_typedesc(desc, true, false, &ret))
313 return LLNI_classinfo_wrap(ret);
318 * Class: java/lang/reflect/VMField
320 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
322 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_VMField_get(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
328 java_handle_t *object;
330 LLNI_field_get_cls(_this, clazz, c);
331 LLNI_field_get_val(_this, slot , slot);
332 f = &c->fields[slot];
334 /* check if the field can be accessed */
336 if (!_field_access_check(_this, f, (java_handle_t *) o))
339 switch (f->parseddesc->decltype) {
340 case PRIMITIVETYPE_BOOLEAN:
341 case PRIMITIVETYPE_BYTE:
342 case PRIMITIVETYPE_CHAR:
343 case PRIMITIVETYPE_SHORT:
344 case PRIMITIVETYPE_INT:
345 value.i = _field_get_int(f, o);
348 case PRIMITIVETYPE_LONG:
349 value.l = _field_get_long(f, o);
352 case PRIMITIVETYPE_FLOAT:
353 value.f = _field_get_float(f, o);
356 case PRIMITIVETYPE_DOUBLE:
357 value.d = _field_get_double(f, o);
361 return (java_lang_Object *) _field_get_handle(f, o);
364 /* Now box the primitive types. */
366 object = Primitive::box(f->parseddesc->decltype, value);
368 return (java_lang_Object *) object;
373 * Class: java/lang/reflect/VMField
375 * Signature: (Ljava/lang/Object;)Z
377 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getBoolean(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
383 /* get the class and the field */
385 LLNI_field_get_cls(_this, clazz, c);
386 LLNI_field_get_val(_this, slot , slot);
387 f = &c->fields[slot];
389 /* check if the field can be accessed */
391 if (!_field_access_check(_this, f, (java_handle_t *) o))
394 /* check the field type and return the value */
396 switch (f->parseddesc->decltype) {
397 case PRIMITIVETYPE_BOOLEAN:
398 return (int32_t) _field_get_int(f, o);
400 exceptions_throw_illegalargumentexception();
407 * Class: java/lang/reflect/VMField
409 * Signature: (Ljava/lang/Object;)B
411 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getByte(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
417 /* get the class and the field */
419 LLNI_field_get_cls(_this, clazz, c);
420 LLNI_field_get_val(_this, slot , slot);
421 f = &c->fields[slot];
423 /* check if the field can be accessed */
425 if (!_field_access_check(_this, f, (java_handle_t *) o))
428 /* check the field type and return the value */
430 switch (f->parseddesc->decltype) {
431 case PRIMITIVETYPE_BYTE:
432 return (int32_t) _field_get_int(f, o);
434 exceptions_throw_illegalargumentexception();
441 * Class: java/lang/reflect/VMField
443 * Signature: (Ljava/lang/Object;)C
445 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getChar(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
451 /* get the class and the field */
453 LLNI_field_get_cls(_this, clazz, c);
454 LLNI_field_get_val(_this, slot , slot);
455 f = &c->fields[slot];
457 /* check if the field can be accessed */
459 if (!_field_access_check(_this, f, (java_handle_t *) o))
462 /* check the field type and return the value */
464 switch (f->parseddesc->decltype) {
465 case PRIMITIVETYPE_CHAR:
466 return (int32_t) _field_get_int(f, o);
468 exceptions_throw_illegalargumentexception();
475 * Class: java/lang/reflect/VMField
477 * Signature: (Ljava/lang/Object;)S
479 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getShort(JNIEnv *env, java_lang_reflect_VMField *_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 /* check if the field can be accessed */
493 if (!_field_access_check(_this, f, (java_handle_t *) o))
496 /* check the field type and return the value */
498 switch (f->parseddesc->decltype) {
499 case PRIMITIVETYPE_BYTE:
500 case PRIMITIVETYPE_SHORT:
501 return (int32_t) _field_get_int(f, o);
503 exceptions_throw_illegalargumentexception();
510 * Class: java/lang/reflect/VMField
512 * Signature: (Ljava/lang/Object;)I
514 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getInt(JNIEnv *env , java_lang_reflect_VMField *_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 /* check if the field can be accessed */
528 if (!_field_access_check(_this, f, (java_handle_t *) o))
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) _field_get_int(f, o);
540 exceptions_throw_illegalargumentexception();
547 * Class: java/lang/reflect/VMField
549 * Signature: (Ljava/lang/Object;)J
551 JNIEXPORT int64_t JNICALL Java_java_lang_reflect_VMField_getLong(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
557 /* get the class and the field */
559 LLNI_field_get_cls(_this, clazz, c);
560 LLNI_field_get_val(_this, slot , slot);
561 f = &c->fields[slot];
563 /* check if the field can be accessed */
565 if (!_field_access_check(_this, f, (java_handle_t *) o))
568 /* check the field type and return the value */
570 switch (f->parseddesc->decltype) {
571 case PRIMITIVETYPE_BYTE:
572 case PRIMITIVETYPE_CHAR:
573 case PRIMITIVETYPE_SHORT:
574 case PRIMITIVETYPE_INT:
575 return (int64_t) _field_get_int(f, o);
576 case PRIMITIVETYPE_LONG:
577 return (int64_t) _field_get_long(f, o);
579 exceptions_throw_illegalargumentexception();
586 * Class: java/lang/reflect/VMField
588 * Signature: (Ljava/lang/Object;)F
590 JNIEXPORT float JNICALL Java_java_lang_reflect_VMField_getFloat(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
596 /* get the class and the field */
598 LLNI_field_get_cls(_this, clazz, c);
599 LLNI_field_get_val(_this, slot , slot);
600 f = &c->fields[slot];
602 /* check if the field can be accessed */
604 if (!_field_access_check(_this, f, (java_handle_t *) o))
607 /* check the field type and return the value */
609 switch (f->parseddesc->decltype) {
610 case PRIMITIVETYPE_BYTE:
611 case PRIMITIVETYPE_CHAR:
612 case PRIMITIVETYPE_SHORT:
613 case PRIMITIVETYPE_INT:
614 return (float) _field_get_int(f, o);
615 case PRIMITIVETYPE_LONG:
616 return (float) _field_get_long(f, o);
617 case PRIMITIVETYPE_FLOAT:
618 return (float) _field_get_float(f, o);
620 exceptions_throw_illegalargumentexception();
627 * Class: java/lang/reflect/VMField
629 * Signature: (Ljava/lang/Object;)D
631 JNIEXPORT double JNICALL Java_java_lang_reflect_VMField_getDouble(JNIEnv *env , java_lang_reflect_VMField *_this, java_lang_Object *o)
637 /* get the class and the field */
639 LLNI_field_get_cls(_this, clazz, c);
640 LLNI_field_get_val(_this, slot , slot);
641 f = &c->fields[slot];
643 /* check if the field can be accessed */
645 if (!_field_access_check(_this, f, (java_handle_t *) o))
648 /* check the field type and return the value */
650 switch (f->parseddesc->decltype) {
651 case PRIMITIVETYPE_BYTE:
652 case PRIMITIVETYPE_CHAR:
653 case PRIMITIVETYPE_SHORT:
654 case PRIMITIVETYPE_INT:
655 return (double) _field_get_int(f, o);
656 case PRIMITIVETYPE_LONG:
657 return (double) _field_get_long(f, o);
658 case PRIMITIVETYPE_FLOAT:
659 return (double) _field_get_float(f, o);
660 case PRIMITIVETYPE_DOUBLE:
661 return (double) _field_get_double(f, o);
663 exceptions_throw_illegalargumentexception();
670 * Class: java/lang/reflect/VMField
672 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
674 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, java_lang_Object *value)
682 /* get the class and the field */
684 LLNI_field_get_cls(_this, clazz, dc);
685 LLNI_field_get_val(_this, slot , slot);
686 df = &dc->fields[slot];
688 /* check if the field can be accessed */
690 if (!_field_access_check(_this, df, (java_handle_t *) o))
693 /* get the source classinfo from the object */
698 LLNI_class_get(value, sc);
700 /* The fieldid is used to set the new value, for primitive
701 types the value has to be retrieved from the wrapping
704 switch (df->parseddesc->decltype) {
705 case PRIMITIVETYPE_BOOLEAN: {
708 /* determine the field to read the value */
710 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
713 switch (sf->parseddesc->decltype) {
714 case PRIMITIVETYPE_BOOLEAN:
715 LLNI_field_get_val((java_lang_Boolean *) value, value, val);
718 exceptions_throw_illegalargumentexception();
722 _field_set_int(df, o, val);
726 case PRIMITIVETYPE_BYTE: {
729 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
732 switch (sf->parseddesc->decltype) {
733 case PRIMITIVETYPE_BYTE:
734 LLNI_field_get_val((java_lang_Byte *) value, value, val);
737 exceptions_throw_illegalargumentexception();
741 _field_set_int(df, o, val);
745 case PRIMITIVETYPE_CHAR: {
748 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
751 switch (sf->parseddesc->decltype) {
752 case PRIMITIVETYPE_CHAR:
753 LLNI_field_get_val((java_lang_Character *) value, value, val);
756 exceptions_throw_illegalargumentexception();
760 _field_set_int(df, o, val);
764 case PRIMITIVETYPE_SHORT: {
767 /* get field only by name, it can be one of B, S */
769 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
772 switch (sf->parseddesc->decltype) {
773 case PRIMITIVETYPE_BYTE:
774 LLNI_field_get_val((java_lang_Byte *) value, value, val);
776 case PRIMITIVETYPE_SHORT:
777 LLNI_field_get_val((java_lang_Short *) value, value, val);
780 exceptions_throw_illegalargumentexception();
784 _field_set_int(df, o, val);
788 case PRIMITIVETYPE_INT: {
791 /* get field only by name, it can be one of B, S, C, I */
793 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
796 switch (sf->parseddesc->decltype) {
797 case PRIMITIVETYPE_BYTE:
798 LLNI_field_get_val((java_lang_Byte *) value, value, val);
800 case PRIMITIVETYPE_CHAR:
801 LLNI_field_get_val((java_lang_Character *) value, value, val);
803 case PRIMITIVETYPE_SHORT:
804 LLNI_field_get_val((java_lang_Short *) value, value, val);
806 case PRIMITIVETYPE_INT:
807 LLNI_field_get_val((java_lang_Integer *) value, value, val);
810 exceptions_throw_illegalargumentexception();
814 _field_set_int(df, o, val);
818 case PRIMITIVETYPE_LONG: {
821 /* get field only by name, it can be one of B, S, C, I, J */
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);
843 exceptions_throw_illegalargumentexception();
847 _field_set_long(df, o, val);
851 case PRIMITIVETYPE_FLOAT: {
854 /* get field only by name, it can be one of B, S, C, I, J, F */
856 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
859 switch (sf->parseddesc->decltype) {
860 case PRIMITIVETYPE_BYTE:
861 LLNI_field_get_val((java_lang_Byte *) value, value, val);
863 case PRIMITIVETYPE_CHAR:
864 LLNI_field_get_val((java_lang_Character *) value, value, val);
866 case PRIMITIVETYPE_SHORT:
867 LLNI_field_get_val((java_lang_Short *) value, value, val);
869 case PRIMITIVETYPE_INT:
870 LLNI_field_get_val((java_lang_Integer *) value, value, val);
872 case PRIMITIVETYPE_LONG:
873 LLNI_field_get_val((java_lang_Long *) value, value, val);
875 case PRIMITIVETYPE_FLOAT:
876 LLNI_field_get_val((java_lang_Float *) value, value, val);
879 exceptions_throw_illegalargumentexception();
883 _field_set_float(df, o, val);
887 case PRIMITIVETYPE_DOUBLE: {
890 /* get field only by name, it can be one of B, S, C, I, J, F, D */
892 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
895 switch (sf->parseddesc->decltype) {
896 case PRIMITIVETYPE_BYTE:
897 LLNI_field_get_val((java_lang_Byte *) value, value, val);
899 case PRIMITIVETYPE_CHAR:
900 LLNI_field_get_val((java_lang_Character *) value, value, val);
902 case PRIMITIVETYPE_SHORT:
903 LLNI_field_get_val((java_lang_Short *) value, value, val);
905 case PRIMITIVETYPE_INT:
906 LLNI_field_get_val((java_lang_Integer *) value, value, val);
908 case PRIMITIVETYPE_LONG:
909 LLNI_field_get_val((java_lang_Long *) value, value, val);
911 case PRIMITIVETYPE_FLOAT:
912 LLNI_field_get_val((java_lang_Float *) value, value, val);
914 case PRIMITIVETYPE_DOUBLE:
915 LLNI_field_get_val((java_lang_Double *) value, value, val);
918 exceptions_throw_illegalargumentexception();
922 _field_set_double(df, o, val);
927 /* check if value is an instance of the destination class */
930 /* if (!builtin_instanceof((java_handle_t *) value, df->class)) */
933 _field_set_handle(df, o, (java_handle_t *) value);
937 /* raise exception */
939 exceptions_throw_illegalargumentexception();
944 * Class: java/lang/reflect/VMField
946 * Signature: (Ljava/lang/Object;Z)V
948 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setBoolean(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value)
954 /* get the class and the field */
956 LLNI_field_get_cls(_this, clazz, c);
957 LLNI_field_get_val(_this, slot , slot);
958 f = &c->fields[slot];
960 /* check if the field can be accessed */
962 if (!_field_access_check(_this, f, (java_handle_t *) o))
965 /* check the field type and set the value */
967 switch (f->parseddesc->decltype) {
968 case PRIMITIVETYPE_BOOLEAN:
969 _field_set_int(f, o, value);
972 exceptions_throw_illegalargumentexception();
980 * Class: java/lang/reflect/VMField
982 * Signature: (Ljava/lang/Object;B)V
984 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setByte(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value)
990 /* get the class and the field */
992 LLNI_field_get_cls(_this, clazz, c);
993 LLNI_field_get_val(_this, slot , slot);
994 f = &c->fields[slot];
996 /* check if the field can be accessed */
998 if (!_field_access_check(_this, f, (java_handle_t *) o))
1001 /* check the field type and set the value */
1003 switch (f->parseddesc->decltype) {
1004 case PRIMITIVETYPE_BYTE:
1005 case PRIMITIVETYPE_SHORT:
1006 case PRIMITIVETYPE_INT:
1007 _field_set_int(f, o, value);
1009 case PRIMITIVETYPE_LONG:
1010 _field_set_long(f, o, value);
1012 case PRIMITIVETYPE_FLOAT:
1013 _field_set_float(f, o, value);
1015 case PRIMITIVETYPE_DOUBLE:
1016 _field_set_double(f, o, value);
1019 exceptions_throw_illegalargumentexception();
1027 * Class: java/lang/reflect/VMField
1029 * Signature: (Ljava/lang/Object;C)V
1031 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setChar(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value)
1037 /* get the class and the field */
1039 LLNI_field_get_cls(_this, clazz, c);
1040 LLNI_field_get_val(_this, slot , slot);
1041 f = &c->fields[slot];
1043 /* check if the field can be accessed */
1045 if (!_field_access_check(_this, f, (java_handle_t *) o))
1048 /* check the field type and set the value */
1050 switch (f->parseddesc->decltype) {
1051 case PRIMITIVETYPE_CHAR:
1052 case PRIMITIVETYPE_INT:
1053 _field_set_int(f, o, value);
1055 case PRIMITIVETYPE_LONG:
1056 _field_set_long(f, o, value);
1058 case PRIMITIVETYPE_FLOAT:
1059 _field_set_float(f, o, value);
1061 case PRIMITIVETYPE_DOUBLE:
1062 _field_set_double(f, o, value);
1065 exceptions_throw_illegalargumentexception();
1073 * Class: java/lang/reflect/VMField
1075 * Signature: (Ljava/lang/Object;S)V
1077 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setShort(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value)
1083 /* get the class and the field */
1085 LLNI_field_get_cls(_this, clazz, c);
1086 LLNI_field_get_val(_this, slot , slot);
1087 f = &c->fields[slot];
1089 /* check if the field can be accessed */
1091 if (!_field_access_check(_this, f, (java_handle_t *) o))
1094 /* check the field type and set the value */
1096 switch (f->parseddesc->decltype) {
1097 case PRIMITIVETYPE_SHORT:
1098 case PRIMITIVETYPE_INT:
1099 _field_set_int(f, o, value);
1101 case PRIMITIVETYPE_LONG:
1102 _field_set_long(f, o, value);
1104 case PRIMITIVETYPE_FLOAT:
1105 _field_set_float(f, o, value);
1107 case PRIMITIVETYPE_DOUBLE:
1108 _field_set_double(f, o, value);
1111 exceptions_throw_illegalargumentexception();
1119 * Class: java/lang/reflect/VMField
1121 * Signature: (Ljava/lang/Object;I)V
1123 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setInt(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value)
1129 /* get the class and the field */
1131 LLNI_field_get_cls(_this, clazz, c);
1132 LLNI_field_get_val(_this, slot , slot);
1133 f = &c->fields[slot];
1135 /* check if the field can be accessed */
1137 if (!_field_access_check(_this, f, (java_handle_t *) o))
1140 /* check the field type and set the value */
1142 switch (f->parseddesc->decltype) {
1143 case PRIMITIVETYPE_INT:
1144 _field_set_int(f, o, value);
1146 case PRIMITIVETYPE_LONG:
1147 _field_set_long(f, o, value);
1149 case PRIMITIVETYPE_FLOAT:
1150 _field_set_float(f, o, value);
1152 case PRIMITIVETYPE_DOUBLE:
1153 _field_set_double(f, o, value);
1156 exceptions_throw_illegalargumentexception();
1164 * Class: java/lang/reflect/VMField
1166 * Signature: (Ljava/lang/Object;J)V
1168 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setLong(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int64_t value)
1174 /* get the class and the field */
1176 LLNI_field_get_cls(_this, clazz, c);
1177 LLNI_field_get_val(_this, slot , slot);
1178 f = &c->fields[slot];
1180 /* check if the field can be accessed */
1182 if (!_field_access_check(_this, f, (java_handle_t *) o))
1185 /* check the field type and set the value */
1187 switch (f->parseddesc->decltype) {
1188 case PRIMITIVETYPE_LONG:
1189 _field_set_long(f, o, value);
1191 case PRIMITIVETYPE_FLOAT:
1192 _field_set_float(f, o, value);
1194 case PRIMITIVETYPE_DOUBLE:
1195 _field_set_double(f, o, value);
1198 exceptions_throw_illegalargumentexception();
1206 * Class: java/lang/reflect/VMField
1208 * Signature: (Ljava/lang/Object;F)V
1210 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setFloat(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, float value)
1216 /* get the class and the field */
1218 LLNI_field_get_cls(_this, clazz, c);
1219 LLNI_field_get_val(_this, slot , slot);
1220 f = &c->fields[slot];
1222 /* check if the field can be accessed */
1224 if (!_field_access_check(_this, f, (java_handle_t *) o))
1227 /* check the field type and set the value */
1229 switch (f->parseddesc->decltype) {
1230 case PRIMITIVETYPE_FLOAT:
1231 _field_set_float(f, o, value);
1233 case PRIMITIVETYPE_DOUBLE:
1234 _field_set_double(f, o, value);
1237 exceptions_throw_illegalargumentexception();
1245 * Class: java/lang/reflect/VMField
1247 * Signature: (Ljava/lang/Object;D)V
1249 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setDouble(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, double value)
1255 /* get the class and the field */
1257 LLNI_field_get_cls(_this, clazz, c);
1258 LLNI_field_get_val(_this, slot , slot);
1259 f = &c->fields[slot];
1261 /* check if the field can be accessed */
1263 if (!_field_access_check(_this, f, (java_handle_t *) o))
1266 /* check the field type and set the value */
1268 switch (f->parseddesc->decltype) {
1269 case PRIMITIVETYPE_DOUBLE:
1270 _field_set_double(f, o, value);
1273 exceptions_throw_illegalargumentexception();
1281 * Class: java/lang/reflect/VMField
1282 * Method: getSignature
1283 * Signature: ()Ljava/lang/String;
1285 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_VMField_getSignature(JNIEnv *env, java_lang_reflect_VMField* _this)
1292 /* get the class and the field */
1294 LLNI_field_get_cls(_this, clazz, c);
1295 LLNI_field_get_val(_this, slot , slot);
1296 f = &c->fields[slot];
1298 if (f->signature == NULL)
1301 o = javastring_new(f->signature);
1303 /* in error case o is NULL */
1305 return (java_lang_String *) o;
1309 #if defined(ENABLE_ANNOTATIONS)
1311 * Class: java/lang/reflect/VMField
1312 * Method: declaredAnnotations
1313 * Signature: ()Ljava/util/Map;
1315 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_VMField_declaredAnnotations(JNIEnv *env, java_lang_reflect_VMField *_this)
1317 java_util_Map *declaredAnnotations = NULL; /* parsed annotations */
1318 java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
1319 java_lang_Class *declaringClass = NULL; /* the constant pool of this class is used */
1320 classinfo *referer = NULL; /* class, which calles the annotation parser */
1321 /* (for the parameter 'referer' of vm_call_method()) */
1323 LLNI_field_get_ref(_this, declaredAnnotations, declaredAnnotations);
1325 /* are the annotations parsed yet? */
1326 if (declaredAnnotations == NULL) {
1327 LLNI_field_get_ref(_this, annotations, annotations);
1328 LLNI_field_get_ref(_this, clazz, declaringClass);
1329 LLNI_class_get(_this, referer);
1331 declaredAnnotations = reflect_get_declaredannotations(annotations, (classinfo*) declaringClass, referer);
1333 LLNI_field_set_ref(_this, declaredAnnotations, declaredAnnotations);
1336 return declaredAnnotations;
1344 * These are local overrides for various environment variables in Emacs.
1345 * Please do not remove this and leave it at the end of the file, where
1346 * Emacs will automagically detect them.
1347 * ---------------------------------------------------------------------
1350 * indent-tabs-mode: t
1354 * vim:noexpandtab:sw=4:ts=4: