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