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 2215 2005-04-04 14:59:12Z edwin $
39 /* forward declarations *******************************************************/
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;
47 #include "vm/global.h"
48 #include "vm/references.h"
49 #include "vm/jit/jit.h"
52 /* constants ******************************************************************/
54 #define RESOLVE_STATIC 0x0001
55 #define RESOLVE_PUTFIELD 0x0002
58 /* enums **********************************************************************/
68 resolveIllegalAccessError
72 /* structs ********************************************************************/
74 struct unresolved_subtype_set {
75 classref_or_classinfo *subtyperefs; /* NULL terminated list */
78 struct unresolved_class {
79 constant_classref *classref;
80 methodinfo *referermethod;
81 unresolved_subtype_set subtypeconstraints;
84 /* XXX unify heads of unresolved_field and unresolved_method? */
86 struct unresolved_field {
87 constant_FMIref *fieldref;
88 methodinfo *referermethod;
91 unresolved_subtype_set instancetypes;
92 unresolved_subtype_set valueconstraints;
95 struct unresolved_method {
96 constant_FMIref *methodref;
97 methodinfo *referermethod;
100 unresolved_subtype_set instancetypes;
101 unresolved_subtype_set *paramconstraints;
104 #define SUBTYPESET_IS_EMPTY(stset) \
105 ((stset).subtyperefs == NULL)
107 #define UNRESOLVED_SUBTYPE_SET_EMTPY(stset) \
108 do { (stset).subtyperefs = NULL; } while(0)
110 /* function prototypes ********************************************************/
112 /* resolve_class_from_name *****************************************************
114 Resolve a symbolic class reference
117 referer..........the class containing the reference
118 refmethod........the method from which resolution was triggered
119 (may be NULL if not applicable)
120 classname........class name to resolve
121 mode.............mode of resolution:
122 resolveLazy...only resolve if it does not
123 require loading classes
124 resolveEager..load classes if necessary
127 *result..........set to result of resolution, or to NULL if
128 the reference has not been resolved
129 In the case of an exception, *result is
130 guaranteed to be set to NULL.
133 true.............everything ok
134 (*result may still be NULL for resolveLazy)
135 false............an exception has been thrown
138 The returned class is *not* guaranteed to be linked!
139 (It is guaranteed to be loaded, though.)
141 *******************************************************************************/
144 resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
149 /* resolve_classref ************************************************************
151 Resolve a symbolic class reference
154 refmethod........the method from which resolution was triggered
155 (may be NULL if not applicable)
156 ref..............class reference
157 mode.............mode of resolution:
158 resolveLazy...only resolve if it does not
159 require loading classes
160 resolveEager..load classes if necessary
161 link.............if true, guarantee that the returned class, if any,
165 *result..........set to result of resolution, or to NULL if
166 the reference has not been resolved
167 In the case of an exception, *result is
168 guaranteed to be set to NULL.
171 true.............everything ok
172 (*result may still be NULL for resolveLazy)
173 false............an exception has been thrown
175 *******************************************************************************/
178 resolve_classref(methodinfo *refmethod,
179 constant_classref *ref,
184 /* resolve_classref_or_classinfo ***********************************************
186 Resolve a symbolic class reference if necessary
189 refmethod........the method from which resolution was triggered
190 (may be NULL if not applicable)
191 cls..............class reference or classinfo
192 mode.............mode of resolution:
193 resolveLazy...only resolve if it does not
194 require loading classes
195 resolveEager..load classes if necessary
196 link.............if true, guarantee that the returned class, if any,
200 *result..........set to result of resolution, or to NULL if
201 the reference has not been resolved
202 In the case of an exception, *result is
203 guaranteed to be set to NULL.
206 true.............everything ok
207 (*result may still be NULL for resolveLazy)
208 false............an exception has been thrown
210 *******************************************************************************/
213 resolve_classref_or_classinfo(methodinfo *refmethod,
214 classref_or_classinfo cls,
219 /* resolve_class_from_typedesc *************************************************
221 Return a classinfo * for the given type descriptor
224 d................type descriptor
225 link.............if true, guarantee that the returned class, if any,
228 *result..........set to result of resolution, or to NULL if
229 the reference has not been resolved
230 In the case of an exception, *result is
231 guaranteed to be set to NULL.
234 true.............everything ok
235 false............an exception has been thrown
238 This function always resolved eagerly.
240 *******************************************************************************/
242 bool resolve_class_from_typedesc(typedesc *d,bool link,classinfo **result);
244 /* resolve_class ***************************************************************
246 Resolve an unresolved class reference
249 ref..............struct containing the reference
250 mode.............mode of resolution:
251 resolveLazy...only resolve if it does not
252 require loading classes
253 resolveEager..load classes if necessary
256 *result..........set to the result of resolution, or to NULL if
257 the reference has not been resolved
258 In the case of an exception, *result is
259 guaranteed to be set to NULL.
262 true.............everything ok
263 (*result may still be NULL for resolveLazy)
264 false............an exception has been thrown
266 *******************************************************************************/
269 resolve_class(unresolved_class *ref,
273 /* resolve_field ***************************************************************
275 Resolve an unresolved field reference
278 ref..............struct containing the reference
279 mode.............mode of resolution:
280 resolveLazy...only resolve if it does not
281 require loading classes
282 resolveEager..load classes if necessary
285 *result..........set to the result of resolution, or to NULL if
286 the reference has not been resolved
287 In the case of an exception, *result is
288 guaranteed to be set to NULL.
291 true.............everything ok
292 (*result may still be NULL for resolveLazy)
293 false............an exception has been thrown
295 *******************************************************************************/
298 resolve_field(unresolved_field *ref,
302 /* resolve_method **************************************************************
304 Resolve an unresolved method reference
307 ref..............struct containing the reference
308 mode.............mode of resolution:
309 resolveLazy...only resolve if it does not
310 require loading classes
311 resolveEager..load classes if necessary
314 *result..........set to the result of resolution, or to NULL if
315 the reference has not been resolved
316 In the case of an exception, *result is
317 guaranteed to be set to NULL.
320 true.............everything ok
321 (*result may still be NULL for resolveLazy)
322 false............an exception has been thrown
324 *******************************************************************************/
327 resolve_method(unresolved_method *ref,
329 methodinfo **result);
331 /* resolve_and_check_subtype_set ***********************************************
333 Resolve the references in the given set and test subtype relationships
336 referer..........the class containing the references
337 refmethod........the method triggering the resolution
338 ref..............a set of class/interface references
340 type.............the type to test against the set
341 reversed.........if true, test if type is a subtype of
342 the set members, instead of the other
344 mode.............mode of resolution:
345 resolveLazy...only resolve if it does not
346 require loading classes
347 resolveEager..load classes if necessary
348 error............which type of exception to throw if
349 the test fails. May be:
350 resolveLinkageError, or
351 resolveIllegalAccessError
354 *checked.........set to true if all checks were performed,
355 otherwise set to false
356 (This is guaranteed to be true if mode was
357 resolveEager and no exception occured.)
358 If checked == NULL, this parameter is not used.
361 true.............the check succeeded
362 false............the check failed. An exception has been
366 The references in the set are resolved first, so any
367 exception which may occurr during resolution may
368 be thrown by this function.
370 *******************************************************************************/
373 resolve_and_check_subtype_set(classinfo *referer,methodinfo *refmethod,
374 unresolved_subtype_set *ref,
375 classref_or_classinfo type,
381 /* create_unresolved_class *****************************************************
383 Create an unresolved_class struct for the given class reference
386 refmethod........the method triggering the resolution (if any)
387 classref.........the class reference
388 valuetype........value type to check against the resolved class
391 a pointer to a new unresolved_class struct
393 *******************************************************************************/
396 create_unresolved_class(methodinfo *refmethod,
397 constant_classref *classref,
398 typeinfo *valuetype);
400 /* create_unresolved_field *****************************************************
402 Create an unresolved_field struct for the given field access instruction
405 referer..........the class containing the reference
406 refmethod........the method triggering the resolution (if any)
407 iptr.............the {GET,PUT}{FIELD,STATIC}{,CONST} instruction
408 stack............the input stack of the instruction
411 a pointer to a new unresolved_field struct
413 *******************************************************************************/
416 create_unresolved_field(classinfo *referer,methodinfo *refmethod,
418 stackelement *stack);
420 /* create_unresolved_method ****************************************************
422 Create an unresolved_method struct for the given method invocation
425 referer..........the class containing the reference
426 refmethod........the method triggering the resolution (if any)
427 iptr.............the INVOKE* instruction
428 stack............the input stack of the instruction
431 a pointer to a new unresolved_method struct
433 *******************************************************************************/
436 create_unresolved_method(classinfo *referer,methodinfo *refmethod,
438 stackelement *stack);
440 /* unresolved_class_free *******************************************************
442 Free the memory used by an unresolved_class
445 ref..............the unresolved_class
447 *******************************************************************************/
449 void unresolved_class_free(unresolved_class *ref);
451 /* unresolved_field_free *******************************************************
453 Free the memory used by an unresolved_field
456 ref..............the unresolved_field
458 *******************************************************************************/
460 void unresolved_field_free(unresolved_field *ref);
462 /* unresolved_method_free ******************************************************
464 Free the memory used by an unresolved_method
467 ref..............the unresolved_method
469 *******************************************************************************/
471 void unresolved_method_free(unresolved_method *ref);
473 /* unresolved_class_debug_dump *************************************************
475 Print debug info for unresolved_class to stream
478 ref..............the unresolved_class
479 file.............the stream
481 *******************************************************************************/
483 void unresolved_class_debug_dump(unresolved_class *ref,FILE *file);
485 /* unresolved_field_debug_dump *************************************************
487 Print debug info for unresolved_field to stream
490 ref..............the unresolved_field
491 file.............the stream
493 *******************************************************************************/
495 void unresolved_field_debug_dump(unresolved_field *ref,FILE *file);
497 /* unresolved_method_debug_dump ************************************************
499 Print debug info for unresolved_method to stream
502 ref..............the unresolved_method
503 file.............the stream
505 *******************************************************************************/
507 void unresolved_method_debug_dump(unresolved_method *ref,FILE *file);
509 /* unresolved_subtype_set_debug_dump *******************************************
511 Print debug info for unresolved_subtype_set to stream
514 stset............the unresolved_subtype_set
515 file.............the stream
517 *******************************************************************************/
519 void unresolved_subtype_set_debug_dump(unresolved_subtype_set *stset,FILE *file);
521 #endif /* _RESOLVE_H */
524 * These are local overrides for various environment variables in Emacs.
525 * Please do not remove this and leave it at the end of the file, where
526 * Emacs will automagically detect them.
527 * ---------------------------------------------------------------------
530 * indent-tabs-mode: t
534 * vim:noexpandtab:sw=4:ts=4: