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