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.h"
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.h"
45 #include "vm/builtin.h"
46 #include "vm/exceptions.hpp"
47 #include "vm/global.h"
48 #include "vm/initialize.h"
49 #include "vm/javaobjects.hpp"
50 #include "vm/loader.h"
51 #include "vm/primitive.hpp"
52 #include "vm/resolve.h"
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 java_handle_t* ho = (java_handle_t*) o;
251 /* check if the field can be accessed */
253 if (!_field_access_check(rvmf, f, ho))
258 switch (f->parseddesc->primitivetype) {
259 case PRIMITIVETYPE_BOOLEAN:
260 case PRIMITIVETYPE_BYTE:
261 case PRIMITIVETYPE_CHAR:
262 case PRIMITIVETYPE_SHORT:
263 case PRIMITIVETYPE_INT:
264 value.i = _field_get_int(f, ho);
267 case PRIMITIVETYPE_LONG:
268 value.l = _field_get_long(f, ho);
271 case PRIMITIVETYPE_FLOAT:
272 value.f = _field_get_float(f, ho);
275 case PRIMITIVETYPE_DOUBLE:
276 value.d = _field_get_double(f, ho);
280 return (jobject) _field_get_handle(f, ho);
283 /* Now box the primitive types. */
285 java_handle_t* object = Primitive::box(f->parseddesc->primitivetype, value);
287 return (jobject) object;
292 * Class: java/lang/reflect/VMField
294 * Signature: (Ljava/lang/Object;)Z
296 JNIEXPORT jboolean JNICALL Java_java_lang_reflect_VMField_getBoolean(JNIEnv *env, jobject _this, jobject o)
298 java_lang_reflect_VMField rvmf(_this);
299 fieldinfo* f = rvmf.get_field();
301 java_handle_t* ho = (java_handle_t*) o;
303 /* check if the field can be accessed */
305 if (!_field_access_check(rvmf, f, ho))
308 /* check the field type and return the value */
310 switch (f->parseddesc->primitivetype) {
311 case PRIMITIVETYPE_BOOLEAN:
312 return (int32_t) _field_get_int(f, ho);
314 exceptions_throw_illegalargumentexception();
321 * Class: java/lang/reflect/VMField
323 * Signature: (Ljava/lang/Object;)B
325 JNIEXPORT jbyte JNICALL Java_java_lang_reflect_VMField_getByte(JNIEnv *env, jobject _this, jobject o)
327 java_lang_reflect_VMField rvmf(_this);
328 fieldinfo* f = rvmf.get_field();
330 java_handle_t* ho = (java_handle_t*) o;
332 /* check if the field can be accessed */
334 if (!_field_access_check(rvmf, f, ho))
337 /* check the field type and return the value */
339 switch (f->parseddesc->primitivetype) {
340 case PRIMITIVETYPE_BYTE:
341 return (int32_t) _field_get_int(f, ho);
343 exceptions_throw_illegalargumentexception();
350 * Class: java/lang/reflect/VMField
352 * Signature: (Ljava/lang/Object;)C
354 JNIEXPORT jchar JNICALL Java_java_lang_reflect_VMField_getChar(JNIEnv *env, jobject _this, jobject o)
356 java_lang_reflect_VMField rvmf(_this);
357 fieldinfo* f = rvmf.get_field();
359 java_handle_t* ho = (java_handle_t*) o;
361 /* check if the field can be accessed */
363 if (!_field_access_check(rvmf, f, ho))
366 /* check the field type and return the value */
368 switch (f->parseddesc->primitivetype) {
369 case PRIMITIVETYPE_CHAR:
370 return (int32_t) _field_get_int(f, ho);
372 exceptions_throw_illegalargumentexception();
379 * Class: java/lang/reflect/VMField
381 * Signature: (Ljava/lang/Object;)S
383 JNIEXPORT jshort JNICALL Java_java_lang_reflect_VMField_getShort(JNIEnv *env, jobject _this, jobject o)
385 java_lang_reflect_VMField rvmf(_this);
386 fieldinfo* f = rvmf.get_field();
388 java_handle_t* ho = (java_handle_t*) o;
390 /* check if the field can be accessed */
392 if (!_field_access_check(rvmf, f, ho))
395 /* check the field type and return the value */
397 switch (f->parseddesc->primitivetype) {
398 case PRIMITIVETYPE_BYTE:
399 case PRIMITIVETYPE_SHORT:
400 return (int32_t) _field_get_int(f, ho);
402 exceptions_throw_illegalargumentexception();
409 * Class: java/lang/reflect/VMField
411 * Signature: (Ljava/lang/Object;)I
413 JNIEXPORT jint JNICALL Java_java_lang_reflect_VMField_getInt(JNIEnv *env , jobject _this, jobject o)
415 java_lang_reflect_VMField rvmf(_this);
416 fieldinfo* f = rvmf.get_field();
418 java_handle_t* ho = (java_handle_t*) o;
420 /* check if the field can be accessed */
422 if (!_field_access_check(rvmf, f, ho))
425 /* check the field type and return the value */
427 switch (f->parseddesc->primitivetype) {
428 case PRIMITIVETYPE_BYTE:
429 case PRIMITIVETYPE_CHAR:
430 case PRIMITIVETYPE_SHORT:
431 case PRIMITIVETYPE_INT:
432 return (int32_t) _field_get_int(f, ho);
434 exceptions_throw_illegalargumentexception();
441 * Class: java/lang/reflect/VMField
443 * Signature: (Ljava/lang/Object;)J
445 JNIEXPORT jlong JNICALL Java_java_lang_reflect_VMField_getLong(JNIEnv *env, jobject _this, jobject o)
447 java_lang_reflect_VMField rvmf(_this);
448 fieldinfo* f = rvmf.get_field();
450 java_handle_t* ho = (java_handle_t*) o;
452 /* check if the field can be accessed */
454 if (!_field_access_check(rvmf, f, ho))
457 /* check the field type and return the value */
459 switch (f->parseddesc->primitivetype) {
460 case PRIMITIVETYPE_BYTE:
461 case PRIMITIVETYPE_CHAR:
462 case PRIMITIVETYPE_SHORT:
463 case PRIMITIVETYPE_INT:
464 return (int64_t) _field_get_int(f, ho);
465 case PRIMITIVETYPE_LONG:
466 return (int64_t) _field_get_long(f, ho);
468 exceptions_throw_illegalargumentexception();
475 * Class: java/lang/reflect/VMField
477 * Signature: (Ljava/lang/Object;)F
479 JNIEXPORT jfloat JNICALL Java_java_lang_reflect_VMField_getFloat(JNIEnv *env, jobject _this, jobject o)
481 java_lang_reflect_VMField rvmf(_this);
482 fieldinfo* f = rvmf.get_field();
484 java_handle_t* ho = (java_handle_t*) o;
486 /* check if the field can be accessed */
488 if (!_field_access_check(rvmf, f, ho))
491 /* 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 (float) _field_get_int(f, ho);
499 case PRIMITIVETYPE_LONG:
500 return (float) _field_get_long(f, ho);
501 case PRIMITIVETYPE_FLOAT:
502 return (float) _field_get_float(f, ho);
504 exceptions_throw_illegalargumentexception();
511 * Class: java/lang/reflect/VMField
513 * Signature: (Ljava/lang/Object;)D
515 JNIEXPORT jdouble JNICALL Java_java_lang_reflect_VMField_getDouble(JNIEnv *env , jobject _this, jobject o)
517 java_lang_reflect_VMField rvmf(_this);
518 fieldinfo* f = rvmf.get_field();
520 java_handle_t* ho = (java_handle_t*) o;
522 /* check if the field can be accessed */
524 if (!_field_access_check(rvmf, f, ho))
527 /* check the field type and return the value */
529 switch (f->parseddesc->primitivetype) {
530 case PRIMITIVETYPE_BYTE:
531 case PRIMITIVETYPE_CHAR:
532 case PRIMITIVETYPE_SHORT:
533 case PRIMITIVETYPE_INT:
534 return (jdouble) _field_get_int(f, ho);
535 case PRIMITIVETYPE_LONG:
536 return (jdouble) _field_get_long(f, ho);
537 case PRIMITIVETYPE_FLOAT:
538 return (jdouble) _field_get_float(f, ho);
539 case PRIMITIVETYPE_DOUBLE:
540 return (jdouble) _field_get_double(f, ho);
542 exceptions_throw_illegalargumentexception();
549 * Class: java/lang/reflect/VMField
551 * Signature: (Ljava/lang/Object;Ljava/lang/Object;)V
553 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_set(JNIEnv *env, jobject _this, jobject o, jobject value)
555 java_lang_reflect_VMField rvmf(_this);
556 fieldinfo* df = rvmf.get_field();
558 java_handle_t* ho = (java_handle_t*) o;
559 java_handle_t* hvalue = (java_handle_t*) value;
564 /* check if the field can be accessed */
566 if (!_field_access_check(rvmf, df, ho))
569 /* get the source classinfo from the object */
574 LLNI_class_get(hvalue, sc);
576 /* The fieldid is used to set the new value, for primitive
577 types the value has to be retrieved from the wrapping
580 switch (df->parseddesc->primitivetype) {
581 case PRIMITIVETYPE_BOOLEAN: {
584 /* determine the field to read the value */
586 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_Z)))
589 switch (sf->parseddesc->primitivetype) {
590 case PRIMITIVETYPE_BOOLEAN:
591 val = java_lang_Boolean(hvalue).get_value();
594 exceptions_throw_illegalargumentexception();
598 _field_set_int(df, ho, val);
602 case PRIMITIVETYPE_BYTE: {
605 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_B)))
608 switch (sf->parseddesc->primitivetype) {
609 case PRIMITIVETYPE_BYTE:
610 val = java_lang_Byte(hvalue).get_value();
613 exceptions_throw_illegalargumentexception();
617 _field_set_int(df, ho, val);
621 case PRIMITIVETYPE_CHAR: {
624 if ((sc == NULL) || !(sf = class_findfield(sc, utf_value, utf_C)))
627 switch (sf->parseddesc->primitivetype) {
628 case PRIMITIVETYPE_CHAR:
629 val = java_lang_Character(hvalue).get_value();
632 exceptions_throw_illegalargumentexception();
636 _field_set_int(df, ho, val);
640 case PRIMITIVETYPE_SHORT: {
643 /* get field only by name, it can be one of B, S */
645 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
648 switch (sf->parseddesc->primitivetype) {
649 case PRIMITIVETYPE_BYTE:
650 val = java_lang_Byte(hvalue).get_value();
652 case PRIMITIVETYPE_SHORT:
653 val = java_lang_Short(hvalue).get_value();
656 exceptions_throw_illegalargumentexception();
660 _field_set_int(df, ho, val);
664 case PRIMITIVETYPE_INT: {
667 /* get field only by name, it can be one of B, S, C, I */
669 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
672 switch (sf->parseddesc->primitivetype) {
673 case PRIMITIVETYPE_BYTE:
674 val = java_lang_Byte(hvalue).get_value();
676 case PRIMITIVETYPE_CHAR:
677 val = java_lang_Character(hvalue).get_value();
679 case PRIMITIVETYPE_SHORT:
680 val = java_lang_Short(hvalue).get_value();
682 case PRIMITIVETYPE_INT:
683 val = java_lang_Integer(hvalue).get_value();
686 exceptions_throw_illegalargumentexception();
690 _field_set_int(df, ho, val);
694 case PRIMITIVETYPE_LONG: {
697 /* get field only by name, it can be one of B, S, C, I, J */
699 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
702 switch (sf->parseddesc->primitivetype) {
703 case PRIMITIVETYPE_BYTE:
704 val = java_lang_Byte(hvalue).get_value();
706 case PRIMITIVETYPE_CHAR:
707 val = java_lang_Character(hvalue).get_value();
709 case PRIMITIVETYPE_SHORT:
710 val = java_lang_Short(hvalue).get_value();
712 case PRIMITIVETYPE_INT:
713 val = java_lang_Integer(hvalue).get_value();
715 case PRIMITIVETYPE_LONG:
716 val = java_lang_Long(hvalue).get_value();
719 exceptions_throw_illegalargumentexception();
723 _field_set_long(df, ho, val);
727 case PRIMITIVETYPE_FLOAT: {
730 /* get field only by name, it can be one of B, S, C, I, J, F */
732 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
735 switch (sf->parseddesc->primitivetype) {
736 case PRIMITIVETYPE_BYTE:
737 val = java_lang_Byte(hvalue).get_value();
739 case PRIMITIVETYPE_CHAR:
740 val = java_lang_Character(hvalue).get_value();
742 case PRIMITIVETYPE_SHORT:
743 val = java_lang_Short(hvalue).get_value();
745 case PRIMITIVETYPE_INT:
746 val = java_lang_Integer(hvalue).get_value();
748 case PRIMITIVETYPE_LONG:
749 val = java_lang_Long(hvalue).get_value();
751 case PRIMITIVETYPE_FLOAT:
752 val = java_lang_Float(hvalue).get_value();
755 exceptions_throw_illegalargumentexception();
759 _field_set_float(df, ho, val);
763 case PRIMITIVETYPE_DOUBLE: {
766 /* get field only by name, it can be one of B, S, C, I, J, F, D */
768 if ((sc == NULL) || !(sf = class_findfield_by_name(sc, utf_value)))
771 switch (sf->parseddesc->primitivetype) {
772 case PRIMITIVETYPE_BYTE:
773 val = java_lang_Byte(hvalue).get_value();
775 case PRIMITIVETYPE_CHAR:
776 val = java_lang_Character(hvalue).get_value();
778 case PRIMITIVETYPE_SHORT:
779 val = java_lang_Short(hvalue).get_value();
781 case PRIMITIVETYPE_INT:
782 val = java_lang_Integer(hvalue).get_value();
784 case PRIMITIVETYPE_LONG:
785 val = java_lang_Long(hvalue).get_value();
787 case PRIMITIVETYPE_FLOAT:
788 val = java_lang_Float(hvalue).get_value();
790 case PRIMITIVETYPE_DOUBLE:
791 val = java_lang_Double(hvalue).get_value();
794 exceptions_throw_illegalargumentexception();
798 _field_set_double(df, ho, val);
803 /* check if value is an instance of the destination class */
806 /* if (!builtin_instanceof((java_handle_t *) value, df->class)) */
809 _field_set_handle(df, ho, hvalue);
813 /* raise exception */
815 exceptions_throw_illegalargumentexception();
820 * Class: java/lang/reflect/VMField
822 * Signature: (Ljava/lang/Object;Z)V
824 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setBoolean(JNIEnv *env, jobject _this, jobject o, jboolean value)
826 java_lang_reflect_VMField rvmf(_this);
827 fieldinfo* f = rvmf.get_field();
829 java_handle_t* ho = (java_handle_t*) o;
831 /* check if the field can be accessed */
833 if (!_field_access_check(rvmf, f, ho))
836 /* check the field type and set the value */
838 switch (f->parseddesc->primitivetype) {
839 case PRIMITIVETYPE_BOOLEAN:
840 _field_set_int(f, ho, value);
843 exceptions_throw_illegalargumentexception();
849 * Class: java/lang/reflect/VMField
851 * Signature: (Ljava/lang/Object;B)V
853 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setByte(JNIEnv *env, jobject _this, jobject o, jbyte value)
855 java_lang_reflect_VMField rvmf(_this);
856 fieldinfo* f = rvmf.get_field();
858 java_handle_t* ho = (java_handle_t*) o;
860 /* check if the field can be accessed */
862 if (!_field_access_check(rvmf, f, ho))
865 /* check the field type and set the value */
867 switch (f->parseddesc->primitivetype) {
868 case PRIMITIVETYPE_BYTE:
869 case PRIMITIVETYPE_SHORT:
870 case PRIMITIVETYPE_INT:
871 _field_set_int(f, ho, value);
873 case PRIMITIVETYPE_LONG:
874 _field_set_long(f, ho, value);
876 case PRIMITIVETYPE_FLOAT:
877 _field_set_float(f, ho, value);
879 case PRIMITIVETYPE_DOUBLE:
880 _field_set_double(f, ho, value);
883 exceptions_throw_illegalargumentexception();
889 * Class: java/lang/reflect/VMField
891 * Signature: (Ljava/lang/Object;C)V
893 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setChar(JNIEnv *env, jobject _this, jobject o, jchar value)
895 java_lang_reflect_VMField rvmf(_this);
896 fieldinfo* f = rvmf.get_field();
898 java_handle_t* ho = (java_handle_t*) o;
900 /* check if the field can be accessed */
902 if (!_field_access_check(rvmf, f, ho))
905 /* check the field type and set the value */
907 switch (f->parseddesc->primitivetype) {
908 case PRIMITIVETYPE_CHAR:
909 case PRIMITIVETYPE_INT:
910 _field_set_int(f, ho, value);
912 case PRIMITIVETYPE_LONG:
913 _field_set_long(f, ho, value);
915 case PRIMITIVETYPE_FLOAT:
916 _field_set_float(f, ho, value);
918 case PRIMITIVETYPE_DOUBLE:
919 _field_set_double(f, ho, value);
922 exceptions_throw_illegalargumentexception();
928 * Class: java/lang/reflect/VMField
930 * Signature: (Ljava/lang/Object;S)V
932 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setShort(JNIEnv *env, jobject _this, jobject o, jshort value)
934 java_lang_reflect_VMField rvmf(_this);
935 fieldinfo* f = rvmf.get_field();
937 java_handle_t* ho = (java_handle_t*) o;
939 /* check if the field can be accessed */
941 if (!_field_access_check(rvmf, f, ho))
944 /* check the field type and set the value */
946 switch (f->parseddesc->primitivetype) {
947 case PRIMITIVETYPE_SHORT:
948 case PRIMITIVETYPE_INT:
949 _field_set_int(f, ho, value);
951 case PRIMITIVETYPE_LONG:
952 _field_set_long(f, ho, value);
954 case PRIMITIVETYPE_FLOAT:
955 _field_set_float(f, ho, value);
957 case PRIMITIVETYPE_DOUBLE:
958 _field_set_double(f, ho, value);
961 exceptions_throw_illegalargumentexception();
967 * Class: java/lang/reflect/VMField
969 * Signature: (Ljava/lang/Object;I)V
971 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setInt(JNIEnv *env, jobject _this, jobject o, jint value)
973 java_lang_reflect_VMField rvmf(_this);
974 fieldinfo* f = rvmf.get_field();
976 java_handle_t* ho = (java_handle_t*) o;
978 /* check if the field can be accessed */
980 if (!_field_access_check(rvmf, f, ho))
983 /* check the field type and set the value */
985 switch (f->parseddesc->primitivetype) {
986 case PRIMITIVETYPE_INT:
987 _field_set_int(f, ho, value);
989 case PRIMITIVETYPE_LONG:
990 _field_set_long(f, ho, value);
992 case PRIMITIVETYPE_FLOAT:
993 _field_set_float(f, ho, value);
995 case PRIMITIVETYPE_DOUBLE:
996 _field_set_double(f, ho, value);
999 exceptions_throw_illegalargumentexception();
1005 * Class: java/lang/reflect/VMField
1007 * Signature: (Ljava/lang/Object;J)V
1009 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setLong(JNIEnv *env, jobject _this, jobject o, jlong value)
1011 java_lang_reflect_VMField rvmf(_this);
1012 fieldinfo* f = rvmf.get_field();
1014 java_handle_t* ho = (java_handle_t*) o;
1016 /* check if the field can be accessed */
1018 if (!_field_access_check(rvmf, f, ho))
1021 /* check the field type and set the value */
1023 switch (f->parseddesc->primitivetype) {
1024 case PRIMITIVETYPE_LONG:
1025 _field_set_long(f, ho, value);
1027 case PRIMITIVETYPE_FLOAT:
1028 _field_set_float(f, ho, value);
1030 case PRIMITIVETYPE_DOUBLE:
1031 _field_set_double(f, ho, value);
1034 exceptions_throw_illegalargumentexception();
1040 * Class: java/lang/reflect/VMField
1042 * Signature: (Ljava/lang/Object;F)V
1044 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setFloat(JNIEnv *env, jobject _this, jobject o, jfloat value)
1046 java_lang_reflect_VMField rvmf(_this);
1047 fieldinfo* f = rvmf.get_field();
1049 java_handle_t* ho = (java_handle_t*) o;
1051 /* check if the field can be accessed */
1053 if (!_field_access_check(rvmf, f, ho))
1056 /* check the field type and set the value */
1058 switch (f->parseddesc->primitivetype) {
1059 case PRIMITIVETYPE_FLOAT:
1060 _field_set_float(f, ho, value);
1062 case PRIMITIVETYPE_DOUBLE:
1063 _field_set_double(f, ho, value);
1066 exceptions_throw_illegalargumentexception();
1072 * Class: java/lang/reflect/VMField
1074 * Signature: (Ljava/lang/Object;D)V
1076 JNIEXPORT void JNICALL Java_java_lang_reflect_VMField_setDouble(JNIEnv *env, jobject _this, jobject o, jdouble value)
1078 java_lang_reflect_VMField rvmf(_this);
1079 fieldinfo* f = rvmf.get_field();
1081 java_handle_t* ho = (java_handle_t*) o;
1083 /* check if the field can be accessed */
1085 if (!_field_access_check(rvmf, f, ho))
1088 /* check the field type and set the value */
1090 switch (f->parseddesc->primitivetype) {
1091 case PRIMITIVETYPE_DOUBLE:
1092 _field_set_double(f, ho, value);
1095 exceptions_throw_illegalargumentexception();
1101 * Class: java/lang/reflect/VMField
1102 * Method: getSignature
1103 * Signature: ()Ljava/lang/String;
1105 JNIEXPORT jstring JNICALL Java_java_lang_reflect_VMField_getSignature(JNIEnv *env, jobject _this)
1107 java_lang_reflect_VMField rvmf(_this);
1108 fieldinfo* f = rvmf.get_field();
1110 if (f->signature == NULL)
1113 java_handle_t* o = javastring_new(f->signature);
1115 /* in error case o is NULL */
1121 #if defined(ENABLE_ANNOTATIONS)
1123 * Class: java/lang/reflect/VMField
1124 * Method: declaredAnnotations
1125 * Signature: ()Ljava/util/Map;
1127 JNIEXPORT jobject JNICALL Java_java_lang_reflect_VMField_declaredAnnotations(JNIEnv *env, jobject _this)
1129 java_lang_reflect_VMField rvmf(_this);
1131 java_handle_t* declaredAnnotations = rvmf.get_declaredAnnotations();
1133 // Are the annotations parsed yet?
1134 if (declaredAnnotations == NULL) {
1135 java_handle_bytearray_t* annotations = rvmf.get_annotations();
1136 classinfo* declaringClass = rvmf.get_clazz();
1139 LLNI_class_get(_this, referer);
1141 declaredAnnotations = Reflection::get_declaredannotations(annotations, declaringClass, referer);
1143 rvmf.set_declaredAnnotations(declaredAnnotations);
1146 return (jobject) declaredAnnotations;
1153 /* native methods implemented by this file ************************************/
1155 static const JNINativeMethod methods[] = {
1156 { (char*) "getModifiersInternal", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getModifiersInternal },
1157 { (char*) "getType", (char*) "()Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getType },
1158 { (char*) "get", (char*) "(Ljava/lang/Object;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_get },
1159 { (char*) "getBoolean", (char*) "(Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getBoolean },
1160 { (char*) "getByte", (char*) "(Ljava/lang/Object;)B", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getByte },
1161 { (char*) "getChar", (char*) "(Ljava/lang/Object;)C", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getChar },
1162 { (char*) "getShort", (char*) "(Ljava/lang/Object;)S", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getShort },
1163 { (char*) "getInt", (char*) "(Ljava/lang/Object;)I", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getInt },
1164 { (char*) "getLong", (char*) "(Ljava/lang/Object;)J", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getLong },
1165 { (char*) "getFloat", (char*) "(Ljava/lang/Object;)F", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getFloat },
1166 { (char*) "getDouble", (char*) "(Ljava/lang/Object;)D", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getDouble },
1167 { (char*) "set", (char*) "(Ljava/lang/Object;Ljava/lang/Object;)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_set },
1168 { (char*) "setBoolean", (char*) "(Ljava/lang/Object;Z)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setBoolean },
1169 { (char*) "setByte", (char*) "(Ljava/lang/Object;B)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setByte },
1170 { (char*) "setChar", (char*) "(Ljava/lang/Object;C)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setChar },
1171 { (char*) "setShort", (char*) "(Ljava/lang/Object;S)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setShort },
1172 { (char*) "setInt", (char*) "(Ljava/lang/Object;I)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setInt },
1173 { (char*) "setLong", (char*) "(Ljava/lang/Object;J)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setLong },
1174 { (char*) "setFloat", (char*) "(Ljava/lang/Object;F)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setFloat },
1175 { (char*) "setDouble", (char*) "(Ljava/lang/Object;D)V", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_setDouble },
1176 { (char*) "getSignature", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_getSignature },
1177 #if defined(ENABLE_ANNOTATIONS)
1178 { (char*) "declaredAnnotations", (char*) "()Ljava/util/Map;", (void*) (uintptr_t) &Java_java_lang_reflect_VMField_declaredAnnotations },
1183 /* _Jv_java_lang_reflect_VMField_init ******************************************
1185 Register native functions.
1187 *******************************************************************************/
1191 void _Jv_java_lang_reflect_VMField_init(void)
1195 u = utf_new_char("java/lang/reflect/VMField");
1197 native_method_register(u, methods, NATIVE_METHODS_COUNT);
1203 * These are local overrides for various environment variables in Emacs.
1204 * Please do not remove this and leave it at the end of the file, where
1205 * Emacs will automagically detect them.
1206 * ---------------------------------------------------------------------
1209 * indent-tabs-mode: t
1213 * vim:noexpandtab:sw=4:ts=4: