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