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 2738 2005-06-18 16:37:34Z 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 link.............if true, guarantee that the returned class, if any,
129 *result..........set to result of resolution, or to NULL if
130 the reference has not been resolved
131 In the case of an exception, *result is
132 guaranteed to be set to NULL.
135 true.............everything ok
136 (*result may still be NULL for resolveLazy)
137 false............an exception has been thrown
140 The returned class is *not* guaranteed to be linked!
141 (It is guaranteed to be loaded, though.)
143 *******************************************************************************/
146 resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
152 /* resolve_classref ************************************************************
154 Resolve a symbolic class reference
157 refmethod........the method from which resolution was triggered
158 (may be NULL if not applicable)
159 ref..............class reference
160 mode.............mode of resolution:
161 resolveLazy...only resolve if it does not
162 require loading classes
163 resolveEager..load classes if necessary
164 link.............if true, guarantee that the returned class, if any,
168 *result..........set to result of resolution, or to NULL if
169 the reference has not been resolved
170 In the case of an exception, *result is
171 guaranteed to be set to NULL.
174 true.............everything ok
175 (*result may still be NULL for resolveLazy)
176 false............an exception has been thrown
178 *******************************************************************************/
181 resolve_classref(methodinfo *refmethod,
182 constant_classref *ref,
187 /* resolve_classref_or_classinfo ***********************************************
189 Resolve a symbolic class reference if necessary
192 refmethod........the method from which resolution was triggered
193 (may be NULL if not applicable)
194 cls..............class reference or classinfo
195 mode.............mode of resolution:
196 resolveLazy...only resolve if it does not
197 require loading classes
198 resolveEager..load classes if necessary
199 link.............if true, guarantee that the returned class, if any,
203 *result..........set to result of resolution, or to NULL if
204 the reference has not been resolved
205 In the case of an exception, *result is
206 guaranteed to be set to NULL.
209 true.............everything ok
210 (*result may still be NULL for resolveLazy)
211 false............an exception has been thrown
213 *******************************************************************************/
216 resolve_classref_or_classinfo(methodinfo *refmethod,
217 classref_or_classinfo cls,
222 /* resolve_class_from_typedesc *************************************************
224 Return a classinfo * for the given type descriptor
227 d................type descriptor
228 link.............if true, guarantee that the returned class, if any,
231 *result..........set to result of resolution, or to NULL if
232 the reference has not been resolved
233 In the case of an exception, *result is
234 guaranteed to be set to NULL.
237 true.............everything ok
238 false............an exception has been thrown
241 This function always resolved eagerly.
243 *******************************************************************************/
245 bool resolve_class_from_typedesc(typedesc *d,bool link,classinfo **result);
247 /* resolve_class ***************************************************************
249 Resolve an unresolved class reference
252 ref..............struct containing the reference
253 mode.............mode of resolution:
254 resolveLazy...only resolve if it does not
255 require loading classes
256 resolveEager..load classes if necessary
259 *result..........set to the result of resolution, or to NULL if
260 the reference has not been resolved
261 In the case of an exception, *result is
262 guaranteed to be set to NULL.
265 true.............everything ok
266 (*result may still be NULL for resolveLazy)
267 false............an exception has been thrown
269 *******************************************************************************/
272 resolve_class(unresolved_class *ref,
276 /* resolve_field ***************************************************************
278 Resolve an unresolved field reference
281 ref..............struct containing the reference
282 mode.............mode of resolution:
283 resolveLazy...only resolve if it does not
284 require loading classes
285 resolveEager..load classes if necessary
288 *result..........set to the result of resolution, or to NULL if
289 the reference has not been resolved
290 In the case of an exception, *result is
291 guaranteed to be set to NULL.
294 true.............everything ok
295 (*result may still be NULL for resolveLazy)
296 false............an exception has been thrown
298 *******************************************************************************/
301 resolve_field(unresolved_field *ref,
305 /* resolve_method **************************************************************
307 Resolve an unresolved method reference
310 ref..............struct containing the reference
311 mode.............mode of resolution:
312 resolveLazy...only resolve if it does not
313 require loading classes
314 resolveEager..load classes if necessary
317 *result..........set to the result of resolution, or to NULL if
318 the reference has not been resolved
319 In the case of an exception, *result is
320 guaranteed to be set to NULL.
323 true.............everything ok
324 (*result may still be NULL for resolveLazy)
325 false............an exception has been thrown
327 *******************************************************************************/
330 resolve_method(unresolved_method *ref,
332 methodinfo **result);
334 /* resolve_and_check_subtype_set ***********************************************
336 Resolve the references in the given set and test subtype relationships
339 referer..........the class containing the references
340 refmethod........the method triggering the resolution
341 ref..............a set of class/interface references
343 type.............the type to test against the set
344 reversed.........if true, test if type is a subtype of
345 the set members, instead of the other
347 mode.............mode of resolution:
348 resolveLazy...only resolve if it does not
349 require loading classes
350 resolveEager..load classes if necessary
351 error............which type of exception to throw if
352 the test fails. May be:
353 resolveLinkageError, or
354 resolveIllegalAccessError
357 *checked.........set to true if all checks were performed,
358 otherwise set to false
359 (This is guaranteed to be true if mode was
360 resolveEager and no exception occured.)
361 If checked == NULL, this parameter is not used.
364 true.............the check succeeded
365 false............the check failed. An exception has been
369 The references in the set are resolved first, so any
370 exception which may occurr during resolution may
371 be thrown by this function.
373 *******************************************************************************/
376 resolve_and_check_subtype_set(classinfo *referer,methodinfo *refmethod,
377 unresolved_subtype_set *ref,
378 classref_or_classinfo type,
384 /* create_unresolved_class *****************************************************
386 Create an unresolved_class struct for the given class reference
389 refmethod........the method triggering the resolution (if any)
390 classref.........the class reference
391 valuetype........value type to check against the resolved class
392 may be NULL, if no typeinfo is available
395 a pointer to a new unresolved_class struct, or
396 NULL if an exception has been thrown
398 *******************************************************************************/
401 create_unresolved_class(methodinfo *refmethod,
402 constant_classref *classref,
403 typeinfo *valuetype);
405 /* create_unresolved_field *****************************************************
407 Create an unresolved_field struct for the given field access instruction
410 referer..........the class containing the reference
411 refmethod........the method triggering the resolution (if any)
412 iptr.............the {GET,PUT}{FIELD,STATIC}{,CONST} instruction
415 a pointer to a new unresolved_field struct, or
416 NULL if an exception has been thrown
418 *******************************************************************************/
421 create_unresolved_field(classinfo *referer,methodinfo *refmethod,
424 /* constrain_unresolved_field **************************************************
426 Record subtype constraints for a field access.
429 ref..............the unresolved_field structure of the access
430 referer..........the class containing the reference
431 refmethod........the method triggering the resolution (if any)
432 iptr.............the {GET,PUT}{FIELD,STATIC}{,CONST} instruction
433 stack............the input stack of the instruction
436 true.............everything ok
437 false............an exception has been thrown
439 *******************************************************************************/
442 constrain_unresolved_field(unresolved_field *ref,
443 classinfo *referer,methodinfo *refmethod,
445 stackelement *stack);
447 /* create_unresolved_method ****************************************************
449 Create an unresolved_method struct for the given method invocation
452 referer..........the class containing the reference
453 refmethod........the method triggering the resolution (if any)
454 iptr.............the INVOKE* instruction
457 a pointer to a new unresolved_method struct, or
458 NULL if an exception has been thrown
460 *******************************************************************************/
463 create_unresolved_method(classinfo *referer,methodinfo *refmethod,
466 /* constrain_unresolved_method *************************************************
468 Record subtype constraints for the arguments of a method call.
471 ref..............the unresolved_method structure of the call
472 referer..........the class containing the reference
473 refmethod........the method triggering the resolution (if any)
474 iptr.............the INVOKE* instruction
475 stack............the input stack of the instruction
478 true.............everything ok
479 false............an exception has been thrown
481 *******************************************************************************/
484 constrain_unresolved_method(unresolved_method *ref,
485 classinfo *referer,methodinfo *refmethod,
487 stackelement *stack);
489 /* unresolved_class_free *******************************************************
491 Free the memory used by an unresolved_class
494 ref..............the unresolved_class
496 *******************************************************************************/
498 void unresolved_class_free(unresolved_class *ref);
500 /* unresolved_field_free *******************************************************
502 Free the memory used by an unresolved_field
505 ref..............the unresolved_field
507 *******************************************************************************/
509 void unresolved_field_free(unresolved_field *ref);
511 /* unresolved_method_free ******************************************************
513 Free the memory used by an unresolved_method
516 ref..............the unresolved_method
518 *******************************************************************************/
520 void unresolved_method_free(unresolved_method *ref);
522 /* unresolved_class_debug_dump *************************************************
524 Print debug info for unresolved_class to stream
527 ref..............the unresolved_class
528 file.............the stream
530 *******************************************************************************/
532 void unresolved_class_debug_dump(unresolved_class *ref,FILE *file);
534 /* unresolved_field_debug_dump *************************************************
536 Print debug info for unresolved_field to stream
539 ref..............the unresolved_field
540 file.............the stream
542 *******************************************************************************/
544 void unresolved_field_debug_dump(unresolved_field *ref,FILE *file);
546 /* unresolved_method_debug_dump ************************************************
548 Print debug info for unresolved_method to stream
551 ref..............the unresolved_method
552 file.............the stream
554 *******************************************************************************/
556 void unresolved_method_debug_dump(unresolved_method *ref,FILE *file);
558 /* unresolved_subtype_set_debug_dump *******************************************
560 Print debug info for unresolved_subtype_set to stream
563 stset............the unresolved_subtype_set
564 file.............the stream
566 *******************************************************************************/
568 void unresolved_subtype_set_debug_dump(unresolved_subtype_set *stset,FILE *file);
570 #endif /* _RESOLVE_H */
573 * These are local overrides for various environment variables in Emacs.
574 * Please do not remove this and leave it at the end of the file, where
575 * Emacs will automagically detect them.
576 * ---------------------------------------------------------------------
579 * indent-tabs-mode: t
583 * vim:noexpandtab:sw=4:ts=4: