1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_CLASSFILE_DICTIONARY_HPP
26 #define SHARE_VM_CLASSFILE_DICTIONARY_HPP
27
28 #include "classfile/systemDictionary.hpp"
29 #include "oops/instanceKlass.hpp"
30 #include "oops/oop.hpp"
31 #include "utilities/hashtable.hpp"
32
33 class DictionaryEntry;
34 class PSPromotionManager;
35
36 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 // The data structure for the system dictionary (and the shared system
38 // dictionary).
39
40 class Dictionary : public TwoOopHashtable<Klass*, mtClass> {
41 friend class VMStructs;
42 private:
43 // current iteration index.
44 static int _current_class_index;
45 // pointer to the current hash table entry.
46 static DictionaryEntry* _current_class_entry;
47
48 DictionaryEntry* get_entry(int index, unsigned int hash,
49 Symbol* name, ClassLoaderData* loader_data);
50
51 DictionaryEntry* bucket(int i) {
52 return (DictionaryEntry*)Hashtable<Klass*, mtClass>::bucket(i);
53 }
54
55 // The following method is not MT-safe and must be done under lock.
56 DictionaryEntry** bucket_addr(int i) {
57 return (DictionaryEntry**)Hashtable<Klass*, mtClass>::bucket_addr(i);
58 }
59
60 void add_entry(int index, DictionaryEntry* new_entry) {
61 Hashtable<Klass*, mtClass>::add_entry(index, (HashtableEntry<Klass*, mtClass>*)new_entry);
62 }
63
64 public:
65 Dictionary(int table_size);
66 Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries);
67
101 return (loader_data->is_the_null_class_loader_data() || !ClassUnloading);
102 }
103
104 // Unload (that is, break root links to) all unmarked classes and
105 // loaders. Returns "true" iff something was unloaded.
106 bool do_unloading();
107
108 // Protection domains
109 Klass* find(int index, unsigned int hash, Symbol* name,
110 ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
111 bool is_valid_protection_domain(int index, unsigned int hash,
112 Symbol* name, ClassLoaderData* loader_data,
113 Handle protection_domain);
114 void add_protection_domain(int index, unsigned int hash,
115 instanceKlassHandle klass, ClassLoaderData* loader_data,
116 Handle protection_domain, TRAPS);
117
118 // Sharing support
119 void reorder_dictionary();
120
121
122 #ifndef PRODUCT
123 void print();
124 #endif
125 void verify();
126 };
127
128 // The following classes can be in dictionary.cpp, but we need these
129 // to be in header file so that SA's vmStructs can access.
130
131 class ProtectionDomainEntry :public CHeapObj<mtClass> {
132 friend class VMStructs;
133 public:
134 ProtectionDomainEntry* _next;
135 oop _protection_domain;
136
137 ProtectionDomainEntry(oop protection_domain, ProtectionDomainEntry* next) {
138 _protection_domain = protection_domain;
139 _next = next;
140 }
141
142 ProtectionDomainEntry* next() { return _next; }
143 oop protection_domain() { return _protection_domain; }
144 };
145
146 // An entry in the system dictionary, this describes a class as
147 // { Klass*, loader, protection_domain }.
148
149 class DictionaryEntry : public HashtableEntry<Klass*, mtClass> {
150 friend class VMStructs;
151 private:
152 // Contains the set of approved protection domains that can access
153 // this system dictionary entry.
154 ProtectionDomainEntry* _pd_set;
155 ClassLoaderData* _loader_data;
156
157 public:
158 // Tells whether a protection is in the approved set.
159 bool contains_protection_domain(oop protection_domain) const;
160 // Adds a protection domain to the approved set.
161 void add_protection_domain(oop protection_domain);
162
163 Klass* klass() const { return (Klass*)literal(); }
164 Klass** klass_addr() { return (Klass**)literal_addr(); }
165
166 DictionaryEntry* next() const {
167 return (DictionaryEntry*)HashtableEntry<Klass*, mtClass>::next();
168 }
169
170 DictionaryEntry** next_addr() {
171 return (DictionaryEntry**)HashtableEntry<Klass*, mtClass>::next_addr();
172 }
173
174 ClassLoaderData* loader_data() const { return _loader_data; }
175 void set_loader_data(ClassLoaderData* loader_data) { _loader_data = loader_data; }
176
177 ProtectionDomainEntry* pd_set() const { return _pd_set; }
178 void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
179
180 bool has_protection_domain() { return _pd_set != NULL; }
181
182 // Tells whether the initiating class' protection can access the this _klass
183 bool is_valid_protection_domain(Handle protection_domain) {
184 if (!ProtectionDomainVerification) return true;
185 if (!SystemDictionary::has_checkPackageAccess()) return true;
186
187 return protection_domain() == NULL
188 ? true
189 : contains_protection_domain(protection_domain());
190 }
191
192
193 void protection_domain_set_oops_do(OopClosure* f) {
194 for (ProtectionDomainEntry* current = _pd_set;
195 current != NULL;
196 current = current->_next) {
197 f->do_oop(&(current->_protection_domain));
198 }
199 }
200
201 void verify_protection_domain_set() {
202 for (ProtectionDomainEntry* current = _pd_set;
203 current != NULL;
204 current = current->_next) {
205 current->_protection_domain->verify();
206 }
207 }
208
209 bool equals(Symbol* class_name, ClassLoaderData* loader_data) const {
210 Klass* klass = (Klass*)literal();
211 return (InstanceKlass::cast(klass)->name() == class_name &&
212 _loader_data == loader_data);
213 }
214
215 void print() {
216 int count = 0;
217 for (ProtectionDomainEntry* current = _pd_set;
218 current != NULL;
219 current = current->_next) {
220 count++;
221 }
222 tty->print_cr("pd set = #%d", count);
223 }
224 };
225
|
1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_CLASSFILE_DICTIONARY_HPP
26 #define SHARE_VM_CLASSFILE_DICTIONARY_HPP
27
28 #include "classfile/systemDictionary.hpp"
29 #include "oops/instanceKlass.hpp"
30 #include "oops/oop.inline.hpp"
31 #include "utilities/hashtable.hpp"
32
33 class DictionaryEntry;
34 class PSPromotionManager;
35 class ProtectionDomainCacheTable;
36 class ProtectionDomainCacheEntry;
37
38 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39 // The data structure for the system dictionary (and the shared system
40 // dictionary).
41
42 class Dictionary : public TwoOopHashtable<Klass*, mtClass> {
43 friend class VMStructs;
44 private:
45 // current iteration index.
46 static int _current_class_index;
47 // pointer to the current hash table entry.
48 static DictionaryEntry* _current_class_entry;
49
50 ProtectionDomainCacheTable* _pd_cache_table;
51
52 DictionaryEntry* get_entry(int index, unsigned int hash,
53 Symbol* name, ClassLoaderData* loader_data);
54
55 DictionaryEntry* bucket(int i) {
56 return (DictionaryEntry*)Hashtable<Klass*, mtClass>::bucket(i);
57 }
58
59 // The following method is not MT-safe and must be done under lock.
60 DictionaryEntry** bucket_addr(int i) {
61 return (DictionaryEntry**)Hashtable<Klass*, mtClass>::bucket_addr(i);
62 }
63
64 void add_entry(int index, DictionaryEntry* new_entry) {
65 Hashtable<Klass*, mtClass>::add_entry(index, (HashtableEntry<Klass*, mtClass>*)new_entry);
66 }
67
68 public:
69 Dictionary(int table_size);
70 Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries);
71
105 return (loader_data->is_the_null_class_loader_data() || !ClassUnloading);
106 }
107
108 // Unload (that is, break root links to) all unmarked classes and
109 // loaders. Returns "true" iff something was unloaded.
110 bool do_unloading();
111
112 // Protection domains
113 Klass* find(int index, unsigned int hash, Symbol* name,
114 ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
115 bool is_valid_protection_domain(int index, unsigned int hash,
116 Symbol* name, ClassLoaderData* loader_data,
117 Handle protection_domain);
118 void add_protection_domain(int index, unsigned int hash,
119 instanceKlassHandle klass, ClassLoaderData* loader_data,
120 Handle protection_domain, TRAPS);
121
122 // Sharing support
123 void reorder_dictionary();
124
125 ProtectionDomainCacheEntry* cache_get(oop protection_domain);
126
127 #ifndef PRODUCT
128 void print();
129 #endif
130 void verify();
131 };
132
133 // The following classes can be in dictionary.cpp, but we need these
134 // to be in header file so that SA's vmStructs can access them.
135 class ProtectionDomainCacheEntry : public HashtableEntry<oop, mtClass> {
136 friend class VMStructs;
137 private:
138 int _refcount;
139 int _scan_generation;
140 public:
141 oop protection_domain() { return literal(); }
142
143 void increment_refcount() {
144 assert(_refcount >= 0, "sanity");
145 _refcount++;
146 }
147
148 int refcount() { return _refcount; }
149 int decrement_refcount() {
150 assert(_refcount > 0, "sanity");
151 _refcount--;
152 return _refcount;
153 }
154
155 void init() {
156 _refcount = 0;
157 _scan_generation = 0;
158 }
159
160 ProtectionDomainCacheEntry* next() {
161 return (ProtectionDomainCacheEntry*)HashtableEntry<oop, mtClass>::next();
162 }
163
164 ProtectionDomainCacheEntry** next_addr() {
165 return (ProtectionDomainCacheEntry**)HashtableEntry<oop, mtClass>::next_addr();
166 }
167
168 void oops_do(OopClosure* f) {
169 f->do_oop(literal_addr());
170 }
171
172 void set_strongly_reachable(int gen) { _scan_generation = gen; }
173
174 bool is_strongly_reachable(int gen) { return _scan_generation == gen; }
175 };
176
177 class ProtectionDomainCacheTable : public Hashtable<oop, mtClass> {
178 friend class VMStructs;
179 private:
180 ProtectionDomainCacheEntry* bucket(int i) {
181 return (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::bucket(i);
182 }
183
184 // The following method is not MT-safe and must be done under lock.
185 ProtectionDomainCacheEntry** bucket_addr(int i) {
186 return (ProtectionDomainCacheEntry**) Hashtable<oop, mtClass>::bucket_addr(i);
187 }
188
189 ProtectionDomainCacheEntry* new_entry(unsigned int hash, oop protection_domain) {
190 ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain);
191 entry->init();
192 return entry;
193 }
194
195 unsigned int compute_hash(oop protection_domain) {
196 return (unsigned int)(protection_domain->identity_hash());
197 }
198
199 int index_for(oop protection_domain) {
200 return hash_to_index(compute_hash(protection_domain));
201 }
202
203 ProtectionDomainCacheEntry* add_entry(int index, unsigned int hash, oop protection_domain);
204 ProtectionDomainCacheEntry* find_entry(int index, oop protection_domain);
205
206 public:
207
208 ProtectionDomainCacheTable(int table_size);
209
210 ProtectionDomainCacheEntry* get(oop protection_domain);
211 void free(ProtectionDomainCacheEntry* entry);
212
213 // GC support
214 void oops_do(OopClosure* f);
215 void always_strong_oops_do(OopClosure* f, int gen);
216
217 #ifndef PRODUCT
218 void print();
219 #endif
220 void verify();
221 };
222
223
224 class ProtectionDomainEntry :public CHeapObj<mtClass> {
225 friend class VMStructs;
226 public:
227 ProtectionDomainEntry* _next;
228 ProtectionDomainCacheEntry* _pd_cache;
229
230 ProtectionDomainEntry(ProtectionDomainCacheEntry* pd_cache, ProtectionDomainEntry* next) {
231 _pd_cache = pd_cache;
232 _next = next;
233 _pd_cache->increment_refcount();
234 }
235
236 ProtectionDomainEntry* next() { return _next; }
237 oop protection_domain() { return _pd_cache->protection_domain(); }
238 ProtectionDomainCacheEntry * release_pd_cache() {
239 if (_pd_cache->decrement_refcount() == 0) {
240 return _pd_cache;
241 } else {
242 return NULL;
243 }
244 }
245 };
246
247 // An entry in the system dictionary, this describes a class as
248 // { Klass*, loader, protection_domain }.
249
250 class DictionaryEntry : public HashtableEntry<Klass*, mtClass> {
251 friend class VMStructs;
252 private:
253 // Contains the set of approved protection domains that can access
254 // this system dictionary entry.
255 ProtectionDomainEntry* _pd_set;
256 ClassLoaderData* _loader_data;
257
258 public:
259 // Tells whether a protection is in the approved set.
260 bool contains_protection_domain(oop protection_domain) const;
261 // Adds a protection domain to the approved set.
262 void add_protection_domain(Dictionary* dict, oop protection_domain);
263
264 Klass* klass() const { return (Klass*)literal(); }
265 Klass** klass_addr() { return (Klass**)literal_addr(); }
266
267 DictionaryEntry* next() const {
268 return (DictionaryEntry*)HashtableEntry<Klass*, mtClass>::next();
269 }
270
271 DictionaryEntry** next_addr() {
272 return (DictionaryEntry**)HashtableEntry<Klass*, mtClass>::next_addr();
273 }
274
275 ClassLoaderData* loader_data() const { return _loader_data; }
276 void set_loader_data(ClassLoaderData* loader_data) { _loader_data = loader_data; }
277
278 ProtectionDomainEntry* pd_set() const { return _pd_set; }
279 void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
280
281 bool has_protection_domain() { return _pd_set != NULL; }
282
283 // Tells whether the initiating class' protection can access the this _klass
284 bool is_valid_protection_domain(Handle protection_domain) {
285 if (!ProtectionDomainVerification) return true;
286 if (!SystemDictionary::has_checkPackageAccess()) return true;
287
288 return protection_domain() == NULL
289 ? true
290 : contains_protection_domain(protection_domain());
291 }
292
293 void set_strongly_reachable(int gen) {
294 for (ProtectionDomainEntry* current = _pd_set;
295 current != NULL;
296 current = current->_next) {
297 current->_pd_cache->set_strongly_reachable(gen);
298 }
299 }
300
301 void verify_protection_domain_set() {
302 for (ProtectionDomainEntry* current = _pd_set;
303 current != NULL;
304 current = current->_next) {
305 current->_pd_cache->protection_domain()->verify();
306 }
307 }
308
309 bool equals(Symbol* class_name, ClassLoaderData* loader_data) const {
310 Klass* klass = (Klass*)literal();
311 return (InstanceKlass::cast(klass)->name() == class_name &&
312 _loader_data == loader_data);
313 }
314
315 void print() {
316 int count = 0;
317 for (ProtectionDomainEntry* current = _pd_set;
318 current != NULL;
319 current = current->_next) {
320 count++;
321 }
322 tty->print_cr("pd set = #%d", count);
323 }
324 };
325
|