Fixes PR84 for arm.
[cacao.git] / src / vm / method.h
1 /* src/vm/method.h - method functions header
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _METHOD_H
27 #define _METHOD_H
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /* forward typedefs ***********************************************************/
34
35 typedef struct methodinfo          methodinfo; 
36 typedef struct raw_exception_entry raw_exception_entry;
37 typedef struct lineinfo            lineinfo; 
38 typedef struct method_assumption   method_assumption;
39 typedef struct method_worklist     method_worklist;
40 typedef struct codeinfo            codeinfo;
41
42 #include "config.h"
43 #include "vm/types.h"
44
45 #include "vm/builtin.h"
46 #include "vm/descriptor.h"
47 #include "vm/global.h"
48 #include "vm/linker.h"
49 #include "vm/loader.h"
50 #include "vm/references.h"
51
52 #if defined(ENABLE_JAVASE)
53 # include "vm/stackmap.h"
54 #endif
55
56 #include "vm/utf8.h"
57
58
59 #if defined(ENABLE_REPLACEMENT)
60 /* Initial value for the hit countdown field of each method. */
61 #define METHOD_INITIAL_HIT_COUNTDOWN  1000
62 #endif
63
64
65 /* methodinfo *****************************************************************/
66
67 struct methodinfo {                 /* method structure                       */
68         java_object_t header;           /* we need this in jit's monitorenter     */
69         s4            flags;            /* ACC flags                              */
70         utf          *name;             /* name of method                         */
71         utf          *descriptor;       /* JavaVM descriptor string of method     */
72 #if defined(ENABLE_JAVASE)
73         utf          *signature;        /* Signature attribute                    */
74         stack_map_t  *stack_map;        /* StackMapTable attribute                */
75 #endif
76
77         methoddesc   *parseddesc;       /* parsed descriptor                      */
78                              
79         classinfo    *clazz;            /* class, the method belongs to           */
80         s4            vftblindex;       /* index of method in virtual function    */
81                                         /* table (if it is a virtual method)      */
82         s4            maxstack;         /* maximum stack depth of method          */
83         s4            maxlocals;        /* maximum number of local variables      */
84         s4            jcodelength;      /* length of JavaVM code                  */
85         u1           *jcode;            /* pointer to JavaVM code                 */
86
87         s4            rawexceptiontablelength;  /* exceptiontable length          */
88         raw_exception_entry *rawexceptiontable; /* the exceptiontable             */
89
90         u2            thrownexceptionscount; /* number of exceptions attribute    */
91         classref_or_classinfo *thrownexceptions; /* except. a method may throw    */
92
93         u2            linenumbercount;  /* number of linenumber attributes        */
94         lineinfo     *linenumbers;      /* array of lineinfo items                */
95
96         u1           *stubroutine;      /* stub for compiling or calling natives  */
97         codeinfo     *code;             /* current code of this method            */
98
99 #if defined(ENABLE_LSRA)
100         s4            maxlifetimes;     /* helper for lsra                        */
101 #endif
102
103         methodinfo   *overwrites;       /* method that is directly overwritten    */
104         method_assumption *assumptions; /* list of assumptions about this method  */
105
106 #if defined(ENABLE_REPLACEMENT)
107         s4            hitcountdown;     /* decreased for each hit                 */
108 #endif
109
110 #if defined(ENABLE_DEBUG_FILTER)
111         u1            filtermatches;    /* flags indicating which filters the method matches */
112 #endif
113
114 #if defined(ENABLE_ESCAPE)
115         u1           *paramescape;
116 #endif
117 };
118
119 /* method_assumption ***********************************************************
120
121    This struct is used for registering assumptions about methods.
122
123 *******************************************************************************/
124
125 struct method_assumption {
126         method_assumption *next;
127         methodinfo        *context;
128 };
129
130
131 /* method_worklist *************************************************************
132
133    List node used for method worklists.
134
135 *******************************************************************************/
136
137 struct method_worklist {
138         method_worklist *next;
139         methodinfo      *m;
140 };
141
142
143 /* raw_exception_entry ********************************************************/
144
145 /* exception table entry read by the loader */
146
147 struct raw_exception_entry {    /* exceptiontable entry in a method           */
148         classref_or_classinfo catchtype; /* catchtype of exc. (0 == catchall)     */
149         u2              startpc;    /* start pc of guarded area (inclusive)       */
150         u2              endpc;      /* end pc of guarded area (exklusive)         */
151         u2              handlerpc;  /* pc of exception handler                    */
152 };
153
154
155 /* lineinfo *******************************************************************/
156
157 struct lineinfo {
158         u2 start_pc;
159         u2 line_number;
160 };
161
162
163 /* global variables ***********************************************************/
164
165 extern methodinfo *method_java_lang_reflect_Method_invoke;
166
167
168 /* inline functions ***********************************************************/
169
170 inline static bool method_is_builtin(methodinfo* m)
171 {
172         return m->flags & ACC_METHOD_BUILTIN;
173 }
174
175
176 /* function prototypes ********************************************************/
177
178 void method_init(void);
179
180 bool method_load(classbuffer *cb, methodinfo *m, descriptor_pool *descpool);
181 void method_free(methodinfo *m);
182 bool method_canoverwrite(methodinfo *m, methodinfo *old);
183
184 methodinfo *method_new_builtin(builtintable_entry *bte);
185
186 methodinfo *method_vftbl_lookup(vftbl_t *vftbl, methodinfo* m);
187
188 int32_t                    method_get_parametercount(methodinfo *m);
189 java_handle_objectarray_t *method_get_parametertypearray(methodinfo *m);
190 java_handle_objectarray_t *method_get_exceptionarray(methodinfo *m);
191 classinfo                 *method_returntype_get(methodinfo *m);
192
193 void method_add_assumption_monomorphic(methodinfo *m, methodinfo *caller);
194 void method_break_assumption_monomorphic(methodinfo *m, method_worklist **wl);
195
196 s4   method_count_implementations(methodinfo *m, classinfo *c, methodinfo **found);
197
198 java_handle_bytearray_t *method_get_annotations(methodinfo *m);
199 java_handle_bytearray_t *method_get_parameterannotations(methodinfo *m);
200 java_handle_bytearray_t *method_get_annotationdefault(methodinfo *m);
201
202 #if !defined(NDEBUG)
203 void method_printflags(methodinfo *m);
204 void method_print(methodinfo *m);
205 void method_println(methodinfo *m);
206 void method_methodref_print(constant_FMIref *mr);
207 void method_methodref_println(constant_FMIref *mr);
208 #endif
209
210 #ifdef __cplusplus
211 }
212 #endif
213
214 #endif /* _METHOD_H */
215
216
217 /*
218  * These are local overrides for various environment variables in Emacs.
219  * Please do not remove this and leave it at the end of the file, where
220  * Emacs will automagically detect them.
221  * ---------------------------------------------------------------------
222  * Local variables:
223  * mode: c
224  * indent-tabs-mode: t
225  * c-basic-offset: 4
226  * tab-width: 4
227  * End:
228  * vim:noexpandtab:sw=4:ts=4:
229  */