* src/mm/dumpmemory.c: Moved to .cpp.
[cacao.git] / src / vm / resolve.h
1 /* src/vm/resolve.h - resolving classes/interfaces/fields/methods
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 _RESOLVE_H
27 #define _RESOLVE_H
28
29 /* forward declarations *******************************************************/
30
31 typedef struct unresolved_class unresolved_class;
32 typedef struct unresolved_field unresolved_field;
33 typedef struct unresolved_method unresolved_method;
34 typedef struct unresolved_subtype_set unresolved_subtype_set;
35
36
37 #include "config.h"
38 #include "vm/types.h"
39
40 #include "vm/class.h"
41 #include "vm/field.h"
42 #include "vm/global.h"
43 #include "vm/method.h"
44 #include "vm/references.h"
45
46 #include "vm/jit/jit.hpp"
47 #include "vm/jit/reg.h"
48
49 #include "vm/jit/ir/instruction.hpp"
50 #include "vm/jit/verify/typeinfo.h"
51
52
53 /* constants ******************************************************************/
54
55 #define RESOLVE_STATIC    0x0001  /* ref to static fields/methods             */
56 #define RESOLVE_PUTFIELD  0x0002  /* field ref inside a PUT{FIELD,STATIC}...  */
57 #define RESOLVE_SPECIAL   0x0004  /* method ref inside INVOKESPECIAL          */
58
59
60 /* enums **********************************************************************/
61
62 typedef enum {
63         resolveLazy,
64         resolveEager
65 } resolve_mode_t;
66
67 typedef enum {
68         resolveLinkageError,
69         resolveIllegalAccessError
70 } resolve_err_t;
71
72 typedef enum {
73         resolveFailed = false,  /* this must be a false value */
74         resolveDeferred = true, /* this must be a true value  */
75         resolveSucceeded
76 } resolve_result_t;
77
78 /* structs ********************************************************************/
79
80 struct unresolved_subtype_set {
81         classref_or_classinfo *subtyperefs;     /* NULL terminated list */
82 };
83
84 struct unresolved_class {
85         constant_classref      *classref;
86         methodinfo                     *referermethod;
87         unresolved_subtype_set  subtypeconstraints;
88 };
89
90 /* XXX unify heads of unresolved_field and unresolved_method? */
91
92 struct unresolved_field {
93         constant_FMIref *fieldref;
94         methodinfo      *referermethod;
95         s4               flags;
96         
97         unresolved_subtype_set  instancetypes;
98         unresolved_subtype_set  valueconstraints;
99 };
100
101 struct unresolved_method {
102         constant_FMIref *methodref;
103         methodinfo      *referermethod;
104         s4               flags;
105         
106         unresolved_subtype_set  instancetypes;
107         unresolved_subtype_set *paramconstraints;
108 };
109
110 #define SUBTYPESET_IS_EMPTY(stset) \
111         ((stset).subtyperefs == NULL)
112
113 #define UNRESOLVED_SUBTYPE_SET_EMTPY(stset) \
114         do { (stset).subtyperefs = NULL; } while(0)
115
116
117 /* function prototypes ********************************************************/
118
119 #ifdef __cplusplus
120 extern "C" {
121 #endif
122
123 void resolve_handle_pending_exception(bool throwError);
124
125 bool resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
126                                                 utf *classname,
127                                                 resolve_mode_t mode,
128                                                 bool checkaccess,
129                                                 bool link,
130                                                 classinfo **result);
131
132 bool resolve_classref(methodinfo *refmethod,
133                                  constant_classref *ref,
134                                  resolve_mode_t mode,
135                                  bool checkaccess,
136                              bool link,
137                                  classinfo **result);
138
139 bool resolve_classref_or_classinfo(methodinfo *refmethod,
140                                                           classref_or_classinfo cls,
141                                                           resolve_mode_t mode,
142                                                           bool checkaccess,
143                                                           bool link,
144                                                           classinfo **result);
145
146 classinfo *resolve_classref_or_classinfo_eager(classref_or_classinfo cls, bool checkaccess);
147
148 bool resolve_class_from_typedesc(typedesc *d,bool checkaccess,bool link,classinfo **result);
149
150 #ifdef ENABLE_VERIFIER
151 bool resolve_class(unresolved_class *ref,
152                           resolve_mode_t mode,
153                           bool checkaccess,
154                           classinfo **result);
155
156 classinfo * resolve_class_eager(unresolved_class *ref);
157 classinfo * resolve_class_eager_no_access_check(unresolved_class *ref);
158 #endif /* ENABLE_VERIFIER */
159
160 bool resolve_field(unresolved_field *ref,
161                           resolve_mode_t mode,
162                           fieldinfo **result);
163
164 bool resolve_method(unresolved_method *ref,
165                           resolve_mode_t mode,
166                            methodinfo **result);
167
168 classinfo * resolve_classref_eager(constant_classref *ref);
169 classinfo * resolve_classref_eager_nonabstract(constant_classref *ref);
170 fieldinfo * resolve_field_eager(unresolved_field *ref);
171 methodinfo * resolve_method_eager(unresolved_method *ref);
172
173 #ifdef ENABLE_VERIFIER
174 unresolved_class * create_unresolved_class(methodinfo *refmethod,
175                                                 constant_classref *classref,
176                                                 typeinfo_t *valuetype);
177 #endif
178
179 unresolved_field *resolve_create_unresolved_field(classinfo *referer,
180                                                                                           methodinfo *refmethod,
181                                                                                           instruction *iptr);
182
183 unresolved_method * resolve_create_unresolved_method(classinfo *referer,
184                                                                                                          methodinfo *refmethod,
185                                                                                                          constant_FMIref *methodref,
186                                                                                                          bool invokestatic,
187                                                                                                          bool invokespecial);
188
189 void unresolved_class_free(unresolved_class *ref);
190 void unresolved_field_free(unresolved_field *ref);
191 void unresolved_method_free(unresolved_method *ref);
192
193 resolve_result_t resolve_method_lazy(methodinfo *refmethod,
194                                                                          constant_FMIref *methodref,
195                                                                          bool invokespecial);
196
197 resolve_result_t resolve_field_lazy(methodinfo *refmethod,
198                                                                         constant_FMIref *fieldref);
199
200 #if defined(ENABLE_VERIFIER)
201 resolve_result_t resolve_field_verifier_checks(methodinfo *refmethod,
202                                                                                            constant_FMIref *fieldref,
203                                                                                            classinfo *container,
204                                                                                            fieldinfo *fi,
205                                                                                            typeinfo_t *instanceti,
206                                                                                            typeinfo_t *valueti,
207                                                                                            bool isstatic,
208                                                                                            bool isput);
209
210 bool resolve_constrain_unresolved_field(unresolved_field *ref,
211                                                                                 classinfo *referer, 
212                                                                                 methodinfo *refmethod,
213                                                                             typeinfo_t *instanceti,
214                                                                             typeinfo_t *valueti);
215
216 resolve_result_t resolve_method_verifier_checks(methodinfo *refmethod,
217                                                                                                 constant_FMIref *methodref,
218                                                                                                 methodinfo *mi,
219                                                                                                 bool invokestatic);
220
221 resolve_result_t resolve_method_instance_type_checks(methodinfo *refmethod,
222                                                                                                          methodinfo *mi,
223                                                                                                          typeinfo_t *instanceti,
224                                                                                                          bool invokespecial);
225
226 resolve_result_t resolve_method_param_type_checks(jitdata *jd, 
227                                                                                                   methodinfo *refmethod,
228                                                                                                   instruction *iptr, 
229                                                                                                   methodinfo *mi,
230                                                                                                   bool invokestatic);
231
232 resolve_result_t resolve_method_param_type_checks_stackbased(
233                 methodinfo *refmethod, 
234                 methodinfo *mi,
235                 bool invokestatic, 
236                 typedescriptor_t *stack);
237
238 bool resolve_method_loading_constraints(classinfo *referer,
239                                                                                 methodinfo *mi);
240
241 bool resolve_constrain_unresolved_method_instance(unresolved_method *ref,
242                                                                                                   methodinfo *refmethod,
243                                                                                                   typeinfo_t *instanceti,
244                                                                                                   bool invokespecial);
245
246 bool resolve_constrain_unresolved_method_params(jitdata *jd,
247                                                                                                 unresolved_method *ref,
248                                                                                                 methodinfo *refmethod,
249                                                                                                 instruction *iptr);
250
251 bool resolve_constrain_unresolved_method_params_stackbased(
252                 unresolved_method *ref,
253                 methodinfo *refmethod,
254                 typedescriptor_t *stack);
255
256 #endif /* defined(ENABLE_VERIFIER) */
257
258 #ifndef NDEBUG
259 void unresolved_class_debug_dump(unresolved_class *ref,FILE *file);
260 void unresolved_field_debug_dump(unresolved_field *ref,FILE *file);
261 void unresolved_method_debug_dump(unresolved_method *ref,FILE *file);
262 void unresolved_subtype_set_debug_dump(unresolved_subtype_set *stset,FILE *file);
263 #endif
264
265 #ifdef __cplusplus
266 }
267 #endif
268         
269 #endif /* _RESOLVE_H */
270
271 /*
272  * These are local overrides for various environment variables in Emacs.
273  * Please do not remove this and leave it at the end of the file, where
274  * Emacs will automagically detect them.
275  * ---------------------------------------------------------------------
276  * Local variables:
277  * mode: c
278  * indent-tabs-mode: t
279  * c-basic-offset: 4
280  * tab-width: 4
281  * End:
282  * vim:noexpandtab:sw=4:ts=4:
283  */
284