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