1 /* src/vmcore/classcache.h - loaded class cache and loading constraints
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
8 This file is part of CACAO.
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.
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.
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
34 #include <stdio.h> /* for FILE */
36 #if defined(ENABLE_JVMTI)
37 # include "native/jni.h"
40 #include "toolbox/hashtable.h"
42 #include "vm/global.h"
44 #include "vmcore/class.h"
45 #include "vmcore/loader.h"
46 #include "vmcore/references.h"
49 /* forward declarations *******************************************************/
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;
55 /* global variables ***********************************************************/
57 extern hashtable hashtable_classcache;
60 /* structs ********************************************************************/
62 /*----------------------------------------------------------------------------*/
63 /* The Loaded Class Cache */
65 /* The loaded class cache is implemented as a two-level data structure. */
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. */
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. */
75 /* A classcache_class_entry records the following: */
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 */
83 /* The classcache_class_entry:s approximate the equivalence classes created */
84 /* by the loading constraints and the equivalence of loaded classes. */
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 /*----------------------------------------------------------------------------*/
94 /* classcache_name_entry
96 * For each classname a classcache_name_entry struct is created.
99 struct classcache_name_entry
101 utf *name; /* class name */
102 classcache_name_entry *hashlink; /* link for external chaining */
103 classcache_class_entry *classes; /* equivalence classes for this name*/
106 struct classcache_class_entry
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 */
114 struct classcache_loader_entry
116 classloader *loader; /* class loader object */
117 classcache_loader_entry *next; /* next loader entry in the list */
121 /* callback function type for classcache_foreach_loaded_class */
123 typedef void (*classcache_foreach_functionptr_t)(classinfo *, void *);
126 /* function prototypes ********************************************************/
128 /* initialize the loaded class cache */
129 bool classcache_init(void);
130 void classcache_free(void);
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);
136 bool classcache_store_unique(classinfo *cls);
137 classinfo * classcache_store(classloader *initloader,classinfo *cls,bool mayfree);
138 classinfo * classcache_store_defined(classinfo *cls);
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,
146 s4 classcache_get_loaded_class_count(void);
148 void classcache_foreach_loaded_class(classcache_foreach_functionptr_t func,
151 #if defined(ENABLE_JVMTI)
152 void classcache_get_loaded_classes(s4 *class_count_ptr,
153 classinfo ***classes_ptr);
157 void classcache_debug_dump(FILE *file,utf *only);
160 #endif /* _CLASSCACHE_H */
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 * ---------------------------------------------------------------------
169 * indent-tabs-mode: t
173 * vim:noexpandtab:sw=4:ts=4: