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.h"
63 #include "vm/global.h"
64 #include "vm/initialize.h"
65 #include "vm/primitive.hpp"
66 #include "vm/resolve.h"
67 #include "vm/stringlocal.h"
69 #include "vm/jit/stacktrace.h"
71 #include "vmcore/loader.h"
72 #include "vmcore/utf8.h"
75 /* native methods implemented by this file ************************************/
77 static const JNINativeMethod methods[] = {
78 { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getModifiersInternal },
79 { (char*) "getType", (char*) "()Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getType },
80 { (char*) "get", (char*) "(Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_get },
81 { (char*) "getBoolean", (char*) "(Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getBoolean },
82 { (char*) "getByte", (char*) "(Ljava/lang/Object;)B", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getByte },
83 { (char*) "getChar", (char*) "(Ljava/lang/Object;)C", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getChar },
84 { (char*) "getShort", (char*) "(Ljava/lang/Object;)S", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getShort },
85 { (char*) "getInt", (char*) "(Ljava/lang/Object;)I", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getInt },
86 { (char*) "getLong", (char*) "(Ljava/lang/Object;)J", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getLong },
87 { (char*) "getFloat", (char*) "(Ljava/lang/Object;)F", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getFloat },
88 { (char*) "getDouble", (char*) "(Ljava/lang/Object;)D", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getDouble },
89 { (char*) "set", (char*) "(Ljava/lang/Object;Ljava/lang/Object;)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_set },
90 { (char*) "setBoolean", (char*) "(Ljava/lang/Object;Z)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setBoolean },
91 { (char*) "setByte", (char*) "(Ljava/lang/Object;B)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setByte },
92 { (char*) "setChar", (char*) "(Ljava/lang/Object;C)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setChar },
93 { (char*) "setShort", (char*) "(Ljava/lang/Object;S)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setShort },
94 { (char*) "setInt", (char*) "(Ljava/lang/Object;I)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setInt },
95 { (char*) "setLong", (char*) "(Ljava/lang/Object;J)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setLong },
96 { (char*) "setFloat", (char*) "(Ljava/lang/Object;F)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setFloat },
97 { (char*) "setDouble", (char*) "(Ljava/lang/Object;D)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setDouble },
98 { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getSignature },
99 #if defined(ENABLE_ANNOTATIONS)
100 { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_declaredAnnotations },
105 /* _Jv_java_lang_reflect_VMField_init ******************************************
107 Register native functions.
109 *******************************************************************************/
113 void _Jv_java_lang_reflect_VMField_init(void)
117 u = utf_new_char("java/lang/reflect/VMField");
119 native_method_register(u, methods, NATIVE_METHODS_COUNT);
124 /* _field_access_check *********************************************************
126 Checks if the field can be accessed.
129 true......field can be accessed, or
130 false.....otherwise (maybe an Exception was thrown).
132 *******************************************************************************/
134 static bool _field_access_check(java_lang_reflect_VMField *_this,
135 fieldinfo *f, java_handle_t *o)
137 java_lang_reflect_Field *rf;
140 /* check if we should bypass security checks (AccessibleObject) */
142 LLNI_field_get_ref(_this, f, rf);
143 LLNI_field_get_val(rf, flag, flag);
146 /* This function is always called like this:
147 [0] java.lang.reflect.VMField.xxx (Native Method)
148 [1] java.lang.reflect.Field.xxx
152 if (!access_check_field(f, 2))
156 /* some general checks */
158 if (f->flags & ACC_STATIC) {
159 /* initialize class if required */
161 if (!(f->clazz->state & CLASS_INITIALIZED))
162 if (!initialize_class(f->clazz))
165 /* everything is ok */
170 /* obj is required for not-static fields */
173 exceptions_throw_nullpointerexception();
177 if (builtin_instanceof(o, f->clazz))
183 exceptions_throw_illegalargumentexception();
188 /* _field_get_type *************************************************************
190 Returns the content of the given field.
192 *******************************************************************************/
194 #define _FIELD_GET_TYPE(name, type, uniontype) \
195 static inline type _field_get_##name(fieldinfo *f, java_lang_Object *o) \
198 if (f->flags & ACC_STATIC) { \
199 ret = f->value->uniontype; \
201 LLNI_CRITICAL_START; \
202 ret = *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset); \
208 static inline java_handle_t *_field_get_handle(fieldinfo *f, java_lang_Object *o)
215 if (f->flags & ACC_STATIC) {
216 obj = (java_object_t*) f->value->a;
218 obj = *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset);
221 hdl = LLNI_WRAP(obj);
228 _FIELD_GET_TYPE(int, int32_t, i)
229 _FIELD_GET_TYPE(long, int64_t, l)
230 _FIELD_GET_TYPE(float, float, f)
231 _FIELD_GET_TYPE(double, double, d)
234 /* _field_set_type *************************************************************
236 Sets the content of the given field to the given value.
238 *******************************************************************************/
240 #define _FIELD_SET_TYPE(name, type, uniontype) \
241 static inline void _field_set_##name(fieldinfo *f, java_lang_Object *o, type value) \
243 if (f->flags & ACC_STATIC) { \
244 f->value->uniontype = value; \
246 LLNI_CRITICAL_START; \
247 *(type *) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = value; \
252 static inline void _field_set_handle(fieldinfo *f, java_lang_Object *o, java_handle_t *value)
256 if (f->flags & ACC_STATIC) {
257 f->value->a = LLNI_DIRECT(value);
259 *(java_object_t **) (((intptr_t) LLNI_DIRECT(o)) + f->offset) = LLNI_DIRECT(value);
265 _FIELD_SET_TYPE(int, int32_t, i)
266 _FIELD_SET_TYPE(long, int64_t, l)
267 _FIELD_SET_TYPE(float, float, f)
268 _FIELD_SET_TYPE(double, double, d)
274 * Class: java/lang/reflect/VMField
275 * Method: getModifiersInternal
278 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getModifiersInternal(JNIEnv *env, java_lang_reflect_VMField *_this)
284 LLNI_field_get_cls(_this, clazz, c);
285 LLNI_field_get_val(_this, slot , slot);
286 f = &(c->fields[slot]);
293 * Class: java/lang/reflect/VMField
295 * Signature: ()Ljava/lang/Class;
297 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_VMField_getType(JNIEnv *env, java_lang_reflect_VMField *_this)
304 LLNI_field_get_cls(_this, clazz, c);
305 LLNI_field_get_val(_this, slot , slot);
306 desc = c->fields[slot].parseddesc;
311 if (!resolve_class_from_typedesc(desc, true, false, &ret))
314 return LLNI_classinfo_wrap(ret);
319 * Class: java/lang/reflect/VMField
321 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
323 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_VMField_get(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
329 java_handle_t *object;
331 LLNI_field_get_cls(_this, clazz, c);
332 LLNI_field_get_val(_this, slot , slot);
333 f = &c->fields[slot];
335 /* check if the field can be accessed */
337 if (!_field_access_check(_this, f, (java_handle_t *) o))
340 switch (f->parseddesc->decltype) {
341 case PRIMITIVETYPE_BOOLEAN:
342 case PRIMITIVETYPE_BYTE:
343 case PRIMITIVETYPE_CHAR:
344 case PRIMITIVETYPE_SHORT:
345 case PRIMITIVETYPE_INT:
346 value.i = _field_get_int(f, o);
349 case PRIMITIVETYPE_LONG:
350 value.l = _field_get_long(f, o);
353 case PRIMITIVETYPE_FLOAT:
354 value.f = _field_get_float(f, o);
357 case PRIMITIVETYPE_DOUBLE:
358 value.d = _field_get_double(f, o);
362 return (java_lang_Object *) _field_get_handle(f, o);
365 /* Now box the primitive types. */
367 object = Primitive::box(f->parseddesc->decltype, value);
369 return (java_lang_Object *) object;
374 * Class: java/lang/reflect/VMField
376 * Signature: (Ljava/lang/Object;)Z
378 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getBoolean(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
384 /* get the class and the field */
386 LLNI_field_get_cls(_this, clazz, c);
387 LLNI_field_get_val(_this, slot , slot);
388 f = &c->fields[slot];
390 /* check if the field can be accessed */
392 if (!_field_access_check(_this, f, (java_handle_t *) o))
395 /* check the field type and return the value */
397 switch (f->parseddesc->decltype) {
398 case PRIMITIVETYPE_BOOLEAN:
399 return (int32_t) _field_get_int(f, o);
401 exceptions_throw_illegalargumentexception();
408 * Class: java/lang/reflect/VMField
410 * Signature: (Ljava/lang/Object;)B
412 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getByte(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
418 /* get the class and the field */
420 LLNI_field_get_cls(_this, clazz, c);
421 LLNI_field_get_val(_this, slot , slot);
422 f = &c->fields[slot];
424 /* check if the field can be accessed */
426 if (!_field_access_check(_this, f, (java_handle_t *) o))
429 /* check the field type and return the value */
431 switch (f->parseddesc->decltype) {
432 case PRIMITIVETYPE_BYTE:
433 return (int32_t) _field_get_int(f, o);
435 exceptions_throw_illegalargumentexception();
442 * Class: java/lang/reflect/VMField
444 * Signature: (Ljava/lang/Object;)C
446 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getChar(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
452 /* get the class and the field */
454 LLNI_field_get_cls(_this, clazz, c);
455 LLNI_field_get_val(_this, slot , slot);
456 f = &c->fields[slot];
458 /* check if the field can be accessed */
460 if (!_field_access_check(_this, f, (java_handle_t *) o))
463 /* check the field type and return the value */
465 switch (f->parseddesc->decltype) {
466 case PRIMITIVETYPE_CHAR:
467 return (int32_t) _field_get_int(f, o);
469 exceptions_throw_illegalargumentexception();
476 * Class: java/lang/reflect/VMField
478 * Signature: (Ljava/lang/Object;)S
480 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getShort(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
486 /* get the class and the field */
488 LLNI_field_get_cls(_this, clazz, c);
489 LLNI_field_get_val(_this, slot , slot);
490 f = &c->fields[slot];
492 /* check if the field can be accessed */
494 if (!_field_access_check(_this, f, (java_handle_t *) o))
497 /* check the field type and return the value */
499 switch (f->parseddesc->decltype) {
500 case PRIMITIVETYPE_BYTE:
501 case PRIMITIVETYPE_SHORT:
502 return (int32_t) _field_get_int(f, o);
504 exceptions_throw_illegalargumentexception();
511 * Class: java/lang/reflect/VMField
513 * Signature: (Ljava/lang/Object;)I
515 JNIEXPORT int32_t JNICALL Java_java_lang_reflect_VMField_getInt(JNIEnv *env , java_lang_reflect_VMField *_this, java_lang_Object *o)
521 /* get the class and the field */
523 LLNI_field_get_cls(_this, clazz, c);
524 LLNI_field_get_val(_this, slot , slot);
525 f = &c->fields[slot];
527 /* check if the field can be accessed */
529 if (!_field_access_check(_this, f, (java_handle_t *) o))
532 /* check the field type and return the value */
534 switch (f->parseddesc->decltype) {
535 case PRIMITIVETYPE_BYTE:
536 case PRIMITIVETYPE_CHAR:
537 case PRIMITIVETYPE_SHORT:
538 case PRIMITIVETYPE_INT:
539 return (int32_t) _field_get_int(f, o);
541 exceptions_throw_illegalargumentexception();
548 * Class: java/lang/reflect/VMField
550 * Signature: (Ljava/lang/Object;)J
552 JNIEXPORT int64_t JNICALL Java_java_lang_reflect_VMField_getLong(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
558 /* get the class and the field */
560 LLNI_field_get_cls(_this, clazz, c);
561 LLNI_field_get_val(_this, slot , slot);
562 f = &c->fields[slot];
564 /* check if the field can be accessed */
566 if (!_field_access_check(_this, f, (java_handle_t *) o))
569 /* check the field type and return the value */
571 switch (f->parseddesc->decltype) {
572 case PRIMITIVETYPE_BYTE:
573 case PRIMITIVETYPE_CHAR:
574 case PRIMITIVETYPE_SHORT:
575 case PRIMITIVETYPE_INT:
576 return (int64_t) _field_get_int(f, o);
577 case PRIMITIVETYPE_LONG:
578 return (int64_t) _field_get_long(f, o);
580 exceptions_throw_illegalargumentexception();
587 * Class: java/lang/reflect/VMField
589 * Signature: (Ljava/lang/Object;)F
591 JNIEXPORT float JNICALL Java_java_lang_reflect_VMField_getFloat(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o)
597 /* get the class and the field */
599 LLNI_field_get_cls(_this, clazz, c);
600 LLNI_field_get_val(_this, slot , slot);
601 f = &c->fields[slot];
603 /* check if the field can be accessed */
605 if (!_field_access_check(_this, f, (java_handle_t *) o))
608 /* check the field type and return the value */
610 switch (f->parseddesc->decltype) {
611 case PRIMITIVETYPE_BYTE:
612 case PRIMITIVETYPE_CHAR:
613 case PRIMITIVETYPE_SHORT:
614 case PRIMITIVETYPE_INT:
615 return (float) _field_get_int(f, o);
616 case PRIMITIVETYPE_LONG:
617 return (float) _field_get_long(f, o);
618 case PRIMITIVETYPE_FLOAT:
619 return (float) _field_get_float(f, o);
621 exceptions_throw_illegalargumentexception();
628 * Class: java/lang/reflect/VMField
630 * Signature: (Ljava/lang/Object;)D
632 JNIEXPORT double JNICALL Java_java_lang_reflect_VMField_getDouble(JNIEnv *env , java_lang_reflect_VMField *_this, java_lang_Object *o)
638 /* get the class and the field */
640 LLNI_field_get_cls(_this, clazz, c);
641 LLNI_field_get_val(_this, slot , slot);
642 f = &c->fields[slot];
644 /* check if the field can be accessed */
646 if (!_field_access_check(_this, f, (java_handle_t *) o))
649 /* check the field type and return the value */
651 switch (f->parseddesc->decltype) {
652 case PRIMITIVETYPE_BYTE:
653 case PRIMITIVETYPE_CHAR:
654 case PRIMITIVETYPE_SHORT:
655 case PRIMITIVETYPE_INT:
656 return (double) _field_get_int(f, o);
657 case PRIMITIVETYPE_LONG:
658 return (double) _field_get_long(f, o);
659 case PRIMITIVETYPE_FLOAT:
660 return (double) _field_get_float(f, o);
661 case PRIMITIVETYPE_DOUBLE:
662 return (double) _field_get_double(f, o);
664 exceptions_throw_illegalargumentexception();
671 * Class: java/lang/reflect/VMField
673 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
675 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, java_lang_Object *value)
683 /* get the class and the field */
685 LLNI_field_get_cls(_this, clazz, dc);
686 LLNI_field_get_val(_this, slot , slot);
687 df = &dc->fields[slot];
689 /* check if the field can be accessed */
691 if (!_field_access_check(_this, df, (java_handle_t *) o))
694 /* get the source classinfo from the object */
699 LLNI_class_get(value, sc);
701 /* The fieldid is used to set the new value, for primitive
702 types the value has to be retrieved from the wrapping
705 switch (df->parseddesc->decltype) {
706 case PRIMITIVETYPE_BOOLEAN: {
709 /* determine the field to read the value */
711 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
714 switch (sf->parseddesc->decltype) {
715 case PRIMITIVETYPE_BOOLEAN:
716 LLNI_field_get_val((java_lang_Boolean *) value, value, val);
719 exceptions_throw_illegalargumentexception();
723 _field_set_int(df, o, val);
727 case PRIMITIVETYPE_BYTE: {
730 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
733 switch (sf->parseddesc->decltype) {
734 case PRIMITIVETYPE_BYTE:
735 LLNI_field_get_val((java_lang_Byte *) value, value, val);
738 exceptions_throw_illegalargumentexception();
742 _field_set_int(df, o, val);
746 case PRIMITIVETYPE_CHAR: {
749 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
752 switch (sf->parseddesc->decltype) {
753 case PRIMITIVETYPE_CHAR:
754 LLNI_field_get_val((java_lang_Character *) value, value, val);
757 exceptions_throw_illegalargumentexception();
761 _field_set_int(df, o, val);
765 case PRIMITIVETYPE_SHORT: {
768 /* get field only by name, it can be one of B, S */
770 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
773 switch (sf->parseddesc->decltype) {
774 case PRIMITIVETYPE_BYTE:
775 LLNI_field_get_val((java_lang_Byte *) value, value, val);
777 case PRIMITIVETYPE_SHORT:
778 LLNI_field_get_val((java_lang_Short *) value, value, val);
781 exceptions_throw_illegalargumentexception();
785 _field_set_int(df, o, val);
789 case PRIMITIVETYPE_INT: {
792 /* get field only by name, it can be one of B, S, C, I */
794 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
797 switch (sf->parseddesc->decltype) {
798 case PRIMITIVETYPE_BYTE:
799 LLNI_field_get_val((java_lang_Byte *) value, value, val);
801 case PRIMITIVETYPE_CHAR:
802 LLNI_field_get_val((java_lang_Character *) value, value, val);
804 case PRIMITIVETYPE_SHORT:
805 LLNI_field_get_val((java_lang_Short *) value, value, val);
807 case PRIMITIVETYPE_INT:
808 LLNI_field_get_val((java_lang_Integer *) value, value, val);
811 exceptions_throw_illegalargumentexception();
815 _field_set_int(df, o, val);
819 case PRIMITIVETYPE_LONG: {
822 /* get field only by name, it can be one of B, S, C, I, J */
824 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
827 switch (sf->parseddesc->decltype) {
828 case PRIMITIVETYPE_BYTE:
829 LLNI_field_get_val((java_lang_Byte *) value, value, val);
831 case PRIMITIVETYPE_CHAR:
832 LLNI_field_get_val((java_lang_Character *) value, value, val);
834 case PRIMITIVETYPE_SHORT:
835 LLNI_field_get_val((java_lang_Short *) value, value, val);
837 case PRIMITIVETYPE_INT:
838 LLNI_field_get_val((java_lang_Integer *) value, value, val);
840 case PRIMITIVETYPE_LONG:
841 LLNI_field_get_val((java_lang_Long *) value, value, val);
844 exceptions_throw_illegalargumentexception();
848 _field_set_long(df, o, val);
852 case PRIMITIVETYPE_FLOAT: {
855 /* get field only by name, it can be one of B, S, C, I, J, F */
857 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
860 switch (sf->parseddesc->decltype) {
861 case PRIMITIVETYPE_BYTE:
862 LLNI_field_get_val((java_lang_Byte *) value, value, val);
864 case PRIMITIVETYPE_CHAR:
865 LLNI_field_get_val((java_lang_Character *) value, value, val);
867 case PRIMITIVETYPE_SHORT:
868 LLNI_field_get_val((java_lang_Short *) value, value, val);
870 case PRIMITIVETYPE_INT:
871 LLNI_field_get_val((java_lang_Integer *) value, value, val);
873 case PRIMITIVETYPE_LONG:
874 LLNI_field_get_val((java_lang_Long *) value, value, val);
876 case PRIMITIVETYPE_FLOAT:
877 LLNI_field_get_val((java_lang_Float *) value, value, val);
880 exceptions_throw_illegalargumentexception();
884 _field_set_float(df, o, val);
888 case PRIMITIVETYPE_DOUBLE: {
891 /* get field only by name, it can be one of B, S, C, I, J, F, D */
893 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
896 switch (sf->parseddesc->decltype) {
897 case PRIMITIVETYPE_BYTE:
898 LLNI_field_get_val((java_lang_Byte *) value, value, val);
900 case PRIMITIVETYPE_CHAR:
901 LLNI_field_get_val((java_lang_Character *) value, value, val);
903 case PRIMITIVETYPE_SHORT:
904 LLNI_field_get_val((java_lang_Short *) value, value, val);
906 case PRIMITIVETYPE_INT:
907 LLNI_field_get_val((java_lang_Integer *) value, value, val);
909 case PRIMITIVETYPE_LONG:
910 LLNI_field_get_val((java_lang_Long *) value, value, val);
912 case PRIMITIVETYPE_FLOAT:
913 LLNI_field_get_val((java_lang_Float *) value, value, val);
915 case PRIMITIVETYPE_DOUBLE:
916 LLNI_field_get_val((java_lang_Double *) value, value, val);
919 exceptions_throw_illegalargumentexception();
923 _field_set_double(df, o, val);
928 /* check if value is an instance of the destination class */
931 /* if (!builtin_instanceof((java_handle_t *) value, df->class)) */
934 _field_set_handle(df, o, (java_handle_t *) value);
938 /* raise exception */
940 exceptions_throw_illegalargumentexception();
945 * Class: java/lang/reflect/VMField
947 * Signature: (Ljava/lang/Object;Z)V
949 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setBoolean(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value)
955 /* get the class and the field */
957 LLNI_field_get_cls(_this, clazz, c);
958 LLNI_field_get_val(_this, slot , slot);
959 f = &c->fields[slot];
961 /* check if the field can be accessed */
963 if (!_field_access_check(_this, f, (java_handle_t *) o))
966 /* check the field type and set the value */
968 switch (f->parseddesc->decltype) {
969 case PRIMITIVETYPE_BOOLEAN:
970 _field_set_int(f, o, value);
973 exceptions_throw_illegalargumentexception();
981 * Class: java/lang/reflect/VMField
983 * Signature: (Ljava/lang/Object;B)V
985 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setByte(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value)
991 /* get the class and the field */
993 LLNI_field_get_cls(_this, clazz, c);
994 LLNI_field_get_val(_this, slot , slot);
995 f = &c->fields[slot];
997 /* check if the field can be accessed */
999 if (!_field_access_check(_this, f, (java_handle_t *) o))
1002 /* check the field type and set the value */
1004 switch (f->parseddesc->decltype) {
1005 case PRIMITIVETYPE_BYTE:
1006 case PRIMITIVETYPE_SHORT:
1007 case PRIMITIVETYPE_INT:
1008 _field_set_int(f, o, value);
1010 case PRIMITIVETYPE_LONG:
1011 _field_set_long(f, o, value);
1013 case PRIMITIVETYPE_FLOAT:
1014 _field_set_float(f, o, value);
1016 case PRIMITIVETYPE_DOUBLE:
1017 _field_set_double(f, o, value);
1020 exceptions_throw_illegalargumentexception();
1028 * Class: java/lang/reflect/VMField
1030 * Signature: (Ljava/lang/Object;C)V
1032 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setChar(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value)
1038 /* get the class and the field */
1040 LLNI_field_get_cls(_this, clazz, c);
1041 LLNI_field_get_val(_this, slot , slot);
1042 f = &c->fields[slot];
1044 /* check if the field can be accessed */
1046 if (!_field_access_check(_this, f, (java_handle_t *) o))
1049 /* check the field type and set the value */
1051 switch (f->parseddesc->decltype) {
1052 case PRIMITIVETYPE_CHAR:
1053 case PRIMITIVETYPE_INT:
1054 _field_set_int(f, o, value);
1056 case PRIMITIVETYPE_LONG:
1057 _field_set_long(f, o, value);
1059 case PRIMITIVETYPE_FLOAT:
1060 _field_set_float(f, o, value);
1062 case PRIMITIVETYPE_DOUBLE:
1063 _field_set_double(f, o, value);
1066 exceptions_throw_illegalargumentexception();
1074 * Class: java/lang/reflect/VMField
1076 * Signature: (Ljava/lang/Object;S)V
1078 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setShort(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value)
1084 /* get the class and the field */
1086 LLNI_field_get_cls(_this, clazz, c);
1087 LLNI_field_get_val(_this, slot , slot);
1088 f = &c->fields[slot];
1090 /* check if the field can be accessed */
1092 if (!_field_access_check(_this, f, (java_handle_t *) o))
1095 /* check the field type and set the value */
1097 switch (f->parseddesc->decltype) {
1098 case PRIMITIVETYPE_SHORT:
1099 case PRIMITIVETYPE_INT:
1100 _field_set_int(f, o, value);
1102 case PRIMITIVETYPE_LONG:
1103 _field_set_long(f, o, value);
1105 case PRIMITIVETYPE_FLOAT:
1106 _field_set_float(f, o, value);
1108 case PRIMITIVETYPE_DOUBLE:
1109 _field_set_double(f, o, value);
1112 exceptions_throw_illegalargumentexception();
1120 * Class: java/lang/reflect/VMField
1122 * Signature: (Ljava/lang/Object;I)V
1124 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setInt(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int32_t value)
1130 /* get the class and the field */
1132 LLNI_field_get_cls(_this, clazz, c);
1133 LLNI_field_get_val(_this, slot , slot);
1134 f = &c->fields[slot];
1136 /* check if the field can be accessed */
1138 if (!_field_access_check(_this, f, (java_handle_t *) o))
1141 /* check the field type and set the value */
1143 switch (f->parseddesc->decltype) {
1144 case PRIMITIVETYPE_INT:
1145 _field_set_int(f, o, value);
1147 case PRIMITIVETYPE_LONG:
1148 _field_set_long(f, o, value);
1150 case PRIMITIVETYPE_FLOAT:
1151 _field_set_float(f, o, value);
1153 case PRIMITIVETYPE_DOUBLE:
1154 _field_set_double(f, o, value);
1157 exceptions_throw_illegalargumentexception();
1165 * Class: java/lang/reflect/VMField
1167 * Signature: (Ljava/lang/Object;J)V
1169 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setLong(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, int64_t value)
1175 /* get the class and the field */
1177 LLNI_field_get_cls(_this, clazz, c);
1178 LLNI_field_get_val(_this, slot , slot);
1179 f = &c->fields[slot];
1181 /* check if the field can be accessed */
1183 if (!_field_access_check(_this, f, (java_handle_t *) o))
1186 /* check the field type and set the value */
1188 switch (f->parseddesc->decltype) {
1189 case PRIMITIVETYPE_LONG:
1190 _field_set_long(f, o, value);
1192 case PRIMITIVETYPE_FLOAT:
1193 _field_set_float(f, o, value);
1195 case PRIMITIVETYPE_DOUBLE:
1196 _field_set_double(f, o, value);
1199 exceptions_throw_illegalargumentexception();
1207 * Class: java/lang/reflect/VMField
1209 * Signature: (Ljava/lang/Object;F)V
1211 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setFloat(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, float value)
1217 /* get the class and the field */
1219 LLNI_field_get_cls(_this, clazz, c);
1220 LLNI_field_get_val(_this, slot , slot);
1221 f = &c->fields[slot];
1223 /* check if the field can be accessed */
1225 if (!_field_access_check(_this, f, (java_handle_t *) o))
1228 /* check the field type and set the value */
1230 switch (f->parseddesc->decltype) {
1231 case PRIMITIVETYPE_FLOAT:
1232 _field_set_float(f, o, value);
1234 case PRIMITIVETYPE_DOUBLE:
1235 _field_set_double(f, o, value);
1238 exceptions_throw_illegalargumentexception();
1246 * Class: java/lang/reflect/VMField
1248 * Signature: (Ljava/lang/Object;D)V
1250 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setDouble(JNIEnv *env, java_lang_reflect_VMField *_this, java_lang_Object *o, double value)
1256 /* get the class and the field */
1258 LLNI_field_get_cls(_this, clazz, c);
1259 LLNI_field_get_val(_this, slot , slot);
1260 f = &c->fields[slot];
1262 /* check if the field can be accessed */
1264 if (!_field_access_check(_this, f, (java_handle_t *) o))
1267 /* check the field type and set the value */
1269 switch (f->parseddesc->decltype) {
1270 case PRIMITIVETYPE_DOUBLE:
1271 _field_set_double(f, o, value);
1274 exceptions_throw_illegalargumentexception();
1282 * Class: java/lang/reflect/VMField
1283 * Method: getSignature
1284 * Signature: ()Ljava/lang/String;
1286 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_VMField_getSignature(JNIEnv *env, java_lang_reflect_VMField* _this)
1293 /* get the class and the field */
1295 LLNI_field_get_cls(_this, clazz, c);
1296 LLNI_field_get_val(_this, slot , slot);
1297 f = &c->fields[slot];
1299 if (f->signature == NULL)
1302 o = javastring_new(f->signature);
1304 /* in error case o is NULL */
1306 return (java_lang_String *) o;
1310 #if defined(ENABLE_ANNOTATIONS)
1312 * Class: java/lang/reflect/VMField
1313 * Method: declaredAnnotations
1314 * Signature: ()Ljava/util/Map;
1316 JNIEXPORT struct java_util_Map* JNICALL Java_java_lang_reflect_VMField_declaredAnnotations(JNIEnv *env, java_lang_reflect_VMField *_this)
1318 java_util_Map *declaredAnnotations = NULL; /* parsed annotations */
1319 java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
1320 java_lang_Class *declaringClass = NULL; /* the constant pool of this class is used */
1321 classinfo *referer = NULL; /* class, which calles the annotation parser */
1322 /* (for the parameter 'referer' of vm_call_method()) */
1324 LLNI_field_get_ref(_this, declaredAnnotations, declaredAnnotations);
1326 /* are the annotations parsed yet? */
1327 if (declaredAnnotations == NULL) {
1328 LLNI_field_get_ref(_this, annotations, annotations);
1329 LLNI_field_get_ref(_this, clazz, declaringClass);
1330 LLNI_class_get(_this, referer);
1332 declaredAnnotations = reflect_get_declaredannotatios(annotations, declaringClass, referer);
1334 LLNI_field_set_ref(_this, declaredAnnotations, declaredAnnotations);
1337 return declaredAnnotations;
1345 * These are local overrides for various environment variables in Emacs.
1346 * Please do not remove this and leave it at the end of the file, where
1347 * Emacs will automagically detect them.
1348 * ---------------------------------------------------------------------
1351 * indent-tabs-mode: t
1355 * vim:noexpandtab:sw=4:ts=4: