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