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