27 #include "classfile/systemDictionary.hpp" 28 #include "logging/log.hpp" 29 #include "logging/logStream.hpp" 30 #include "memory/iterator.hpp" 31 #include "memory/resourceArea.hpp" 32 #include "oops/oop.inline.hpp" 33 #include "oops/weakHandle.inline.hpp" 34 #include "utilities/hashtable.inline.hpp" 35 36 unsigned int ProtectionDomainCacheTable::compute_hash(Handle protection_domain) { 37 // Identity hash can safepoint, so keep protection domain in a Handle. 38 return (unsigned int)(protection_domain->identity_hash()); 39 } 40 41 int ProtectionDomainCacheTable::index_for(Handle protection_domain) { 42 return hash_to_index(compute_hash(protection_domain)); 43 } 44 45 ProtectionDomainCacheTable::ProtectionDomainCacheTable(int table_size) 46 : Hashtable<ClassLoaderWeakHandle, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry)) 47 { 48 } 49 50 void ProtectionDomainCacheTable::unlink() { 51 assert(SafepointSynchronize::is_at_safepoint(), "must be"); 52 for (int i = 0; i < table_size(); ++i) { 53 ProtectionDomainCacheEntry** p = bucket_addr(i); 54 ProtectionDomainCacheEntry* entry = bucket(i); 55 while (entry != NULL) { 56 oop pd = entry->object_no_keepalive(); 57 if (pd != NULL) { 58 p = entry->next_addr(); 59 } else { 60 LogTarget(Debug, protectiondomain) lt; 61 if (lt.is_enabled()) { 62 LogStream ls(lt); 63 ls.print_cr("protection domain unlinked at %d", i); 64 } 65 entry->literal().release(); 66 *p = entry->next(); 67 free_entry(entry); 68 } 69 entry = *p; 70 } 71 } 72 } 73 74 void ProtectionDomainCacheTable::print_on(outputStream* st) const { 75 st->print_cr("Protection domain cache table (table_size=%d, classes=%d)", 76 table_size(), number_of_entries()); 77 for (int index = 0; index < table_size(); index++) { 78 for (ProtectionDomainCacheEntry* probe = bucket(index); 79 probe != NULL; 80 probe = probe->next()) { 81 st->print_cr("%4d: protection_domain: " PTR_FORMAT, index, p2i(probe->object_no_keepalive())); 82 } 83 } 84 } 85 86 void ProtectionDomainCacheTable::verify() { 87 verify_table<ProtectionDomainCacheEntry>("Protection Domain Table"); 88 } 89 90 oop ProtectionDomainCacheEntry::object() { 91 return literal().resolve(); 92 } 93 94 oop ProtectionDomainEntry::object() { 107 } 108 109 void ProtectionDomainCacheEntry::verify() { 110 guarantee(object_no_keepalive() == NULL || oopDesc::is_oop(object_no_keepalive()), "must be an oop"); 111 } 112 113 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(Handle protection_domain) { 114 unsigned int hash = compute_hash(protection_domain); 115 int index = hash_to_index(hash); 116 117 ProtectionDomainCacheEntry* entry = find_entry(index, protection_domain); 118 if (entry == NULL) { 119 entry = add_entry(index, hash, protection_domain); 120 } 121 // keep entry alive 122 (void)entry->object(); 123 return entry; 124 } 125 126 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, Handle protection_domain) { 127 for (ProtectionDomainCacheEntry* e = bucket(index); e != NULL; e = e->next()) { 128 if (oopDesc::equals(e->object_no_keepalive(), protection_domain())) { 129 return e; 130 } 131 } 132 133 return NULL; 134 } 135 136 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, unsigned int hash, Handle protection_domain) { 137 assert_locked_or_safepoint(SystemDictionary_lock); 138 assert(index == index_for(protection_domain), "incorrect index?"); 139 assert(find_entry(index, protection_domain) == NULL, "no double entry"); 140 141 ClassLoaderWeakHandle w = ClassLoaderWeakHandle::create(protection_domain); 142 ProtectionDomainCacheEntry* p = new_entry(hash, w); 143 Hashtable<ClassLoaderWeakHandle, mtClass>::add_entry(index, p); 144 return p; 145 } | 27 #include "classfile/systemDictionary.hpp" 28 #include "logging/log.hpp" 29 #include "logging/logStream.hpp" 30 #include "memory/iterator.hpp" 31 #include "memory/resourceArea.hpp" 32 #include "oops/oop.inline.hpp" 33 #include "oops/weakHandle.inline.hpp" 34 #include "utilities/hashtable.inline.hpp" 35 36 unsigned int ProtectionDomainCacheTable::compute_hash(Handle protection_domain) { 37 // Identity hash can safepoint, so keep protection domain in a Handle. 38 return (unsigned int)(protection_domain->identity_hash()); 39 } 40 41 int ProtectionDomainCacheTable::index_for(Handle protection_domain) { 42 return hash_to_index(compute_hash(protection_domain)); 43 } 44 45 ProtectionDomainCacheTable::ProtectionDomainCacheTable(int table_size) 46 : Hashtable<ClassLoaderWeakHandle, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry)) 47 { _dead_entries = false; 48 } 49 50 void ProtectionDomainCacheTable::trigger_cleanup() { 51 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); 52 _dead_entries = true; 53 Service_lock->notify_all(); 54 } 55 56 void ProtectionDomainCacheTable::unlink() { 57 MutexLocker ml(SystemDictionary_lock); 58 for (int i = 0; i < table_size(); ++i) { 59 ProtectionDomainCacheEntry** p = bucket_addr(i); 60 ProtectionDomainCacheEntry* entry = bucket(i); 61 while (entry != NULL) { 62 oop pd = entry->object_no_keepalive(); 63 if (pd != NULL) { 64 p = entry->next_addr(); 65 } else { 66 LogTarget(Debug, protectiondomain, table) lt; 67 if (lt.is_enabled()) { 68 LogStream ls(lt); 69 ls.print_cr("protection domain unlinked at %d", i); 70 } 71 entry->literal().release(); 72 *p = entry->next(); 73 free_entry(entry); 74 } 75 entry = *p; 76 } 77 } 78 _dead_entries = false; 79 } 80 81 void ProtectionDomainCacheTable::print_on(outputStream* st) const { 82 assert_locked_or_safepoint(SystemDictionary_lock); 83 st->print_cr("Protection domain cache table (table_size=%d, classes=%d)", 84 table_size(), number_of_entries()); 85 for (int index = 0; index < table_size(); index++) { 86 for (ProtectionDomainCacheEntry* probe = bucket(index); 87 probe != NULL; 88 probe = probe->next()) { 89 st->print_cr("%4d: protection_domain: " PTR_FORMAT, index, p2i(probe->object_no_keepalive())); 90 } 91 } 92 } 93 94 void ProtectionDomainCacheTable::verify() { 95 verify_table<ProtectionDomainCacheEntry>("Protection Domain Table"); 96 } 97 98 oop ProtectionDomainCacheEntry::object() { 99 return literal().resolve(); 100 } 101 102 oop ProtectionDomainEntry::object() { 115 } 116 117 void ProtectionDomainCacheEntry::verify() { 118 guarantee(object_no_keepalive() == NULL || oopDesc::is_oop(object_no_keepalive()), "must be an oop"); 119 } 120 121 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(Handle protection_domain) { 122 unsigned int hash = compute_hash(protection_domain); 123 int index = hash_to_index(hash); 124 125 ProtectionDomainCacheEntry* entry = find_entry(index, protection_domain); 126 if (entry == NULL) { 127 entry = add_entry(index, hash, protection_domain); 128 } 129 // keep entry alive 130 (void)entry->object(); 131 return entry; 132 } 133 134 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, Handle protection_domain) { 135 assert_locked_or_safepoint(SystemDictionary_lock); 136 for (ProtectionDomainCacheEntry* e = bucket(index); e != NULL; e = e->next()) { 137 if (oopDesc::equals(e->object_no_keepalive(), protection_domain())) { 138 return e; 139 } 140 } 141 142 return NULL; 143 } 144 145 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, unsigned int hash, Handle protection_domain) { 146 assert_locked_or_safepoint(SystemDictionary_lock); 147 assert(index == index_for(protection_domain), "incorrect index?"); 148 assert(find_entry(index, protection_domain) == NULL, "no double entry"); 149 150 LogTarget(Debug, protectiondomain, table) lt; 151 if (lt.is_enabled()) { 152 LogStream ls(lt); 153 ls.print("protection domain added "); 154 protection_domain->print_value_on(&ls); 155 ls.cr(); 156 } 157 ClassLoaderWeakHandle w = ClassLoaderWeakHandle::create(protection_domain); 158 ProtectionDomainCacheEntry* p = new_entry(hash, w); 159 Hashtable<ClassLoaderWeakHandle, mtClass>::add_entry(index, p); 160 return p; 161 } |