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