* src/vm/jit/jit.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 void resolve_handle_pending_exception(bool throwError);
120
121 bool resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
122                                                 utf *classname,
123                                                 resolve_mode_t mode,
124                                                 bool checkaccess,
125                                                 bool link,
126                                                 classinfo **result);
127
128 bool resolve_classref(methodinfo *refmethod,
129                                  constant_classref *ref,
130                                  resolve_mode_t mode,
131                                  bool checkaccess,
132                              bool link,
133                                  classinfo **result);
134
135 bool resolve_classref_or_classinfo(methodinfo *refmethod,
136                                                           classref_or_classinfo cls,
137                                                           resolve_mode_t mode,
138                                                           bool checkaccess,
139                                                           bool link,
140                                                           classinfo **result);
141
142 classinfo *resolve_classref_or_classinfo_eager(classref_or_classinfo cls, bool checkaccess);
143
144 bool resolve_class_from_typedesc(typedesc *d,bool checkaccess,bool link,classinfo **result);
145
146 #ifdef ENABLE_VERIFIER
147 bool resolve_class(unresolved_class *ref,
148                           resolve_mode_t mode,
149                           bool checkaccess,
150                           classinfo **result);
151
152 classinfo * resolve_class_eager(unresolved_class *ref);
153 classinfo * resolve_class_eager_no_access_check(unresolved_class *ref);
154 #endif /* ENABLE_VERIFIER */
155
156 bool resolve_field(unresolved_field *ref,
157                           resolve_mode_t mode,
158                           fieldinfo **result);
159
160 bool resolve_method(unresolved_method *ref,
161                           resolve_mode_t mode,
162                            methodinfo **result);
163
164 classinfo * resolve_classref_eager(constant_classref *ref);
165 classinfo * resolve_classref_eager_nonabstract(constant_classref *ref);
166 fieldinfo * resolve_field_eager(unresolved_field *ref);
167 methodinfo * resolve_method_eager(unresolved_method *ref);
168
169 #ifdef ENABLE_VERIFIER
170 unresolved_class * create_unresolved_class(methodinfo *refmethod,
171                                                 constant_classref *classref,
172                                                 typeinfo_t *valuetype);
173 #endif
174
175 unresolved_field *resolve_create_unresolved_field(classinfo *referer,
176                                                                                           methodinfo *refmethod,
177                                                                                           instruction *iptr);
178
179 unresolved_method * resolve_create_unresolved_method(classinfo *referer,
180                                                                                                          methodinfo *refmethod,
181                                                                                                          constant_FMIref *methodref,
182                                                                                                          bool invokestatic,
183                                                                                                          bool invokespecial);
184
185 void unresolved_class_free(unresolved_class *ref);
186 void unresolved_field_free(unresolved_field *ref);
187 void unresolved_method_free(unresolved_method *ref);
188
189 resolve_result_t resolve_method_lazy(methodinfo *refmethod,
190                                                                          constant_FMIref *methodref,
191                                                                          bool invokespecial);
192
193 resolve_result_t resolve_field_lazy(methodinfo *refmethod,
194                                                                         constant_FMIref *fieldref);
195
196 #if defined(ENABLE_VERIFIER)
197 resolve_result_t resolve_field_verifier_checks(methodinfo *refmethod,
198                                                                                            constant_FMIref *fieldref,
199                                                                                            classinfo *container,
200                                                                                            fieldinfo *fi,
201                                                                                            typeinfo_t *instanceti,
202                                                                                            typeinfo_t *valueti,
203                                                                                            bool isstatic,
204                                                                                            bool isput);
205
206 bool resolve_constrain_unresolved_field(unresolved_field *ref,
207                                                                                 classinfo *referer, 
208                                                                                 methodinfo *refmethod,
209                                                                             typeinfo_t *instanceti,
210                                                                             typeinfo_t *valueti);
211
212 resolve_result_t resolve_method_verifier_checks(methodinfo *refmethod,
213                                                                                                 constant_FMIref *methodref,
214                                                                                                 methodinfo *mi,
215                                                                                                 bool invokestatic);
216
217 resolve_result_t resolve_method_instance_type_checks(methodinfo *refmethod,
218                                                                                                          methodinfo *mi,
219                                                                                                          typeinfo_t *instanceti,
220                                                                                                          bool invokespecial);
221
222 resolve_result_t resolve_method_param_type_checks(jitdata *jd, 
223                                                                                                   methodinfo *refmethod,
224                                                                                                   instruction *iptr, 
225                                                                                                   methodinfo *mi,
226                                                                                                   bool invokestatic);
227
228 resolve_result_t resolve_method_param_type_checks_stackbased(
229                 methodinfo *refmethod, 
230                 methodinfo *mi,
231                 bool invokestatic, 
232                 typedescriptor_t *stack);
233
234 bool resolve_method_loading_constraints(classinfo *referer,
235                                                                                 methodinfo *mi);
236
237 bool resolve_constrain_unresolved_method_instance(unresolved_method *ref,
238                                                                                                   methodinfo *refmethod,
239                                                                                                   typeinfo_t *instanceti,
240                                                                                                   bool invokespecial);
241
242 bool resolve_constrain_unresolved_method_params(jitdata *jd,
243                                                                                                 unresolved_method *ref,
244                                                                                                 methodinfo *refmethod,
245                                                                                                 instruction *iptr);
246
247 bool resolve_constrain_unresolved_method_params_stackbased(
248                 unresolved_method *ref,
249                 methodinfo *refmethod,
250                 typedescriptor_t *stack);
251
252 #endif /* defined(ENABLE_VERIFIER) */
253
254 #ifndef NDEBUG
255 void unresolved_class_debug_dump(unresolved_class *ref,FILE *file);
256 void unresolved_field_debug_dump(unresolved_field *ref,FILE *file);
257 void unresolved_method_debug_dump(unresolved_method *ref,FILE *file);
258 void unresolved_subtype_set_debug_dump(unresolved_subtype_set *stset,FILE *file);
259 #endif
260         
261 #endif /* _RESOLVE_H */
262
263 /*
264  * These are local overrides for various environment variables in Emacs.
265  * Please do not remove this and leave it at the end of the file, where
266  * Emacs will automagically detect them.
267  * ---------------------------------------------------------------------
268  * Local variables:
269  * mode: c
270  * indent-tabs-mode: t
271  * c-basic-offset: 4
272  * tab-width: 4
273  * End:
274  * vim:noexpandtab:sw=4:ts=4:
275  */
276