1 /* vm/resolve.h - resolving classes/interfaces/fields/methods
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Edwin Steiner
31 $Id: resolve.h 2112 2005-03-29 21:29:08Z twisti $
39 /* forward declarations *******************************************************/
41 typedef struct unresolved_field unresolved_field;
42 typedef struct unresolved_method unresolved_method;
43 typedef struct unresolved_subtype_set unresolved_subtype_set;
46 #include "vm/global.h"
47 #include "vm/loader.h"
48 #include "vm/jit/jit.h"
51 /* constants ******************************************************************/
53 #define RESOLVE_STATIC 0x0001
54 #define RESOLVE_PUTFIELD 0x0002
57 /* enums **********************************************************************/
67 resolveIllegalAccessError
71 /* classref_or_classinfo ******************************************************/
74 constant_classref *ref; /* a symbolic class reference */
75 classinfo *cls; /* an already loaded class */
76 void *any; /* used for general access (x != NULL,...) */
77 } classref_or_classinfo;
80 /* structs ********************************************************************/
82 struct unresolved_subtype_set {
83 classref_or_classinfo *subtyperefs; /* NULL terminated list */
87 /* XXX unify heads of unresolved_field and unresolved_method? */
89 struct unresolved_field {
90 constant_FMIref *fieldref;
91 methodinfo *referermethod;
94 unresolved_subtype_set instancetypes;
95 unresolved_subtype_set valueconstraints;
98 struct unresolved_method {
99 constant_FMIref *methodref;
100 methodinfo *referermethod;
103 unresolved_subtype_set instancetypes;
104 unresolved_subtype_set *paramconstraints;
107 #define SUBTYPESET_IS_EMPTY(stset) \
108 ((stset).subtyperefs == NULL)
110 #define UNRESOLVED_SUBTYPE_SET_EMTPY(stset) \
111 do { (stset).subtyperefs = NULL; } while(0)
113 /* a value that never occurrs in classinfo.header.vftbl */
114 #define CLASSREF_PSEUDO_VFTBL ((vftbl_t *) 1)
116 /* macro for testing if a classref_or_classinfo is a classref */
117 /* `reforinfo` is only evaluated once */
118 #define IS_CLASSREF(reforinfo) \
119 ((reforinfo).ref->pseudo_vftbl == CLASSREF_PSEUDO_VFTBL)
121 /* macro for casting a classref/classinfo * to a classref_or_classinfo */
122 #define CLASSREF_OR_CLASSINFO(value) \
123 (*((classref_or_classinfo *)(&(value))))
126 /* function prototypes ********************************************************/
128 /* resolve_class ***************************************************************
130 Resolve a symbolic class reference
133 referer..........the class containing the reference
134 refmethod........the method from which resolution was triggered
135 (may be NULL if not applicable)
136 classname........class name to resolve
137 mode.............mode of resolution:
138 resolveLazy...only resolve if it does not
139 require loading classes
140 resolveEager..load classes if necessary
143 *result..........set to result of resolution, or to NULL if
144 the reference has not been resolved
145 In the case of an exception, *result is
146 guaranteed to be set to NULL.
149 true.............everything ok
150 (*result may still be NULL for resolveLazy)
151 false............an exception has been thrown
154 The returned class is *not* guaranteed to be linked!
155 (It is guaranteed to be loaded, though.)
157 *******************************************************************************/
160 resolve_class(classinfo *referer,methodinfo *refmethod,
165 /* resolve_classref_or_classinfo ***********************************************
167 Resolve a symbolic class reference if necessary
170 refmethod........the method from which resolution was triggered
171 (may be NULL if not applicable)
172 cls..............class reference or classinfo
173 mode.............mode of resolution:
174 resolveLazy...only resolve if it does not
175 require loading classes
176 resolveEager..load classes if necessary
177 link.............if true, guarantee that the returned class, if any,
181 *result..........set to result of resolution, or to NULL if
182 the reference has not been resolved
183 In the case of an exception, *result is
184 guaranteed to be set to NULL.
187 true.............everything ok
188 (*result may still be NULL for resolveLazy)
189 false............an exception has been thrown
191 *******************************************************************************/
194 resolve_classref_or_classinfo(methodinfo *refmethod,
195 classref_or_classinfo cls,
200 /* resolve_field ***************************************************************
202 Resolve an unresolved field reference
205 ref..............struct containing the reference
206 mode.............mode of resolution:
207 resolveLazy...only resolve if it does not
208 require loading classes
209 resolveEager..load classes if necessary
212 *result..........set to the result of resolution, or to NULL if
213 the reference has not been resolved
214 In the case of an exception, *result is
215 guaranteed to be set to NULL.
218 true.............everything ok
219 (*result may still be NULL for resolveLazy) XXX implement
220 false............an exception has been thrown
222 *******************************************************************************/
225 resolve_field(unresolved_field *ref,
229 /* resolve_method **************************************************************
231 Resolve an unresolved method reference
234 ref..............struct containing the reference
235 mode.............mode of resolution:
236 resolveLazy...only resolve if it does not
237 require loading classes
238 resolveEager..load classes if necessary
241 *result..........set to the result of resolution, or to NULL if
242 the reference has not been resolved
243 In the case of an exception, *result is
244 guaranteed to be set to NULL.
247 true.............everything ok
248 (*result may still be NULL for resolveLazy) XXX implement
249 false............an exception has been thrown
251 *******************************************************************************/
254 resolve_method(unresolved_method *ref,
256 methodinfo **result);
258 /* resolve_and_check_subtype_set ***********************************************
260 Resolve the references in the given set and test subtype relationships
263 referer..........the class containing the references
264 refmethod........the method triggering the resolution
265 ref..............a set of class/interface references
267 type.............the type to test against the set
268 reversed.........if true, test if type is a subtype of
269 the set members, instead of the other
271 mode.............mode of resolution:
272 resolveLazy...only resolve if it does not
273 require loading classes
274 resolveEager..load classes if necessary
275 error............which type of exception to throw if
276 the test fails. May be:
277 resolveLinkageError, or
278 resolveIllegalAccessError
281 *checked.........set to true if all checks were performed,
282 otherwise set to false
283 (This is guaranteed to be true if mode was
284 resolveEager and no exception occured.)
285 If checked == NULL, this parameter is not used.
288 true.............the check succeeded
289 false............the check failed. An exception has been
293 The references in the set are resolved first, so any
294 exception which may occurr during resolution may
295 be thrown by this function.
297 *******************************************************************************/
300 resolve_and_check_subtype_set(classinfo *referer,methodinfo *refmethod,
301 unresolved_subtype_set *ref,
302 classref_or_classinfo type,
308 /* create_unresolved_field *****************************************************
310 Create an unresolved_field struct for the given field access instruction
313 referer..........the class containing the reference
314 refmethod........the method triggering the resolution (if any)
315 iptr.............the {GET,PUT}{FIELD,STATIC}{,CONST} instruction
316 stack............the input stack of the instruction
319 a pointer to a new unresolved_field struct
321 *******************************************************************************/
324 create_unresolved_field(classinfo *referer,methodinfo *refmethod,
326 stackelement *stack);
328 /* create_unresolved_method ****************************************************
330 Create an unresolved_method struct for the given method invocation
333 referer..........the class containing the reference
334 refmethod........the method triggering the resolution (if any)
335 iptr.............the INVOKE* instruction
336 stack............the input stack of the instruction
339 a pointer to a new unresolved_method struct
341 *******************************************************************************/
344 create_unresolved_method(classinfo *referer,methodinfo *refmethod,
346 stackelement *stack);
348 /* unresolved_field_free *******************************************************
350 Free the memory used by an unresolved_field
353 ref..............the unresolved_field
355 *******************************************************************************/
357 void unresolved_field_free(unresolved_field *ref);
359 /* unresolved_method_free ******************************************************
361 Free the memory used by an unresolved_method
364 ref..............the unresolved_method
366 *******************************************************************************/
368 void unresolved_method_free(unresolved_method *ref);
370 /* unresolved_field_debug_dump *************************************************
372 Print debug info for unresolved_field to stream
375 ref..............the unresolved_field
376 file.............the stream
378 *******************************************************************************/
380 void unresolved_field_debug_dump(unresolved_field *ref,FILE *file);
382 /* unresolved_method_debug_dump ************************************************
384 Print debug info for unresolved_method to stream
387 ref..............the unresolved_method
388 file.............the stream
390 *******************************************************************************/
392 void unresolved_method_debug_dump(unresolved_method *ref,FILE *file);
394 /* unresolved_subtype_set_debug_dump *******************************************
396 Print debug info for unresolved_subtype_set to stream
399 stset............the unresolved_subtype_set
400 file.............the stream
402 *******************************************************************************/
404 void unresolved_subtype_set_debug_dump(unresolved_subtype_set *stset,FILE *file);
406 #endif /* _RESOLVE_H */
409 * These are local overrides for various environment variables in Emacs.
410 * Please do not remove this and leave it at the end of the file, where
411 * Emacs will automagically detect them.
412 * ---------------------------------------------------------------------
415 * indent-tabs-mode: t
419 * vim:noexpandtab:sw=4:ts=4: