1 /* 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
31 $Id: Method.c 1801 2004-12-21 20:19:19Z jowenn $
37 #include "native/jni.h"
38 #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_reflect_Method.h"
42 #include "toolbox/logging.h"
43 #include "vm/global.h"
44 #include "vm/builtin.h"
45 #include "vm/jit/stacktrace.h"
46 #include "vm/exceptions.h"
49 * Class: java_lang_reflect_Method
50 * Method: getModifiers
53 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Method_getModifiers(JNIEnv *env, java_lang_reflect_Method *this)
55 classinfo *c = (classinfo *) this->declaringClass;
57 if (this->slot < 0 || this->slot >= c->methodscount)
58 panic("error illegal slot for method in class (getReturnType)");
60 return (c->methods[this->slot]).flags &
61 (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED | ACC_ABSTRACT | ACC_STATIC | ACC_FINAL |
62 ACC_SYNCHRONIZED | ACC_NATIVE | ACC_STRICT);
67 * Class: java_lang_reflect_Method
68 * Method: getReturnType
69 * Signature: ()Ljava/lang/Class;
71 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_reflect_Method_getReturnType(JNIEnv *env, java_lang_reflect_Method *this)
73 classinfo *c = (classinfo *) this->declaringClass;
75 if (this->slot < 0 || this->slot >= c->methodscount)
76 panic("error illegal slot for method in class (getReturnType)");
78 return (java_lang_Class *) get_returntype(&(c->methods[this->slot]));
83 * Class: java_lang_reflect_Method
84 * Method: getParameterTypes
85 * Signature: ()[Ljava/lang/Class;
87 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getParameterTypes(JNIEnv *env, java_lang_reflect_Method *this)
89 classinfo *c = (classinfo *) this->declaringClass;
91 if (this->slot < 0 || this->slot >= c->methodscount)
92 panic("error illegal slot for method in class(getParameterTypes)");
94 return get_parametertypes(&(c->methods[this->slot]));
99 * Class: java_lang_reflect_Method
100 * Method: getExceptionTypes
101 * Signature: ()[Ljava/lang/Class;
103 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Method_getExceptionTypes(JNIEnv *env, java_lang_reflect_Method *this)
105 classinfo *c = (classinfo *) this->declaringClass;
107 if (this->slot < 0 || this->slot >= c->methodscount)
108 panic("error illegal slot for method in class(getExceptionTypes)");
110 return get_exceptiontypes(&(c->methods[this->slot]));
116 * Class: java_lang_reflect_Method
117 * Method: invokeNative
118 * Signature: (Ljava/lang/Object;[Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
120 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Method_invokeNative(JNIEnv *env, java_lang_reflect_Method *this, java_lang_Object *obj, java_objectarray *params, java_lang_Class *declaringClass, s4 slot)
122 struct methodinfo *mi;
124 classinfo *c = (classinfo *) declaringClass;
126 if (slot < 0 || slot >= c->methodscount) {
127 panic("error illegal slot for method in class(getParameterTypes)");
129 mi = &(c->methods[slot]);
131 #if (defined(__ALPHA__) || defined(__I386__))
132 /*log_text("Checking access rights");*/
133 if (!(getField(this,jboolean,getFieldID_critical(env,this->header.vftbl->class,"flag","Z")))) {
135 struct methodinfo *callingMethod;
137 if ((mi->flags & ACC_PUBLIC)==0) {
138 callingMethod=cacao_callingMethod();
139 if ((mi->flags & ACC_PRIVATE)!=0) {
140 if (c!=callingMethod->class) {
144 if ((mi->flags & ACC_PROTECTED)!=0) {
145 if (!builtin_isanysubclass(callingMethod->class, c)) {
149 /* default visibility*/
150 if (c->packagename!=callingMethod->class->packagename) {
158 *exceptionptr = new_exception(string_java_lang_IllegalAccessException);
166 return (java_lang_Object *) jni_method_invokeNativeHelper(env, mi, (jobject) obj, params);
171 * These are local overrides for various environment variables in Emacs.
172 * Please do not remove this and leave it at the end of the file, where
173 * Emacs will automagically detect them.
174 * ---------------------------------------------------------------------
177 * indent-tabs-mode: t