724cc14ba5ea9d0d640a3a2d9e2e03fee1836ff8
[cacao.git] / src / vmcore / method.h
1 /* src/vmcore/method.h - method functions header
2
3    Copyright (C) 1996-2005, 2006, 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    $Id: method.h 8343 2007-08-17 21:39:32Z michi $
26 */
27
28
29 #ifndef _METHOD_H
30 #define _METHOD_H
31
32 /* forward typedefs ***********************************************************/
33
34 typedef struct methodinfo          methodinfo; 
35 typedef struct raw_exception_entry raw_exception_entry;
36 typedef struct lineinfo            lineinfo; 
37 typedef struct method_assumption   method_assumption;
38 typedef struct method_worklist     method_worklist;
39 typedef struct codeinfo            codeinfo;
40
41 #include "config.h"
42 #include "vm/types.h"
43
44 #include "vm/global.h"
45
46 #include "vmcore/descriptor.h"
47 #include "vmcore/references.h"
48 #include "vmcore/linker.h"
49 #include "vmcore/loader.h"
50
51 #if defined(ENABLE_JAVASE)
52 # include "vmcore/stackmap.h"
53 #endif
54
55 #include "vmcore/utf8.h"
56
57
58 #if defined(ENABLE_REPLACEMENT)
59 /* Initial value for the hit countdown field of each method. */
60 #define METHOD_INITIAL_HIT_COUNTDOWN  1000
61 #endif
62
63
64 /* methodinfo *****************************************************************/
65
66 struct methodinfo {                 /* method structure                       */
67         java_object_t header;           /* we need this in jit's monitorenter     */
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    *class;            /* 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         u1           *stubroutine;      /* stub for compiling or calling natives  */
96         codeinfo     *code;             /* current code of this method            */
97
98 #if defined(ENABLE_LSRA)
99         s4            maxlifetimes;     /* helper for lsra                        */
100 #endif
101
102         methodinfo   *overwrites;       /* method that is directly overwritten    */
103         method_assumption *assumptions; /* list of assumptions about this method  */
104
105 #if defined(ENABLE_REPLACEMENT)
106         s4            hitcountdown;     /* decreased for each hit                 */
107 #endif
108
109 #if defined(ENABLE_DEBUG_FILTER)
110         u1            filtermatches;    /* flags indicating which filters the method matches */
111 #endif
112 };
113
114
115 /* method_assumption ***********************************************************
116
117    This struct is used for registering assumptions about methods.
118
119 *******************************************************************************/
120
121 struct method_assumption {
122         method_assumption *next;
123         methodinfo        *context;
124 };
125
126
127 /* method_worklist *************************************************************
128
129    List node used for method worklists.
130
131 *******************************************************************************/
132
133 struct method_worklist {
134         method_worklist *next;
135         methodinfo      *m;
136 };
137
138
139 /* raw_exception_entry ********************************************************/
140
141 /* exception table entry read by the loader */
142
143 struct raw_exception_entry {    /* exceptiontable entry in a method           */
144         classref_or_classinfo catchtype; /* catchtype of exc. (0 == catchall)     */
145         u2              startpc;    /* start pc of guarded area (inclusive)       */
146         u2              endpc;      /* end pc of guarded area (exklusive)         */
147         u2              handlerpc;  /* pc of exception handler                    */
148 };
149
150
151 /* lineinfo *******************************************************************/
152
153 struct lineinfo {
154         u2 start_pc;
155         u2 line_number;
156 };
157
158
159 /* function prototypes ********************************************************/
160
161 bool method_load(classbuffer *cb, methodinfo *m, descriptor_pool *descpool);
162 void method_free(methodinfo *m);
163 bool method_canoverwrite(methodinfo *m, methodinfo *old);
164
165 methodinfo *method_vftbl_lookup(vftbl_t *vftbl, methodinfo* m);
166
167 int32_t                    method_get_parametercount(methodinfo *m);
168 java_handle_objectarray_t *method_get_parametertypearray(methodinfo *m);
169 java_handle_objectarray_t *method_get_exceptionarray(methodinfo *m);
170 classinfo                 *method_returntype_get(methodinfo *m);
171
172 void method_add_assumption_monomorphic(methodinfo *m, methodinfo *caller);
173 void method_break_assumption_monomorphic(methodinfo *m, method_worklist **wl);
174
175 s4   method_count_implementations(methodinfo *m, classinfo *c, methodinfo **found);
176
177 java_handle_bytearray_t *method_get_annotations(methodinfo *m);
178 java_handle_bytearray_t *method_get_parameterannotations(methodinfo *m);
179 java_handle_bytearray_t *method_get_annotationdefault(methodinfo *m);
180
181 #if !defined(NDEBUG)
182 void method_printflags(methodinfo *m);
183 void method_print(methodinfo *m);
184 void method_println(methodinfo *m);
185 void method_methodref_print(constant_FMIref *mr);
186 void method_methodref_println(constant_FMIref *mr);
187 #endif
188
189 #endif /* _METHOD_H */
190
191
192 /*
193  * These are local overrides for various environment variables in Emacs.
194  * Please do not remove this and leave it at the end of the file, where
195  * Emacs will automagically detect them.
196  * ---------------------------------------------------------------------
197  * Local variables:
198  * mode: c
199  * indent-tabs-mode: t
200  * c-basic-offset: 4
201  * tab-width: 4
202  * End:
203  * vim:noexpandtab:sw=4:ts=4:
204  */