merged volatile memory barriers
[cacao.git] / src / vm / classcache.hpp
1 /* src/vm/classcache.hpp - loaded class cache and loading constraints
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _CLASSCACHE_H
27 #define _CLASSCACHE_H
28
29 #include "config.h"
30
31 #include "vm/types.h"
32
33 #include <stdio.h>  /* for FILE */
34
35 #include "toolbox/hashtable.h"
36
37 #include "vm/class.hpp"
38 #include "vm/global.h"
39 #include "vm/loader.hpp"
40 #include "vm/references.h"
41
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 /* forward declarations *******************************************************/
48
49 typedef struct classcache_name_entry classcache_name_entry;
50 typedef struct classcache_class_entry classcache_class_entry;
51 typedef struct classcache_loader_entry classcache_loader_entry;
52
53 /* global variables ***********************************************************/
54
55 extern hashtable hashtable_classcache;
56
57
58 /* structs ********************************************************************/
59
60 /*----------------------------------------------------------------------------*/
61 /* The Loaded Class Cache                                                     */
62 /*                                                                            */
63 /* The loaded class cache is implemented as a two-level data structure.       */
64 /*                                                                            */
65 /* The first level is a hash table indexed by class names. For each class     */
66 /* name in the cache there is a classcache_name_entry, which collects all     */
67 /* information about classes with this class name.                            */
68 /*                                                                            */
69 /* Second level: For each classcache_name_entry there is a list of            */
70 /* classcache_class_entry:s representing the possible different resolutions   */
71 /* of the class name.                                                         */
72 /*                                                                            */
73 /* A classcache_class_entry records the following:                            */
74 /*                                                                            */
75 /* - the loaded class object, if this entry has been resolved, otherwise NULL */
76 /* - the list of initiating loaders which have resolved the class name to     */
77 /*   this class object                                                        */
78 /* - the list of initiating loaders which are constrained to resolve this     */
79 /*   class name to this class object in the future                            */
80 /*                                                                            */
81 /* The classcache_class_entry:s approximate the equivalence classes created   */
82 /* by the loading constraints and the equivalence of loaded classes.          */
83 /*                                                                            */
84 /* When a loading constraint (loaderA,loaderB,NAME) is added, then the        */
85 /* classcache_class_entry:s for NAME containing loaderA and loaderB resp.     */
86 /* must be merged into one entry. If this is impossible, because the entries  */
87 /* have already been resolved to different class objects, then the constraint */
88 /* is violated and an expception must be thrown.                              */
89 /*----------------------------------------------------------------------------*/
90
91
92 /* classcache_name_entry
93  *
94  * For each classname a classcache_name_entry struct is created.
95  */
96
97 struct classcache_name_entry
98 {
99         utf                     *name;        /* class name                       */
100         classcache_name_entry   *hashlink;    /* link for external chaining       */
101         classcache_class_entry  *classes;     /* equivalence classes for this name*/
102 };
103
104 struct classcache_class_entry
105 {
106         classinfo               *classobj;    /* the loaded class object, or NULL */
107         classcache_loader_entry *loaders;
108         classcache_loader_entry *constraints;
109         classcache_class_entry  *next;        /* next class entry for same name   */
110 };
111
112 struct classcache_loader_entry
113 {
114         classloader_t            *loader;     /* class loader object              */
115         classcache_loader_entry  *next;       /* next loader entry in the list    */
116 };
117
118
119 /* callback function type for  classcache_foreach_loaded_class */
120
121 typedef void (*classcache_foreach_functionptr_t)(classinfo *, void *);
122
123
124 /* function prototypes ********************************************************/
125
126 /* initialize the loaded class cache */
127 bool classcache_init(void);
128 void classcache_free(void);
129
130 classinfo * classcache_lookup(classloader_t *initloader,utf *classname);
131 classinfo * classcache_lookup_defined(classloader_t *defloader,utf *classname);
132 classinfo * classcache_lookup_defined_or_initiated(classloader_t *loader,utf *classname);
133
134 bool classcache_store_unique(classinfo *cls);
135 classinfo * classcache_store(classloader_t *initloader,classinfo *cls,bool mayfree);
136 classinfo * classcache_store_defined(classinfo *cls);
137
138 #if defined(ENABLE_VERIFIER)
139 bool classcache_add_constraint(classloader_t *a,classloader_t *b,utf *classname);
140 bool classcache_add_constraints_for_params(classloader_t *a,classloader_t *b,
141                                                                                    methodinfo *m);
142 #endif
143
144 s4 classcache_get_loaded_class_count(void);
145
146 void classcache_foreach_loaded_class(classcache_foreach_functionptr_t func,
147                                                                          void *data);
148
149 #ifndef NDEBUG
150 void classcache_debug_dump(FILE *file,utf *only);
151 #endif
152         
153 #ifdef __cplusplus
154 }
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