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 #include "precompiled.hpp"
26 #include "classfile/classLoaderData.inline.hpp"
27 #include "classfile/sharedClassUtil.hpp"
28 #include "classfile/dictionary.hpp"
29 #include "classfile/protectionDomainCache.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "classfile/systemDictionaryShared.hpp"
32 #include "memory/iterator.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "runtime/orderAccess.inline.hpp"
36 #include "utilities/hashtable.inline.hpp"
37
38 DictionaryEntry* Dictionary::_current_class_entry = NULL;
39 int Dictionary::_current_class_index = 0;
40
41 size_t Dictionary::entry_size() {
42 if (DumpSharedSpaces) {
43 return SystemDictionaryShared::dictionary_entry_size();
44 } else {
45 return sizeof(DictionaryEntry);
46 }
47 }
48
49 Dictionary::Dictionary(int table_size)
50 : TwoOopHashtable<InstanceKlass*, mtClass>(table_size, (int)entry_size()) {
51 _current_class_index = 0;
52 _current_class_entry = NULL;
263 if (probe->loader_data() == k->class_loader_data()) {
264 f(k, CHECK);
265 }
266 }
267 }
268 }
269
270 // All classes, and their class loaders
271 // Don't iterate over placeholders
272 void Dictionary::classes_do(void f(Klass*, ClassLoaderData*)) {
273 for (int index = 0; index < table_size(); index++) {
274 for (DictionaryEntry* probe = bucket(index);
275 probe != NULL;
276 probe = probe->next()) {
277 Klass* k = probe->klass();
278 f(k, probe->loader_data());
279 }
280 }
281 }
282
283 void Dictionary::oops_do(OopClosure* f) {
284 // Only the protection domain oops contain references into the heap. Iterate
285 // over all of them.
286 _pd_cache_table->oops_do(f);
287 }
288
289 void Dictionary::unlink(BoolObjectClosure* is_alive) {
290 // Only the protection domain cache table may contain references to the heap
291 // that need to be unlinked.
292 _pd_cache_table->unlink(is_alive);
293 }
294
295 InstanceKlass* Dictionary::try_get_next_class() {
296 while (true) {
297 if (_current_class_entry != NULL) {
298 InstanceKlass* k = _current_class_entry->klass();
299 _current_class_entry = _current_class_entry->next();
300 return k;
301 }
302 _current_class_index = (_current_class_index + 1) % table_size();
391 assert(entry != NULL,"entry must be present, we just created it");
392 assert(protection_domain() != NULL,
393 "real protection domain should be present");
394
395 entry->add_protection_domain(this, protection_domain);
396
397 assert(entry->contains_protection_domain(protection_domain()),
398 "now protection domain should be present");
399 }
400
401
402 bool Dictionary::is_valid_protection_domain(int index, unsigned int hash,
403 Symbol* name,
404 ClassLoaderData* loader_data,
405 Handle protection_domain) {
406 DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
407 return entry->is_valid_protection_domain(protection_domain);
408 }
409
410
411 void Dictionary::reorder_dictionary() {
412
413 // Copy all the dictionary entries into a single master list.
414
415 DictionaryEntry* master_list = NULL;
416 for (int i = 0; i < table_size(); ++i) {
417 DictionaryEntry* p = bucket(i);
418 while (p != NULL) {
419 DictionaryEntry* tmp;
420 tmp = p->next();
421 p->set_next(master_list);
422 master_list = p;
423 p = tmp;
424 }
425 set_entry(i, NULL);
426 }
427
428 // Add the dictionary entries back to the list in the correct buckets.
429 while (master_list != NULL) {
430 DictionaryEntry* p = master_list;
431 master_list = master_list->next();
|
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 #include "precompiled.hpp"
26 #include "classfile/classLoaderData.inline.hpp"
27 #include "classfile/sharedClassUtil.hpp"
28 #include "classfile/dictionary.hpp"
29 #include "classfile/protectionDomainCache.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "classfile/systemDictionaryShared.hpp"
32 #include "memory/iterator.hpp"
33 #include "memory/metaspaceClosure.hpp"
34 #include "memory/resourceArea.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "runtime/orderAccess.inline.hpp"
37 #include "utilities/hashtable.inline.hpp"
38
39 DictionaryEntry* Dictionary::_current_class_entry = NULL;
40 int Dictionary::_current_class_index = 0;
41
42 size_t Dictionary::entry_size() {
43 if (DumpSharedSpaces) {
44 return SystemDictionaryShared::dictionary_entry_size();
45 } else {
46 return sizeof(DictionaryEntry);
47 }
48 }
49
50 Dictionary::Dictionary(int table_size)
51 : TwoOopHashtable<InstanceKlass*, mtClass>(table_size, (int)entry_size()) {
52 _current_class_index = 0;
53 _current_class_entry = NULL;
264 if (probe->loader_data() == k->class_loader_data()) {
265 f(k, CHECK);
266 }
267 }
268 }
269 }
270
271 // All classes, and their class loaders
272 // Don't iterate over placeholders
273 void Dictionary::classes_do(void f(Klass*, ClassLoaderData*)) {
274 for (int index = 0; index < table_size(); index++) {
275 for (DictionaryEntry* probe = bucket(index);
276 probe != NULL;
277 probe = probe->next()) {
278 Klass* k = probe->klass();
279 f(k, probe->loader_data());
280 }
281 }
282 }
283
284 // Used to scan and relocate the classes during CDS archive dump.
285 void Dictionary::classes_do(MetaspaceClosure* it) {
286 for (int index = 0; index < table_size(); index++) {
287 for (DictionaryEntry* probe = bucket(index);
288 probe != NULL;
289 probe = probe->next()) {
290 it->push(probe->klass_addr());
291 if (DumpSharedSpaces) {
292 ((SharedDictionaryEntry*)probe)->metaspace_pointers_do(it);
293 }
294 }
295 }
296 }
297
298
299 void Dictionary::oops_do(OopClosure* f) {
300 // Only the protection domain oops contain references into the heap. Iterate
301 // over all of them.
302 _pd_cache_table->oops_do(f);
303 }
304
305 void Dictionary::unlink(BoolObjectClosure* is_alive) {
306 // Only the protection domain cache table may contain references to the heap
307 // that need to be unlinked.
308 _pd_cache_table->unlink(is_alive);
309 }
310
311 InstanceKlass* Dictionary::try_get_next_class() {
312 while (true) {
313 if (_current_class_entry != NULL) {
314 InstanceKlass* k = _current_class_entry->klass();
315 _current_class_entry = _current_class_entry->next();
316 return k;
317 }
318 _current_class_index = (_current_class_index + 1) % table_size();
407 assert(entry != NULL,"entry must be present, we just created it");
408 assert(protection_domain() != NULL,
409 "real protection domain should be present");
410
411 entry->add_protection_domain(this, protection_domain);
412
413 assert(entry->contains_protection_domain(protection_domain()),
414 "now protection domain should be present");
415 }
416
417
418 bool Dictionary::is_valid_protection_domain(int index, unsigned int hash,
419 Symbol* name,
420 ClassLoaderData* loader_data,
421 Handle protection_domain) {
422 DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
423 return entry->is_valid_protection_domain(protection_domain);
424 }
425
426
427 void Dictionary::reorder_dictionary_for_sharing() {
428
429 // Copy all the dictionary entries into a single master list.
430
431 DictionaryEntry* master_list = NULL;
432 for (int i = 0; i < table_size(); ++i) {
433 DictionaryEntry* p = bucket(i);
434 while (p != NULL) {
435 DictionaryEntry* tmp;
436 tmp = p->next();
437 p->set_next(master_list);
438 master_list = p;
439 p = tmp;
440 }
441 set_entry(i, NULL);
442 }
443
444 // Add the dictionary entries back to the list in the correct buckets.
445 while (master_list != NULL) {
446 DictionaryEntry* p = master_list;
447 master_list = master_list->next();
|