dont use stack in create_unresolved_ functions if no typeinfo available
[cacao.git] / src / vm / resolve.h
1 /* vm/resolve.h - resolving classes/interfaces/fields/methods
2
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
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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Edwin Steiner
28
29    Changes:
30
31    $Id: resolve.h 2217 2005-04-05 10:26:33Z edwin $
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 "vm/global.h"
48 #include "vm/references.h"
49 #include "vm/jit/jit.h"
50
51
52 /* constants ******************************************************************/
53
54 #define RESOLVE_STATIC    0x0001
55 #define RESOLVE_PUTFIELD  0x0002
56
57
58 /* enums **********************************************************************/
59
60 typedef enum {
61         resolveLazy,
62         resolveEager
63 } resolve_mode_t;
64
65
66 typedef enum {
67         resolveLinkageError,
68         resolveIllegalAccessError
69 } resolve_err_t;
70
71
72 /* structs ********************************************************************/
73
74 struct unresolved_subtype_set {
75         classref_or_classinfo *subtyperefs;     /* NULL terminated list */
76 };
77
78 struct unresolved_class {
79         constant_classref      *classref;
80         methodinfo                     *referermethod;
81         unresolved_subtype_set  subtypeconstraints;
82 };
83
84 /* XXX unify heads of unresolved_field and unresolved_method? */
85
86 struct unresolved_field {
87         constant_FMIref *fieldref;
88         methodinfo      *referermethod;
89         s4               flags;
90         
91         unresolved_subtype_set  instancetypes;
92         unresolved_subtype_set  valueconstraints;
93 };
94
95 struct unresolved_method {
96         constant_FMIref *methodref;
97         methodinfo      *referermethod;
98         s4               flags;
99         
100         unresolved_subtype_set  instancetypes;
101         unresolved_subtype_set *paramconstraints;
102 };
103
104 #define SUBTYPESET_IS_EMPTY(stset) \
105         ((stset).subtyperefs == NULL)
106
107 #define UNRESOLVED_SUBTYPE_SET_EMTPY(stset) \
108         do { (stset).subtyperefs = NULL; } while(0)
109
110 /* function prototypes ********************************************************/
111
112 /* resolve_class_from_name *****************************************************
113  
114    Resolve a symbolic class reference
115   
116    IN:
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   
126    OUT:
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.
131   
132    RETURN VALUE:
133        true.............everything ok 
134                         (*result may still be NULL for resolveLazy)
135        false............an exception has been thrown
136
137    NOTE:
138        The returned class is *not* guaranteed to be linked!
139            (It is guaranteed to be loaded, though.)
140    
141 *******************************************************************************/
142
143 bool
144 resolve_class_from_name(classinfo* referer,methodinfo *refmethod,
145                                                 utf *classname,
146                                                 resolve_mode_t mode,
147                                                 classinfo **result);
148
149 /* resolve_classref ************************************************************
150  
151    Resolve a symbolic class reference
152   
153    IN:
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,
162                             has been linked
163   
164    OUT:
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.
169   
170    RETURN VALUE:
171        true.............everything ok 
172                         (*result may still be NULL for resolveLazy)
173        false............an exception has been thrown
174    
175 *******************************************************************************/
176
177 bool
178 resolve_classref(methodinfo *refmethod,
179                                  constant_classref *ref,
180                                  resolve_mode_t mode,
181                              bool link,
182                                  classinfo **result);
183
184 /* resolve_classref_or_classinfo ***********************************************
185  
186    Resolve a symbolic class reference if necessary
187   
188    IN:
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,
197                             has been linked
198   
199    OUT:
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.
204   
205    RETURN VALUE:
206        true.............everything ok 
207                         (*result may still be NULL for resolveLazy)
208        false............an exception has been thrown
209    
210 *******************************************************************************/
211
212 bool
213 resolve_classref_or_classinfo(methodinfo *refmethod,
214                                                           classref_or_classinfo cls,
215                                                           resolve_mode_t mode,
216                                                           bool link,
217                                                           classinfo **result);
218
219 /* resolve_class_from_typedesc *************************************************
220  
221    Return a classinfo * for the given type descriptor
222   
223    IN:
224        d................type descriptor
225            link.............if true, guarantee that the returned class, if any,
226                             has been linked
227    OUT:
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.
232   
233    RETURN VALUE:
234        true.............everything ok 
235        false............an exception has been thrown
236
237    NOTE:
238        This function always resolved eagerly.
239    
240 *******************************************************************************/
241
242 bool resolve_class_from_typedesc(typedesc *d,bool link,classinfo **result);
243
244 /* resolve_class ***************************************************************
245  
246    Resolve an unresolved class reference
247   
248    IN:
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
254   
255    OUT:
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.
260   
261    RETURN VALUE:
262        true.............everything ok 
263                         (*result may still be NULL for resolveLazy)
264        false............an exception has been thrown
265    
266 *******************************************************************************/
267
268 bool
269 resolve_class(unresolved_class *ref,
270                           resolve_mode_t mode,
271                           classinfo **result);
272
273 /* resolve_field ***************************************************************
274  
275    Resolve an unresolved field reference
276   
277    IN:
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
283   
284    OUT:
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.
289   
290    RETURN VALUE:
291        true.............everything ok 
292                         (*result may still be NULL for resolveLazy)
293        false............an exception has been thrown
294    
295 *******************************************************************************/
296
297 bool
298 resolve_field(unresolved_field *ref,
299                           resolve_mode_t mode,
300                           fieldinfo **result);
301
302 /* resolve_method **************************************************************
303  
304    Resolve an unresolved method reference
305   
306    IN:
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
312   
313    OUT:
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.
318   
319    RETURN VALUE:
320        true.............everything ok 
321                         (*result may still be NULL for resolveLazy)
322        false............an exception has been thrown
323    
324 *******************************************************************************/
325
326 bool
327 resolve_method(unresolved_method *ref,
328                           resolve_mode_t mode,
329                            methodinfo **result);
330
331 /* resolve_and_check_subtype_set ***********************************************
332  
333    Resolve the references in the given set and test subtype relationships
334   
335    IN:
336        referer..........the class containing the references
337        refmethod........the method triggering the resolution
338        ref..............a set of class/interface references
339                         (may be empty)
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
343                         way round
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
352
353    OUT:
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.
359   
360    RETURN VALUE:
361        true.............the check succeeded
362        false............the check failed. An exception has been
363                         thrown.
364    
365    NOTE:
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.
369    
370 *******************************************************************************/
371
372 bool
373 resolve_and_check_subtype_set(classinfo *referer,methodinfo *refmethod,
374                                                           unresolved_subtype_set *ref,
375                                                           classref_or_classinfo type,
376                                                           bool reversed,
377                                                           resolve_mode_t mode,
378                                                           resolve_err_t error,
379                                                           bool *checked);
380
381 /* create_unresolved_class *****************************************************
382  
383    Create an unresolved_class struct for the given class reference
384   
385    IN:
386            refmethod........the method triggering the resolution (if any)
387            classref.........the class reference
388            valuetype........value type to check against the resolved class
389                                                 may be NULL, if no typeinfo is available
390
391    RETURN VALUE:
392        a pointer to a new unresolved_class struct
393
394 *******************************************************************************/
395
396 unresolved_class *
397 create_unresolved_class(methodinfo *refmethod,
398                                                 constant_classref *classref,
399                                                 typeinfo *valuetype);
400
401 /* create_unresolved_field *****************************************************
402  
403    Create an unresolved_field struct for the given field access instruction
404   
405    IN:
406        referer..........the class containing the reference
407            refmethod........the method triggering the resolution (if any)
408            iptr.............the {GET,PUT}{FIELD,STATIC}{,CONST} instruction
409            stack............the input stack of the instruction
410                             NULL if no typeinfo is available
411
412    RETURN VALUE:
413        a pointer to a new unresolved_field struct
414
415 *******************************************************************************/
416
417 unresolved_field *
418 create_unresolved_field(classinfo *referer,methodinfo *refmethod,
419                                                 instruction *iptr,
420                                                 stackelement *stack);
421
422 /* create_unresolved_method ****************************************************
423  
424    Create an unresolved_method struct for the given method invocation
425   
426    IN:
427        referer..........the class containing the reference
428            refmethod........the method triggering the resolution (if any)
429            iptr.............the INVOKE* instruction
430            stack............the input stack of the instruction
431                             NULL if no typeinfo is available
432
433    RETURN VALUE:
434        a pointer to a new unresolved_method struct
435
436 *******************************************************************************/
437
438 unresolved_method *
439 create_unresolved_method(classinfo *referer,methodinfo *refmethod,
440                                                  instruction *iptr,
441                                                  stackelement *stack);
442
443 /* unresolved_class_free *******************************************************
444  
445    Free the memory used by an unresolved_class
446   
447    IN:
448        ref..............the unresolved_class
449
450 *******************************************************************************/
451
452 void unresolved_class_free(unresolved_class *ref);
453
454 /* unresolved_field_free *******************************************************
455  
456    Free the memory used by an unresolved_field
457   
458    IN:
459        ref..............the unresolved_field
460
461 *******************************************************************************/
462
463 void unresolved_field_free(unresolved_field *ref);
464
465 /* unresolved_method_free ******************************************************
466  
467    Free the memory used by an unresolved_method
468   
469    IN:
470        ref..............the unresolved_method
471
472 *******************************************************************************/
473
474 void unresolved_method_free(unresolved_method *ref);
475
476 /* unresolved_class_debug_dump *************************************************
477  
478    Print debug info for unresolved_class to stream
479   
480    IN:
481        ref..............the unresolved_class
482            file.............the stream
483
484 *******************************************************************************/
485
486 void unresolved_class_debug_dump(unresolved_class *ref,FILE *file);
487
488 /* unresolved_field_debug_dump *************************************************
489  
490    Print debug info for unresolved_field to stream
491   
492    IN:
493        ref..............the unresolved_field
494            file.............the stream
495
496 *******************************************************************************/
497
498 void unresolved_field_debug_dump(unresolved_field *ref,FILE *file);
499
500 /* unresolved_method_debug_dump ************************************************
501  
502    Print debug info for unresolved_method to stream
503   
504    IN:
505        ref..............the unresolved_method
506            file.............the stream
507
508 *******************************************************************************/
509
510 void unresolved_method_debug_dump(unresolved_method *ref,FILE *file);
511
512 /* unresolved_subtype_set_debug_dump *******************************************
513  
514    Print debug info for unresolved_subtype_set to stream
515   
516    IN:
517        stset............the unresolved_subtype_set
518            file.............the stream
519
520 *******************************************************************************/
521
522 void unresolved_subtype_set_debug_dump(unresolved_subtype_set *stset,FILE *file);
523         
524 #endif /* _RESOLVE_H */
525
526 /*
527  * These are local overrides for various environment variables in Emacs.
528  * Please do not remove this and leave it at the end of the file, where
529  * Emacs will automagically detect them.
530  * ---------------------------------------------------------------------
531  * Local variables:
532  * mode: c
533  * indent-tabs-mode: t
534  * c-basic-offset: 4
535  * tab-width: 4
536  * End:
537  * vim:noexpandtab:sw=4:ts=4:
538  */
539