1 /* src/native/vm/gnu/java_lang_reflect_Method.c
3 Copyright (C) 1996-2005, 2006, 2007 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
8 This file is part of CACAO.
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.
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.
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
25 $Id: java_lang_reflect_Method.c 8063 2007-06-11 14:44:58Z twisti $
36 #include "native/jni.h"
37 #include "native/native.h"
39 #include "native/include/java_lang_Object.h"
40 #include "native/include/java_lang_Class.h"
41 #include "native/include/java_lang_String.h"
43 #include "native/include/java_lang_reflect_Method.h"
45 #include "vm/access.h"
46 #include "vm/global.h"
47 #include "vm/builtin.h"
48 #include "vm/exceptions.h"
49 #include "vm/initialize.h"
50 #include "vm/resolve.h"
51 #include "vm/stringlocal.h"
53 #include "vmcore/method.h"
56 /* native methods implemented by this file ************************************/
58 static JNINativeMethod methods[] = {
59 { "getModifiersInternal", "()I", (void *) (ptrint) &Java_java_lang_reflect_Method_getModifiersInternal },
60 { "getReturnType", "()Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getReturnType },
61 { "getParameterTypes", "()[Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getParameterTypes },
62 { "getExceptionTypes", "()[Ljava/lang/Class;", (void *) (ptrint) &Java_java_lang_reflect_Method_getExceptionTypes },
63 { "invokeNative", "(Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Method_invokeNative },
64 { "getSignature", "()Ljava/lang/String;", (void *) (ptrint) &Java_java_lang_reflect_Method_getSignature },
68 /* _Jv_java_lang_reflect_Method_init *******************************************
70 Register native functions.
72 *******************************************************************************/
74 void _Jv_java_lang_reflect_Method_init(void)
78 u = utf_new_char("java/lang/reflect/Method");
80 native_method_register(u, methods, NATIVE_METHODS_COUNT);
85 * Class: java/lang/reflect/Method
86 * Method: getModifiersInternal
89 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiersInternal(JNIEnv *env, java_lang_reflect_Method *this)
94 c = (classinfo *) this->declaringClass;
95 m = &(c->methods[this->slot]);
102 * Class: java/lang/reflect/Method
103 * Method: getReturnType
104 * Signature: ()Ljava/lang/Class;
106 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
112 c = (classinfo *) this->declaringClass;
113 m = &(c->methods[this->slot]);
115 result = method_returntype_get(m);
117 return (java_lang_Class *) result;
122 * Class: java/lang/reflect/Method
123 * Method: getParameterTypes
124 * Signature: ()[Ljava/lang/Class;
126 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
131 c = (classinfo *) this->declaringClass;
132 m = &(c->methods[this->slot]);
134 return method_get_parametertypearray(m);
139 * Class: java/lang/reflect/Method
140 * Method: getExceptionTypes
141 * Signature: ()[Ljava/lang/Class;
143 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
148 c = (classinfo *) this->declaringClass;
149 m = &(c->methods[this->slot]);
151 return method_get_exceptionarray(m);
156 * Class: java/lang/reflect/Method
157 * Method: invokeNative
158 * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
160 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)
165 c = (classinfo *) declaringClass;
166 m = &(c->methods[slot]);
168 /* check method access */
170 /* check if we should bypass security checks (AccessibleObject) */
172 if (this->flag == false) {
173 if (!access_check_method(m, 1))
177 /* check if method class is initialized */
179 if (!(c->state & CLASS_INITIALIZED))
180 if (!initialize_class(c))
183 /* call the Java method via a helper function */
185 return (java_lang_Object *) _Jv_jni_invokeNative(m, (jobject) o, args);
190 * Class: java/lang/reflect/Method
191 * Method: getSignature
192 * Signature: ()Ljava/lang/String;
194 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Method_getSignature(JNIEnv *env, java_lang_reflect_Method* this)
198 java_objectheader *o;
200 c = (classinfo *) this->declaringClass;
201 m = &(c->methods[this->slot]);
203 if (m->signature == NULL)
206 o = javastring_new(m->signature);
208 /* in error case o is NULL */
210 return (java_lang_String *) o;
215 * These are local overrides for various environment variables in Emacs.
216 * Please do not remove this and leave it at the end of the file, where
217 * Emacs will automagically detect them.
218 * ---------------------------------------------------------------------
221 * indent-tabs-mode: t