5d6e99c596b029c25d7af275e0a348fdddc39ecf
[cacao.git] / src / native / vm / java_lang_reflect_Method.c
1 /* src/native/vm/Method.c - java/lang/reflect/Method
2
3    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Roman Obermaiser
28
29    Changes: Joseph Wenninger
30             Christian Thalinger
31
32    $Id: java_lang_reflect_Method.c 5223 2006-08-08 16:21:22Z edwin $
33
34 */
35
36
37 #include "config.h"
38
39 #include <assert.h>
40
41 #include "vm/types.h"
42
43 #include "native/jni.h"
44 #include "native/native.h"
45 #include "native/include/java_lang_Object.h"
46 #include "native/include/java_lang_Class.h"
47 #include "native/include/java_lang_reflect_Method.h"
48 #include "vm/access.h"
49 #include "vm/global.h"
50 #include "vm/builtin.h"
51 #include "vm/exceptions.h"
52 #include "vm/initialize.h"
53 #include "vm/stringlocal.h"
54
55
56 /*
57  * Class:     java/lang/reflect/Method
58  * Method:    getModifiersInternal
59  * Signature: ()I
60  */
61 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiersInternal(JNIEnv *env, java_lang_reflect_Method *this)
62 {
63         classinfo  *c;
64         methodinfo *m;
65
66         c = (classinfo *) this->declaringClass;
67         m = &(c->methods[this->slot]);
68
69         return m->flags;
70 }
71
72
73 /*
74  * Class:     java/lang/reflect/Method
75  * Method:    getReturnType
76  * Signature: ()Ljava/lang/Class;
77  */
78 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
79 {
80         classinfo  *c;
81         methodinfo *m;
82
83         c = (classinfo *) this->declaringClass;
84         m = &(c->methods[this->slot]);
85
86         return (java_lang_Class *) native_get_returntype(m);
87 }
88
89
90 /*
91  * Class:     java/lang/reflect/Method
92  * Method:    getParameterTypes
93  * Signature: ()[Ljava/lang/Class;
94  */
95 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
96 {
97         classinfo  *c;
98         methodinfo *m;
99
100         c = (classinfo *) this->declaringClass;
101         m = &(c->methods[this->slot]);
102
103         return native_get_parametertypes(m);
104 }
105
106
107 /*
108  * Class:     java/lang/reflect/Method
109  * Method:    getExceptionTypes
110  * Signature: ()[Ljava/lang/Class;
111  */
112 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
113 {
114         classinfo  *c;
115         methodinfo *m;
116
117         c = (classinfo *) this->declaringClass;
118         m = &(c->methods[this->slot]);
119
120         return native_get_exceptiontypes(m);
121 }
122
123
124 /*
125  * Class:     java/lang/reflect/Method
126  * Method:    invokeNative
127  * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
128  */
129 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Method_invokeNative(JNIEnv *env, java_lang_reflect_Method *this, java_lang_Object *o, java_objectarray *args, java_lang_Class *declaringClass, s4 slot)
130 {
131         classinfo        *c;
132         methodinfo       *m;
133         java_objectarray *oa;
134         classinfo        *callerclass;
135
136         c = (classinfo *) declaringClass;
137         m = &(c->methods[slot]);
138
139         /* check method access */
140         /* check if we should bypass security checks (AccessibleObject) */
141
142         if (this->flag == false) {
143                 if (!access_check_caller(c, m->flags, 1))
144                         return NULL;
145         }
146
147         /* check if method class is initialized */
148
149         if (!(c->state & CLASS_INITIALIZED))
150                 if (!initialize_class(c))
151                         return NULL;
152
153         /* call the Java method via a helper function */
154
155         return (java_lang_Object *) _Jv_jni_invokeNative(m, (jobject) o, args);
156 }
157
158
159 /*
160  * These are local overrides for various environment variables in Emacs.
161  * Please do not remove this and leave it at the end of the file, where
162  * Emacs will automagically detect them.
163  * ---------------------------------------------------------------------
164  * Local variables:
165  * mode: c
166  * indent-tabs-mode: t
167  * c-basic-offset: 4
168  * tab-width: 4
169  * End:
170  */