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