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.hpp"
32 #include "native/llni.h"
33 #include "native/native.hpp"
35 #if defined(ENABLE_JNI_HEADERS)
36 # include "native/vm/include/java_lang_reflect_VMField.h"
39 #if defined(ENABLE_ANNOTATIONS)
41 # include "native/vm/reflection.hpp"
44 #include "vm/access.hpp"
45 #include "vm/jit/builtin.hpp"
46 #include "vm/exceptions.hpp"
47 #include "vm/global.h"
48 #include "vm/initialize.hpp"
49 #include "vm/javaobjects.hpp"
50 #include "vm/loader.hpp"
51 #include "vm/primitive.hpp"
52 #include "vm/resolve.hpp"
53 #include "vm/string.hpp"
57 /* _field_access_check *********************************************************
59 Checks if the field can be accessed.
62 true......field can be accessed, or
63 false.....otherwise (maybe an Exception was thrown).
65 *******************************************************************************/
67 static bool _field_access_check(const java_lang_reflect_VMField& rvmf, fieldinfo *f, java_handle_t *o)
69 // Check if we should bypass security checks (AccessibleObject).
71 java_lang_reflect_Field rf(rvmf.get_f());
72 int32_t override = rf.get_flag();
74 if (override == false) {
75 /* This function is always called like this:
76 [0] java.lang.reflect.VMField.xxx (Native Method)
77 [1] java.lang.reflect.Field.xxx
81 if (!access_check_field(f, 2))
85 /* some general checks */
87 if (f->flags & ACC_STATIC) {
88 /* initialize class if required */
90 if (!(f->clazz->state & CLASS_INITIALIZED))
91 if (!initialize_class(f->clazz))
94 /* everything is ok */
99 /* obj is required for not-static fields */
102 exceptions_throw_nullpointerexception();
106 if (builtin_instanceof(o, f->clazz))
112 exceptions_throw_illegalargumentexception();
117 /* _field_get_type *************************************************************
119 Returns the content of the given field.
121 *******************************************************************************/
123 #define _FIELD_GET_TYPE(name, type, uniontype) \
124 static inline type _field_get_##name(fieldinfo *f, java_handle_t* h) \
127 if (f->flags & ACC_STATIC) { \
128 ret = f->value->uniontype; \
130 LLNI_CRITICAL_START; \
131 ret = *(type *) (((intptr_t) LLNI_DIRECT(h)) + f->offset); \
137 static inline java_handle_t *_field_get_handle(fieldinfo *f, java_handle_t* h)
139 java_object_t* result;
140 java_handle_t* hresult;
144 if (f->flags & ACC_STATIC) {
145 result = (java_object_t*) f->value->a;
147 result = *(java_object_t**) (((intptr_t) LLNI_DIRECT(h)) + f->offset);
150 hresult = LLNI_WRAP(result);
157 _FIELD_GET_TYPE(int, int32_t, i)
158 _FIELD_GET_TYPE(long, int64_t, l)
159 _FIELD_GET_TYPE(float, float, f)
160 _FIELD_GET_TYPE(double, double, d)
163 /* _field_set_type *************************************************************
165 Sets the content of the given field to the given value.
167 *******************************************************************************/
169 #define _FIELD_SET_TYPE(name, type, uniontype) \
170 static inline void _field_set_##name(fieldinfo* f, java_handle_t* h, type value) \
172 if (f->flags & ACC_STATIC) { \
173 f->value->uniontype = value; \
175 LLNI_CRITICAL_START; \
176 *(type *) (((intptr_t) LLNI_DIRECT(h)) + f->offset) = value; \
181 static inline void _field_set_handle(fieldinfo* f, java_handle_t* h, java_handle_t* hvalue)
185 if (f->flags & ACC_STATIC) {
186 f->value->a = LLNI_DIRECT(hvalue);
188 *(java_object_t**) (((intptr_t) LLNI_DIRECT(h)) + f->offset) = LLNI_DIRECT(hvalue);
194 _FIELD_SET_TYPE(int, int32_t, i)
195 _FIELD_SET_TYPE(long, int64_t, l)
196 _FIELD_SET_TYPE(float, float, f)
197 _FIELD_SET_TYPE(double, double, d)
200 // Native functions are exported as C functions.
204 * Class: java/lang/reflect/VMField
205 * Method: getModifiersInternal
208 JNIEXPORT jint JNICALL Java_java_lang_reflect_VMField_getModifiersInternal(JNIEnv *env, jobject _this)
210 java_lang_reflect_VMField rvmf(_this);
211 fieldinfo* f = rvmf.get_field();
217 * Class: java/lang/reflect/VMField
219 * Signature: ()Ljava/lang/Class;
221 JNIEXPORT jclass JNICALL Java_java_lang_reflect_VMField_getType(JNIEnv *env, jobject _this)
223 java_lang_reflect_VMField rvmf(_this);
224 fieldinfo* f = rvmf.get_field();
227 typedesc* desc = f->parseddesc;
232 if (!resolve_class_from_typedesc(desc, true, false, &ret))
235 return (jclass) LLNI_classinfo_wrap(ret);
240 * Class: java/lang/reflect/VMField
242 * Signature: (Ljava/lang/Object;)Ljava/lang/Object;
244 JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMField_get(JNIEnv *env, jobject _this, jobject o)
246 java_lang_reflect_VMField rvmf(_this);
247 fieldinfo* f = rvmf.get_field();
249 // Check if the field can be accessed.
250 if (!_field_access_check(rvmf, f, o))
255 switch (f->parseddesc->primitivetype) {
256 case PRIMITIVETYPE_BOOLEAN:
257 case PRIMITIVETYPE_BYTE:
258 case PRIMITIVETYPE_CHAR:
259 case PRIMITIVETYPE_SHORT:
260 case PRIMITIVETYPE_INT:
261 value.i = _field_get_int(f, o);
264 case PRIMITIVETYPE_LONG:
265 value.l = _field_get_long(f, o);
268 case PRIMITIVETYPE_FLOAT:
269 value.f = _field_get_float(f, o);
272 case PRIMITIVETYPE_DOUBLE:
273 value.d = _field_get_double(f, o);
277 return (jobject) _field_get_handle(f, o);
280 // Now box the primitive types.
281 java_handle_t* object = Primitive::box(f->parseddesc->primitivetype, value);
288 * Class: java/lang/reflect/VMField
290 * Signature: (Ljava/lang/Object;)Z
292 JNIEXPORT jboolean JNICALL Java_java_lang_reflect_VMField_getBoolean(JNIEnv *env, jobject _this, jobject o)
294 java_lang_reflect_VMField rvmf(_this);
295 fieldinfo* f = rvmf.get_field();
297 // Check if the field can be accessed.
298 if (!_field_access_check(rvmf, f, o))
301 // Check the field type and return the value.
302 switch (f->parseddesc->primitivetype) {
303 case PRIMITIVETYPE_BOOLEAN:
304 return (jint) _field_get_int(f, o);
306 exceptions_throw_illegalargumentexception();
313 * Class: java/lang/reflect/VMField
315 * Signature: (Ljava/lang/Object;)B
317 JNIEXPORT jbyte JNICALL Java_java_lang_reflect_VMField_getByte(JNIEnv *env, jobject _this, jobject o)
319 java_lang_reflect_VMField rvmf(_this);
320 fieldinfo* f = rvmf.get_field();
322 // Check if the field can be accessed.
323 if (!_field_access_check(rvmf, f, o))
326 // Check the field type and return the value.
327 switch (f->parseddesc->primitivetype) {
328 case PRIMITIVETYPE_BYTE:
329 return (jint) _field_get_int(f, o);
331 exceptions_throw_illegalargumentexception();
338 * Class: java/lang/reflect/VMField
340 * Signature: (Ljava/lang/Object;)C
342 JNIEXPORT jchar JNICALL Java_java_lang_reflect_VMField_getChar(JNIEnv *env, jobject _this, jobject o)
344 java_lang_reflect_VMField rvmf(_this);
345 fieldinfo* f = rvmf.get_field();
347 // Check if the field can be accessed.
348 if (!_field_access_check(rvmf, f, o))
351 // Check the field type and return the value.
352 switch (f->parseddesc->primitivetype) {
353 case PRIMITIVETYPE_CHAR:
354 return (jint) _field_get_int(f, o);
356 exceptions_throw_illegalargumentexception();
363 * Class: java/lang/reflect/VMField
365 * Signature: (Ljava/lang/Object;)S
367 JNIEXPORT jshort JNICALL Java_java_lang_reflect_VMField_getShort(JNIEnv *env, jobject _this, jobject o)
369 java_lang_reflect_VMField rvmf(_this);
370 fieldinfo* f = rvmf.get_field();
372 // Check if the field can be accessed.
373 if (!_field_access_check(rvmf, f, o))
376 // Check the field type and return the value.
377 switch (f->parseddesc->primitivetype) {
378 case PRIMITIVETYPE_BYTE:
379 case PRIMITIVETYPE_SHORT:
380 return (jint) _field_get_int(f, o);
382 exceptions_throw_illegalargumentexception();
389 * Class: java/lang/reflect/VMField
391 * Signature: (Ljava/lang/Object;)I
393 JNIEXPORT jint JNICALL Java_java_lang_reflect_VMField_getInt(JNIEnv *env , jobject _this, jobject o)
395 java_lang_reflect_VMField rvmf(_this);
396 fieldinfo* f = rvmf.get_field();
398 // Check if the field can be accessed.
399 if (!_field_access_check(rvmf, f, o))
402 // Check the field type and return the value.
403 switch (f->parseddesc->primitivetype) {
404 case PRIMITIVETYPE_BYTE:
405 case PRIMITIVETYPE_CHAR:
406 case PRIMITIVETYPE_SHORT:
407 case PRIMITIVETYPE_INT:
408 return (jint) _field_get_int(f, o);
410 exceptions_throw_illegalargumentexception();
417 * Class: java/lang/reflect/VMField
419 * Signature: (Ljava/lang/Object;)J
421 JNIEXPORT jlong JNICALL Java_java_lang_reflect_VMField_getLong(JNIEnv *env, jobject _this, jobject o)
423 java_lang_reflect_VMField rvmf(_this);
424 fieldinfo* f = rvmf.get_field();
426 // Check if the field can be accessed.
427 if (!_field_access_check(rvmf, f, o))
430 // Check the field type and return the value.
431 switch (f->parseddesc->primitivetype) {
432 case PRIMITIVETYPE_BYTE:
433 case PRIMITIVETYPE_CHAR:
434 case PRIMITIVETYPE_SHORT:
435 case PRIMITIVETYPE_INT:
436 return (jlong) _field_get_int(f, o);
437 case PRIMITIVETYPE_LONG:
438 return (jlong) _field_get_long(f, o);
440 exceptions_throw_illegalargumentexception();
447 * Class: java/lang/reflect/VMField
449 * Signature: (Ljava/lang/Object;)F
451 JNIEXPORT jfloat JNICALL Java_java_lang_reflect_VMField_getFloat(JNIEnv *env, jobject _this, jobject o)
453 java_lang_reflect_VMField rvmf(_this);
454 fieldinfo* f = rvmf.get_field();
456 // Check if the field can be accessed.
457 if (!_field_access_check(rvmf, f, o))
460 // Check the field type and return the value.
461 switch (f->parseddesc->primitivetype) {
462 case PRIMITIVETYPE_BYTE:
463 case PRIMITIVETYPE_CHAR:
464 case PRIMITIVETYPE_SHORT:
465 case PRIMITIVETYPE_INT:
466 return (jfloat) _field_get_int(f, o);
467 case PRIMITIVETYPE_LONG:
468 return (jfloat) _field_get_long(f, o);
469 case PRIMITIVETYPE_FLOAT:
470 return (jfloat) _field_get_float(f, o);
472 exceptions_throw_illegalargumentexception();
479 * Class: java/lang/reflect/VMField
481 * Signature: (Ljava/lang/Object;)D
483 JNIEXPORT jdouble JNICALL Java_java_lang_reflect_VMField_getDouble(JNIEnv *env , jobject _this, jobject o)
485 java_lang_reflect_VMField rvmf(_this);
486 fieldinfo* f = rvmf.get_field();
488 // Check if the field can be accessed.
489 if (!_field_access_check(rvmf, f, o))
492 // Check the field type and return the value.
493 switch (f->parseddesc->primitivetype) {
494 case PRIMITIVETYPE_BYTE:
495 case PRIMITIVETYPE_CHAR:
496 case PRIMITIVETYPE_SHORT:
497 case PRIMITIVETYPE_INT:
498 return (jdouble) _field_get_int(f, o);
499 case PRIMITIVETYPE_LONG:
500 return (jdouble) _field_get_long(f, o);
501 case PRIMITIVETYPE_FLOAT:
502 return (jdouble) _field_get_float(f, o);
503 case PRIMITIVETYPE_DOUBLE:
504 return (jdouble) _field_get_double(f, o);
506 exceptions_throw_illegalargumentexception();
513 * Class: java/lang/reflect/VMField
515 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
517 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, jobject _this, jobject o, jobject value)
519 java_lang_reflect_VMField rvmf(_this);
520 fieldinfo* df = rvmf.get_field();
525 // Check if the field can be accessed.
526 if (!_field_access_check(rvmf, df, o))
529 // Get the source classinfo from the object.
533 LLNI_class_get(value, sc);
535 /* The fieldid is used to set the new value, for primitive
536 types the value has to be retrieved from the wrapping
539 switch (df->parseddesc->primitivetype) {
540 case PRIMITIVETYPE_BOOLEAN: {
543 /* determine the field to read the value */
545 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
548 switch (sf->parseddesc->primitivetype) {
549 case PRIMITIVETYPE_BOOLEAN:
550 val = java_lang_Boolean(value).get_value();
553 exceptions_throw_illegalargumentexception();
557 _field_set_int(df, o, val);
561 case PRIMITIVETYPE_BYTE: {
564 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
567 switch (sf->parseddesc->primitivetype) {
568 case PRIMITIVETYPE_BYTE:
569 val = java_lang_Byte(value).get_value();
572 exceptions_throw_illegalargumentexception();
576 _field_set_int(df, o, val);
580 case PRIMITIVETYPE_CHAR: {
583 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
586 switch (sf->parseddesc->primitivetype) {
587 case PRIMITIVETYPE_CHAR:
588 val = java_lang_Character(value).get_value();
591 exceptions_throw_illegalargumentexception();
595 _field_set_int(df, o, val);
599 case PRIMITIVETYPE_SHORT: {
602 /* get field only by name, it can be one of B, S */
604 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
607 switch (sf->parseddesc->primitivetype) {
608 case PRIMITIVETYPE_BYTE:
609 val = java_lang_Byte(value).get_value();
611 case PRIMITIVETYPE_SHORT:
612 val = java_lang_Short(value).get_value();
615 exceptions_throw_illegalargumentexception();
619 _field_set_int(df, o, val);
623 case PRIMITIVETYPE_INT: {
626 /* get field only by name, it can be one of B, S, C, I */
628 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
631 switch (sf->parseddesc->primitivetype) {
632 case PRIMITIVETYPE_BYTE:
633 val = java_lang_Byte(value).get_value();
635 case PRIMITIVETYPE_CHAR:
636 val = java_lang_Character(value).get_value();
638 case PRIMITIVETYPE_SHORT:
639 val = java_lang_Short(value).get_value();
641 case PRIMITIVETYPE_INT:
642 val = java_lang_Integer(value).get_value();
645 exceptions_throw_illegalargumentexception();
649 _field_set_int(df, o, val);
653 case PRIMITIVETYPE_LONG: {
656 /* get field only by name, it can be one of B, S, C, I, J */
658 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
661 switch (sf->parseddesc->primitivetype) {
662 case PRIMITIVETYPE_BYTE:
663 val = java_lang_Byte(value).get_value();
665 case PRIMITIVETYPE_CHAR:
666 val = java_lang_Character(value).get_value();
668 case PRIMITIVETYPE_SHORT:
669 val = java_lang_Short(value).get_value();
671 case PRIMITIVETYPE_INT:
672 val = java_lang_Integer(value).get_value();
674 case PRIMITIVETYPE_LONG:
675 val = java_lang_Long(value).get_value();
678 exceptions_throw_illegalargumentexception();
682 _field_set_long(df, o, val);
686 case PRIMITIVETYPE_FLOAT: {
689 /* get field only by name, it can be one of B, S, C, I, J, F */
691 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
694 switch (sf->parseddesc->primitivetype) {
695 case PRIMITIVETYPE_BYTE:
696 val = java_lang_Byte(value).get_value();
698 case PRIMITIVETYPE_CHAR:
699 val = java_lang_Character(value).get_value();
701 case PRIMITIVETYPE_SHORT:
702 val = java_lang_Short(value).get_value();
704 case PRIMITIVETYPE_INT:
705 val = java_lang_Integer(value).get_value();
707 case PRIMITIVETYPE_LONG:
708 val = java_lang_Long(value).get_value();
710 case PRIMITIVETYPE_FLOAT:
711 val = java_lang_Float(value).get_value();
714 exceptions_throw_illegalargumentexception();
718 _field_set_float(df, o, val);
722 case PRIMITIVETYPE_DOUBLE: {
725 /* get field only by name, it can be one of B, S, C, I, J, F, D */
727 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
730 switch (sf->parseddesc->primitivetype) {
731 case PRIMITIVETYPE_BYTE:
732 val = java_lang_Byte(value).get_value();
734 case PRIMITIVETYPE_CHAR:
735 val = java_lang_Character(value).get_value();
737 case PRIMITIVETYPE_SHORT:
738 val = java_lang_Short(value).get_value();
740 case PRIMITIVETYPE_INT:
741 val = java_lang_Integer(value).get_value();
743 case PRIMITIVETYPE_LONG:
744 val = java_lang_Long(value).get_value();
746 case PRIMITIVETYPE_FLOAT:
747 val = java_lang_Float(value).get_value();
749 case PRIMITIVETYPE_DOUBLE:
750 val = java_lang_Double(value).get_value();
753 exceptions_throw_illegalargumentexception();
757 _field_set_double(df, o, val);
762 /* check if value is an instance of the destination class */
765 /* if (!builtin_instanceof((java_handle_t *) value, df->class)) */
768 _field_set_handle(df, o, value);
772 /* raise exception */
774 exceptions_throw_illegalargumentexception();
779 * Class: java/lang/reflect/VMField
781 * Signature: (Ljava/lang/Object;Z)V
783 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setBoolean(JNIEnv *env, jobject _this, jobject o, jboolean value)
785 java_lang_reflect_VMField rvmf(_this);
786 fieldinfo* f = rvmf.get_field();
788 // Check if the field can be accessed.
789 if (!_field_access_check(rvmf, f, o))
792 // Check the field type and set the value.
793 switch (f->parseddesc->primitivetype) {
794 case PRIMITIVETYPE_BOOLEAN:
795 _field_set_int(f, o, value);
798 exceptions_throw_illegalargumentexception();
804 * Class: java/lang/reflect/VMField
806 * Signature: (Ljava/lang/Object;B)V
808 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setByte(JNIEnv *env, jobject _this, jobject o, jbyte value)
810 java_lang_reflect_VMField rvmf(_this);
811 fieldinfo* f = rvmf.get_field();
813 // Check if the field can be accessed.
814 if (!_field_access_check(rvmf, f, o))
817 // Check the field type and set the value.
818 switch (f->parseddesc->primitivetype) {
819 case PRIMITIVETYPE_BYTE:
820 case PRIMITIVETYPE_SHORT:
821 case PRIMITIVETYPE_INT:
822 _field_set_int(f, o, value);
824 case PRIMITIVETYPE_LONG:
825 _field_set_long(f, o, value);
827 case PRIMITIVETYPE_FLOAT:
828 _field_set_float(f, o, value);
830 case PRIMITIVETYPE_DOUBLE:
831 _field_set_double(f, o, value);
834 exceptions_throw_illegalargumentexception();
840 * Class: java/lang/reflect/VMField
842 * Signature: (Ljava/lang/Object;C)V
844 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setChar(JNIEnv *env, jobject _this, jobject o, jchar value)
846 java_lang_reflect_VMField rvmf(_this);
847 fieldinfo* f = rvmf.get_field();
849 // Check if the field can be accessed.
850 if (!_field_access_check(rvmf, f, o))
853 // Check the field type and set the value.
854 switch (f->parseddesc->primitivetype) {
855 case PRIMITIVETYPE_CHAR:
856 case PRIMITIVETYPE_INT:
857 _field_set_int(f, o, value);
859 case PRIMITIVETYPE_LONG:
860 _field_set_long(f, o, value);
862 case PRIMITIVETYPE_FLOAT:
863 _field_set_float(f, o, value);
865 case PRIMITIVETYPE_DOUBLE:
866 _field_set_double(f, o, value);
869 exceptions_throw_illegalargumentexception();
875 * Class: java/lang/reflect/VMField
877 * Signature: (Ljava/lang/Object;S)V
879 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setShort(JNIEnv *env, jobject _this, jobject o, jshort value)
881 java_lang_reflect_VMField rvmf(_this);
882 fieldinfo* f = rvmf.get_field();
884 // Check if the field can be accessed.
885 if (!_field_access_check(rvmf, f, o))
888 // Check the field type and set the value.
889 switch (f->parseddesc->primitivetype) {
890 case PRIMITIVETYPE_SHORT:
891 case PRIMITIVETYPE_INT:
892 _field_set_int(f, o, value);
894 case PRIMITIVETYPE_LONG:
895 _field_set_long(f, o, value);
897 case PRIMITIVETYPE_FLOAT:
898 _field_set_float(f, o, value);
900 case PRIMITIVETYPE_DOUBLE:
901 _field_set_double(f, o, value);
904 exceptions_throw_illegalargumentexception();
910 * Class: java/lang/reflect/VMField
912 * Signature: (Ljava/lang/Object;I)V
914 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setInt(JNIEnv *env, jobject _this, jobject o, jint value)
916 java_lang_reflect_VMField rvmf(_this);
917 fieldinfo* f = rvmf.get_field();
919 // Check if the field can be accessed.
920 if (!_field_access_check(rvmf, f, o))
923 // Check the field type and set the value.
924 switch (f->parseddesc->primitivetype) {
925 case PRIMITIVETYPE_INT:
926 _field_set_int(f, o, value);
928 case PRIMITIVETYPE_LONG:
929 _field_set_long(f, o, value);
931 case PRIMITIVETYPE_FLOAT:
932 _field_set_float(f, o, value);
934 case PRIMITIVETYPE_DOUBLE:
935 _field_set_double(f, o, value);
938 exceptions_throw_illegalargumentexception();
944 * Class: java/lang/reflect/VMField
946 * Signature: (Ljava/lang/Object;J)V
948 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setLong(JNIEnv *env, jobject _this, jobject o, jlong value)
950 java_lang_reflect_VMField rvmf(_this);
951 fieldinfo* f = rvmf.get_field();
953 // Check if the field can be accessed.
954 if (!_field_access_check(rvmf, f, o))
957 // Check the field type and set the value.
958 switch (f->parseddesc->primitivetype) {
959 case PRIMITIVETYPE_LONG:
960 _field_set_long(f, o, value);
962 case PRIMITIVETYPE_FLOAT:
963 _field_set_float(f, o, value);
965 case PRIMITIVETYPE_DOUBLE:
966 _field_set_double(f, o, value);
969 exceptions_throw_illegalargumentexception();
975 * Class: java/lang/reflect/VMField
977 * Signature: (Ljava/lang/Object;F)V
979 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setFloat(JNIEnv *env, jobject _this, jobject o, jfloat value)
981 java_lang_reflect_VMField rvmf(_this);
982 fieldinfo* f = rvmf.get_field();
984 // Check if the field can be accessed.
985 if (!_field_access_check(rvmf, f, o))
988 // Check the field type and set the value.
989 switch (f->parseddesc->primitivetype) {
990 case PRIMITIVETYPE_FLOAT:
991 _field_set_float(f, o, value);
993 case PRIMITIVETYPE_DOUBLE:
994 _field_set_double(f, o, value);
997 exceptions_throw_illegalargumentexception();
1003 * Class: java/lang/reflect/VMField
1005 * Signature: (Ljava/lang/Object;D)V
1007 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setDouble(JNIEnv *env, jobject _this, jobject o, jdouble value)
1009 java_lang_reflect_VMField rvmf(_this);
1010 fieldinfo* f = rvmf.get_field();
1012 // Check if the field can be accessed.
1013 if (!_field_access_check(rvmf, f, o))
1016 // Check the field type and set the value.
1017 switch (f->parseddesc->primitivetype) {
1018 case PRIMITIVETYPE_DOUBLE:
1019 _field_set_double(f, o, value);
1022 exceptions_throw_illegalargumentexception();
1028 * Class: java/lang/reflect/VMField
1029 * Method: getSignature
1030 * Signature: ()Ljava/lang/String;
1032 JNIEXPORT jstring JNICALL Java_java_lang_reflect_VMField_getSignature(JNIEnv *env, jobject _this)
1034 java_lang_reflect_VMField rvmf(_this);
1035 fieldinfo* f = rvmf.get_field();
1037 if (f->signature == NULL)
1040 java_handle_t* o = javastring_new(f->signature);
1042 /* in error case o is NULL */
1048 #if defined(ENABLE_ANNOTATIONS)
1050 * Class: java/lang/reflect/VMField
1051 * Method: declaredAnnotations
1052 * Signature: ()Ljava/util/Map;
1054 JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMField_declaredAnnotations(JNIEnv *env, jobject _this)
1056 java_lang_reflect_VMField rvmf(_this);
1058 java_handle_t* declaredAnnotations = rvmf.get_declaredAnnotations();
1060 // Are the annotations parsed yet?
1061 if (declaredAnnotations == NULL) {
1062 java_handle_bytearray_t* annotations = rvmf.get_annotations();
1063 classinfo* declaringClass = rvmf.get_clazz();
1064 classinfo* referer = rvmf.get_Class();
1066 declaredAnnotations = Reflection::get_declaredannotations(annotations, declaringClass, referer);
1068 rvmf.set_declaredAnnotations(declaredAnnotations);
1071 return (jobject) declaredAnnotations;
1078 /* native methods implemented by this file ************************************/
1080 static const JNINativeMethod methods[] = {
1081 { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getModifiersInternal },
1082 { (char*) "getType", (char*) "()Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getType },
1083 { (char*) "get", (char*) "(Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_get },
1084 { (char*) "getBoolean", (char*) "(Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getBoolean },
1085 { (char*) "getByte", (char*) "(Ljava/lang/Object;)B", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getByte },
1086 { (char*) "getChar", (char*) "(Ljava/lang/Object;)C", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getChar },
1087 { (char*) "getShort", (char*) "(Ljava/lang/Object;)S", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getShort },
1088 { (char*) "getInt", (char*) "(Ljava/lang/Object;)I", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getInt },
1089 { (char*) "getLong", (char*) "(Ljava/lang/Object;)J", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getLong },
1090 { (char*) "getFloat", (char*) "(Ljava/lang/Object;)F", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getFloat },
1091 { (char*) "getDouble", (char*) "(Ljava/lang/Object;)D", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getDouble },
1092 { (char*) "set", (char*) "(Ljava/lang/Object;Ljava/lang/Object;)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_set },
1093 { (char*) "setBoolean", (char*) "(Ljava/lang/Object;Z)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setBoolean },
1094 { (char*) "setByte", (char*) "(Ljava/lang/Object;B)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setByte },
1095 { (char*) "setChar", (char*) "(Ljava/lang/Object;C)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setChar },
1096 { (char*) "setShort", (char*) "(Ljava/lang/Object;S)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setShort },
1097 { (char*) "setInt", (char*) "(Ljava/lang/Object;I)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setInt },
1098 { (char*) "setLong", (char*) "(Ljava/lang/Object;J)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setLong },
1099 { (char*) "setFloat", (char*) "(Ljava/lang/Object;F)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setFloat },
1100 { (char*) "setDouble", (char*) "(Ljava/lang/Object;D)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setDouble },
1101 { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getSignature },
1102 #if defined(ENABLE_ANNOTATIONS)
1103 { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_declaredAnnotations },
1108 /* _Jv_java_lang_reflect_VMField_init ******************************************
1110 Register native functions.
1112 *******************************************************************************/
1114 void _Jv_java_lang_reflect_VMField_init(void)
1116 utf* u = utf_new_char("java/lang/reflect/VMField");
1118 NativeMethods& nm = VM::get_current()->get_nativemethods();
1119 nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
1124 * These are local overrides for various environment variables in Emacs.
1125 * Please do not remove this and leave it at the end of the file, where
1126 * Emacs will automagically detect them.
1127 * ---------------------------------------------------------------------
1130 * indent-tabs-mode: t
1134 * vim:noexpandtab:sw=4:ts=4: