extended type system to use symbolic references
[cacao.git] / src / vm / classcache.h
1 /* src/vm/classcache.h - loaded class cache and loading constraints
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: classcache.h 2181 2005-04-01 16:53:33Z edwin $
32
33 */
34
35
36 #ifndef _CLASSCACHE_H
37 #define _CLASSCACHE_H
38
39 #include <stdio.h>  /* for FILE */
40
41 #include "vm/references.h"
42
43
44 /* forward declarations *******************************************************/
45
46 typedef struct classcache_name_entry classcache_name_entry;
47 typedef struct classcache_class_entry classcache_class_entry;
48 typedef struct classcache_loader_entry classcache_loader_entry;
49
50 typedef java_objectheader classloader;
51
52 /* structs ********************************************************************/
53
54
55 /*----------------------------------------------------------------------------*/
56 /* The Loaded Class Cache                                                     */
57 /*                                                                            */
58 /* The loaded class cache is implemented as a two-level data structure.       */
59 /*                                                                            */
60 /* The first level is a hash table indexed by class names. For each class     */
61 /* name in the cache there is a classcache_name_entry, which collects all     */
62 /* information about classes with this class name.                            */
63 /*                                                                            */
64 /* Second level: For each classcache_name_entry there is a list of            */
65 /* classcache_class_entry:s representing the possible different resolutions   */
66 /* of the class name.                                                         */
67 /*                                                                            */
68 /* A classcache_class_entry records the following:                            */
69 /*                                                                            */
70 /* - the loaded class object, if this entry has been resolved, otherwise NULL */
71 /* - the list of initiating loaders which have resolved the class name to     */
72 /*   this class object                                                        */
73 /* - the list of initiating loaders which are constrained to resolve this     */
74 /*   class name to this class object in the future                            */
75 /*                                                                            */
76 /* The classcache_class_entry:s approximate the equivalence classes created   */
77 /* by the loading constraints and (XXX?) the equivalence of loaded classes.   */
78 /*                                                                            */
79 /* When a loading constraint (loaderA,loaderB,NAME) is added, then the        */
80 /* classcache_class_entry:s for NAME containing loaderA and loaderB resp.     */
81 /* must be merged into one entry. If this is impossible, because the entries  */
82 /* have already been resolved to different class objects, then the constraint */
83 /* is violated and an expception must be thrown.                              */
84 /*----------------------------------------------------------------------------*/
85
86
87 /* classcache_name_entry
88  *
89  * For each classname a classcache_name_entry struct is created.
90  */
91
92 struct classcache_name_entry
93 {
94         utf                     *name;        /* class name                       */
95         classcache_name_entry   *hashlink;        /* link for external chaining       */
96         classcache_class_entry  *classes;     /* equivalence classes for this name*/
97 };
98
99 struct classcache_class_entry
100 {
101         classinfo               *classobj;    /* the loaded class object, or NULL */
102         classcache_loader_entry *loaders;
103         classcache_loader_entry *constraints;
104         classcache_class_entry  *next;        /* next class entry for same name   */
105 };
106
107 struct classcache_loader_entry
108 {
109         classloader              *loader;     /* class loader object              */
110         classcache_loader_entry  *next;       /* next loader entry in the list    */
111 };
112
113 /* function prototypes ********************************************************/
114
115 /* classcache_init *************************************************************
116  
117    Initialize the loaded class cache
118   
119 *******************************************************************************/
120
121 void classcache_init();
122
123 /* classcache_free *************************************************************
124  
125    Free the memory used by the class cache
126
127    NOTE:
128        The class cache may not be used any more after this call, except
129            when it is reinitialized with classcache_init.
130   
131 *******************************************************************************/
132
133 void classcache_free();
134
135 /* classcache_lookup ***********************************************************
136  
137    Lookup a possibly loaded class
138   
139    IN:
140        initloader.......initiating loader for resolving the class name
141        classname........class name to look up
142   
143    RETURN VALUE:
144        The return value is a pointer to the cached class object,
145        or NULL, if the class is not in the cache.
146    
147 *******************************************************************************/
148
149 classinfo * classcache_lookup(classloader *initloader,utf *classname);
150
151 /* classcache_store ************************************************************
152    
153    Store a loaded class
154   
155    IN:
156        initloader.......initiating loader used to load the class
157        cls..............class object to cache
158   
159    RETURN VALUE:
160        true.............everything ok, the class was stored in
161                         the cache if necessary,
162        false............an exception has been thrown.
163    
164 *******************************************************************************/
165
166 bool classcache_store(classloader *initloader,classinfo *cls);
167
168 /* classcache_add_constraint ***************************************************
169  
170    Add a loading constraint
171   
172    IN:
173        a................first initiating loader
174        b................second initiating loader
175        classname........class name
176   
177    RETURN VALUE:
178        true.............everything ok, the constraint has been added,
179        false............an exception has been thrown.
180    
181 *******************************************************************************/
182
183 bool classcache_add_constraint(classloader *a,classloader *b,utf *classname);
184
185 /* classcache_debug_dump *******************************************************
186  
187    Print the contents of the loaded class cache to a stream
188   
189    IN:
190        file.............output stream
191   
192 *******************************************************************************/
193
194 void classcache_debug_dump(FILE *file);
195         
196 #endif /* _CLASSCACHE_H */
197
198 /*
199  * These are local overrides for various environment variables in Emacs.
200  * Please do not remove this and leave it at the end of the file, where
201  * Emacs will automagically detect them.
202  * ---------------------------------------------------------------------
203  * Local variables:
204  * mode: c
205  * indent-tabs-mode: t
206  * c-basic-offset: 4
207  * tab-width: 4
208  * End:
209  * vim:noexpandtab:sw=4:ts=4:
210  */
211