* Removed all Id tags.
[cacao.git] / src / vmcore / classcache.h
1 /* src/vmcore/classcache.h - loaded class cache and loading constraints
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #ifndef _CLASSCACHE_H
29 #define _CLASSCACHE_H
30
31 #include "config.h"
32 #include "vm/types.h"
33
34 #include <stdio.h>  /* for FILE */
35
36 #if defined(ENABLE_JVMTI)
37 # include "native/jni.h"
38 #endif
39
40 #include "toolbox/hashtable.h"
41
42 #include "vm/global.h"
43
44 #include "vmcore/class.h"
45 #include "vmcore/references.h"
46
47
48 /* forward declarations *******************************************************/
49
50 typedef struct classcache_name_entry classcache_name_entry;
51 typedef struct classcache_class_entry classcache_class_entry;
52 typedef struct classcache_loader_entry classcache_loader_entry;
53
54 /* global variables ***********************************************************/
55
56 extern hashtable hashtable_classcache;
57
58
59 /* structs ********************************************************************/
60
61 /*----------------------------------------------------------------------------*/
62 /* The Loaded Class Cache                                                     */
63 /*                                                                            */
64 /* The loaded class cache is implemented as a two-level data structure.       */
65 /*                                                                            */
66 /* The first level is a hash table indexed by class names. For each class     */
67 /* name in the cache there is a classcache_name_entry, which collects all     */
68 /* information about classes with this class name.                            */
69 /*                                                                            */
70 /* Second level: For each classcache_name_entry there is a list of            */
71 /* classcache_class_entry:s representing the possible different resolutions   */
72 /* of the class name.                                                         */
73 /*                                                                            */
74 /* A classcache_class_entry records the following:                            */
75 /*                                                                            */
76 /* - the loaded class object, if this entry has been resolved, otherwise NULL */
77 /* - the list of initiating loaders which have resolved the class name to     */
78 /*   this class object                                                        */
79 /* - the list of initiating loaders which are constrained to resolve this     */
80 /*   class name to this class object in the future                            */
81 /*                                                                            */
82 /* The classcache_class_entry:s approximate the equivalence classes created   */
83 /* by the loading constraints and the equivalence of loaded classes.          */
84 /*                                                                            */
85 /* When a loading constraint (loaderA,loaderB,NAME) is added, then the        */
86 /* classcache_class_entry:s for NAME containing loaderA and loaderB resp.     */
87 /* must be merged into one entry. If this is impossible, because the entries  */
88 /* have already been resolved to different class objects, then the constraint */
89 /* is violated and an expception must be thrown.                              */
90 /*----------------------------------------------------------------------------*/
91
92
93 /* classcache_name_entry
94  *
95  * For each classname a classcache_name_entry struct is created.
96  */
97
98 struct classcache_name_entry
99 {
100         utf                     *name;        /* class name                       */
101         classcache_name_entry   *hashlink;    /* link for external chaining       */
102         classcache_class_entry  *classes;     /* equivalence classes for this name*/
103 };
104
105 struct classcache_class_entry
106 {
107         classinfo               *classobj;    /* the loaded class object, or NULL */
108         classcache_loader_entry *loaders;
109         classcache_loader_entry *constraints;
110         classcache_class_entry  *next;        /* next class entry for same name   */
111 };
112
113 struct classcache_loader_entry
114 {
115         classloader              *loader;     /* class loader object              */
116         classcache_loader_entry  *next;       /* next loader entry in the list    */
117 };
118
119
120 /* callback function type for  classcache_foreach_loaded_class */
121
122 typedef void (*classcache_foreach_functionptr_t)(classinfo *, void *);
123
124
125 /* function prototypes ********************************************************/
126
127 /* initialize the loaded class cache */
128 bool classcache_init(void);
129 void classcache_free(void);
130
131 classinfo * classcache_lookup(classloader *initloader,utf *classname);
132 classinfo * classcache_lookup_defined(classloader *defloader,utf *classname);
133 classinfo * classcache_lookup_defined_or_initiated(classloader *loader,utf *classname);
134
135 bool classcache_store_unique(classinfo *cls);
136 classinfo * classcache_store(classloader *initloader,classinfo *cls,bool mayfree);
137 classinfo * classcache_store_defined(classinfo *cls);
138
139 #if defined(ENABLE_VERIFIER)
140 bool classcache_add_constraint(classloader *a,classloader *b,utf *classname);
141 bool classcache_add_constraints_for_params(classloader *a,classloader *b,
142                                                                                    methodinfo *m);
143 #endif
144
145 s4 classcache_get_loaded_class_count(void);
146
147 void classcache_foreach_loaded_class(classcache_foreach_functionptr_t func,
148                                                                          void *data);
149
150 #if defined(ENABLE_JVMTI)
151 void classcache_get_loaded_classes(s4 *class_count_ptr,
152                                                                    classinfo ***classes_ptr);
153 #endif
154
155 #ifndef NDEBUG
156 void classcache_debug_dump(FILE *file,utf *only);
157 #endif
158         
159 #endif /* _CLASSCACHE_H */
160
161 /*
162  * These are local overrides for various environment variables in Emacs.
163  * Please do not remove this and leave it at the end of the file, where
164  * Emacs will automagically detect them.
165  * ---------------------------------------------------------------------
166  * Local variables:
167  * mode: c
168  * indent-tabs-mode: t
169  * c-basic-offset: 4
170  * tab-width: 4
171  * End:
172  * vim:noexpandtab:sw=4:ts=4:
173  */
174