* src/vm/method.cpp (method_load): Loads LocalVariableTable attribute.
[cacao.git] / src / vm / method.hpp
1 /* src/vm/method.hpp - 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 /* forward typedefs ***********************************************************/
30
31 typedef struct methodinfo          methodinfo; 
32 typedef struct raw_exception_entry raw_exception_entry;
33 typedef struct lineinfo            lineinfo;
34 typedef struct localvarinfo        localvarinfo;
35 typedef struct method_assumption   method_assumption;
36 typedef struct method_worklist     method_worklist;
37 typedef struct codeinfo            codeinfo;
38
39 #include "config.h"
40 #include "vm/types.h"
41
42 #include "threads/mutex.hpp"
43
44 #include "vm/breakpoint.hpp"
45 #include "vm/jit/builtin.hpp"
46 #include "vm/descriptor.hpp"
47 #include "vm/global.h"
48 #include "vm/linker.hpp"
49 #include "vm/loader.hpp"
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 /* methodinfo *****************************************************************/
65
66 struct methodinfo {                 /* method structure                       */
67         Mutex        *mutex;            /* we need this in jit's locking          */
68         s4            flags;            /* ACC flags                              */
69         utf          *name;             /* name of method                         */
70         utf          *descriptor;       /* JavaVM descriptor string of method     */
71 #if defined(ENABLE_JAVASE)
72         utf          *signature;        /* Signature attribute                    */
73         stack_map_t  *stack_map;        /* StackMapTable attribute                */
74 #endif
75
76         methoddesc   *parseddesc;       /* parsed descriptor                      */
77
78         classinfo    *clazz;            /* class, the method belongs to           */
79         s4            vftblindex;       /* index of method in virtual function    */
80                                         /* table (if it is a virtual method)      */
81         s4            maxstack;         /* maximum stack depth of method          */
82         s4            maxlocals;        /* maximum number of local variables      */
83         s4            jcodelength;      /* length of JavaVM code                  */
84         u1           *jcode;            /* pointer to JavaVM code                 */
85
86         s4            rawexceptiontablelength;  /* exceptiontable length          */
87         raw_exception_entry *rawexceptiontable; /* the exceptiontable             */
88
89         u2            thrownexceptionscount; /* number of exceptions attribute    */
90         classref_or_classinfo *thrownexceptions; /* except. a method may throw    */
91
92         u2            linenumbercount;  /* number of linenumber attributes        */
93         lineinfo     *linenumbers;      /* array of lineinfo items                */
94
95 #if defined(ENABLE_JAVASE) && defined(ENABLE_JVMTI)
96         uint16_t      localvarcount;    /* number of local variable attributes    */
97         localvarinfo* localvars;        /* array of localvarinfo items            */
98 #endif
99
100         u1           *stubroutine;      /* stub for compiling or calling natives  */
101         codeinfo     *code;             /* current code of this method            */
102
103 #if defined(ENABLE_LSRA)
104         s4            maxlifetimes;     /* helper for lsra                        */
105 #endif
106
107         methodinfo   *overwrites;       /* method that is directly overwritten    */
108         method_assumption *assumptions; /* list of assumptions about this method  */
109
110         BreakpointTable* breakpoints;   /* breakpoints in this method             */
111
112 #if defined(ENABLE_REPLACEMENT)
113         s4            hitcountdown;     /* decreased for each hit                 */
114 #endif
115
116 #if defined(ENABLE_DEBUG_FILTER)
117         u1            filtermatches;    /* flags indicating which filters the method matches */
118 #endif
119
120 #if defined(ENABLE_ESCAPE)
121         u1           *paramescape;
122 #endif
123 };
124
125 /* method_assumption ***********************************************************
126
127    This struct is used for registering assumptions about methods.
128
129 *******************************************************************************/
130
131 struct method_assumption {
132         method_assumption *next;
133         methodinfo        *context;
134 };
135
136
137 /* method_worklist *************************************************************
138
139    List node used for method worklists.
140
141 *******************************************************************************/
142
143 struct method_worklist {
144         method_worklist *next;
145         methodinfo      *m;
146 };
147
148
149 /* raw_exception_entry ********************************************************/
150
151 /* exception table entry read by the loader */
152
153 struct raw_exception_entry {    /* exceptiontable entry in a method           */
154         classref_or_classinfo catchtype; /* catchtype of exc. (0 == catchall)     */
155         u2              startpc;    /* start pc of guarded area (inclusive)       */
156         u2              endpc;      /* end pc of guarded area (exklusive)         */
157         u2              handlerpc;  /* pc of exception handler                    */
158 };
159
160
161 /* lineinfo *******************************************************************/
162
163 struct lineinfo {
164         u2 start_pc;
165         u2 line_number;
166 };
167
168
169 /* localvarinfo ***************************************************************/
170
171 struct localvarinfo {
172         uint16_t start_pc;
173         uint16_t length;
174         utf*     name;
175         utf*     descriptor;
176         uint16_t index;
177 };
178
179
180 /* global variables ***********************************************************/
181
182 extern methodinfo *method_java_lang_reflect_Method_invoke;
183
184
185 #ifdef __cplusplus
186 extern "C" {
187 #endif
188
189 /* inline functions ***********************************************************/
190
191 inline static bool method_is_builtin(methodinfo* m)
192 {
193         return m->flags & ACC_METHOD_BUILTIN;
194 }
195
196
197 /* function prototypes ********************************************************/
198
199 void method_init(void);
200
201 bool method_load(classbuffer *cb, methodinfo *m, descriptor_pool *descpool);
202 void method_free(methodinfo *m);
203 bool method_canoverwrite(methodinfo *m, methodinfo *old);
204
205 methodinfo *method_new_builtin(builtintable_entry *bte);
206
207 methodinfo *method_vftbl_lookup(vftbl_t *vftbl, methodinfo* m);
208
209 int32_t                    method_get_parametercount(methodinfo *m);
210 java_handle_objectarray_t *method_get_parametertypearray(methodinfo *m);
211 java_handle_objectarray_t *method_get_exceptionarray(methodinfo *m);
212 classinfo                 *method_returntype_get(methodinfo *m);
213
214 void method_add_assumption_monomorphic(methodinfo *m, methodinfo *caller);
215 void method_break_assumption_monomorphic(methodinfo *m, method_worklist **wl);
216
217 s4   method_count_implementations(methodinfo *m, classinfo *c, methodinfo **found);
218
219 java_handle_bytearray_t *method_get_annotations(methodinfo *m);
220 java_handle_bytearray_t *method_get_parameterannotations(methodinfo *m);
221 java_handle_bytearray_t *method_get_annotationdefault(methodinfo *m);
222
223 #if !defined(NDEBUG)
224 void method_printflags(methodinfo *m);
225 void method_print(methodinfo *m);
226 void method_println(methodinfo *m);
227 void method_methodref_print(constant_FMIref *mr);
228 void method_methodref_println(constant_FMIref *mr);
229 #endif
230
231 #ifdef __cplusplus
232 }
233 #endif
234
235 #endif /* _METHOD_H */
236
237
238 /*
239  * These are local overrides for various environment variables in Emacs.
240  * Please do not remove this and leave it at the end of the file, where
241  * Emacs will automagically detect them.
242  * ---------------------------------------------------------------------
243  * Local variables:
244  * mode: c++
245  * indent-tabs-mode: t
246  * c-basic-offset: 4
247  * tab-width: 4
248  * End:
249  * vim:noexpandtab:sw=4:ts=4:
250  */