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 2788 2005-06-22 16:08:51Z 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
125 checkaccess......if true, access rights to the class are checked
126 link.............if true, guarantee that the returned class, if any,
130 *result..........set to result of resolution, or to NULL if
131 the reference has not been resolved
132 In the case of an exception, *result is
133 guaranteed to be set to NULL.
136 true.............everything ok
137 (*result may still be NULL for resolveLazy)
138 false............an exception has been thrown
141 The returned class is *not* guaranteed to be linked!
142 (It is guaranteed to be loaded, though.)
144 *******************************************************************************/
147 resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
154 /* resolve_classref ************************************************************
156 Resolve a symbolic class reference
159 refmethod........the method from which resolution was triggered
160 (may be NULL if not applicable)
161 ref..............class reference
162 mode.............mode of resolution:
163 resolveLazy...only resolve if it does not
164 require loading classes
165 resolveEager..load classes if necessary
166 checkaccess......if true, access rights to the class are checked
167 link.............if true, guarantee that the returned class, if any,
171 *result..........set to result of resolution, or to NULL if
172 the reference has not been resolved
173 In the case of an exception, *result is
174 guaranteed to be set to NULL.
177 true.............everything ok
178 (*result may still be NULL for resolveLazy)
179 false............an exception has been thrown
181 *******************************************************************************/
184 resolve_classref(methodinfo *refmethod,
185 constant_classref *ref,
191 /* resolve_classref_or_classinfo ***********************************************
193 Resolve a symbolic class reference if necessary
196 refmethod........the method from which resolution was triggered
197 (may be NULL if not applicable)
198 cls..............class reference or classinfo
199 mode.............mode of resolution:
200 resolveLazy...only resolve if it does not
201 require loading classes
202 resolveEager..load classes if necessary
203 checkaccess......if true, access rights to the class are checked
204 link.............if true, guarantee that the returned class, if any,
208 *result..........set to result of resolution, or to NULL if
209 the reference has not been resolved
210 In the case of an exception, *result is
211 guaranteed to be set to NULL.
214 true.............everything ok
215 (*result may still be NULL for resolveLazy)
216 false............an exception has been thrown
218 *******************************************************************************/
221 resolve_classref_or_classinfo(methodinfo *refmethod,
222 classref_or_classinfo cls,
228 /* resolve_class_from_typedesc *************************************************
230 Return a classinfo * for the given type descriptor
233 d................type descriptor
234 checkaccess......if true, access rights to the class are checked
235 link.............if true, guarantee that the returned class, if any,
238 *result..........set to result of resolution, or to NULL if
239 the reference has not been resolved
240 In the case of an exception, *result is
241 guaranteed to be set to NULL.
244 true.............everything ok
245 false............an exception has been thrown
248 This function always resolved eagerly.
250 *******************************************************************************/
252 bool resolve_class_from_typedesc(typedesc *d,bool checkaccess,bool link,classinfo **result);
254 /* resolve_class ***************************************************************
256 Resolve an unresolved class reference. The class is also linked.
259 ref..............struct containing the reference
260 mode.............mode of resolution:
261 resolveLazy...only resolve if it does not
262 require loading classes
263 resolveEager..load classes if necessary
264 checkaccess......if true, access rights to the class are checked
267 *result..........set to the result of resolution, or to NULL if
268 the reference has not been resolved
269 In the case of an exception, *result is
270 guaranteed to be set to NULL.
273 true.............everything ok
274 (*result may still be NULL for resolveLazy)
275 false............an exception has been thrown
277 *******************************************************************************/
280 resolve_class(unresolved_class *ref,
285 /* resolve_field ***************************************************************
287 Resolve an unresolved field reference
290 ref..............struct containing the reference
291 mode.............mode of resolution:
292 resolveLazy...only resolve if it does not
293 require loading classes
294 resolveEager..load classes if necessary
297 *result..........set to the result of resolution, or to NULL if
298 the reference has not been resolved
299 In the case of an exception, *result is
300 guaranteed to be set to NULL.
303 true.............everything ok
304 (*result may still be NULL for resolveLazy)
305 false............an exception has been thrown
307 *******************************************************************************/
310 resolve_field(unresolved_field *ref,
314 /* resolve_method **************************************************************
316 Resolve an unresolved method reference
319 ref..............struct containing the reference
320 mode.............mode of resolution:
321 resolveLazy...only resolve if it does not
322 require loading classes
323 resolveEager..load classes if necessary
326 *result..........set to the result of resolution, or to NULL if
327 the reference has not been resolved
328 In the case of an exception, *result is
329 guaranteed to be set to NULL.
332 true.............everything ok
333 (*result may still be NULL for resolveLazy)
334 false............an exception has been thrown
336 *******************************************************************************/
339 resolve_method(unresolved_method *ref,
341 methodinfo **result);
343 /* resolve_and_check_subtype_set ***********************************************
345 Resolve the references in the given set and test subtype relationships
348 referer..........the class containing the references
349 refmethod........the method triggering the resolution
350 ref..............a set of class/interface references
352 type.............the type to test against the set
353 reversed.........if true, test if type is a subtype of
354 the set members, instead of the other
356 mode.............mode of resolution:
357 resolveLazy...only resolve if it does not
358 require loading classes
359 resolveEager..load classes if necessary
360 error............which type of exception to throw if
361 the test fails. May be:
362 resolveLinkageError, or
363 resolveIllegalAccessError
366 *checked.........set to true if all checks were performed,
367 otherwise set to false
368 (This is guaranteed to be true if mode was
369 resolveEager and no exception occured.)
370 If checked == NULL, this parameter is not used.
373 true.............the check succeeded
374 false............the check failed. An exception has been
378 The references in the set are resolved first, so any
379 exception which may occurr during resolution may
380 be thrown by this function.
382 *******************************************************************************/
385 resolve_and_check_subtype_set(classinfo *referer,methodinfo *refmethod,
386 unresolved_subtype_set *ref,
387 classref_or_classinfo type,
393 /* create_unresolved_class *****************************************************
395 Create an unresolved_class struct for the given class reference
398 refmethod........the method triggering the resolution (if any)
399 classref.........the class reference
400 valuetype........value type to check against the resolved class
401 may be NULL, if no typeinfo is available
404 a pointer to a new unresolved_class struct, or
405 NULL if an exception has been thrown
407 *******************************************************************************/
410 create_unresolved_class(methodinfo *refmethod,
411 constant_classref *classref,
412 typeinfo *valuetype);
414 /* create_unresolved_field *****************************************************
416 Create an unresolved_field struct for the given field access instruction
419 referer..........the class containing the reference
420 refmethod........the method triggering the resolution (if any)
421 iptr.............the {GET,PUT}{FIELD,STATIC}{,CONST} instruction
424 a pointer to a new unresolved_field struct, or
425 NULL if an exception has been thrown
427 *******************************************************************************/
430 create_unresolved_field(classinfo *referer,methodinfo *refmethod,
433 /* constrain_unresolved_field **************************************************
435 Record subtype constraints for a field access.
438 ref..............the unresolved_field structure of the access
439 referer..........the class containing the reference
440 refmethod........the method triggering the resolution (if any)
441 iptr.............the {GET,PUT}{FIELD,STATIC}{,CONST} instruction
442 stack............the input stack of the instruction
445 true.............everything ok
446 false............an exception has been thrown
448 *******************************************************************************/
451 constrain_unresolved_field(unresolved_field *ref,
452 classinfo *referer,methodinfo *refmethod,
454 stackelement *stack);
456 /* create_unresolved_method ****************************************************
458 Create an unresolved_method struct for the given method invocation
461 referer..........the class containing the reference
462 refmethod........the method triggering the resolution (if any)
463 iptr.............the INVOKE* instruction
466 a pointer to a new unresolved_method struct, or
467 NULL if an exception has been thrown
469 *******************************************************************************/
472 create_unresolved_method(classinfo *referer,methodinfo *refmethod,
475 /* constrain_unresolved_method *************************************************
477 Record subtype constraints for the arguments of a method call.
480 ref..............the unresolved_method structure of the call
481 referer..........the class containing the reference
482 refmethod........the method triggering the resolution (if any)
483 iptr.............the INVOKE* instruction
484 stack............the input stack of the instruction
487 true.............everything ok
488 false............an exception has been thrown
490 *******************************************************************************/
493 constrain_unresolved_method(unresolved_method *ref,
494 classinfo *referer,methodinfo *refmethod,
496 stackelement *stack);
498 /* unresolved_class_free *******************************************************
500 Free the memory used by an unresolved_class
503 ref..............the unresolved_class
505 *******************************************************************************/
507 void unresolved_class_free(unresolved_class *ref);
509 /* unresolved_field_free *******************************************************
511 Free the memory used by an unresolved_field
514 ref..............the unresolved_field
516 *******************************************************************************/
518 void unresolved_field_free(unresolved_field *ref);
520 /* unresolved_method_free ******************************************************
522 Free the memory used by an unresolved_method
525 ref..............the unresolved_method
527 *******************************************************************************/
529 void unresolved_method_free(unresolved_method *ref);
531 /* unresolved_class_debug_dump *************************************************
533 Print debug info for unresolved_class to stream
536 ref..............the unresolved_class
537 file.............the stream
539 *******************************************************************************/
541 void unresolved_class_debug_dump(unresolved_class *ref,FILE *file);
543 /* unresolved_field_debug_dump *************************************************
545 Print debug info for unresolved_field to stream
548 ref..............the unresolved_field
549 file.............the stream
551 *******************************************************************************/
553 void unresolved_field_debug_dump(unresolved_field *ref,FILE *file);
555 /* unresolved_method_debug_dump ************************************************
557 Print debug info for unresolved_method to stream
560 ref..............the unresolved_method
561 file.............the stream
563 *******************************************************************************/
565 void unresolved_method_debug_dump(unresolved_method *ref,FILE *file);
567 /* unresolved_subtype_set_debug_dump *******************************************
569 Print debug info for unresolved_subtype_set to stream
572 stset............the unresolved_subtype_set
573 file.............the stream
575 *******************************************************************************/
577 void unresolved_subtype_set_debug_dump(unresolved_subtype_set *stset,FILE *file);
579 #endif /* _RESOLVE_H */
582 * These are local overrides for various environment variables in Emacs.
583 * Please do not remove this and leave it at the end of the file, where
584 * Emacs will automagically detect them.
585 * ---------------------------------------------------------------------
588 * indent-tabs-mode: t
592 * vim:noexpandtab:sw=4:ts=4: