* src/vm/jit/powerpc/linux/md-abi.h (LA_WORD_SIZE): Renamed to
[cacao.git] / src / vm / classcache.h
1 /* src/vm/classcache.h - loaded class cache and loading constraints
2
3    Copyright (C) 1996-2005, 2006 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    Contact: cacao@cacaojvm.org
26
27    Authors: Edwin Steiner
28
29    Changes: Christian Thalinger
30
31    $Id: classcache.h 5192 2006-07-31 14:21:15Z twisti $
32
33 */
34
35
36 #ifndef _CLASSCACHE_H
37 #define _CLASSCACHE_H
38
39 #include "config.h"
40 #include "vm/types.h"
41
42 #include <stdio.h>  /* for FILE */
43
44 #if defined(ENABLE_JVMTI)
45 # include "native/jni.h"
46 #endif
47
48 #include "vm/hashtable.h"
49 #include "vm/references.h"
50
51
52 /* forward declarations *******************************************************/
53
54 typedef struct classcache_name_entry classcache_name_entry;
55 typedef struct classcache_class_entry classcache_class_entry;
56 typedef struct classcache_loader_entry classcache_loader_entry;
57
58 typedef java_objectheader classloader;
59
60 /* global variables ***********************************************************/
61
62 extern hashtable hashtable_classcache;
63
64
65 /* structs ********************************************************************/
66
67 /*----------------------------------------------------------------------------*/
68 /* The Loaded Class Cache                                                     */
69 /*                                                                            */
70 /* The loaded class cache is implemented as a two-level data structure.       */
71 /*                                                                            */
72 /* The first level is a hash table indexed by class names. For each class     */
73 /* name in the cache there is a classcache_name_entry, which collects all     */
74 /* information about classes with this class name.                            */
75 /*                                                                            */
76 /* Second level: For each classcache_name_entry there is a list of            */
77 /* classcache_class_entry:s representing the possible different resolutions   */
78 /* of the class name.                                                         */
79 /*                                                                            */
80 /* A classcache_class_entry records the following:                            */
81 /*                                                                            */
82 /* - the loaded class object, if this entry has been resolved, otherwise NULL */
83 /* - the list of initiating loaders which have resolved the class name to     */
84 /*   this class object                                                        */
85 /* - the list of initiating loaders which are constrained to resolve this     */
86 /*   class name to this class object in the future                            */
87 /*                                                                            */
88 /* The classcache_class_entry:s approximate the equivalence classes created   */
89 /* by the loading constraints and the equivalence of loaded classes.          */
90 /*                                                                            */
91 /* When a loading constraint (loaderA,loaderB,NAME) is added, then the        */
92 /* classcache_class_entry:s for NAME containing loaderA and loaderB resp.     */
93 /* must be merged into one entry. If this is impossible, because the entries  */
94 /* have already been resolved to different class objects, then the constraint */
95 /* is violated and an expception must be thrown.                              */
96 /*----------------------------------------------------------------------------*/
97
98
99 /* classcache_name_entry
100  *
101  * For each classname a classcache_name_entry struct is created.
102  */
103
104 struct classcache_name_entry
105 {
106         utf                     *name;        /* class name                       */
107         classcache_name_entry   *hashlink;    /* link for external chaining       */
108         classcache_class_entry  *classes;     /* equivalence classes for this name*/
109 };
110
111 struct classcache_class_entry
112 {
113         classinfo               *classobj;    /* the loaded class object, or NULL */
114         classcache_loader_entry *loaders;
115         classcache_loader_entry *constraints;
116         classcache_class_entry  *next;        /* next class entry for same name   */
117 };
118
119 struct classcache_loader_entry
120 {
121         classloader              *loader;     /* class loader object              */
122         classcache_loader_entry  *next;       /* next loader entry in the list    */
123 };
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 #if defined(ENABLE_JVMTI)
149 void classcache_get_loaded_classes(s4 *class_count_ptr,
150                                                                    classinfo ***classes_ptr);
151 #endif
152
153 #ifndef NDEBUG
154 void classcache_debug_dump(FILE *file,utf *only);
155 #endif
156         
157 #endif /* _CLASSCACHE_H */
158
159 /*
160  * These are local overrides for various environment variables in Emacs.
161  * Please do not remove this and leave it at the end of the file, where
162  * Emacs will automagically detect them.
163  * ---------------------------------------------------------------------
164  * Local variables:
165  * mode: c
166  * indent-tabs-mode: t
167  * c-basic-offset: 4
168  * tab-width: 4
169  * End:
170  * vim:noexpandtab:sw=4:ts=4:
171  */
172