f828d3ac0c0a5a07dbbbb3cae4d8e2e8a76f1b46
[cacao.git] / src / vm / resolve.h
1 /* src/vm/resolve.h - resolving classes/interfaces/fields/methods
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: resolve.h 7486 2007-03-08 13:50:07Z twisti $
26
27 */
28
29
30 #ifndef _RESOLVE_H
31 #define _RESOLVE_H
32
33 /* forward declarations *******************************************************/
34
35 typedef struct unresolved_class unresolved_class;
36 typedef struct unresolved_field unresolved_field;
37 typedef struct unresolved_method unresolved_method;
38 typedef struct unresolved_subtype_set unresolved_subtype_set;
39
40
41 #include "config.h"
42 #include "vm/types.h"
43
44 #include "vm/global.h"
45
46 #include "vm/jit/jit.h"
47 #include "vm/jit/reg.h"
48 #include "vm/jit/verify/typeinfo.h"
49
50 #include "vmcore/class.h"
51 #include "vmcore/field.h"
52 #include "vmcore/method.h"
53 #include "vmcore/references.h"
54
55
56 /* constants ******************************************************************/
57
58 #define RESOLVE_STATIC    0x0001  /* ref to static fields/methods             */
59 #define RESOLVE_PUTFIELD  0x0002  /* field ref inside a PUT{FIELD,STATIC}...  */
60 #define RESOLVE_SPECIAL   0x0004  /* method ref inside INVOKESPECIAL          */
61
62
63 /* enums **********************************************************************/
64
65 typedef enum {
66         resolveLazy,
67         resolveEager
68 } resolve_mode_t;
69
70 typedef enum {
71         resolveLinkageError,
72         resolveIllegalAccessError
73 } resolve_err_t;
74
75 typedef enum {
76         resolveFailed = false,  /* this must be a false value */
77         resolveDeferred = true, /* this must be a true value  */
78         resolveSucceeded
79 } resolve_result_t;
80
81 /* structs ********************************************************************/
82
83 struct unresolved_subtype_set {
84         classref_or_classinfo *subtyperefs;     /* NULL terminated list */
85 };
86
87 struct unresolved_class {
88         constant_classref      *classref;
89         methodinfo                     *referermethod;
90         unresolved_subtype_set  subtypeconstraints;
91 };
92
93 /* XXX unify heads of unresolved_field and unresolved_method? */
94
95 struct unresolved_field {
96         constant_FMIref *fieldref;
97         methodinfo      *referermethod;
98         s4               flags;
99         
100         unresolved_subtype_set  instancetypes;
101         unresolved_subtype_set  valueconstraints;
102 };
103
104 struct unresolved_method {
105         constant_FMIref *methodref;
106         methodinfo      *referermethod;
107         s4               flags;
108         
109         unresolved_subtype_set  instancetypes;
110         unresolved_subtype_set *paramconstraints;
111 };
112
113 #define SUBTYPESET_IS_EMPTY(stset) \
114         ((stset).subtyperefs == NULL)
115
116 #define UNRESOLVED_SUBTYPE_SET_EMTPY(stset) \
117         do { (stset).subtyperefs = NULL; } while(0)
118
119 /* function prototypes ********************************************************/
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 *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 *instanceti,
202                                                                                            typeinfo *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 *instanceti,
210                                                                             typeinfo *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 *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 *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 *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 *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