CACAO
classcache.hpp
Go to the documentation of this file.
1 /* src/vm/classcache.hpp - loaded class cache and loading constraints
2 
3  Copyright (C) 1996-2013
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_HPP_
27 #define CLASSCACHE_HPP_ 1
28 
29 #include "config.h"
30 
31 #include "vm/types.hpp"
32 
33 #include <stdio.h> /* for FILE */
34 
35 #include "toolbox/hashtable.hpp"
36 
37 #include "vm/loader.hpp"
38 
39 struct classinfo;
40 
41 /* forward declarations *******************************************************/
42 
46 
47 /* global variables ***********************************************************/
48 
50 
51 
52 /* structs ********************************************************************/
53 
54 /*----------------------------------------------------------------------------*/
55 /* The Loaded Class Cache */
56 /* */
57 /* The loaded class cache is implemented as a two-level data structure. */
58 /* */
59 /* The first level is a hash table indexed by class names. For each class */
60 /* name in the cache there is a classcache_name_entry, which collects all */
61 /* information about classes with this class name. */
62 /* */
63 /* Second level: For each classcache_name_entry there is a list of */
64 /* classcache_class_entry:s representing the possible different resolutions */
65 /* of the class name. */
66 /* */
67 /* A classcache_class_entry records the following: */
68 /* */
69 /* - the loaded class object, if this entry has been resolved, otherwise NULL */
70 /* - the list of initiating loaders which have resolved the class name to */
71 /* this class object */
72 /* - the list of initiating loaders which are constrained to resolve this */
73 /* class name to this class object in the future */
74 /* */
75 /* The classcache_class_entry:s approximate the equivalence classes created */
76 /* by the loading constraints and the equivalence of loaded classes. */
77 /* */
78 /* When a loading constraint (loaderA,loaderB,NAME) is added, then the */
79 /* classcache_class_entry:s for NAME containing loaderA and loaderB resp. */
80 /* must be merged into one entry. If this is impossible, because the entries */
81 /* have already been resolved to different class objects, then the constraint */
82 /* is violated and an expception must be thrown. */
83 /*----------------------------------------------------------------------------*/
84 
85 
86 /* classcache_name_entry
87  *
88  * For each classname a classcache_name_entry struct is created.
89  */
90 
92 {
93  Utf8String name; /* class name */
94  classcache_name_entry *hashlink; /* link for external chaining */
95  classcache_class_entry *classes; /* equivalence classes for this name*/
96 };
97 
99 {
100  classinfo *classobj; /* the loaded class object, or NULL */
103  classcache_class_entry *next; /* next class entry for same name */
104 };
105 
107 {
108  classloader_t *loader; /* class loader object */
109  classcache_loader_entry *next; /* next loader entry in the list */
110 };
111 
112 
113 /* callback function type for classcache_foreach_loaded_class */
114 
116 
117 
118 /* function prototypes ********************************************************/
119 
120 /* initialize the loaded class cache */
121 bool classcache_init(void);
122 void classcache_free(void);
123 
124 classinfo * classcache_lookup(classloader_t *initloader,Utf8String classname);
127 
129 classinfo * classcache_store(classloader_t *initloader,classinfo *cls,bool mayfree);
131 
132 #if defined(ENABLE_VERIFIER)
135  methodinfo *m);
136 #endif
137 
139 
141  void *data);
142 
143 #ifndef NDEBUG
144 void classcache_debug_dump(FILE *file,Utf8String only);
145 #endif
146 
147 #endif // CLASSCACHE_HPP_
148 
149 
150 /*
151  * These are local overrides for various environment variables in Emacs.
152  * Please do not remove this and leave it at the end of the file, where
153  * Emacs will automagically detect them.
154  * ---------------------------------------------------------------------
155  * Local variables:
156  * mode: c++
157  * indent-tabs-mode: t
158  * c-basic-offset: 4
159  * tab-width: 4
160  * End:
161  * vim:noexpandtab:sw=4:ts=4:
162  */
163 
classcache_loader_entry * loaders
Definition: classcache.hpp:101
classinfo * classcache_lookup_defined_or_initiated(classloader_t *loader, Utf8String classname)
Definition: classcache.cpp:662
classinfo * classcache_lookup(classloader_t *initloader, Utf8String classname)
Definition: classcache.cpp:564
bool classcache_add_constraints_for_params(classloader_t *a, classloader_t *b, methodinfo *m)
classcache_class_entry * next
Definition: classcache.hpp:103
classinfo * classcache_store_defined(classinfo *cls)
Definition: classcache.cpp:917
typedef void(JNICALL *jvmtiEventSingleStep)(jvmtiEnv *jvmti_env
void classcache_debug_dump(FILE *file, Utf8String only)
void classcache_free(void)
classloader_t * loader
Definition: classcache.hpp:108
hashtable hashtable_classcache
Definition: classcache.cpp:223
classinfo * classcache_store(classloader_t *initloader, classinfo *cls, bool mayfree)
Definition: classcache.cpp:730
void(* classcache_foreach_functionptr_t)(classinfo *, void *)
Definition: classcache.hpp:115
classcache_class_entry * classes
Definition: classcache.hpp:95
classcache_loader_entry * constraints
Definition: classcache.hpp:102
bool classcache_store_unique(classinfo *cls)
Definition: classcache.cpp:883
Definition: classcache.hpp:106
int32_t s4
Definition: types.hpp:45
JNIEnv jclass jobject loader
Definition: jvmti.h:312
bool classcache_init(void)
Definition: classcache.cpp:247
Utf8String name
Definition: classcache.hpp:93
Definition: classcache.hpp:98
void classcache_foreach_loaded_class(classcache_foreach_functionptr_t func, void *data)
s4 classcache_get_loaded_class_count(void)
bool classcache_add_constraint(classloader_t *a, classloader_t *b, Utf8String classname)
classcache_name_entry * hashlink
Definition: classcache.hpp:94
classinfo * classcache_lookup_defined(classloader_t *defloader, Utf8String classname)
Definition: classcache.cpp:616
classcache_loader_entry * next
Definition: classcache.hpp:109
classinfo * classobj
Definition: classcache.hpp:100
Definition: classcache.hpp:91