Merged revisions 8123-8136 via svnmerge from
[cacao.git] / src / native / vm / java_lang_reflect_Method.c
1 /* src/native/vm/java_lang_reflect_Method.c
2
3    Copyright (C) 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
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    $Id: java_lang_reflect_Method.c 8063 2007-06-11 14:44:58Z twisti $
26
27 */
28
29
30 #include "config.h"
31
32 #include <assert.h>
33
34 #include "vm/types.h"
35
36 #include "native/jni.h"
37 #include "native/native.h"
38
39 #include "native/include/java_lang_Object.h"
40
41 #include "native/include/java_lang_reflect_Method.h"
42
43 #include "vm/access.h"
44 #include "vm/builtin.h"
45 #include "vm/initialize.h"
46
47 #include "vmcore/class.h"
48 #include "vmcore/method.h"
49
50
51 /*
52  * Class:     java/lang/reflect/Method
53  * Method:    invoke
54  * Signature: (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
55  */
56 java_lang_Object *_Jv_java_lang_reflect_Method_invoke(java_lang_reflect_Method *this, java_lang_Object *o, java_objectarray *args)
57 {
58         classinfo  *c;
59         methodinfo *m;
60         s4          override;
61
62         c = (classinfo *) this->clazz;
63         m = &(c->methods[this->slot]);
64
65         /* check method access */
66
67         /* check if we should bypass security checks (AccessibleObject) */
68
69 #if defined(WITH_CLASSPATH_GNU)
70         override = this->flag;
71 #elif defined(WITH_CLASSPATH_SUN)
72         override = this->override;
73 #else
74 # error unknown classpath configuration
75 #endif
76
77         if (override == false) {
78                 if (!access_check_method(m, 1))
79                         return NULL;
80         }
81
82         /* check if method class is initialized */
83
84         if (!(c->state & CLASS_INITIALIZED))
85                 if (!initialize_class(c))
86                         return NULL;
87
88         /* call the Java method via a helper function */
89
90         return (java_lang_Object *) _Jv_jni_invokeNative(m, (java_objectheader *) o, args);
91 }
92
93
94 /*
95  * These are local overrides for various environment variables in Emacs.
96  * Please do not remove this and leave it at the end of the file, where
97  * Emacs will automagically detect them.
98  * ---------------------------------------------------------------------
99  * Local variables:
100  * mode: c
101  * indent-tabs-mode: t
102  * c-basic-offset: 4
103  * tab-width: 4
104  * End:
105  */