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