1 /* src/native/vm/Method.c - java/lang/reflect/Method
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Roman Obermaiser
29 Changes: Joseph Wenninger
32 $Id: Method.c 4331 2006-01-20 14:49:53Z twisti $
41 #include "native/jni.h"
42 #include "native/native.h"
43 #include "native/include/java_lang_Object.h"
44 #include "native/include/java_lang_Class.h"
45 #include "native/include/java_lang_reflect_Method.h"
46 #include "toolbox/logging.h"
47 #include "vm/access.h"
48 #include "vm/global.h"
49 #include "vm/builtin.h"
50 #include "vm/exceptions.h"
51 #include "vm/initialize.h"
52 #include "vm/stringlocal.h"
53 #include "vm/jit/stacktrace.h"
57 * Class: java/lang/reflect/Method
58 * Method: getModifiers
61 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiers(JNIEnv *env, java_lang_reflect_Method *this)
66 c = (classinfo *) this->declaringClass;
67 m = &(c->methods[this->slot]);
70 (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED | ACC_ABSTRACT |
71 ACC_STATIC | ACC_FINAL | ACC_SYNCHRONIZED | ACC_NATIVE |
77 * Class: java/lang/reflect/Method
78 * Method: getReturnType
79 * Signature: ()Ljava/lang/Class;
81 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
86 c = (classinfo *) this->declaringClass;
87 m = &(c->methods[this->slot]);
89 return (java_lang_Class *) native_get_returntype(m);
94 * Class: java/lang/reflect/Method
95 * Method: getParameterTypes
96 * Signature: ()[Ljava/lang/Class;
98 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
103 c = (classinfo *) this->declaringClass;
104 m = &(c->methods[this->slot]);
106 return native_get_parametertypes(m);
111 * Class: java/lang/reflect/Method
112 * Method: getExceptionTypes
113 * Signature: ()[Ljava/lang/Class;
115 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
120 c = (classinfo *) this->declaringClass;
121 m = &(c->methods[this->slot]);
123 return native_get_exceptiontypes(m);
128 * Class: java/lang/reflect/Method
129 * Method: invokeNative
130 * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
132 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)
136 java_objectarray *oa;
137 classinfo *callerclass;
139 c = (classinfo *) declaringClass;
140 m = &(c->methods[slot]);
142 /* check method access */
144 if (!(m->flags & ACC_PUBLIC) || !(c->flags & ACC_PUBLIC)) {
145 /* check if we should bypass security checks (AccessibleObject) */
147 if (this->flag == false) {
148 /* get the calling class */
150 oa = cacao_createClassContextArray();
152 /* this function is always called like this:
154 java.lang.reflect.Method.invokeNative (Native Method)
155 [0] java.lang.reflect.Method.invoke (Method.java:329)
159 callerclass = (classinfo *) oa->data[1];
161 if (!access_is_accessible_class(callerclass,c)
162 || !access_is_accessible_member(callerclass, c, m->flags))
165 new_exception(string_java_lang_IllegalAccessException);
171 /* check if method class is initialized */
173 if (!(c->state & CLASS_INITIALIZED))
174 if (!initialize_class(c))
177 /* call the Java method via a helper function */
179 return (java_lang_Object *) _Jv_jni_invokeNative(m, (jobject) o, args);
184 * These are local overrides for various environment variables in Emacs.
185 * Please do not remove this and leave it at the end of the file, where
186 * Emacs will automagically detect them.
187 * ---------------------------------------------------------------------
190 * indent-tabs-mode: t